@metamask-previews/keyring-controller 21.0.1-preview-7f6d1f4 → 21.0.1-preview-c7dcfd5a

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
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Fixed
11
+
12
+ - The cached encryption key is ignored when the vault needs to upgrade its encryption parameters ([#5601](https://github.com/MetaMask/core/pull/5601))
13
+
10
14
  ## [21.0.1]
11
15
 
12
16
  ### Fixed
@@ -1377,7 +1377,14 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1377
1377
  });
1378
1378
  }, _KeyringController_updateVault = function _KeyringController_updateVault() {
1379
1379
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withVaultLock).call(this, async () => {
1380
- const { encryptionKey, encryptionSalt } = this.state;
1380
+ const { encryptionKey, encryptionSalt, vault } = this.state;
1381
+ // READ THIS CAREFULLY:
1382
+ // We do check if the vault is still considered up-to-date, if not, we would not re-use the
1383
+ // cached key and we will re-generate a new one (based on the password).
1384
+ //
1385
+ // This helps doing seamless updates of the vault. Useful in case we change some cryptographic
1386
+ // parameters to the KDF.
1387
+ const useCachedKey = encryptionKey && vault && __classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated?.(vault);
1381
1388
  if (!__classPrivateFieldGet(this, _KeyringController_password, "f") && !encryptionKey) {
1382
1389
  throw new Error(constants_1.KeyringControllerError.MissingCredentials);
1383
1390
  }
@@ -1388,7 +1395,7 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1388
1395
  const updatedState = {};
1389
1396
  if (__classPrivateFieldGet(this, _KeyringController_cacheEncryptionKey, "f")) {
1390
1397
  assertIsExportableKeyEncryptor(__classPrivateFieldGet(this, _KeyringController_encryptor, "f"));
1391
- if (encryptionKey) {
1398
+ if (useCachedKey) {
1392
1399
  const key = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").importKey(encryptionKey);
1393
1400
  const vaultJSON = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").encryptWithKey(key, serializedKeyrings);
1394
1401
  vaultJSON.salt = encryptionSalt;