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

Commit

Permalink
Merge remote-tracking branch 'origin/main' into export-key
Browse files Browse the repository at this point in the history
* origin/main:
  Set password sooner to avoid redundant persistance (#154)
  Ensure newly created vaults are unlocked (#155)
  • Loading branch information
Gudahtt committed Nov 7, 2022
2 parents 37af169 + 5c0ef4c commit 4021e0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 1 addition & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class KeyringController extends EventEmitter {
this.password = password;

await this.createFirstKeyTree();
await this.persistAllKeyrings();
this.setUnlocked();
this.fullUpdate();
}
Expand Down Expand Up @@ -127,7 +126,6 @@ class KeyringController extends EventEmitter {
this.password = password;

this.clearKeyrings();

const firstKeyring = await this.addNewKeyring(
KEYRINGS_TYPE_MAP.HD_KEYRING,
{
Expand All @@ -139,8 +137,6 @@ class KeyringController extends EventEmitter {
if (!firstAccount) {
throw new Error('KeyringController - First Account not found.');
}

await this.persistAllKeyrings();
this.setUnlocked();
return this.fullUpdate();
}
Expand Down Expand Up @@ -515,7 +511,6 @@ class KeyringController extends EventEmitter {
* - Faucets that account on testnet
* - Puts the current seed words into the state tree
*
* @param {string} password - The keyring controller password.
* @returns {Promise<void>} - A promise that resolves if the operation was successful.
*/
async createFirstKeyTree() {
Expand Down Expand Up @@ -847,7 +842,7 @@ class KeyringController extends EventEmitter {
forgetKeyring(keyring) {
if (keyring.forgetDevice) {
keyring.forgetDevice();
this.persistAllKeyrings.bind(this)();
this.persistAllKeyrings();
this._updateMemStoreKeyrings.bind(this)();
} else {
throw new Error(
Expand Down
11 changes: 10 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('KeyringController', function () {
});

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

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

it('should unlock the vault', async function () {
keyringController.store.updateState({ vault: null });
assert(!keyringController.store.getState().vault, 'no previous vault');

await keyringController.createNewVaultAndKeychain(password);
const { isUnlocked } = keyringController.memStore.getState();
expect(isUnlocked).toBe(true);
});

it('should encrypt keyrings with the correct password each time they are persisted', async function () {
keyringController.store.updateState({ vault: null });
assert(!keyringController.store.getState().vault, 'no previous vault');
Expand Down

0 comments on commit 4021e0c

Please sign in to comment.