From f4a7ae1ca4e5df1359c4b89bc4647300cee4f3fa Mon Sep 17 00:00:00 2001 From: Fornax <23104993+0xfornax@users.noreply.github.com> Date: Fri, 18 Sep 2026 14:44:24 -0300 Subject: [PATCH] Skip password prompt --- rocketpool-cli/wallet/commands.go | 4 ++-- rocketpool-cli/wallet/init.go | 5 ++++- rocketpool-cli/wallet/recover.go | 5 ++++- rocketpool-cli/wallet/utils.go | 22 +++++++--------------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/rocketpool-cli/wallet/commands.go b/rocketpool-cli/wallet/commands.go index 6d5461672..8c8b18bec 100644 --- a/rocketpool-cli/wallet/commands.go +++ b/rocketpool-cli/wallet/commands.go @@ -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", @@ -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", diff --git a/rocketpool-cli/wallet/init.go b/rocketpool-cli/wallet/init.go index a26f62191..bc3aeb4dc 100644 --- a/rocketpool-cli/wallet/init.go +++ b/rocketpool-cli/wallet/init.go @@ -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 diff --git a/rocketpool-cli/wallet/recover.go b/rocketpool-cli/wallet/recover.go index 74e8b4c53..fb9bdb2d6 100644 --- a/rocketpool-cli/wallet/recover.go +++ b/rocketpool-cli/wallet/recover.go @@ -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 diff --git a/rocketpool-cli/wallet/utils.go b/rocketpool-cli/wallet/utils.go index e77edfb3f..a6056bdfe 100644 --- a/rocketpool-cli/wallet/utils.go +++ b/rocketpool-cli/wallet/utils.go @@ -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" @@ -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