Last active
July 6, 2019 01:47
-
-
Save makevoid/84ce2891a0f3a60174fbb24f892f3af3 to your computer and use it in GitHub Desktop.
ethereum-wallet-old-implementation.js
This file contains hidden or 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 bip39 = require("bip39") | |
| const hdkey = require('ethereumjs-wallet/hdkey') | |
| const web3 = require("web3") | |
| const mnemonic = "---> set your 12 words mnemonic <---" | |
| // derive key | |
| const seed = bip39.mnemonicToSeedSync(mnemonic) | |
| const hdwallet = hdkey.fromMasterSeed(seed) | |
| // chose your coin (0 - btc | |
| // to learn more about HD key derivation paths google it :D | |
| const hdpath = "m/44'/0'/0'/0" // btc. | |
| //const hdpath = "m/44'/60'/0'/0" // eth. | |
| //const hdpath = "m/44'/700'/0'/0" // xdai. | |
| const index = 0 | |
| const path = `${wallet_hdpath}/${index}` | |
| // console.log("deriv. path:", path) | |
| const wallet = hdwallet.derivePath(path).getWallet() | |
| const address = '0x' + wallet.getAddress().toString("hex") | |
| const privateKey = wallet.getPrivateKey().toString("hex") | |
| accounts.push({ address: address, privateKey: privateKey }) | |
| console.log("address:", address) | |
| // extra - mnemonic storage | |
| // const c = console | |
| // let mnemonic, mnemonicString | |
| // const store = localStorage | |
| // | |
| // let store | |
| // if (typeof localStorage !== "undefined") { | |
| // store = localStorage | |
| // } else { | |
| // store = {} | |
| // console.error("Warning: localStorage is not defined") | |
| // } | |
| // | |
| // 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 | |
| // } | |
| // } | |
| // BIP 39 version - the current version of github.com/makevoid/ethereum-keychain is based off this code | |
| // | |
| // let bip39 = require("bip39") | |
| // let hdkey = require('ethereumjs-wallet/hdkey') | |
| // let hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(seed)) // except here I switched to bitcoinjs-lib | |
| // let wallet_hdpath = "m/44'/60'/0'/0" | |
| // | |
| // | |
| // const keypairHD = new EthereumBIP44(mnemonic.toHDPrivateKey()) | |
| // const address = keypairHD.getAddress(0) | |
| // const privateKey = keypairHD.getPrivateKey(0) | |
| // privateKey = privateKey.toString('hex') | |
| // | |
| // c.log("mnemonic:", mnemonicString) | |
| // c.log("address:", address) | |
| // c.log("privateKey:", privateKey) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment