diff --git a/lib/commands/create-keys.js b/lib/commands/create-keys.js index ef68b2f..38987cc 100644 --- a/lib/commands/create-keys.js +++ b/lib/commands/create-keys.js @@ -19,20 +19,17 @@ module.exports.handler = (argv) => { // TODO: validate user backed up mnemonic const seed = bip39.mnemonicToSeedSync(mnemonic); - console.log("Seed: ", seed.toString('hex')) const node = bip32.fromSeed(seed); - console.log("xpriv: ", node.toBase58()); // TODO: Get user key password const password = "vanished"; // TODO: Encrypt text securely... const encryptedPrivateKey = cryptoUtil.encrypt(node.toBase58(), password); - console.log("Encrypted Private Key: ", encryptedPrivateKey); - // Check if a key exist... db.Key.create({ - encryptedPrivateKey: encryptedPrivateKey, + encryptedPrivateKey: encryptedPrivateKey.cipherText, + iv: encryptedPrivateKey.iv, name: "FirstKey" }).then(key => { console.log("Successfully created: ", key.name) diff --git a/lib/commands/random-xpub.js b/lib/commands/random-xpub.js index 21f0be9..7d593a3 100644 --- a/lib/commands/random-xpub.js +++ b/lib/commands/random-xpub.js @@ -22,19 +22,14 @@ module.exports.handler = (argv) => { // TODO: Load password from config... if(key) { const password = "vanished"; - - console.log("Encrypted: ", key.encryptedPrivateKey); - - const decryptedPrivateKey = cryptoUtil.decrypt(key.encryptedPrivateKey, password); - console.log("Decrypted: ", decryptedPrivateKey); - const masterNode = bip32.fromBase58(decryptedPrivateKey); + const iv = key.iv; - console.log("Node: ", masterNode.toBase58()); + const decryptedPrivateKey = cryptoUtil.decrypt(key.encryptedPrivateKey, password, iv); + const masterNode = bip32.fromBase58(decryptedPrivateKey); const derivationPath = `m/${cryptoUtil.randomDerivationPath(true)}` const xpubNode = masterNode.derivePath(derivationPath); - console.log("Xpub: ", xpubNode.neutered().toBase58()); // TODO save xpub and derivation path in db... return db.ExtendedPublicKey.create({