Created
June 8, 2019 18:44
-
-
Save mx0c/3e8c0996a1655786f54b37af1ba1bd3c 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 EthCrypto = require('eth-crypto'); | |
const bip39 = require('bip39'); | |
const hdkey = require('hdkey'); | |
const ethUtil = require('ethereumjs-util'); | |
async function main(){ | |
const mnemonic = bip39.generateMnemonic(); | |
const root = hdkey.fromMasterSeed(mnemonic); | |
const masterPrivateKey = root.privateKey.toString('hex'); | |
const masterPubKey = root.publicKey.toString('hex'); | |
var path = "m/44'/60'/0'/0/0"; | |
const addrNode = root.derive(path) | |
const pubKey = addrNode.publicKey.toString('hex'); | |
const privateKey = addrNode.privateKey.toString('hex'); | |
const msg = "thisissecret"; | |
const encrypt = await EthCrypto.encryptWithPublicKey(pubKey,msg); | |
const decrypt = await EthCrypto.decryptWithPrivateKey(masterPrivateKey,encrypt); | |
console.log(decrypt); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment