package main import ( "bufio" "io" "github.com/cosmos/cosmos-sdk/client/flags" clientkeys "github.com/cosmos/cosmos-sdk/client/keys" "github.com/cosmos/cosmos-sdk/crypto/keyring" sdk "github.com/cosmos/cosmos-sdk/types" ethermintcrypto "github.com/cosmos/ethermint/crypto" "github.com/spf13/cobra" "github.com/spf13/viper" ) const ( flagDryRun = "dry-run" ) // keyCommands registers a sub-tree of commands to interact with // local private key storage. func keyCommands() *cobra.Command { cmd := &cobra.Command{ Use: "keys", Short: "Add or view local private keys", Long: `Keys allows you to manage your local keystore for tendermint. These keys may be in any format supported by go-crypto and can be used by light-clients, full nodes, or any other application that needs to sign with a private key.`, } addCmd := clientkeys.AddKeyCommand() addCmd.RunE = runAddCmd cmd.AddCommand( clientkeys.MnemonicKeyCommand(), addCmd, clientkeys.ExportKeyCommand(), clientkeys.ImportKeyCommand(), clientkeys.ListKeysCmd(), clientkeys.ShowKeysCmd(), flags.LineBreak, clientkeys.DeleteKeyCommand(), clientkeys.ParseKeyStringCommand(), clientkeys.MigrateCommand(), flags.LineBreak, unsafeExportEthKeyCommand(), ) return cmd } func getKeyring(transient bool, buf io.Reader) (keyring.Keyring, error) { if transient { return keyring.NewInMemory(ethermintcrypto.EthSeckp256k1Option), nil } return keyring.New( sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), buf, keyring.Option(ethermintcrypto.EthSeckp256k1Option), ) } func runAddCmd(cmd *cobra.Command, args []string) error { inBuf := bufio.NewReader(cmd.InOrStdin()) keystore, err := getKeyring(viper.GetBool(flagDryRun), inBuf) if err != nil { return err } return clientkeys.RunAddCmd(cmd, args, keystore, inBuf) }