Browse Source

Add xpub vanity seed key format

master
Luke Childs 5 years ago
parent
commit
e4c9c08325
  1. 5
      src/index.js
  2. 19
      src/key-formats/xpub.js

5
src/index.js

@ -4,7 +4,8 @@ const ONE_SECOND = 1000;
const keyFormats = {
wif: require('./key-formats/wif'),
bip39: require('./key-formats/bip39')
bip39: require('./key-formats/bip39'),
xpub: require('./key-formats/xpub')
};
const addressFormats = {
@ -59,7 +60,7 @@ class Vain extends Emitter {
attempts++;
keyData = generateKey({addressFormat, options});
keyData = generateKey({addressFormat, options, attempts});
address = addressFormat.derive(keyData.publicKey);
if (address.startsWith(this.prefix)) {

19
src/key-formats/xpub.js

@ -0,0 +1,19 @@
const bitcoin = require('bitcoinjs-lib');
const generateXpubKey = ({options, attempts}) => {
const change = 0;
const index = attempts - 1;
const derivationPath = `${change}/${index}`;
const node = bitcoin.bip32.fromBase58(options.xpub);
const {publicKey} = node.derivePath(derivationPath);
const format = () => ({
xpub: options.xpub,
derivationPath
});
return {publicKey, format};
};
module.exports = generateXpubKey;
Loading…
Cancel
Save