Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Support adding offline pubkeys to gaiacli keys #3224

Merged
merged 4 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BREAKING CHANGES
* [\#3176](https://github.com/cosmos/cosmos-sdk/issues/3176) `tx/sign` endpoint now expects `BaseReq` fields as nested object.

* SDK
* [stake] \#2513 Validator power type from Dec -> Int
* [stake] \#2513 Validator power type from Dec -> Int
* [\#3064](https://github.com/cosmos/cosmos-sdk/issues/3064) Sanitize `sdk.Coin` denom. Coins denoms are now case insensitive, i.e. 100fooToken equals to 100FOOTOKEN.

* Tendermint
Expand Down Expand Up @@ -58,6 +58,7 @@ IMPROVEMENTS
* [\#3176](https://github.com/cosmos/cosmos-sdk/issues/3176) Validate tx/sign endpoint POST body.

* Gaia CLI (`gaiacli`)
* [\#3224](https://github.com/cosmos/cosmos-sdk/pull/3224) Support adding offline public keys to the keystore

* Gaia
* [\#3158](https://github.com/cosmos/cosmos-sdk/pull/3158) Validate slashing genesis
Expand All @@ -83,7 +84,7 @@ BUG FIXES

* Gaia CLI (`gaiacli`)
* \#3141 Fix the bug in GetAccount when `len(res) == 0` and `err == nil`

* Gaia
* \#3148 Fix `gaiad export` by adding a boolean to `NewGaiaApp` determining whether or not to load the latest version
* \#3181 Correctly reset total accum update height and jailed-validator bond height / unbonding height on export-for-zero-height
Expand Down
23 changes: 18 additions & 5 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import (
ccrypto "github.com/cosmos/cosmos-sdk/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/cosmos-sdk/crypto/keys/hd"
sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
flagPublicKey = "pubkey"
flagInteractive = "interactive"
flagBIP44Path = "bip44-path"
flagRecover = "recover"
Expand All @@ -36,16 +38,18 @@ func addKeyCommand() *cobra.Command {
Short: "Add an encrypted private key (either newly generated or recovered), encrypt it, and save to disk",
Long: `Derive a new private key and encrypt to disk.
Optionally specify a BIP39 mnemonic, a BIP39 passphrase to further secure the mnemonic,
and a bip32 HD path to derive a specific account. The key will be stored under the given name
and a bip32 HD path to derive a specific account. The key will be stored under the given name
and encrypted with the given password. The only input that is required is the encryption password.

If run with -i, it will prompt the user for BIP44 path, BIP39 mnemonic, and passphrase.
The flag --recover allows one to recover a key from a seed passphrase.
If run with --dry-run, a key would be generated (or recovered) but not stored to the local keystore.
Use the --pubkey flag to add arbitrary public keys to the keystore for constructing multisig transactions.
`,
Args: cobra.ExactArgs(1),
RunE: runAddCmd,
}
cmd.Flags().String(FlagPublicKey, "", "Store only a public key (useful for constructing multisigs e.g. cosmospub1...)")
cmd.Flags().BoolP(flagInteractive, "i", false, "Interactively prompt user for BIP39 passphrase and mnemonic")
cmd.Flags().Bool(client.FlagUseLedger, false, "Store a local reference to a private key on a Ledger device")
cmd.Flags().String(flagBIP44Path, "44'/118'/0'/0/0", "BIP44 path from which to derive a private key")
Expand Down Expand Up @@ -73,6 +77,9 @@ func runAddCmd(cmd *cobra.Command, args []string) error {

buf := client.BufferStdin()
name := args[0]

interactive := viper.GetBool(flagInteractive)

if viper.GetBool(flagDryRun) {
// we throw this away, so don't enforce args,
// we want to get a new random seed phrase quickly
Expand All @@ -94,7 +101,7 @@ func runAddCmd(cmd *cobra.Command, args []string) error {
}

// ask for a password when generating a local key
if !viper.GetBool(client.FlagUseLedger) {
if viper.GetString(flagPublicKey) == "" && !viper.GetBool(client.FlagUseLedger) {
encryptPassword, err = client.GetCheckPassword(
"Enter a passphrase to encrypt your key to disk:",
"Repeat the passphrase:", buf)
Expand All @@ -104,10 +111,16 @@ func runAddCmd(cmd *cobra.Command, args []string) error {
}
}

interactive := viper.GetBool(flagInteractive)
flags := cmd.Flags()
bipFlag := flags.Lookup(flagBIP44Path)
if viper.GetString(flagPublicKey) != "" {
pk, err := sdk.GetAccPubKeyBech32(viper.GetString(flagPublicKey))
if err != nil {
return err
}
kb.CreateOffline(name, pk)
return nil
}

bipFlag := cmd.Flags().Lookup(flagBIP44Path)
bip44Params, err := getBIP44ParamsAndPath(bipFlag.Value.String(), bipFlag.Changed || !interactive)
if err != nil {
return err
Expand Down