mirror of https://github.com/lukechilds/vainjs.git
Luke Childs
6 years ago
7 changed files with 90 additions and 6 deletions
@ -0,0 +1,20 @@ |
|||||
|
const bip39 = require('bip39'); |
||||
|
const bitcoin = require('bitcoinjs-lib'); |
||||
|
|
||||
|
const generatebip39Key = ({addressFormat}) => { |
||||
|
const mnemonic = bip39.generateMnemonic(); |
||||
|
const seed = bip39.mnemonicToSeedSync(mnemonic); |
||||
|
|
||||
|
const node = bitcoin.bip32.fromSeed(seed); |
||||
|
const derivationPath = `m/${addressFormat.bip39}'/0'/0'/0/0`; |
||||
|
const {publicKey} = node.derivePath(derivationPath); |
||||
|
|
||||
|
const format = () => ({ |
||||
|
derivationPath, |
||||
|
mnemonic |
||||
|
}); |
||||
|
|
||||
|
return {publicKey, format}; |
||||
|
}; |
||||
|
|
||||
|
module.exports = generatebip39Key; |
Loading…
Reference in new issue