-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbtc.js
More file actions
28 lines (25 loc) · 918 Bytes
/
btc.js
File metadata and controls
28 lines (25 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const bip39 = require('bip39')
const bitcoinjs = require('bitcoinjs-lib')
async function revealAddress (words, offset, hdPath) {
try {
const seed = bip39.mnemonicToSeedSync(words)
const master = bitcoinjs.bip32.fromSeed(seed,bitcoinjs.networks.bitcoin)
const result = []
for (let i = 0; i < offset; i++) {
const childkey = master.derivePath(`${hdPath}/${i}`)
const pub = childkey.publicKey.toString('hex')
const pri = childkey.toWIF()
const add = bitcoinjs.payments.p2pkh({ pubkey: childkey.publicKey, network: bitcoinjs.networks.bitcoin })
result.push({
index: i,
address: add.address,
publicKey: pub,
privateKey: pri
})
}
return result
} catch (error) {
throw error
}
}
module.exports = revealAddress