From d08c40253a14cc0a93a591a9633fd4dc27f41f57 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Sat, 20 Sep 2025 17:02:29 +0800 Subject: [PATCH 1/3] fix: source flag for key add --- client/keys/add.go | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/client/keys/add.go b/client/keys/add.go index 23ebf13f7..54df68752 100644 --- a/client/keys/add.go +++ b/client/keys/add.go @@ -6,6 +6,8 @@ import ( "encoding/json" "errors" "fmt" + "io" + "os" "sort" "github.com/spf13/cobra" @@ -35,6 +37,7 @@ const ( flagMultiSigThreshold = "multisig-threshold" flagNoSort = "nosort" flagHDPath = "hd-path" + flagMnemonicSrc = "source" mnemonicEntropySize = 256 ) @@ -183,19 +186,34 @@ func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf var mnemonic, bip39Passphrase string recoverKey, _ := cmd.Flags().GetBool(flagRecover) + mnemonicSrc, _ := cmd.Flags().GetString(flagMnemonicSrc) if recoverKey { - mnemonic, err = input.GetString("Enter your bip39 mnemonic", inBuf) - if err != nil { - return err + if mnemonicSrc != "" { + mnemonic, err = readMnemonicFromFile(mnemonicSrc) + if err != nil { + return err + } + } else { + mnemonic, err = input.GetString("Enter your bip39 mnemonic", inBuf) + if err != nil { + return err + } } if !bip39.IsMnemonicValid(mnemonic) { return errors.New("invalid mnemonic") } } else if interactive { - mnemonic, err = input.GetString("Enter your bip39 mnemonic, or hit enter to generate one.", inBuf) - if err != nil { - return err + if mnemonicSrc != "" { + mnemonic, err = readMnemonicFromFile(mnemonicSrc) + if err != nil { + return err + } + } else { + mnemonic, err = input.GetString("Enter your bip39 mnemonic, or hit enter to generate one.", inBuf) + if err != nil { + return err + } } if !bip39.IsMnemonicValid(mnemonic) && mnemonic != "" { @@ -303,3 +321,17 @@ func validateMultisigThreshold(k, nKeys int) error { } return nil } + +func readMnemonicFromFile(filePath string) (string, error) { + file, err := os.Open(filePath) + if err != nil { + return "", err + } + defer file.Close() + + bz, err := io.ReadAll(file) + if err != nil { + return "", err + } + return string(bz), nil +} From d0bdf430cc572e5591abe0c4b118206da57a7f64 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Sat, 20 Sep 2025 21:50:53 +0800 Subject: [PATCH 2/3] doc --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90165d117..f68c5628a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - [\#545](https://github.com/cosmos/evm/pull/545) Check if mempool is not nil before accepting nonce gap error tx. - [\#585](https://github.com/cosmos/evm/pull/585) Use zero constructor to avoid nil pointer panic when BaseFee is 0d - [\#591](https://github.com/cosmos/evm/pull/591) CheckTxHandler should handle "invalid nonce" tx +- [\#643](https://github.com/cosmos/evm/pull/643) Support for mnemonic source flag in key add command. ### IMPROVEMENTS From e7292641ee3cdab5c9dda1b6685cc699ca73fc70 Mon Sep 17 00:00:00 2001 From: Alex | Interchain Labs Date: Mon, 22 Sep 2025 11:12:14 -0400 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f68c5628a..e4939677a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ - [\#545](https://github.com/cosmos/evm/pull/545) Check if mempool is not nil before accepting nonce gap error tx. - [\#585](https://github.com/cosmos/evm/pull/585) Use zero constructor to avoid nil pointer panic when BaseFee is 0d - [\#591](https://github.com/cosmos/evm/pull/591) CheckTxHandler should handle "invalid nonce" tx -- [\#643](https://github.com/cosmos/evm/pull/643) Support for mnemonic source flag in key add command. +- [\#643](https://github.com/cosmos/evm/pull/643) Support for mnemonic source (file, stdin,etc) flag in key add command. ### IMPROVEMENTS