@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.
- package/CHANGELOG.md +10 -1
- package/dist/KeyringController.js +3 -3
- package/dist/KeyringController.mjs +2 -2
- package/dist/{chunk-CHLPTPMZ.js → chunk-DNQK26H6.js} +2 -1
- package/dist/chunk-DNQK26H6.js.map +1 -0
- package/dist/{chunk-BVSGYW4D.js → chunk-LKJCRVNR.js} +263 -208
- package/dist/chunk-LKJCRVNR.js.map +1 -0
- package/dist/{chunk-6HZWCYLD.mjs → chunk-SFPZOKV2.mjs} +175 -120
- package/dist/chunk-SFPZOKV2.mjs.map +1 -0
- package/dist/{chunk-NAAWD7HX.mjs → chunk-XPARO3LL.mjs} +2 -1
- package/dist/{chunk-NAAWD7HX.mjs.map → chunk-XPARO3LL.mjs.map} +1 -1
- package/dist/constants.js +2 -2
- package/dist/constants.mjs +1 -1
- package/dist/index.js +3 -3
- package/dist/index.mjs +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/KeyringController.d.ts +8 -6
- package/dist/types/KeyringController.d.ts.map +1 -1
- package/dist/types/constants.d.ts +2 -1
- package/dist/types/constants.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-6HZWCYLD.mjs.map +0 -1
- package/dist/chunk-BVSGYW4D.js.map +0 -1
- package/dist/chunk-CHLPTPMZ.js.map +0 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
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 _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,
|
|
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.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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
150
|
-
|
|
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,11 +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
|
-
|
|
165
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _createNewVaultWithKeyring);
|
|
166
166
|
/**
|
|
167
|
-
*
|
|
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
|
-
|
|
172
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, 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.
|
|
@@ -176,7 +179,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
176
179
|
* @param encryptionSalt - The salt used to encrypt the vault.
|
|
177
180
|
* @returns A promise resolving to the deserialized keyrings array.
|
|
178
181
|
*/
|
|
179
|
-
|
|
182
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _unlockKeyrings);
|
|
180
183
|
/**
|
|
181
184
|
* Create a new keyring, ensuring that the first account is
|
|
182
185
|
* also created.
|
|
@@ -185,7 +188,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
185
188
|
* @param opts - Optional parameters required to instantiate the keyring.
|
|
186
189
|
* @returns A promise that resolves if the operation is successful.
|
|
187
190
|
*/
|
|
188
|
-
|
|
191
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _createKeyringWithFirstAccount);
|
|
189
192
|
/**
|
|
190
193
|
* Instantiate, initialize and return a new keyring of the given `type`,
|
|
191
194
|
* using the given `opts`. The keyring is built using the keyring builder
|
|
@@ -195,12 +198,15 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
195
198
|
* @param data - The data to restore a previously serialized keyring.
|
|
196
199
|
* @returns The new keyring.
|
|
197
200
|
*/
|
|
198
|
-
|
|
201
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _newKeyring);
|
|
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
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _clearKeyrings);
|
|
204
210
|
/**
|
|
205
211
|
* Restore a Keyring from a provided serialized payload.
|
|
206
212
|
* On success, returns the resulting keyring instance.
|
|
@@ -208,7 +214,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
208
214
|
* @param serialized - The serialized keyring.
|
|
209
215
|
* @returns The deserialized keyring or undefined if the keyring type is unsupported.
|
|
210
216
|
*/
|
|
211
|
-
|
|
217
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _restoreKeyring);
|
|
212
218
|
/**
|
|
213
219
|
* Destroy Keyring
|
|
214
220
|
*
|
|
@@ -218,14 +224,14 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
218
224
|
*
|
|
219
225
|
* @param keyring - The keyring to destroy.
|
|
220
226
|
*/
|
|
221
|
-
|
|
227
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _destroyKeyring);
|
|
222
228
|
/**
|
|
223
229
|
* Remove empty keyrings.
|
|
224
230
|
*
|
|
225
231
|
* Loops through the keyrings and removes the ones with empty accounts
|
|
226
232
|
* (usually after removing the last / only account) from a keyring.
|
|
227
233
|
*/
|
|
228
|
-
|
|
234
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _removeEmptyKeyrings);
|
|
229
235
|
/**
|
|
230
236
|
* Checks for duplicate keypairs, using the the first account in the given
|
|
231
237
|
* array. Rejects if a duplicate is found.
|
|
@@ -236,32 +242,45 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
236
242
|
* @param newAccountArray - Array of new accounts.
|
|
237
243
|
* @returns The account, if no duplicate is found.
|
|
238
244
|
*/
|
|
239
|
-
|
|
245
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _checkForDuplicate);
|
|
240
246
|
/**
|
|
241
247
|
* Set the `isUnlocked` to true and notify listeners
|
|
242
248
|
* through the messenger.
|
|
243
249
|
*
|
|
244
250
|
* @fires KeyringController:unlock
|
|
245
251
|
*/
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
252
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _setUnlocked);
|
|
253
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _getMemState);
|
|
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
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _withVaultLock);
|
|
266
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _initVaultMutex, new (0, _asyncmutex.Mutex)());
|
|
267
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _vaultOperationMutex, new (0, _asyncmutex.Mutex)());
|
|
268
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _keyringBuilders, void 0);
|
|
269
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _keyrings, void 0);
|
|
270
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _unsupportedKeyrings, void 0);
|
|
271
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _password, void 0);
|
|
272
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _encryptor, void 0);
|
|
273
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _cacheEncryptionKey, void 0);
|
|
274
|
+
_chunkDNQK26H6js.__privateAdd.call(void 0, this, _qrKeyringStateListener, void 0);
|
|
275
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _keyringBuilders, keyringBuilders ? defaultKeyringBuilders.concat(keyringBuilders) : defaultKeyringBuilders);
|
|
276
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _encryptor, encryptor);
|
|
277
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _keyrings, []);
|
|
278
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _unsupportedKeyrings, []);
|
|
279
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _cacheEncryptionKey, Boolean(options.cacheEncryptionKey));
|
|
280
|
+
if (_chunkDNQK26H6js.__privateGet.call(void 0, this, _cacheEncryptionKey)) {
|
|
262
281
|
assertIsExportableKeyEncryptor(encryptor);
|
|
263
282
|
}
|
|
264
|
-
|
|
283
|
+
_chunkDNQK26H6js.__privateMethod.call(void 0, this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
|
|
265
284
|
}
|
|
266
285
|
/**
|
|
267
286
|
* Adds a new account to the default (first) HD seed phrase keyring.
|
|
@@ -276,15 +295,18 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
276
295
|
if (!primaryKeyring) {
|
|
277
296
|
throw new Error("No HD keyring found");
|
|
278
297
|
}
|
|
279
|
-
const oldAccounts = await
|
|
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
|
|
303
|
+
const existingAccount = oldAccounts[accountCount];
|
|
304
|
+
if (!existingAccount) {
|
|
305
|
+
throw new Error(`Can't find account at index ${accountCount}`);
|
|
306
|
+
}
|
|
285
307
|
return {
|
|
286
|
-
keyringState:
|
|
287
|
-
addedAccountAddress:
|
|
308
|
+
keyringState: _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this),
|
|
309
|
+
addedAccountAddress: existingAccount
|
|
288
310
|
};
|
|
289
311
|
}
|
|
290
312
|
const addedAccountAddress = await this.addNewAccountForKeyring(
|
|
@@ -292,7 +314,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
292
314
|
);
|
|
293
315
|
await this.verifySeedPhrase();
|
|
294
316
|
return {
|
|
295
|
-
keyringState:
|
|
317
|
+
keyringState: _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this),
|
|
296
318
|
addedAccountAddress
|
|
297
319
|
};
|
|
298
320
|
}
|
|
@@ -334,7 +356,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
334
356
|
await primaryKeyring.addAccounts(1);
|
|
335
357
|
await this.persistAllKeyrings();
|
|
336
358
|
await this.verifySeedPhrase();
|
|
337
|
-
return
|
|
359
|
+
return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
|
|
338
360
|
}
|
|
339
361
|
/**
|
|
340
362
|
* Effectively the same as creating a new keychain then populating it
|
|
@@ -346,19 +368,19 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
346
368
|
* @returns Promise resolving to the restored keychain object.
|
|
347
369
|
*/
|
|
348
370
|
async createNewVaultAndRestore(password, seed) {
|
|
349
|
-
const releaseLock = await this.
|
|
371
|
+
const releaseLock = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _initVaultMutex).acquire();
|
|
350
372
|
if (!password || !password.length) {
|
|
351
373
|
throw new Error("Invalid password");
|
|
352
374
|
}
|
|
353
375
|
try {
|
|
354
|
-
await
|
|
376
|
+
await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _createNewVaultWithKeyring, createNewVaultWithKeyring_fn).call(this, password, {
|
|
355
377
|
type: "HD Key Tree" /* hd */,
|
|
356
378
|
opts: {
|
|
357
379
|
mnemonic: seed,
|
|
358
380
|
numberOfAccounts: 1
|
|
359
381
|
}
|
|
360
382
|
});
|
|
361
|
-
return
|
|
383
|
+
return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
|
|
362
384
|
} finally {
|
|
363
385
|
releaseLock();
|
|
364
386
|
}
|
|
@@ -370,15 +392,15 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
370
392
|
* @returns Newly-created keychain object.
|
|
371
393
|
*/
|
|
372
394
|
async createNewVaultAndKeychain(password) {
|
|
373
|
-
const releaseLock = await this.
|
|
395
|
+
const releaseLock = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _initVaultMutex).acquire();
|
|
374
396
|
try {
|
|
375
397
|
const accounts = await this.getAccounts();
|
|
376
398
|
if (!accounts.length) {
|
|
377
|
-
await
|
|
399
|
+
await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _createNewVaultWithKeyring, createNewVaultWithKeyring_fn).call(this, password, {
|
|
378
400
|
type: "HD Key Tree" /* hd */
|
|
379
401
|
});
|
|
380
402
|
}
|
|
381
|
-
return
|
|
403
|
+
return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
|
|
382
404
|
} finally {
|
|
383
405
|
releaseLock();
|
|
384
406
|
}
|
|
@@ -395,7 +417,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
395
417
|
if (type === "QR Hardware Wallet Device" /* qr */) {
|
|
396
418
|
return this.getOrAddQRKeyring();
|
|
397
419
|
}
|
|
398
|
-
const keyring = await
|
|
420
|
+
const keyring = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, type, opts);
|
|
399
421
|
if (type === "HD Key Tree" /* hd */ && (!_utils.isObject.call(void 0, opts) || !opts.mnemonic)) {
|
|
400
422
|
if (!keyring.generateRandomMnemonic) {
|
|
401
423
|
throw new Error(
|
|
@@ -406,8 +428,8 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
406
428
|
await keyring.addAccounts(1);
|
|
407
429
|
}
|
|
408
430
|
const accounts = await keyring.getAccounts();
|
|
409
|
-
await
|
|
410
|
-
|
|
431
|
+
await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _checkForDuplicate, checkForDuplicate_fn).call(this, type, accounts);
|
|
432
|
+
_chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).push(keyring);
|
|
411
433
|
await this.persistAllKeyrings();
|
|
412
434
|
return keyring;
|
|
413
435
|
}
|
|
@@ -421,7 +443,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
421
443
|
if (!this.state.vault) {
|
|
422
444
|
throw new Error("KeyringController - Cannot unlock without a previous vault." /* VaultError */);
|
|
423
445
|
}
|
|
424
|
-
await
|
|
446
|
+
await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).decrypt(password, this.state.vault);
|
|
425
447
|
}
|
|
426
448
|
/**
|
|
427
449
|
* Returns the status of the vault.
|
|
@@ -439,8 +461,8 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
439
461
|
*/
|
|
440
462
|
async exportSeedPhrase(password) {
|
|
441
463
|
await this.verifyPassword(password);
|
|
442
|
-
assertHasUint8ArrayMnemonic(
|
|
443
|
-
return
|
|
464
|
+
assertHasUint8ArrayMnemonic(_chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings)[0]);
|
|
465
|
+
return _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings)[0].mnemonic;
|
|
444
466
|
}
|
|
445
467
|
/**
|
|
446
468
|
* Gets the private key from the keyring controlling an address.
|
|
@@ -460,12 +482,12 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
460
482
|
return await keyring.exportAccount(_ethsigutil.normalize.call(void 0, address));
|
|
461
483
|
}
|
|
462
484
|
/**
|
|
463
|
-
* Returns the public addresses of all accounts
|
|
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
|
*/
|
|
467
489
|
async getAccounts() {
|
|
468
|
-
const keyrings =
|
|
490
|
+
const keyrings = _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings);
|
|
469
491
|
const keyringArrays = await Promise.all(
|
|
470
492
|
keyrings.map(async (keyring) => keyring.getAccounts())
|
|
471
493
|
);
|
|
@@ -523,7 +545,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
523
545
|
async getKeyringForAccount(account) {
|
|
524
546
|
const hexed = _ethsigutil.normalize.call(void 0, account);
|
|
525
547
|
const candidates = await Promise.all(
|
|
526
|
-
|
|
548
|
+
_chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).map(async (keyring) => {
|
|
527
549
|
return Promise.all([keyring, keyring.getAccounts()]);
|
|
528
550
|
})
|
|
529
551
|
);
|
|
@@ -556,7 +578,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
556
578
|
* @returns An array of keyrings of the given type.
|
|
557
579
|
*/
|
|
558
580
|
getKeyringsByType(type) {
|
|
559
|
-
return
|
|
581
|
+
return _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).filter((keyring) => keyring.type === type);
|
|
560
582
|
}
|
|
561
583
|
/**
|
|
562
584
|
* Persist all serialized keyrings in the vault.
|
|
@@ -565,60 +587,66 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
565
587
|
* operation completes.
|
|
566
588
|
*/
|
|
567
589
|
async persistAllKeyrings() {
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
590
|
+
return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _withVaultLock, withVaultLock_fn).call(this, async () => {
|
|
591
|
+
const { encryptionKey, encryptionSalt } = this.state;
|
|
592
|
+
if (!_chunkDNQK26H6js.__privateGet.call(void 0, 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
|
+
_chunkDNQK26H6js.__privateGet.call(void 0, 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(..._chunkDNQK26H6js.__privateGet.call(void 0, 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 (_chunkDNQK26H6js.__privateGet.call(void 0, this, _cacheEncryptionKey)) {
|
|
610
|
+
assertIsExportableKeyEncryptor(_chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor));
|
|
611
|
+
if (encryptionKey) {
|
|
612
|
+
const key = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).importKey(encryptionKey);
|
|
613
|
+
const vaultJSON = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).encryptWithKey(
|
|
614
|
+
key,
|
|
615
|
+
serializedKeyrings
|
|
616
|
+
);
|
|
617
|
+
vaultJSON.salt = encryptionSalt;
|
|
618
|
+
updatedState.vault = JSON.stringify(vaultJSON);
|
|
619
|
+
} else if (_chunkDNQK26H6js.__privateGet.call(void 0, this, _password)) {
|
|
620
|
+
const { vault: newVault, exportedKeyString } = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).encryptWithDetail(
|
|
621
|
+
_chunkDNQK26H6js.__privateGet.call(void 0, this, _password),
|
|
622
|
+
serializedKeyrings
|
|
623
|
+
);
|
|
624
|
+
updatedState.vault = newVault;
|
|
625
|
+
updatedState.encryptionKey = exportedKeyString;
|
|
626
|
+
}
|
|
627
|
+
} else {
|
|
628
|
+
if (typeof _chunkDNQK26H6js.__privateGet.call(void 0, this, _password) !== "string") {
|
|
629
|
+
throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
|
|
630
|
+
}
|
|
631
|
+
updatedState.vault = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).encrypt(
|
|
632
|
+
_chunkDNQK26H6js.__privateGet.call(void 0, this, _password),
|
|
597
633
|
serializedKeyrings
|
|
598
634
|
);
|
|
599
|
-
vault = newVault;
|
|
600
|
-
newEncryptionKey = exportedKeyString;
|
|
601
635
|
}
|
|
602
|
-
|
|
603
|
-
|
|
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
|
-
|
|
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 _chunkCHLPTPMZjs.__privateMethod.call(void 0, this, _updateKeyringsInState, updateKeyringsInState_fn).call(this);
|
|
615
|
-
if (newEncryptionKey) {
|
|
639
|
+
const updatedKeyrings = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getUpdatedKeyrings, getUpdatedKeyrings_fn).call(this);
|
|
616
640
|
this.update((state) => {
|
|
617
|
-
state.
|
|
618
|
-
state.
|
|
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
|
-
|
|
648
|
+
return true;
|
|
649
|
+
});
|
|
622
650
|
}
|
|
623
651
|
/**
|
|
624
652
|
* Imports an account with the specified import strategy.
|
|
@@ -668,7 +696,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
668
696
|
]);
|
|
669
697
|
const accounts = await newKeyring.getAccounts();
|
|
670
698
|
return {
|
|
671
|
-
keyringState:
|
|
699
|
+
keyringState: _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this),
|
|
672
700
|
importedAccountAddress: accounts[0]
|
|
673
701
|
};
|
|
674
702
|
}
|
|
@@ -689,11 +717,11 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
689
717
|
await keyring.removeAccount(address);
|
|
690
718
|
const accounts = await keyring.getAccounts();
|
|
691
719
|
if (accounts.length === 0) {
|
|
692
|
-
await
|
|
720
|
+
await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _removeEmptyKeyrings, removeEmptyKeyrings_fn).call(this);
|
|
693
721
|
}
|
|
694
722
|
await this.persistAllKeyrings();
|
|
695
723
|
this.messagingSystem.publish(`${name}:accountRemoved`, address);
|
|
696
|
-
return
|
|
724
|
+
return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
|
|
697
725
|
}
|
|
698
726
|
/**
|
|
699
727
|
* Deallocates all secrets and locks the wallet.
|
|
@@ -701,15 +729,15 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
701
729
|
* @returns Promise resolving to current state.
|
|
702
730
|
*/
|
|
703
731
|
async setLocked() {
|
|
704
|
-
|
|
705
|
-
|
|
732
|
+
_chunkDNQK26H6js.__privateMethod.call(void 0, this, _unsubscribeFromQRKeyringsEvents, unsubscribeFromQRKeyringsEvents_fn).call(this);
|
|
733
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _password, void 0);
|
|
706
734
|
this.update((state) => {
|
|
707
735
|
state.isUnlocked = false;
|
|
708
736
|
state.keyrings = [];
|
|
709
737
|
});
|
|
710
|
-
await
|
|
738
|
+
await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this);
|
|
711
739
|
this.messagingSystem.publish(`${name}:lock`);
|
|
712
|
-
return
|
|
740
|
+
return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
|
|
713
741
|
}
|
|
714
742
|
/**
|
|
715
743
|
* Signs message by calling down into a specific keyring.
|
|
@@ -803,9 +831,10 @@ var KeyringController = class extends _basecontroller.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 = _ethsigutil.normalize.call(void 0, from);
|
|
810
839
|
const keyring = await this.getKeyringForAccount(
|
|
811
840
|
address
|
|
@@ -813,7 +842,11 @@ var KeyringController = class extends _basecontroller.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(
|
|
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.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 = _ethsigutil.normalize.call(void 0, from);
|
|
828
862
|
const keyring = await this.getKeyringForAccount(
|
|
829
863
|
address
|
|
@@ -831,16 +865,17 @@ var KeyringController = class extends _basecontroller.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 = _ethsigutil.normalize.call(void 0, from);
|
|
845
880
|
const keyring = await this.getKeyringForAccount(
|
|
846
881
|
address
|
|
@@ -848,7 +883,7 @@ var KeyringController = class extends _basecontroller.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,
|
|
@@ -859,13 +894,13 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
859
894
|
* @returns Promise resolving to the current state.
|
|
860
895
|
*/
|
|
861
896
|
async submitEncryptionKey(encryptionKey, encryptionSalt) {
|
|
862
|
-
|
|
863
|
-
|
|
897
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _keyrings, await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _unlockKeyrings, unlockKeyrings_fn).call(this, void 0, encryptionKey, encryptionSalt));
|
|
898
|
+
_chunkDNQK26H6js.__privateMethod.call(void 0, this, _setUnlocked, setUnlocked_fn).call(this);
|
|
864
899
|
const qrKeyring = this.getQRKeyring();
|
|
865
900
|
if (qrKeyring) {
|
|
866
|
-
|
|
901
|
+
_chunkDNQK26H6js.__privateMethod.call(void 0, this, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn).call(this, qrKeyring);
|
|
867
902
|
}
|
|
868
|
-
return
|
|
903
|
+
return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
|
|
869
904
|
}
|
|
870
905
|
/**
|
|
871
906
|
* Attempts to decrypt the current vault and load its keyrings,
|
|
@@ -875,13 +910,13 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
875
910
|
* @returns Promise resolving to the current state.
|
|
876
911
|
*/
|
|
877
912
|
async submitPassword(password) {
|
|
878
|
-
|
|
879
|
-
|
|
913
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _keyrings, await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _unlockKeyrings, unlockKeyrings_fn).call(this, password));
|
|
914
|
+
_chunkDNQK26H6js.__privateMethod.call(void 0, this, _setUnlocked, setUnlocked_fn).call(this);
|
|
880
915
|
const qrKeyring = this.getQRKeyring();
|
|
881
916
|
if (qrKeyring) {
|
|
882
|
-
|
|
917
|
+
_chunkDNQK26H6js.__privateMethod.call(void 0, this, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn).call(this, qrKeyring);
|
|
883
918
|
}
|
|
884
|
-
return
|
|
919
|
+
return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
|
|
885
920
|
}
|
|
886
921
|
/**
|
|
887
922
|
* Verifies the that the seed phrase restores the current keychain's accounts.
|
|
@@ -899,7 +934,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
899
934
|
if (accounts.length === 0) {
|
|
900
935
|
throw new Error("Cannot verify an empty keyring.");
|
|
901
936
|
}
|
|
902
|
-
const hdKeyringBuilder =
|
|
937
|
+
const hdKeyringBuilder = _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getKeyringBuilderForType, getKeyringBuilderForType_fn).call(this, "HD Key Tree" /* hd */);
|
|
903
938
|
const hdKeyring = hdKeyringBuilder();
|
|
904
939
|
await hdKeyring.deserialize({
|
|
905
940
|
mnemonic: seedWords,
|
|
@@ -931,7 +966,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
931
966
|
* @returns The added keyring
|
|
932
967
|
*/
|
|
933
968
|
async getOrAddQRKeyring() {
|
|
934
|
-
return this.getQRKeyring() || await
|
|
969
|
+
return this.getQRKeyring() || await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this);
|
|
935
970
|
}
|
|
936
971
|
// TODO: Replace `any` with type
|
|
937
972
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1011,6 +1046,8 @@ var KeyringController = class extends _basecontroller.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();
|
|
@@ -1071,28 +1108,28 @@ registerMessageHandlers_fn = function() {
|
|
|
1071
1108
|
};
|
|
1072
1109
|
_getKeyringBuilderForType = new WeakSet();
|
|
1073
1110
|
getKeyringBuilderForType_fn = function(type) {
|
|
1074
|
-
return
|
|
1111
|
+
return _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyringBuilders).find(
|
|
1075
1112
|
(keyringBuilder) => keyringBuilder.type === type
|
|
1076
1113
|
);
|
|
1077
1114
|
};
|
|
1078
1115
|
_addQRKeyring = new WeakSet();
|
|
1079
1116
|
addQRKeyring_fn = async function() {
|
|
1080
|
-
const qrKeyring = await
|
|
1117
|
+
const qrKeyring = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, "QR Hardware Wallet Device" /* qr */, {
|
|
1081
1118
|
accounts: []
|
|
1082
1119
|
});
|
|
1083
1120
|
const accounts = await qrKeyring.getAccounts();
|
|
1084
|
-
await
|
|
1085
|
-
|
|
1121
|
+
await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _checkForDuplicate, checkForDuplicate_fn).call(this, "QR Hardware Wallet Device" /* qr */, accounts);
|
|
1122
|
+
_chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).push(qrKeyring);
|
|
1086
1123
|
await this.persistAllKeyrings();
|
|
1087
|
-
|
|
1124
|
+
_chunkDNQK26H6js.__privateMethod.call(void 0, this, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn).call(this, qrKeyring);
|
|
1088
1125
|
return qrKeyring;
|
|
1089
1126
|
};
|
|
1090
1127
|
_subscribeToQRKeyringEvents = new WeakSet();
|
|
1091
1128
|
subscribeToQRKeyringEvents_fn = function(qrKeyring) {
|
|
1092
|
-
|
|
1129
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _qrKeyringStateListener, (state) => {
|
|
1093
1130
|
this.messagingSystem.publish(`${name}:qrKeyringStateChange`, state);
|
|
1094
1131
|
});
|
|
1095
|
-
qrKeyring.getMemStore().subscribe(
|
|
1132
|
+
qrKeyring.getMemStore().subscribe(_chunkDNQK26H6js.__privateGet.call(void 0, this, _qrKeyringStateListener));
|
|
1096
1133
|
};
|
|
1097
1134
|
_unsubscribeFromQRKeyringsEvents = new WeakSet();
|
|
1098
1135
|
unsubscribeFromQRKeyringsEvents_fn = function() {
|
|
@@ -1100,8 +1137,8 @@ unsubscribeFromQRKeyringsEvents_fn = function() {
|
|
|
1100
1137
|
"QR Hardware Wallet Device" /* qr */
|
|
1101
1138
|
);
|
|
1102
1139
|
qrKeyrings.forEach((qrKeyring) => {
|
|
1103
|
-
if (
|
|
1104
|
-
qrKeyring.getMemStore().unsubscribe(
|
|
1140
|
+
if (_chunkDNQK26H6js.__privateGet.call(void 0, this, _qrKeyringStateListener)) {
|
|
1141
|
+
qrKeyring.getMemStore().unsubscribe(_chunkDNQK26H6js.__privateGet.call(void 0, this, _qrKeyringStateListener));
|
|
1105
1142
|
}
|
|
1106
1143
|
});
|
|
1107
1144
|
};
|
|
@@ -1110,71 +1147,78 @@ createNewVaultWithKeyring_fn = async function(password, keyring) {
|
|
|
1110
1147
|
if (typeof password !== "string") {
|
|
1111
1148
|
throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
|
|
1112
1149
|
}
|
|
1113
|
-
|
|
1114
|
-
await
|
|
1115
|
-
await
|
|
1116
|
-
|
|
1117
|
-
return
|
|
1150
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _password, password);
|
|
1151
|
+
await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this);
|
|
1152
|
+
await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _createKeyringWithFirstAccount, createKeyringWithFirstAccount_fn).call(this, keyring.type, keyring.opts);
|
|
1153
|
+
_chunkDNQK26H6js.__privateMethod.call(void 0, this, _setUnlocked, setUnlocked_fn).call(this);
|
|
1154
|
+
return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
|
|
1118
1155
|
};
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
this.update((state) => {
|
|
1123
|
-
state.keyrings = keyrings;
|
|
1124
|
-
});
|
|
1156
|
+
_getUpdatedKeyrings = new WeakSet();
|
|
1157
|
+
getUpdatedKeyrings_fn = async function() {
|
|
1158
|
+
return Promise.all(_chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).map(displayForKeyring));
|
|
1125
1159
|
};
|
|
1126
1160
|
_unlockKeyrings = new WeakSet();
|
|
1127
1161
|
unlockKeyrings_fn = async function(password, encryptionKey, encryptionSalt) {
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
if (
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1162
|
+
return _chunkDNQK26H6js.__privateMethod.call(void 0, 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 _chunkDNQK26H6js.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this, { skipStateUpdate: true });
|
|
1168
|
+
let vault;
|
|
1169
|
+
const updatedState = {};
|
|
1170
|
+
if (_chunkDNQK26H6js.__privateGet.call(void 0, this, _cacheEncryptionKey)) {
|
|
1171
|
+
assertIsExportableKeyEncryptor(_chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor));
|
|
1172
|
+
if (password) {
|
|
1173
|
+
const result = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).decryptWithDetail(
|
|
1174
|
+
password,
|
|
1175
|
+
encryptedVault
|
|
1176
|
+
);
|
|
1177
|
+
vault = result.vault;
|
|
1178
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, 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 _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).importKey(encryptionKey);
|
|
1190
|
+
vault = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).decryptWithKey(
|
|
1191
|
+
key,
|
|
1192
|
+
parsedEncryptedVault
|
|
1193
|
+
);
|
|
1194
|
+
updatedState.encryptionKey = encryptionKey;
|
|
1195
|
+
updatedState.encryptionSalt = encryptionSalt;
|
|
1151
1196
|
}
|
|
1152
|
-
|
|
1197
|
+
} else {
|
|
1198
|
+
if (typeof password !== "string") {
|
|
1153
1199
|
throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
|
|
1154
1200
|
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
this.update((state) => {
|
|
1158
|
-
state.encryptionKey = encryptionKey;
|
|
1159
|
-
state.encryptionSalt = encryptionSalt;
|
|
1160
|
-
});
|
|
1201
|
+
vault = await _chunkDNQK26H6js.__privateGet.call(void 0, this, _encryptor).decrypt(password, encryptedVault);
|
|
1202
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _password, password);
|
|
1161
1203
|
}
|
|
1162
|
-
|
|
1163
|
-
|
|
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
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1207
|
+
await Promise.all(vault.map(_chunkDNQK26H6js.__privateMethod.call(void 0, this, _restoreKeyring, restoreKeyring_fn).bind(this)));
|
|
1208
|
+
const updatedKeyrings = await _chunkDNQK26H6js.__privateMethod.call(void 0, 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 (_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)) {
|
|
1217
|
+
releaseLock();
|
|
1218
|
+
await this.persistAllKeyrings();
|
|
1219
|
+
}
|
|
1220
|
+
return _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings);
|
|
1221
|
+
});
|
|
1178
1222
|
};
|
|
1179
1223
|
_createKeyringWithFirstAccount = new WeakSet();
|
|
1180
1224
|
createKeyringWithFirstAccount_fn = async function(type, opts) {
|
|
@@ -1186,7 +1230,7 @@ createKeyringWithFirstAccount_fn = async function(type, opts) {
|
|
|
1186
1230
|
};
|
|
1187
1231
|
_newKeyring = new WeakSet();
|
|
1188
1232
|
newKeyring_fn = async function(type, data) {
|
|
1189
|
-
const keyringBuilder =
|
|
1233
|
+
const keyringBuilder = _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getKeyringBuilderForType, getKeyringBuilderForType_fn).call(this, type);
|
|
1190
1234
|
if (!keyringBuilder) {
|
|
1191
1235
|
throw new Error(
|
|
1192
1236
|
`${"KeyringController - No keyringBuilder found for keyring" /* NoKeyringBuilder */}. Keyring type: ${type}`
|
|
@@ -1200,25 +1244,27 @@ newKeyring_fn = async function(type, data) {
|
|
|
1200
1244
|
return keyring;
|
|
1201
1245
|
};
|
|
1202
1246
|
_clearKeyrings = new WeakSet();
|
|
1203
|
-
clearKeyrings_fn = async function() {
|
|
1204
|
-
for (const keyring of
|
|
1205
|
-
await
|
|
1247
|
+
clearKeyrings_fn = async function(options = { skipStateUpdate: false }) {
|
|
1248
|
+
for (const keyring of _chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings)) {
|
|
1249
|
+
await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _destroyKeyring, destroyKeyring_fn).call(this, keyring);
|
|
1250
|
+
}
|
|
1251
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _keyrings, []);
|
|
1252
|
+
if (!options.skipStateUpdate) {
|
|
1253
|
+
this.update((state) => {
|
|
1254
|
+
state.keyrings = [];
|
|
1255
|
+
});
|
|
1206
1256
|
}
|
|
1207
|
-
_chunkCHLPTPMZjs.__privateSet.call(void 0, this, _keyrings, []);
|
|
1208
|
-
this.update((state) => {
|
|
1209
|
-
state.keyrings = [];
|
|
1210
|
-
});
|
|
1211
1257
|
};
|
|
1212
1258
|
_restoreKeyring = new WeakSet();
|
|
1213
1259
|
restoreKeyring_fn = async function(serialized) {
|
|
1214
1260
|
try {
|
|
1215
1261
|
const { type, data } = serialized;
|
|
1216
|
-
const keyring = await
|
|
1262
|
+
const keyring = await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, type, data);
|
|
1217
1263
|
await keyring.getAccounts();
|
|
1218
|
-
|
|
1264
|
+
_chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).push(keyring);
|
|
1219
1265
|
return keyring;
|
|
1220
1266
|
} catch (_) {
|
|
1221
|
-
|
|
1267
|
+
_chunkDNQK26H6js.__privateGet.call(void 0, this, _unsupportedKeyrings).push(serialized);
|
|
1222
1268
|
return void 0;
|
|
1223
1269
|
}
|
|
1224
1270
|
};
|
|
@@ -1230,16 +1276,16 @@ _removeEmptyKeyrings = new WeakSet();
|
|
|
1230
1276
|
removeEmptyKeyrings_fn = async function() {
|
|
1231
1277
|
const validKeyrings = [];
|
|
1232
1278
|
await Promise.all(
|
|
1233
|
-
|
|
1279
|
+
_chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).map(async (keyring) => {
|
|
1234
1280
|
const accounts = await keyring.getAccounts();
|
|
1235
1281
|
if (accounts.length > 0) {
|
|
1236
1282
|
validKeyrings.push(keyring);
|
|
1237
1283
|
} else {
|
|
1238
|
-
await
|
|
1284
|
+
await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _destroyKeyring, destroyKeyring_fn).call(this, keyring);
|
|
1239
1285
|
}
|
|
1240
1286
|
})
|
|
1241
1287
|
);
|
|
1242
|
-
|
|
1288
|
+
_chunkDNQK26H6js.__privateSet.call(void 0, this, _keyrings, validKeyrings);
|
|
1243
1289
|
};
|
|
1244
1290
|
_checkForDuplicate = new WeakSet();
|
|
1245
1291
|
checkForDuplicate_fn = async function(type, newAccountArray) {
|
|
@@ -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 _chunkDNQK26H6js.__privateGet.call(void 0, 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
|
|
|
@@ -1287,4 +1342,4 @@ var KeyringController_default = KeyringController;
|
|
|
1287
1342
|
|
|
1288
1343
|
|
|
1289
1344
|
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;
|
|
1290
|
-
//# sourceMappingURL=chunk-
|
|
1345
|
+
//# sourceMappingURL=chunk-LKJCRVNR.js.map
|