@metamask-previews/keyring-controller 22.0.2-preview-0013a1bd → 22.0.2-preview-7a575715

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,10 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Added
11
-
12
- - Add support for envelope encryption ([#5940](https://github.com/MetaMask/core/pull/5940))
13
-
14
10
  ## [22.0.2]
15
11
 
16
12
  ### 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_password, _KeyringController_encryptionKey, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringById, _KeyringController_getKeyringByIdOrDefault, _KeyringController_getKeyringMetadata, _KeyringController_getKeyringBuilderForType, _KeyringController_addQRKeyring, _KeyringController_subscribeToQRKeyringEvents, _KeyringController_unsubscribeFromQRKeyringsEvents, _KeyringController_createNewVaultWithKeyring, _KeyringController_updateCachedEncryptionKey, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_getSessionState, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_isNewEncryptionAvailable, _KeyringController_isEnvelopeEncryptionEnabled, _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_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_getSessionState, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_isNewEncryptionAvailable, _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");
@@ -168,17 +168,6 @@ function assertIsValidPassword(password) {
168
168
  throw new Error(constants_1.KeyringControllerError.InvalidEmptyPassword);
169
169
  }
170
170
  }
171
- /**
172
- * Assert that the provided cacheEncryptionKey is true.
173
- *
174
- * @param cacheEncryptionKey - The cacheEncryptionKey to check.
175
- * @throws If the cacheEncryptionKey is not true.
176
- */
177
- function assertIsCacheEncryptionKeyTrue(cacheEncryptionKey) {
178
- if (!cacheEncryptionKey) {
179
- throw new Error(constants_1.KeyringControllerError.CacheEncryptionKeyDisabled);
180
- }
181
- }
182
171
  /**
183
172
  * Checks if the provided value is a serialized keyrings array.
184
173
  *
@@ -269,7 +258,6 @@ class KeyringController extends base_controller_1.BaseController {
269
258
  keyrings: { persist: false, anonymous: false },
270
259
  encryptionKey: { persist: false, anonymous: false },
271
260
  encryptionSalt: { persist: false, anonymous: false },
272
- encryptedEncryptionKey: { persist: true, anonymous: false },
273
261
  },
274
262
  messenger,
275
263
  state: {
@@ -286,7 +274,6 @@ class KeyringController extends base_controller_1.BaseController {
286
274
  _KeyringController_keyrings.set(this, void 0);
287
275
  _KeyringController_unsupportedKeyrings.set(this, void 0);
288
276
  _KeyringController_password.set(this, void 0);
289
- _KeyringController_encryptionKey.set(this, void 0);
290
277
  _KeyringController_qrKeyringStateListener.set(this, void 0);
291
278
  __classPrivateFieldSet(this, _KeyringController_keyringBuilders, keyringBuilders
292
279
  ? keyringBuilders.concat(defaultKeyringBuilders)
@@ -369,11 +356,9 @@ class KeyringController extends base_controller_1.BaseController {
369
356
  * @param password - Password to unlock keychain.
370
357
  * @param seed - A BIP39-compliant seed phrase as Uint8Array,
371
358
  * either as a string or an array of UTF-8 bytes that represent the string.
372
- * @param encryptionKey - Optional encryption key to encrypt the new vault. If
373
- * set, envelope encryption will be used.
374
359
  * @returns Promise resolving when the operation ends successfully.
375
360
  */
376
- async createNewVaultAndRestore(password, seed, encryptionKey) {
361
+ async createNewVaultAndRestore(password, seed) {
377
362
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
378
363
  assertIsValidPassword(password);
379
364
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createNewVaultWithKeyring).call(this, password, {
@@ -382,28 +367,25 @@ class KeyringController extends base_controller_1.BaseController {
382
367
  mnemonic: seed,
383
368
  numberOfAccounts: 1,
384
369
  },
385
- }, encryptionKey);
370
+ });
386
371
  });
387
372
  }
