@metamask-previews/keyring-controller 15.0.0-preview-fb52b9eb → 15.0.0-preview-2036edd1

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 @@
3
3
 
4
4
 
5
5
 
6
- var _chunkQDPHKQONjs = require('./chunk-QDPHKQON.js');
6
+ var _chunkDNQK26H6js = require('./chunk-DNQK26H6.js');
7
7
 
8
8
  // src/KeyringController.ts
9
9
  var _util = require('@ethereumjs/util');
@@ -86,7 +86,7 @@ async function displayForKeyring(keyring) {
86
86
  accounts: accounts.map(_ethsigutil.normalize)
87
87
  };
88
88
  }
89
- var _controllerOperationMutex, _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, _updateVault, updateVault_fn, _getAccountsFromKeyrings, getAccountsFromKeyrings_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, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn, _withControllerLock, withControllerLock_fn, _withVaultLock, withVaultLock_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, _updateVault, updateVault_fn, _getAccountsFromKeyrings, getAccountsFromKeyrings_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.BaseController {
91
91
  /**
92
92
  * Creates a KeyringController instance.
@@ -124,14 +124,14 @@ var KeyringController = class extends _basecontroller.BaseController {
124
124
  * Constructor helper for registering this controller's messaging system
125
125
  * actions.
126
126
  */
127
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _registerMessageHandlers);
127
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _registerMessageHandlers);
128
128
  /**
129
129
  * Get the keyring builder for the given `type`.
130
130
  *
131
131
  * @param type - The type of keyring to get the builder for.
132
132
  * @returns The keyring builder, or undefined if none exists.
133
133
  */
134
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _getKeyringBuilderForType);
134
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _getKeyringBuilderForType);
135
135
  /**
136
136
  * Add qr hardware keyring.
137
137
  *
@@ -139,15 +139,15 @@ var KeyringController = class extends _basecontroller.BaseController {
139
139
  * @throws If a QRKeyring builder is not provided
140
140
  * when initializing the controller
141
141
  */
142
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _addQRKeyring);
142
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _addQRKeyring);
143
143
  /**
144
144
  * Subscribe to a QRKeyring state change events and
145
145
  * forward them through the messaging system.
146
146
  *
147
147
  * @param qrKeyring - The QRKeyring instance to subscribe to
148
148
  */
149
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _subscribeToQRKeyringEvents);
150
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _unsubscribeFromQRKeyringsEvents);
149
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _subscribeToQRKeyringEvents);
150
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _unsubscribeFromQRKeyringsEvents);
151
151
  /**
152
152
  * Create new vault with an initial keyring
153
153
  *
@@ -162,14 +162,14 @@ var KeyringController = class extends _basecontroller.BaseController {
162
162
  * @param keyring.opts - Optional parameters required to instantiate the keyring.
163
163
  * @returns A promise that resolves to the state.
164
164
  */
165
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _createNewVaultWithKeyring);
165
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _createNewVaultWithKeyring);
166
166
  /**
167
167
  * Get the updated array of each keyring's type and
168
168
  * accounts list.
169
169
  *
170
170
  * @returns A promise resolving to the updated keyrings array.
171
171
  */
172
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _getUpdatedKeyrings);
172
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _getUpdatedKeyrings);
173
173
  /**
174
174
  * Unlock Keyrings, decrypting the vault and deserializing all
175
175
  * keyrings contained in it, using a password or an encryption key with salt.
@@ -179,20 +179,20 @@ var KeyringController = class extends _basecontroller.BaseController {
179
179
  * @param encryptionSalt - The salt used to encrypt the vault.
180
180
  * @returns A promise resolving to the deserialized keyrings array.
181
181
  */
182
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _unlockKeyrings);
182
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _unlockKeyrings);
183
183
  /**
184
184
  * Update the vault with the current keyrings.
185
185
  *
186
186
  * @returns A promise resolving to `true` if the operation is successful.
187
187
  */
188
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _updateVault);
188
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _updateVault);
189
189
  /**
190
190
  * Retrieves all the accounts from keyrings instances
191
191
  * that are currently in memory.
192
192
  *
193
193
  * @returns A promise resolving to an array of accounts.
194
194
  */
195
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _getAccountsFromKeyrings);
195
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _getAccountsFromKeyrings);
196
196
  /**
197
197
  * Create a new keyring, ensuring that the first account is
198
198
  * also created.
@@ -201,7 +201,7 @@ var KeyringController = class extends _basecontroller.BaseController {
201
201
  * @param opts - Optional parameters required to instantiate the keyring.
202
202
  * @returns A promise that resolves if the operation is successful.
203
203
  */
204
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _createKeyringWithFirstAccount);
204
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _createKeyringWithFirstAccount);
205
205
  /**
206
206
  * Instantiate, initialize and return a new keyring of the given `type`,
207
207
  * using the given `opts`. The keyring is built using the keyring builder
@@ -214,7 +214,7 @@ var KeyringController = class extends _basecontroller.BaseController {
214
214
  * @returns The new keyring.
215
215
  * @throws If the keyring includes duplicated accounts.
216
216
  */
217
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _newKeyring);
217
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _newKeyring);
218
218
  /**
219
219
  * Remove all managed keyrings, destroying all their
220
220
  * instances in memory.
@@ -222,7 +222,7 @@ var KeyringController = class extends _basecontroller.BaseController {
222
222
  * @param options - Operations options.
223
223
  * @param options.skipStateUpdate - Whether to skip updating the controller state.
224
224
  */
225
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _clearKeyrings);
225
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _clearKeyrings);
226
226
  /**
227
227
  * Restore a Keyring from a provided serialized payload.
228
228
  * On success, returns the resulting keyring instance.
@@ -230,7 +230,7 @@ var KeyringController = class extends _basecontroller.BaseController {
230
230
  * @param serialized - The serialized keyring.
231
231
  * @returns The deserialized keyring or undefined if the keyring type is unsupported.
232
232
  */
233
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _restoreKeyring);
233
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _restoreKeyring);
234
234
  /**
235
235
  * Destroy Keyring
236
236
  *
@@ -240,14 +240,14 @@ var KeyringController = class extends _basecontroller.BaseController {
240
240
  *
241
241
  * @param keyring - The keyring to destroy.
242
242
  */
243
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _destroyKeyring);
243
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _destroyKeyring);
244
244
  /**
245
245
  * Remove empty keyrings.
246
246
  *
247
247
  * Loops through the keyrings and removes the ones with empty accounts
248
248
  * (usually after removing the last / only account) from a keyring.
249
249
  */
250
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _removeEmptyKeyrings);
250
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _removeEmptyKeyrings);
251
251
  /**
252
252
  * Checks for duplicate keypairs, using the the first account in the given
253
253
  * array. Rejects if a duplicate is found.
@@ -258,33 +258,15 @@ var KeyringController = class extends _basecontroller.BaseController {
258
258
  * @param newAccountArray - Array of new accounts.
259
259
  * @returns The account, if no duplicate is found.
260
260
  */
261
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _checkForDuplicate);
261
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _checkForDuplicate);
262
262
  /**
263
263
  * Set the `isUnlocked` to true and notify listeners
264
264
  * through the messenger.
265
265
  *
266
266
  * @fires KeyringController:unlock
267
267
  */
