Browse Source

Simplify internal generateKey API

master
Luke Childs 6 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++;
keyData = generateKey({addressFormat, options, attempts});
keyData = generateKey({...options, addressFormat, attempts});
address = addressFormat.derive(keyData.publicKey);
if (address.startsWith(this.prefix)) {

4
src/key-formats/bip39.js

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

6
src/key-formats/xpub.js

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

Loading…
Cancel
Save