@metamask-previews/keyring-controller 14.0.1-preview-f04be62f → 15.0.0-preview-11ae513

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.
@@ -3,7 +3,7 @@ import {
3
3
  __privateGet,
4
4
  __privateMethod,
5
5
  __privateSet
6
- } from "./chunk-NAAWD7HX.mjs";
6
+ } from "./chunk-XPARO3LL.mjs";
7
7
 
8
8
  // src/KeyringController.ts
9
9
  import { isValidPrivate, toBuffer, getBinarySize } from "@ethereumjs/util";
@@ -86,7 +86,7 @@ async function displayForKeyring(keyring) {
86
86
  accounts: accounts.map(normalize)
87
87
  };
88
88
  }
89
- var _keyringBuilders, _keyrings, _unsupportedKeyrings, _password, _encryptor, _cacheEncryptionKey, _qrKeyringStateListener, _registerMessageHandlers, registerMessageHandlers_fn, _getKeyringBuilderForType, getKeyringBuilderForType_fn, _addQRKeyring, addQRKeyring_fn, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn, _unsubscribeFromQRKeyringsEvents, unsubscribeFromQRKeyringsEvents_fn, _createNewVaultWithKeyring, createNewVaultWithKeyring_fn, _updateKeyringsInState, updateKeyringsInState_fn, _unlockKeyrings, unlockKeyrings_fn, _createKeyringWithFirstAccount, createKeyringWithFirstAccount_fn, _newKeyring, newKeyring_fn, _clearKeyrings, clearKeyrings_fn, _restoreKeyring, restoreKeyring_fn, _destroyKeyring, destroyKeyring_fn, _removeEmptyKeyrings, removeEmptyKeyrings_fn, _checkForDuplicate, checkForDuplicate_fn, _setUnlocked, setUnlocked_fn, _getMemState, getMemState_fn;
89
+ var _initVaultMutex, _vaultOperationMutex, _keyringBuilders, _keyrings, _unsupportedKeyrings, _password, _encryptor, _cacheEncryptionKey, _qrKeyringStateListener, _registerMessageHandlers, registerMessageHandlers_fn, _getKeyringBuilderForType, getKeyringBuilderForType_fn, _addQRKeyring, addQRKeyring_fn, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn, _unsubscribeFromQRKeyringsEvents, unsubscribeFromQRKeyringsEvents_fn, _createNewVaultWithKeyring, createNewVaultWithKeyring_fn, _getUpdatedKeyrings, getUpdatedKeyrings_fn, _unlockKeyrings, unlockKeyrings_fn, _createKeyringWithFirstAccount, createKeyringWithFirstAccount_fn, _newKeyring, newKeyring_fn, _clearKeyrings, clearKeyrings_fn, _restoreKeyring, restoreKeyring_fn, _destroyKeyring, destroyKeyring_fn, _removeEmptyKeyrings, removeEmptyKeyrings_fn, _checkForDuplicate, checkForDuplicate_fn, _setUnlocked, setUnlocked_fn, _getMemState, getMemState_fn, _withVaultLock, withVaultLock_fn;
90
90
  var KeyringController = class extends BaseController {
91
91
  /**
92
92
  * Creates a KeyringController instance.
@@ -164,9 +164,12 @@ var KeyringController = class extends BaseController {
164
164
  */
165
165
  __privateAdd(this, _createNewVaultWithKeyring);
166
166
  /**
167
- * Update the controller state with its current keyrings.
167
+ * Get the updated array of each keyring's type and
168
+ * accounts list.
169
+ *
170
+ * @returns A promise resolving to the updated keyrings array.
168
171
  */
169
- __privateAdd(this, _updateKeyringsInState);
172
+ __privateAdd(this, _getUpdatedKeyrings);
170
173
  /**
171
174
  * Unlock Keyrings, decrypting the vault and deserializing all
172
175
  * keyrings contained in it, using a password or an encryption key with salt.
@@ -199,6 +202,9 @@ var KeyringController = class extends BaseController {
199
202
  /**
200
203
  * Remove all managed keyrings, destroying all their
201
204
  * instances in memory.
205
+ *
206
+ * @param options - Operations options.
207
+ * @param options.skipStateUpdate - Whether to skip updating the controller state.
202
208
  */
203
209
  __privateAdd(this, _clearKeyrings);
204
210
  /**
@@ -245,7 +251,20 @@ var KeyringController = class extends BaseController {
245
251
  */
246
252
  __privateAdd(this, _setUnlocked);
247
253
  __privateAdd(this, _getMemState);
248
- this.mutex = new Mutex();
254
+ /**
255
+ * Lock the vault mutex before executing the given function,
256
+ * and release it after the function is resolved or after an
257
+ * error is thrown.
258
+ *
259
+ * This ensures that each operation that interacts with the vault
260
+ * is executed in a mutually exclusive way.
261
+ *
262
+ * @param fn - The function to execute while the vault mutex is locked.
263
+ * @returns The result of the function.
264
+ */
265
+ __privateAdd(this, _withVaultLock);
266
+ __privateAdd(this, _initVaultMutex, new Mutex());
267
+ __privateAdd(this, _vaultOperationMutex, new Mutex());
249
268
  __privateAdd(this, _keyringBuilders, void 0);
250
269
  __privateAdd(this, _keyrings, void 0);
251
270
  __privateAdd(this, _unsupportedKeyrings, void 0);
@@ -276,15 +295,18 @@ var KeyringController = class extends BaseController {
276
295
  if (!primaryKeyring) {
277
296
  throw new Error("No HD keyring found");
278
297
  }
279
- const oldAccounts = await this.getAccounts();
298
+ const oldAccounts = await primaryKeyring.getAccounts();
280
299
  if (accountCount && oldAccounts.length !== accountCount) {
281
300
  if (accountCount > oldAccounts.length) {
282
301
  throw new Error("Account out of sequence");
283
302
  }
284
- const primaryKeyringAccounts = await primaryKeyring.getAccounts();
303
+ const existingAccount = oldAccounts[accountCount];
304
+ if (!existingAccount) {
305
+ throw new Error(`Can't find account at index ${accountCount}`);
306
+ }
285
307
  return {
286
308
  keyringState: __privateMethod(this, _getMemState, getMemState_fn).call(this),
287
- addedAccountAddress: primaryKeyringAccounts[accountCount]
309
+ addedAccountAddress: existingAccount
288
310
  };
289
311
  }
290
312
  const addedAccountAddress = await this.addNewAccountForKeyring(
@@ -346,7 +368,7 @@ var KeyringController = class extends BaseController {
346
368
  * @returns Promise resolving to the restored keychain object.
347
369
  */
348
370
  async createNewVaultAndRestore(password, seed) {
349
- const releaseLock = await this.mutex.acquire();
371
+ const releaseLock = await __privateGet(this, _initVaultMutex).acquire();
350
372
  if (!password || !password.length) {
351
373
  throw new Error("Invalid password");
352
374
  }
@@ -370,7 +392,7 @@ var KeyringController = class extends BaseController {
370
392
  * @returns Newly-created keychain object.
371
393
  */
372
394
  async createNewVaultAndKeychain(password) {
373
- const releaseLock = await this.mutex.acquire();
395
+ const releaseLock = await __privateGet(this, _initVaultMutex).acquire();
374
396
  try {
375
397
  const accounts = await this.getAccounts();
376
398
  if (!accounts.length) {
@@ -460,7 +482,7 @@ var KeyringController = class extends BaseController {
460
482
  return await keyring.exportAccount(normalize(address));
461
483
  }
462
484
  /**
463
- * Returns the public addresses of all accounts for the current keyring.
485
+ * Returns the public addresses of all accounts from every keyring.
464
486
  *
465
487
  * @returns A promise resolving to an array of addresses.
466
488
  */
@@ -565,60 +587,66 @@ var KeyringController = class extends BaseController {
565
587
  * operation completes.
566
588
  */
567
589
  async persistAllKeyrings() {
568
- const { encryptionKey, encryptionSalt } = this.state;
569
- if (!__privateGet(this, _password) && !encryptionKey) {
570
- throw new Error("KeyringController - Cannot persist vault without password and encryption key" /* MissingCredentials */);
571
- }
572
- const serializedKeyrings = await Promise.all(
573
- __privateGet(this, _keyrings).map(async (keyring) => {
574
- const [type, data] = await Promise.all([
575
- keyring.type,
576
- keyring.serialize()
577
- ]);
578
- return { type, data };
579
- })
580
- );
581
- serializedKeyrings.push(...__privateGet(this, _unsupportedKeyrings));
582
- let vault;
583
- let newEncryptionKey;
584
- if (__privateGet(this, _cacheEncryptionKey)) {
585
- assertIsExportableKeyEncryptor(__privateGet(this, _encryptor));
586
- if (encryptionKey) {
587
- const key = await __privateGet(this, _encryptor).importKey(encryptionKey);
588
- const vaultJSON = await __privateGet(this, _encryptor).encryptWithKey(
589
- key,
590
- serializedKeyrings
591
- );
592
- vaultJSON.salt = encryptionSalt;
593
- vault = JSON.stringify(vaultJSON);
594
- } else if (__privateGet(this, _password)) {
595
- const { vault: newVault, exportedKeyString } = await __privateGet(this, _encryptor).encryptWithDetail(
590
+ return __privateMethod(this, _withVaultLock, withVaultLock_fn).call(this, async () => {
591
+ const { encryptionKey, encryptionSalt } = this.state;
592
+ if (!__privateGet(this, _password) && !encryptionKey) {
593
+ throw new Error("KeyringController - Cannot persist vault without password and encryption key" /* MissingCredentials */);
594
+ }
595
+ const serializedKeyrings = await Promise.all(
596
+ __privateGet(this, _keyrings).map(async (keyring) => {
597
+ const [type, data] = await Promise.all([
598
+ keyring.type,
599
+ keyring.serialize()
600
+ ]);
601
+ return { type, data };
602
+ })
603
+ );
604
+ serializedKeyrings.push(...__privateGet(this, _unsupportedKeyrings));
605
+ if (!serializedKeyrings.some((keyring) => keyring.type === "HD Key Tree" /* hd */)) {
606
+ throw new Error("KeyringController - No HD Keyring found" /* NoHdKeyring */);
607
+ }
608
+ const updatedState = {};
609
+ if (__privateGet(this, _cacheEncryptionKey)) {
610
+ assertIsExportableKeyEncryptor(__privateGet(this, _encryptor));
611
+ if (encryptionKey) {
612
+ const key = await __privateGet(this, _encryptor).importKey(encryptionKey);
613
+ const vaultJSON = await __privateGet(this, _encryptor).encryptWithKey(
614
+ key,
615
+ serializedKeyrings
616
+ );
617
+ vaultJSON.salt = encryptionSalt;
618
+ updatedState.vault = JSON.stringify(vaultJSON);
619
+ } else if (__privateGet(this, _password)) {
620
+ const { vault: newVault, exportedKeyString } = await __privateGet(this, _encryptor).encryptWithDetail(
621
+ __privateGet(this, _password),
622
+ serializedKeyrings
623
+ );
624
+ updatedState.vault = newVault;
625
+ updatedState.encryptionKey = exportedKeyString;
626
+ }
627
+ } else {
628
+ if (typeof __privateGet(this, _password) !== "string") {
629
+ throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
630
+ }
631
+ updatedState.vault = await __privateGet(this, _encryptor).encrypt(
596
632
  __privateGet(this, _password),
597
633
  serializedKeyrings
598
634
  );
599
- vault = newVault;
600
- newEncryptionKey = exportedKeyString;
601
635
  }
602
- } else {
603
- if (typeof __privateGet(this, _password) !== "string") {
604
- throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
636
+ if (!updatedState.vault) {
637
+ throw new Error("KeyringController - Cannot persist vault without vault information" /* MissingVaultData */);
605
638
  }
606
- vault = await __privateGet(this, _encryptor).encrypt(__privateGet(this, _password), serializedKeyrings);
607
- }
608
- if (!vault) {
609
- throw new Error("KeyringController - Cannot persist vault without vault information" /* MissingVaultData */);
610
- }
611
- this.update((state) => {
612
- state.vault = vault;
613
- });
614
- await __privateMethod(this, _updateKeyringsInState, updateKeyringsInState_fn).call(this);
615
- if (newEncryptionKey) {
639
+ const updatedKeyrings = await __privateMethod(this, _getUpdatedKeyrings, getUpdatedKeyrings_fn).call(this);
616
640
  this.update((state) => {
617
- state.encryptionKey = newEncryptionKey;
618
- state.encryptionSalt = JSON.parse(vault).salt;
641
+ state.vault = updatedState.vault;
642
+ state.keyrings = updatedKeyrings;
643
+ if (updatedState.encryptionKey) {
644
+ state.encryptionKey = updatedState.encryptionKey;
645
+ state.encryptionSalt = JSON.parse(updatedState.vault).salt;
646
+ }
619
647
  });
620
- }
621
- return true;
648
+ return true;
649
+ });
622
650
  }
623
651
  /**
624
652
  * Imports an account with the specified import strategy.
@@ -803,9 +831,10 @@ var KeyringController = class extends BaseController {
803
831
  *
804
832
  * @param from - Address of the sender.
805
833
  * @param transactions - Base transactions to include in the UserOperation.
834
+ * @param executionContext - The execution context to use for the UserOperation.
806
835
  * @returns A pseudo-UserOperation that can be used to construct a real.
807
836
  */
808
- async prepareUserOperation(from, transactions) {
837
+ async prepareUserOperation(from, transactions, executionContext) {
809
838
  const address = normalize(from);
810
839
  const keyring = await this.getKeyringForAccount(
811
840
  address
@@ -813,7 +842,11 @@ var KeyringController = class extends BaseController {
813
842
  if (!keyring.prepareUserOperation) {
814
843
  throw new Error("KeyringController - The keyring for the current address does not support the method prepareUserOperation." /* UnsupportedPrepareUserOperation */);
815
844
  }
816
- return await keyring.prepareUserOperation(address, transactions);
845
+ return await keyring.prepareUserOperation(
846
+ address,
847
+ transactions,
848
+ executionContext
849
+ );
817
850
  }
818
851
  /**
819
852
  * Patches properties of a UserOperation. Currently, only the
@@ -821,9 +854,10 @@ var KeyringController = class extends BaseController {
821
854
  *
822
855
  * @param from - Address of the sender.
823
856
  * @param userOp - UserOperation to patch.
857
+ * @param executionContext - The execution context to use for the UserOperation.
824
858
  * @returns A patch to apply to the UserOperation.
825
859
  */
826
- async patchUserOperation(from, userOp) {
860
+ async patchUserOperation(from, userOp, executionContext) {
827
861
  const address = normalize(from);
828
862
  const keyring = await this.getKeyringForAccount(
829
863
  address
@@ -831,16 +865,17 @@ var KeyringController = class extends BaseController {
831
865
  if (!keyring.patchUserOperation) {
832
866
  throw new Error("KeyringController - The keyring for the current address does not support the method patchUserOperation." /* UnsupportedPatchUserOperation */);
833
867
  }
834
- return await keyring.patchUserOperation(address, userOp);
868
+ return await keyring.patchUserOperation(address, userOp, executionContext);
835
869
  }
836
870
  /**
837
871
  * Signs an UserOperation.
838
872
  *
839
873
  * @param from - Address of the sender.
840
874
  * @param userOp - UserOperation to sign.
875
+ * @param executionContext - The execution context to use for the UserOperation.
841
876
  * @returns The signature of the UserOperation.
842
877
  */
843
- async signUserOperation(from, userOp) {
878
+ async signUserOperation(from, userOp, executionContext) {
844
879
  const address = normalize(from);
845
880
  const keyring = await this.getKeyringForAccount(
846
881
  address
@@ -848,7 +883,7 @@ var KeyringController = class extends BaseController {
848
883
  if (!keyring.signUserOperation) {
849
884
  throw new Error("KeyringController - The keyring for the current address does not support the method signUserOperation." /* UnsupportedSignUserOperation */);
850
885
  }
851
- return await keyring.signUserOperation(address, userOp);
886
+ return await keyring.signUserOperation(address, userOp, executionContext);
852
887
  }
853
888
  /**
854
889
  * Attempts to decrypt the current vault and load its keyrings,
@@ -1011,6 +1046,8 @@ var KeyringController = class extends BaseController {
1011
1046
  return { removedAccounts, remainingAccounts };
1012
1047
  }
1013
1048
  };
1049
+ _initVaultMutex = new WeakMap();
1050
+ _vaultOperationMutex = new WeakMap();
1014
1051
  _keyringBuilders = new WeakMap();
1015
1052
  _keyrings = new WeakMap();
1016
1053
  _unsupportedKeyrings = new WeakMap();
@@ -1116,65 +1153,72 @@ createNewVaultWithKeyring_fn = async function(password, keyring) {
1116
1153
  __privateMethod(this, _setUnlocked, setUnlocked_fn).call(this);
1117
1154
  return __privateMethod(this, _getMemState, getMemState_fn).call(this);
1118
1155
  };
1119
- _updateKeyringsInState = new WeakSet();
1120
- updateKeyringsInState_fn = async function() {
1121
- const keyrings = await Promise.all(__privateGet(this, _keyrings).map(displayForKeyring));
1122
- this.update((state) => {
1123
- state.keyrings = keyrings;
1124
- });
1156
+ _getUpdatedKeyrings = new WeakSet();
1157
+ getUpdatedKeyrings_fn = async function() {
1158
+ return Promise.all(__privateGet(this, _keyrings).map(displayForKeyring));
1125
1159
  };
1126
1160
  _unlockKeyrings = new WeakSet();
1127
1161
  unlockKeyrings_fn = async function(password, encryptionKey, encryptionSalt) {
1128
- const encryptedVault = this.state.vault;
1129
- if (!encryptedVault) {
1130
- throw new Error("KeyringController - Cannot unlock without a previous vault." /* VaultError */);
1131
- }
1132
- await __privateMethod(this, _clearKeyrings, clearKeyrings_fn).call(this);
1133
- let vault;
1134
- if (__privateGet(this, _cacheEncryptionKey)) {
1135
- assertIsExportableKeyEncryptor(__privateGet(this, _encryptor));
1136
- if (password) {
1137
- const result = await __privateGet(this, _encryptor).decryptWithDetail(
1138
- password,
1139
- encryptedVault
1140
- );
1141
- vault = result.vault;
1142
- __privateSet(this, _password, password);
1143
- this.update((state) => {
1144
- state.encryptionKey = result.exportedKeyString;
1145
- state.encryptionSalt = result.salt;
1146
- });
1147
- } else {
1148
- const parsedEncryptedVault = JSON.parse(encryptedVault);
1149
- if (encryptionSalt !== parsedEncryptedVault.salt) {
1150
- throw new Error("KeyringController - Encryption key and salt provided are expired" /* ExpiredCredentials */);
1162
+ return __privateMethod(this, _withVaultLock, withVaultLock_fn).call(this, async ({ releaseLock }) => {
1163
+ const encryptedVault = this.state.vault;
1164
+ if (!encryptedVault) {
1165
+ throw new Error("KeyringController - Cannot unlock without a previous vault." /* VaultError */);
1166
+ }
1167
+ await __privateMethod(this, _clearKeyrings, clearKeyrings_fn).call(this, { skipStateUpdate: true });
1168
+ let vault;
1169
+ const updatedState = {};
1170
+ if (__privateGet(this, _cacheEncryptionKey)) {
1171
+ assertIsExportableKeyEncryptor(__privateGet(this, _encryptor));
1172
+ if (password) {
1173
+ const result = await __privateGet(this, _encryptor).decryptWithDetail(
1174
+ password,
1175
+ encryptedVault
1176
+ );
1177
+ vault = result.vault;
1178
+ __privateSet(this, _password, password);
1179
+ updatedState.encryptionKey = result.exportedKeyString;
1180
+ updatedState.encryptionSalt = result.salt;
1181
+ } else {
1182
+ const parsedEncryptedVault = JSON.parse(encryptedVault);
1183
+ if (encryptionSalt !== parsedEncryptedVault.salt) {
1184
+ throw new Error("KeyringController - Encryption key and salt provided are expired" /* ExpiredCredentials */);
1185
+ }
1186
+ if (typeof encryptionKey !== "string") {
1187
+ throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
1188
+ }
1189
+ const key = await __privateGet(this, _encryptor).importKey(encryptionKey);
1190
+ vault = await __privateGet(this, _encryptor).decryptWithKey(
1191
+ key,
1192
+ parsedEncryptedVault
1193
+ );
1194
+ updatedState.encryptionKey = encryptionKey;
1195
+ updatedState.encryptionSalt = encryptionSalt;
1151
1196
  }
1152
- if (typeof encryptionKey !== "string") {
1197
+ } else {
1198
+ if (typeof password !== "string") {
1153
1199
  throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
1154
1200
  }
1155
- const key = await __privateGet(this, _encryptor).importKey(encryptionKey);
1156
- vault = await __privateGet(this, _encryptor).decryptWithKey(key, parsedEncryptedVault);
1157
- this.update((state) => {
1158
- state.encryptionKey = encryptionKey;
1159
- state.encryptionSalt = encryptionSalt;
1160
- });
1201
+ vault = await __privateGet(this, _encryptor).decrypt(password, encryptedVault);
1202
+ __privateSet(this, _password, password);
1161
1203
  }
1162
- } else {
1163
- if (typeof password !== "string") {
1164
- throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
1204
+ if (!isSerializedKeyringsArray(vault)) {
1205
+ throw new Error("KeyringController - The decrypted vault has an unexpected shape." /* VaultDataError */);
1165
1206
  }
1166
- vault = await __privateGet(this, _encryptor).decrypt(password, encryptedVault);
1167
- __privateSet(this, _password, password);
1168
- }
1169
- if (!isSerializedKeyringsArray(vault)) {
1170
- throw new Error("KeyringController - The decrypted vault has an unexpected shape." /* VaultDataError */);
1171
- }
1172
- await Promise.all(vault.map(__privateMethod(this, _restoreKeyring, restoreKeyring_fn).bind(this)));
1173
- await __privateMethod(this, _updateKeyringsInState, updateKeyringsInState_fn).call(this);
1174
- if (__privateGet(this, _password) && (!__privateGet(this, _cacheEncryptionKey) || !encryptionKey) && __privateGet(this, _encryptor).isVaultUpdated && !__privateGet(this, _encryptor).isVaultUpdated(encryptedVault)) {
1175
- await this.persistAllKeyrings();
1176
- }
1177
- return __privateGet(this, _keyrings);
1207
+ await Promise.all(vault.map(__privateMethod(this, _restoreKeyring, restoreKeyring_fn).bind(this)));
1208
+ const updatedKeyrings = await __privateMethod(this, _getUpdatedKeyrings, getUpdatedKeyrings_fn).call(this);
1209
+ this.update((state) => {
1210
+ state.keyrings = updatedKeyrings;
1211
+ if (updatedState.encryptionKey || updatedState.encryptionSalt) {
1212
+ state.encryptionKey = updatedState.encryptionKey;
1213
+ state.encryptionSalt = updatedState.encryptionSalt;
1214
+ }
1215
+ });
1216
+ if (__privateGet(this, _password) && (!__privateGet(this, _cacheEncryptionKey) || !encryptionKey) && __privateGet(this, _encryptor).isVaultUpdated && !__privateGet(this, _encryptor).isVaultUpdated(encryptedVault)) {
1217
+ releaseLock();
1218
+ await this.persistAllKeyrings();
1219
+ }
1220
+ return __privateGet(this, _keyrings);
1221
+ });
1178
1222
  };
1179
1223
  _createKeyringWithFirstAccount = new WeakSet();
1180
1224
  createKeyringWithFirstAccount_fn = async function(type, opts) {
@@ -1200,14 +1244,16 @@ newKeyring_fn = async function(type, data) {
1200
1244
  return keyring;
1201
1245
  };
1202
1246
  _clearKeyrings = new WeakSet();
1203
- clearKeyrings_fn = async function() {
1247
+ clearKeyrings_fn = async function(options = { skipStateUpdate: false }) {
1204
1248
  for (const keyring of __privateGet(this, _keyrings)) {
1205
1249
  await __privateMethod(this, _destroyKeyring, destroyKeyring_fn).call(this, keyring);
1206
1250
  }
1207
1251
  __privateSet(this, _keyrings, []);
1208
- this.update((state) => {
1209
- state.keyrings = [];
1210
- });
1252
+ if (!options.skipStateUpdate) {
1253
+ this.update((state) => {
1254
+ state.keyrings = [];
1255
+ });
1256
+ }
1211
1257
  };
1212
1258
  _restoreKeyring = new WeakSet();
1213
1259
  restoreKeyring_fn = async function(serialized) {
@@ -1275,6 +1321,15 @@ getMemState_fn = function() {
1275
1321
  keyrings: this.state.keyrings
1276
1322
  };
1277
1323
  };
1324
+ _withVaultLock = new WeakSet();
1325
+ withVaultLock_fn = async function(fn) {
1326
+ const releaseLock = await __privateGet(this, _vaultOperationMutex).acquire();
1327
+ try {
1328
+ return await fn({ releaseLock });
1329
+ } finally {
1330
+ releaseLock();
1331
+ }
1332
+ };
1278
1333
  var KeyringController_default = KeyringController;
1279
1334
 
1280
1335
  export {
@@ -1287,4 +1342,4 @@ export {
1287
1342
  KeyringController,
1288
1343
  KeyringController_default
1289
1344
  };
1290
- //# sourceMappingURL=chunk-6HZWCYLD.mjs.map
1345
+ //# sourceMappingURL=chunk-SFPZOKV2.mjs.map