268
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _setUnlocked);
269
- /**
270
- * Assert that the controller mutex is locked.
271
- *
272
- * @throws If the controller mutex is not locked.
273
- */
274
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _assertControllerMutexIsLocked);
275
- /**
276
- * Lock the controller mutex before executing the given function,
277
- * and release it after the function is resolved or after an
278
- * error is thrown.
279
- *
280
- * This wrapper ensures that each mutable operation that interacts with the
281
- * controller and that changes its state is executed in a mutually exclusive way,
282
- * preventing unsafe concurrent access that could lead to unpredictable behavior.
283
- *
284
- * @param fn - The function to execute while the controller mutex is locked.
285
- * @returns The result of the function.
286
- */
287
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _withControllerLock);
268
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _setUnlocked);
269
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _getMemState);
288
270
  /**
289
271
  * Lock the vault mutex before executing the given function,
290
272
  * and release it after the function is resolved or after an
@@ -296,99 +278,100 @@ var KeyringController = class extends _basecontroller.BaseController {
296
278
  * @param fn - The function to execute while the vault mutex is locked.
297
279
  * @returns The result of the function.
298
280
  */
299
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _withVaultLock);
300
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _controllerOperationMutex, new (0, _asyncmutex.Mutex)());
301
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _vaultOperationMutex, new (0, _asyncmutex.Mutex)());
302
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _keyringBuilders, void 0);
303
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _keyrings, void 0);
304
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _unsupportedKeyrings, void 0);
305
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _password, void 0);
306
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _encryptor, void 0);
307
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _cacheEncryptionKey, void 0);
308
- _chunkQDPHKQONjs.__privateAdd.call(void 0, this, _qrKeyringStateListener, void 0);
309
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _keyringBuilders, keyringBuilders ? defaultKeyringBuilders.concat(keyringBuilders) : defaultKeyringBuilders);
310
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _encryptor, encryptor);
311
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _keyrings, []);
312
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _unsupportedKeyrings, []);
313
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _cacheEncryptionKey, Boolean(options.cacheEncryptionKey));
314
- if (_chunkQDPHKQONjs.__privateGet.call(void 0, this, _cacheEncryptionKey)) {
281
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _withVaultLock);
282
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _initVaultMutex, new (0, _asyncmutex.Mutex)());
283
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _vaultOperationMutex, new (0, _asyncmutex.Mutex)());
284
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _keyringBuilders, void 0);
285
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _keyrings, void 0);
286
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _unsupportedKeyrings, void 0);
287
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _password, void 0);
288
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _encryptor, void 0);
289
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _cacheEncryptionKey, void 0);
290
+ _chunkDNQK26H6js.__privateAdd.call(void 0, this, _qrKeyringStateListener, void 0);
291
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _keyringBuilders, keyringBuilders ? defaultKeyringBuilders.concat(keyringBuilders) : defaultKeyringBuilders);
292
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _encryptor, encryptor);
293
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _keyrings, []);
294
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _unsupportedKeyrings, []);
295
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _cacheEncryptionKey, Boolean(options.cacheEncryptionKey));
296
+ if (_chunkDNQK26H6js.__privateGet.call(void 0, this, _cacheEncryptionKey)) {
315
297
  assertIsExportableKeyEncryptor(encryptor);
316
298
  }
317
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
299
+ _chunkDNQK26H6js.__privateMethod.call(void 0, this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
318
300
  }
319
301
  /**
320
302
  * Adds a new account to the default (first) HD seed phrase keyring.
321
303
  *
322
304
  * @param accountCount - Number of accounts before adding a new one, used to
323
305
  * make the method idempotent.
324
- * @returns Promise resolving to the added account address.
306
+ * @returns Promise resolving to keyring current state and added account
307
+ * address.
325
308
  */
326
309
  async addNewAccount(accountCount) {
327
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
328
- const primaryKeyring = this.getKeyringsByType("HD Key Tree")[0];
329
- if (!primaryKeyring) {
330
- throw new Error("No HD keyring found");
310
+ const primaryKeyring = this.getKeyringsByType("HD Key Tree")[0];
311
+ if (!primaryKeyring) {
312
+ throw new Error("No HD keyring found");
313
+ }
314
+ const oldAccounts = await primaryKeyring.getAccounts();
315
+ if (accountCount && oldAccounts.length !== accountCount) {
316
+ if (accountCount > oldAccounts.length) {
317
+ throw new Error("Account out of sequence");
331
318
  }
332
- const oldAccounts = await primaryKeyring.getAccounts();
333
- if (accountCount && oldAccounts.length !== accountCount) {
334
- if (accountCount > oldAccounts.length) {
335
- throw new Error("Account out of sequence");
336
- }
337
- const existingAccount = oldAccounts[accountCount];
338
- if (!existingAccount) {
339
- throw new Error(`Can't find account at index ${accountCount}`);
340
- }
341
- return existingAccount;
319
+ const existingAccount = oldAccounts[accountCount];
320
+ if (!existingAccount) {
321
+ throw new Error(`Can't find account at index ${accountCount}`);
342
322
  }
343
- const [addedAccountAddress] = await primaryKeyring.addAccounts(1);
344
- await this.verifySeedPhrase();
345
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
346
- return addedAccountAddress;
347
- });
323
+ return {
324
+ keyringState: _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this),
325
+ addedAccountAddress: existingAccount
326
+ };
327
+ }
328
+ const [addedAccountAddress] = await primaryKeyring.addAccounts(1);
329
+ await this.verifySeedPhrase();
330
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
331
+ return {
332
+ keyringState: _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this),
333
+ addedAccountAddress
334
+ };
348
335
  }
349
336
  /**
350
337
  * Adds a new account to the specified keyring.
351
338
  *
352
339
  * @param keyring - Keyring to add the account to.
353
340
  * @param accountCount - Number of accounts before adding a new one, used to make the method idempotent.
354
- * @returns Promise resolving to the added account address
341
+ * @returns Promise resolving to keyring current state and added account
355
342
  */
356
343
  async addNewAccountForKeyring(keyring, accountCount) {
357
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
358
- const oldAccounts = await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
359
- if (accountCount && oldAccounts.length !== accountCount) {
360
- if (accountCount > oldAccounts.length) {
361
- throw new Error("Account out of sequence");
362
- }
363
- const existingAccount = oldAccounts[accountCount];
364
- _utils.assertIsStrictHexString.call(void 0, existingAccount);
365
- return existingAccount;
344
+ const oldAccounts = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
345
+ if (accountCount && oldAccounts.length !== accountCount) {
346
+ if (accountCount > oldAccounts.length) {
347
+ throw new Error("Account out of sequence");
366
348
  }
367
- await keyring.addAccounts(1);
368
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
369
- const addedAccountAddress = (await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this)).find(
370
- (selectedAddress) => !oldAccounts.includes(selectedAddress)
371
- );
372
- _utils.assertIsStrictHexString.call(void 0, addedAccountAddress);
373
- return addedAccountAddress;
374
- });
349
+ const existingAccount = oldAccounts[accountCount];
350
+ _utils.assertIsStrictHexString.call(void 0, existingAccount);
351
+ return existingAccount;
352
+ }
353
+ await keyring.addAccounts(1);
354
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
355
+ const addedAccountAddress = (await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this)).find(
356
+ (selectedAddress) => !oldAccounts.includes(selectedAddress)
357
+ );
358
+ _utils.assertIsStrictHexString.call(void 0, addedAccountAddress);
359
+ return addedAccountAddress;
375
360
  }
