@metamask-previews/keyring-controller 19.0.5-preview-d21875e1 → 19.0.5-preview-082735ba
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/dist/KeyringController.cjs +54 -24
- package/dist/KeyringController.cjs.map +1 -1
- package/dist/KeyringController.d.cts +14 -28
- package/dist/KeyringController.d.cts.map +1 -1
- package/dist/KeyringController.d.mts +14 -28
- package/dist/KeyringController.d.mts.map +1 -1
- package/dist/KeyringController.mjs +54 -24
- package/dist/KeyringController.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
36
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
38
|
};
|
|
39
|
-
var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders,
|
|
39
|
+
var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_password, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_qrKeyringStateListener, _KeyringController_registerMessageHandlers, _KeyringController_getKeyringBuilderForType, _KeyringController_addQRKeyring, _KeyringController_subscribeToQRKeyringEvents, _KeyringController_unsubscribeFromQRKeyringsEvents, _KeyringController_createNewVaultWithKeyring, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_removeEmptyKeyrings, _KeyringController_checkForDuplicate, _KeyringController_setUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
41
|
exports.KeyringController = exports.getDefaultKeyringState = exports.keyringBuilderFactory = exports.SignTypedDataVersion = exports.AccountImportStrategy = exports.isCustodyKeyring = exports.KeyringTypes = void 0;
|
|
42
42
|
const util_1 = require("@ethereumjs/util");
|
|
@@ -55,18 +55,31 @@ const name = 'KeyringController';
|
|
|
55
55
|
*/
|
|
56
56
|
var KeyringTypes;
|
|
57
57
|
(function (KeyringTypes) {
|
|
58
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
58
60
|
KeyringTypes["simple"] = "Simple Key Pair";
|
|
61
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
59
63
|
KeyringTypes["hd"] = "HD Key Tree";
|
|
64
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
60
66
|
KeyringTypes["qr"] = "QR Hardware Wallet Device";
|
|
67
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
61
69
|
KeyringTypes["trezor"] = "Trezor Hardware";
|
|
70
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
62
72
|
KeyringTypes["ledger"] = "Ledger Hardware";
|
|
73
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
63
75
|
KeyringTypes["lattice"] = "Lattice Hardware";
|
|
76
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
64
78
|
KeyringTypes["snap"] = "Snap Keyring";
|
|
65
79
|
})(KeyringTypes || (exports.KeyringTypes = KeyringTypes = {}));
|
|
66
80
|
/**
|
|
67
81
|
* Custody keyring types are a special case, as they are not a single type
|
|
68
82
|
* but they all start with the prefix "Custody".
|
|
69
|
-
*
|
|
70
83
|
* @param keyringType - The type of the keyring.
|
|
71
84
|
* @returns Whether the keyring type is a custody keyring.
|
|
72
85
|
*/
|
|
@@ -79,7 +92,11 @@ exports.isCustodyKeyring = isCustodyKeyring;
|
|
|
79
92
|
*/
|
|
80
93
|
var AccountImportStrategy;
|
|
81
94
|
(function (AccountImportStrategy) {
|
|
95
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
82
97
|
AccountImportStrategy["privateKey"] = "privateKey";
|
|
98
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
83
100
|
AccountImportStrategy["json"] = "json";
|
|
84
101
|
})(AccountImportStrategy || (exports.AccountImportStrategy = AccountImportStrategy = {}));
|
|
85
102
|
/**
|
|
@@ -259,11 +276,11 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
259
276
|
_KeyringController_controllerOperationMutex.set(this, new async_mutex_1.Mutex());
|
|
260
277
|
_KeyringController_vaultOperationMutex.set(this, new async_mutex_1.Mutex());
|
|
261
278
|
_KeyringController_keyringBuilders.set(this, void 0);
|
|
279
|
+
_KeyringController_keyrings.set(this, void 0);
|
|
262
280
|
_KeyringController_unsupportedKeyrings.set(this, void 0);
|
|
281
|
+
_KeyringController_password.set(this, void 0);
|
|
263
282
|
_KeyringController_encryptor.set(this, void 0);
|
|
264
283
|
_KeyringController_cacheEncryptionKey.set(this, void 0);
|
|
265
|
-
_KeyringController_keyrings.set(this, void 0);
|
|
266
|
-
_KeyringController_password.set(this, void 0);
|
|
267
284
|
_KeyringController_qrKeyringStateListener.set(this, void 0);
|
|
268
285
|
__classPrivateFieldSet(this, _KeyringController_keyringBuilders, keyringBuilders
|
|
269
286
|
? keyringBuilders.concat(defaultKeyringBuilders)
|
|
@@ -365,7 +382,6 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
365
382
|
* If there is a pre-existing locked vault, it will be replaced.
|
|
366
383
|
*
|
|
367
384
|
* @param password - Password to unlock the new vault.
|
|
368
|
-
* @returns Promise resolving when the operation ends successfully.
|
|
369
385
|
*/
|
|
370
386
|
async createNewVaultAndKeychain(password) {
|
|
371
387
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
|
|
@@ -546,7 +562,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
546
562
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
|
|
547
563
|
let privateKey;
|
|
548
564
|
switch (strategy) {
|
|
549
|
-
case
|
|
565
|
+
case 'privateKey':
|
|
550
566
|
const [importedKey] = args;
|
|
551
567
|
if (!importedKey) {
|
|
552
568
|
throw new Error('Cannot import an empty key.');
|
|
@@ -566,7 +582,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
566
582
|
}
|
|
567
583
|
privateKey = (0, utils_1.remove0x)(prefixed);
|
|
568
584
|
break;
|
|
569
|
-
case
|
|
585
|
+
case 'json':
|
|
570
586
|
let wallet;
|
|
571
587
|
const [input, password] = args;
|
|
572
588
|
try {
|
|
@@ -578,7 +594,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
578
594
|
privateKey = (0, utils_1.bytesToHex)(wallet.getPrivateKey());
|
|
579
595
|
break;
|
|
580
596
|
default:
|
|
581
|
-
throw new Error(`Unexpected import strategy: '${
|
|
597
|
+
throw new Error(`Unexpected import strategy: '${strategy}'`);
|
|
582
598
|
}
|
|
583
599
|
const newKeyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, KeyringTypes.simple, [
|
|
584
600
|
privateKey,
|
|
@@ -603,6 +619,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
603
619
|
}
|
|
604
620
|
// The `removeAccount` method of snaps keyring is async. We have to update
|
|
605
621
|
// the interface of the other keyrings to be async as well.
|
|
622
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
606
623
|
// FIXME: We do cast to `Hex` to makes the type checker happy here, and
|
|
607
624
|
// because `Keyring<State>.removeAccount` requires address to be `Hex`. Those
|
|
608
625
|
// type would need to be updated for a full non-EVM support.
|
|
@@ -1038,7 +1055,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
1038
1055
|
}
|
|
1039
1056
|
}
|
|
1040
1057
|
exports.KeyringController = KeyringController;
|
|
1041
|
-
_KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(),
|
|
1058
|
+
_KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_password = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_cacheEncryptionKey = new WeakMap(), _KeyringController_qrKeyringStateListener = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
|
|
1042
1059
|
this.messagingSystem.registerActionHandler(`${name}:signMessage`, this.signMessage.bind(this));
|
|
1043
1060
|
this.messagingSystem.registerActionHandler(`${name}:signPersonalMessage`, this.signPersonalMessage.bind(this));
|
|
1044
1061
|
this.messagingSystem.registerActionHandler(`${name}:signTypedMessage`, this.signTypedMessage.bind(this));
|
|
@@ -1373,6 +1390,9 @@ async function _KeyringController_newKeyring(type, data) {
|
|
|
1373
1390
|
// NOTE: Not all keyrings implement this method in a asynchronous-way. Using `await` for
|
|
1374
1391
|
// non-thenable will still be valid (despite not being really useful). It allows us to cover both
|
|
1375
1392
|
// cases and allow retro-compatibility too.
|
|
1393
|
+
// FIXME: For some reason, it seems that eslint is complaining about this call being non-thenable
|
|
1394
|
+
// even though it is... For now, we just disable it:
|
|
1395
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
1376
1396
|
await keyring.generateRandomMnemonic();
|
|
1377
1397
|
await keyring.addAccounts(1);
|
|
1378
1398
|
}
|
|
@@ -1487,12 +1507,14 @@ async function _KeyringController_checkForDuplicate(type, newAccountArray) {
|
|
|
1487
1507
|
* and save the keyrings to state after it, or rollback to their
|
|
1488
1508
|
* previous state in case of error.
|
|
1489
1509
|
*
|
|
1490
|
-
* @param
|
|
1510
|
+
* @param fn - The function to execute.
|
|
1491
1511
|
* @returns The result of the function.
|
|
1492
1512
|
*/
|
|
1493
|
-
|
|
1513
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
1514
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1515
|
+
async function _KeyringController_persistOrRollback(fn) {
|
|
1494
1516
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async ({ releaseLock }) => {
|
|
1495
|
-
const callbackResult = await
|
|
1517
|
+
const callbackResult = await fn({ releaseLock });
|
|
1496
1518
|
// State is committed only if the operation is successful
|
|
1497
1519
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
1498
1520
|
return callbackResult;
|
|
@@ -1502,15 +1524,17 @@ async function _KeyringController_persistOrRollback(callback) {
|
|
|
1502
1524
|
* Execute the given function after acquiring the controller lock
|
|
1503
1525
|
* and rollback keyrings and password states in case of error.
|
|
1504
1526
|
*
|
|
1505
|
-
* @param
|
|
1527
|
+
* @param fn - The function to execute atomically.
|
|
1506
1528
|
* @returns The result of the function.
|
|
1507
1529
|
*/
|
|
1508
|
-
|
|
1530
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
1531
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1532
|
+
async function _KeyringController_withRollback(fn) {
|
|
1509
1533
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async ({ releaseLock }) => {
|
|
1510
1534
|
const currentSerializedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSerializedKeyrings).call(this);
|
|
1511
1535
|
const currentPassword = __classPrivateFieldGet(this, _KeyringController_password, "f");
|
|
1512
1536
|
try {
|
|
1513
|
-
return await
|
|
1537
|
+
return await fn({ releaseLock });
|
|
1514
1538
|
}
|
|
1515
1539
|
catch (e) {
|
|
1516
1540
|
// Keyrings and password are restored to their previous state
|
|
@@ -1533,11 +1557,13 @@ async function _KeyringController_withRollback(callback) {
|
|
|
1533
1557
|
* controller and that changes its state is executed in a mutually exclusive way,
|
|
1534
1558
|
* preventing unsafe concurrent access that could lead to unpredictable behavior.
|
|
1535
1559
|
*
|
|
1536
|
-
* @param
|
|
1560
|
+
* @param fn - The function to execute while the controller mutex is locked.
|
|
1537
1561
|
* @returns The result of the function.
|
|
1538
1562
|
*/
|
|
1539
|
-
|
|
1540
|
-
|
|
1563
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
1564
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1565
|
+
async function _KeyringController_withControllerLock(fn) {
|
|
1566
|
+
return withLock(__classPrivateFieldGet(this, _KeyringController_controllerOperationMutex, "f"), fn);
|
|
1541
1567
|
}, _KeyringController_withVaultLock =
|
|
1542
1568
|
/**
|
|
1543
1569
|
* Lock the vault mutex before executing the given function,
|
|
@@ -1547,12 +1573,14 @@ async function _KeyringController_withControllerLock(callback) {
|
|
|
1547
1573
|
* This ensures that each operation that interacts with the vault
|
|
1548
1574
|
* is executed in a mutually exclusive way.
|
|
1549
1575
|
*
|
|
1550
|
-
* @param
|
|
1576
|
+
* @param fn - The function to execute while the vault mutex is locked.
|
|
1551
1577
|
* @returns The result of the function.
|
|
1552
1578
|
*/
|
|
1553
|
-
|
|
1579
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
1580
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1581
|
+
async function _KeyringController_withVaultLock(fn) {
|
|
1554
1582
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1555
|
-
return withLock(__classPrivateFieldGet(this, _KeyringController_vaultOperationMutex, "f"),
|
|
1583
|
+
return withLock(__classPrivateFieldGet(this, _KeyringController_vaultOperationMutex, "f"), fn);
|
|
1556
1584
|
};
|
|
1557
1585
|
/**
|
|
1558
1586
|
* Lock the given mutex before executing the given function,
|
|
@@ -1560,13 +1588,15 @@ async function _KeyringController_withVaultLock(callback) {
|
|
|
1560
1588
|
* error is thrown.
|
|
1561
1589
|
*
|
|
1562
1590
|
* @param mutex - The mutex to lock.
|
|
1563
|
-
* @param
|
|
1591
|
+
* @param fn - The function to execute while the mutex is locked.
|
|
1564
1592
|
* @returns The result of the function.
|
|
1565
1593
|
*/
|
|
1566
|
-
|
|
1594
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
1595
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1596
|
+
async function withLock(mutex, fn) {
|
|
1567
1597
|
const releaseLock = await mutex.acquire();
|
|
1568
1598
|
try {
|
|
1569
|
-
return await
|
|
1599
|
+
return await fn({ releaseLock });
|
|
1570
1600
|
}
|
|
1571
1601
|
finally {
|
|
1572
1602
|
releaseLock();
|