@metamask-previews/keyring-controller 25.2.0-preview-54abb25 → 25.2.0-preview-19b4ad7e6

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringController-method-action-types.mjs","sourceRoot":"","sources":["../src/KeyringController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { KeyringController } from './KeyringController';\n\n/**\n * Adds a new account to the default (first) HD seed phrase keyring.\n *\n * @param accountCount - Number of accounts before adding a new one, used to\n * make the method idempotent.\n * @returns Promise resolving to the added account address.\n */\nexport type KeyringControllerAddNewAccountAction = {\n type: `KeyringController:addNewAccount`;\n handler: KeyringController['addNewAccount'];\n};\n\n/**\n * Effectively the same as creating a new keychain then populating it\n * using the given seed phrase.\n *\n * @param password - Password to unlock keychain.\n * @param seed - A BIP39-compliant seed phrase as Uint8Array,\n * either as a string or an array of UTF-8 bytes that represent the string.\n * @returns Promise resolving when the operation ends successfully.\n */\nexport type KeyringControllerCreateNewVaultAndRestoreAction = {\n type: `KeyringController:createNewVaultAndRestore`;\n handler: KeyringController['createNewVaultAndRestore'];\n};\n\n/**\n * Create a new vault and primary keyring.\n *\n * This only works if keyrings are empty. If there is a pre-existing unlocked vault, calling this will have no effect.\n * If there is a pre-existing locked vault, it will be replaced.\n *\n * @param password - Password to unlock the new vault.\n * @returns Promise resolving when the operation ends successfully.\n */\nexport type KeyringControllerCreateNewVaultAndKeychainAction = {\n type: `KeyringController:createNewVaultAndKeychain`;\n handler: KeyringController['createNewVaultAndKeychain'];\n};\n\n/**\n * Adds a new keyring of the given `type`.\n *\n * @param type - Keyring type name.\n * @param opts - Keyring options.\n * @throws If a builder for the given `type` does not exist.\n * @returns Promise resolving to the new keyring metadata.\n */\nexport type KeyringControllerAddNewKeyringAction = {\n type: `KeyringController:addNewKeyring`;\n handler: KeyringController['addNewKeyring'];\n};\n\n/**\n * Returns the public addresses of all accounts from every keyring.\n *\n * @returns A promise resolving to an array of addresses.\n */\nexport type KeyringControllerGetAccountsAction = {\n type: `KeyringController:getAccounts`;\n handler: KeyringController['getAccounts'];\n};\n\n/**\n * Get encryption public key.\n *\n * @param account - An account address.\n * @param opts - Additional encryption options.\n * @throws If the `account` does not exist or does not support the `getEncryptionPublicKey` method\n * @returns Promise resolving to encyption public key of the `account` if one exists.\n */\nexport type KeyringControllerGetEncryptionPublicKeyAction = {\n type: `KeyringController:getEncryptionPublicKey`;\n handler: KeyringController['getEncryptionPublicKey'];\n};\n\n/**\n * Attempts to decrypt the provided message parameters.\n *\n * @param messageParams - The decryption message parameters.\n * @param messageParams.from - The address of the account you want to use to decrypt the message.\n * @param messageParams.data - The encrypted data that you want to decrypt.\n * @returns The raw decryption result.\n */\nexport type KeyringControllerDecryptMessageAction = {\n type: `KeyringController:decryptMessage`;\n handler: KeyringController['decryptMessage'];\n};\n\n/**\n * Returns the currently initialized keyring that manages\n * the specified `address` if one exists.\n *\n * @deprecated Use of this method is discouraged as actions executed directly on\n * keyrings are not being reflected in the KeyringController state and not\n * persisted in the vault. Use `withKeyring` instead.\n * @param account - An account address.\n * @returns Promise resolving to keyring of the `account` if one exists.\n */\nexport type KeyringControllerGetKeyringForAccountAction = {\n type: `KeyringController:getKeyringForAccount`;\n handler: KeyringController['getKeyringForAccount'];\n};\n\n/**\n * Returns all keyrings of the given type.\n *\n * @deprecated Use of this method is discouraged as actions executed directly on\n * keyrings are not being reflected in the KeyringController state and not\n * persisted in the vault. Use `withKeyring` instead.\n * @param type - Keyring type name.\n * @returns An array of keyrings of the given type.\n */\nexport type KeyringControllerGetKeyringsByTypeAction = {\n type: `KeyringController:getKeyringsByType`;\n handler: KeyringController['getKeyringsByType'];\n};\n\n/**\n * Persist all serialized keyrings in the vault.\n *\n * @deprecated This method is being phased out in favor of `withKeyring`.\n * @returns Promise resolving with `true` value when the\n * operation completes.\n */\nexport type KeyringControllerPersistAllKeyringsAction = {\n type: `KeyringController:persistAllKeyrings`;\n handler: KeyringController['persistAllKeyrings'];\n};\n\n/**\n * Removes an account from keyring state.\n *\n * @param address - Address of the account to remove.\n * @fires KeyringController:accountRemoved\n * @returns Promise resolving when the account is removed.\n */\nexport type KeyringControllerRemoveAccountAction = {\n type: `KeyringController:removeAccount`;\n handler: KeyringController['removeAccount'];\n};\n\n/**\n * Signs message by calling down into a specific keyring.\n *\n * @param messageParams - PersonalMessageParams object to sign.\n * @returns Promise resolving to a signed message string.\n */\nexport type KeyringControllerSignMessageAction = {\n type: `KeyringController:signMessage`;\n handler: KeyringController['signMessage'];\n};\n\n/**\n * Signs EIP-7702 Authorization message by calling down into a specific keyring.\n *\n * @param params - EIP7702AuthorizationParams object to sign.\n * @returns Promise resolving to an EIP-7702 Authorization signature.\n * @throws Will throw UnsupportedSignEIP7702Authorization if the keyring does not support signing EIP-7702 Authorization messages.\n */\nexport type KeyringControllerSignEip7702AuthorizationAction = {\n type: `KeyringController:signEip7702Authorization`;\n handler: KeyringController['signEip7702Authorization'];\n};\n\n/**\n * Signs personal message by calling down into a specific keyring.\n *\n * @param messageParams - PersonalMessageParams object to sign.\n * @returns Promise resolving to a signed message string.\n */\nexport type KeyringControllerSignPersonalMessageAction = {\n type: `KeyringController:signPersonalMessage`;\n handler: KeyringController['signPersonalMessage'];\n};\n\n/**\n * Signs typed message by calling down into a specific keyring.\n *\n * @param messageParams - TypedMessageParams object to sign.\n * @param version - Compatibility version EIP712.\n * @throws Will throw when passed an unrecognized version.\n * @returns Promise resolving to a signed message string or an error if any.\n */\nexport type KeyringControllerSignTypedMessageAction = {\n type: `KeyringController:signTypedMessage`;\n handler: KeyringController['signTypedMessage'];\n};\n\n/**\n * Convert a base transaction to a base UserOperation.\n *\n * @param from - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @param executionContext - The execution context to use for the UserOperation.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\nexport type KeyringControllerPrepareUserOperationAction = {\n type: `KeyringController:prepareUserOperation`;\n handler: KeyringController['prepareUserOperation'];\n};\n\n/**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param from - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @param executionContext - The execution context to use for the UserOperation.\n * @returns A patch to apply to the UserOperation.\n */\nexport type KeyringControllerPatchUserOperationAction = {\n type: `KeyringController:patchUserOperation`;\n handler: KeyringController['patchUserOperation'];\n};\n\n/**\n * Signs an UserOperation.\n *\n * @param from - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @param executionContext - The execution context to use for the UserOperation.\n * @returns The signature of the UserOperation.\n */\nexport type KeyringControllerSignUserOperationAction = {\n type: `KeyringController:signUserOperation`;\n handler: KeyringController['signUserOperation'];\n};\n\n/**\n * Select a keyring and execute the given operation with\n * the selected keyring, as a mutually exclusive atomic\n * operation.\n *\n * The method automatically persists changes at the end of the\n * function execution, or rolls back the changes if an error\n * is thrown.\n *\n * @param selector - Keyring selector object.\n * @param operation - Function to execute with the selected keyring.\n * @param options - Additional options.\n * @param options.createIfMissing - Whether to create a new keyring if the selected one is missing.\n * @param options.createWithData - Optional data to use when creating a new keyring.\n * @returns Promise resolving to the result of the function execution.\n * @template SelectedKeyring - The type of the selected keyring.\n * @template CallbackResult - The type of the value resolved by the callback function.\n * @deprecated This method overload is deprecated. Use `withKeyring` without options instead.\n */\nexport type KeyringControllerWithKeyringAction = {\n type: `KeyringController:withKeyring`;\n handler: KeyringController['withKeyring'];\n};\n\n/**\n * Select a keyring and execute the given operation with the selected\n * keyring, **without** acquiring the controller's mutual exclusion lock.\n *\n * ## When to use this method\n *\n * This method is an escape hatch for read-only access to keyring data that\n * is immutable once the keyring is initialized. A typical safe use case is\n * reading the `mnemonic` from an `HdKeyring`: the mnemonic is set during\n * `deserialize()` and never mutated afterwards, so it can safely be read\n * without holding the lock.\n *\n * ## Why it is \"unsafe\"\n *\n * The \"unsafe\" designation mirrors the semantics of `unsafe { }` blocks in\n * Rust: the method itself does not enforce thread-safety guarantees. By\n * calling this method the **caller** explicitly takes responsibility for\n * ensuring that:\n *\n * - The operation is **read-only** — no state is mutated.\n * - The data being read is **immutable** after the keyring is initialized,\n * so concurrent locked operations cannot alter it while this callback\n * runs.\n *\n * Do **not** use this method to:\n * - Mutate keyring state (add accounts, sign, etc.) — use `withKeyring`.\n * - Read mutable fields that could change during concurrent operations.\n *\n * @param selector - Keyring selector object.\n * @param operation - Read-only function to execute with the selected keyring.\n * @returns Promise resolving to the result of the function execution.\n * @template SelectedKeyring - The type of the selected keyring.\n * @template CallbackResult - The type of the value resolved by the callback function.\n */\nexport type KeyringControllerWithKeyringUnsafeAction = {\n type: `KeyringController:withKeyringUnsafe`;\n handler: KeyringController['withKeyringUnsafe'];\n};\n\nexport type KeyringControllerAccountSupports7702Action = {\n type: `KeyringController:accountSupports7702`;\n handler: KeyringController['accountSupports7702'];\n};\n\n/**\n * Union of all KeyringController action types.\n */\nexport type KeyringControllerMethodActions =\n | KeyringControllerAddNewAccountAction\n | KeyringControllerCreateNewVaultAndRestoreAction\n | KeyringControllerCreateNewVaultAndKeychainAction\n | KeyringControllerAddNewKeyringAction\n | KeyringControllerGetAccountsAction\n | KeyringControllerGetEncryptionPublicKeyAction\n | KeyringControllerDecryptMessageAction\n | KeyringControllerGetKeyringForAccountAction\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerPersistAllKeyringsAction\n | KeyringControllerRemoveAccountAction\n | KeyringControllerSignMessageAction\n | KeyringControllerSignEip7702AuthorizationAction\n | KeyringControllerSignPersonalMessageAction\n | KeyringControllerSignTypedMessageAction\n | KeyringControllerPrepareUserOperationAction\n | KeyringControllerPatchUserOperationAction\n | KeyringControllerSignUserOperationAction\n | KeyringControllerWithKeyringAction\n | KeyringControllerWithKeyringUnsafeAction\n | KeyringControllerAccountSupports7702Action;\n"]}
@@ -33,14 +33,17 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
33
33
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
34
34
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
35
35
  };
