From 3be478253ad5a56a3648ab415435607d2537a9c9 Mon Sep 17 00:00:00 2001 From: Tasos Bitsios Date: Thu, 31 Oct 2024 17:22:45 +0100 Subject: [PATCH 1/5] goal: added "wallet new -n" non-interactive wallet creation skipping password prompt --- cmd/goal/messages.go | 1 + cmd/goal/wallet.go | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cmd/goal/messages.go b/cmd/goal/messages.go index 1bc78ce30a..5b2c17cc36 100644 --- a/cmd/goal/messages.go +++ b/cmd/goal/messages.go @@ -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" diff --git a/cmd/goal/wallet.go b/cmd/goal/wallet.go index e95aea62a6..cddcbfceab 100644 --- a/cmd/goal/wallet.go +++ b/cmd/goal/wallet.go @@ -33,6 +33,7 @@ import ( var ( recoverWallet bool + noPassword bool defaultWalletName string ) @@ -45,6 +46,7 @@ func init() { // 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{ @@ -113,17 +115,23 @@ var newWalletCmd = &cobra.Command{ } } - // Fetch a password for the wallet - fmt.Printf(infoChoosePasswordPrompt, walletName) - walletPassword := ensurePassword() + walletPassword := []byte{} - // Confirm the password - fmt.Printf(infoPasswordConfirmation) - passwordConfirmation := ensurePassword() + if noPassword { + reportInfoln(infoSkipPassword) + } else { + // Fetch a password for the wallet + fmt.Printf(infoChoosePasswordPrompt, walletName) + walletPassword = ensurePassword() - // Check the password confirmation - if !bytes.Equal(walletPassword, passwordConfirmation) { - reportErrorln(errorPasswordConfirmation) + // Confirm the password + fmt.Print(infoPasswordConfirmation) + passwordConfirmation := ensurePassword() + + // Check the password confirmation + if !bytes.Equal(walletPassword, passwordConfirmation) { + reportErrorln(errorPasswordConfirmation) + } } // Create the wallet @@ -134,7 +142,7 @@ var newWalletCmd = &cobra.Command{ } reportInfof(infoCreatedWallet, walletName) - if !recoverWallet { + if !recoverWallet && !noPassword { // Offer to print backup seed fmt.Printf(infoBackupExplanation) resp, err := reader.ReadString('\n') From f5417d6b37c9cf4414399143c740d2af94e2e897 Mon Sep 17 00:00:00 2001 From: Pavel Zbitskiy Date: Fri, 21 Feb 2025 16:38:33 -0500 Subject: [PATCH 2/5] add --unencrypted and --no-display-seed options --- cmd/goal/wallet.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/goal/wallet.go b/cmd/goal/wallet.go index cddcbfceab..70291c96ee 100644 --- a/cmd/goal/wallet.go +++ b/cmd/goal/wallet.go @@ -32,9 +32,10 @@ import ( ) var ( - recoverWallet bool - noPassword bool - defaultWalletName string + recoverWallet bool + createUnencryptedWallet bool + noDisplaySeed bool + defaultWalletName string ) func init() { @@ -46,7 +47,8 @@ func init() { // 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") + newWalletCmd.Flags().BoolVarP(&createUnencryptedWallet, "unencrypted", "n", false, "Create a new wallet without prompting for password.") + newWalletCmd.Flags().BoolVarP(&noDisplaySeed, "no-display-seed", "s", false, "Create a new wallet without displaying the seed phrase.") } var walletCmd = &cobra.Command{ @@ -117,7 +119,7 @@ var newWalletCmd = &cobra.Command{ walletPassword := []byte{} - if noPassword { + if createUnencryptedWallet { reportInfoln(infoSkipPassword) } else { // Fetch a password for the wallet @@ -142,9 +144,9 @@ var newWalletCmd = &cobra.Command{ } reportInfof(infoCreatedWallet, walletName) - if !recoverWallet && !noPassword { + if !recoverWallet && !noDisplaySeed { // Offer to print backup seed - fmt.Printf(infoBackupExplanation) + fmt.Println(infoBackupExplanation) resp, err := reader.ReadString('\n') resp = strings.TrimSpace(resp) if err != nil { From 57e6518eb5751a2d723dcbc361f30026d0564cbd Mon Sep 17 00:00:00 2001 From: Pavel Zbitskiy <65323360+algorandskiy@users.noreply.github.com> Date: Fri, 21 Feb 2025 18:02:05 -0500 Subject: [PATCH 3/5] Update cmd/goal/wallet.go --- cmd/goal/wallet.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/goal/wallet.go b/cmd/goal/wallet.go index 70291c96ee..1477638a62 100644 --- a/cmd/goal/wallet.go +++ b/cmd/goal/wallet.go @@ -47,8 +47,8 @@ func init() { // 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(&createUnencryptedWallet, "unencrypted", "n", false, "Create a new wallet without prompting for password.") - newWalletCmd.Flags().BoolVarP(&noDisplaySeed, "no-display-seed", "s", false, "Create a new wallet without displaying the seed phrase.") + newWalletCmd.Flags().BoolVar(&createUnencryptedWallet, "unencrypted", false, "Create a new wallet without prompting for password.") + newWalletCmd.Flags().BoolVar(&noDisplaySeed, "no-display-seed", false, "Create a new wallet without displaying the seed phrase.") } var walletCmd = &cobra.Command{ From caec3f786ede0eff542c8b3abb534092d64d9e1b Mon Sep 17 00:00:00 2001 From: Pavel Zbitskiy <65323360+algorandskiy@users.noreply.github.com> Date: Mon, 24 Feb 2025 10:01:45 -0500 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: John Jannotti --- cmd/goal/messages.go | 2 +- cmd/goal/wallet.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/goal/messages.go b/cmd/goal/messages.go index 5b2c17cc36..b9c7ac2e6e 100644 --- a/cmd/goal/messages.go +++ b/cmd/goal/messages.go @@ -174,7 +174,7 @@ const ( infoPasswordConfirmation = "Please confirm the password: " infoCreatingWallet = "Creating wallet..." infoCreatedWallet = "Created wallet '%s'" - infoSkipPassword = "Skipping password prompt" + infoUnencrypted = "Creating unencrypted wallet" 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" diff --git a/cmd/goal/wallet.go b/cmd/goal/wallet.go index 1477638a62..1033a8a00f 100644 --- a/cmd/goal/wallet.go +++ b/cmd/goal/wallet.go @@ -47,7 +47,7 @@ func init() { // 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().BoolVar(&createUnencryptedWallet, "unencrypted", false, "Create a new wallet without prompting for password.") + newWalletCmd.Flags().BoolVar(&createUnencryptedWallet, "unencrypted", false, "Create a new wallet without a password.") newWalletCmd.Flags().BoolVar(&noDisplaySeed, "no-display-seed", false, "Create a new wallet without displaying the seed phrase.") } @@ -120,7 +120,7 @@ var newWalletCmd = &cobra.Command{ walletPassword := []byte{} if createUnencryptedWallet { - reportInfoln(infoSkipPassword) + reportInfoln(infoUnencrypted) } else { // Fetch a password for the wallet fmt.Printf(infoChoosePasswordPrompt, walletName) From f2c89e75f3cc1ca23c41053f5e8d68b7f524b3ac Mon Sep 17 00:00:00 2001 From: Pavel Zbitskiy Date: Mon, 24 Feb 2025 10:17:49 -0500 Subject: [PATCH 5/5] fix formatter --- cmd/goal/messages.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/goal/messages.go b/cmd/goal/messages.go index b9c7ac2e6e..21d4e4f503 100644 --- a/cmd/goal/messages.go +++ b/cmd/goal/messages.go @@ -174,7 +174,7 @@ const ( infoPasswordConfirmation = "Please confirm the password: " infoCreatingWallet = "Creating wallet..." infoCreatedWallet = "Created wallet '%s'" - infoUnencrypted = "Creating unencrypted wallet" + infoUnencrypted = "Creating unencrypted wallet" 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"