refactor(client/keys): hide inputting when keys add -i ask for bip39 passphrase (#18743)
This commit is contained in:
parent
b80be014b7
commit
6cca5e37fd
@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Improvements
|
||||
|
||||
* (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.
|
||||
* (x/bank) [#18636](https://github.com/cosmos/cosmos-sdk/pull/18636) `SendCoinsFromModuleToAccount`, `SendCoinsFromModuleToModule`, `SendCoinsFromAccountToModule`, `DelegateCoinsFromAccountToModule`, `UndelegateCoinsFromModuleToAccount`, `MintCoins` and `BurnCoins` methods now returns an error instead of panicking if any module accounts does not exist or unauthorized.
|
||||
|
||||
@ -77,6 +77,21 @@ func GetString(prompt string, buf *bufio.Reader) (string, error) {
|
||||
return strings.TrimSpace(out), nil
|
||||
}
|
||||
|
||||
// GetSecretString returns the secret string output of a given reader.
|
||||
func GetSecretString(prompt string, buf *bufio.Reader) (secret string, err error) {
|
||||
if inputIsTty() {
|
||||
secret, err = speakeasy.FAsk(os.Stderr, prompt)
|
||||
} else {
|
||||
secret, err = readLineFromBuf(buf)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return secret, nil
|
||||
}
|
||||
|
||||
// inputIsTty returns true iff we have an interactive prompt,
|
||||
// where we can disable echo and request to repeat the password.
|
||||
// If false, we can optimize for piped input from another command
|
||||
|
||||
@ -313,16 +313,16 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
|
||||
|
||||
// override bip39 passphrase
|
||||
if interactive {
|
||||
bip39Passphrase, err = input.GetString(
|
||||
bip39Passphrase, err = input.GetSecretString(
|
||||
"Enter your bip39 passphrase. This is combined with the mnemonic to derive the seed. "+
|
||||
"Most users should just hit enter to use the default, \"\"", inBuf)
|
||||
"Most users should just hit enter to use the default, \"\"\n", inBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// if they use one, make them re-enter it
|
||||
if len(bip39Passphrase) != 0 {
|
||||
p2, err := input.GetString("Repeat the passphrase:", inBuf)
|
||||
p2, err := input.GetSecretString("Repeat the passphrase:\n", inBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -118,6 +118,10 @@ func Test_runAddCmdBasic(t *testing.T) {
|
||||
|
||||
const password = "password1!"
|
||||
|
||||
// set password default interactive key generation successfully
|
||||
mockIn.Reset("\n\n")
|
||||
require.NoError(t, cmd.ExecuteContext(ctx))
|
||||
|
||||
// set password and complete interactive key generation successfully
|
||||
mockIn.Reset("\n" + password + "\n" + password + "\n")
|
||||
require.NoError(t, cmd.ExecuteContext(ctx))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user