36
- var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_keyringV2Builders, _KeyringController_encryptor, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_encryptionKey, _KeyringController_getKeyringForAccount, _KeyringController_getKeyringEntryForAccount, _KeyringController_findKeyringIndexForAccount, _KeyringController_getKeyringEntriesByType, _KeyringController_assertNoUnsafeDirectKeyringAccess, _KeyringController_registerMessageHandlers, _KeyringController_selectKeyringEntry, _KeyringController_selectKeyring, _KeyringController_getKeyringById, _KeyringController_getKeyringEntryById, _KeyringController_getKeyringByIdOrDefault, _KeyringController_getKeyringMetadata, _KeyringController_getKeyringBuilderForType, _KeyringController_getKeyringV2BuilderForType, _KeyringController_createNewVaultWithKeyring, _KeyringController_deriveAndSetEncryptionKey, _KeyringController_setEncryptionKey, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_getSessionState, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_isNewEncryptionAvailable, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_createKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_assertNoDuplicateAccounts, _KeyringController_setUnlocked, _KeyringController_assertIsUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ var _KeyringController_instances, _KeyringController_controllerOperationMutex, _KeyringController_vaultOperationMutex, _KeyringController_keyringBuilders, _KeyringController_encryptor, _KeyringController_keyrings, _KeyringController_unsupportedKeyrings, _KeyringController_encryptionKey, _KeyringController_getKeyringForAccount, _KeyringController_findKeyringIndexForAccount, _KeyringController_assertNoUnsafeDirectKeyringAccess, _KeyringController_registerMessageHandlers, _KeyringController_selectKeyring, _KeyringController_getKeyringById, _KeyringController_getKeyringByIdOrDefault, _KeyringController_getKeyringMetadata, _KeyringController_getKeyringBuilderForType, _KeyringController_createNewVaultWithKeyring, _KeyringController_deriveAndSetEncryptionKey, _KeyringController_setEncryptionKey, _KeyringController_verifySeedPhrase, _KeyringController_getUpdatedKeyrings, _KeyringController_getSerializedKeyrings, _KeyringController_getSessionState, _KeyringController_restoreSerializedKeyrings, _KeyringController_unlockKeyrings, _KeyringController_updateVault, _KeyringController_isNewEncryptionAvailable, _KeyringController_getAccountsFromKeyrings, _KeyringController_createKeyringWithFirstAccount, _KeyringController_newKeyring, _KeyringController_createKeyring, _KeyringController_clearKeyrings, _KeyringController_restoreKeyring, _KeyringController_destroyKeyring, _KeyringController_assertNoDuplicateAccounts, _KeyringController_setUnlocked, _KeyringController_assertIsUnlocked, _KeyringController_persistOrRollback, _KeyringController_withRollback, _KeyringController_assertControllerMutexIsLocked, _KeyringController_withControllerLock, _KeyringController_withVaultLock;
37
40
  Object.defineProperty(exports, "__esModule", { value: true });
