Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rocketpool-cli/wallet/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func RegisterCommands(app *cli.Command, name string, aliases []string) {
&cli.StringFlag{
Name: "password",
Aliases: []string{"p"},
Usage: "The password to secure the wallet with (if not already set)",
Usage: "The password to secure the wallet with (randomly generated if omitted; only used if not already set)",
},
&cli.BoolFlag{
Name: "confirm-mnemonic",
Expand Down Expand Up @@ -86,7 +86,7 @@ func RegisterCommands(app *cli.Command, name string, aliases []string) {
&cli.StringFlag{
Name: "password",
Aliases: []string{"p"},
Usage: "The password to secure the wallet with (if not already set)",
Usage: "The password to secure the wallet with (randomly generated if omitted; only used if not already set)",
},
&cli.StringFlag{
Name: "mnemonic",
Expand Down
5 changes: 4 additions & 1 deletion rocketpool-cli/wallet/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ func initWallet(password string, confirmMnemonicFlag bool, derivationPath string
// Set password if not set
if !status.PasswordSet {
if password == "" {
password = promptPassword()
password, err = generatePassword()
if err != nil {
return err
}
}
if _, err := rp.SetPassword(password); err != nil {
return err
Expand Down
5 changes: 4 additions & 1 deletion rocketpool-cli/wallet/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func recoverWallet(password, mnemonic, addressFlag string, skipValidatorKeyRecov
// Set password if not set
if !status.PasswordSet {
if password == "" {
password = promptPassword()
password, err = generatePassword()
if err != nil {
return err
}
}
if _, err := rp.SetPassword(password); err != nil {
return err
Expand Down
22 changes: 7 additions & 15 deletions rocketpool-cli/wallet/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/goccy/go-json"
"github.com/mitchellh/go-homedir"
"github.com/sethvargo/go-password/password"
"gopkg.in/yaml.v2"

"github.com/rocket-pool/smartnode/bindings/types"
Expand All @@ -17,26 +18,17 @@ import (
"github.com/rocket-pool/smartnode/rocketpool-cli/wallet/bip39"
hexutils "github.com/rocket-pool/smartnode/shared/hex"
"github.com/rocket-pool/smartnode/shared/services/config"
"github.com/rocket-pool/smartnode/shared/services/passwords"
"github.com/rocket-pool/smartnode/shared/services/rocketpool"
"github.com/rocket-pool/smartnode/shared/types/api"
)

// Prompt for a wallet password
func promptPassword() string {
for {
password := promptcli.PromptPassword(
"Please enter a password to secure your wallet with:",
fmt.Sprintf("^.{%d,}$", passwords.MinPasswordLength),
fmt.Sprintf("Your password must be at least %d characters long. Please try again:", passwords.MinPasswordLength),
)
confirmation := promptcli.PromptPassword("Please confirm your password:", "^.*$", "")
if password == confirmation {
return password
}
fmt.Println("Password confirmation does not match.")
fmt.Println("")
// Generate a wallet password using cryptographically secure randomness.
func generatePassword() (string, error) {
generated, err := password.Generate(32, 6, 6, false, false)
if err != nil {
return "", fmt.Errorf("error generating wallet password: %w", err)
}
return generated, nil
}

// Prompt for a recovery mnemonic phrase
Expand Down
Loading