Browse Source

Simplify internal generateKey API

master
Luke Childs 5 years ago
parent
commit
f15dc93f91
  1. 2
      src/index.js
  2. 4
      src/key-formats/bip39.js
  3. 6
      src/key-formats/xpub.js

2
src/index.js

@ -60,7 +60,7 @@ class Vain extends Emitter {
attempts++; attempts++;
keyData = generateKey({addressFormat, options, attempts}); keyData = generateKey({...options, addressFormat, attempts});
address = addressFormat.derive(keyData.publicKey); address = addressFormat.derive(keyData.publicKey);
if (address.startsWith(this.prefix)) { if (address.startsWith(this.prefix)) {

4
src/key-formats/bip39.js

@ -1,8 +1,8 @@
const bip39 = require('bip39'); const bip39 = require('bip39');
const bitcoin = require('bitcoinjs-lib'); const bitcoin = require('bitcoinjs-lib');
const generatebip39Key = ({addressFormat, options}) => { const generatebip39Key = ({addressFormat, entropy}) => {
const mnemonic = bip39.generateMnemonic(options.entropy); const mnemonic = bip39.generateMnemonic(entropy);
const seed = bip39.mnemonicToSeedSync(mnemonic); const seed = bip39.mnemonicToSeedSync(mnemonic);
const node = bitcoin.bip32.fromSeed(seed); const node = bitcoin.bip32.fromSeed(seed);

6
src/key-formats/xpub.js

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

Loading…
Cancel
Save