38
41
  exports.KeyringController = exports.getDefaultKeyringState = exports.keyringBuilderFactory = exports.SignTypedDataVersion = exports.AccountImportStrategy = exports.isCustodyKeyring = exports.KeyringTypes = void 0;
39
42
  const util_1 = require("@ethereumjs/util");
40
43
  const base_controller_1 = require("@metamask/base-controller");
41
44
  const eth_hd_keyring_1 = require("@metamask/eth-hd-keyring");
42
45
  const eth_sig_util_1 = require("@metamask/eth-sig-util");
43
- const eth_simple_keyring_1 = __importStar(require("@metamask/eth-simple-keyring"));
46
+ const eth_simple_keyring_1 = __importDefault(require("@metamask/eth-simple-keyring"));
44
47
  const utils_1 = require("@metamask/utils");
45
48
  const async_mutex_1 = require("async-mutex");
46
49
  const ethereumjs_wallet_1 = __importStar(require("ethereumjs-wallet"));
@@ -50,6 +53,29 @@ const ulid_1 = require("ulid");
50
53
  const constants_1 = require("./constants.cjs");
51
54
  const errors_1 = require("./errors.cjs");
52
55
  const name = 'KeyringController';
56
+ const MESSENGER_EXPOSED_METHODS = [
57
+ 'signMessage',
58
+ 'signEip7702Authorization',
59
+ 'signPersonalMessage',
60
+ 'signTypedMessage',
61
+ 'decryptMessage',
62
+ 'getEncryptionPublicKey',
63
+ 'getAccounts',
64
+ 'getKeyringsByType',
65
+ 'getKeyringForAccount',
66
+ 'persistAllKeyrings',
67
+ 'prepareUserOperation',
68
+ 'patchUserOperation',
69
+ 'signUserOperation',
70
+ 'addNewAccount',
71
+ 'withKeyring',
72
+ 'withKeyringUnsafe',
73
+ 'addNewKeyring',
74
+ 'createNewVaultAndKeychain',
75
+ 'createNewVaultAndRestore',
76
+ 'removeAccount',
77
+ 'accountSupports7702',
78
+ ];
53
79
  /**
54
80
  * Available keyring types
55
81
  */
