@metamask-previews/keyring-controller 22.0.2-preview-c6e5eb7 → 22.0.2-preview-d7c00b1

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,14 @@ 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 method `exportEncryptionKey` ([#5984](https://github.com/MetaMask/core/pull/5984))
13
+
14
+ ### Changed
15
+
16
+ - Make salt optional with method `submitEncryptionKey` ([#5984](https://github.com/MetaMask/core/pull/5984))
17
+
10
18
  ## [22.0.2]
11
19
 
12
20
  ### 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_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;
39
+ var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_password, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringById, _KeyringController_getKeyringByIdOrDefault, _KeyringController_getKeyringMetadata, _KeyringController_getKeyringBuilderForType, _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,6 +168,17 @@ function assertIsValidPassword(password) {
168
168
  throw new Error(constants_1.KeyringControllerError.InvalidEmptyPassword);
169
169
  }
170
170
  }
171
+ /**
172
+ * Assert that the provided encryption key is a valid non-empty string.
173
+ *
174
+ * @param encryptionKey - The encryption key to check.
175
+ * @throws If the encryption key is not a valid string.
176
+ */
177
+ function assertIsEncryptionKeySet(encryptionKey) {
178
+ if (!encryptionKey) {
179
+ throw new Error(constants_1.KeyringControllerError.EncryptionKeyNotSet);
180
+ }
181
+ }
171
182
  /**
172
183
  * Checks if the provided value is a serialized keyrings array.
173
184
  *
@@ -274,7 +285,6 @@ class KeyringController extends base_controller_1.BaseController {
274
285
  _KeyringController_keyrings.set(this, void 0);
275
286
  _KeyringController_unsupportedKeyrings.set(this, void 0);
276
287
  _KeyringController_password.set(this, void 0);
277
- _KeyringController_qrKeyringStateListener.set(this, void 0);
278
288
  __classPrivateFieldSet(this, _KeyringController_keyringBuilders, keyringBuilders
279
289
  ? keyringBuilders.concat(defaultKeyringBuilders)
280
290
  : defaultKeyringBuilders, "f");
@@ -399,9 +409,6 @@ class KeyringController extends base_controller_1.BaseController {
399
409
  */
400
410
  async addNewKeyring(type, opts) {
401
411
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
402
- if (type === KeyringTypes.qr) {
403
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringMetadata).call(this, await this.getOrAddQRKeyring());
404
- }
405
412
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringMetadata).call(this, await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, type, opts)));
406
413
  }
407
414
  /**
@@ -660,7 +667,6 @@ class KeyringController extends base_controller_1.BaseController {
660
667
  async setLocked() {
661
668
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
662
669
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
663
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_unsubscribeFromQRKeyringsEvents).call(this);
664
670
  __classPrivateFieldSet(this, _KeyringController_password, undefined, "f");
665
671
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_clearKeyrings).call(this);
666
672
  this.update((state) => {
@@ -843,6 +849,10 @@ class KeyringController extends base_controller_1.BaseController {
843
849
  */
844
850
  changePassword(password) {
845
851
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
852
+ // If the password is the same, do nothing.
853
+ if (__classPrivateFieldGet(this, _KeyringController_password, "f") === password) {
854
+ return Promise.resolve();
855
+ }
846
856
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
847
857
  assertIsValidPassword(password);
848
858
  __classPrivateFieldSet(this, _KeyringController_password, password, "f");
@@ -858,11 +868,12 @@ class KeyringController extends base_controller_1.BaseController {
858
868
  });
859
869
  }
860
870
  /**
861
- * Attempts to decrypt the current vault and load its keyrings,
862
- * using the given encryption key and salt.
871
+ * Attempts to decrypt the current vault and load its keyrings, using the
872
+ * given encryption key and salt. The optional salt can be used to check for
873
+ * consistency with the vault salt.
863
874
  *
864
875
  * @param encryptionKey - Key to unlock the keychain.
865
- * @param encryptionSalt - Salt to unlock the keychain.
876
+ * @param encryptionSalt - Optional salt to unlock the keychain.
866
877
  * @returns Promise resolving when the operation completes.
867
878
  */
