@metamask-previews/keyring-controller 21.0.4-preview-19ee5ff2 → 21.0.4-preview-5ea27f10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -11,10 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
 
12
12
  - Bump `@metamask/base-controller` from ^8.0.0 to ^8.0.1 ([#5722](https://github.com/MetaMask/core/pull/5722))
13
13
 
14
- ### Fixed
15
-
16
- - The vault encryption upgrade fails grecefully during login ([#5740](https://github.com/MetaMask/core/pull/5740))
17
-
18
14
  ## [21.0.4]
19
15
 
20
16
  ### Fixed
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_keyringsMetadata, _KeyringController_password, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringById, _KeyringController_getKeyringByIdOrDefault, _KeyringController_getKeyringMetadata, _KeyringController_getKeyringBuilderForType, _KeyringController_addQRKeyring, _KeyringController_subscribeToQRKeyringEvents, _KeyringController_unsubscribeFromQRKeyringsEvents, _KeyringController_createNewVaultWithKeyring, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_upgradeVaultEncryptionParams, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_createKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_removeEmptyKeyrings, _KeyringController_assertNoDuplicateAccounts, _KeyringController_setUnlocked, _KeyringController_assertIsUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
39
+ var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_keyringsMetadata, _KeyringController_password, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringById, _KeyringController_getKeyringByIdOrDefault, _KeyringController_getKeyringMetadata, _KeyringController_getKeyringBuilderForType, _KeyringController_addQRKeyring, _KeyringController_subscribeToQRKeyringEvents, _KeyringController_unsubscribeFromQRKeyringsEvents, _KeyringController_createNewVaultWithKeyring, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_createKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_removeEmptyKeyrings, _KeyringController_assertNoDuplicateAccounts, _KeyringController_setUnlocked, _KeyringController_assertIsUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.KeyringController = exports.getDefaultKeyringState = exports.keyringBuilderFactory = exports.SignTypedDataVersion = exports.AccountImportStrategy = exports.isCustodyKeyring = exports.KeyringTypes = void 0;
42
42
  const util_1 = require("@ethereumjs/util");
@@ -874,20 +874,10 @@ class KeyringController extends base_controller_1.BaseController {
874
874
  * @returns Promise resolving when the operation completes.
875
875
  */
876
876
  async submitPassword(password) {
877
- await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
877
+ return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
878
878
  __classPrivateFieldSet(this, _KeyringController_keyrings, await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_unlockKeyrings).call(this, password), "f");
879
879
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setUnlocked).call(this);
880
880
  });
881
- try {
882
- // If there are stronger encryption params available, we
883
- // can attempt to upgrade the vault encryption params.
884
- await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_upgradeVaultEncryptionParams).call(this));
885
- }
886
- catch (error) {
887
- // We don't want to throw an error if the upgrade fails
888
- // since the controller is already unlocked.
889
- console.error('Failed to upgrade vault encryption params:', error);
890
- }
891
881
  }
892
882
  /**
893
883
  * Verifies the that the seed phrase restores the current keychain's accounts.
@@ -1316,7 +1306,7 @@ async function _KeyringController_restoreSerializedKeyrings(serializedKeyrings)
1316
1306
  * @returns A promise resolving to the deserialized keyrings array.
1317
1307
  */
1318
1308
  async function _KeyringController_unlockKeyrings(password, encryptionKey, encryptionSalt) {
1319
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withVaultLock).call(this, async () => {
1309
+ return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withVaultLock).call(this, async ({ releaseLock }) => {
1320
1310
  const encryptedVault = this.state.vault;
1321
1311
  if (!encryptedVault) {
1322
1312
  throw new Error(constants_1.KeyringControllerError.VaultError);
@@ -1375,6 +1365,16 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1375
1365
  state.encryptionSalt = updatedState.encryptionSalt;
1376
1366
  }
1377
1367
  });
1368
+ if (__classPrivateFieldGet(this, _KeyringController_password, "f") &&
1369
+ (!__classPrivateFieldGet(this, _KeyringController_cacheEncryptionKey, "f") || !encryptionKey) &&
1370
+ __classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated &&
1371
+ !__classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated(encryptedVault)) {
1372
+ // The lock needs to be released before persisting the keyrings
1373
+ // to avoid deadlock
1374
+ releaseLock();
1375
+ // Re-encrypt the vault with safer method if one is available
1376
+ await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
1377
+ }
1378
1378
  return __classPrivateFieldGet(this, _KeyringController_keyrings, "f");
1379
1379
  });
1380
1380
  }, _KeyringController_updateVault = function _KeyringController_updateVault() {
@@ -1433,20 +1433,6 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1433
1433
  });
1434
1434
  return true;
1435
1435
  });
1436
- }, _KeyringController_upgradeVaultEncryptionParams =
1437
- /**
1438
- * Upgrade the vault encryption parameters if needed.
1439
- *
1440
- * @returns A promise resolving to `void`.
1441
- */
1442
- async function _KeyringController_upgradeVaultEncryptionParams() {
1443
- const { vault } = this.state;
1444
- if (vault &&
1445
- __classPrivateFieldGet(this, _KeyringController_password, "f") &&
1446
- __classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated &&
1447
- !__classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated(vault)) {
1448
- await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
1449
- }
1450
1436
  }, _KeyringController_getAccountsFromKeyrings =
1451
1437
  /**
1452
1438
  * Retrieves all the accounts from keyrings instances