@metamask-previews/keyring-controller 15.0.0-preview-aedc5103 → 15.0.0-preview-02d970ca
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-STOYI7AT.js → chunk-2GJQ6KDW.js} +434 -336
- package/dist/chunk-2GJQ6KDW.js.map +1 -0
- package/dist/{chunk-XPARO3LL.mjs → chunk-4OE2G6WW.mjs} +4 -1
- package/dist/chunk-4OE2G6WW.mjs.map +1 -0
- package/dist/{chunk-5QTEIEPG.mjs → chunk-USAGXPFN.mjs} +344 -246
- package/dist/chunk-USAGXPFN.mjs.map +1 -0
- package/dist/{chunk-DNQK26H6.js → chunk-ZGV2QNCG.js} +4 -1
- package/dist/chunk-ZGV2QNCG.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 +69 -29
- package/dist/types/KeyringController.d.ts.map +1 -1
- package/dist/types/constants.d.ts +4 -1
- package/dist/types/constants.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-5QTEIEPG.mjs.map +0 -1
- package/dist/chunk-DNQK26H6.js.map +0 -1
- package/dist/chunk-STOYI7AT.js.map +0 -1
- package/dist/chunk-XPARO3LL.mjs.map +0 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkZGV2QNCGjs = require('./chunk-ZGV2QNCG.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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__privateAdd.call(void 0, this, _subscribeToQRKeyringEvents);
|
|
150
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__privateAdd.call(void 0, this, _getSerializedKeyrings);
|
|
182
|
+
/**
|
|
183
|
+
* Restore a serialized keyrings array.
|
|
184
|
+
*
|
|
185
|
+
* @param serializedKeyrings - The serialized keyrings array.
|
|
186
|
+
*/
|
|
187
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__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
|
+
_chunkZGV2QNCGjs.__privateAdd.call(void 0, this, _withVaultLock);
|
|
328
|
+
_chunkZGV2QNCGjs.__privateAdd.call(void 0, this, _controllerOperationMutex, new (0, _asyncmutex.Mutex)());
|
|
329
|
+
_chunkZGV2QNCGjs.__privateAdd.call(void 0, this, _vaultOperationMutex, new (0, _asyncmutex.Mutex)());
|
|
330
|
+
_chunkZGV2QNCGjs.__privateAdd.call(void 0, this, _keyringBuilders, void 0);
|
|
331
|
+
_chunkZGV2QNCGjs.__privateAdd.call(void 0, this, _keyrings, void 0);
|
|
332
|
+
_chunkZGV2QNCGjs.__privateAdd.call(void 0, this, _unsupportedKeyrings, void 0);
|
|
333
|
+
_chunkZGV2QNCGjs.__privateAdd.call(void 0, this, _password, void 0);
|
|
334
|
+
_chunkZGV2QNCGjs.__privateAdd.call(void 0, this, _encryptor, void 0);
|
|
335
|
+
_chunkZGV2QNCGjs.__privateAdd.call(void 0, this, _cacheEncryptionKey, void 0);
|
|
336
|
+
_chunkZGV2QNCGjs.__privateAdd.call(void 0, this, _qrKeyringStateListener, void 0);
|
|
337
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _keyringBuilders, keyringBuilders ? defaultKeyringBuilders.concat(keyringBuilders) : defaultKeyringBuilders);
|
|
338
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _encryptor, encryptor);
|
|
339
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _keyrings, []);
|
|
340
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _unsupportedKeyrings, []);
|
|
341
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _cacheEncryptionKey, Boolean(options.cacheEncryptionKey));
|
|
342
|
+
if (_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _cacheEncryptionKey)) {
|
|
297
343
|
assertIsExportableKeyEncryptor(encryptor);
|
|
298
344
|
}
|
|
299
|
-
|
|
345
|
+
_chunkZGV2QNCGjs.__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 _chunkZGV2QNCGjs.__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 _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _persistOrRollback, persistOrRollback_fn).call(this, async () => {
|
|
385
|
+
const oldAccounts = await _chunkZGV2QNCGjs.__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 _chunkZGV2QNCGjs.__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 _chunkZGV2QNCGjs.__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 _chunkZGV2QNCGjs.__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 _chunkZGV2QNCGjs.__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 _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _persistOrRollback, persistOrRollback_fn).call(this, async () => {
|
|
449
|
+
const accounts = await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
|
|
413
450
|
if (!accounts.length) {
|
|
414
|
-
await
|
|
451
|
+
await _chunkZGV2QNCGjs.__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 _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _persistOrRollback, persistOrRollback_fn).call(this, async () => _chunkZGV2QNCGjs.__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 _chunkZGV2QNCGjs.__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(_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _keyrings)[0]);
|
|
500
|
+
return _chunkZGV2QNCGjs.__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.
|
|
@@ -532,14 +569,14 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
532
569
|
*
|
|
533
570
|
* @deprecated Use of this method is discouraged as actions executed directly on
|
|
534
571
|
* keyrings are not being reflected in the KeyringController state and not
|
|
535
|
-
* persisted in the vault.
|
|
572
|
+
* persisted in the vault. Use `withKeyring` instead.
|
|
536
573
|
* @param account - An account address.
|
|
537
574
|
* @returns Promise resolving to keyring of the `account` if one exists.
|
|
538
575
|
*/
|
|
539
576
|
async getKeyringForAccount(account) {
|
|
540
577
|
const hexed = _ethsigutil.normalize.call(void 0, account);
|
|
541
578
|
const candidates = await Promise.all(
|
|
542
|
-
|
|
579
|
+
_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _keyrings).map(async (keyring) => {
|
|
543
580
|
return Promise.all([keyring, keyring.getAccounts()]);
|
|
544
581
|
})
|
|
545
582
|
);
|
|
@@ -567,21 +604,22 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
567
604
|
*
|
|
568
605
|
* @deprecated Use of this method is discouraged as actions executed directly on
|
|
569
606
|
* keyrings are not being reflected in the KeyringController state and not
|
|
570
|
-
* persisted in the vault.
|
|
607
|
+
* persisted in the vault. Use `withKeyring` instead.
|
|
571
608
|
* @param type - Keyring type name.
|
|
572
609
|
* @returns An array of keyrings of the given type.
|
|
573
610
|
*/
|
|
574
611
|
getKeyringsByType(type) {
|
|
575
|
-
return
|
|
612
|
+
return _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _keyrings).filter((keyring) => keyring.type === type);
|
|
576
613
|
}
|
|
577
614
|
/**
|
|
578
615
|
* Persist all serialized keyrings in the vault.
|
|
579
616
|
*
|
|
617
|
+
* @deprecated This method is being phased out in favor of `withKeyring`.
|
|
580
618
|
* @returns Promise resolving with `true` value when the
|
|
581
619
|
* operation completes.
|
|
582
620
|
*/
|
|
583
621
|
async persistAllKeyrings() {
|
|
584
|
-
return
|
|
622
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _persistOrRollback, persistOrRollback_fn).call(this, async () => true);
|
|
585
623
|
}
|
|
586
624
|
/**
|
|
587
625
|
* Imports an account with the specified import strategy.
|
|
@@ -589,88 +627,89 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
589
627
|
* @param strategy - Import strategy name.
|
|
590
628
|
* @param args - Array of arguments to pass to the underlying stategy.
|
|
591
629
|
* @throws Will throw when passed an unrecognized strategy.
|
|
592
|
-
* @returns Promise resolving to
|
|
593
|
-
* address.
|
|
630
|
+
* @returns Promise resolving to the imported account address.
|
|
594
631
|
*/
|
|
595
632
|
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
|
-
|
|
633
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _persistOrRollback, persistOrRollback_fn).call(this, async () => {
|
|
634
|
+
let privateKey;
|
|
635
|
+
switch (strategy) {
|
|
636
|
+
case "privateKey":
|
|
637
|
+
const [importedKey] = args;
|
|
638
|
+
if (!importedKey) {
|
|
639
|
+
throw new Error("Cannot import an empty key.");
|
|
640
|
+
}
|
|
641
|
+
const prefixed = _utils.add0x.call(void 0, importedKey);
|
|
642
|
+
let bufferedPrivateKey;
|
|
643
|
+
try {
|
|
644
|
+
bufferedPrivateKey = _util.toBuffer.call(void 0, prefixed);
|
|
645
|
+
} catch {
|
|
646
|
+
throw new Error("Cannot import invalid private key.");
|
|
647
|
+
}
|
|
648
|
+
if (!_util.isValidPrivate.call(void 0, bufferedPrivateKey) || // ensures that the key is 64 bytes long
|
|
649
|
+
_util.getBinarySize.call(void 0, prefixed) !== 64 + "0x".length) {
|
|
650
|
+
throw new Error("Cannot import invalid private key.");
|
|
651
|
+
}
|
|
652
|
+
privateKey = _utils.remove0x.call(void 0, prefixed);
|
|
653
|
+
break;
|
|
654
|
+
case "json":
|
|
655
|
+
let wallet;
|
|
656
|
+
const [input, password] = args;
|
|
657
|
+
try {
|
|
658
|
+
wallet = _ethereumjswallet.thirdparty.fromEtherWallet(input, password);
|
|
659
|
+
} catch (e) {
|
|
660
|
+
wallet = wallet || await _ethereumjswallet2.default.fromV3(input, password, true);
|
|
661
|
+
}
|
|
662
|
+
privateKey = _utils.bytesToHex.call(void 0, wallet.getPrivateKey());
|
|
663
|
+
break;
|
|
664
|
+
default:
|
|
665
|
+
throw new Error(`Unexpected import strategy: '${strategy}'`);
|
|
666
|
+
}
|
|
667
|
+
const newKeyring = await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, "Simple Key Pair" /* simple */, [
|
|
668
|
+
privateKey
|
|
669
|
+
]);
|
|
670
|
+
const accounts = await newKeyring.getAccounts();
|
|
671
|
+
return accounts[0];
|
|
672
|
+
});
|
|
635
673
|
}
|
|
636
674
|
/**
|
|
637
675
|
* Removes an account from keyring state.
|
|
638
676
|
*
|
|
639
677
|
* @param address - Address of the account to remove.
|
|
640
678
|
* @fires KeyringController:accountRemoved
|
|
641
|
-
* @returns Promise resolving
|
|
679
|
+
* @returns Promise resolving when the account is removed.
|
|
642
680
|
*/
|
|
643
681
|
async removeAccount(address) {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
682
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _persistOrRollback, persistOrRollback_fn).call(this, async () => {
|
|
683
|
+
const keyring = await this.getKeyringForAccount(
|
|
684
|
+
address
|
|
685
|
+
);
|
|
686
|
+
if (!keyring.removeAccount) {
|
|
687
|
+
throw new Error("`KeyringController - The keyring for the current address does not support the method removeAccount" /* UnsupportedRemoveAccount */);
|
|
688
|
+
}
|
|
689
|
+
await keyring.removeAccount(address);
|
|
690
|
+
const accounts = await keyring.getAccounts();
|
|
691
|
+
if (accounts.length === 0) {
|
|
692
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _removeEmptyKeyrings, removeEmptyKeyrings_fn).call(this);
|
|
693
|
+
}
|
|
694
|
+
});
|
|
656
695
|
this.messagingSystem.publish(`${name}:accountRemoved`, address);
|
|
657
|
-
return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
|
|
658
696
|
}
|
|
659
697
|
/**
|
|
660
698
|
* Deallocates all secrets and locks the wallet.
|
|
661
699
|
*
|
|
662
|
-
* @returns Promise resolving
|
|
700
|
+
* @returns Promise resolving when the operation completes.
|
|
663
701
|
*/
|
|
664
702
|
async setLocked() {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
state
|
|
703
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _withRollback, withRollback_fn).call(this, async () => {
|
|
704
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _unsubscribeFromQRKeyringsEvents, unsubscribeFromQRKeyringsEvents_fn).call(this);
|
|
705
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _password, void 0);
|
|
706
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this);
|
|
707
|
+
this.update((state) => {
|
|
708
|
+
state.isUnlocked = false;
|
|
709
|
+
state.keyrings = [];
|
|
710
|
+
});
|
|
711
|
+
this.messagingSystem.publish(`${name}:lock`);
|
|
670
712
|
});
|
|
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
713
|
}
|
|
675
714
|
/**
|
|
676
715
|
* Signs message by calling down into a specific keyring.
|
|
@@ -824,32 +863,26 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
824
863
|
*
|
|
825
864
|
* @param encryptionKey - Key to unlock the keychain.
|
|
826
865
|
* @param encryptionSalt - Salt to unlock the keychain.
|
|
827
|
-
* @returns Promise resolving
|
|
866
|
+
* @returns Promise resolving when the operation completes.
|
|
828
867
|
*/
|
|
829
868
|
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);
|
|
869
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _withRollback, withRollback_fn).call(this, async () => {
|
|
870
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _keyrings, await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _unlockKeyrings, unlockKeyrings_fn).call(this, void 0, encryptionKey, encryptionSalt));
|
|
871
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _setUnlocked, setUnlocked_fn).call(this);
|
|
872
|
+
});
|
|
837
873
|
}
|
|
838
874
|
/**
|
|
839
875
|
* Attempts to decrypt the current vault and load its keyrings,
|
|
840
876
|
* using the given password.
|
|
841
877
|
*
|
|
842
878
|
* @param password - Password to unlock the keychain.
|
|
843
|
-
* @returns Promise resolving
|
|
879
|
+
* @returns Promise resolving when the operation completes.
|
|
844
880
|
*/
|
|
845
881
|
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);
|
|
882
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _withRollback, withRollback_fn).call(this, async () => {
|
|
883
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _keyrings, await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _unlockKeyrings, unlockKeyrings_fn).call(this, password));
|
|
884
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _setUnlocked, setUnlocked_fn).call(this);
|
|
885
|
+
});
|
|
853
886
|
}
|
|
854
887
|
/**
|
|
855
888
|
* Verifies the that the seed phrase restores the current keychain's accounts.
|
|
@@ -867,7 +900,7 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
867
900
|
if (accounts.length === 0) {
|
|
868
901
|
throw new Error("Cannot verify an empty keyring.");
|
|
869
902
|
}
|
|
870
|
-
const hdKeyringBuilder =
|
|
903
|
+
const hdKeyringBuilder = _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _getKeyringBuilderForType, getKeyringBuilderForType_fn).call(this, "HD Key Tree" /* hd */);
|
|
871
904
|
const hdKeyring = hdKeyringBuilder();
|
|
872
905
|
await hdKeyring.deserialize({
|
|
873
906
|
mnemonic: seedWords,
|
|
@@ -884,6 +917,29 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
884
917
|
});
|
|
885
918
|
return seedWords;
|
|
886
919
|
}
|
|
920
|
+
async withKeyring(selector, operation, options = {
|
|
921
|
+
createIfMissing: false
|
|
922
|
+
}) {
|
|
923
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _persistOrRollback, persistOrRollback_fn).call(this, async () => {
|
|
924
|
+
let keyring;
|
|
925
|
+
if ("address" in selector) {
|
|
926
|
+
keyring = await this.getKeyringForAccount(selector.address);
|
|
927
|
+
} else {
|
|
928
|
+
keyring = this.getKeyringsByType(selector.type)[selector.index || 0];
|
|
929
|
+
if (!keyring && options.createIfMissing) {
|
|
930
|
+
keyring = await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, selector.type, options.createWithData);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
if (!keyring) {
|
|
934
|
+
throw new Error("KeyringController - Keyring not found." /* KeyringNotFound */);
|
|
935
|
+
}
|
|
936
|
+
const result = await operation(keyring);
|
|
937
|
+
if (Object.is(result, keyring)) {
|
|
938
|
+
throw new Error("KeyringController - Returning keyring instances is unsafe" /* UnsafeDirectKeyringAccess */);
|
|
939
|
+
}
|
|
940
|
+
return result;
|
|
941
|
+
});
|
|
942
|
+
}
|
|
887
943
|
// QR Hardware related methods
|
|
888
944
|
/**
|
|
889
945
|
* Get QR Hardware keyring.
|
|
@@ -899,14 +955,15 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
899
955
|
* @returns The added keyring
|
|
900
956
|
*/
|
|
901
957
|
async getOrAddQRKeyring() {
|
|
902
|
-
return this.getQRKeyring() || await
|
|
958
|
+
return this.getQRKeyring() || await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _persistOrRollback, persistOrRollback_fn).call(this, async () => _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this));
|
|
903
959
|
}
|
|
904
960
|
// TODO: Replace `any` with type
|
|
905
961
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
906
962
|
async restoreQRKeyring(serialized) {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
963
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _persistOrRollback, persistOrRollback_fn).call(this, async () => {
|
|
964
|
+
const keyring = this.getQRKeyring() || await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this);
|
|
965
|
+
keyring.deserialize(serialized);
|
|
966
|
+
});
|
|
910
967
|
}
|
|
911
968
|
async resetQRKeyringState() {
|
|
912
969
|
(await this.getOrAddQRKeyring()).resetStore();
|
|
@@ -933,34 +990,37 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
933
990
|
(await this.getOrAddQRKeyring()).cancelSync();
|
|
934
991
|
}
|
|
935
992
|
async connectQRHardware(page) {
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
993
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _persistOrRollback, persistOrRollback_fn).call(this, async () => {
|
|
994
|
+
try {
|
|
995
|
+
const keyring = this.getQRKeyring() || await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this);
|
|
996
|
+
let accounts;
|
|
997
|
+
switch (page) {
|
|
998
|
+
case -1:
|
|
999
|
+
accounts = await keyring.getPreviousPage();
|
|
1000
|
+
break;
|
|
1001
|
+
case 1:
|
|
1002
|
+
accounts = await keyring.getNextPage();
|
|
1003
|
+
break;
|
|
1004
|
+
default:
|
|
1005
|
+
accounts = await keyring.getFirstPage();
|
|
1006
|
+
}
|
|
1007
|
+
return accounts.map((account) => {
|
|
1008
|
+
return {
|
|
1009
|
+
...account,
|
|
1010
|
+
balance: "0x0"
|
|
1011
|
+
};
|
|
1012
|
+
});
|
|
1013
|
+
} catch (e) {
|
|
1014
|
+
throw new Error(`Unspecified error when connect QR Hardware, ${e}`);
|
|
948
1015
|
}
|
|
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
|
-
}
|
|
1016
|
+
});
|
|
958
1017
|
}
|
|
959
1018
|
async unlockQRHardwareWalletAccount(index) {
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1019
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _persistOrRollback, persistOrRollback_fn).call(this, async () => {
|
|
1020
|
+
const keyring = this.getQRKeyring() || await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _addQRKeyring, addQRKeyring_fn).call(this);
|
|
1021
|
+
keyring.setAccountToUnlock(index);
|
|
1022
|
+
await keyring.addAccounts(1);
|
|
1023
|
+
});
|
|
964
1024
|
}
|
|
965
1025
|
async getAccountKeyringType(account) {
|
|
966
1026
|
const keyring = await this.getKeyringForAccount(
|
|
@@ -969,21 +1029,22 @@ var KeyringController = class extends _basecontroller.BaseController {
|
|
|
969
1029
|
return keyring.type;
|
|
970
1030
|
}
|
|
971
1031
|
async forgetQRDevice() {
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1032
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _persistOrRollback, persistOrRollback_fn).call(this, async () => {
|
|
1033
|
+
const keyring = this.getQRKeyring();
|
|
1034
|
+
if (!keyring) {
|
|
1035
|
+
return { removedAccounts: [], remainingAccounts: [] };
|
|
1036
|
+
}
|
|
1037
|
+
const allAccounts = await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
|
|
1038
|
+
keyring.forgetDevice();
|
|
1039
|
+
const remainingAccounts = await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
|
|
1040
|
+
const removedAccounts = allAccounts.filter(
|
|
1041
|
+
(address) => !remainingAccounts.includes(address)
|
|
1042
|
+
);
|
|
1043
|
+
return { removedAccounts, remainingAccounts };
|
|
1044
|
+
});
|
|
984
1045
|
}
|
|
985
1046
|
};
|
|
986
|
-
|
|
1047
|
+
_controllerOperationMutex = new WeakMap();
|
|
987
1048
|
_vaultOperationMutex = new WeakMap();
|
|
988
1049
|
_keyringBuilders = new WeakMap();
|
|
989
1050
|
_keyrings = new WeakMap();
|
|
@@ -1045,28 +1106,23 @@ registerMessageHandlers_fn = function() {
|
|
|
1045
1106
|
};
|
|
1046
1107
|
_getKeyringBuilderForType = new WeakSet();
|
|
1047
1108
|
getKeyringBuilderForType_fn = function(type) {
|
|
1048
|
-
return
|
|
1109
|
+
return _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _keyringBuilders).find(
|
|
1049
1110
|
(keyringBuilder) => keyringBuilder.type === type
|
|
1050
1111
|
);
|
|
1051
1112
|
};
|
|
1052
1113
|
_addQRKeyring = new WeakSet();
|
|
1053
1114
|
addQRKeyring_fn = async function() {
|
|
1054
|
-
|
|
1115
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1116
|
+
return await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, "QR Hardware Wallet Device" /* qr */, {
|
|
1055
1117
|
accounts: []
|
|
1056
1118
|
});
|
|
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
1119
|
};
|
|
1064
1120
|
_subscribeToQRKeyringEvents = new WeakSet();
|
|
1065
1121
|
subscribeToQRKeyringEvents_fn = function(qrKeyring) {
|
|
1066
|
-
|
|
1122
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _qrKeyringStateListener, (state) => {
|
|
1067
1123
|
this.messagingSystem.publish(`${name}:qrKeyringStateChange`, state);
|
|
1068
1124
|
});
|
|
1069
|
-
qrKeyring.getMemStore().subscribe(
|
|
1125
|
+
qrKeyring.getMemStore().subscribe(_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _qrKeyringStateListener));
|
|
1070
1126
|
};
|
|
1071
1127
|
_unsubscribeFromQRKeyringsEvents = new WeakSet();
|
|
1072
1128
|
unsubscribeFromQRKeyringsEvents_fn = function() {
|
|
@@ -1074,45 +1130,69 @@ unsubscribeFromQRKeyringsEvents_fn = function() {
|
|
|
1074
1130
|
"QR Hardware Wallet Device" /* qr */
|
|
1075
1131
|
);
|
|
1076
1132
|
qrKeyrings.forEach((qrKeyring) => {
|
|
1077
|
-
if (
|
|
1078
|
-
qrKeyring.getMemStore().unsubscribe(
|
|
1133
|
+
if (_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _qrKeyringStateListener)) {
|
|
1134
|
+
qrKeyring.getMemStore().unsubscribe(_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _qrKeyringStateListener));
|
|
1079
1135
|
}
|
|
1080
1136
|
});
|
|
1081
1137
|
};
|
|
1082
1138
|
_createNewVaultWithKeyring = new WeakSet();
|
|
1083
1139
|
createNewVaultWithKeyring_fn = async function(password, keyring) {
|
|
1140
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1084
1141
|
if (typeof password !== "string") {
|
|
1085
1142
|
throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
|
|
1086
1143
|
}
|
|
1087
|
-
|
|
1088
|
-
await
|
|
1089
|
-
await
|
|
1090
|
-
|
|
1091
|
-
return _chunkDNQK26H6js.__privateMethod.call(void 0, this, _getMemState, getMemState_fn).call(this);
|
|
1144
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _password, password);
|
|
1145
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this);
|
|
1146
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _createKeyringWithFirstAccount, createKeyringWithFirstAccount_fn).call(this, keyring.type, keyring.opts);
|
|
1147
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _setUnlocked, setUnlocked_fn).call(this);
|
|
1092
1148
|
};
|
|
1093
1149
|
_getUpdatedKeyrings = new WeakSet();
|
|
1094
1150
|
getUpdatedKeyrings_fn = async function() {
|
|
1095
|
-
return Promise.all(
|
|
1151
|
+
return Promise.all(_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _keyrings).map(displayForKeyring));
|
|
1152
|
+
};
|
|
1153
|
+
_getSerializedKeyrings = new WeakSet();
|
|
1154
|
+
getSerializedKeyrings_fn = async function({ includeUnsupported } = {
|
|
1155
|
+
includeUnsupported: true
|
|
1156
|
+
}) {
|
|
1157
|
+
const serializedKeyrings = await Promise.all(
|
|
1158
|
+
_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _keyrings).map(async (keyring) => {
|
|
1159
|
+
const [type, data] = await Promise.all([
|
|
1160
|
+
keyring.type,
|
|
1161
|
+
keyring.serialize()
|
|
1162
|
+
]);
|
|
1163
|
+
return { type, data };
|
|
1164
|
+
})
|
|
1165
|
+
);
|
|
1166
|
+
if (includeUnsupported) {
|
|
1167
|
+
serializedKeyrings.push(..._chunkZGV2QNCGjs.__privateGet.call(void 0, this, _unsupportedKeyrings));
|
|
1168
|
+
}
|
|
1169
|
+
return serializedKeyrings;
|
|
1170
|
+
};
|
|
1171
|
+
_restoreSerializedKeyrings = new WeakSet();
|
|
1172
|
+
restoreSerializedKeyrings_fn = async function(serializedKeyrings) {
|
|
1173
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this);
|
|
1174
|
+
for (const serializedKeyring of serializedKeyrings) {
|
|
1175
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _restoreKeyring, restoreKeyring_fn).call(this, serializedKeyring);
|
|
1176
|
+
}
|
|
1096
1177
|
};
|
|
1097
1178
|
_unlockKeyrings = new WeakSet();
|
|
1098
1179
|
unlockKeyrings_fn = async function(password, encryptionKey, encryptionSalt) {
|
|
1099
|
-
return
|
|
1180
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _withVaultLock, withVaultLock_fn).call(this, async ({ releaseLock }) => {
|
|
1100
1181
|
const encryptedVault = this.state.vault;
|
|
1101
1182
|
if (!encryptedVault) {
|
|
1102
1183
|
throw new Error("KeyringController - Cannot unlock without a previous vault." /* VaultError */);
|
|
1103
1184
|
}
|
|
1104
|
-
await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _clearKeyrings, clearKeyrings_fn).call(this, { skipStateUpdate: true });
|
|
1105
1185
|
let vault;
|
|
1106
1186
|
const updatedState = {};
|
|
1107
|
-
if (
|
|
1108
|
-
assertIsExportableKeyEncryptor(
|
|
1187
|
+
if (_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _cacheEncryptionKey)) {
|
|
1188
|
+
assertIsExportableKeyEncryptor(_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _encryptor));
|
|
1109
1189
|
if (password) {
|
|
1110
|
-
const result = await
|
|
1190
|
+
const result = await _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _encryptor).decryptWithDetail(
|
|
1111
1191
|
password,
|
|
1112
1192
|
encryptedVault
|
|
1113
1193
|
);
|
|
1114
1194
|
vault = result.vault;
|
|
1115
|
-
|
|
1195
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _password, password);
|
|
1116
1196
|
updatedState.encryptionKey = result.exportedKeyString;
|
|
1117
1197
|
updatedState.encryptionSalt = result.salt;
|
|
1118
1198
|
} else {
|
|
@@ -1123,8 +1203,8 @@ unlockKeyrings_fn = async function(password, encryptionKey, encryptionSalt) {
|
|
|
1123
1203
|
if (typeof encryptionKey !== "string") {
|
|
1124
1204
|
throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
|
|
1125
1205
|
}
|
|
1126
|
-
const key = await
|
|
1127
|
-
vault = await
|
|
1206
|
+
const key = await _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _encryptor).importKey(encryptionKey);
|
|
1207
|
+
vault = await _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _encryptor).decryptWithKey(
|
|
1128
1208
|
key,
|
|
1129
1209
|
parsedEncryptedVault
|
|
1130
1210
|
);
|
|
@@ -1135,14 +1215,14 @@ unlockKeyrings_fn = async function(password, encryptionKey, encryptionSalt) {
|
|
|
1135
1215
|
if (typeof password !== "string") {
|
|
1136
1216
|
throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
|
|
1137
1217
|
}
|
|
1138
|
-
vault = await
|
|
1139
|
-
|
|
1218
|
+
vault = await _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _encryptor).decrypt(password, encryptedVault);
|
|
1219
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _password, password);
|
|
1140
1220
|
}
|
|
1141
1221
|
if (!isSerializedKeyringsArray(vault)) {
|
|
1142
1222
|
throw new Error("KeyringController - The decrypted vault has an unexpected shape." /* VaultDataError */);
|
|
1143
1223
|
}
|
|
1144
|
-
await
|
|
1145
|
-
const updatedKeyrings = await
|
|
1224
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _restoreSerializedKeyrings, restoreSerializedKeyrings_fn).call(this, vault);
|
|
1225
|
+
const updatedKeyrings = await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _getUpdatedKeyrings, getUpdatedKeyrings_fn).call(this);
|
|
1146
1226
|
this.update((state) => {
|
|
1147
1227
|
state.keyrings = updatedKeyrings;
|
|
1148
1228
|
if (updatedState.encryptionKey || updatedState.encryptionSalt) {
|
|
@@ -1150,65 +1230,56 @@ unlockKeyrings_fn = async function(password, encryptionKey, encryptionSalt) {
|
|
|
1150
1230
|
state.encryptionSalt = updatedState.encryptionSalt;
|
|
1151
1231
|
}
|
|
1152
1232
|
});
|
|
1153
|
-
if (
|
|
1233
|
+
if (_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _password) && (!_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _cacheEncryptionKey) || !encryptionKey) && _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _encryptor).isVaultUpdated && !_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _encryptor).isVaultUpdated(encryptedVault)) {
|
|
1154
1234
|
releaseLock();
|
|
1155
|
-
await
|
|
1235
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
|
|
1156
1236
|
}
|
|
1157
|
-
return
|
|
1237
|
+
return _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _keyrings);
|
|
1158
1238
|
});
|
|
1159
1239
|
};
|
|
1160
1240
|
_updateVault = new WeakSet();
|
|
1161
1241
|
updateVault_fn = function() {
|
|
1162
|
-
return
|
|
1242
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _withVaultLock, withVaultLock_fn).call(this, async () => {
|
|
1163
1243
|
const { encryptionKey, encryptionSalt } = this.state;
|
|
1164
|
-
if (!
|
|
1244
|
+
if (!_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _password) && !encryptionKey) {
|
|
1165
1245
|
throw new Error("KeyringController - Cannot persist vault without password and encryption key" /* MissingCredentials */);
|
|
1166
1246
|
}
|
|
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));
|
|
1247
|
+
const serializedKeyrings = await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _getSerializedKeyrings, getSerializedKeyrings_fn).call(this);
|
|
1177
1248
|
if (!serializedKeyrings.some((keyring) => keyring.type === "HD Key Tree" /* hd */)) {
|
|
1178
1249
|
throw new Error("KeyringController - No HD Keyring found" /* NoHdKeyring */);
|
|
1179
1250
|
}
|
|
1180
1251
|
const updatedState = {};
|
|
1181
|
-
if (
|
|
1182
|
-
assertIsExportableKeyEncryptor(
|
|
1252
|
+
if (_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _cacheEncryptionKey)) {
|
|
1253
|
+
assertIsExportableKeyEncryptor(_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _encryptor));
|
|
1183
1254
|
if (encryptionKey) {
|
|
1184
|
-
const key = await
|
|
1185
|
-
const vaultJSON = await
|
|
1255
|
+
const key = await _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _encryptor).importKey(encryptionKey);
|
|
1256
|
+
const vaultJSON = await _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _encryptor).encryptWithKey(
|
|
1186
1257
|
key,
|
|
1187
1258
|
serializedKeyrings
|
|
1188
1259
|
);
|
|
1189
1260
|
vaultJSON.salt = encryptionSalt;
|
|
1190
1261
|
updatedState.vault = JSON.stringify(vaultJSON);
|
|
1191
|
-
} else if (
|
|
1192
|
-
const { vault: newVault, exportedKeyString } = await
|
|
1193
|
-
|
|
1262
|
+
} else if (_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _password)) {
|
|
1263
|
+
const { vault: newVault, exportedKeyString } = await _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _encryptor).encryptWithDetail(
|
|
1264
|
+
_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _password),
|
|
1194
1265
|
serializedKeyrings
|
|
1195
1266
|
);
|
|
1196
1267
|
updatedState.vault = newVault;
|
|
1197
1268
|
updatedState.encryptionKey = exportedKeyString;
|
|
1198
1269
|
}
|
|
1199
1270
|
} else {
|
|
1200
|
-
if (typeof
|
|
1271
|
+
if (typeof _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _password) !== "string") {
|
|
1201
1272
|
throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
|
|
1202
1273
|
}
|
|
1203
|
-
updatedState.vault = await
|
|
1204
|
-
|
|
1274
|
+
updatedState.vault = await _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _encryptor).encrypt(
|
|
1275
|
+
_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _password),
|
|
1205
1276
|
serializedKeyrings
|
|
1206
1277
|
);
|
|
1207
1278
|
}
|
|
1208
1279
|
if (!updatedState.vault) {
|
|
1209
1280
|
throw new Error("KeyringController - Cannot persist vault without vault information" /* MissingVaultData */);
|
|
1210
1281
|
}
|
|
1211
|
-
const updatedKeyrings = await
|
|
1282
|
+
const updatedKeyrings = await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _getUpdatedKeyrings, getUpdatedKeyrings_fn).call(this);
|
|
1212
1283
|
this.update((state) => {
|
|
1213
1284
|
state.vault = updatedState.vault;
|
|
1214
1285
|
state.keyrings = updatedKeyrings;
|
|
@@ -1222,7 +1293,7 @@ updateVault_fn = function() {
|
|
|
1222
1293
|
};
|
|
1223
1294
|
_getAccountsFromKeyrings = new WeakSet();
|
|
1224
1295
|
getAccountsFromKeyrings_fn = async function() {
|
|
1225
|
-
const keyrings =
|
|
1296
|
+
const keyrings = _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _keyrings);
|
|
1226
1297
|
const keyringArrays = await Promise.all(
|
|
1227
1298
|
keyrings.map(async (keyring) => keyring.getAccounts())
|
|
1228
1299
|
);
|
|
@@ -1233,15 +1304,17 @@ getAccountsFromKeyrings_fn = async function() {
|
|
|
1233
1304
|
};
|
|
1234
1305
|
_createKeyringWithFirstAccount = new WeakSet();
|
|
1235
1306
|
createKeyringWithFirstAccount_fn = async function(type, opts) {
|
|
1236
|
-
|
|
1307
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1308
|
+
const keyring = await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, type, opts);
|
|
1237
1309
|
const [firstAccount] = await keyring.getAccounts();
|
|
1238
1310
|
if (!firstAccount) {
|
|
1239
1311
|
throw new Error("KeyringController - First Account not found." /* NoFirstAccount */);
|
|
1240
1312
|
}
|
|
1241
1313
|
};
|
|
1242
1314
|
_newKeyring = new WeakSet();
|
|
1243
|
-
newKeyring_fn = async function(type, data
|
|
1244
|
-
|
|
1315
|
+
newKeyring_fn = async function(type, data) {
|
|
1316
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1317
|
+
const keyringBuilder = _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _getKeyringBuilderForType, getKeyringBuilderForType_fn).call(this, type);
|
|
1245
1318
|
if (!keyringBuilder) {
|
|
1246
1319
|
throw new Error(
|
|
1247
1320
|
`${"KeyringController - No keyringBuilder found for keyring" /* NoKeyringBuilder */}. Keyring type: ${type}`
|
|
@@ -1261,35 +1334,29 @@ newKeyring_fn = async function(type, data, persist = false) {
|
|
|
1261
1334
|
keyring.generateRandomMnemonic();
|
|
1262
1335
|
await keyring.addAccounts(1);
|
|
1263
1336
|
}
|
|
1264
|
-
await
|
|
1265
|
-
if (
|
|
1266
|
-
|
|
1267
|
-
await _chunkDNQK26H6js.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
|
|
1337
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _checkForDuplicate, checkForDuplicate_fn).call(this, type, await keyring.getAccounts());
|
|
1338
|
+
if (type === "QR Hardware Wallet Device" /* qr */) {
|
|
1339
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn).call(this, keyring);
|
|
1268
1340
|
}
|
|
1341
|
+
_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _keyrings).push(keyring);
|
|
1269
1342
|
return keyring;
|
|
1270
1343
|
};
|
|
1271
1344
|
_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
|
-
});
|
|
1345
|
+
clearKeyrings_fn = async function() {
|
|
1346
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1347
|
+
for (const keyring of _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _keyrings)) {
|
|
1348
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _destroyKeyring, destroyKeyring_fn).call(this, keyring);
|
|
1281
1349
|
}
|
|
1350
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _keyrings, []);
|
|
1282
1351
|
};
|
|
1283
1352
|
_restoreKeyring = new WeakSet();
|
|
1284
1353
|
restoreKeyring_fn = async function(serialized) {
|
|
1354
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1285
1355
|
try {
|
|
1286
1356
|
const { type, data } = serialized;
|
|
1287
|
-
|
|
1288
|
-
await keyring.getAccounts();
|
|
1289
|
-
_chunkDNQK26H6js.__privateGet.call(void 0, this, _keyrings).push(keyring);
|
|
1290
|
-
return keyring;
|
|
1357
|
+
return await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _newKeyring, newKeyring_fn).call(this, type, data);
|
|
1291
1358
|
} catch (_) {
|
|
1292
|
-
|
|
1359
|
+
_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _unsupportedKeyrings).push(serialized);
|
|
1293
1360
|
return void 0;
|
|
1294
1361
|
}
|
|
1295
1362
|
};
|
|
@@ -1299,22 +1366,23 @@ destroyKeyring_fn = async function(keyring) {
|
|
|
1299
1366
|
};
|
|
1300
1367
|
_removeEmptyKeyrings = new WeakSet();
|
|
1301
1368
|
removeEmptyKeyrings_fn = async function() {
|
|
1369
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1302
1370
|
const validKeyrings = [];
|
|
1303
1371
|
await Promise.all(
|
|
1304
|
-
|
|
1372
|
+
_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _keyrings).map(async (keyring) => {
|
|
1305
1373
|
const accounts = await keyring.getAccounts();
|
|
1306
1374
|
if (accounts.length > 0) {
|
|
1307
1375
|
validKeyrings.push(keyring);
|
|
1308
1376
|
} else {
|
|
1309
|
-
await
|
|
1377
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _destroyKeyring, destroyKeyring_fn).call(this, keyring);
|
|
1310
1378
|
}
|
|
1311
1379
|
})
|
|
1312
1380
|
);
|
|
1313
|
-
|
|
1381
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _keyrings, validKeyrings);
|
|
1314
1382
|
};
|
|
1315
1383
|
_checkForDuplicate = new WeakSet();
|
|
1316
1384
|
checkForDuplicate_fn = async function(type, newAccountArray) {
|
|
1317
|
-
const accounts = await
|
|
1385
|
+
const accounts = await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
|
|
1318
1386
|
switch (type) {
|
|
1319
1387
|
case "Simple Key Pair" /* simple */: {
|
|
1320
1388
|
const isIncluded = Boolean(
|
|
@@ -1334,27 +1402,57 @@ checkForDuplicate_fn = async function(type, newAccountArray) {
|
|
|
1334
1402
|
};
|
|
1335
1403
|
_setUnlocked = new WeakSet();
|
|
1336
1404
|
setUnlocked_fn = function() {
|
|
1405
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1337
1406
|
this.update((state) => {
|
|
1338
1407
|
state.isUnlocked = true;
|
|
1339
1408
|
});
|
|
1340
1409
|
this.messagingSystem.publish(`${name}:unlock`);
|
|
1341
1410
|
};
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
return {
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1411
|
+
_persistOrRollback = new WeakSet();
|
|
1412
|
+
persistOrRollback_fn = async function(fn) {
|
|
1413
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _withRollback, withRollback_fn).call(this, async ({ releaseLock }) => {
|
|
1414
|
+
const callbackResult = await fn({ releaseLock });
|
|
1415
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _updateVault, updateVault_fn).call(this);
|
|
1416
|
+
return callbackResult;
|
|
1417
|
+
});
|
|
1418
|
+
};
|
|
1419
|
+
_withRollback = new WeakSet();
|
|
1420
|
+
withRollback_fn = async function(fn) {
|
|
1421
|
+
return _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _withControllerLock, withControllerLock_fn).call(this, async ({ releaseLock }) => {
|
|
1422
|
+
const currentSerializedKeyrings = await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _getSerializedKeyrings, getSerializedKeyrings_fn).call(this);
|
|
1423
|
+
const currentPassword = _chunkZGV2QNCGjs.__privateGet.call(void 0, this, _password);
|
|
1424
|
+
try {
|
|
1425
|
+
return await fn({ releaseLock });
|
|
1426
|
+
} catch (e) {
|
|
1427
|
+
await _chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _restoreSerializedKeyrings, restoreSerializedKeyrings_fn).call(this, currentSerializedKeyrings);
|
|
1428
|
+
_chunkZGV2QNCGjs.__privateSet.call(void 0, this, _password, currentPassword);
|
|
1429
|
+
throw e;
|
|
1430
|
+
}
|
|
1431
|
+
});
|
|
1432
|
+
};
|
|
1433
|
+
_assertControllerMutexIsLocked = new WeakSet();
|
|
1434
|
+
assertControllerMutexIsLocked_fn = function() {
|
|
1435
|
+
if (!_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _controllerOperationMutex).isLocked()) {
|
|
1436
|
+
throw new Error("KeyringController - attempt to update vault during a non mutually exclusive operation" /* ControllerLockRequired */);
|
|
1437
|
+
}
|
|
1438
|
+
};
|
|
1439
|
+
_withControllerLock = new WeakSet();
|
|
1440
|
+
withControllerLock_fn = async function(fn) {
|
|
1441
|
+
return withLock(_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _controllerOperationMutex), fn);
|
|
1348
1442
|
};
|
|
1349
1443
|
_withVaultLock = new WeakSet();
|
|
1350
1444
|
withVaultLock_fn = async function(fn) {
|
|
1351
|
-
|
|
1445
|
+
_chunkZGV2QNCGjs.__privateMethod.call(void 0, this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1446
|
+
return withLock(_chunkZGV2QNCGjs.__privateGet.call(void 0, this, _vaultOperationMutex), fn);
|
|
1447
|
+
};
|
|
1448
|
+
async function withLock(mutex, fn) {
|
|
1449
|
+
const releaseLock = await mutex.acquire();
|
|
1352
1450
|
try {
|
|
1353
1451
|
return await fn({ releaseLock });
|
|
1354
1452
|
} finally {
|
|
1355
1453
|
releaseLock();
|
|
1356
1454
|
}
|
|
1357
|
-
}
|
|
1455
|
+
}
|
|
1358
1456
|
var KeyringController_default = KeyringController;
|
|
1359
1457
|
|
|
1360
1458
|
|
|
@@ -1367,4 +1465,4 @@ var KeyringController_default = KeyringController;
|
|
|
1367
1465
|
|
|
1368
1466
|
|
|
1369
1467
|
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-
|
|
1468
|
+
//# sourceMappingURL=chunk-2GJQ6KDW.js.map
|