Skip to content

Commit

Permalink
feat(cli): hide password input
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sangaman committed Sep 5, 2019
1 parent d6bb21f commit dd6e8d9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
34 changes: 24 additions & 10 deletions lib/cli/commands/create.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import { Arguments } from 'yargs';
import { callback, loadXudInitClient } from '../command';
import { CreateNodeRequest } from '../../proto/xudrpc_pb';
import readline from 'readline';

export const command = 'create <password>';
export const command = 'create';

export const describe = 'create an xud node';

export const builder = {
password: {
description: 'password to encrypt xud key and wallets',
type: 'string',
},
};
export const builder = {};

export const handler = (argv: Arguments) => {
const request = new CreateNodeRequest();
request.setPassword(argv.password);
loadXudInitClient(argv).createNode(request, callback(argv));
const rl = readline.createInterface({
input: process.stdin,
terminal: true,
});

process.stdout.write('Enter master xud password: ');
rl.question('', (password1) => {
process.stdout.write('\n');
process.stdout.write('Re-enter password: ');
rl.question('', (password2) => {
process.stdout.write('\n');
rl.close();
if (password1 === password2) {
const request = new CreateNodeRequest();
request.setPassword(argv.password);
loadXudInitClient(argv).createNode(request, callback(argv));
} else {
console.log('Passwords do not match, please try again');
}
});
});
};
26 changes: 16 additions & 10 deletions lib/cli/commands/unlock.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { Arguments } from 'yargs';
import { callback, loadXudInitClient } from '../command';
import { UnlockNodeRequest } from '../../proto/xudrpc_pb';
import readline from 'readline';

export const command = 'unlock <password>';
export const command = 'unlock';

export const describe = 'unlock an xud node';

export const builder = {
password: {
description: 'password to decrypt xud key and wallets',
type: 'string',
},
};
export const builder = {};

export const handler = (argv: Arguments) => {
const request = new UnlockNodeRequest();
request.setPassword(argv.password);
loadXudInitClient(argv).unlockNode(request, callback(argv));
const rl = readline.createInterface({
input: process.stdin,
terminal: true,
});

process.stdout.write('Enter master xud password: ');
rl.question('', (password) => {
process.stdout.write('\n');
rl.close();
const request = new UnlockNodeRequest();
request.setPassword(password);
loadXudInitClient(argv).unlockNode(request, callback(argv));
});
};

0 comments on commit dd6e8d9

Please sign in to comment.