diff --git a/src/index.js b/src/index.js index 7a7997b..ed02b7b 100644 --- a/src/index.js +++ b/src/index.js @@ -15,7 +15,7 @@ const addressFormats = new Map(Object.entries({ class Vain extends Emitter { constructor({keyFormat = 'wif', addressFormat = 'p2pkh', prefix}) { super(); - this.keyFormat = keyFormats.get(keyFormat); + this.generateKey = keyFormats.get(keyFormat); this.addressFormat = addressFormats.get(addressFormat); if (typeof prefix !== 'string' || prefix.length === 0) { @@ -44,7 +44,7 @@ class Vain extends Emitter { while (!found) { attempts++; - keyData = this.keyFormat.generate(); + keyData = this.generateKey(); address = this.addressFormat.derive(keyData.publicKey); if (address.startsWith(this.prefix)) { @@ -72,7 +72,7 @@ class Vain extends Emitter { duration, addressesPerSecond, address, - ...this.keyFormat.format(keyData) + ...keyData.format() }; this.emit('found', result); resolve(result); diff --git a/src/wif.js b/src/wif.js index eb97387..e19d596 100644 --- a/src/wif.js +++ b/src/wif.js @@ -1,9 +1,14 @@ const bitcoin = require('bitcoinjs-lib'); -const wif = {}; +const wif = () => { + const keyPair = bitcoin.ECPair.makeRandom(); + const {publicKey} = keyPair; -wif.generate = bitcoin.ECPair.makeRandom; + const format = () => ({ + wif: keyPair.toWIF() + }); -wif.format = keyPair => ({wif: keyPair.toWIF()}); + return {publicKey, format}; +}; module.exports = wif;