Created
October 21, 2016 14:33
-
-
Save makevoid/91887247021641fd7192da6a845d584b to your computer and use it in GitHub Desktop.
ethereum mnemonic
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
"use strict" | |
const Mnemonic = require('bitcore-mnemonic') | |
const EthereumBIP44 = require('ethereum-bip44/dist/es5') | |
const c = console | |
let mnemonic | |
let mnemonicString | |
let store | |
if (typeof localStorage !== "undefined") { | |
store = localStorage | |
} | |
if (store && store.mnemonic) { | |
mnemonicString = store.mnemonic | |
mnemonic = new Mnemonic(store.mnemonic) | |
} else { | |
mnemonic = new Mnemonic() | |
mnemonicString = mnemonic.phrase.toString() | |
if (store) { | |
store.mnemonic = mnemonicString | |
} | |
} | |
let keypairHD = new EthereumBIP44(mnemonic.toHDPrivateKey()) | |
let address = keypairHD.getAddress(0) | |
let privateKey = keypairHD.getPrivateKey(0) | |
privateKey = privateKey.toString('hex') | |
c.log("mnemonic:", mnemonicString) | |
c.log("address:", address) | |
c.log("privateKey:", privateKey) | |
if (typeof window !== "undefined" && window) { | |
window.address = address | |
window.privateKey = privateKey | |
window.mnemonicString = mnemonicString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment