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