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 #3202

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ IMPROVEMENTS
* Gaia REST API (`gaiacli advanced rest-server`)

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


* Gaia
* [\#3158](https://github.com/cosmos/cosmos-sdk/pull/3158) Validate slashing genesis
Expand Down
39 changes: 29 additions & 10 deletions client/keys/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net/http"
"os"

"github.com/cosmos/go-bip39"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be reverted

"github.com/gorilla/mux"
"github.com/cosmos/go-bip39"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid formatting here.

"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -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 @@ -46,6 +48,7 @@ If run with --dry-run, a key would be generated (or recovered) but not stored to
Args: cobra.ExactArgs(1),
RunE: runAddCmd,
}
cmd.Flags().String(FlagPublicKey, "cosmospub1....", "Store only a public key (useful for constructing multisigs)")
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 +76,12 @@ func runAddCmd(cmd *cobra.Command, args []string) error {

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

interactive := viper.GetBool(flagInteractive)
flags := cmd.Flags()

pubKeyFlag := flags.Lookup(flagPublicKey)

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,18 +103,28 @@ func runAddCmd(cmd *cobra.Command, args []string) error {
}

// ask for a password when generating a local key
if !viper.GetBool(client.FlagUseLedger) {
encryptPassword, err = client.GetCheckPassword(
"Enter a passphrase to encrypt your key to disk:",
"Repeat the passphrase:", buf)
if err != nil {
return err

if !pubKeyFlag.Changed {
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
if !viper.GetBool(client.FlagUseLedger) {
encryptPassword, err = client.GetCheckPassword(
"Enter a passphrase to encrypt your key to disk:",
"Repeat the passphrase:", buf)
if err != nil {
return err
}
}
}
}

interactive := viper.GetBool(flagInteractive)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
flags := cmd.Flags()
if pubKeyFlag.Changed {
pk, err := sdk.GetAccPubKeyBech32(pubKeyFlag.Value.String())
if err != nil {
return err
}
kb.CreateOffline(name, pk)
return nil
}

bipFlag := flags.Lookup(flagBIP44Path)

bip44Params, err := getBIP44ParamsAndPath(bipFlag.Value.String(), bipFlag.Changed || !interactive)
Expand Down