@@ -123,17 +149,6 @@ const defaultKeyringBuilders = [
123
149
  keyringBuilderFactory(eth_simple_keyring_1.default),
124
150
  keyringBuilderFactory(eth_hd_keyring_1.HdKeyring),
125
151
  ];
126
- const hdKeyringV2Builder = Object.assign((keyring, metadata) => new eth_hd_keyring_1.HdKeyringV2({
127
- legacyKeyring: keyring,
128
- entropySource: metadata.id,
129
- }), { type: KeyringTypes.hd });
130
- const simpleKeyringV2Builder = Object.assign((keyring) => new eth_simple_keyring_1.SimpleKeyringV2({
131
- legacyKeyring: keyring,
132
- }), { type: KeyringTypes.simple });
133
- const defaultKeyringV2Builders = [
134
- simpleKeyringV2Builder,
135
- hdKeyringV2Builder,
136
- ];
137
152
  const getDefaultKeyringState = () => {
138
153
  return {
139
154
  isUnlocked: false,
@@ -259,7 +274,7 @@ class KeyringController extends base_controller_1.BaseController {
259
274
  * @param options.state - Initial state to set on this controller.
260
275
  */
261
276
  constructor(options) {
262
- const { encryptor, keyringBuilders, keyringV2Builders, messenger, state } = options;
277
+ const { encryptor, keyringBuilders, messenger, state } = options;
263
278
  super({
264
279
  name,
265
280
  metadata: {
@@ -304,7 +319,6 @@ class KeyringController extends base_controller_1.BaseController {
304
319
  _KeyringController_controllerOperationMutex.set(this, new async_mutex_1.Mutex());
305
320
  _KeyringController_vaultOperationMutex.set(this, new async_mutex_1.Mutex());
306
321
  _KeyringController_keyringBuilders.set(this, void 0);
307
- _KeyringController_keyringV2Builders.set(this, void 0);
308
322
  _KeyringController_encryptor.set(this, void 0);
309
323
  _KeyringController_keyrings.set(this, void 0);
310
324
  _KeyringController_unsupportedKeyrings.set(this, void 0);
@@ -312,9 +326,6 @@ class KeyringController extends base_controller_1.BaseController {
312
326
  __classPrivateFieldSet(this, _KeyringController_keyringBuilders, keyringBuilders
313
327
  ? keyringBuilders.concat(defaultKeyringBuilders)
314
328
  : defaultKeyringBuilders, "f");
315
- __classPrivateFieldSet(this, _KeyringController_keyringV2Builders, keyringV2Builders
316
- ? keyringV2Builders.concat(defaultKeyringV2Builders)
317
- : defaultKeyringV2Builders, "f");
318
329
  __classPrivateFieldSet(this, _KeyringController_encryptor, encryptor, "f");
319
330
  __classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
320
331
  __classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
@@ -559,7 +570,9 @@ class KeyringController extends base_controller_1.BaseController {
559
570
  */
560
571
  getKeyringsByType(type) {
561
572
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
562
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntriesByType).call(this, type).map(({ keyring }) => keyring);
573
+ return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")
574
+ .filter(({ keyring }) => keyring.type === type)
575
+ .map(({ keyring }) => keyring);
563
576
  }
564
577
  /**
565
578
  * Persist all serialized keyrings in the vault.
@@ -648,7 +661,7 @@ class KeyringController extends base_controller_1.BaseController {
648
661
  if (keyringIndex === -1) {
649
662
  throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.NoKeyring);
650
663
  }
651
- const { keyring, keyringV2 } = __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex];
664
+ const { keyring } = __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex];
652
665
  const isPrimaryKeyring = keyringIndex === 0;
653
666
  const shouldRemoveKeyring = (await keyring.getAccounts()).length === 1;
654
667
  // Primary keyring should never be removed, so we need to keep at least one account in it
@@ -669,7 +682,7 @@ class KeyringController extends base_controller_1.BaseController {
669
682
  await keyring.removeAccount(address);
670
683
  if (shouldRemoveKeyring) {
671
684
  __classPrivateFieldGet(this, _KeyringController_keyrings, "f").splice(keyringIndex, 1);
672
- await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring, keyringV2);
685
+ await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
673
686
  }
674
687
  });
675
688
  this.messenger.publish(`${name}:accountRemoved`, address);
@@ -1027,125 +1040,23 @@ class KeyringController extends base_controller_1.BaseController {
1027
1040
  metadata: __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringMetadata).call(this, keyring),
1028
1041
  }), keyring);
1029
1042
  }
1030
- /**
1031
- * Select a keyring, wrap it in a `KeyringV2` adapter, and execute
1032
- * the given operation with the wrapped keyring as a mutually
1033
- * exclusive atomic operation.
1034
- *
1035
- * We re-wrap the keyring in a `KeyringV2` adapter on each invocation,
1036
- * since V2 wrappers are ephemeral adapters created on-the-fly, and cheap to create.
1037
- *
1038
- * The method automatically persists changes at the end of the
1039
- * function execution, or rolls back the changes if an error
1040
- * is thrown.
1041
- *
1042
- * A `KeyringV2Builder` for the selected keyring's type must exist
1043
- * (either as a default or registered via the `keyringV2Builders`
1044
- * constructor option); otherwise an error is thrown.
1045
- *
1046
- * Selection is performed against the V1 keyrings in `#keyrings`, since
1047
- * V2 wrappers are ephemeral adapters created on-the-fly.
1048
- *
1049
- * @param selector - Keyring selector object.
1050
- * @param operation - Function to execute with the wrapped V2 keyring.
1051
- * @returns Promise resolving to the result of the function execution.
1052
- * @template CallbackResult - The type of the value resolved by the callback function.
1053
- */
1054
- async withKeyringV2(selector, operation) {
1055
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1056
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
1057
- const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, {
1058
- v2: true,
1059
- selector,
1060
- });
1061
- if (!entry) {
1062
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringNotFound);
1063
- }
1064
- if (!entry.keyringV2) {
1065
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringV2NotSupported);
1066
- }
1067
- const { metadata } = entry;
1068
- const keyring = entry.keyringV2;
1069
- const result = await operation({
1070
- keyring,
1071
- metadata,
1072
- });
1073
- if (Object.is(result, keyring)) {
1074
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.UnsafeDirectKeyringAccess);
1075
- }
1076
- return result;
1077
- });
1078
- }
1079
- /**
1080
- * Select a keyring, wrap it in a `KeyringV2` adapter, and execute
1081
- * the given read-only operation **without** acquiring the controller's
1082
- * mutual exclusion lock.
1083
- *
1084
- * ## When to use this method
1085
- *
1086
- * This method is an escape hatch for read-only access to keyring data that
1087
- * is immutable once the keyring is initialized. A typical safe use case is
1088
- * reading immutable fields from a `KeyringV2` adapter: data that is set
1089
- * during initialization and never mutated afterwards.
1090
- *
1091
- * ## Why it is "unsafe"
1092
- *
1093
- * The "unsafe" designation mirrors the semantics of `unsafe { }` blocks in
1094
- * Rust: the method itself does not enforce thread-safety guarantees. By
1095
- * calling this method the **caller** explicitly takes responsibility for
1096
- * ensuring that:
1097
- *
1098
- * - The operation is **read-only** — no state is mutated.
1099
- * - The data being read is **immutable** after the keyring is initialized,
1100
- * so concurrent locked operations cannot alter it while this callback
1101
- * runs.
1102
- *
1103
- * Do **not** use this method to:
1104
- * - Mutate keyring state (add accounts, sign, etc.) — use `withKeyringV2`.
1105
- * - Read mutable fields that could change during concurrent operations.
1106
- *
1107
- * @param selector - Keyring selector object.
1108
- * @param operation - Read-only function to execute with the wrapped V2 keyring.
1109
- * @returns Promise resolving to the result of the function execution.
1110
- * @template SelectedKeyring - The type of the selected V2 keyring.
1111
- * @template CallbackResult - The type of the value resolved by the callback function.
1112
- */
1113
- async withKeyringV2Unsafe(selector, operation) {
1114
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1115
- const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, {
1116
- v2: true,
1117
- selector,
1118
- });
1119
- if (!entry) {
1120
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringNotFound);
1121
- }
1122
- if (!entry.keyringV2) {
1123
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringV2NotSupported);
1124
- }
1125
- const { metadata } = entry;
1126
- const keyring = entry.keyringV2;
1127
- const result = await operation({ keyring, metadata });
1128
- if (Object.is(result, keyring)) {
1129
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.UnsafeDirectKeyringAccess);
1130
- }
1131
- return result;
1132
- }
1133
1043
  async getAccountKeyringType(account) {
1134
1044
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1135
1045
  const keyring = (await this.getKeyringForAccount(account));
1136
1046
  return keyring.type;
1137
1047
  }
