diff --git a/lib/wallet/masterkey.js b/lib/wallet/masterkey.js index d1786e4a1..fde09bd71 100644 --- a/lib/wallet/masterkey.js +++ b/lib/wallet/masterkey.js @@ -656,7 +656,7 @@ class MasterKey { */ toJSON(network, unsafe) { - if (this.encrypted) { + if (!this.key) { return { encrypted: true, until: this.until, diff --git a/test/wallet-http-test.js b/test/wallet-http-test.js index 70fbe8a5e..1b6c3c0e5 100644 --- a/test/wallet-http-test.js +++ b/test/wallet-http-test.js @@ -85,6 +85,31 @@ for (const witnessOpt of witnessOptions) { addr = Address.fromString(str, node.network); }); + it('should enable seed phrase recovery', async () => { + const options = { + passphrase: 'PASSPHRASE', + mnemonic: 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong' + }; + const walletName = `test_seed-${witnessOpt}`; + + const testwallet = await wclient.createWallet(walletName, options); + assert.strictEqual(testwallet.master.encrypted, false); + + const master1 = await wclient.getMaster(walletName); + assert.strictEqual(master1.encrypted, false); + assert.strictEqual(master1.mnemonic.phrase, options.mnemonic); + + await wclient.lock(walletName); + const master2 = await wclient.getMaster(walletName); + assert.strictEqual(master2.encrypted, true); + assert.strictEqual(master2.mnemonic, undefined); + + await wclient.unlock(walletName, 'PASSPHRASE', 100); + const master3 = await wclient.getMaster(walletName); + assert.strictEqual(master3.encrypted, false); + assert.strictEqual(master3.mnemonic.phrase, options.mnemonic); + }); + it('should fill with funds', async () => { const mtx = new MTX(); mtx.addOutpoint(new Outpoint(consensus.ZERO_HASH, 0));