388
373
  /**
389
374
  * Create a new vault and primary keyring.
390
375
  *
391
- * This only works if keyrings are empty. If there is a pre-existing unlocked
392
- * vault, calling this will have no effect. If there is a pre-existing locked
393
- * vault, it will be replaced.
376
+ * This only works if keyrings are empty. If there is a pre-existing unlocked vault, calling this will have no effect.
377
+ * If there is a pre-existing locked vault, it will be replaced.
394
378
  *
395
379
  * @param password - Password to unlock the new vault.
396
- * @param encryptionKey - Optional encryption key to encrypt the new vault. If
397
- * set, envelope encryption will be used.
398
380
  * @returns Promise resolving when the operation ends successfully.
399
381
  */
400
- async createNewVaultAndKeychain(password, encryptionKey) {
382
+ async createNewVaultAndKeychain(password) {
401
383
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
402
384
  const accounts = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getAccountsFromKeyrings).call(this);
403
385
  if (!accounts.length) {
404
386
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createNewVaultWithKeyring).call(this, password, {
405
387
  type: KeyringTypes.hd,
406
- }, encryptionKey);
388
+ });
407
389
  }
408
390
  });
409
391
  }
@@ -432,16 +414,7 @@ class KeyringController extends base_controller_1.BaseController {
432
414
  if (!this.state.vault) {
433
415
  throw new Error(constants_1.KeyringControllerError.VaultError);
434
416
  }
435
- if (this.state.encryptedEncryptionKey) {
436
- // Envelope encryption mode.
437
- assertIsExportableKeyEncryptor(__classPrivateFieldGet(this, _KeyringController_encryptor, "f"));
438
- const decryptedEncryptionKey = (await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").decrypt(password, this.state.encryptedEncryptionKey));
439
- const importedKey = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").importKey(decryptedEncryptionKey);
440
- await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").decryptWithKey(importedKey, this.state.vault);
441
- }
442
- else {
443
- await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").decrypt(password, this.state.vault);
444
- }
417
+ await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").decrypt(password, this.state.vault);
445
418
  }
446
419
  /**
447
420
  * Returns the status of the vault.
@@ -630,7 +603,7 @@ class KeyringController extends base_controller_1.BaseController {
630
603
  try {
631
604
  wallet = ethereumjs_wallet_1.thirdparty.fromEtherWallet(input, password);
632
605
  }
633
- catch {
606
+ catch (e) {
634
607
  wallet = wallet || (await ethereumjs_wallet_1.default.fromV3(input, password, true));
635
608
  }
636
609
  privateKey = (0, utils_1.bytesToHex)(wallet.getPrivateKey());
@@ -689,7 +662,6 @@ class KeyringController extends base_controller_1.BaseController {
689
662
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
690
663
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_unsubscribeFromQRKeyringsEvents).call(this);
691
664
  __classPrivateFieldSet(this, _KeyringController_password, undefined, "f");
692
- __classPrivateFieldSet(this, _KeyringController_encryptionKey, undefined, "f");
693
665
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_clearKeyrings).call(this);
694
666
  this.update((state) => {
695
667
  state.isUnlocked = false;
@@ -870,24 +842,10 @@ class KeyringController extends base_controller_1.BaseController {
870
842
  * @returns Promise resolving when the operation completes.
871
843
  */
872
844
  changePassword(password) {
873
- return this.changePasswordAndEncryptionKey(password);
874
- }
875
- /**
876
- * Changes the password and encryption key used to encrypt the vault.
877
- *
878
- * @param password - The new password.
879
- * @param encryptionKey - The new encryption key. If omitted, the encryption
880
- * key will not be changed.
881
- * @returns Promise resolving when the operation completes.
882
- */
883
- changePasswordAndEncryptionKey(password, encryptionKey) {
884
845
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
885
846
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
886
847
  assertIsValidPassword(password);
887
- // Update password.
888
848
  __classPrivateFieldSet(this, _KeyringController_password, password, "f");
889
- // Update encryption key.
890
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateCachedEncryptionKey).call(this, encryptionKey);
891
849
  // We need to clear encryption key and salt from state
892
850
  // to force the controller to re-encrypt the vault using
893
851
  // the new password.
@@ -1201,7 +1159,7 @@ class KeyringController extends base_controller_1.BaseController {
1201
1159
  }
1202
1160
  }
1203
1161
  exports.KeyringController = KeyringController;
1204
- _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_cacheEncryptionKey = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_password = new WeakMap(), _KeyringController_encryptionKey = new WeakMap(), _KeyringController_qrKeyringStateListener = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
1162
+ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_cacheEncryptionKey = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_password = new WeakMap(), _KeyringController_qrKeyringStateListener = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
1205
1163
  this.messagingSystem.registerActionHandler(`${name}:signMessage`, this.signMessage.bind(this));
