Skip to content

Commit dd6e8d9

Browse files
committed
feat(cli): hide password input
This prompts the user for a password without displaying it on the screen or saving it to the command history for the `CreateNode` and `UnlockNode` calls via the cli.
1 parent d6bb21f commit dd6e8d9

File tree

2 files changed

+40
-20
lines changed

2 files changed

+40
-20
lines changed

lib/cli/commands/create.ts

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
import { Arguments } from 'yargs';
22
import { callback, loadXudInitClient } from '../command';
33
import { CreateNodeRequest } from '../../proto/xudrpc_pb';
4+
import readline from 'readline';
45

5-
export const command = 'create <password>';
6+
export const command = 'create';
67

78
export const describe = 'create an xud node';
89

9-
export const builder = {
10-
password: {
11-
description: 'password to encrypt xud key and wallets',
12-
type: 'string',
13-
},
14-
};
10+
export const builder = {};
1511

1612
export const handler = (argv: Arguments) => {
17-
const request = new CreateNodeRequest();
18-
request.setPassword(argv.password);
19-
loadXudInitClient(argv).createNode(request, callback(argv));
13+
const rl = readline.createInterface({
14+
input: process.stdin,
15+
terminal: true,
16+
});
17+
18+
process.stdout.write('Enter master xud password: ');
19+
rl.question('', (password1) => {
20+
process.stdout.write('\n');
21+
process.stdout.write('Re-enter password: ');
22+
rl.question('', (password2) => {
23+
process.stdout.write('\n');
24+
rl.close();
25+
if (password1 === password2) {
26+
const request = new CreateNodeRequest();
27+
request.setPassword(argv.password);
28+
loadXudInitClient(argv).createNode(request, callback(argv));
29+
} else {
30+
console.log('Passwords do not match, please try again');
31+
}
32+
});
33+
});
2034
};

lib/cli/commands/unlock.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { Arguments } from 'yargs';
22
import { callback, loadXudInitClient } from '../command';
33
import { UnlockNodeRequest } from '../../proto/xudrpc_pb';
4+
import readline from 'readline';
45

5-
export const command = 'unlock <password>';
6+
export const command = 'unlock';
67

78
export const describe = 'unlock an xud node';
89

9-
export const builder = {
10-
password: {
11-
description: 'password to decrypt xud key and wallets',
12-
type: 'string',
13-
},
14-
};
10+
export const builder = {};
1511

1612
export const handler = (argv: Arguments) => {
17-
const request = new UnlockNodeRequest();
18-
request.setPassword(argv.password);
19-
loadXudInitClient(argv).unlockNode(request, callback(argv));
13+
const rl = readline.createInterface({
14+
input: process.stdin,
15+
terminal: true,
16+
});
17+
18+
process.stdout.write('Enter master xud password: ');
19+
rl.question('', (password) => {
20+
process.stdout.write('\n');
21+
rl.close();
22+
const request = new UnlockNodeRequest();
23+
request.setPassword(password);
24+
loadXudInitClient(argv).unlockNode(request, callback(argv));
25+
});
2026
};

0 commit comments

Comments
 (0)