1048
+ async accountSupports7702(account) {
1049
+ const keyringType = await this.getAccountKeyringType(account);
1050
+ return (keyringType === KeyringTypes.hd ||
1051
+ keyringType === KeyringTypes.simple);
1052
+ }
1138
1053
  }
1139
1054
  exports.KeyringController = KeyringController;
1140
- _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_keyringV2Builders = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_encryptionKey = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_getKeyringForAccount = async function _KeyringController_getKeyringForAccount(account) {
1141
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1142
- const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryForAccount).call(this, account);
1143
- return entry?.keyring;
1144
- }, _KeyringController_getKeyringEntryForAccount = async function _KeyringController_getKeyringEntryForAccount(account) {
1055
+ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_vaultOperationMutex = new WeakMap(), _KeyringController_keyringBuilders = new WeakMap(), _KeyringController_encryptor = new WeakMap(), _KeyringController_keyrings = new WeakMap(), _KeyringController_unsupportedKeyrings = new WeakMap(), _KeyringController_encryptionKey = new WeakMap(), _KeyringController_instances = new WeakSet(), _KeyringController_getKeyringForAccount = async function _KeyringController_getKeyringForAccount(account) {
1145
1056
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1146
1057
  const keyringIndex = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_findKeyringIndexForAccount).call(this, account);
1147
1058
  if (keyringIndex > -1) {
1148
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex];
1059
+ return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex].keyring;
1149
1060
  }
