Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit 4021e0c

Browse files
committed
Merge remote-tracking branch 'origin/main' into export-key
* origin/main: Set password sooner to avoid redundant persistance (#154) Ensure newly created vaults are unlocked (#155)
2 parents 37af169 + 5c0ef4c commit 4021e0c

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class KeyringController extends EventEmitter {
8787
this.password = password;
8888

8989
await this.createFirstKeyTree();
90-
await this.persistAllKeyrings();
9190
this.setUnlocked();
9291
this.fullUpdate();
9392
}
@@ -127,7 +126,6 @@ class KeyringController extends EventEmitter {
127126
this.password = password;
128127

129128
this.clearKeyrings();
130-
131129
const firstKeyring = await this.addNewKeyring(
132130
KEYRINGS_TYPE_MAP.HD_KEYRING,
133131
{
@@ -139,8 +137,6 @@ class KeyringController extends EventEmitter {
139137
if (!firstAccount) {
140138
throw new Error('KeyringController - First Account not found.');
141139
}
142-
143-
await this.persistAllKeyrings();
144140
this.setUnlocked();
145141
return this.fullUpdate();
146142
}
@@ -515,7 +511,6 @@ class KeyringController extends EventEmitter {
515511
* - Faucets that account on testnet
516512
* - Puts the current seed words into the state tree
517513
*
518-
* @param {string} password - The keyring controller password.
519514
* @returns {Promise<void>} - A promise that resolves if the operation was successful.
520515
*/
521516
async createFirstKeyTree() {
@@ -847,7 +842,7 @@ class KeyringController extends EventEmitter {
847842
forgetKeyring(keyring) {
848843
if (keyring.forgetDevice) {
849844
keyring.forgetDevice();
850-
this.persistAllKeyrings.bind(this)();
845+
this.persistAllKeyrings();
851846
this._updateMemStoreKeyrings.bind(this)();
852847
} else {
853848
throw new Error(

test/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('KeyringController', function () {
9595
});
9696

9797
describe('createNewVaultAndKeychain', function () {
98-
it('should set a vault on the configManager', async function () {
98+
it('should create a new vault', async function () {
9999
keyringController.store.updateState({ vault: null });
100100
assert(!keyringController.store.getState().vault, 'no previous vault');
101101

@@ -105,6 +105,15 @@ describe('KeyringController', function () {
105105
expect(vault).toBeTruthy();
106106
});
107107

108+
it('should unlock the vault', async function () {
109+
keyringController.store.updateState({ vault: null });
110+
assert(!keyringController.store.getState().vault, 'no previous vault');
111+
112+
await keyringController.createNewVaultAndKeychain(password);
113+
const { isUnlocked } = keyringController.memStore.getState();
114+
expect(isUnlocked).toBe(true);
115+
});
116+
108117
it('should encrypt keyrings with the correct password each time they are persisted', async function () {
109118
keyringController.store.updateState({ vault: null });
110119
assert(!keyringController.store.getState().vault, 'no previous vault');

0 commit comments

Comments
 (0)