1206
1164
  this.messagingSystem.registerActionHandler(`${name}:signEip7702Authorization`, this.signEip7702Authorization.bind(this));
1207
1165
  this.messagingSystem.registerActionHandler(`${name}:signPersonalMessage`, this.signPersonalMessage.bind(this));
@@ -1270,10 +1228,9 @@ async function _KeyringController_addQRKeyring() {
1270
1228
  * @param keyring - A object containing the params to instantiate a new keyring.
1271
1229
  * @param keyring.type - The keyring type.
1272
1230
  * @param keyring.opts - Optional parameters required to instantiate the keyring.
1273
- * @param encryptionKey - Optional encryption key to encrypt the vault.
1274
1231
  * @returns A promise that resolves to the state.
1275
1232
  */
1276
- async function _KeyringController_createNewVaultWithKeyring(password, keyring, encryptionKey) {
1233
+ async function _KeyringController_createNewVaultWithKeyring(password, keyring) {
1277
1234
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1278
1235
  if (typeof password !== 'string') {
1279
1236
  throw new TypeError(constants_1.KeyringControllerError.WrongPasswordType);
@@ -1283,20 +1240,9 @@ async function _KeyringController_createNewVaultWithKeyring(password, keyring, e
1283
1240
  delete state.encryptionSalt;
1284
1241
  });
1285
1242
  __classPrivateFieldSet(this, _KeyringController_password, password, "f");
1286
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateCachedEncryptionKey).call(this, encryptionKey);
1287
1243
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_clearKeyrings).call(this);
1288
1244
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyringWithFirstAccount).call(this, keyring.type, keyring.opts);
1289
1245
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setUnlocked).call(this);
1290
- }, _KeyringController_updateCachedEncryptionKey = function _KeyringController_updateCachedEncryptionKey(encryptionKey) {
1291
- if (!encryptionKey && this.state.encryptedEncryptionKey) {
1292
- // If no encryption key is provided and we are in envelope encryption
1293
- // mode, use the cached encryption key. This case occurs when we call
1294
- // change password without providing a new encryption key.
1295
- __classPrivateFieldSet(this, _KeyringController_encryptionKey, this.state.encryptionKey, "f");
1296
- }
1297
- else {
1298
- __classPrivateFieldSet(this, _KeyringController_encryptionKey, encryptionKey, "f");
1299
- }
1300
1246
  }, _KeyringController_verifySeedPhrase =
1301
1247
  /**
1302
1248
  * Internal non-exclusive method to verify the seed phrase.
@@ -1386,7 +1332,6 @@ async function _KeyringController_getSessionState() {
1386
1332
  return {
1387
1333
  keyrings: await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSerializedKeyrings).call(this),
1388
1334
  password: __classPrivateFieldGet(this, _KeyringController_password, "f"),
1389
- encryptionKey: __classPrivateFieldGet(this, _KeyringController_encryptionKey, "f"),
1390
1335
  };
1391
1336
  }, _KeyringController_restoreSerializedKeyrings =
1392
1337
  /**
@@ -1422,7 +1367,7 @@ async function _KeyringController_restoreSerializedKeyrings(serializedKeyrings)
1422
1367
  */
