Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
hideEchoBack: true // The typed text on screen is hidden by `*` (default).
});
try {
return web3.eth.accounts.decrypt(keyStore, password);
} catch (error) {
console.log(chalk.red('Could not decrypt your key store. Probably your password is wrong, please try again.'));
return getAccount(filePath);
}
} else {
let privKey = readlineSync.question('Enter your private key to generate your key store file: ', {
hideEchoBack: true // The typed text on screen is hidden by `*` (default).
});
if (privKey.substr(0, 2) !== '0x') {
privKey = '0x' + privKey;
}
const password = readlineSync.questionNewPassword(
'Enter a password to encrypt your private key: ',
{ confirmMessage: 'Enter the same password to confirm: ', min: 6 }
);
const keyStore = web3.eth.accounts.encrypt(privKey, password);
fs.writeFileSync(filePath, JSON.stringify(keyStore));
return getAccount(filePath);
}
}