1150
1061
  return undefined;
1151
1062
  }, _KeyringController_findKeyringIndexForAccount = async function _KeyringController_findKeyringIndexForAccount(account) {
@@ -1153,9 +1064,6 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
1153
1064
  const address = account.toLowerCase();
1154
1065
  const accountsPerKeyring = await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(({ keyring }) => keyring.getAccounts()));
1155
1066
  return accountsPerKeyring.findIndex((accounts) => accounts.map((a) => a.toLowerCase()).includes(address));
1156
- }, _KeyringController_getKeyringEntriesByType = function _KeyringController_getKeyringEntriesByType(type) {
1157
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1158
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").filter(({ keyring }) => keyring.type === type);
1159
1067
  }, _KeyringController_assertNoUnsafeDirectKeyringAccess = function _KeyringController_assertNoUnsafeDirectKeyringAccess(value, keyring) {
1160
1068
  if (Object.is(value, keyring)) {
1161
1069
  // Access to a keyring instance outside of controller safeguards
@@ -1166,82 +1074,33 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
1166
1074
  }
1167
1075
  return value;
1168
1076
  }, _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
1169
- this.messenger.registerActionHandler(`${name}:signMessage`, this.signMessage.bind(this));
1170
- this.messenger.registerActionHandler(`${name}:signEip7702Authorization`, this.signEip7702Authorization.bind(this));
1171
- this.messenger.registerActionHandler(`${name}:signPersonalMessage`, this.signPersonalMessage.bind(this));
1172
- this.messenger.registerActionHandler(`${name}:signTypedMessage`, this.signTypedMessage.bind(this));
1173
- this.messenger.registerActionHandler(`${name}:decryptMessage`, this.decryptMessage.bind(this));
1174
- this.messenger.registerActionHandler(`${name}:getEncryptionPublicKey`, this.getEncryptionPublicKey.bind(this));
1175
- this.messenger.registerActionHandler(`${name}:getAccounts`, this.getAccounts.bind(this));
1176
- this.messenger.registerActionHandler(`${name}:getKeyringsByType`, this.getKeyringsByType.bind(this));
1177
- this.messenger.registerActionHandler(`${name}:getKeyringForAccount`, this.getKeyringForAccount.bind(this));
1178
- this.messenger.registerActionHandler(`${name}:persistAllKeyrings`, this.persistAllKeyrings.bind(this));
1179
- this.messenger.registerActionHandler(`${name}:prepareUserOperation`, this.prepareUserOperation.bind(this));
1180
- this.messenger.registerActionHandler(`${name}:patchUserOperation`, this.patchUserOperation.bind(this));
1181
- this.messenger.registerActionHandler(`${name}:signUserOperation`, this.signUserOperation.bind(this));
1182
- this.messenger.registerActionHandler(`${name}:addNewAccount`, this.addNewAccount.bind(this));
1183
- this.messenger.registerActionHandler(`${name}:withKeyring`, this.withKeyring.bind(this));
1184
- this.messenger.registerActionHandler(`${name}:withKeyringUnsafe`, this.withKeyringUnsafe.bind(this));
1185
- this.messenger.registerActionHandler(`${name}:withKeyringV2`, this.withKeyringV2.bind(this));
1186
- this.messenger.registerActionHandler(`${name}:withKeyringV2Unsafe`, this.withKeyringV2Unsafe.bind(this));
1187
- this.messenger.registerActionHandler(`${name}:addNewKeyring`, this.addNewKeyring.bind(this));
1188
- this.messenger.registerActionHandler(`${name}:createNewVaultAndKeychain`, this.createNewVaultAndKeychain.bind(this));
1189
- this.messenger.registerActionHandler(`${name}:createNewVaultAndRestore`, this.createNewVaultAndRestore.bind(this));
1190
- this.messenger.registerActionHandler(`${name}:removeAccount`, this.removeAccount.bind(this));
1191
- }, _KeyringController_selectKeyringEntry =
1077
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
1078
+ }, _KeyringController_selectKeyring =
1192
1079
  /**
1193
- * Select a keyring entry using a selector without acquiring the controller lock.
1080
+ * Select a keyring using a selector without acquiring the controller lock.
1194
1081
  *
1195
- * @param options - Selection options.
1196
- * @param options.v2 - Tag to indicate whether the selector is for a V2 keyring.
1197
- * @param options.selector - Keyring selector object.
1198
- * @returns The selected keyring entry, or `undefined` if no match is found.
1082
+ * @param selector - Keyring selector object.
1083
+ * @returns The selected keyring, or `undefined` if no match is found.
1199
1084
  * @template SelectedKeyring - The expected type of the selected keyring.
1200
- * @template SelectedKeyringV2 - The expected type of the selected keyring (v2).
1201
1085
  */