376
361
  /**
377
362
  * Adds a new account to the default (first) HD seed phrase keyring without updating identities in preferences.
378
363
  *
379
- * @returns Promise resolving to the added account address.
364
+ * @returns Promise resolving to current state when the account is added.
380
365
  */
381
366
  async addNewAccountWithoutUpdate() {
382
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
383
- const primaryKeyring = this.getKeyringsByType("HD Key Tree")[0];
384
- if (!primaryKeyring) {
385
- throw new Error("No HD keyring found");
386
- }
387
- const [addedAccountAddress] = await primaryKeyring.addAccounts(1);
388
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
389
- await this.verifySeedPhrase();
390
- return addedAccountAddress;
391
- });
367
+ const primaryKeyring = this.getKeyringsByType("HD Key Tree")[0];
368
+ if (!primaryKeyring) {
369
+ throw new Error("No HD keyring found");
370
+ }
371
+ await primaryKeyring.addAccounts(1);
372
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
373
+ await this.verifySeedPhrase();
374
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
392
375
  }
393
376
  /**
394
377
  * Effectively the same as creating a new keychain then populating it
@@ -397,37 +380,45 @@ var KeyringController = class extends _basecontroller.BaseController {
397
380
  * @param password - Password to unlock keychain.
398
381
  * @param seed - A BIP39-compliant seed phrase as Uint8Array,
399
382
  * either as a string or an array of UTF-8 bytes that represent the string.
400
- * @returns Promise resolving when the operation ends successfully.
383
+ * @returns Promise resolving to the restored keychain object.
401
384
  */
402
385
  async createNewVaultAndRestore(password, seed) {
403
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
404
- if (!password || !password.length) {
405
- throw new Error("Invalid password");
406
- }
407
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _createNewVaultWithKeyring, createNewVaultWithKeyring_fn).call(this, password, {
386
+ const releaseLock = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _initVaultMutex).acquire();
387
+ if (!password || !password.length) {
388
+ throw new Error("Invalid password");
389
+ }
390
+ try {
391
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _createNewVaultWithKeyring, createNewVaultWithKeyring_fn).call(this, password, {
408
392
  type: "HD Key Tree" /* hd */,
409
393
  opts: {
410
394
  mnemonic: seed,
411
395
  numberOfAccounts: 1
412
396
  }
413
397
  });
414
- });
398
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
399
+ } finally {
400
+ releaseLock();
401
+ }
415
402
  }
416
403
  /**
417
404
  * Create a new primary keychain and wipe any previous keychains.
418
405
  *
419
406
  * @param password - Password to unlock the new vault.
420
- * @returns Promise resolving when the operation ends successfully.
407
+ * @returns Newly-created keychain object.
421
408
  */
422
409
  async createNewVaultAndKeychain(password) {
423
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
424
- const accounts = await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
410
+ const releaseLock = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _initVaultMutex).acquire();
411
+ try {
412
+ const accounts = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
425
413
  if (!accounts.length) {
426
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _createNewVaultWithKeyring, createNewVaultWithKeyring_fn).call(this, password, {
414
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _createNewVaultWithKeyring, createNewVaultWithKeyring_fn).call(this, password, {
427
415
  type: "HD Key Tree" /* hd */
428
416
  });
429
417
  }
430
- });
418
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
419
+ } finally {
420
+ releaseLock();
421
+ }
431
422
  }
432
423
  /**
433
424
  * Adds a new keyring of the given `type`.
@@ -441,7 +432,7 @@ var KeyringController = class extends _basecontroller.BaseController {
441
432
  if (type === "QR Hardware Wallet Device" /* qr */) {
442
433
  return this.getOrAddQRKeyring();
443
434
  }
444
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, type, opts, true));
435
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, type, opts, true);
445
436
  }
446
437
  /**
447
438
  * Method to verify a given password validity. Throws an
@@ -453,7 +444,7 @@ var KeyringController = class extends _basecontroller.BaseController {
453
444
  if (!this.state.vault) {
454
445
  throw new Error("KeyringController - Cannot unlock without a previous vault." /* VaultError */);
455
446
  }
456
- await _chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor).decrypt(password, this.state.vault);
447
+ await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).decrypt(password, this.state.vault);
457
448
  }
458
449
  /**
459
450
  * Returns the status of the vault.
@@ -471,8 +462,8 @@ var KeyringController = class extends _basecontroller.BaseController {
471
462
  */
472
463
  async exportSeedPhrase(password) {
473
464
  await this.verifyPassword(password);
474
- assertHasUint8ArrayMnemonic(_chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings)[0]);
475
- return _chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings)[0].mnemonic;
465
+ assertHasUint8ArrayMnemonic(_chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings)[0]);
466
+ return _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings)[0].mnemonic;
476
467
  }
477
468
  /**
478
469
  * Gets the private key from the keyring controlling an address.
@@ -497,10 +488,7 @@ var KeyringController = class extends _basecontroller.BaseController {
497
488
  * @returns A promise resolving to an array of addresses.
498
489
  */
499
490
  async getAccounts() {
500
- return this.state.keyrings.reduce(
501
- (accounts, keyring) => accounts.concat(keyring.accounts),
502
- []
503
- );
491
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
504
492
  }
505
493
  /**
506
494
  * Get encryption public key.
@@ -551,7 +539,7 @@ var KeyringController = class extends _basecontroller.BaseController {
551
539
  async getKeyringForAccount(account) {
552
540
  const hexed = _ethsigutil.normalize.call(void 0, account);
553
541
  const candidates = await Promise.all(
554
- _chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings).map(async (keyring) => {
542
+ _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).map(async (keyring) => {
555
543
  return Promise.all([keyring, keyring.getAccounts()]);
556
544
  })
557
545
  );
@@ -584,7 +572,7 @@ var KeyringController = class extends _basecontroller.BaseController {
584
572
  * @returns An array of keyrings of the given type.
585
573
  */
586
574
  getKeyringsByType(type) {
587
- return _chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings).filter((keyring) => keyring.type === type);
575
+ return _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).filter((keyring) => keyring.type === type);
588
576
  }
589
577
  /**
590
578
  * Persist all serialized keyrings in the vault.
@@ -593,7 +581,7 @@ var KeyringController = class extends _basecontroller.BaseController {
593
581
  * operation completes.
594
582
  */
595
583
  async persistAllKeyrings() {
596
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this));
584
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
597
585
  }
598
586
  /**
599
587
  * Imports an account with the specified import strategy.
@@ -601,88 +589,88 @@ var KeyringController = class extends _basecontroller.BaseController {
601
589
  * @param strategy - Import strategy name.
602
590
  * @param args - Array of arguments to pass to the underlying stategy.
603
591
  * @throws Will throw when passed an unrecognized strategy.
604
- * @returns Promise resolving to the imported account address.
592
+ * @returns Promise resolving to keyring current state and imported account
593
+ * address.
605
594
  */