1423
1368
  async function _KeyringController_unlockKeyrings(password, encryptionKey, encryptionSalt) {
1424
1369
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withVaultLock).call(this, async () => {
1425
- const { vault: encryptedVault, encryptedEncryptionKey } = this.state;
1370
+ const encryptedVault = this.state.vault;
1426
1371
  if (!encryptedVault) {
1427
1372
  throw new Error(constants_1.KeyringControllerError.VaultError);
1428
1373
  }
@@ -1431,20 +1376,11 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1431
1376
  if (__classPrivateFieldGet(this, _KeyringController_cacheEncryptionKey, "f")) {
1432
1377
  assertIsExportableKeyEncryptor(__classPrivateFieldGet(this, _KeyringController_encryptor, "f"));
1433
1378
  if (password) {
1434
- if (encryptedEncryptionKey) {
1435
- const decryptedEncryptionKey = (await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").decrypt(password, encryptedEncryptionKey));
1436
- const importedKey = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").importKey(decryptedEncryptionKey);
1437
- vault = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").decryptWithKey(importedKey, encryptedVault);
1438
- __classPrivateFieldSet(this, _KeyringController_password, password, "f");
1439
- updatedState.encryptionKey = decryptedEncryptionKey;
1440
- }
1441
- else {
1442
- const result = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").decryptWithDetail(password, encryptedVault);
1443
- vault = result.vault;
1444
- __classPrivateFieldSet(this, _KeyringController_password, password, "f");
1445
- updatedState.encryptionKey = result.exportedKeyString;
1446
- updatedState.encryptionSalt = result.salt;
1447
- }
1379
+ const result = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").decryptWithDetail(password, encryptedVault);
1380
+ vault = result.vault;
1381
+ __classPrivateFieldSet(this, _KeyringController_password, password, "f");
1382
+ updatedState.encryptionKey = result.exportedKeyString;
1383
+ updatedState.encryptionSalt = result.salt;
1448
1384
  }
1449
1385
  else {
1450
1386
  const parsedEncryptedVault = JSON.parse(encryptedVault);
@@ -1454,8 +1390,8 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1454
1390
  if (typeof encryptionKey !== 'string') {
1455
1391
  throw new TypeError(constants_1.KeyringControllerError.WrongPasswordType);
1456
1392
  }
1457
- const importedKey = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").importKey(encryptionKey);
1458
- vault = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").decryptWithKey(importedKey, parsedEncryptedVault);
1393
+ const key = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").importKey(encryptionKey);
1394
+ vault = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").decryptWithKey(key, parsedEncryptedVault);
1459
1395
  // This call is required on the first call because encryptionKey
1460
1396
  // is not yet inside the memStore
1461
1397
  updatedState.encryptionKey = encryptionKey;
@@ -1515,34 +1451,15 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1515
1451
  updatedState.vault = JSON.stringify(vaultJSON);
1516
1452
  }
1517
1453
  else if (__classPrivateFieldGet(this, _KeyringController_password, "f")) {
1518
- if (__classPrivateFieldGet(this, _KeyringController_encryptionKey, "f")) {
1519
- // Update cached key.
1520
- updatedState.encryptionKey = __classPrivateFieldGet(this, _KeyringController_encryptionKey, "f");
1521
- // Encrypt key and update encrypted key.
1522
- const encryptedEncryptionKey = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").encrypt(__classPrivateFieldGet(this, _KeyringController_password, "f"), __classPrivateFieldGet(this, _KeyringController_encryptionKey, "f"));
1523
- updatedState.encryptedEncryptionKey = encryptedEncryptionKey;
1524
- // Encrypt and update vault.
1525
- const importedKey = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").importKey(__classPrivateFieldGet(this, _KeyringController_encryptionKey, "f"));
1526
- const vaultJSON = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").encryptWithKey(importedKey, serializedKeyrings);
1527
- // Note that we don't need to explicitly append the salt to the
1528
- // vault here as it's already stored as part of the encrypted
1529
- // encryption key.
1530
- updatedState.vault = JSON.stringify(vaultJSON);
1531
- }
1532
- else {
1533
- const { vault: newVault, exportedKeyString } = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").encryptWithDetail(__classPrivateFieldGet(this, _KeyringController_password, "f"), serializedKeyrings);
1534
- updatedState.vault = newVault;
1535
- updatedState.encryptionKey = exportedKeyString;
1536
- }
1454
+ const { vault: newVault, exportedKeyString } = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").encryptWithDetail(__classPrivateFieldGet(this, _KeyringController_password, "f"), serializedKeyrings);
1455
+ updatedState.vault = newVault;
1456
+ updatedState.encryptionKey = exportedKeyString;
1537
1457
  }
1538
1458
  }
1539
1459
  else {
1540
1460
  assertIsValidPassword(__classPrivateFieldGet(this, _KeyringController_password, "f"));
1541
1461
  updatedState.vault = await __classPrivateFieldGet(this, _KeyringController_encryptor, "f").encrypt(__classPrivateFieldGet(this, _KeyringController_password, "f"), serializedKeyrings);
1542
1462
  }
1543
- if (__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_isEnvelopeEncryptionEnabled).call(this)) {
1544
- assertIsCacheEncryptionKeyTrue(__classPrivateFieldGet(this, _KeyringController_cacheEncryptionKey, "f"));
1545
- }
1546
1463
  if (!updatedState.vault) {
1547
1464
  throw new Error(constants_1.KeyringControllerError.MissingVaultData);
1548
1465
  }
@@ -1554,9 +1471,6 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1554
1471
  state.encryptionKey = updatedState.encryptionKey;
1555
1472
  state.encryptionSalt = JSON.parse(updatedState.vault).salt;
1556
1473
  }
1557
- if (updatedState.encryptedEncryptionKey) {
1558
- state.encryptedEncryptionKey = updatedState.encryptedEncryptionKey;
1559
- }
1560
1474
  });
