Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 90f9d73

Browse files
Add wallet.restoreWallet, giving lnd the seed and password to restore.
1 parent f01ded5 commit 90f9d73

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/action/wallet.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,20 @@ class WalletAction {
235235
await this.unlockWallet({ walletPassword: password });
236236
}
237237

238+
/**
239+
* Initialize the wallet with the password input the seed that was already
240+
* inputted, and the default recovery window.
241+
* @return {Promise<undefined>}
242+
*/
243+
async restoreWallet() {
244+
const { password, restoreSeed } = this._store.wallet;
245+
await this.initWallet({
246+
walletPassword: password,
247+
seedMnemonic: restoreSeed.toJSON(),
248+
recoveryWindow: RECOVERY_WINDOW,
249+
});
250+
}
251+
238252
/**
239253
* Unlock the wallet by calling the grpc api with the user chosen password.
240254
* @param {string} options.walletPassword The password used to encrypt the wallet

test/unit/action/wallet.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import NotificationAction from '../../../src/action/notification';
77
import * as logger from '../../../src/action/log';
88
import nock from 'nock';
99
import 'isomorphic-fetch';
10+
import { RECOVERY_WINDOW } from '../../../src/config';
1011

1112
describe('Action Wallet Unit Tests', () => {
1213
let store;
@@ -275,6 +276,24 @@ describe('Action Wallet Unit Tests', () => {
275276
});
276277
});
277278

279+
describe('restoreWallet()', () => {
280+
beforeEach(() => {
281+
sandbox.stub(wallet, 'initWallet');
282+
});
283+
284+
it('calls initWallet with password and restoreSeed', async () => {
285+
wallet.setPassword({ password: 'secret123' });
286+
const seed = Array(24).fill('foo');
287+
store.wallet.restoreSeed = seed;
288+
await wallet.restoreWallet();
289+
expect(wallet.initWallet, 'was called with', {
290+
walletPassword: 'secret123',
291+
seedMnemonic: seed,
292+
recoveryWindow: RECOVERY_WINDOW,
293+
});
294+
});
295+
});
296+
278297
describe('unlockWallet()', () => {
279298
it('should unlock wallet', async () => {
280299
grpc.sendUnlockerCommand.withArgs('UnlockWallet').resolves();

0 commit comments

Comments
 (0)