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
const Libbfa = require( process.env.BFAHOME + '/bin/libbfa.js');
const bfa = new Libbfa();
const rl = require('readline').createInterface(
{ input: process.stdin, output: process.stdout }
);
var web3 = bfa.newweb3();
const Libbfa = require( process.env.BFAHOME + '/bin/libbfa.js');
const bfa = new Libbfa();
const Writable = require('stream').Writable;
var mutableStdout = new Writable(
{
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.
// Do not edit.
var passphrase = "";
function atLeastOneFailedSoGetNewPass(x)
{
if ( !process.stdin.isTTY )
bye( 0, "Stdin is not a tty. Will not try with other passwords." );
// first we print the question
mutableStdout.muted = false;
rl.question(
"Enter another password to try: ",
(answer) => {
passphrase = answer;
process.stdout.write( "\n" );
mutableStdout.muted = false;
passphrase = answer;
if ( answer == "" )
bye( 0, "Bye." );
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 )
......@@ -31,13 +56,6 @@ function bye( exitcode, msg )
process.exit( exitcode );
}
function pluralEnglish( num, single, plural )
{
if ( num == 1 )
return single;
return plural;
}
function unlockall()
{
var wallets = new Array();
......@@ -61,7 +79,7 @@ function unlockall()
{
var addr = wallets[i].accounts[j].address;
//console.log( "Trying to unlock " + addr + "." );
var promise =
var promise =
web3.eth.personal.unlockAccount( addr, passphrase, 0 )
.catch(
error =>
......@@ -79,7 +97,7 @@ function unlockall()
console.log(
"Attempting to unlock "
+ promises.length
+ " account" + pluralEnglish(promises.length,"","s")
+ " account" + ( promises.length == 1 ? '' : 's' )
+ empty + "."
);
Promise.all( promises )
......@@ -88,7 +106,7 @@ function unlockall()
{
if ( failures == 0 )
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();
},
function(x)
......@@ -105,11 +123,4 @@ function unlockall()
)
}
web3.eth .personal.extend({
methods: [{
name: 'bfalistWallets',
call: 'personal_listWallets',
params: 0
}]
});
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