-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (28 loc) · 869 Bytes
/
index.js
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
29
30
31
32
33
34
35
const bip39 = require('bip39')
const hdkey = require('hdkey')
const bip44Constants = require('bip44-constants')
function getCoinType(blockchain) {
return bip44Constants[blockchain] - 0x80000000
}
function getKey(root, coinType) {
const addrNode = root.derive(`m/44'/${coinType}'/0'/0/0`)
return addrNode._privateKey.toString('hex')
}
function printPrivateKeys(_mnemonic = null) {
const mnemonic = _mnemonic || bip39.generateMnemonic()
if (!bip39.validateMnemonic(mnemonic)) {
throw new Error('Invalid mnemonic!')
}
const seed = bip39.mnemonicToSeed(mnemonic)
const root = hdkey.fromMasterSeed(seed)
const ethKey = getKey(root, getCoinType('ETH'))
const neoKey = getKey(root, getCoinType('NEO'))
const res = {
ETH: ethKey,
NEO: neoKey,
mnemonic,
}
console.info(res)
return null
}
printPrivateKeys(process.env.MNEMONIC)