868
879
  async submitEncryptionKey(encryptionKey, encryptionSalt) {
@@ -886,6 +897,19 @@ class KeyringController extends base_controller_1.BaseController {
886
897
  console.error('Failed to update vault during login:', error);
887
898
  }
888
899
  }
900
+ /**
901
+ * Exports the vault encryption key.
902
+ *
903
+ * @returns The vault encryption key.
904
+ */
905
+ async exportEncryptionKey() {
906
+ __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
907
+ return await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async () => {
908
+ const { encryptionKey } = this.state;
909
+ assertIsEncryptionKeySet(encryptionKey);
910
+ return encryptionKey;
911
+ });
912
+ }
889
913
  /**
890
914
  * Attempts to decrypt the current vault and load its keyrings,
891
915
  * using the given password.
@@ -960,206 +984,14 @@ class KeyringController extends base_controller_1.BaseController {
960
984
  return result;
961
985
  });
962
986
  }
963
- // QR Hardware related methods
964
- /**
965
- * Get QR Hardware keyring.
966
- *
967
- * @returns The QR Keyring if defined, otherwise undefined
968
- * @deprecated Use `withKeyring` instead.
969
- */
970
- getQRKeyring() {
971
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
972
- // QRKeyring is not yet compatible with Keyring type from @metamask/utils
973
- return this.getKeyringsByType(KeyringTypes.qr)[0];
974
- }
975
- /**
976
- * Get QR hardware keyring. If it doesn't exist, add it.
977
- *
978
- * @returns The added keyring
979
- * @deprecated Use `addNewKeyring` and `withKeyring` instead.
980
- */
981
- async getOrAddQRKeyring() {
982
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
983
- return (this.getQRKeyring() ||
984
- (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_addQRKeyring).call(this))));
985
- }
986
- /**
987
- * Restore QR keyring from serialized data.
988
- *
989
- * @param serialized - Serialized data to restore the keyring from.
990
- * @returns Promise resolving when the operation completes.
991
- * @deprecated Use `withKeyring` instead.
992
- */
993
- // TODO: Replace `any` with type
994
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
995
- async restoreQRKeyring(serialized) {
996
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
997
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
998
- const keyring = this.getQRKeyring() || (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_addQRKeyring).call(this));
999
- keyring.deserialize(serialized);
1000
- });
1001
- }
1002
- /**
1003
- * Reset QR keyring state.
1004
- *
1005
- * @returns Promise resolving when the operation completes.
1006
- * @deprecated Use `withKeyring` instead.
1007
- */
1008
- async resetQRKeyringState() {
1009
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1010
- (await this.getOrAddQRKeyring()).resetStore();
1011
- }
1012
- /**
1013
- * Get QR keyring state.
1014
- *
1015
- * @returns Promise resolving to the keyring state.
1016
- * @deprecated Use `withKeyring` or subscribe to `"KeyringController:qrKeyringStateChange"`
1017
- * instead.
1018
- */
1019
- async getQRKeyringState() {
1020
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1021
- return (await this.getOrAddQRKeyring()).getMemStore();
1022
- }
1023
- /**
1024
- * Submit QR hardware wallet public HDKey.
1025
- *
1026
- * @param cryptoHDKey - The key to submit.
1027
- * @returns Promise resolving when the operation completes.
1028
- * @deprecated Use `withKeyring` instead.
1029
- */
1030
- async submitQRCryptoHDKey(cryptoHDKey) {
1031
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1032
- (await this.getOrAddQRKeyring()).submitCryptoHDKey(cryptoHDKey);
1033
- }
1034
- /**
1035
- * Submit QR hardware wallet account.
1036
- *
1037
- * @param cryptoAccount - The account to submit.
1038
- * @returns Promise resolving when the operation completes.
1039
- * @deprecated Use `withKeyring` instead.
1040
- */
1041
- async submitQRCryptoAccount(cryptoAccount) {
1042
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1043
- (await this.getOrAddQRKeyring()).submitCryptoAccount(cryptoAccount);
1044
- }
1045
- /**
1046
- * Submit QR hardware wallet signature.
1047
- *
1048
- * @param requestId - The request ID.
1049
- * @param ethSignature - The signature to submit.
1050
- * @returns Promise resolving when the operation completes.
1051
- * @deprecated Use `withKeyring` instead.
1052
- */
1053
- async submitQRSignature(requestId, ethSignature) {
1054
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1055
- (await this.getOrAddQRKeyring()).submitSignature(requestId, ethSignature);
1056
- }
1057
- /**
1058
- * Cancel QR sign request.
1059
- *
1060
- * @returns Promise resolving when the operation completes.
1061
- * @deprecated Use `withKeyring` instead.
1062
- */
1063
- async cancelQRSignRequest() {
1064
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1065
- (await this.getOrAddQRKeyring()).cancelSignRequest();
1066
- }
1067
- /**
1068
- * Cancels qr keyring sync.
1069
- *
1070
- * @returns Promise resolving when the operation completes.
1071
- * @deprecated Use `withKeyring` instead.
1072
- */
1073
- async cancelQRSynchronization() {
1074
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1075
- (await this.getOrAddQRKeyring()).cancelSync();
1076
- }
1077
- /**
1078
- * Connect to QR hardware wallet.
1079
- *
1080
- * @param page - The page to connect to.
1081
- * @returns Promise resolving to the connected accounts.
1082
- * @deprecated Use of this method is discouraged as it creates a dangling promise
1083
- * internal to the `QRKeyring`, which can lead to unpredictable deadlocks. Please use
1084
- * `withKeyring` instead.
1085
- */
1086
- async connectQRHardware(page) {
1087
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1088
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
1089
- try {
1090
- const keyring = this.getQRKeyring() || (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_addQRKeyring).call(this));
1091
- let accounts;
1092
- switch (page) {
1093
- case -1:
1094
- accounts = await keyring.getPreviousPage();
1095
- break;
1096
- case 1:
1097
- accounts = await keyring.getNextPage();
1098
- break;
1099
- default:
1100
- accounts = await keyring.getFirstPage();
1101
- }
1102
- // TODO: Replace `any` with type
1103
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1104
- return accounts.map((account) => {
1105
- return {
1106
- ...account,
1107
- balance: '0x0',
1108
- };
1109
- });
1110
- }
1111
- catch (e) {
1112
- // TODO: Add test case for when keyring throws
1113
- /* istanbul ignore next */
1114
- // TODO: Either fix this lint violation or explain why it's necessary to ignore.
1115
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1116
- throw new Error(`Unspecified error when connect QR Hardware, ${e}`);
1117
- }
1118
- });
1119
- }
1120
- /**
1121
- * Unlock a QR hardware wallet account.
1122
- *
1123
- * @param index - The index of the account to unlock.
1124
- * @returns Promise resolving when the operation completes.
1125
- * @deprecated Use `withKeyring` instead.
1126
- */
1127
- async unlockQRHardwareWalletAccount(index) {
1128
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1129
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
1130
- const keyring = this.getQRKeyring() || (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_addQRKeyring).call(this));
1131
- keyring.setAccountToUnlock(index);
1132
- await keyring.addAccounts(1);
1133
- });
1134
- }
1135
987
  async getAccountKeyringType(account) {
1136
988
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1137
989
  const keyring = (await this.getKeyringForAccount(account));
1138
990
  return keyring.type;
1139
991
  }
