Skip to content

Instantly share code, notes, and snippets.

@makevoid
Created October 21, 2016 14:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makevoid/91887247021641fd7192da6a845d584b to your computer and use it in GitHub Desktop.
Save makevoid/91887247021641fd7192da6a845d584b to your computer and use it in GitHub Desktop.
ethereum mnemonic
"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