From 412f636d6cee2fb44d6a90a9a0f461a9899ba35c Mon Sep 17 00:00:00 2001 From: Anton Bukov Date: Sat, 8 Sep 2018 18:06:23 +0300 Subject: [PATCH] Add deployer feature --- index.js | 11 ++++++++--- libs/VanityEth.js | 17 ++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 8ec2b6d..0ba5464 100755 --- a/index.js +++ b/index.js @@ -6,8 +6,9 @@ var cluster = require('cluster') var numCPUs = require('os').cpus().length var argv = require('yargs') .usage('Usage: $0 [options]') - .example('$0 -checksum -i B00B5', 'get a wallet where address matches B00B5 in checksum format') + .example('$0 --checksum -i B00B5', 'get a wallet where address matches B00B5 in checksum format') .example('$0 --contract -i ABC', 'get a wallet where 0 nonce contract address matches the vanity') + .example('$0 --deployer -i ABC', 'get a wallet where 0 nonce contract of 0 nonce contract address matches the vanity') .example('$0 -n 25 -i ABC', 'get 25 vanity wallets') .example('$0 -n 1000', 'get 1000 random wallets') .alias('i', 'input') @@ -21,6 +22,8 @@ var argv = require('yargs') .describe('n', 'number of wallets') .boolean('contract') .describe('contract', 'contract address for contract deployment') + .boolean('deployer') + .describe('deployer', 'contract address for contract deployment') .alias('l', 'log') .boolean('l') .describe('l', 'log output to file') @@ -34,6 +37,7 @@ if (cluster.isMaster) { isChecksum: argv.checksum ? true : false, numWallets: argv.count ? argv.count : 1, isContract: argv.contract ? true : false, + isDeployer: argv.deployer ? true : false, log: argv.log ? true : false, logFname: argv.log ? 'VanityEth-log-' + Date.now() + '.txt' : '' } @@ -52,7 +56,8 @@ if (cluster.isMaster) { const worker_env = { input: args.input, isChecksum: args.isChecksum, - isContract: args.isContract + isContract: args.isContract, + isDeployer: args.isDeployer } proc = cluster.fork(worker_env); proc.on('message', function(message) { @@ -70,7 +75,7 @@ if (cluster.isMaster) { } else { const worker_env = process.env; while (true) { - process.send(VanityEth.getVanityWallet(worker_env.input, worker_env.isChecksum == 'true', worker_env.isContract == 'true')) + process.send(VanityEth.getVanityWallet(worker_env.input, worker_env.isChecksum == 'true', worker_env.isContract == 'true', worker_env.isDeployer == 'true')) } } process.stdin.resume(); diff --git a/libs/VanityEth.js b/libs/VanityEth.js index a33653a..caba3a5 100644 --- a/libs/VanityEth.js +++ b/libs/VanityEth.js @@ -14,8 +14,15 @@ var isValidHex = function(hex) { var re = /^[0-9A-F]+$/g; return re.test(hex); } -var isValidVanityWallet = function(wallet, input, isChecksum, isContract) { +var isValidVanityWallet = function(wallet, input, isChecksum, isContract, isDeployer) { var _add = wallet.address; + if (isDeployer) { + var _deployerAdd = getDeterministicContractAddress(_add); + var _contractAdd = getDeterministicContractAddress(_deployerAdd, 1); + _contractAdd = isChecksum ? ethUtils.toChecksumAddress(_contractAdd) : _contractAdd; + wallet.contract = _contractAdd; + return _contractAdd.substr(2, input.length) == input + } if (isContract) { var _contractAdd = getDeterministicContractAddress(_add); _contractAdd = isChecksum ? ethUtils.toChecksumAddress(_contractAdd) : _contractAdd; @@ -25,16 +32,16 @@ var isValidVanityWallet = function(wallet, input, isChecksum, isContract) { _add = isChecksum ? ethUtils.toChecksumAddress(_add) : _add; return _add.substr(2, input.length) == input; } -var getVanityWallet = function(input = '', isChecksum = false, isContract = false) { +var getVanityWallet = function(input = '', isChecksum = false, isContract = false, isDeployer = false) { if (!isValidHex(input)) throw new Error(ERRORS.invalidHex); input = isChecksum ? input : input.toLowerCase(); var _wallet = getRandomWallet(); - while (!isValidVanityWallet(_wallet, input, isChecksum, isContract)) _wallet = getRandomWallet(isChecksum); + while (!isValidVanityWallet(_wallet, input, isChecksum, isContract, isDeployer)) _wallet = getRandomWallet(isChecksum); if (isChecksum) _wallet.address = ethUtils.toChecksumAddress(_wallet.address); return _wallet; } -var getDeterministicContractAddress = function(address) { - return '0x' + ethUtils.sha3(ethUtils.rlp.encode([address, 0])).slice(12).toString('hex'); +var getDeterministicContractAddress = function(address, nonce = 0) { + return '0x' + ethUtils.sha3(ethUtils.rlp.encode([address, nonce])).slice(12).toString('hex'); } module.exports = { getVanityWallet: getVanityWallet,