1140
- /**
1141
- * Forget the QR hardware wallet.
1142
- *
1143
- * @returns Promise resolving to the removed accounts and the remaining accounts.
1144
- * @deprecated Use `withKeyring` instead.
1145
- */
1146
- async forgetQRDevice() {
1147
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1148
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
1149
- const keyring = this.getQRKeyring();
1150
- if (!keyring) {
1151
- return { removedAccounts: [], remainingAccounts: [] };
1152
- }
1153
- const allAccounts = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getAccountsFromKeyrings).call(this));
1154
- keyring.forgetDevice();
1155
- const remainingAccounts = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getAccountsFromKeyrings).call(this));
1156
- const removedAccounts = allAccounts.filter((address) => !remainingAccounts.includes(address));
1157
- return { removedAccounts, remainingAccounts };
1158
- });
1159
- }
1160
992
  }
1161
993
  exports.KeyringController = KeyringController;
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() {
994
+ _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_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
1163
995
  this.messagingSystem.registerActionHandler(`${name}:signMessage`, this.signMessage.bind(this));
1164
996
  this.messagingSystem.registerActionHandler(`${name}:signEip7702Authorization`, this.signEip7702Authorization.bind(this));
1165
997
  this.messagingSystem.registerActionHandler(`${name}:signPersonalMessage`, this.signPersonalMessage.bind(this));
@@ -1191,30 +1023,6 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
1191
1023
  return keyringWithMetadata.metadata;
1192
1024
  }, _KeyringController_getKeyringBuilderForType = function _KeyringController_getKeyringBuilderForType(type) {
1193
1025
  return __classPrivateFieldGet(this, _KeyringController_keyringBuilders, "f").find((keyringBuilder) => keyringBuilder.type === type);
1194
- }, _KeyringController_addQRKeyring =
1195
- /**
1196
- * Add qr hardware keyring.
1197
- *
1198
- * @returns The added keyring
1199
- * @throws If a QRKeyring builder is not provided
1200
- * when initializing the controller
1201
- */
1202
- async function _KeyringController_addQRKeyring() {
1203
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1204
- // QRKeyring is not yet compatible with Keyring type from @metamask/utils
1205
- return (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, KeyringTypes.qr));
1206
- }, _KeyringController_subscribeToQRKeyringEvents = function _KeyringController_subscribeToQRKeyringEvents(qrKeyring) {
1207
- __classPrivateFieldSet(this, _KeyringController_qrKeyringStateListener, (state) => {
1208
- this.messagingSystem.publish(`${name}:qrKeyringStateChange`, state);
1209
- }, "f");
1210
- qrKeyring.getMemStore().subscribe(__classPrivateFieldGet(this, _KeyringController_qrKeyringStateListener, "f"));
1211
- }, _KeyringController_unsubscribeFromQRKeyringsEvents = function _KeyringController_unsubscribeFromQRKeyringsEvents() {
1212
- const qrKeyrings = this.getKeyringsByType(KeyringTypes.qr);
1213
- qrKeyrings.forEach((qrKeyring) => {
1214
- if (__classPrivateFieldGet(this, _KeyringController_qrKeyringStateListener, "f")) {
1215
- qrKeyring.getMemStore().unsubscribe(__classPrivateFieldGet(this, _KeyringController_qrKeyringStateListener, "f"));
1216
- }
1217
- });
1218
1026
  }, _KeyringController_createNewVaultWithKeyring =
