Skip to content

Instantly share code, notes, and snippets.

@nakov
Created April 11, 2018 10:01
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 nakov/095fecc5ba4061cd55d037097c9eb4a0 to your computer and use it in GitHub Desktop.
Save nakov/095fecc5ba4061cd55d037097c9eb4a0 to your computer and use it in GitHub Desktop.
Encrypt / Decrypt Mnemonic words as JSON
(async function() {
let defaultDerivePath = "m/44'/60'/0'/0/0";
let hdnode = require('ethers/wallet/hdnode');
let ss = require('ethers/wallet/secret-storage');
//let words = 'verb position snow palace gift limb citizen alpha stay sphere swear proof';
let words = 'tiger guilt skill adjust worry rival roof bicycle raven mail cherry strong body afford again praise upper wolf dry joke web bargain sea hint';
let entropy = hdnode.mnemonicToEntropy(words);
privKey = hdnode.fromMnemonic(words).derivePath(defaultDerivePath).privateKey;
console.log("Entropy:", entropy);
console.log("Private key:", privKey);
console.log();
let options = {entropy: entropy};
let json = await ss.encrypt(privKey, 'pass123', options);
console.log("JSON:", json);
console.log();
let decrypted = await ss.decrypt(json, 'pass123');
console.log(decrypted);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment