@metamask-previews/keyring-controller 19.0.5-preview-442894ce → 19.0.5-preview-43593c4e
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 +25 -55
- package/dist/KeyringController.cjs.map +1 -1
- package/dist/KeyringController.d.cts +31 -17
- package/dist/KeyringController.d.cts.map +1 -1
- package/dist/KeyringController.d.mts +31 -17
- package/dist/KeyringController.d.mts.map +1 -1
- package/dist/KeyringController.mjs +25 -55
- package/dist/KeyringController.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -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_unsupportedKeyrings, _KeyringController_encryptor, _KeyringController_cacheEncryptionKey, _KeyringController_keyrings, _KeyringController_password, _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,31 +55,18 @@ 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
|
|
60
58
|
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
|
|
63
59
|
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
|
|
66
60
|
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
|
|
69
61
|
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
|
|
72
62
|
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
|
|
75
63
|
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
|
|
78
64
|
KeyringTypes["snap"] = "Snap Keyring";
|
|
79
65
|
})(KeyringTypes || (exports.KeyringTypes = KeyringTypes = {}));
|
|
80
66
|
/**
|
|
81
67
|
* Custody keyring types are a special case, as they are not a single type
|
|
82
68
|
* but they all start with the prefix "Custody".
|
|
69
|
+
*
|
|
83
70
|
* @param keyringType - The type of the keyring.
|
|
84
71
|
* @returns Whether the keyring type is a custody keyring.
|
|
85
72
|
*/
|
|
@@ -92,11 +79,7 @@ exports.isCustodyKeyring = isCustodyKeyring;
|
|
|
92
79
|
*/
|
|
93
80
|
var AccountImportStrategy;
|
|
94
81
|
(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
|
|
97
82
|
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
|
|
100
83
|
AccountImportStrategy["json"] = "json";
|
|
101
84
|
})(AccountImportStrategy || (exports.AccountImportStrategy = AccountImportStrategy = {}));
|
|
102
85
|
/**
|
|
@@ -252,7 +235,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
252
235
|
* @param options.encryptor - An optional object for defining encryption schemes.
|
|
253
236
|
* @param options.keyringBuilders - Set a new name for account.
|
|
254
237
|
* @param options.cacheEncryptionKey - Whether to cache or not encryption key.
|
|
255
|
-
* @param options.messenger - A restricted
|
|
238
|
+
* @param options.messenger - A restricted messenger.
|
|
256
239
|
* @param options.state - Initial state to set on this controller.
|
|
257
240
|
*/
|
|
258
241
|
constructor(options) {
|
|
@@ -276,11 +259,11 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
276
259
|
_KeyringController_controllerOperationMutex.set(this, new async_mutex_1.Mutex());
|
|
277
260
|
_KeyringController_vaultOperationMutex.set(this, new async_mutex_1.Mutex());
|
|
278
261
|
_KeyringController_keyringBuilders.set(this, void 0);
|
|
279
|
-
_KeyringController_keyrings.set(this, void 0);
|
|
280
262
|
_KeyringController_unsupportedKeyrings.set(this, void 0);
|
|
281
|
-
_KeyringController_password.set(this, void 0);
|
|
282
263
|
_KeyringController_encryptor.set(this, void 0);
|
|
283
264
|
_KeyringController_cacheEncryptionKey.set(this, void 0);
|
|
265
|
+
_KeyringController_keyrings.set(this, void 0);
|
|
266
|
+
_KeyringController_password.set(this, void 0);
|
|
284
267
|
_KeyringController_qrKeyringStateListener.set(this, void 0);
|
|
285
268
|
__classPrivateFieldSet(this, _KeyringController_keyringBuilders, keyringBuilders
|
|
286
269
|
? keyringBuilders.concat(defaultKeyringBuilders)
|
|
@@ -382,6 +365,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
382
365
|
* If there is a pre-existing locked vault, it will be replaced.
|
|
383
366
|
*
|
|
384
367
|
* @param password - Password to unlock the new vault.
|
|
368
|
+
* @returns Promise resolving when the operation ends successfully.
|
|
385
369
|
*/
|
|
386
370
|
async createNewVaultAndKeychain(password) {
|
|
387
371
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
|
|
@@ -562,7 +546,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
562
546
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
|
|
563
547
|
let privateKey;
|
|
564
548
|
switch (strategy) {
|
|
565
|
-
case
|
|
549
|
+
case AccountImportStrategy.privateKey:
|
|
566
550
|
const [importedKey] = args;
|
|
567
551
|
if (!importedKey) {
|
|
568
552
|
throw new Error('Cannot import an empty key.');
|
|
@@ -582,7 +566,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
582
566
|
}
|
|
583
567
|
privateKey = (0, utils_1.remove0x)(prefixed);
|
|
584
568
|
break;
|
|
585
|
-
case
|
|
569
|
+
case AccountImportStrategy.json:
|
|
586
570
|
let wallet;
|
|
587
571
|
const [input, password] = args;
|
|
588
572
|
try {
|
|
@@ -594,7 +578,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
594
578
|
privateKey = (0, utils_1.bytesToHex)(wallet.getPrivateKey());
|
|
595
579
|
break;
|
|
596
580
|
default:
|
|
597
|
-
throw new Error(`Unexpected import strategy: '${strategy}'`);
|
|
581
|
+
throw new Error(`Unexpected import strategy: '${String(strategy)}'`);
|
|
598
582
|
}
|
|
599
583
|
const newKeyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, KeyringTypes.simple, [
|
|
600
584
|
privateKey,
|
|
@@ -619,7 +603,6 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
619
603
|
}
|
|
620
604
|
// The `removeAccount` method of snaps keyring is async. We have to update
|
|
621
605
|
// the interface of the other keyrings to be async as well.
|
|
622
|
-
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
623
606
|
// FIXME: We do cast to `Hex` to makes the type checker happy here, and
|
|
624
607
|
// because `Keyring<State>.removeAccount` requires address to be `Hex`. Those
|
|
625
608
|
// type would need to be updated for a full non-EVM support.
|
|
@@ -1055,7 +1038,7 @@ class KeyringController extends base_controller_1.BaseController {
|
|
|
1055
1038
|
}
|
|
1056
1039
|
}
|
|
1057
1040
|
exports.KeyringController = KeyringController;
|
|
1058
|
-
_KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(),
|
|
1041
|
+
_KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_cacheEncryptionKey = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_password = new WeakMap(), _KeyringController_qrKeyringStateListener = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
|
|
1059
1042
|
this.messagingSystem.registerActionHandler(`${name}:signMessage`, this.signMessage.bind(this));
|
|
1060
1043
|
this.messagingSystem.registerActionHandler(`${name}:signPersonalMessage`, this.signPersonalMessage.bind(this));
|
|
1061
1044
|
this.messagingSystem.registerActionHandler(`${name}:signTypedMessage`, this.signTypedMessage.bind(this));
|
|
@@ -1390,9 +1373,6 @@ async function _KeyringController_newKeyring(type, data) {
|
|
|
1390
1373
|
// NOTE: Not all keyrings implement this method in a asynchronous-way. Using `await` for
|
|
1391
1374
|
// non-thenable will still be valid (despite not being really useful). It allows us to cover both
|
|
1392
1375
|
// 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
|
|
1396
1376
|
await keyring.generateRandomMnemonic();
|
|
1397
1377
|
await keyring.addAccounts(1);
|
|
1398
1378
|
}
|
|
@@ -1507,14 +1487,12 @@ async function _KeyringController_checkForDuplicate(type, newAccountArray) {
|
|
|
1507
1487
|
* and save the keyrings to state after it, or rollback to their
|
|
1508
1488
|
* previous state in case of error.
|
|
1509
1489
|
*
|
|
1510
|
-
* @param
|
|
1490
|
+
* @param callback - The function to execute.
|
|
1511
1491
|
* @returns The result of the function.
|
|
1512
1492
|
*/
|
|
1513
|
-
|
|
1514
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1515
|
-
async function _KeyringController_persistOrRollback(fn) {
|
|
1493
|
+
async function _KeyringController_persistOrRollback(callback) {
|
|
1516
1494
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async ({ releaseLock }) => {
|
|
1517
|
-
const callbackResult = await
|
|
1495
|
+
const callbackResult = await callback({ releaseLock });
|
|
1518
1496
|
// State is committed only if the operation is successful
|
|
1519
1497
|
await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
|
|
1520
1498
|
return callbackResult;
|
|
@@ -1524,17 +1502,15 @@ async function _KeyringController_persistOrRollback(fn) {
|
|
|
1524
1502
|
* Execute the given function after acquiring the controller lock
|
|
1525
1503
|
* and rollback keyrings and password states in case of error.
|
|
1526
1504
|
*
|
|
1527
|
-
* @param
|
|
1505
|
+
* @param callback - The function to execute atomically.
|
|
1528
1506
|
* @returns The result of the function.
|
|
1529
1507
|
*/
|
|
1530
|
-
|
|
1531
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1532
|
-
async function _KeyringController_withRollback(fn) {
|
|
1508
|
+
async function _KeyringController_withRollback(callback) {
|
|
1533
1509
|
return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withControllerLock).call(this, async ({ releaseLock }) => {
|
|
1534
1510
|
const currentSerializedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSerializedKeyrings).call(this);
|
|
1535
1511
|
const currentPassword = __classPrivateFieldGet(this, _KeyringController_password, "f");
|
|
1536
1512
|
try {
|
|
1537
|
-
return await
|
|
1513
|
+
return await callback({ releaseLock });
|
|
1538
1514
|
}
|
|
1539
1515
|
catch (e) {
|
|
1540
1516
|
// Keyrings and password are restored to their previous state
|
|
@@ -1557,13 +1533,11 @@ async function _KeyringController_withRollback(fn) {
|
|
|
1557
1533
|
* controller and that changes its state is executed in a mutually exclusive way,
|
|
1558
1534
|
* preventing unsafe concurrent access that could lead to unpredictable behavior.
|
|
1559
1535
|
*
|
|
1560
|
-
* @param
|
|
1536
|
+
* @param callback - The function to execute while the controller mutex is locked.
|
|
1561
1537
|
* @returns The result of the function.
|
|
1562
1538
|
*/
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
async function _KeyringController_withControllerLock(fn) {
|
|
1566
|
-
return withLock(__classPrivateFieldGet(this, _KeyringController_controllerOperationMutex, "f"), fn);
|
|
1539
|
+
async function _KeyringController_withControllerLock(callback) {
|
|
1540
|
+
return withLock(__classPrivateFieldGet(this, _KeyringController_controllerOperationMutex, "f"), callback);
|
|
1567
1541
|
}, _KeyringController_withVaultLock =
|
|
1568
1542
|
/**
|
|
1569
1543
|
* Lock the vault mutex before executing the given function,
|
|
@@ -1573,14 +1547,12 @@ async function _KeyringController_withControllerLock(fn) {
|
|
|
1573
1547
|
* This ensures that each operation that interacts with the vault
|
|
1574
1548
|
* is executed in a mutually exclusive way.
|
|
1575
1549
|
*
|
|
1576
|
-
* @param
|
|
1550
|
+
* @param callback - The function to execute while the vault mutex is locked.
|
|
1577
1551
|
* @returns The result of the function.
|
|
1578
1552
|
*/
|
|
1579
|
-
|
|
1580
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1581
|
-
async function _KeyringController_withVaultLock(fn) {
|
|
1553
|
+
async function _KeyringController_withVaultLock(callback) {
|
|
1582
1554
|
__classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
|
|
1583
|
-
return withLock(__classPrivateFieldGet(this, _KeyringController_vaultOperationMutex, "f"),
|
|
1555
|
+
return withLock(__classPrivateFieldGet(this, _KeyringController_vaultOperationMutex, "f"), callback);
|
|
1584
1556
|
};
|
|
1585
1557
|
/**
|
|
1586
1558
|
* Lock the given mutex before executing the given function,
|
|
@@ -1588,15 +1560,13 @@ async function _KeyringController_withVaultLock(fn) {
|
|
|
1588
1560
|
* error is thrown.
|
|
1589
1561
|
*
|
|
1590
1562
|
* @param mutex - The mutex to lock.
|
|
1591
|
-
* @param
|
|
1563
|
+
* @param callback - The function to execute while the mutex is locked.
|
|
1592
1564
|
* @returns The result of the function.
|
|
1593
1565
|
*/
|
|
1594
|
-
|
|
1595
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1596
|
-
async function withLock(mutex, fn) {
|
|
1566
|
+
async function withLock(mutex, callback) {
|
|
1597
1567
|
const releaseLock = await mutex.acquire();
|
|
1598
1568
|
try {
|
|
1599
|
-
return await
|
|
1569
|
+
return await callback({ releaseLock });
|
|
1600
1570
|
}
|
|
1601
1571
|
finally {
|
|
1602
1572
|
releaseLock();
|