Skip to content

Commit

Permalink
Add xpub vanity seed key format
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed Jun 18, 2019
1 parent deff42e commit e4c9c08
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/index.js
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)) {
Expand Down
19 changes: 19 additions & 0 deletions 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;

0 comments on commit e4c9c08

Please sign in to comment.