feat(client/keys): add --yes option to keys export and keys mnemonic (#18745)
Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
parent
6cca5e37fd
commit
0268ff937b
@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Improvements
|
||||
|
||||
* (client/keys) [#18745](https://github.com/cosmos/cosmos-sdk/pull/18745) Improve `<appd> keys export` and `<appd> keys mnemonic` by adding --yes option to skip interactive confirmation.
|
||||
* (client/keys) [#18743](https://github.com/cosmos/cosmos-sdk/pull/18743) Improve `<appd> keys add -i` by hiding inputting of bip39 passphrase.
|
||||
* (client/keys) [#18703](https://github.com/cosmos/cosmos-sdk/pull/18703) Improve `<appd> keys add` and `<appd> keys show` by checking whether there are duplicate keys in the multisig case.
|
||||
* (x/gov) [#18707](https://github.com/cosmos/cosmos-sdk/pull/18707) Improve genesis validation.
|
||||
|
||||
@ -65,15 +65,19 @@ and export your keys in ASCII-armored encrypted format.`,
|
||||
cmd.Flags().Bool(flagUnarmoredHex, false, "Export unarmored hex privkey. Requires --unsafe.")
|
||||
cmd.Flags().Bool(flagUnsafe, false, "Enable unsafe operations. This flag must be switched on along with all unsafe operation-specific options.")
|
||||
cmd.Flags().Bool(flagIndiscreet, false, "Print unarmored hex privkey directly on current terminal (only valid when --unarmored-hex is true)")
|
||||
cmd.Flags().BoolP(flagYes, "y", false, "Skip confirmation prompt when export unarmored hex privkey")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func exportUnsafeUnarmored(ctx client.Context, cmd *cobra.Command, uid string, buf *bufio.Reader) error {
|
||||
if yes, err := input.GetConfirmation("WARNING: The private key will be exported as an unarmored hexadecimal string. USE AT YOUR OWN RISK. Continue?", buf, cmd.ErrOrStderr()); err != nil {
|
||||
return err
|
||||
} else if !yes {
|
||||
return nil
|
||||
// confirm export unarmored hex privkey, unless -y is passed
|
||||
if skip, _ := cmd.Flags().GetBool(flagYes); !skip {
|
||||
if yes, err := input.GetConfirmation("WARNING: The private key will be exported as an unarmored hexadecimal string. USE AT YOUR OWN RISK. Continue?", buf, cmd.ErrOrStderr()); err != nil {
|
||||
return err
|
||||
} else if !yes {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
hexPrivKey, err := unsafeExportPrivKeyHex(ctx.Keyring.(unsafeExporter), uid)
|
||||
|
||||
@ -49,6 +49,14 @@ func Test_runExportCmd(t *testing.T) {
|
||||
mustFail: true,
|
||||
expectedOutput: "",
|
||||
},
|
||||
{
|
||||
name: "--unsafe --unarmored-hex --yes success",
|
||||
keyringBackend: keyring.BackendTest,
|
||||
extraArgs: []string{"--unsafe", "--unarmored-hex", "--yes"},
|
||||
userInput: "",
|
||||
mustFail: false,
|
||||
expectedOutputContain: "2485e33678db4175dc0ecef2d6e1fc493d4a0d7f7ce83324b6ed70afe77f3485\n",
|
||||
},
|
||||
{
|
||||
name: "--unsafe --unarmored-hex success",
|
||||
keyringBackend: keyring.BackendTest,
|
||||
|
||||
@ -40,13 +40,15 @@ func MnemonicKeyCommand() *cobra.Command {
|
||||
return fmt.Errorf("256-bits is 43 characters in Base-64, and 100 in Base-6. You entered %v, and probably want more", len(inputEntropy))
|
||||
}
|
||||
|
||||
conf, err := input.GetConfirmation(fmt.Sprintf("> Input length: %d", len(inputEntropy)), buf, cmd.ErrOrStderr())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if skip, _ := cmd.Flags().GetBool(flagYes); !skip {
|
||||
yes, err := input.GetConfirmation(fmt.Sprintf("> Input length: %d", len(inputEntropy)), buf, cmd.ErrOrStderr())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !conf {
|
||||
return nil
|
||||
if !yes {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// hash input entropy to get entropy seed
|
||||
@ -76,5 +78,6 @@ func MnemonicKeyCommand() *cobra.Command {
|
||||
|
||||
cmd.Flags().Bool(flagUserEntropy, false, "Prompt the user to supply their own entropy, instead of relying on the system")
|
||||
cmd.Flags().Bool(flagIndiscreet, false, "Print mnemonic directly on current terminal")
|
||||
cmd.Flags().BoolP(flagYes, "y", false, "Skip confirmation prompt when check input entropy length")
|
||||
return cmd
|
||||
}
|
||||
|
||||
@ -52,6 +52,13 @@ func Test_RunMnemonicCmdUser(t *testing.T) {
|
||||
fakeEntropy = strings.Repeat(":)", 40) + "\nn\n" // entropy + accept count
|
||||
mockIn.Reset(fakeEntropy)
|
||||
require.NoError(t, cmd.Execute())
|
||||
|
||||
// test for skip confirmation
|
||||
cmd.SetArgs([]string{fmt.Sprintf("--%s", flagUserEntropy), fmt.Sprintf("--%s", flagIndiscreet), fmt.Sprintf("--%s", flagYes)})
|
||||
fakeEntropy = strings.Repeat(":)", 40) + "\n" // entropy + accept count
|
||||
mockIn.Reset(fakeEntropy)
|
||||
require.NoError(t, cmd.Execute())
|
||||
require.Equal(t, "volcano hungry midnight divorce post ship bicycle fitness hospital critic protect ring trim alien there safe fine subway style impulse identify right improve print\n", mockOut.String())
|
||||
}
|
||||
|
||||
func Test_RunMnemonicCmdUserDiscreetly(t *testing.T) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user