606
595
  async importAccountWithStrategy(strategy, args) {
607
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
608
- let privateKey;
609
- switch (strategy) {
610
- case "privateKey":
611
- const [importedKey] = args;
612
- if (!importedKey) {
613
- throw new Error("Cannot import an empty key.");
614
- }
615
- const prefixed = _utils.add0x.call(void 0, importedKey);
616
- let bufferedPrivateKey;
617
- try {
618
- bufferedPrivateKey = _util.toBuffer.call(void 0, prefixed);
619
- } catch {
620
- throw new Error("Cannot import invalid private key.");
621
- }
622
- if (!_util.isValidPrivate.call(void 0, bufferedPrivateKey) || // ensures that the key is 64 bytes long
623
- _util.getBinarySize.call(void 0, prefixed) !== 64 + "0x".length) {
624
- throw new Error("Cannot import invalid private key.");
625
- }
626
- privateKey = _utils.remove0x.call(void 0, prefixed);
627
- break;
628
- case "json":
629
- let wallet;
630
- const [input, password] = args;
631
- try {
632
- wallet = _ethereumjswallet.thirdparty.fromEtherWallet(input, password);
633
- } catch (e) {
634
- wallet = wallet || await _ethereumjswallet2.default.fromV3(input, password, true);
635
- }
636
- privateKey = _utils.bytesToHex.call(void 0, wallet.getPrivateKey());
637
- break;
638
- default:
639
- throw new Error(`Unexpected import strategy: '${strategy}'`);
640
- }
641
- const newKeyring = await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, "Simple Key Pair" /* simple */, [privateKey], true);
642
- const accounts = await newKeyring.getAccounts();
643
- return accounts[0];
644
- });
596
+ let privateKey;
597
+ switch (strategy) {
598
+ case "privateKey":
599
+ const [importedKey] = args;
600
+ if (!importedKey) {
601
+ throw new Error("Cannot import an empty key.");
602
+ }
603
+ const prefixed = _utils.add0x.call(void 0, importedKey);
604
+ let bufferedPrivateKey;
605
+ try {
606
+ bufferedPrivateKey = _util.toBuffer.call(void 0, prefixed);
607
+ } catch {
608
+ throw new Error("Cannot import invalid private key.");
609
+ }
610
+ if (!_util.isValidPrivate.call(void 0, bufferedPrivateKey) || // ensures that the key is 64 bytes long
611
+ _util.getBinarySize.call(void 0, prefixed) !== 64 + "0x".length) {
612
+ throw new Error("Cannot import invalid private key.");
613
+ }
614
+ privateKey = _utils.remove0x.call(void 0, prefixed);
615
+ break;
616
+ case "json":
617
+ let wallet;
618
+ const [input, password] = args;
619
+ try {
620
+ wallet = _ethereumjswallet.thirdparty.fromEtherWallet(input, password);
621
+ } catch (e) {
622
+ wallet = wallet || await _ethereumjswallet2.default.fromV3(input, password, true);
623
+ }
624
+ privateKey = _utils.bytesToHex.call(void 0, wallet.getPrivateKey());
625
+ break;
626
+ default:
627
+ throw new Error(`Unexpected import strategy: '${strategy}'`);
628
+ }
629
+ const newKeyring = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, "Simple Key Pair" /* simple */, [privateKey], true);
630
+ const accounts = await newKeyring.getAccounts();
631
+ return {
632
+ keyringState: _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this),
633
+ importedAccountAddress: accounts[0]
634
+ };
645
635
  }
646
636
  /**
647
637
  * Removes an account from keyring state.
648
638
  *
649
639
  * @param address - Address of the account to remove.
650
640
  * @fires KeyringController:accountRemoved
651
- * @returns Promise resolving when the account is removed.
641
+ * @returns Promise resolving current state when this account removal completes.
652
642
  */
653
643
  async removeAccount(address) {
654
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
655
- const keyring = await this.getKeyringForAccount(
656
- address
657
- );
658
- if (!keyring.removeAccount) {
659
- throw new Error("`KeyringController - The keyring for the current address does not support the method removeAccount" /* UnsupportedRemoveAccount */);
660
- }
661
- await keyring.removeAccount(address);
662
- const accounts = await keyring.getAccounts();
663
- if (accounts.length === 0) {
664
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _removeEmptyKeyrings, removeEmptyKeyrings_fn).call(this);
665
- }
666
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
667
- });
644
+ const keyring = await this.getKeyringForAccount(
645
+ address
646
+ );
647
+ if (!keyring.removeAccount) {
648
+ throw new Error("`KeyringController - The keyring for the current address does not support the method removeAccount" /* UnsupportedRemoveAccount */);
649
+ }
650
+ await keyring.removeAccount(address);
651
+ const accounts = await keyring.getAccounts();
652
+ if (accounts.length === 0) {
653
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _removeEmptyKeyrings, removeEmptyKeyrings_fn).call(this);
654
+ }
655
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
668
656
  this.messagingSystem.publish(`${name}:accountRemoved`, address);
657
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
669
658
  }
670
659
  /**
671
660
  * Deallocates all secrets and locks the wallet.
672
661
  *
673
- * @returns Promise resolving when the operation completes.
662
+ * @returns Promise resolving to current state.
674
663
  */
675
664
  async setLocked() {
676
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
677
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _unsubscribeFromQRKeyringsEvents, unsubscribeFromQRKeyringsEvents_fn).call(this);
678
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _password, void 0);
679
- this.update((state) => {
680
- state.isUnlocked = false;
681
- state.keyrings = [];
682
- });
683
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this);
684
- this.messagingSystem.publish(`${name}:lock`);
665
+ _chunkDNQK26H6js.__privateMethod.call(void 0, this, _unsubscribeFromQRKeyringsEvents, unsubscribeFromQRKeyringsEvents_fn).call(this);
666
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _password, void 0);
667
+ this.update((state) => {
668
+ state.isUnlocked = false;
669
+ state.keyrings = [];
685
670
  });
671
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this);
672
+ this.messagingSystem.publish(`${name}:lock`);
673
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
686
674
  }
687
675
  /**
688
676
  * Signs message by calling down into a specific keyring.
@@ -836,34 +824,32 @@ var KeyringController = class extends _basecontroller.BaseController {
836
824
  *
837
825
  * @param encryptionKey - Key to unlock the keychain.
838
826
  * @param encryptionSalt - Salt to unlock the keychain.
839
- * @returns Promise resolving when the operation completes.
827
+ * @returns Promise resolving to the current state.
840
828
  */
841
829
  async submitEncryptionKey(encryptionKey, encryptionSalt) {
842
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
843
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _keyrings, await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _unlockKeyrings, unlockKeyrings_fn).call(this, void 0, encryptionKey, encryptionSalt));
844
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _setUnlocked, setUnlocked_fn).call(this);
845
- const qrKeyring = this.getQRKeyring();
846
- if (qrKeyring) {
847
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn).call(this, qrKeyring);
848
- }
849
- });
830
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _keyrings, await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _unlockKeyrings, unlockKeyrings_fn).call(this, void 0, encryptionKey, encryptionSalt));
831
+ _chunkDNQK26H6js.__privateMethod.call(void 0, this, _setUnlocked, setUnlocked_fn).call(this);
832
+ const qrKeyring = this.getQRKeyring();
833
+ if (qrKeyring) {
834
+ _chunkDNQK26H6js.__privateMethod.call(void 0, this, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn).call(this, qrKeyring);
835
+ }
836
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
850
837
  }
