mirror of https://github.com/lukechilds/vainjs.git
4 changed files with 111 additions and 76 deletions
@ -1,26 +1,28 @@ |
|||
const Vain = require('..'); |
|||
const prettyMs = require('pretty-ms'); |
|||
|
|||
const prefix = 'BTC'; |
|||
console.log(); |
|||
console.log(`Searching for the prefix "${prefix}"...`); |
|||
['p2pkh', 'p2wpkh-p2sh'].forEach(addressFormat => { |
|||
const prefix = 'BTC'; |
|||
console.log(); |
|||
console.log(`Searching for the prefix "${prefix}" for addres format "${addressFormat}"...`); |
|||
|
|||
const vain = new Vain({prefix}); |
|||
const vain = new Vain({prefix, addressFormat}); |
|||
|
|||
vain.on('update', data => { |
|||
const duration = prettyMs(data.duration); |
|||
const {attempts} = data; |
|||
const speed = `${data.addressesPerSecond} addr/s`; |
|||
console.log(`Duration: ${duration} | Attempts: ${attempts} | Speed: ${speed}`); |
|||
}); |
|||
vain.on('update', data => { |
|||
const duration = prettyMs(data.duration); |
|||
const {attempts} = data; |
|||
const speed = `${data.addressesPerSecond} addr/s`; |
|||
console.log(`Duration: ${duration} | Attempts: ${attempts} | Speed: ${speed}`); |
|||
}); |
|||
|
|||
vain.on('found', data => { |
|||
console.log(); |
|||
console.log(`Address: ${data.address}`); |
|||
console.log(`WIF: ${data.wif}`); |
|||
console.log(); |
|||
console.log(`Found in ${prettyMs(data.duration)}`); |
|||
console.log(`Speed: ${data.addressesPerSecond} addr/s`); |
|||
}); |
|||
vain.on('found', data => { |
|||
console.log(); |
|||
console.log(`Address: ${data.address}`); |
|||
console.log(`WIF: ${data.wif}`); |
|||
console.log(); |
|||
console.log(`Found in ${prettyMs(data.duration)}`); |
|||
console.log(`Speed: ${data.addressesPerSecond} addr/s`); |
|||
}); |
|||
|
|||
vain.start(); |
|||
vain.start(); |
|||
}); |
|||
|
@ -1,56 +1,22 @@ |
|||
const Emitter = require('tiny-emitter'); |
|||
const bitcoin = require('bitcoinjs-lib'); |
|||
|
|||
const ONE_SECOND = 1000; |
|||
|
|||
const p2pkh = prefix => { |
|||
const emitter = new Emitter(); |
|||
|
|||
process.nextTick(() => { |
|||
const startTime = Date.now(); |
|||
|
|||
let found; |
|||
let attempts = 0; |
|||
let keyPair; |
|||
let address; |
|||
let lastUpdate = Date.now(); |
|||
|
|||
while (!found) { |
|||
attempts++; |
|||
keyPair = bitcoin.ECPair.makeRandom(); |
|||
({address} = bitcoin.payments.p2pkh({pubkey: keyPair.publicKey})); |
|||
|
|||
if (address.startsWith(prefix)) { |
|||
found = true; |
|||
} |
|||
|
|||
const now = Date.now(); |
|||
if ((now - lastUpdate) > ONE_SECOND) { |
|||
const duration = now - startTime; |
|||
const addressesPerSecond = Math.floor(attempts / (duration / ONE_SECOND)); |
|||
emitter.emit('update', { |
|||
duration, |
|||
attempts, |
|||
addressesPerSecond |
|||
}); |
|||
lastUpdate = now; |
|||
} |
|||
} |
|||
|
|||
const endTime = Date.now(); |
|||
const duration = endTime - startTime; |
|||
const addressesPerSecond = Math.floor(attempts / (duration / ONE_SECOND)); |
|||
const p2pkh = { |
|||
prefix: '1' |
|||
}; |
|||
|
|||
emitter.emit('found', { |
|||
duration, |
|||
attempts, |
|||
addressesPerSecond, |
|||
address, |
|||
wif: keyPair.toWIF() |
|||
}); |
|||
}); |
|||
p2pkh.derive = () => { |
|||
const keyPair = bitcoin.ECPair.makeRandom(); |
|||
const {address} = bitcoin.payments.p2pkh({pubkey: keyPair.publicKey}); |
|||
|
|||
return emitter; |
|||
return { |
|||
address, |
|||
keyPair |
|||
}; |
|||
}; |
|||
|
|||
p2pkh.format = ({address, keyPair}) => ({ |
|||
address, |
|||
wif: keyPair.toWIF() |
|||
}); |
|||
|
|||
module.exports = p2pkh; |
|||
|
@ -0,0 +1,24 @@ |
|||
const bitcoin = require('bitcoinjs-lib'); |
|||
|
|||
const p2wpkhp2sh = { |
|||
prefix: '3' |
|||
}; |
|||
|
|||
p2wpkhp2sh.derive = () => { |
|||
const keyPair = bitcoin.ECPair.makeRandom(); |
|||
const {address} = bitcoin.payments.p2sh({ |
|||
redeem: bitcoin.payments.p2wpkh({pubkey: keyPair.publicKey}) |
|||
}); |
|||
|
|||
return { |
|||
address, |
|||
keyPair |
|||
}; |
|||
}; |
|||
|
|||
p2wpkhp2sh.format = ({address, keyPair}) => ({ |
|||
address, |
|||
wif: keyPair.toWIF() |
|||
}); |
|||
|
|||
module.exports = p2wpkhp2sh; |
Loading…
Reference in new issue