1202
- async function _KeyringController_selectKeyringEntry({ v2, selector, }) {
1203
- let entry;
1086
+ async function _KeyringController_selectKeyring(selector) {
1087
+ let keyring;
1204
1088
  if ('address' in selector) {
1205
- entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryForAccount).call(this, selector.address);
1089
+ keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringForAccount).call(this, selector.address));
1206
1090
  }
1207
1091
  else if ('type' in selector) {
1208
- entry = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntriesByType).call(this, selector.type)[selector.index ?? 0];
1092
+ keyring = this.getKeyringsByType(selector.type)[selector.index ?? 0];
1209
1093
  }
1210
1094
  else if ('id' in selector) {
1211
- entry = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryById).call(this, selector.id);
1095
+ keyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, selector.id);
1212
1096
  }
1213
1097
  else if ('filter' in selector) {
1214
- entry = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ keyring, keyringV2, metadata }) => {
1215
- // If v2, then we'll use the v2 selector which expects a `KeyringV2` instance.
1216
- if (v2) {
1217
- // However, some keyrings do not have a v2 wrapper, so we just skip them.
1218
- if (!keyringV2) {
1219
- return false;
1220
- }
1221
- return selector.filter(keyringV2, metadata);
1222
- }
1223
- return selector.filter(keyring, metadata);
1224
- });
1098
+ keyring = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ keyring: filteredKeyring, metadata }) => selector.filter(filteredKeyring, metadata))?.keyring;
1225
1099
  }
