Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions cmd/mantrachaind/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
ethermintclient "github.com/cosmos/evm/client"
cosmosevmserver "github.com/cosmos/evm/server"
cosmosevmserverflags "github.com/cosmos/evm/server/flags"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -86,7 +85,7 @@ func initRootCmd(
genesisCommand(txConfig, basicManager),
queryCommand(),
txCommand(),
ethermintclient.KeyCommands(app.DefaultNodeHome, false),
KeyCommands(app.DefaultNodeHome, false),
)

_, err := cosmosevmserverflags.AddTxFlags(rootCmd)
Expand Down
102 changes: 102 additions & 0 deletions cmd/mantrachaind/cmd/keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package cmd

import (
"bufio"

"github.com/spf13/cobra"

"github.com/cometbft/cometbft/libs/cli"

ethermintclient "github.com/cosmos/evm/client"
clientkeys "github.com/cosmos/evm/client/keys"
"github.com/cosmos/evm/crypto/hd"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
)

// KeyCommands registers a subtree of commands to interact with
// local private key storage.
//
// The defaultToEthKeys boolean indicates whether to use
// Ethereum compatible keys by default or stick with the Cosmos SDK default.
func KeyCommands(defaultNodeHome string, defaultToEthKeys bool) *cobra.Command {
cmd := &cobra.Command{
Use: "keys",
Short: "Manage your application's keys",
Long: `Keyring management commands. These keys may be in any format supported by the
CometBFT crypto library and can be used by light-clients, full nodes, or any other application
that needs to sign with a private key.

The keyring supports the following backends:

os Uses the operating system's default credentials store.
file Uses encrypted file-based keystore within the app's configuration directory.
This keyring will request a password each time it is accessed, which may occur
multiple times in a single command resulting in repeated password prompts.
kwallet Uses KDE Wallet Manager as a credentials management application.
pass Uses the pass command line utility to store and retrieve keys.
test Stores keys insecurely to disk. It does not prompt for a password to be unlocked
and it should be use only for testing purposes.

kwallet and pass backends depend on external tools. Refer to their respective documentation for more
information:
KWallet https://github.com/KDE/kwallet
pass https://www.passwordstore.org/

The pass backend requires GnuPG: https://gnupg.org/
`,
}

// support adding Ethereum supported keys
addCmd := keys.AddKeyCommand()

if defaultToEthKeys {
ethSecp256k1Str := string(hd.EthSecp256k1Type)

// update the default signing algorithm value to "eth_secp256k1"
algoFlag := addCmd.Flag(flags.FlagKeyType)
algoFlag.DefValue = ethSecp256k1Str
err := algoFlag.Value.Set(ethSecp256k1Str)
if err != nil {
panic(err)
}
}

addCmd.RunE = runAddCmd

cmd.AddCommand(
keys.MnemonicKeyCommand(),
addCmd,
keys.ExportKeyCommand(),
keys.ImportKeyCommand(),
keys.ListKeysCmd(),
keys.ListKeyTypesCmd(),
keys.ShowKeysCmd(),
keys.DeleteKeyCommand(),
keys.RenameKeyCommand(),
keys.ParseKeyStringCommand(),
keys.MigrateCommand(),
flags.LineBreak,
ethermintclient.UnsafeExportEthKeyCommand(),
ethermintclient.UnsafeImportKeyCommand(),
)

cmd.PersistentFlags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
cmd.PersistentFlags().String(flags.FlagKeyringDir, "", "The client Keyring directory; if omitted, the default 'home' directory will be used")
cmd.PersistentFlags().String(flags.FlagKeyringBackend, keyring.BackendOS, "Select keyring's backend (os|file|test)")
cmd.PersistentFlags().String(cli.OutputFlag, "text", "Output format (text|json)")
return cmd
}

func runAddCmd(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd).WithKeyringOptions(hd.EthSecp256k1Option())
clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
buf := bufio.NewReader(clientCtx.Input)
return clientkeys.RunAddCmd(clientCtx, cmd, args, buf)
}
Loading