Accounts V2: Log and UX cleanup (#6955)

* Clena up password entry for importing
* Merge branch 'master' of github.com:prysmaticlabs/prysm into accounts-v2-cleanup
* Fix password entry
* Clean
* Merge branch 'master' of github.com:prysmaticlabs/prysm into accounts-v2-cleanup
* Change color
* Merge branch 'master' of github.com:prysmaticlabs/prysm into accounts-v2-cleanup
* Fix
* Merge branch 'master' of github.com:prysmaticlabs/prysm into accounts-v2-cleanup
* Fix
* Merge branch 'master' of github.com:prysmaticlabs/prysm into accounts-v2-cleanup
* Cleanup
* Clean go.mod
* Fix
This commit is contained in:
Ivan Martinez
2020-08-10 18:35:30 -04:00
committed by GitHub
parent ceb11f432e
commit 8b9138a76a
4 changed files with 20 additions and 10 deletions

View File

@@ -84,7 +84,7 @@ func PasswordPrompt(promptText string, validateFunc func(string) error) (string,
var responseValid bool
var response string
for !responseValid {
fmt.Printf("%s: \n", au.Bold(promptText))
fmt.Printf("%s: ", au.Bold(promptText))
bytePassword, err := terminal.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
return "", err
@@ -93,6 +93,7 @@ func PasswordPrompt(promptText string, validateFunc func(string) error) (string,
if err := validateFunc(response); err != nil {
fmt.Printf("\nEntry not valid: %s\n", au.BrightRed(err))
} else {
fmt.Println("")
responseValid = true
}
}

View File

@@ -69,7 +69,7 @@ func ImportAccount(cliCtx *cli.Context) error {
return nil, errors.Wrap(err, "could not create new wallet")
}
if err = createDirectKeymanagerWallet(cliCtx, w); err != nil {
return nil, errors.Wrap(err, "could not initialize wallet")
return nil, errors.Wrap(err, "could not create keymanager")
}
log.WithField("wallet-path", w.walletDir).Info(
"Successfully created new wallet",
@@ -100,13 +100,13 @@ func ImportAccount(cliCtx *cli.Context) error {
if err != nil {
return errors.Wrap(err, "could not parse keys directory")
}
keystoresImported := make([]*v2keymanager.Keystore, 0)
// Consider that the keysDir might be a path to a specific file and handle accordingly.
isDir, err := fileutil.HasDir(keysDir)
if err != nil {
return errors.Wrap(err, "could not determine if path is a directory")
}
keystoresImported := make([]*v2keymanager.Keystore, 0)
// Consider that the keysDir might be a path to a specific file and handle accordingly.
if isDir {
files, err := ioutil.ReadDir(keysDir)
if err != nil {

View File

@@ -383,7 +383,11 @@ func createOrOpenWallet(cliCtx *cli.Context, creationFunc func(cliCtx *cli.Conte
return nil, errors.Wrap(err, "could not check if wallet has files")
}
if !isEmptyWallet {
return OpenWallet(cliCtx)
wallet, err := OpenWallet(cliCtx)
if err != nil {
return nil, errors.Wrap(err, "could not open wallet")
}
return wallet, nil
}
}
return creationFunc(cliCtx)

View File

@@ -2,6 +2,7 @@ package direct
import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"io"
@@ -340,7 +341,6 @@ func (dr *Keymanager) createAccountsKeystore(
privateKeys [][]byte,
publicKeys [][]byte,
) (*v2keymanager.Keystore, error) {
au := aurora.NewAurora(true)
encryptor := keystorev4.New()
id, err := uuid.NewRandom()
if err != nil {
@@ -371,7 +371,6 @@ func (dr *Keymanager) createAccountsKeystore(
_, privKeyExists := existingPrivKeys[string(sk)]
_, pubKeyExists := existingPubKeys[string(pk)]
if privKeyExists || pubKeyExists {
fmt.Printf("Pubkey %#x has already been imported\n", au.BrightRed(bytesutil.Trunc(pk)))
continue
}
dr.accountsStore.PublicKeys = append(dr.accountsStore.PublicKeys, pk)
@@ -402,16 +401,22 @@ func (dr *Keymanager) askUntilPasswordConfirms(
var secretKey []byte
var password string
var err error
publicKey, err := hex.DecodeString(keystore.Pubkey)
if err != nil {
return nil, "", errors.Wrap(err, "could not decode public key")
}
formattedPublicKey := fmt.Sprintf("%#x", bytesutil.Trunc(publicKey))
for {
password, err = promptutil.PasswordPrompt(
"Wrong password entered, try again", promptutil.NotEmpty,
fmt.Sprintf("\nPlease try again, could not use password to import account %s", au.BrightGreen(formattedPublicKey)),
promptutil.NotEmpty,
)
if err != nil {
return nil, "", fmt.Errorf("could not read account password: %v", err)
}
secretKey, err = decryptor.Decrypt(keystore.Crypto, password)
if err != nil && strings.Contains(err.Error(), "invalid checksum") {
fmt.Println(au.Red("Incorrect password entered, please try again"))
fmt.Print(au.Red("Incorrect password entered, please try again"))
continue
}
if err != nil {