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

Changes to allow us to unlock locked keys

parent 526ad7f5
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();
// First time we try to unlock, we will use this empty passphrase.
var passphrase = "";
function atLeastOneFailedSoGetNewPass(x)
{
if ( !process.stdin.isTTY )
bye( 0, "Stdin is not a tty. Will not try with other passwords." );
rl.question(
"Enter another password to try: ",
(answer) => {
passphrase = answer;
if ( answer == "" )
bye( 0, "Bye." );
unlockall();
}
);
}
function bye( exitcode, msg )
{
console.log( msg );
rl.close();
process.exit( exitcode );
}
function pluralEnglish( num, single, plural )
{
if ( num == 1 )
return single;
return plural;
}
function unlockall()
{
var wallets = new Array();
web3.eth.personal.bfalistWallets()
.then(
function pushone(x)
{
var failures = 0;
var promises = new Array();
var i = x.length;
while ( i-- > 0 )
if ( x[i].status == "Locked" )
wallets.push( x[i] );
i = wallets.length;
if ( i == 0 )
bye( 0, "List of accounts to unlock is empty." );
while ( i-- > 0 )
{
var j = wallets[i].accounts.length;
while ( j-- > 0 )
{
var addr = wallets[i].accounts[j].address;
//console.log( "Trying to unlock " + addr + "." );
var promise =
web3.eth.personal.unlockAccount( addr, passphrase, 0 )
.catch(
error =>
{
failures++;
return error;
}
);
promises.push( promise );
}
}
var empty = "";
if ( passphrase == "" )
empty = " with an empty passphrase";
console.log(
"Attempting to unlock "
+ promises.length
+ " account" + pluralEnglish(promises.length,"","s")
+ empty + "."
);
Promise.all( promises )
.then(
function(x)
{
if ( failures == 0 )
bye( 0, "OK." );
console.log( failures + " account" + pluralEnglish(failures," is","s are") + " still locked." );
atLeastOneFailedSoGetNewPass();
},
function(x)
{
console.log( x );
bye( 1, "I can't imagine this text will ever be shown." );
}
);
},
function errWalletList(x)
{
bye( 1, x );
}
)
}
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