Skip to content

Instantly share code, notes, and snippets.

@mx0c
Created June 8, 2019 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mx0c/3e8c0996a1655786f54b37af1ba1bd3c to your computer and use it in GitHub Desktop.
Save mx0c/3e8c0996a1655786f54b37af1ba1bd3c to your computer and use it in GitHub Desktop.
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