@metamask-previews/keyring-controller 15.0.0-preview-fb52b9eb → 15.0.0-preview-2036edd1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -13
- package/dist/KeyringController.js +3 -3
- package/dist/KeyringController.mjs +2 -2
- package/dist/{chunk-RVCG63UG.mjs → chunk-5QTEIEPG.mjs} +206 -242
- package/dist/chunk-5QTEIEPG.mjs.map +1 -0
- package/dist/{chunk-QDPHKQON.js → chunk-DNQK26H6.js} +1 -2
- package/dist/chunk-DNQK26H6.js.map +1 -0
- package/dist/{chunk-ISACMNF3.js → chunk-STOYI7AT.js} +310 -346
- package/dist/chunk-STOYI7AT.js.map +1 -0
- package/dist/{chunk-HT7WOORD.mjs → chunk-XPARO3LL.mjs} +1 -2
- package/dist/{chunk-HT7WOORD.mjs.map → chunk-XPARO3LL.mjs.map} +1 -1
- package/dist/constants.js +2 -2
- package/dist/constants.mjs +1 -1
- package/dist/index.js +3 -3
- package/dist/index.mjs +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/KeyringController.d.ts +27 -19
- package/dist/types/KeyringController.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -2
- package/dist/types/constants.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-ISACMNF3.js.map +0 -1
- package/dist/chunk-QDPHKQON.js.map +0 -1
- package/dist/chunk-RVCG63UG.mjs.map +0 -1
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
__privateGet,
|
|
4
4
|
__privateMethod,
|
|
5
5
|
__privateSet
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-XPARO3LL.mjs";
|
|
7
7
|
|
|
8
8
|
// src/KeyringController.ts
|
|
9
9
|
import { isValidPrivate, toBuffer, getBinarySize } from "@ethereumjs/util";
|
|
@@ -86,7 +86,7 @@ async function displayForKeyring(keyring) {
|
|
|
86
86
|
accounts: accounts.map(normalize)
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
|
-
var
|
|
89
|
+
var _initVaultMutex, _vaultOperationMutex, _keyringBuilders, _keyrings, _unsupportedKeyrings, _password, _encryptor, _cacheEncryptionKey, _qrKeyringStateListener, _registerMessageHandlers, registerMessageHandlers_fn, _getKeyringBuilderForType, getKeyringBuilderForType_fn, _addQRKeyring, addQRKeyring_fn, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn, _unsubscribeFromQRKeyringsEvents, unsubscribeFromQRKeyringsEvents_fn, _createNewVaultWithKeyring, createNewVaultWithKeyring_fn, _getUpdatedKeyrings, getUpdatedKeyrings_fn, _unlockKeyrings, unlockKeyrings_fn, _updateVault, updateVault_fn, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn, _createKeyringWithFirstAccount, createKeyringWithFirstAccount_fn, _newKeyring, newKeyring_fn, _clearKeyrings, clearKeyrings_fn, _restoreKeyring, restoreKeyring_fn, _destroyKeyring, destroyKeyring_fn, _removeEmptyKeyrings, removeEmptyKeyrings_fn, _checkForDuplicate, checkForDuplicate_fn, _setUnlocked, setUnlocked_fn, _getMemState, getMemState_fn, _withVaultLock, withVaultLock_fn;
|
|
90
90
|
var KeyringController = class extends BaseController {
|
|
91
91
|
/**
|
|
92
92
|
* Creates a KeyringController instance.
|
|
@@ -266,25 +266,7 @@ var KeyringController = class extends BaseController {
|
|
|
266
266
|
* @fires KeyringController:unlock
|
|
267
267
|
*/
|
|
268
268
|
__privateAdd(this, _setUnlocked);
|
|
269
|
-
|
|
270
|
-
* Assert that the controller mutex is locked.
|
|
271
|
-
*
|
|
272
|
-
* @throws If the controller mutex is not locked.
|
|
273
|
-
*/
|
|
274
|
-
__privateAdd(this, _assertControllerMutexIsLocked);
|
|
275
|
-
/**
|
|
276
|
-
* Lock the controller mutex before executing the given function,
|
|
277
|
-
* and release it after the function is resolved or after an
|
|
278
|
-
* error is thrown.
|
|
279
|
-
*
|
|
280
|
-
* This wrapper ensures that each mutable operation that interacts with the
|
|
281
|
-
* controller and that changes its state is executed in a mutually exclusive way,
|
|
282
|
-
* preventing unsafe concurrent access that could lead to unpredictable behavior.
|
|
283
|
-
*
|
|
284
|
-
* @param fn - The function to execute while the controller mutex is locked.
|
|
285
|
-
* @returns The result of the function.
|
|
286
|
-
*/
|
|
287
|
-
__privateAdd(this, _withControllerLock);
|
|
269
|
+
__privateAdd(this, _getMemState);
|
|
288
270
|
/**
|
|
289
271
|
* Lock the vault mutex before executing the given function,
|
|
290
272
|
* and release it after the function is resolved or after an
|
|
@@ -297,7 +279,7 @@ var KeyringController = class extends BaseController {
|
|
|
297
279
|
* @returns The result of the function.
|
|
298
280
|
*/
|
|
299
281
|
__privateAdd(this, _withVaultLock);
|
|
300
|
-
__privateAdd(this,
|
|
282
|
+
__privateAdd(this, _initVaultMutex, new Mutex());
|
|
301
283
|
__privateAdd(this, _vaultOperationMutex, new Mutex());
|
|
302
284
|
__privateAdd(this, _keyringBuilders, void 0);
|
|
303
285
|
__privateAdd(this, _keyrings, void 0);
|
|
@@ -321,74 +303,75 @@ var KeyringController = class extends BaseController {
|
|
|
321
303
|
*
|
|
322
304
|
* @param accountCount - Number of accounts before adding a new one, used to
|
|
323
305
|
* make the method idempotent.
|
|
324
|
-
* @returns Promise resolving to
|
|
306
|
+
* @returns Promise resolving to keyring current state and added account
|
|
307
|
+
* address.
|
|
325
308
|
*/
|
|
326
309
|
async addNewAccount(accountCount) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
310
|
+
const primaryKeyring = this.getKeyringsByType("HD Key Tree")[0];
|
|
311
|
+
if (!primaryKeyring) {
|
|
312
|
+
throw new Error("No HD keyring found");
|
|
313
|
+
}
|
|
314
|
+
const oldAccounts = await primaryKeyring.getAccounts();
|
|
315
|
+
if (accountCount && oldAccounts.length !== accountCount) {
|
|
316
|
+
if (accountCount > oldAccounts.length) {
|
|
317
|
+
throw new Error("Account out of sequence");
|
|
331
318
|
}
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
|
|
335
|
-
throw new Error("Account out of sequence");
|
|
336
|
-
}
|
|
337
|
-
const existingAccount = oldAccounts[accountCount];
|
|
338
|
-
if (!existingAccount) {
|
|
339
|
-
throw new Error(`Can't find account at index ${accountCount}`);
|
|
340
|
-
}
|
|
341
|
-
return existingAccount;
|
|
319
|
+
const existingAccount = oldAccounts[accountCount];
|
|
320
|
+
if (!existingAccount) {
|
|
321
|
+
throw new Error(`Can't find account at index ${accountCount}`);
|
|
342
322
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}
|
|
323
|
+
return {
|
|
324
|
+
keyringState: __privateMethod(this, _getMemState, getMemState_fn).call(this),
|
|
325
|
+
addedAccountAddress: existingAccount
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
const [addedAccountAddress] = await primaryKeyring.addAccounts(1);
|
|
329
|
+
await this.verifySeedPhrase();
|
|
330
|
+
await __privateMethod(this, _updateVault, updateVault_fn).call(this);
|
|
331
|
+
return {
|
|
332
|
+
keyringState: __privateMethod(this, _getMemState, getMemState_fn).call(this),
|
|
333
|
+
addedAccountAddress
|
|
334
|
+
};
|
|
348
335
|
}
|
|
349
336
|
/**
|
|
350
337
|
* Adds a new account to the specified keyring.
|
|
351
338
|
*
|
|
352
339
|
* @param keyring - Keyring to add the account to.
|
|
353
340
|
* @param accountCount - Number of accounts before adding a new one, used to make the method idempotent.
|
|
354
|
-
* @returns Promise resolving to
|
|
341
|
+
* @returns Promise resolving to keyring current state and added account
|
|
355
342
|
*/
|
|
356
343
|
async addNewAccountForKeyring(keyring, accountCount) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (accountCount
|
|
360
|
-
|
|
361
|
-
throw new Error("Account out of sequence");
|
|
362
|
-
}
|
|
363
|
-
const existingAccount = oldAccounts[accountCount];
|
|
364
|
-
assertIsStrictHexString(existingAccount);
|
|
365
|
-
return existingAccount;
|
|
344
|
+
const oldAccounts = await __privateMethod(this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
|
|
345
|
+
if (accountCount && oldAccounts.length !== accountCount) {
|
|
346
|
+
if (accountCount > oldAccounts.length) {
|
|
347
|
+
throw new Error("Account out of sequence");
|
|
366
348
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
349
|
+
const existingAccount = oldAccounts[accountCount];
|
|
350
|
+
assertIsStrictHexString(existingAccount);
|
|
351
|
+
return existingAccount;
|
|
352
|
+
}
|
|
353
|
+
await keyring.addAccounts(1);
|
|
354
|
+
await __privateMethod(this, _updateVault, updateVault_fn).call(this);
|
|
355
|
+
const addedAccountAddress = (await __privateMethod(this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this)).find(
|
|
356
|
+
(selectedAddress) => !oldAccounts.includes(selectedAddress)
|
|
357
|
+
);
|
|
358
|
+
assertIsStrictHexString(addedAccountAddress);
|
|
359
|
+
return addedAccountAddress;
|
|
375
360
|
}
|
|
376
361
|
/**
|
|
377
362
|
* Adds a new account to the default (first) HD seed phrase keyring without updating identities in preferences.
|
|
378
363
|
*
|
|
379
|
-
* @returns Promise resolving to the
|
|
364
|
+
* @returns Promise resolving to current state when the account is added.
|
|
380
365
|
*/
|
|
381
366
|
async addNewAccountWithoutUpdate() {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
return addedAccountAddress;
|
|
391
|
-
});
|
|
367
|
+
const primaryKeyring = this.getKeyringsByType("HD Key Tree")[0];
|
|
368
|
+
if (!primaryKeyring) {
|
|
369
|
+
throw new Error("No HD keyring found");
|
|
370
|
+
}
|
|
371
|
+
await primaryKeyring.addAccounts(1);
|
|
372
|
+
await __privateMethod(this, _updateVault, updateVault_fn).call(this);
|
|
373
|
+
await this.verifySeedPhrase();
|
|
374
|
+
return __privateMethod(this, _getMemState, getMemState_fn).call(this);
|
|
392
375
|
}
|
|
393
376
|
/**
|
|
394
377
|
* Effectively the same as creating a new keychain then populating it
|
|
@@ -397,13 +380,14 @@ var KeyringController = class extends BaseController {
|
|
|
397
380
|
* @param password - Password to unlock keychain.
|
|
398
381
|
* @param seed - A BIP39-compliant seed phrase as Uint8Array,
|
|
399
382
|
* either as a string or an array of UTF-8 bytes that represent the string.
|
|
400
|
-
* @returns Promise resolving
|
|
383
|
+
* @returns Promise resolving to the restored keychain object.
|
|
401
384
|
*/
|
|
402
385
|
async createNewVaultAndRestore(password, seed) {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
386
|
+
const releaseLock = await __privateGet(this, _initVaultMutex).acquire();
|
|
387
|
+
if (!password || !password.length) {
|
|
388
|
+
throw new Error("Invalid password");
|
|
389
|
+
}
|
|
390
|
+
try {
|
|
407
391
|
await __privateMethod(this, _createNewVaultWithKeyring, createNewVaultWithKeyring_fn).call(this, password, {
|
|
408
392
|
type: "HD Key Tree" /* hd */,
|
|
409
393
|
opts: {
|
|
@@ -411,23 +395,30 @@ var KeyringController = class extends BaseController {
|
|
|
411
395
|
numberOfAccounts: 1
|
|
412
396
|
}
|
|
413
397
|
});
|
|
414
|
-
|
|
398
|
+
return __privateMethod(this, _getMemState, getMemState_fn).call(this);
|
|
399
|
+
} finally {
|
|
400
|
+
releaseLock();
|
|
401
|
+
}
|
|
415
402
|
}
|
|
416
403
|
/**
|
|
417
404
|
* Create a new primary keychain and wipe any previous keychains.
|
|
418
405
|
*
|
|
419
406
|
* @param password - Password to unlock the new vault.
|
|
420
|
-
* @returns
|
|
407
|
+
* @returns Newly-created keychain object.
|
|
421
408
|
*/
|
|
422
409
|
async createNewVaultAndKeychain(password) {
|
|
423
|
-
|
|
410
|
+
const releaseLock = await __privateGet(this, _initVaultMutex).acquire();
|
|
411
|
+
try {
|
|
424
412
|
const accounts = await __privateMethod(this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
|
|
425
413
|
if (!accounts.length) {
|
|
426
414
|
await __privateMethod(this, _createNewVaultWithKeyring, createNewVaultWithKeyring_fn).call(this, password, {
|
|
427
415
|
type: "HD Key Tree" /* hd */
|
|
428
416
|
});
|
|
429
417
|
}
|
|
430
|
-
|
|
418
|
+
return __privateMethod(this, _getMemState, getMemState_fn).call(this);
|
|
419
|
+
} finally {
|
|
420
|
+
releaseLock();
|
|
421
|
+
}
|
|
431
422
|
}
|
|
432
423
|
/**
|
|
433
424
|
* Adds a new keyring of the given `type`.
|
|
@@ -441,7 +432,7 @@ var KeyringController = class extends BaseController {
|
|
|
441
432
|
if (type === "QR Hardware Wallet Device" /* qr */) {
|
|
442
433
|
return this.getOrAddQRKeyring();
|
|
443
434
|
}
|
|
444
|
-
return __privateMethod(this,
|
|
435
|
+
return __privateMethod(this, _newKeyring, newKeyring_fn).call(this, type, opts, true);
|
|
445
436
|
}
|
|
446
437
|
/**
|
|
447
438
|
* Method to verify a given password validity. Throws an
|
|
@@ -497,10 +488,7 @@ var KeyringController = class extends BaseController {
|
|
|
497
488
|
* @returns A promise resolving to an array of addresses.
|
|
498
489
|
*/
|
|
499
490
|
async getAccounts() {
|
|
500
|
-
return this.
|
|
501
|
-
(accounts, keyring) => accounts.concat(keyring.accounts),
|
|
502
|
-
[]
|
|
503
|
-
);
|
|
491
|
+
return __privateMethod(this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
|
|
504
492
|
}
|
|
505
493
|
/**
|
|
506
494
|
* Get encryption public key.
|
|
@@ -593,7 +581,7 @@ var KeyringController = class extends BaseController {
|
|
|
593
581
|
* operation completes.
|
|
594
582
|
*/
|
|
595
583
|
async persistAllKeyrings() {
|
|
596
|
-
return __privateMethod(this,
|
|
584
|
+
return __privateMethod(this, _updateVault, updateVault_fn).call(this);
|
|
597
585
|
}
|
|
598
586
|
/**
|
|
599
587
|
* Imports an account with the specified import strategy.
|
|
@@ -601,88 +589,88 @@ var KeyringController = class extends BaseController {
|
|
|
601
589
|
* @param strategy - Import strategy name.
|
|
602
590
|
* @param args - Array of arguments to pass to the underlying stategy.
|
|
603
591
|
* @throws Will throw when passed an unrecognized strategy.
|
|
604
|
-
* @returns Promise resolving to
|
|
592
|
+
* @returns Promise resolving to keyring current state and imported account
|
|
593
|
+
* address.
|
|
605
594
|
*/
|
|
606
595
|
async importAccountWithStrategy(strategy, args) {
|
|
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
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
596
|
+
let privateKey;
|
|
597
|
+
switch (strategy) {
|
|
598
|
+
case "privateKey":
|
|
599
|
+
const [importedKey] = args;
|
|
600
|
+
if (!importedKey) {
|
|
601
|
+
throw new Error("Cannot import an empty key.");
|
|
602
|
+
}
|
|
603
|
+
const prefixed = add0x(importedKey);
|
|
604
|
+
let bufferedPrivateKey;
|
|
605
|
+
try {
|
|
606
|
+
bufferedPrivateKey = toBuffer(prefixed);
|
|
607
|
+
} catch {
|
|
608
|
+
throw new Error("Cannot import invalid private key.");
|
|
609
|
+
}
|
|
610
|
+
if (!isValidPrivate(bufferedPrivateKey) || // ensures that the key is 64 bytes long
|
|
611
|
+
getBinarySize(prefixed) !== 64 + "0x".length) {
|
|
612
|
+
throw new Error("Cannot import invalid private key.");
|
|
613
|
+
}
|
|
614
|
+
privateKey = remove0x(prefixed);
|
|
615
|
+
break;
|
|
616
|
+
case "json":
|
|
617
|
+
let wallet;
|
|
618
|
+
const [input, password] = args;
|
|
619
|
+
try {
|
|
620
|
+
wallet = importers.fromEtherWallet(input, password);
|
|
621
|
+
} catch (e) {
|
|
622
|
+
wallet = wallet || await Wallet.fromV3(input, password, true);
|
|
623
|
+
}
|
|
624
|
+
privateKey = bytesToHex(wallet.getPrivateKey());
|
|
625
|
+
break;
|
|
626
|
+
default:
|
|
627
|
+
throw new Error(`Unexpected import strategy: '${strategy}'`);
|
|
628
|
+
}
|
|
629
|
+
const newKeyring = await __privateMethod(this, _newKeyring, newKeyring_fn).call(this, "Simple Key Pair" /* simple */, [privateKey], true);
|
|
630
|
+
const accounts = await newKeyring.getAccounts();
|
|
631
|
+
return {
|
|
632
|
+
keyringState: __privateMethod(this, _getMemState, getMemState_fn).call(this),
|
|
633
|
+
importedAccountAddress: accounts[0]
|
|
634
|
+
};
|
|
645
635
|
}
|
|
646
636
|
/**
|
|
647
637
|
* Removes an account from keyring state.
|
|
648
638
|
*
|
|
649
639
|
* @param address - Address of the account to remove.
|
|
650
640
|
* @fires KeyringController:accountRemoved
|
|
651
|
-
* @returns Promise resolving when
|
|
641
|
+
* @returns Promise resolving current state when this account removal completes.
|
|
652
642
|
*/
|
|
653
643
|
async removeAccount(address) {
|
|
654
|
-
await
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
await __privateMethod(this, _updateVault, updateVault_fn).call(this);
|
|
667
|
-
});
|
|
644
|
+
const keyring = await this.getKeyringForAccount(
|
|
645
|
+
address
|
|
646
|
+
);
|
|
647
|
+
if (!keyring.removeAccount) {
|
|
648
|
+
throw new Error("`KeyringController - The keyring for the current address does not support the method removeAccount" /* UnsupportedRemoveAccount */);
|
|
649
|
+
}
|
|
650
|
+
await keyring.removeAccount(address);
|
|
651
|
+
const accounts = await keyring.getAccounts();
|
|
652
|
+
if (accounts.length === 0) {
|
|
653
|
+
await __privateMethod(this, _removeEmptyKeyrings, removeEmptyKeyrings_fn).call(this);
|
|
654
|
+
}
|
|
655
|
+
await __privateMethod(this, _updateVault, updateVault_fn).call(this);
|
|
668
656
|
this.messagingSystem.publish(`${name}:accountRemoved`, address);
|
|
657
|
+
return __privateMethod(this, _getMemState, getMemState_fn).call(this);
|
|
669
658
|
}
|
|
670
659
|
/**
|
|
671
660
|
* Deallocates all secrets and locks the wallet.
|
|
672
661
|
*
|
|
673
|
-
* @returns Promise resolving
|
|
662
|
+
* @returns Promise resolving to current state.
|
|
674
663
|
*/
|
|
675
664
|
async setLocked() {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
state.keyrings = [];
|
|
682
|
-
});
|
|
683
|
-
await __privateMethod(this, _clearKeyrings, clearKeyrings_fn).call(this);
|
|
684
|
-
this.messagingSystem.publish(`${name}:lock`);
|
|
665
|
+
__privateMethod(this, _unsubscribeFromQRKeyringsEvents, unsubscribeFromQRKeyringsEvents_fn).call(this);
|
|
666
|
+
__privateSet(this, _password, void 0);
|
|
667
|
+
this.update((state) => {
|
|
668
|
+
state.isUnlocked = false;
|
|
669
|
+
state.keyrings = [];
|
|
685
670
|
});
|
|
671
|
+
await __privateMethod(this, _clearKeyrings, clearKeyrings_fn).call(this);
|
|
672
|
+
this.messagingSystem.publish(`${name}:lock`);
|
|
673
|
+
return __privateMethod(this, _getMemState, getMemState_fn).call(this);
|
|
686
674
|
}
|
|
687
675
|
/**
|
|
688
676
|
* Signs message by calling down into a specific keyring.
|
|
@@ -836,34 +824,32 @@ var KeyringController = class extends BaseController {
|
|
|
836
824
|
*
|
|
837
825
|
* @param encryptionKey - Key to unlock the keychain.
|
|
838
826
|
* @param encryptionSalt - Salt to unlock the keychain.
|
|
839
|
-
* @returns Promise resolving
|
|
827
|
+
* @returns Promise resolving to the current state.
|
|
840
828
|
*/
|
|
841
829
|
async submitEncryptionKey(encryptionKey, encryptionSalt) {
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
});
|
|
830
|
+
__privateSet(this, _keyrings, await __privateMethod(this, _unlockKeyrings, unlockKeyrings_fn).call(this, void 0, encryptionKey, encryptionSalt));
|
|
831
|
+
__privateMethod(this, _setUnlocked, setUnlocked_fn).call(this);
|
|
832
|
+
const qrKeyring = this.getQRKeyring();
|
|
833
|
+
if (qrKeyring) {
|
|
834
|
+
__privateMethod(this, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn).call(this, qrKeyring);
|
|
835
|
+
}
|
|
836
|
+
return __privateMethod(this, _getMemState, getMemState_fn).call(this);
|
|
850
837
|
}
|
|
851
838
|
/**
|
|
852
839
|
* Attempts to decrypt the current vault and load its keyrings,
|
|
853
840
|
* using the given password.
|
|
854
841
|
*
|
|
855
842
|
* @param password - Password to unlock the keychain.
|
|
856
|
-
* @returns Promise resolving
|
|
843
|
+
* @returns Promise resolving to the current state.
|
|
857
844
|
*/
|
|
858
845
|
async submitPassword(password) {
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
});
|
|
846
|
+
__privateSet(this, _keyrings, await __privateMethod(this, _unlockKeyrings, unlockKeyrings_fn).call(this, password));
|
|
847
|
+
__privateMethod(this, _setUnlocked, setUnlocked_fn).call(this);
|
|
848
|
+
const qrKeyring = this.getQRKeyring();
|
|
849
|
+
if (qrKeyring) {
|
|
850
|
+
__privateMethod(this, _subscribeToQRKeyringEvents, subscribeToQRKeyringEvents_fn).call(this, qrKeyring);
|
|
851
|
+
}
|
|
852
|
+
return __privateMethod(this, _getMemState, getMemState_fn).call(this);
|
|
867
853
|
}
|
|
868
854
|
/**
|
|
869
855
|
* Verifies the that the seed phrase restores the current keychain's accounts.
|
|
@@ -913,16 +899,14 @@ var KeyringController = class extends BaseController {
|
|
|
913
899
|
* @returns The added keyring
|
|
914
900
|
*/
|
|
915
901
|
async getOrAddQRKeyring() {
|
|
916
|
-
return this.getQRKeyring() || await __privateMethod(this,
|
|
902
|
+
return this.getQRKeyring() || await __privateMethod(this, _addQRKeyring, addQRKeyring_fn).call(this);
|
|
917
903
|
}
|
|
918
904
|
// TODO: Replace `any` with type
|
|
919
905
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
920
906
|
async restoreQRKeyring(serialized) {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
await __privateMethod(this, _updateVault, updateVault_fn).call(this);
|
|
925
|
-
});
|
|
907
|
+
const keyring = this.getQRKeyring() || await __privateMethod(this, _addQRKeyring, addQRKeyring_fn).call(this);
|
|
908
|
+
keyring.deserialize(serialized);
|
|
909
|
+
await __privateMethod(this, _updateVault, updateVault_fn).call(this);
|
|
926
910
|
}
|
|
927
911
|
async resetQRKeyringState() {
|
|
928
912
|
(await this.getOrAddQRKeyring()).resetStore();
|
|
@@ -949,38 +933,34 @@ var KeyringController = class extends BaseController {
|
|
|
949
933
|
(await this.getOrAddQRKeyring()).cancelSync();
|
|
950
934
|
}
|
|
951
935
|
async connectQRHardware(page) {
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
accounts = await keyring.getFirstPage();
|
|
965
|
-
}
|
|
966
|
-
return accounts.map((account) => {
|
|
967
|
-
return {
|
|
968
|
-
...account,
|
|
969
|
-
balance: "0x0"
|
|
970
|
-
};
|
|
971
|
-
});
|
|
972
|
-
} catch (e) {
|
|
973
|
-
throw new Error(`Unspecified error when connect QR Hardware, ${e}`);
|
|
936
|
+
try {
|
|
937
|
+
const keyring = this.getQRKeyring() || await __privateMethod(this, _addQRKeyring, addQRKeyring_fn).call(this);
|
|
938
|
+
let accounts;
|
|
939
|
+
switch (page) {
|
|
940
|
+
case -1:
|
|
941
|
+
accounts = await keyring.getPreviousPage();
|
|
942
|
+
break;
|
|
943
|
+
case 1:
|
|
944
|
+
accounts = await keyring.getNextPage();
|
|
945
|
+
break;
|
|
946
|
+
default:
|
|
947
|
+
accounts = await keyring.getFirstPage();
|
|
974
948
|
}
|
|
975
|
-
|
|
949
|
+
return accounts.map((account) => {
|
|
950
|
+
return {
|
|
951
|
+
...account,
|
|
952
|
+
balance: "0x0"
|
|
953
|
+
};
|
|
954
|
+
});
|
|
955
|
+
} catch (e) {
|
|
956
|
+
throw new Error(`Unspecified error when connect QR Hardware, ${e}`);
|
|
957
|
+
}
|
|
976
958
|
}
|
|
977
959
|
async unlockQRHardwareWalletAccount(index) {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
await __privateMethod(this, _updateVault, updateVault_fn).call(this);
|
|
983
|
-
});
|
|
960
|
+
const keyring = this.getQRKeyring() || await __privateMethod(this, _addQRKeyring, addQRKeyring_fn).call(this);
|
|
961
|
+
keyring.setAccountToUnlock(index);
|
|
962
|
+
await keyring.addAccounts(1);
|
|
963
|
+
await __privateMethod(this, _updateVault, updateVault_fn).call(this);
|
|
984
964
|
}
|
|
985
965
|
async getAccountKeyringType(account) {
|
|
986
966
|
const keyring = await this.getKeyringForAccount(
|
|
@@ -989,23 +969,21 @@ var KeyringController = class extends BaseController {
|
|
|
989
969
|
return keyring.type;
|
|
990
970
|
}
|
|
991
971
|
async forgetQRDevice() {
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
return { removedAccounts, remainingAccounts };
|
|
1005
|
-
});
|
|
972
|
+
const keyring = this.getQRKeyring();
|
|
973
|
+
if (!keyring) {
|
|
974
|
+
return { removedAccounts: [], remainingAccounts: [] };
|
|
975
|
+
}
|
|
976
|
+
const allAccounts = await __privateMethod(this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
|
|
977
|
+
keyring.forgetDevice();
|
|
978
|
+
const remainingAccounts = await __privateMethod(this, _getAccountsFromKeyrings, getAccountsFromKeyrings_fn).call(this);
|
|
979
|
+
const removedAccounts = allAccounts.filter(
|
|
980
|
+
(address) => !remainingAccounts.includes(address)
|
|
981
|
+
);
|
|
982
|
+
await __privateMethod(this, _updateVault, updateVault_fn).call(this);
|
|
983
|
+
return { removedAccounts, remainingAccounts };
|
|
1006
984
|
}
|
|
1007
985
|
};
|
|
1008
|
-
|
|
986
|
+
_initVaultMutex = new WeakMap();
|
|
1009
987
|
_vaultOperationMutex = new WeakMap();
|
|
1010
988
|
_keyringBuilders = new WeakMap();
|
|
1011
989
|
_keyrings = new WeakMap();
|
|
@@ -1073,7 +1051,6 @@ getKeyringBuilderForType_fn = function(type) {
|
|
|
1073
1051
|
};
|
|
1074
1052
|
_addQRKeyring = new WeakSet();
|
|
1075
1053
|
addQRKeyring_fn = async function() {
|
|
1076
|
-
__privateMethod(this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1077
1054
|
const qrKeyring = await __privateMethod(this, _newKeyring, newKeyring_fn).call(this, "QR Hardware Wallet Device" /* qr */, {
|
|
1078
1055
|
accounts: []
|
|
1079
1056
|
});
|
|
@@ -1104,7 +1081,6 @@ unsubscribeFromQRKeyringsEvents_fn = function() {
|
|
|
1104
1081
|
};
|
|
1105
1082
|
_createNewVaultWithKeyring = new WeakSet();
|
|
1106
1083
|
createNewVaultWithKeyring_fn = async function(password, keyring) {
|
|
1107
|
-
__privateMethod(this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1108
1084
|
if (typeof password !== "string") {
|
|
1109
1085
|
throw new TypeError("KeyringController - Password must be of type string." /* WrongPasswordType */);
|
|
1110
1086
|
}
|
|
@@ -1112,6 +1088,7 @@ createNewVaultWithKeyring_fn = async function(password, keyring) {
|
|
|
1112
1088
|
await __privateMethod(this, _clearKeyrings, clearKeyrings_fn).call(this);
|
|
1113
1089
|
await __privateMethod(this, _createKeyringWithFirstAccount, createKeyringWithFirstAccount_fn).call(this, keyring.type, keyring.opts);
|
|
1114
1090
|
__privateMethod(this, _setUnlocked, setUnlocked_fn).call(this);
|
|
1091
|
+
return __privateMethod(this, _getMemState, getMemState_fn).call(this);
|
|
1115
1092
|
};
|
|
1116
1093
|
_getUpdatedKeyrings = new WeakSet();
|
|
1117
1094
|
getUpdatedKeyrings_fn = async function() {
|
|
@@ -1256,7 +1233,6 @@ getAccountsFromKeyrings_fn = async function() {
|
|
|
1256
1233
|
};
|
|
1257
1234
|
_createKeyringWithFirstAccount = new WeakSet();
|
|
1258
1235
|
createKeyringWithFirstAccount_fn = async function(type, opts) {
|
|
1259
|
-
__privateMethod(this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1260
1236
|
const keyring = await __privateMethod(this, _newKeyring, newKeyring_fn).call(this, type, opts, true);
|
|
1261
1237
|
const [firstAccount] = await keyring.getAccounts();
|
|
1262
1238
|
if (!firstAccount) {
|
|
@@ -1265,7 +1241,6 @@ createKeyringWithFirstAccount_fn = async function(type, opts) {
|
|
|
1265
1241
|
};
|
|
1266
1242
|
_newKeyring = new WeakSet();
|
|
1267
1243
|
newKeyring_fn = async function(type, data, persist = false) {
|
|
1268
|
-
__privateMethod(this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1269
1244
|
const keyringBuilder = __privateMethod(this, _getKeyringBuilderForType, getKeyringBuilderForType_fn).call(this, type);
|
|
1270
1245
|
if (!keyringBuilder) {
|
|
1271
1246
|
throw new Error(
|
|
@@ -1295,7 +1270,6 @@ newKeyring_fn = async function(type, data, persist = false) {
|
|
|
1295
1270
|
};
|
|
1296
1271
|
_clearKeyrings = new WeakSet();
|
|
1297
1272
|
clearKeyrings_fn = async function(options = { skipStateUpdate: false }) {
|
|
1298
|
-
__privateMethod(this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1299
1273
|
for (const keyring of __privateGet(this, _keyrings)) {
|
|
1300
1274
|
await __privateMethod(this, _destroyKeyring, destroyKeyring_fn).call(this, keyring);
|
|
1301
1275
|
}
|
|
@@ -1308,7 +1282,6 @@ clearKeyrings_fn = async function(options = { skipStateUpdate: false }) {
|
|
|
1308
1282
|
};
|
|
1309
1283
|
_restoreKeyring = new WeakSet();
|
|
1310
1284
|
restoreKeyring_fn = async function(serialized) {
|
|
1311
|
-
__privateMethod(this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1312
1285
|
try {
|
|
1313
1286
|
const { type, data } = serialized;
|
|
1314
1287
|
const keyring = await __privateMethod(this, _newKeyring, newKeyring_fn).call(this, type, data);
|
|
@@ -1326,7 +1299,6 @@ destroyKeyring_fn = async function(keyring) {
|
|
|
1326
1299
|
};
|
|
1327
1300
|
_removeEmptyKeyrings = new WeakSet();
|
|
1328
1301
|
removeEmptyKeyrings_fn = async function() {
|
|
1329
|
-
__privateMethod(this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1330
1302
|
const validKeyrings = [];
|
|
1331
1303
|
await Promise.all(
|
|
1332
1304
|
__privateGet(this, _keyrings).map(async (keyring) => {
|
|
@@ -1362,35 +1334,27 @@ checkForDuplicate_fn = async function(type, newAccountArray) {
|
|
|
1362
1334
|
};
|
|
1363
1335
|
_setUnlocked = new WeakSet();
|
|
1364
1336
|
setUnlocked_fn = function() {
|
|
1365
|
-
__privateMethod(this, _assertControllerMutexIsLocked, assertControllerMutexIsLocked_fn).call(this);
|
|
1366
1337
|
this.update((state) => {
|
|
1367
1338
|
state.isUnlocked = true;
|
|
1368
1339
|
});
|
|
1369
1340
|
this.messagingSystem.publish(`${name}:unlock`);
|
|
1370
1341
|
};
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
};
|
|
1377
|
-
_withControllerLock = new WeakSet();
|
|
1378
|
-
withControllerLock_fn = async function(fn) {
|
|
1379
|
-
return withLock(__privateGet(this, _controllerOperationMutex), fn);
|
|
1342
|
+
_getMemState = new WeakSet();
|
|
1343
|
+
getMemState_fn = function() {
|
|
1344
|
+
return {
|
|
1345
|
+
isUnlocked: this.state.isUnlocked,
|
|
1346
|
+
keyrings: this.state.keyrings
|
|
1347
|
+
};
|
|
1380
1348
|
};
|
|
1381
1349
|
_withVaultLock = new WeakSet();
|
|
1382
1350
|
withVaultLock_fn = async function(fn) {
|
|
1383
|
-
|
|
1384
|
-
return withLock(__privateGet(this, _vaultOperationMutex), fn);
|
|
1385
|
-
};
|
|
1386
|
-
async function withLock(mutex, fn) {
|
|
1387
|
-
const releaseLock = await mutex.acquire();
|
|
1351
|
+
const releaseLock = await __privateGet(this, _vaultOperationMutex).acquire();
|
|
1388
1352
|
try {
|
|
1389
1353
|
return await fn({ releaseLock });
|
|
1390
1354
|
} finally {
|
|
1391
1355
|
releaseLock();
|
|
1392
1356
|
}
|
|
1393
|
-
}
|
|
1357
|
+
};
|
|
1394
1358
|
var KeyringController_default = KeyringController;
|
|
1395
1359
|
|
|
1396
1360
|
export {
|
|
@@ -1403,4 +1367,4 @@ export {
|
|
|
1403
1367
|
KeyringController,
|
|
1404
1368
|
KeyringController_default
|
|
1405
1369
|
};
|
|
1406
|
-
//# sourceMappingURL=chunk-
|
|
1370
|
+
//# sourceMappingURL=chunk-5QTEIEPG.mjs.map
|