diff --git a/ironfish-cli/src/commands/wallet/decrypt.ts b/ironfish-cli/src/commands/wallet/decrypt.ts index 3362da2b95..4eedbcba31 100644 --- a/ironfish-cli/src/commands/wallet/decrypt.ts +++ b/ironfish-cli/src/commands/wallet/decrypt.ts @@ -32,7 +32,9 @@ export class DecryptCommand extends IronfishCommand { let passphrase = flags.passphrase if (!passphrase) { - passphrase = await inputPrompt('Enter a passphrase to decrypt the wallet', true) + passphrase = await inputPrompt('Enter a passphrase to decrypt the wallet', true, { + password: true, + }) } try { diff --git a/ironfish-cli/src/commands/wallet/encrypt.ts b/ironfish-cli/src/commands/wallet/encrypt.ts index b840208a1e..2573ceb8c1 100644 --- a/ironfish-cli/src/commands/wallet/encrypt.ts +++ b/ironfish-cli/src/commands/wallet/encrypt.ts @@ -17,6 +17,9 @@ export class EncryptCommand extends IronfishCommand { passphrase: Flags.string({ description: 'Passphrase to encrypt the wallet with', }), + confirm: Flags.boolean({ + description: 'Suppress the passphrase confirmation prompt', + }), } async start(): Promise { @@ -32,7 +35,20 @@ export class EncryptCommand extends IronfishCommand { let passphrase = flags.passphrase if (!passphrase) { - passphrase = await inputPrompt('Enter a passphrase to encrypt the wallet', true) + passphrase = await inputPrompt('Enter a passphrase to encrypt the wallet', true, { + password: true, + }) + } + + if (!flags.confirm) { + const confirmedPassphrase = await inputPrompt('Confirm your passphrase', true, { + password: true, + }) + + if (confirmedPassphrase !== passphrase) { + this.log('Passphrases do not match') + this.exit(1) + } } try { diff --git a/ironfish-cli/src/commands/wallet/unlock.ts b/ironfish-cli/src/commands/wallet/unlock.ts index 83819307bc..784f93fb85 100644 --- a/ironfish-cli/src/commands/wallet/unlock.ts +++ b/ironfish-cli/src/commands/wallet/unlock.ts @@ -36,7 +36,9 @@ export class UnlockCommand extends IronfishCommand { let passphrase = flags.passphrase if (!passphrase) { - passphrase = await inputPrompt('Enter a passphrase to unlock the wallet', true) + passphrase = await inputPrompt('Enter a passphrase to unlock the wallet', true, { + password: true, + }) } try { diff --git a/ironfish-cli/src/ui/prompt.ts b/ironfish-cli/src/ui/prompt.ts index 6f9f9aa94c..f670e28044 100644 --- a/ironfish-cli/src/ui/prompt.ts +++ b/ironfish-cli/src/ui/prompt.ts @@ -5,24 +5,28 @@ import { ux } from '@oclif/core' import inquirer from 'inquirer' -async function _inputPrompt(message: string): Promise { +async function _inputPrompt(message: string, options?: { password: boolean }): Promise { const result: { prompt: string } = await inquirer.prompt({ - type: 'input', + type: options?.password ? 'password' : 'input', name: 'prompt', message: `${message}:`, }) return result.prompt.trim() } -export async function inputPrompt(message: string, required: boolean = false): Promise { +export async function inputPrompt( + message: string, + required: boolean = false, + options?: { password: boolean }, +): Promise { let userInput: string = '' if (required) { while (!userInput) { - userInput = await _inputPrompt(message) + userInput = await _inputPrompt(message, options) } } else { - userInput = await _inputPrompt(message) + userInput = await _inputPrompt(message, options) } return userInput