Skip to content
Snippets Groups Projects
Commit a10f02d8 authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

unlock.js no longer echo back the typed passphrase.

parent e9837ab5
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/node #!/usr/bin/node
const Libbfa = require( process.env.BFAHOME + '/bin/libbfa.js'); const Libbfa = require( process.env.BFAHOME + '/bin/libbfa.js');
const bfa = new Libbfa(); const bfa = new Libbfa();
const rl = require('readline').createInterface( const Writable = require('stream').Writable;
{ input: process.stdin, output: process.stdout } var mutableStdout = new Writable(
); {
var web3 = bfa.newweb3(); write: function( chunk, encoding, callback )
{
if ( ! this.muted )
process.stdout.write(chunk, encoding);
callback();
}
} );
mutableStdout.muted = false;
const rl = require('readline').createInterface(
{
input: process.stdin,
output: mutableStdout,
terminal: true,
historySize: 0
} );
var web3 = bfa.newweb3();
// First time we try to unlock, we will use this empty passphrase. // First time we try to unlock, we will use this empty passphrase.
// Do not edit.
var passphrase = ""; var passphrase = "";
function atLeastOneFailedSoGetNewPass(x) function atLeastOneFailedSoGetNewPass(x)
{ {
if ( !process.stdin.isTTY ) if ( !process.stdin.isTTY )
bye( 0, "Stdin is not a tty. Will not try with other passwords." ); bye( 0, "Stdin is not a tty. Will not try with other passwords." );
// first we print the question
mutableStdout.muted = false;
rl.question( rl.question(
"Enter another password to try: ", "Enter another password to try: ",
(answer) => { (answer) => {
passphrase = answer; process.stdout.write( "\n" );
mutableStdout.muted = false;
passphrase = answer;
if ( answer == "" ) if ( answer == "" )
bye( 0, "Bye." ); bye( 0, "Bye." );
unlockall(); unlockall();
} }
); );
// Asking the question is an async event, so
// we set the object to mute output while the
// user types his password.
mutableStdout.muted = true;
} }
function bye( exitcode, msg ) function bye( exitcode, msg )
...@@ -31,13 +56,6 @@ function bye( exitcode, msg ) ...@@ -31,13 +56,6 @@ function bye( exitcode, msg )
process.exit( exitcode ); process.exit( exitcode );
} }
function pluralEnglish( num, single, plural )
{
if ( num == 1 )
return single;
return plural;
}
function unlockall() function unlockall()
{ {
var wallets = new Array(); var wallets = new Array();
...@@ -61,7 +79,7 @@ function unlockall() ...@@ -61,7 +79,7 @@ function unlockall()
{ {
var addr = wallets[i].accounts[j].address; var addr = wallets[i].accounts[j].address;
//console.log( "Trying to unlock " + addr + "." ); //console.log( "Trying to unlock " + addr + "." );
var promise = var promise =
web3.eth.personal.unlockAccount( addr, passphrase, 0 ) web3.eth.personal.unlockAccount( addr, passphrase, 0 )
.catch( .catch(
error => error =>
...@@ -79,7 +97,7 @@ function unlockall() ...@@ -79,7 +97,7 @@ function unlockall()
console.log( console.log(
"Attempting to unlock " "Attempting to unlock "
+ promises.length + promises.length
+ " account" + pluralEnglish(promises.length,"","s") + " account" + ( promises.length == 1 ? '' : 's' )
+ empty + "." + empty + "."
); );
Promise.all( promises ) Promise.all( promises )
...@@ -88,7 +106,7 @@ function unlockall() ...@@ -88,7 +106,7 @@ function unlockall()
{ {
if ( failures == 0 ) if ( failures == 0 )
bye( 0, "OK." ); bye( 0, "OK." );
console.log( failures + " account" + pluralEnglish(failures," is","s are") + " still locked." ); console.log( failures + " account" + (failures==1 ? " is" : "s are") + " still locked." );
atLeastOneFailedSoGetNewPass(); atLeastOneFailedSoGetNewPass();
}, },
function(x) function(x)
...@@ -105,11 +123,4 @@ function unlockall() ...@@ -105,11 +123,4 @@ function unlockall()
) )
} }
web3.eth .personal.extend({
methods: [{
name: 'bfalistWallets',
call: 'personal_listWallets',
params: 0
}]
});
unlockall(); unlockall();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment