Created
April 11, 2018 10:01
-
-
Save nakov/095fecc5ba4061cd55d037097c9eb4a0 to your computer and use it in GitHub Desktop.
Encrypt / Decrypt Mnemonic words as JSON
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
(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