From 24373876ac9feb802bf7c69ca2c8799ed1046f95 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Wed, 8 May 2019 16:42:18 +0700 Subject: [PATCH] Add basic P2PKH address miner --- package.json | 4 +++- src/index.js | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2189a62..026f78c 100644 --- a/package.json +++ b/package.json @@ -32,5 +32,7 @@ "nyc": "^13.1.0", "xo": "^0.23.0" }, - "dependencies": {} + "dependencies": { + "bitcoinjs-lib": "^5.0.3" + } } diff --git a/src/index.js b/src/index.js index eb38033..f0b46d4 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,39 @@ -const vanity = () => {}; +const bitcoin = require('bitcoinjs-lib'); -module.exports = vanity; +class Vain { + constructor({prefix}) { + this.prefix = `1${prefix}`; + } + + start() { + const startTime = Date.now(); + + let found; + let attempts = 0; + let keyPair; + let address; + + while (!found) { + attempts++; + keyPair = bitcoin.ECPair.makeRandom(); + ({address} = bitcoin.payments.p2pkh({pubkey: keyPair.publicKey})); + + if (address.startsWith(this.prefix)) { + found = true; + } + } + + const endTime = Date.now(); + const duration = endTime - startTime; + const trysPerSecond = Math.floor(attempts / (duration / 1000)); + + return { + duration, + trysPerSecond, + address, + wif: keyPair.toWIF() + }; + } +}; + +module.exports = Vain;