851
838
  /**
852
839
  * Attempts to decrypt the current vault and load its keyrings,
853
840
  * using the given password.
854
841
  *
855
842
  * @param password - Password to unlock the keychain.
856
- * @returns Promise resolving when the operation completes.
843
+ * @returns Promise resolving to the current state.
857
844
  */
858
845
  async submitPassword(password) {
859
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
860
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _keyrings, await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _unlockKeyrings, unlockKeyrings_fn).call(this, password));
861
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _setUnlocked, setUnlocked_fn).call(this);
862
- const qrKeyring = this.getQRKeyring();
863
- if (qrKeyring) {
864
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn).call(this, qrKeyring);
865
- }
866
- });
846
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _keyrings, await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _unlockKeyrings, unlockKeyrings_fn).call(this, password));
847
+ _chunkDNQK26H6js.__privateMethod.call(void 0, this, _setUnlocked, setUnlocked_fn).call(this);
848
+ const qrKeyring = this.getQRKeyring();
849
+ if (qrKeyring) {
850
+ _chunkDNQK26H6js.__privateMethod.call(void 0, this, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn).call(this, qrKeyring);
851
+ }
852
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
867
853
  }
868
854
  /**
869
855
  * Verifies the that the seed phrase restores the current keychain's accounts.
@@ -881,7 +867,7 @@ var KeyringController = class extends _basecontroller.BaseController {
881
867
  if (accounts.length === 0) {
882
868
  throw new Error("Cannot verify an empty keyring.");
883
869
  }
884
- const hdKeyringBuilder = _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _getKeyringBuilderForType, getKeyringBuilderForType_fn).call(this, "HD Key Tree" /* hd */);
870
+ const hdKeyringBuilder = _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getKeyringBuilderForType, getKeyringBuilderForType_fn).call(this, "HD Key Tree" /* hd */);
885
871
  const hdKeyring = hdKeyringBuilder();
886
872
  await hdKeyring.deserialize({
887
873
  mnemonic: seedWords,
@@ -913,16 +899,14 @@ var KeyringController = class extends _basecontroller.BaseController {
913
899
  * @returns The added keyring
914
900
  */
915
901
  async getOrAddQRKeyring() {
916
- return this.getQRKeyring() || await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this));
902
+ return this.getQRKeyring() || await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this);
917
903
  }
918
904
  // TODO: Replace `any` with type
919
905
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
920
906
  async restoreQRKeyring(serialized) {
921
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
922
- const keyring = this.getQRKeyring() || await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this);
923
- keyring.deserialize(serialized);
924
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
925
- });
907
+ const keyring = this.getQRKeyring() || await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this);
908
+ keyring.deserialize(serialized);
909
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
926
910
  }
927
911
  async resetQRKeyringState() {
928
912
  (await this.getOrAddQRKeyring()).resetStore();
@@ -949,38 +933,34 @@ var KeyringController = class extends _basecontroller.BaseController {
949
933
  (await this.getOrAddQRKeyring()).cancelSync();
950
934
  }
951
935
  async connectQRHardware(page) {
952
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
953
- try {
954
- const keyring = this.getQRKeyring() || await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this);
955
- let accounts;
956
- switch (page) {
957
- case -1:
958
- accounts = await keyring.getPreviousPage();
959
- break;
960
- case 1:
961
- accounts = await keyring.getNextPage();
962
- break;
963
- default:
964
- accounts = await keyring.getFirstPage();
965
- }
966
- return accounts.map((account) => {
967
- return {
968
- ...account,
969
- balance: "0x0"
970
- };
971
- });
972
- } catch (e) {
973
- throw new Error(`Unspecified error when connect QR Hardware, ${e}`);
936
+ try {
937
+ const keyring = this.getQRKeyring() || await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this);
938
+ let accounts;
939
+ switch (page) {
940
+ case -1:
941
+ accounts = await keyring.getPreviousPage();
942
+ break;
943
+ case 1:
944
+ accounts = await keyring.getNextPage();
945
+ break;
946
+ default:
947
+ accounts = await keyring.getFirstPage();
974
948
  }
975
- });
949
+ return accounts.map((account) => {
950
+ return {
951
+ ...account,
952
+ balance: "0x0"
953
+ };
954
+ });
955
+ } catch (e) {
956
+ throw new Error(`Unspecified error when connect QR Hardware, ${e}`);
957
+ }
976
958
  }
977
959
  async unlockQRHardwareWalletAccount(index) {
978
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
979
- const keyring = this.getQRKeyring() || await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this);
980
- keyring.setAccountToUnlock(index);
981
- await keyring.addAccounts(1);
982
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
983
- });
960
+ const keyring = this.getQRKeyring() || await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this);
961
+ keyring.setAccountToUnlock(index);
962
+ await keyring.addAccounts(1);
963
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
984
964
  }
985
965
  async getAccountKeyringType(account) {
986
966
  const keyring = await this.getKeyringForAccount(
@@ -989,23 +969,21 @@ var KeyringController = class extends _basecontroller.BaseController {
989
969
  return keyring.type;
990
970
  }
991
971
  async forgetQRDevice() {
992
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async () => {
993
- const keyring = this.getQRKeyring();
994
- if (!keyring) {
995
- return { removedAccounts: [], remainingAccounts: [] };
996
- }
997
- const allAccounts = await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
998
- keyring.forgetDevice();
999
- const remainingAccounts = await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
1000
- const removedAccounts = allAccounts.filter(
1001
- (address) => !remainingAccounts.includes(address)
1002
- );
1003
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
1004
- return { removedAccounts, remainingAccounts };
1005
- });
972
+ const keyring = this.getQRKeyring();
973
+ if (!keyring) {
974
+ return { removedAccounts: [], remainingAccounts: [] };
975
+ }
976
+ const allAccounts = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
977
+ keyring.forgetDevice();
978
+ const remainingAccounts = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
979
+ const removedAccounts = allAccounts.filter(
980
+ (address) => !remainingAccounts.includes(address)
981
+ );
982
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
983
+ return { removedAccounts, remainingAccounts };
1006
984
  }
1007
985
  };
1008
- _controllerOperationMutex = new WeakMap();
986
+ _initVaultMutex = new WeakMap();
1009
987
  _vaultOperationMutex = new WeakMap();
1010
988
  _keyringBuilders = new WeakMap();
1011
989
  _keyrings = new WeakMap();
@@ -1067,29 +1045,28 @@ registerMessageHandlers_fn = function() {
1067
1045
  };
1068
1046
  _getKeyringBuilderForType = new WeakSet();
1069
1047
  getKeyringBuilderForType_fn = function(type) {
1070
- return _chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyringBuilders).find(
1048
+ return _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyringBuilders).find(
1071
1049
  (keyringBuilder) => keyringBuilder.type === type
1072
1050
  );
1073
1051
  };
1074
1052
  _addQRKeyring = new WeakSet();
