diff --git a/lib/cmds/blockchain/blockchain.js b/lib/cmds/blockchain/blockchain.js index 56b43b5a..5598e91d 100644 --- a/lib/cmds/blockchain/blockchain.js +++ b/lib/cmds/blockchain/blockchain.js @@ -125,6 +125,7 @@ Blockchain.prototype.initChainAndGetAddress = function() { }; var BlockchainClient = function(blockchainConfig, client, env, isDev) { + // TODO add other clients at some point if (client === 'geth') { return new Blockchain({blockchainConfig, client: GethCommands, env, isDev}); } else { diff --git a/lib/contracts/accountParser.js b/lib/contracts/accountParser.js index f2f56f8d..e2460bd6 100644 --- a/lib/contracts/accountParser.js +++ b/lib/contracts/accountParser.js @@ -29,15 +29,23 @@ class AccountParser { if (!accountConfig.privateKey.startsWith('0x')) { accountConfig.privateKey = '0x' + accountConfig.privateKey; } + if (!web3.utils.isHexStrict(accountConfig.privateKey)) { + logger.warn(`Private key ending with ${accountConfig.privateKey.substr(accountConfig.privateKey.length - 5)} is not a HEX string`); + return null; + } return web3.eth.accounts.privateKeyToAccount(accountConfig.privateKey); } if (accountConfig.privateKeyFile) { let fileContent = fs.readFileSync(fs.dappPath(accountConfig.privateKeyFile)).toString(); fileContent = fileContent.trim().split(/[,;]/); - return fileContent.map(key => { + return fileContent.map((key, index) => { if (!key.startsWith('0x')) { key = '0x' + key; } + if (!web3.utils.isHexStrict(key)) { + logger.warn(`Private key is not a HEX string in file ${accountConfig.privateKeyFile} at index ${index}`); + return null; + } return web3.eth.accounts.privateKeyToAccount(key); }); }