1219
1027
  /**
1220
1028
  * Create new vault with an initial keyring
@@ -1384,9 +1192,12 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1384
1192
  }
1385
1193
  else {
1386
1194
  const parsedEncryptedVault = JSON.parse(encryptedVault);
1387
- if (encryptionSalt !== parsedEncryptedVault.salt) {
1195
+ if (encryptionSalt && encryptionSalt !== parsedEncryptedVault.salt) {
1388
1196
  throw new Error(constants_1.KeyringControllerError.ExpiredCredentials);
1389
1197
  }
1198
+ else {
1199
+ encryptionSalt = parsedEncryptedVault.salt;
1200
+ }
1390
1201
  if (typeof encryptionKey !== 'string') {
1391
1202
  throw new TypeError(constants_1.KeyringControllerError.WrongPasswordType);
1392
1203
  }
@@ -1395,9 +1206,6 @@ async function _KeyringController_unlockKeyrings(password, encryptionKey, encryp
1395
1206
  // This call is required on the first call because encryptionKey
1396
1207
  // is not yet inside the memStore
1397
1208
  updatedState.encryptionKey = encryptionKey;
1398
- // we can safely assume that encryptionSalt is defined here
1399
- // because we compare it with the salt from the vault
1400
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1401
1209
  updatedState.encryptionSalt = encryptionSalt;
1402
1210
  }
1403
1211
  }
@@ -1574,11 +1382,6 @@ async function _KeyringController_createKeyring(type, data) {
1574
1382
  await keyring.generateRandomMnemonic();
1575
1383
  await keyring.addAccounts(1);
1576
1384
  }
1577
- if (type === KeyringTypes.qr) {
1578
- // In case of a QR keyring type, we need to subscribe
1579
- // to its events after creating it
1580
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_subscribeToQRKeyringEvents).call(this, keyring);
1581
- }
1582
1385
  return keyring;
1583
1386
  }, _KeyringController_clearKeyrings =
1584
1387
  /**