1075
1053
  addQRKeyring_fn = async function() {
1076
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
1077
- const qrKeyring = await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, "QR Hardware Wallet Device" /* qr */, {
1054
+ const qrKeyring = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, "QR Hardware Wallet Device" /* qr */, {
1078
1055
  accounts: []
1079
1056
  });
1080
1057
  const accounts = await qrKeyring.getAccounts();
1081
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _checkForDuplicate, checkForDuplicate_fn).call(this, "QR Hardware Wallet Device" /* qr */, accounts);
1082
- _chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings).push(qrKeyring);
1083
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
1084
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn).call(this, qrKeyring);
1058
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _checkForDuplicate, checkForDuplicate_fn).call(this, "QR Hardware Wallet Device" /* qr */, accounts);
1059
+ _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).push(qrKeyring);
1060
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
1061
+ _chunkDNQK26H6js.__privateMethod.call(void 0, this, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn).call(this, qrKeyring);
1085
1062
  return qrKeyring;
1086
1063
  };
1087
1064
  _subscribeToQRKeyringEvents = new WeakSet();
1088
1065
  subscribeToQRKeyringEvents_fn = function(qrKeyring) {
1089
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _qrKeyringStateListener, (state) => {
1066
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _qrKeyringStateListener, (state) => {
1090
1067
  this.messagingSystem.publish(`${name}:qrKeyringStateChange`, state);
1091
1068
  });
1092
- qrKeyring.getMemStore().subscribe(_chunkQDPHKQONjs.__privateGet.call(void 0, this, _qrKeyringStateListener));
1069
+ qrKeyring.getMemStore().subscribe(_chunkDNQK26H6js.__privateGet.call(void 0, this, _qrKeyringStateListener));
1093
1070
  };
1094
1071
  _unsubscribeFromQRKeyringsEvents = new WeakSet();
1095
1072
  unsubscribeFromQRKeyringsEvents_fn = function() {
@@ -1097,45 +1074,45 @@ unsubscribeFromQRKeyringsEvents_fn = function() {
1097
1074
  "QR Hardware Wallet Device" /* qr */
1098
1075
  );
1099
1076
  qrKeyrings.forEach((qrKeyring) => {
1100
- if (_chunkQDPHKQONjs.__privateGet.call(void 0, this, _qrKeyringStateListener)) {
1101
- qrKeyring.getMemStore().unsubscribe(_chunkQDPHKQONjs.__privateGet.call(void 0, this, _qrKeyringStateListener));
1077
+ if (_chunkDNQK26H6js.__privateGet.call(void 0, this, _qrKeyringStateListener)) {
1078
+ qrKeyring.getMemStore().unsubscribe(_chunkDNQK26H6js.__privateGet.call(void 0, this, _qrKeyringStateListener));
1102
1079
  }
1103
1080
  });
1104
1081
  };
1105
1082
  _createNewVaultWithKeyring = new WeakSet();
1106
1083
  createNewVaultWithKeyring_fn = async function(password, keyring) {
1107
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
1108
1084
  if (typeof password !== "string") {
1109
1085
  throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
1110
1086
  }
1111
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _password, password);
1112
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this);
1113
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _createKeyringWithFirstAccount, createKeyringWithFirstAccount_fn).call(this, keyring.type, keyring.opts);
1114
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _setUnlocked, setUnlocked_fn).call(this);
1087
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _password, password);
1088
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this);
1089
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _createKeyringWithFirstAccount, createKeyringWithFirstAccount_fn).call(this, keyring.type, keyring.opts);
1090
+ _chunkDNQK26H6js.__privateMethod.call(void 0, this, _setUnlocked, setUnlocked_fn).call(this);
1091
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
1115
1092
  };
1116
1093
  _getUpdatedKeyrings = new WeakSet();
1117
1094
  getUpdatedKeyrings_fn = async function() {
1118
- return Promise.all(_chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings).map(displayForKeyring));
1095
+ return Promise.all(_chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).map(displayForKeyring));
1119
1096
  };
1120
1097
  _unlockKeyrings = new WeakSet();
1121
1098
  unlockKeyrings_fn = async function(password, encryptionKey, encryptionSalt) {
1122
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withVaultLock, withVaultLock_fn).call(this, async ({ releaseLock }) => {
1099
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _withVaultLock, withVaultLock_fn).call(this, async ({ releaseLock }) => {
1123
1100
  const encryptedVault = this.state.vault;
1124
1101
  if (!encryptedVault) {
1125
1102
  throw new Error("KeyringController - Cannot unlock without a previous vault." /* VaultError */);
1126
1103
  }
1127
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this, { skipStateUpdate: true });
1104
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this, { skipStateUpdate: true });
1128
1105
  let vault;
1129
1106
  const updatedState = {};
1130
- if (_chunkQDPHKQONjs.__privateGet.call(void 0, this, _cacheEncryptionKey)) {
1131
- assertIsExportableKeyEncryptor(_chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor));
1107
+ if (_chunkDNQK26H6js.__privateGet.call(void 0, this, _cacheEncryptionKey)) {
1108
+ assertIsExportableKeyEncryptor(_chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor));
1132
1109
  if (password) {
1133
- const result = await _chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor).decryptWithDetail(
1110
+ const result = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).decryptWithDetail(
1134
1111
  password,
1135
1112
  encryptedVault
1136
1113
  );
1137
1114
  vault = result.vault;
1138
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _password, password);
1115
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _password, password);
1139
1116
  updatedState.encryptionKey = result.exportedKeyString;
1140
1117
  updatedState.encryptionSalt = result.salt;
1141
1118
  } else {
@@ -1146,8 +1123,8 @@ unlockKeyrings_fn = async function(password, encryptionKey, encryptionSalt) {
1146
1123
  if (typeof encryptionKey !== "string") {
1147
1124
  throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
1148
1125
  }
1149
- const key = await _chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor).importKey(encryptionKey);
1150
- vault = await _chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor).decryptWithKey(
1126
+ const key = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).importKey(encryptionKey);
1127
+ vault = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).decryptWithKey(
1151
1128
  key,
1152
1129
  parsedEncryptedVault
1153
1130
  );
@@ -1158,14 +1135,14 @@ unlockKeyrings_fn = async function(password, encryptionKey, encryptionSalt) {
1158
1135
  if (typeof password !== "string") {
1159
1136
  throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
1160
1137
  }
1161
- vault = await _chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor).decrypt(password, encryptedVault);
1162
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _password, password);
1138
+ vault = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).decrypt(password, encryptedVault);
1139
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _password, password);
1163
1140
  }
1164
1141
  if (!isSerializedKeyringsArray(vault)) {
1165
1142
  throw new Error("KeyringController - The decrypted vault has an unexpected shape." /* VaultDataError */);
1166
1143
  }
