Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goal: added "wallet new -n" non-interactive wallet creation #6160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions cmd/goal/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ const (
infoPasswordConfirmation = "Please confirm the password: "
infoCreatingWallet = "Creating wallet..."
infoCreatedWallet = "Created wallet '%s'"
infoSkipPassword = "Skipping password prompt"
infoBackupExplanation = "Your new wallet has a backup phrase that can be used for recovery.\nKeeping this backup phrase safe is extremely important.\nWould you like to see it now? (Y/n): "
infoPrintedBackupPhrase = "Your backup phrase is printed below.\nKeep this information safe -- never share it with anyone!"
infoBackupPhrase = "\n%s"
Expand Down
28 changes: 18 additions & 10 deletions cmd/goal/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

var (
recoverWallet bool
noPassword bool
defaultWalletName string
)

Expand All @@ -45,6 +46,7 @@

// Should we recover the wallet?
newWalletCmd.Flags().BoolVarP(&recoverWallet, "recover", "r", false, "Recover the wallet from the backup mnemonic provided at wallet creation (NOT the mnemonic provided by goal account export or by algokey). Regenerate accounts in the wallet with `goal account new`")
newWalletCmd.Flags().BoolVarP(&noPassword, "non-interactive", "n", false, "Create the new wallet without prompting for password or displaying the seed phrase")
}

var walletCmd = &cobra.Command{
Expand Down Expand Up @@ -113,17 +115,23 @@
}
}

// Fetch a password for the wallet
fmt.Printf(infoChoosePasswordPrompt, walletName)
walletPassword := ensurePassword()
walletPassword := []byte{}

Check warning on line 118 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L118

Added line #L118 was not covered by tests

// Confirm the password
fmt.Printf(infoPasswordConfirmation)
passwordConfirmation := ensurePassword()
if noPassword {
reportInfoln(infoSkipPassword)
} else {

Check warning on line 122 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L120-L122

Added lines #L120 - L122 were not covered by tests
// Fetch a password for the wallet
fmt.Printf(infoChoosePasswordPrompt, walletName)
walletPassword = ensurePassword()

Check warning on line 125 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L124-L125

Added lines #L124 - L125 were not covered by tests

// Check the password confirmation
if !bytes.Equal(walletPassword, passwordConfirmation) {
reportErrorln(errorPasswordConfirmation)
// Confirm the password
fmt.Print(infoPasswordConfirmation)
passwordConfirmation := ensurePassword()

Check warning on line 129 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L128-L129

Added lines #L128 - L129 were not covered by tests

// Check the password confirmation
if !bytes.Equal(walletPassword, passwordConfirmation) {
reportErrorln(errorPasswordConfirmation)

Check warning on line 133 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L132-L133

Added lines #L132 - L133 were not covered by tests
}
}

// Create the wallet
Expand All @@ -134,7 +142,7 @@
}
reportInfof(infoCreatedWallet, walletName)

if !recoverWallet {
if !recoverWallet && !noPassword {

Check warning on line 145 in cmd/goal/wallet.go

View check run for this annotation

Codecov / codecov/patch

cmd/goal/wallet.go#L145

Added line #L145 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might make --no-seed a separate option, assuming you agree with my thought that this should be called --unencrypted instead of --non-interactive. I get that you're thinking of the single use case of non-interactive, which ought to imply "no-seed". But if we treat "unencrypted" as the use case, it is separable from "non-interactive".

// Offer to print backup seed
fmt.Printf(infoBackupExplanation)
resp, err := reader.ReadString('\n')
Expand Down
Loading