Browse Source

Return formatting function as part of key generation

master
Luke Childs 6 years ago
parent
commit
89afb8c5e7
  1. 6
      src/index.js
  2. 11
      src/wif.js

6
src/index.js

@ -15,7 +15,7 @@ const addressFormats = new Map(Object.entries({
class Vain extends Emitter { class Vain extends Emitter {
constructor({keyFormat = 'wif', addressFormat = 'p2pkh', prefix}) { constructor({keyFormat = 'wif', addressFormat = 'p2pkh', prefix}) {
super(); super();
this.keyFormat = keyFormats.get(keyFormat); this.generateKey = keyFormats.get(keyFormat);
this.addressFormat = addressFormats.get(addressFormat); this.addressFormat = addressFormats.get(addressFormat);
if (typeof prefix !== 'string' || prefix.length === 0) { if (typeof prefix !== 'string' || prefix.length === 0) {
@ -44,7 +44,7 @@ class Vain extends Emitter {
while (!found) { while (!found) {
attempts++; attempts++;
keyData = this.keyFormat.generate(); keyData = this.generateKey();
address = this.addressFormat.derive(keyData.publicKey); address = this.addressFormat.derive(keyData.publicKey);
if (address.startsWith(this.prefix)) { if (address.startsWith(this.prefix)) {
@ -72,7 +72,7 @@ class Vain extends Emitter {
duration, duration,
addressesPerSecond, addressesPerSecond,
address, address,
...this.keyFormat.format(keyData) ...keyData.format()
}; };
this.emit('found', result); this.emit('found', result);
resolve(result); resolve(result);

11
src/wif.js

@ -1,9 +1,14 @@
const bitcoin = require('bitcoinjs-lib'); 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; module.exports = wif;

Loading…
Cancel
Save