1167
- await Promise.all(vault.map(_chunkQDPHKQONjs.__privateMethod.call(void 0, this, _restoreKeyring, restoreKeyring_fn).bind(this)));
1168
- const updatedKeyrings = await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _getUpdatedKeyrings, getUpdatedKeyrings_fn).call(this);
1144
+ await Promise.all(vault.map(_chunkDNQK26H6js.__privateMethod.call(void 0, this, _restoreKeyring, restoreKeyring_fn).bind(this)));
1145
+ const updatedKeyrings = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getUpdatedKeyrings, getUpdatedKeyrings_fn).call(this);
1169
1146
  this.update((state) => {
1170
1147
  state.keyrings = updatedKeyrings;
1171
1148
  if (updatedState.encryptionKey || updatedState.encryptionSalt) {
@@ -1173,22 +1150,22 @@ unlockKeyrings_fn = async function(password, encryptionKey, encryptionSalt) {
1173
1150
  state.encryptionSalt = updatedState.encryptionSalt;
1174
1151
  }
1175
1152
  });
1176
- if (_chunkQDPHKQONjs.__privateGet.call(void 0, this, _password) && (!_chunkQDPHKQONjs.__privateGet.call(void 0, this, _cacheEncryptionKey) || !encryptionKey) && _chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor).isVaultUpdated && !_chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor).isVaultUpdated(encryptedVault)) {
1153
+ if (_chunkDNQK26H6js.__privateGet.call(void 0, this, _password) && (!_chunkDNQK26H6js.__privateGet.call(void 0, this, _cacheEncryptionKey) || !encryptionKey) && _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).isVaultUpdated && !_chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).isVaultUpdated(encryptedVault)) {
1177
1154
  releaseLock();
1178
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
1155
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
1179
1156
  }
1180
- return _chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings);
1157
+ return _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings);
1181
1158
  });
1182
1159
  };
1183
1160
  _updateVault = new WeakSet();
1184
1161
  updateVault_fn = function() {
1185
- return _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _withVaultLock, withVaultLock_fn).call(this, async () => {
1162
+ return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _withVaultLock, withVaultLock_fn).call(this, async () => {
1186
1163
  const { encryptionKey, encryptionSalt } = this.state;
1187
- if (!_chunkQDPHKQONjs.__privateGet.call(void 0, this, _password) && !encryptionKey) {
1164
+ if (!_chunkDNQK26H6js.__privateGet.call(void 0, this, _password) && !encryptionKey) {
1188
1165
  throw new Error("KeyringController - Cannot persist vault without password and encryption key" /* MissingCredentials */);
1189
1166
  }
1190
1167
  const serializedKeyrings = await Promise.all(
1191
- _chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings).map(async (keyring) => {
1168
+ _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).map(async (keyring) => {
1192
1169
  const [type, data] = await Promise.all([
1193
1170
  keyring.type,
1194
1171
  keyring.serialize()
@@ -1196,42 +1173,42 @@ updateVault_fn = function() {
1196
1173
  return { type, data };
1197
1174
  })
1198
1175
  );
1199
- serializedKeyrings.push(..._chunkQDPHKQONjs.__privateGet.call(void 0, this, _unsupportedKeyrings));
1176
+ serializedKeyrings.push(..._chunkDNQK26H6js.__privateGet.call(void 0, this, _unsupportedKeyrings));
1200
1177
  if (!serializedKeyrings.some((keyring) => keyring.type === "HD Key Tree" /* hd */)) {
1201
1178
  throw new Error("KeyringController - No HD Keyring found" /* NoHdKeyring */);
1202
1179
  }
1203
1180
  const updatedState = {};
1204
- if (_chunkQDPHKQONjs.__privateGet.call(void 0, this, _cacheEncryptionKey)) {
1205
- assertIsExportableKeyEncryptor(_chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor));
1181
+ if (_chunkDNQK26H6js.__privateGet.call(void 0, this, _cacheEncryptionKey)) {
1182
+ assertIsExportableKeyEncryptor(_chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor));
1206
1183
  if (encryptionKey) {
1207
- const key = await _chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor).importKey(encryptionKey);
1208
- const vaultJSON = await _chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor).encryptWithKey(
1184
+ const key = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).importKey(encryptionKey);
1185
+ const vaultJSON = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).encryptWithKey(
1209
1186
  key,
1210
1187
  serializedKeyrings
1211
1188
  );
1212
1189
  vaultJSON.salt = encryptionSalt;
1213
1190
  updatedState.vault = JSON.stringify(vaultJSON);
1214
- } else if (_chunkQDPHKQONjs.__privateGet.call(void 0, this, _password)) {
1215
- const { vault: newVault, exportedKeyString } = await _chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor).encryptWithDetail(
1216
- _chunkQDPHKQONjs.__privateGet.call(void 0, this, _password),
1191
+ } else if (_chunkDNQK26H6js.__privateGet.call(void 0, this, _password)) {
1192
+ const { vault: newVault, exportedKeyString } = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).encryptWithDetail(
1193
+ _chunkDNQK26H6js.__privateGet.call(void 0, this, _password),
1217
1194
  serializedKeyrings
1218
1195
  );
1219
1196
  updatedState.vault = newVault;
1220
1197
  updatedState.encryptionKey = exportedKeyString;
1221
1198
  }
1222
1199
  } else {
1223
- if (typeof _chunkQDPHKQONjs.__privateGet.call(void 0, this, _password) !== "string") {
1200
+ if (typeof _chunkDNQK26H6js.__privateGet.call(void 0, this, _password) !== "string") {
1224
1201
  throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
1225
1202
  }
1226
- updatedState.vault = await _chunkQDPHKQONjs.__privateGet.call(void 0, this, _encryptor).encrypt(
1227
- _chunkQDPHKQONjs.__privateGet.call(void 0, this, _password),
1203
+ updatedState.vault = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).encrypt(
1204
+ _chunkDNQK26H6js.__privateGet.call(void 0, this, _password),
1228
1205
  serializedKeyrings
1229
1206
  );
1230
1207
  }
1231
1208
  if (!updatedState.vault) {
1232
1209
  throw new Error("KeyringController - Cannot persist vault without vault information" /* MissingVaultData */);
1233
1210
  }
1234
- const updatedKeyrings = await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _getUpdatedKeyrings, getUpdatedKeyrings_fn).call(this);
1211
+ const updatedKeyrings = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getUpdatedKeyrings, getUpdatedKeyrings_fn).call(this);
1235
1212
  this.update((state) => {
1236
1213
  state.vault = updatedState.vault;
1237
1214
  state.keyrings = updatedKeyrings;
@@ -1245,7 +1222,7 @@ updateVault_fn = function() {
1245
1222
  };
1246
1223
  _getAccountsFromKeyrings = new WeakSet();
1247
1224
  getAccountsFromKeyrings_fn = async function() {
1248
- const keyrings = _chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings);
1225
+ const keyrings = _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings);
1249
1226
  const keyringArrays = await Promise.all(
1250
1227
  keyrings.map(async (keyring) => keyring.getAccounts())
1251
1228
  );
@@ -1256,8 +1233,7 @@ getAccountsFromKeyrings_fn = async function() {
1256
1233
  };
1257
1234
  _createKeyringWithFirstAccount = new WeakSet();
1258
1235
  createKeyringWithFirstAccount_fn = async function(type, opts) {
1259
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
1260
- const keyring = await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, type, opts, true);
1236
+ const keyring = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, type, opts, true);
1261
1237
  const [firstAccount] = await keyring.getAccounts();
1262
1238
  if (!firstAccount) {
1263
1239
  throw new Error("KeyringController - First Account not found." /* NoFirstAccount */);
@@ -1265,8 +1241,7 @@ createKeyringWithFirstAccount_fn = async function(type, opts) {
1265
1241
  };
1266
1242
  _newKeyring = new WeakSet();
1267
1243
  newKeyring_fn = async function(type, data, persist = false) {
1268
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
1269
- const keyringBuilder = _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _getKeyringBuilderForType, getKeyringBuilderForType_fn).call(this, type);
1244
+ const keyringBuilder = _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getKeyringBuilderForType, getKeyringBuilderForType_fn).call(this, type);
1270
1245
  if (!keyringBuilder) {
1271
1246
  throw new Error(
1272
1247
  `${"KeyringController - No keyringBuilder found for keyring" /* NoKeyringBuilder */}. Keyring type: ${type}`
@@ -1286,20 +1261,19 @@ newKeyring_fn = async function(type, data, persist = false) {
1286
1261
  keyring.generateRandomMnemonic();
1287
1262
  await keyring.addAccounts(1);
1288
1263
  }
1289
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _checkForDuplicate, checkForDuplicate_fn).call(this, type, await keyring.getAccounts());
1264
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _checkForDuplicate, checkForDuplicate_fn).call(this, type, await keyring.getAccounts());
1290
1265
  if (persist) {
1291
- _chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings).push(keyring);
1292
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
1266
+ _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).push(keyring);
1267
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
1293
1268
  }