1226
- return entry;
1227
- }, _KeyringController_selectKeyring =
1228
- /**
1229
- * Select a keyring using a selector without acquiring the controller lock.
1230
- *
1231
- * @param selector - Keyring selector object.
1232
- * @returns The selected keyring, or `undefined` if no match is found.
1233
- * @template SelectedKeyring - The expected type of the selected keyring.
1234
- */
1235
- async function _KeyringController_selectKeyring(selector) {
1236
- const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, {
1237
- v2: false,
1238
- selector,
1239
- });
1240
- return entry?.keyring;
1100
+ return keyring;
1241
1101
  }, _KeyringController_getKeyringById = function _KeyringController_getKeyringById(keyringId) {
1242
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryById).call(this, keyringId)?.keyring;
1243
- }, _KeyringController_getKeyringEntryById = function _KeyringController_getKeyringEntryById(keyringId) {
1244
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ metadata }) => metadata.id === keyringId);
1102
+ return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ metadata }) => metadata.id === keyringId)
1103
+ ?.keyring;
1245
1104
  }, _KeyringController_getKeyringByIdOrDefault = function _KeyringController_getKeyringByIdOrDefault(keyringId) {
1246
1105
  if (!keyringId) {
1247
1106
  return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0]?.keyring;
@@ -1255,8 +1114,6 @@ async function _KeyringController_selectKeyring(selector) {
1255
1114
  return keyringWithMetadata.metadata;
1256
1115
  }, _KeyringController_getKeyringBuilderForType = function _KeyringController_getKeyringBuilderForType(type) {
1257
1116
  return __classPrivateFieldGet(this, _KeyringController_keyringBuilders, "f").find((keyringBuilder) => keyringBuilder.type === type);
1258
- }, _KeyringController_getKeyringV2BuilderForType = function _KeyringController_getKeyringV2BuilderForType(type) {
1259
- return __classPrivateFieldGet(this, _KeyringController_keyringV2Builders, "f").find((builder) => builder.type === type);
1260
1117
  }, _KeyringController_createNewVaultWithKeyring =
1261
1118
  /**
1262
1119
  * Create new vault with an initial keyring
@@ -1580,8 +1437,8 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
1580
1437
  * @throws If the keyring includes duplicated accounts.
1581
1438
  */
1582
1439
  async function _KeyringController_newKeyring(type, data) {
1583
- const { keyring, keyringV2, metadata } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1584
- __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({ keyring, keyringV2, metadata });
1440
+ const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1441
+ __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({ keyring, metadata: getDefaultKeyringMetadata() });
1585
1442
  return keyring;
1586
1443
  }, _KeyringController_createKeyring =
1587
1444
  /**
@@ -1598,13 +1455,11 @@ async function _KeyringController_newKeyring(type, data) {
1598
1455
  *
1599
1456
  * @param type - The type of keyring to add.
1600
1457
  * @param data - Keyring initialization options.
1601
- * @param metadata - Keyring metadata if available.
1602
1458
  * @returns The new keyring.
1603
1459
  * @throws If the keyring includes duplicated accounts.
1604
1460
  */
1605
- async function _KeyringController_createKeyring(type, data, metadata) {
1461
+ async function _KeyringController_createKeyring(type, data) {
1606
1462
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1607
- const keyringMetadata = metadata ?? getDefaultKeyringMetadata();
1608
1463
  const keyringBuilder = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringBuilderForType).call(this, type);
1609
1464
  if (!keyringBuilder) {
1610
1465
  throw new errors_1.KeyringControllerError(`${constants_1.KeyringControllerErrorMessage.NoKeyringBuilder}. Keyring type: ${type}`);
@@ -1628,13 +1483,7 @@ async function _KeyringController_createKeyring(type, data, metadata) {
1628
1483
  await keyring.generateRandomMnemonic();
1629
1484
  await keyring.addAccounts(1);
1630
1485
  }
1631
- // We now create the keyring V2 wrappers and store them in memory.
1632
- const keyringBuilderV2 = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringV2BuilderForType).call(this, type);
1633
- let keyringV2;
1634
- if (keyringBuilderV2) {
1635
- keyringV2 = keyringBuilderV2(keyring, keyringMetadata);
1636
- }
1637
- return { keyring, keyringV2, metadata: keyringMetadata };
1486
+ return keyring;
1638
1487
  }, _KeyringController_clearKeyrings =
1639
1488
  /**
1640
1489
  * Remove all managed keyrings, destroying all their
@@ -1642,8 +1491,8 @@ async function _KeyringController_createKeyring(type, data, metadata) {
1642
1491
  */
1643
1492
  async function _KeyringController_clearKeyrings() {
1644
1493
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1645
- for (const { keyring, keyringV2 } of __classPrivateFieldGet(this, _KeyringController_keyrings, "f")) {
1646
- await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring, keyringV2);
1494
+ for (const { keyring } of __classPrivateFieldGet(this, _KeyringController_keyrings, "f")) {
1495
+ await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
1647
1496
  }
1648
1497
  __classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
1649
1498
  __classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
@@ -1661,22 +1510,21 @@ async function _KeyringController_restoreKeyring(serialized) {
1661
1510
  const { type, data, metadata: serializedMetadata } = serialized;
1662
1511
  let newMetadata = false;
1663
1512
  let metadata = serializedMetadata;
1513
+ const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1514
+ await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoDuplicateAccounts).call(this, [keyring]);
1664
1515
  // If metadata is missing, assume the data is from an installation before
1665
1516
  // we had keyring metadata.
1666
1517
  if (!metadata) {
1667
1518
  newMetadata = true;
1668
1519
  metadata = getDefaultKeyringMetadata();
1669
1520
  }
1670
- const { keyring, keyringV2 } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data, metadata);
1671
- await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoDuplicateAccounts).call(this, [keyring]);
1672
1521
  // The keyring is added to the keyrings array only if it's successfully restored
1673
1522
  // and the metadata is successfully added to the controller
1674
1523
  __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({
1675
1524
  keyring,
1676
- keyringV2,
1677
1525
  metadata,
1678
1526
  });
1679
- return { keyring, keyringV2, metadata, newMetadata };
1527
+ return { keyring, metadata, newMetadata };
1680
1528
  }
1681
1529
  catch (error) {
1682
1530
  console.error(error);
@@ -1692,13 +1540,9 @@ async function _KeyringController_restoreKeyring(serialized) {
1692
1540
  * clears the keyring bridge iframe from the DOM.
1693
1541
  *
1694
1542
  * @param keyring - The keyring to destroy.
1695
- * @param keyringV2 - The keyring v2 to destroy (if any).
1696
1543
  */
1697
- async function _KeyringController_destroyKeyring(keyring, keyringV2) {
1544
+ async function _KeyringController_destroyKeyring(keyring) {
1698
1545
  await keyring.destroy?.();
1699
- if (keyringV2) {
1700
- await keyringV2.destroy?.();
1701
- }
1702
1546
  }, _KeyringController_assertNoDuplicateAccounts =
1703
1547
  /**
1704
1548
  * Assert that there are no duplicate accounts in the keyrings.