cmd: replace passPHRASE with passWORD in any user interactions #19932 (#1535)

This commit is contained in:
Daniel Liu 2025-09-21 19:31:00 +08:00 committed by GitHub
parent 8615067df1
commit 22dc136ffe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 54 additions and 59 deletions

View file

@ -117,11 +117,11 @@ Print a short summary of all accounts`,
Creates a new account and prints the address. Creates a new account and prints the address.
The account is saved in encrypted format, you are prompted for a passphrase. The account is saved in encrypted format, you are prompted for a password.
You must remember this passphrase to unlock your account in the future. You must remember this password to unlock your account in the future.
For non-interactive use the passphrase can be specified with the --password flag: For non-interactive use the password can be specified with the --password flag:
Note, this is meant to be used for testing only, it is a bad idea to save your Note, this is meant to be used for testing only, it is a bad idea to save your
password to file or expose in any other way. password to file or expose in any other way.
@ -144,12 +144,12 @@ password to file or expose in any other way.
Update an existing account. Update an existing account.
The account is saved in the newest version in encrypted format, you are prompted The account is saved in the newest version in encrypted format, you are prompted
for a passphrase to unlock the account and another to save the updated file. for a password to unlock the account and another to save the updated file.
This same command can therefore be used to migrate an account of a deprecated This same command can therefore be used to migrate an account of a deprecated
format to the newest format or change the password for an account. format to the newest format or change the password for an account.
For non-interactive use the passphrase can be specified with the --password flag: For non-interactive use the password can be specified with the --password flag:
XDC account update [options] <address> XDC account update [options] <address>
@ -177,11 +177,11 @@ Prints the address.
The keyfile is assumed to contain an unencrypted private key in hexadecimal format. The keyfile is assumed to contain an unencrypted private key in hexadecimal format.
The account is saved in encrypted format, you are prompted for a passphrase. The account is saved in encrypted format, you are prompted for a password.
You must remember this passphrase to unlock your account in the future. You must remember this password to unlock your account in the future.
For non-interactive use the passphrase can be specified with the -password flag: For non-interactive use the password can be specified with the -password flag:
XDC account import [options] <keyfile> XDC account import [options] <keyfile>
@ -268,17 +268,17 @@ func getPassPhrase(prompt string, confirmation bool, i int, passwords []string)
if prompt != "" { if prompt != "" {
fmt.Println(prompt) fmt.Println(prompt)
} }
password, err := prompt2.Stdin.PromptPassword("Passphrase: ") password, err := prompt2.Stdin.PromptPassword("Password: ")
if err != nil { if err != nil {
utils.Fatalf("Failed to read passphrase: %v", err) utils.Fatalf("Failed to read password: %v", err)
} }
if confirmation { if confirmation {
confirm, err := prompt2.Stdin.PromptPassword("Repeat passphrase: ") confirm, err := prompt2.Stdin.PromptPassword("Repeat password: ")
if err != nil { if err != nil {
utils.Fatalf("Failed to read passphrase confirmation: %v", err) utils.Fatalf("Failed to read password confirmation: %v", err)
} }
if password != confirm { if password != confirm {
utils.Fatalf("Passphrases do not match") utils.Fatalf("Passwords do not match")
} }
} }
return password return password
@ -289,7 +289,7 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr
for _, a := range err.Matches { for _, a := range err.Matches {
fmt.Println(" ", a.URL) fmt.Println(" ", a.URL)
} }
fmt.Println("Testing your passphrase against all of them...") fmt.Println("Testing your password against all of them...")
var match *accounts.Account var match *accounts.Account
for _, a := range err.Matches { for _, a := range err.Matches {
if err := ks.Unlock(a, auth); err == nil { if err := ks.Unlock(a, auth); err == nil {
@ -300,7 +300,7 @@ func ambiguousAddrRecovery(ks *keystore.KeyStore, err *keystore.AmbiguousAddrErr
if match == nil { if match == nil {
utils.Fatalf("None of the listed files could be unlocked.") utils.Fatalf("None of the listed files could be unlocked.")
} }
fmt.Printf("Your passphrase unlocked %s\n", match.URL) fmt.Printf("Your password unlocked %s\n", match.URL)
fmt.Println("In order to avoid this warning, you need to remove the following duplicate key files:") fmt.Println("In order to avoid this warning, you need to remove the following duplicate key files:")
for _, a := range err.Matches { for _, a := range err.Matches {
if a != *match { if a != *match {

View file

@ -76,8 +76,8 @@ func TestAccountNew(t *testing.T) {
XDC.Expect(` XDC.Expect(`
Your new account is locked with a password. Please give a password. Do not forget this password. Your new account is locked with a password. Please give a password. Do not forget this password.
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}} Password: {{.InputLine "foobar"}}
Repeat passphrase: {{.InputLine "foobar"}} Repeat password: {{.InputLine "foobar"}}
Your new key was generated Your new key was generated
@ -121,9 +121,9 @@ func TestAccountNewBadRepeat(t *testing.T) {
XDC.Expect(` XDC.Expect(`
Your new account is locked with a password. Please give a password. Do not forget this password. Your new account is locked with a password. Please give a password. Do not forget this password.
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "something"}} Password: {{.InputLine "something"}}
Repeat passphrase: {{.InputLine "something else"}} Repeat password: {{.InputLine "something else"}}
Fatal: Passphrases do not match Fatal: Passwords do not match
`) `)
} }
@ -135,10 +135,10 @@ func TestAccountUpdate(t *testing.T) {
XDC.Expect(` XDC.Expect(`
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3 Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}} Password: {{.InputLine "foobar"}}
Please give a new password. Do not forget this password. Please give a new password. Do not forget this password.
Passphrase: {{.InputLine "foobar2"}} Password: {{.InputLine "foobar2"}}
Repeat passphrase: {{.InputLine "foobar2"}} Repeat password: {{.InputLine "foobar2"}}
`) `)
} }
@ -148,7 +148,7 @@ func TestWalletImport(t *testing.T) {
defer XDC.ExpectExit() defer XDC.ExpectExit()
XDC.Expect(` XDC.Expect(`
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foo"}} Password: {{.InputLine "foo"}}
Address: {xdcd4584b5f6229b7be90727b0fc8c6b91bb427821f} Address: {xdcd4584b5f6229b7be90727b0fc8c6b91bb427821f}
`) `)
@ -193,7 +193,7 @@ func TestWalletImportBadPassword(t *testing.T) {
defer XDC.ExpectExit() defer XDC.ExpectExit()
XDC.Expect(` XDC.Expect(`
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "wrong"}} Password: {{.InputLine "wrong"}}
Fatal: could not decrypt key with given password Fatal: could not decrypt key with given password
`) `)
} }
@ -208,7 +208,7 @@ func TestUnlockFlag(t *testing.T) {
XDC.Expect(` XDC.Expect(`
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3 Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}} Password: {{.InputLine "foobar"}}
`) `)
XDC.ExpectExit() XDC.ExpectExit()
@ -233,11 +233,11 @@ func TestUnlockFlagWrongPassword(t *testing.T) {
XDC.Expect(` XDC.Expect(`
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3 Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "wrong1"}} Password: {{.InputLine "wrong1"}}
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 2/3 Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 2/3
Passphrase: {{.InputLine "wrong2"}} Password: {{.InputLine "wrong2"}}
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 3/3 Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 3/3
Passphrase: {{.InputLine "wrong3"}} Password: {{.InputLine "wrong3"}}
Fatal: Failed to unlock account f466859ead1932d743d622cb74fc058882e8648a (could not decrypt key with given password) Fatal: Failed to unlock account f466859ead1932d743d622cb74fc058882e8648a (could not decrypt key with given password)
`) `)
} }
@ -252,9 +252,9 @@ func TestUnlockFlagMultiIndex(t *testing.T) {
XDC.Expect(` XDC.Expect(`
Unlocking account 0 | Attempt 1/3 Unlocking account 0 | Attempt 1/3
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}} Password: {{.InputLine "foobar"}}
Unlocking account 2 | Attempt 1/3 Unlocking account 2 | Attempt 1/3
Passphrase: {{.InputLine "foobar"}} Password: {{.InputLine "foobar"}}
`) `)
XDC.ExpectExit() XDC.ExpectExit()
@ -319,12 +319,12 @@ func TestUnlockFlagAmbiguous(t *testing.T) {
XDC.Expect(` XDC.Expect(`
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3 Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}} Password: {{.InputLine "foobar"}}
Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a: Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:
keystore://{{keypath "1"}} keystore://{{keypath "1"}}
keystore://{{keypath "2"}} keystore://{{keypath "2"}}
Testing your passphrase against all of them... Testing your password against all of them...
Your passphrase unlocked keystore://{{keypath "1"}} Your password unlocked keystore://{{keypath "1"}}
In order to avoid this warning, you need to remove the following duplicate key files: In order to avoid this warning, you need to remove the following duplicate key files:
keystore://{{keypath "2"}} keystore://{{keypath "2"}}
`) `)
@ -356,11 +356,11 @@ func TestUnlockFlagAmbiguousWrongPassword(t *testing.T) {
XDC.Expect(` XDC.Expect(`
Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3 Unlocking account f466859ead1932d743d622cb74fc058882e8648a | Attempt 1/3
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "wrong"}} Password: {{.InputLine "wrong"}}
Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a: Multiple key files exist for address f466859ead1932d743d622cb74fc058882e8648a:
keystore://{{keypath "1"}} keystore://{{keypath "1"}}
keystore://{{keypath "2"}} keystore://{{keypath "2"}}
Testing your passphrase against all of them... Testing your password against all of them...
Fatal: None of the listed files could be unlocked. Fatal: None of the listed files could be unlocked.
`) `)
XDC.ExpectExit() XDC.ExpectExit()

View file

@ -3,39 +3,34 @@ ethkey
ethkey is a simple command-line tool for working with Ethereum keyfiles. ethkey is a simple command-line tool for working with Ethereum keyfiles.
# Usage # Usage
### `ethkey generate` ### `ethkey generate`
Generate a new keyfile. Generate a new keyfile.
If you want to use an existing private key to use in the keyfile, it can be If you want to use an existing private key to use in the keyfile, it can be
specified by setting `--privatekey` with the location of the file containing the specified by setting `--privatekey` with the location of the file containing the
private key. private key.
### `ethkey inspect <keyfile>` ### `ethkey inspect <keyfile>`
Print various information about the keyfile. Print various information about the keyfile.
Private key information can be printed by using the `--private` flag; Private key information can be printed by using the `--private` flag;
make sure to use this feature with great caution! make sure to use this feature with great caution!
### `ethkey sign <keyfile> <message/file>` ### `ethkey sign <keyfile> <message/file>`
Sign the message with a keyfile. Sign the message with a keyfile.
It is possible to refer to a file containing the message. It is possible to refer to a file containing the message.
### `ethkey verify <address> <signature> <message/file>` ### `ethkey verify <address> <signature> <message/file>`
Verify the signature of the message. Verify the signature of the message.
It is possible to refer to a file containing the message. It is possible to refer to a file containing the message.
## Passwords
## Passphrases For every command that uses a keyfile, you will be prompted to provide the
password for decrypting the keyfile. To avoid this message, it is possible
For every command that uses a keyfile, you will be prompted to provide the to pass the password by using the `--passwordfile` flag pointing to a file that
passphrase for decrypting the keyfile. To avoid this message, it is possible contains the password.
to pass the passphrase by using the `--passphrase` flag pointing to a file that
contains the passphrase.

View file

@ -31,8 +31,8 @@ func TestMessageSignVerify(t *testing.T) {
generate := runEthkey(t, "generate", keyfile) generate := runEthkey(t, "generate", keyfile)
generate.Expect(` generate.Expect(`
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}} Password: {{.InputLine "foobar"}}
Repeat passphrase: {{.InputLine "foobar"}} Repeat password: {{.InputLine "foobar"}}
`) `)
_, matches := generate.ExpectRegexp(`Address: (xdc[0-9a-fA-F]{40})\n`) _, matches := generate.ExpectRegexp(`Address: (xdc[0-9a-fA-F]{40})\n`)
address := matches[1] address := matches[1]
@ -42,7 +42,7 @@ Repeat passphrase: {{.InputLine "foobar"}}
sign := runEthkey(t, "signmessage", keyfile, message) sign := runEthkey(t, "signmessage", keyfile, message)
sign.Expect(` sign.Expect(`
!! Unsupported terminal, password will be echoed. !! Unsupported terminal, password will be echoed.
Passphrase: {{.InputLine "foobar"}} Password: {{.InputLine "foobar"}}
`) `)
_, matches = sign.ExpectRegexp(`Signature: ([0-9a-f]+)\n`) _, matches = sign.ExpectRegexp(`Signature: ([0-9a-f]+)\n`)
signature := matches[1] signature := matches[1]

View file

@ -29,32 +29,32 @@ import (
) )
// getPassPhrase obtains a passphrase given by the user. It first checks the // getPassPhrase obtains a passphrase given by the user. It first checks the
// --passphrase command line flag and ultimately prompts the user for a // --passfile command line flag and ultimately prompts the user for a
// passphrase. // passphrase.
func getPassPhrase(ctx *cli.Context, confirmation bool) string { func getPassPhrase(ctx *cli.Context, confirmation bool) string {
// Look for the --passphrase flag. // Look for the --passwordfile flag.
passphraseFile := ctx.String(passphraseFlag.Name) passphraseFile := ctx.String(passphraseFlag.Name)
if passphraseFile != "" { if passphraseFile != "" {
content, err := os.ReadFile(passphraseFile) content, err := os.ReadFile(passphraseFile)
if err != nil { if err != nil {
utils.Fatalf("Failed to read passphrase file '%s': %v", utils.Fatalf("Failed to read password file '%s': %v",
passphraseFile, err) passphraseFile, err)
} }
return strings.TrimRight(string(content), "\r\n") return strings.TrimRight(string(content), "\r\n")
} }
// Otherwise prompt the user for the passphrase. // Otherwise prompt the user for the passphrase.
passphrase, err := prompt.Stdin.PromptPassword("Passphrase: ") passphrase, err := prompt.Stdin.PromptPassword("Password: ")
if err != nil { if err != nil {
utils.Fatalf("Failed to read passphrase: %v", err) utils.Fatalf("Failed to read password: %v", err)
} }
if confirmation { if confirmation {
confirm, err := prompt.Stdin.PromptPassword("Repeat passphrase: ") confirm, err := prompt.Stdin.PromptPassword("Repeat password: ")
if err != nil { if err != nil {
utils.Fatalf("Failed to read passphrase confirmation: %v", err) utils.Fatalf("Failed to read password confirmation: %v", err)
} }
if passphrase != confirm { if passphrase != confirm {
utils.Fatalf("Passphrases do not match") utils.Fatalf("Passwords do not match")
} }
} }
return passphrase return passphrase