1294
1269
  return keyring;
1295
1270
  };
1296
1271
  _clearKeyrings = new WeakSet();
1297
1272
  clearKeyrings_fn = async function(options = { skipStateUpdate: false }) {
1298
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
1299
- for (const keyring of _chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings)) {
1300
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _destroyKeyring, destroyKeyring_fn).call(this, keyring);
1273
+ for (const keyring of _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings)) {
1274
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _destroyKeyring, destroyKeyring_fn).call(this, keyring);
1301
1275
  }
1302
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _keyrings, []);
1276
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _keyrings, []);
1303
1277
  if (!options.skipStateUpdate) {
1304
1278
  this.update((state) => {
1305
1279
  state.keyrings = [];
@@ -1308,15 +1282,14 @@ clearKeyrings_fn = async function(options = { skipStateUpdate: false }) {
1308
1282
  };
1309
1283
  _restoreKeyring = new WeakSet();
1310
1284
  restoreKeyring_fn = async function(serialized) {
1311
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
1312
1285
  try {
1313
1286
  const { type, data } = serialized;
1314
- const keyring = await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, type, data);
1287
+ const keyring = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, type, data);
1315
1288
  await keyring.getAccounts();
1316
- _chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings).push(keyring);
1289
+ _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).push(keyring);
1317
1290
  return keyring;
1318
1291
  } catch (_) {
1319
- _chunkQDPHKQONjs.__privateGet.call(void 0, this, _unsupportedKeyrings).push(serialized);
1292
+ _chunkDNQK26H6js.__privateGet.call(void 0, this, _unsupportedKeyrings).push(serialized);
1320
1293
  return void 0;
1321
1294
  }
1322
1295
  };
@@ -1326,23 +1299,22 @@ destroyKeyring_fn = async function(keyring) {
1326
1299
  };
1327
1300
  _removeEmptyKeyrings = new WeakSet();
1328
1301
  removeEmptyKeyrings_fn = async function() {
1329
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
1330
1302
  const validKeyrings = [];
1331
1303
  await Promise.all(
1332
- _chunkQDPHKQONjs.__privateGet.call(void 0, this, _keyrings).map(async (keyring) => {
1304
+ _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).map(async (keyring) => {
1333
1305
  const accounts = await keyring.getAccounts();
1334
1306
  if (accounts.length > 0) {
1335
1307
  validKeyrings.push(keyring);
1336
1308
  } else {
1337
- await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _destroyKeyring, destroyKeyring_fn).call(this, keyring);
1309
+ await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _destroyKeyring, destroyKeyring_fn).call(this, keyring);
1338
1310
  }
1339
1311
  })
1340
1312
  );
1341
- _chunkQDPHKQONjs.__privateSet.call(void 0, this, _keyrings, validKeyrings);
1313
+ _chunkDNQK26H6js.__privateSet.call(void 0, this, _keyrings, validKeyrings);
1342
1314
  };
1343
1315
  _checkForDuplicate = new WeakSet();
1344
1316
  checkForDuplicate_fn = async function(type, newAccountArray) {
1345
- const accounts = await _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
1317
+ const accounts = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
1346
1318
  switch (type) {
1347
1319
  case "Simple Key Pair" /* simple */: {
1348
1320
  const isIncluded = Boolean(
@@ -1362,35 +1334,27 @@ checkForDuplicate_fn = async function(type, newAccountArray) {
1362
1334
  };
1363
1335
  _setUnlocked = new WeakSet();
1364
1336
  setUnlocked_fn = function() {
1365
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
1366
1337
  this.update((state) => {
1367
1338
  state.isUnlocked = true;
1368
1339
  });
1369
1340
  this.messagingSystem.publish(`${name}:unlock`);
1370
1341
  };
1371
- _assertControllerMutexIsLocked = new WeakSet();
1372
- assertControllerMutexIsLocked_fn = function() {
1373
- if (!_chunkQDPHKQONjs.__privateGet.call(void 0, this, _controllerOperationMutex).isLocked()) {
1374
- throw new Error("KeyringController - attempt to update vault during a non mutually exclusive operation" /* ControllerLockRequired */);
1375
- }
1376
- };
1377
- _withControllerLock = new WeakSet();
1378
- withControllerLock_fn = async function(fn) {
1379
- return withLock(_chunkQDPHKQONjs.__privateGet.call(void 0, this, _controllerOperationMutex), fn);
1342
+ _getMemState = new WeakSet();
1343
+ getMemState_fn = function() {
1344
+ return {
1345
+ isUnlocked: this.state.isUnlocked,
1346
+ keyrings: this.state.keyrings
1347
+ };
1380
1348
  };
1381
1349
  _withVaultLock = new WeakSet();
1382
1350
  withVaultLock_fn = async function(fn) {
1383
- _chunkQDPHKQONjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
1384
- return withLock(_chunkQDPHKQONjs.__privateGet.call(void 0, this, _vaultOperationMutex), fn);
1385
- };
1386
- async function withLock(mutex, fn) {
1387
- const releaseLock = await mutex.acquire();
1351
+ const releaseLock = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _vaultOperationMutex).acquire();
1388
1352
  try {
1389
1353
  return await fn({ releaseLock });
1390
1354
  } finally {
1391
1355
  releaseLock();
1392
1356
  }
1393
- }
1357
+ };
1394
1358
  var KeyringController_default = KeyringController;
1395
1359
 
1396
1360
 
@@ -1403,4 +1367,4 @@ var KeyringController_default = KeyringController;
1403
1367
 
1404
1368
 
1405
1369
  exports.KeyringTypes = KeyringTypes; exports.isCustodyKeyring = isCustodyKeyring; exports.AccountImportStrategy = AccountImportStrategy; exports.SignTypedDataVersion = SignTypedDataVersion; exports.keyringBuilderFactory = keyringBuilderFactory; exports.getDefaultKeyringState = getDefaultKeyringState; exports.KeyringController = KeyringController; exports.KeyringController_default = KeyringController_default;
1406
- //# sourceMappingURL=chunk-ISACMNF3.js.map
1370
+ //# sourceMappingURL=chunk-STOYI7AT.js.map