1561
1475
  return true;
1562
1476
  });
@@ -1566,8 +1480,6 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1566
1480
  return false;
1567
1481
  }
1568
1482
  return !__classPrivateFieldGet(this, _KeyringController_encryptor, "f").isVaultUpdated(vault);
1569
- }, _KeyringController_isEnvelopeEncryptionEnabled = function _KeyringController_isEnvelopeEncryptionEnabled() {
1570
- return this.state.encryptedEncryptionKey || __classPrivateFieldGet(this, _KeyringController_encryptionKey, "f");
1571
1483
  }, _KeyringController_getAccountsFromKeyrings =
1572
1484
  /**
1573
1485
  * Retrieves all the accounts from keyrings instances
@@ -1652,8 +1564,7 @@ async function _KeyringController_createKeyring(type, data) {
1652
1564
  if (keyring.init) {
1653
1565
  await keyring.init();
1654
1566
  }
1655
- if (type === KeyringTypes.hd &&
1656
- (!(0, utils_1.isObject)(data) || !data.mnemonic)) {
1567
+ if (type === KeyringTypes.hd && (!(0, utils_1.isObject)(data) || !data.mnemonic)) {
1657
1568
  if (!keyring.generateRandomMnemonic) {
1658
1569
  throw new Error(constants_1.KeyringControllerError.UnsupportedGenerateRandomMnemonic);
1659
1570
  }
@@ -1775,16 +1686,11 @@ async function _KeyringController_assertNoDuplicateAccounts(additionalKeyrings =
1775
1686
  }
1776
1687
  }, _KeyringController_persistOrRollback =
1777
1688
  /**
1778
- * Execute the given function after acquiring the controller lock and save the
1779
- * vault to state after it (only if needed), or rollback to their previous
1780
- * state in case of error.
1781
- *
1782
- * ATTENTION: The callback must **not** alter `controller.state`. Any state
1783
- * change performed by the callback will not be rolled back on error.
1689
+ * Execute the given function after acquiring the controller lock
1690
+ * and save the vault to state after it (only if needed), or rollback to their
1691
+ * previous state in case of error.
1784
1692
  *
1785
- * @param callback - The function to execute. This callback must **not** alter
1786
- * `controller.state`. Any state change performed by the callback will not be
1787
- * rolled back on error.
1693
+ * @param callback - The function to execute.
1788
1694
  * @returns The result of the function.
1789
1695
  */
1790
1696
  async function _KeyringController_persistOrRollback(callback) {
@@ -1810,14 +1716,12 @@ async function _KeyringController_withRollback(callback) {
1810
1716
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async ({ releaseLock }) => {
1811
1717
  const currentSerializedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSerializedKeyrings).call(this);
1812
1718
  const currentPassword = __classPrivateFieldGet(this, _KeyringController_password, "f");
1813
- const currentEncryptionKey = __classPrivateFieldGet(this, _KeyringController_encryptionKey, "f");
1814
1719
  try {
1815
1720
  return await callback({ releaseLock });
1816
1721
  }
1817
1722
  catch (e) {
1818
- // Previous state is restored.
1723
+ // Keyrings and password are restored to their previous state
1819
1724
  __classPrivateFieldSet(this, _KeyringController_password, currentPassword, "f");
1820
- __classPrivateFieldSet(this, _KeyringController_encryptionKey, currentEncryptionKey, "f");
1821
1725
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreSerializedKeyrings).call(this, currentSerializedKeyrings);
1822
1726
  throw e;
1823
1727
  }