Created
December 10, 2018 16:19
-
-
Save kennethhutw/2f64fd66ffacfda3d649bd17578bd4a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const EthWallet = require('ethereumjs-wallet') | |
const HDKey = require('ethereumjs-wallet/hdkey') | |
const bip39 = require('bip39') | |
// Generate mnemonic and seed | |
const mnemonic = bip39.generateMnemonic() | |
const seed = bip39.mnemonicToSeed(mnemonic) | |
console.log(`generated mnemonic:\n\t${mnemonic}\n`) | |
// Wallet from seed and get the public Extended key | |
const walletPriv = HDKey.fromMasterSeed(seed) | |
const pubExtKey = walletPriv.publicExtendedKey() | |
console.log(`public key:\n\t${pubExtKey}`) | |
// Wallet from public Extended key and derive children | |
const walletPub = HDKey.fromExtendedKey(pubExtKey) | |
console.log(`\nchild keys from extended public:\n`) | |
for (var idx = 0; idx < 10; idx++) { | |
console.log( | |
'\t' + | |
walletPub | |
.deriveChild(idx) | |
.getWallet() | |
.getAddressString() | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment