Skip to content

Commit d456d62

Browse files
authored
feat(cli): Hide passphrases in encryption commands (#5343)
1 parent d5868c8 commit d456d62

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

ironfish-cli/src/commands/wallet/decrypt.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export class DecryptCommand extends IronfishCommand {
3232

3333
let passphrase = flags.passphrase
3434
if (!passphrase) {
35-
passphrase = await inputPrompt('Enter a passphrase to decrypt the wallet', true)
35+
passphrase = await inputPrompt('Enter a passphrase to decrypt the wallet', true, {
36+
password: true,
37+
})
3638
}
3739

3840
try {

ironfish-cli/src/commands/wallet/encrypt.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export class EncryptCommand extends IronfishCommand {
1717
passphrase: Flags.string({
1818
description: 'Passphrase to encrypt the wallet with',
1919
}),
20+
confirm: Flags.boolean({
21+
description: 'Suppress the passphrase confirmation prompt',
22+
}),
2023
}
2124

2225
async start(): Promise<void> {
@@ -32,7 +35,20 @@ export class EncryptCommand extends IronfishCommand {
3235

3336
let passphrase = flags.passphrase
3437
if (!passphrase) {
35-
passphrase = await inputPrompt('Enter a passphrase to encrypt the wallet', true)
38+
passphrase = await inputPrompt('Enter a passphrase to encrypt the wallet', true, {
39+
password: true,
40+
})
41+
}
42+
43+
if (!flags.confirm) {
44+
const confirmedPassphrase = await inputPrompt('Confirm your passphrase', true, {
45+
password: true,
46+
})
47+
48+
if (confirmedPassphrase !== passphrase) {
49+
this.log('Passphrases do not match')
50+
this.exit(1)
51+
}
3652
}
3753

3854
try {

ironfish-cli/src/commands/wallet/unlock.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export class UnlockCommand extends IronfishCommand {
3636

3737
let passphrase = flags.passphrase
3838
if (!passphrase) {
39-
passphrase = await inputPrompt('Enter a passphrase to unlock the wallet', true)
39+
passphrase = await inputPrompt('Enter a passphrase to unlock the wallet', true, {
40+
password: true,
41+
})
4042
}
4143

4244
try {

ironfish-cli/src/ui/prompt.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,28 @@
55
import { ux } from '@oclif/core'
66
import inquirer from 'inquirer'
77

8-
async function _inputPrompt(message: string): Promise<string> {
8+
async function _inputPrompt(message: string, options?: { password: boolean }): Promise<string> {
99
const result: { prompt: string } = await inquirer.prompt({
10-
type: 'input',
10+
type: options?.password ? 'password' : 'input',
1111
name: 'prompt',
1212
message: `${message}:`,
1313
})
1414
return result.prompt.trim()
1515
}
1616

17-
export async function inputPrompt(message: string, required: boolean = false): Promise<string> {
17+
export async function inputPrompt(
18+
message: string,
19+
required: boolean = false,
20+
options?: { password: boolean },
21+
): Promise<string> {
1822
let userInput: string = ''
1923

2024
if (required) {
2125
while (!userInput) {
22-
userInput = await _inputPrompt(message)
26+
userInput = await _inputPrompt(message, options)
2327
}
2428
} else {
25-
userInput = await _inputPrompt(message)
29+
userInput = await _inputPrompt(message, options)
2630
}
2731

2832
return userInput

0 commit comments

Comments
 (0)