feat: support password confirmation of clef newaccount

This commit is contained in:
PolyMa 2023-11-30 18:43:12 +08:00 committed by GitHub
parent fa0df76f3c
commit f94c18ed98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -444,7 +444,19 @@ func (api *SignerAPI) newAccount() (common.Address, error) {
if pwErr := ValidatePasswordFormat(resp.Text); pwErr != nil {
api.UI.ShowError(fmt.Sprintf("Account creation attempt #%d failed due to password requirements: %v", i+1, pwErr))
} else {
// No error
// Confirm password if no error
confirmResp, err := api.UI.OnInputRequired(UserInputRequest{
"Confirm account password",
"Please confirm your password",
true})
if err != nil {
log.Warn("error obtaining password", "error", err)
break
}
if confirmResp.Text != resp.Text {
api.UI.ShowError("Passwords do not match! Please retry again.")
break
} else {
acc, err := be[0].(*keystore.KeyStore).NewAccount(resp.Text)
log.Info("Your new key was generated", "address", acc.Address)
log.Warn("Please backup your key file!", "path", acc.URL.Path)
@ -452,6 +464,7 @@ func (api *SignerAPI) newAccount() (common.Address, error) {
return acc.Address, err
}
}
}
// Otherwise fail, with generic error message
return common.Address{}, errors.New("account creation failed")
}