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

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.
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  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");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- 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;
12
+ 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;
13
13
  function $importDefault(module) {
14
14
  if (module?.__esModule) {
15
15
  return module.default;
@@ -18,9 +18,9 @@ function $importDefault(module) {
18
18
  }
19
19
  import { isValidPrivate, getBinarySize } from "@ethereumjs/util";
20
20
  import { BaseController } from "@metamask/base-controller";
21
- import { HdKeyring, HdKeyringV2 } from "@metamask/eth-hd-keyring";
21
+ import { HdKeyring } from "@metamask/eth-hd-keyring";
22
22
  import { normalize as ethNormalize } from "@metamask/eth-sig-util";
23
- import SimpleKeyring, { SimpleKeyringV2 } from "@metamask/eth-simple-keyring";
23
+ import SimpleKeyring from "@metamask/eth-simple-keyring";
24
24
  import { add0x, assertIsStrictHexString, bytesToHex, hasProperty, hexToBytes, isObject, isStrictHexString, isValidHexAddress, isValidJson, remove0x } from "@metamask/utils";
25
25
  import { Mutex } from "async-mutex";
26
26
  import $Wallet from "ethereumjs-wallet";
@@ -33,6 +33,28 @@ import { ulid } from "ulid";
33
33
  import { KeyringControllerErrorMessage } from "./constants.mjs";
34
34
  import { KeyringControllerError } from "./errors.mjs";
35
35
  const name = 'KeyringController';
36
+ const MESSENGER_EXPOSED_METHODS = [
37
+ 'signMessage',
38
+ 'signEip7702Authorization',
39
+ 'signPersonalMessage',
40
+ 'signTypedMessage',
41
+ 'decryptMessage',
42
+ 'getEncryptionPublicKey',
43
+ 'getAccounts',
44
+ 'getKeyringsByType',
45
+ 'getKeyringForAccount',
46
+ 'persistAllKeyrings',
47
+ 'prepareUserOperation',
48
+ 'patchUserOperation',
49
+ 'signUserOperation',
50
+ 'addNewAccount',
51
+ 'withKeyring',
52
+ 'withKeyringUnsafe',
53
+ 'addNewKeyring',
54
+ 'createNewVaultAndKeychain',
55
+ 'createNewVaultAndRestore',
56
+ 'removeAccount',
57
+ ];
36
58
  /**
37
59
  * Available keyring types
38
60
  */
@@ -104,17 +126,6 @@ const defaultKeyringBuilders = [
104
126
  keyringBuilderFactory(SimpleKeyring),
105
127
  keyringBuilderFactory(HdKeyring),
106
128
  ];
107
- const hdKeyringV2Builder = Object.assign((keyring, metadata) => new HdKeyringV2({
108
- legacyKeyring: keyring,
109
- entropySource: metadata.id,
110
- }), { type: KeyringTypes.hd });
111
- const simpleKeyringV2Builder = Object.assign((keyring) => new SimpleKeyringV2({
112
- legacyKeyring: keyring,
113
- }), { type: KeyringTypes.simple });
114
- const defaultKeyringV2Builders = [
115
- simpleKeyringV2Builder,
116
- hdKeyringV2Builder,
117
- ];
118
129
  export const getDefaultKeyringState = () => {
119
130
  return {
120
131
  isUnlocked: false,
@@ -239,7 +250,7 @@ export class KeyringController extends BaseController {
239
250
  * @param options.state - Initial state to set on this controller.
240
251
  */
241
252
  constructor(options) {
242
- const { encryptor, keyringBuilders, keyringV2Builders, messenger, state } = options;
253
+ const { encryptor, keyringBuilders, messenger, state } = options;
243
254
  super({
244
255
  name,
245
256
  metadata: {
@@ -284,7 +295,6 @@ export class KeyringController extends BaseController {
284
295
  _KeyringController_controllerOperationMutex.set(this, new Mutex());
285
296
  _KeyringController_vaultOperationMutex.set(this, new Mutex());
286
297
  _KeyringController_keyringBuilders.set(this, void 0);
287
- _KeyringController_keyringV2Builders.set(this, void 0);
288
298
  _KeyringController_encryptor.set(this, void 0);
289
299
  _KeyringController_keyrings.set(this, void 0);
290
300
  _KeyringController_unsupportedKeyrings.set(this, void 0);
@@ -292,9 +302,6 @@ export class KeyringController extends BaseController {
292
302
  __classPrivateFieldSet(this, _KeyringController_keyringBuilders, keyringBuilders
293
303
  ? keyringBuilders.concat(defaultKeyringBuilders)
294
304
  : defaultKeyringBuilders, "f");
295
- __classPrivateFieldSet(this, _KeyringController_keyringV2Builders, keyringV2Builders
296
- ? keyringV2Builders.concat(defaultKeyringV2Builders)
297
- : defaultKeyringV2Builders, "f");
298
305
  __classPrivateFieldSet(this, _KeyringController_encryptor, encryptor, "f");
299
306
  __classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
300
307
  __classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
@@ -539,7 +546,9 @@ export class KeyringController extends BaseController {
539
546
  */
540
547
  getKeyringsByType(type) {
541
548
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
542
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntriesByType).call(this, type).map(({ keyring }) => keyring);
549
+ return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")
550
+ .filter(({ keyring }) => keyring.type === type)
551
+ .map(({ keyring }) => keyring);
543
552
  }
544
553
  /**
545
554
  * Persist all serialized keyrings in the vault.
@@ -628,7 +637,7 @@ export class KeyringController extends BaseController {
628
637
  if (keyringIndex === -1) {
629
638
  throw new KeyringControllerError(KeyringControllerErrorMessage.NoKeyring);
630
639
  }
631
- const { keyring, keyringV2 } = __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex];
640
+ const { keyring } = __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex];
632
641
  const isPrimaryKeyring = keyringIndex === 0;
633
642
  const shouldRemoveKeyring = (await keyring.getAccounts()).length === 1;
634
643
  // Primary keyring should never be removed, so we need to keep at least one account in it
@@ -649,7 +658,7 @@ export class KeyringController extends BaseController {
649
658
  await keyring.removeAccount(address);
650
659
  if (shouldRemoveKeyring) {
651
660
  __classPrivateFieldGet(this, _KeyringController_keyrings, "f").splice(keyringIndex, 1);
652
- await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring, keyringV2);
661
+ await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
653
662
  }
654
663
  });
655
664
  this.messenger.publish(`${name}:accountRemoved`, address);
@@ -1007,124 +1016,17 @@ export class KeyringController extends BaseController {
1007
1016
  metadata: __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringMetadata).call(this, keyring),
1008
1017
  }), keyring);
1009
1018
  }
1010
- /**
1011
- * Select a keyring, wrap it in a `KeyringV2` adapter, and execute
1012
- * the given operation with the wrapped keyring as a mutually
1013
- * exclusive atomic operation.
1014
- *
1015
- * We re-wrap the keyring in a `KeyringV2` adapter on each invocation,
1016
- * since V2 wrappers are ephemeral adapters created on-the-fly, and cheap to create.
1017
- *
1018
- * The method automatically persists changes at the end of the
1019
- * function execution, or rolls back the changes if an error
1020
- * is thrown.
1021
- *
1022
- * A `KeyringV2Builder` for the selected keyring's type must exist
1023
- * (either as a default or registered via the `keyringV2Builders`
1024
- * constructor option); otherwise an error is thrown.
1025
- *
1026
- * Selection is performed against the V1 keyrings in `#keyrings`, since
1027
- * V2 wrappers are ephemeral adapters created on-the-fly.
1028
- *
1029
- * @param selector - Keyring selector object.
1030
- * @param operation - Function to execute with the wrapped V2 keyring.
1031
- * @returns Promise resolving to the result of the function execution.
1032
- * @template CallbackResult - The type of the value resolved by the callback function.
1033
- */
1034
- async withKeyringV2(selector, operation) {
1035
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1036
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
1037
- const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, {
1038
- v2: true,
1039
- selector,
1040
- });
1041
- if (!entry) {
1042
- throw new KeyringControllerError(KeyringControllerErrorMessage.KeyringNotFound);
1043
- }
1044
- if (!entry.keyringV2) {
1045
- throw new KeyringControllerError(KeyringControllerErrorMessage.KeyringV2NotSupported);
1046
- }
1047
- const { metadata } = entry;
1048
- const keyring = entry.keyringV2;
1049
- const result = await operation({
1050
- keyring,
1051
- metadata,
1052
- });
1053
- if (Object.is(result, keyring)) {
1054
- throw new KeyringControllerError(KeyringControllerErrorMessage.UnsafeDirectKeyringAccess);
1055
- }
1056
- return result;
1057
- });
1058
- }
1059
- /**
1060
- * Select a keyring, wrap it in a `KeyringV2` adapter, and execute
1061
- * the given read-only operation **without** acquiring the controller's
1062
- * mutual exclusion lock.
1063
- *
1064
- * ## When to use this method
1065
- *
1066
- * This method is an escape hatch for read-only access to keyring data that
1067
- * is immutable once the keyring is initialized. A typical safe use case is
1068
- * reading immutable fields from a `KeyringV2` adapter: data that is set
1069
- * during initialization and never mutated afterwards.
1070
- *
1071
- * ## Why it is "unsafe"
1072
- *
1073
- * The "unsafe" designation mirrors the semantics of `unsafe { }` blocks in
1074
- * Rust: the method itself does not enforce thread-safety guarantees. By
1075
- * calling this method the **caller** explicitly takes responsibility for
1076
- * ensuring that:
1077
- *
1078
- * - The operation is **read-only** — no state is mutated.
1079
- * - The data being read is **immutable** after the keyring is initialized,
1080
- * so concurrent locked operations cannot alter it while this callback
1081
- * runs.
1082
- *
1083
- * Do **not** use this method to:
1084
- * - Mutate keyring state (add accounts, sign, etc.) — use `withKeyringV2`.
1085
- * - Read mutable fields that could change during concurrent operations.
1086
- *
1087
- * @param selector - Keyring selector object.
1088
- * @param operation - Read-only function to execute with the wrapped V2 keyring.
1089
- * @returns Promise resolving to the result of the function execution.
1090
- * @template SelectedKeyring - The type of the selected V2 keyring.
1091
- * @template CallbackResult - The type of the value resolved by the callback function.
1092
- */
1093
- async withKeyringV2Unsafe(selector, operation) {
1094
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1095
- const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, {
1096
- v2: true,
1097
- selector,
1098
- });
1099
- if (!entry) {
1100
- throw new KeyringControllerError(KeyringControllerErrorMessage.KeyringNotFound);
1101
- }
1102
- if (!entry.keyringV2) {
1103
- throw new KeyringControllerError(KeyringControllerErrorMessage.KeyringV2NotSupported);
1104
- }
1105
- const { metadata } = entry;
1106
- const keyring = entry.keyringV2;
1107
- const result = await operation({ keyring, metadata });
1108
- if (Object.is(result, keyring)) {
1109
- throw new KeyringControllerError(KeyringControllerErrorMessage.UnsafeDirectKeyringAccess);
1110
- }
1111
- return result;
1112
- }
1113
1019
  async getAccountKeyringType(account) {
1114
1020
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1115
1021
  const keyring = (await this.getKeyringForAccount(account));
1116
1022
  return keyring.type;
1117
1023
  }
1118
1024
  }
1119
- _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) {
1120
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1121
- const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryForAccount).call(this, account);
1122
- return entry?.keyring;
1123
- }, _KeyringController_getKeyringEntryForAccount = async function _KeyringController_getKeyringEntryForAccount(account) {
1025
+ _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) {
1124
1026
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1125
1027
  const keyringIndex = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_findKeyringIndexForAccount).call(this, account);
1126
1028
  if (keyringIndex > -1) {
1127
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex];
1029
+ return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex].keyring;
1128
1030
  }
1129
1031
  return undefined;
1130
1032
  }, _KeyringController_findKeyringIndexForAccount = async function _KeyringController_findKeyringIndexForAccount(account) {
@@ -1132,9 +1034,6 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
1132
1034
  const address = account.toLowerCase();
1133
1035
  const accountsPerKeyring = await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(({ keyring }) => keyring.getAccounts()));
1134
1036
  return accountsPerKeyring.findIndex((accounts) => accounts.map((a) => a.toLowerCase()).includes(address));
1135
- }, _KeyringController_getKeyringEntriesByType = function _KeyringController_getKeyringEntriesByType(type) {
1136
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1137
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").filter(({ keyring }) => keyring.type === type);
1138
1037
  }, _KeyringController_assertNoUnsafeDirectKeyringAccess = function _KeyringController_assertNoUnsafeDirectKeyringAccess(value, keyring) {
1139
1038
  if (Object.is(value, keyring)) {
1140
1039
  // Access to a keyring instance outside of controller safeguards
@@ -1145,82 +1044,33 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
1145
1044
  }
1146
1045
  return value;
1147
1046
  }, _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
1148
- this.messenger.registerActionHandler(`${name}:signMessage`, this.signMessage.bind(this));
1149
- this.messenger.registerActionHandler(`${name}:signEip7702Authorization`, this.signEip7702Authorization.bind(this));
1150
- this.messenger.registerActionHandler(`${name}:signPersonalMessage`, this.signPersonalMessage.bind(this));
1151
- this.messenger.registerActionHandler(`${name}:signTypedMessage`, this.signTypedMessage.bind(this));
1152
- this.messenger.registerActionHandler(`${name}:decryptMessage`, this.decryptMessage.bind(this));
1153
- this.messenger.registerActionHandler(`${name}:getEncryptionPublicKey`, this.getEncryptionPublicKey.bind(this));
1154
- this.messenger.registerActionHandler(`${name}:getAccounts`, this.getAccounts.bind(this));
1155
- this.messenger.registerActionHandler(`${name}:getKeyringsByType`, this.getKeyringsByType.bind(this));
1156
- this.messenger.registerActionHandler(`${name}:getKeyringForAccount`, this.getKeyringForAccount.bind(this));
1157
- this.messenger.registerActionHandler(`${name}:persistAllKeyrings`, this.persistAllKeyrings.bind(this));
1158
- this.messenger.registerActionHandler(`${name}:prepareUserOperation`, this.prepareUserOperation.bind(this));
1159
- this.messenger.registerActionHandler(`${name}:patchUserOperation`, this.patchUserOperation.bind(this));
1160
- this.messenger.registerActionHandler(`${name}:signUserOperation`, this.signUserOperation.bind(this));
1161
- this.messenger.registerActionHandler(`${name}:addNewAccount`, this.addNewAccount.bind(this));
1162
- this.messenger.registerActionHandler(`${name}:withKeyring`, this.withKeyring.bind(this));
1163
- this.messenger.registerActionHandler(`${name}:withKeyringUnsafe`, this.withKeyringUnsafe.bind(this));
1164
- this.messenger.registerActionHandler(`${name}:withKeyringV2`, this.withKeyringV2.bind(this));
1165
- this.messenger.registerActionHandler(`${name}:withKeyringV2Unsafe`, this.withKeyringV2Unsafe.bind(this));
1166
- this.messenger.registerActionHandler(`${name}:addNewKeyring`, this.addNewKeyring.bind(this));
1167
- this.messenger.registerActionHandler(`${name}:createNewVaultAndKeychain`, this.createNewVaultAndKeychain.bind(this));
1168
- this.messenger.registerActionHandler(`${name}:createNewVaultAndRestore`, this.createNewVaultAndRestore.bind(this));
1169
- this.messenger.registerActionHandler(`${name}:removeAccount`, this.removeAccount.bind(this));
1170
- }, _KeyringController_selectKeyringEntry =
1047
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
1048
+ }, _KeyringController_selectKeyring =
1171
1049
  /**
1172
- * Select a keyring entry using a selector without acquiring the controller lock.
1050
+ * Select a keyring using a selector without acquiring the controller lock.
1173
1051
  *
1174
- * @param options - Selection options.
1175
- * @param options.v2 - Tag to indicate whether the selector is for a V2 keyring.
1176
- * @param options.selector - Keyring selector object.
1177
- * @returns The selected keyring entry, or `undefined` if no match is found.
1052
+ * @param selector - Keyring selector object.
1053
+ * @returns The selected keyring, or `undefined` if no match is found.
1178
1054
  * @template SelectedKeyring - The expected type of the selected keyring.
1179
- * @template SelectedKeyringV2 - The expected type of the selected keyring (v2).
1180
1055
  */
1181
- async function _KeyringController_selectKeyringEntry({ v2, selector, }) {
1182
- let entry;
1056
+ async function _KeyringController_selectKeyring(selector) {
1057
+ let keyring;
1183
1058
  if ('address' in selector) {
1184
- entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryForAccount).call(this, selector.address);
1059
+ keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringForAccount).call(this, selector.address));
1185
1060
  }
1186
1061
  else if ('type' in selector) {
1187
- entry = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntriesByType).call(this, selector.type)[selector.index ?? 0];
1062
+ keyring = this.getKeyringsByType(selector.type)[selector.index ?? 0];
1188
1063
  }
1189
1064
  else if ('id' in selector) {
1190
- entry = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryById).call(this, selector.id);
1065
+ keyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, selector.id);
1191
1066
  }
1192
1067
  else if ('filter' in selector) {
1193
- entry = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ keyring, keyringV2, metadata }) => {
1194
- // If v2, then we'll use the v2 selector which expects a `KeyringV2` instance.
1195
- if (v2) {
1196
- // However, some keyrings do not have a v2 wrapper, so we just skip them.
1197
- if (!keyringV2) {
1198
- return false;
1199
- }
1200
- return selector.filter(keyringV2, metadata);
1201
- }
1202
- return selector.filter(keyring, metadata);
1203
- });
1068
+ keyring = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ keyring: filteredKeyring, metadata }) => selector.filter(filteredKeyring, metadata))?.keyring;
1204
1069
  }
1205
- return entry;
1206
- }, _KeyringController_selectKeyring =
1207
- /**
1208
- * Select a keyring using a selector without acquiring the controller lock.
1209
- *
1210
- * @param selector - Keyring selector object.
1211
- * @returns The selected keyring, or `undefined` if no match is found.
1212
- * @template SelectedKeyring - The expected type of the selected keyring.
1213
- */
1214
- async function _KeyringController_selectKeyring(selector) {
1215
- const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, {
1216
- v2: false,
1217
- selector,
1218
- });
1219
- return entry?.keyring;
1070
+ return keyring;
1220
1071
  }, _KeyringController_getKeyringById = function _KeyringController_getKeyringById(keyringId) {
1221
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryById).call(this, keyringId)?.keyring;
1222
- }, _KeyringController_getKeyringEntryById = function _KeyringController_getKeyringEntryById(keyringId) {
1223
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ metadata }) => metadata.id === keyringId);
1072
+ return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ metadata }) => metadata.id === keyringId)
1073
+ ?.keyring;
1224
1074
  }, _KeyringController_getKeyringByIdOrDefault = function _KeyringController_getKeyringByIdOrDefault(keyringId) {
1225
1075
  if (!keyringId) {
1226
1076
  return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0]?.keyring;
@@ -1234,8 +1084,6 @@ async function _KeyringController_selectKeyring(selector) {
1234
1084
  return keyringWithMetadata.metadata;
1235
1085
  }, _KeyringController_getKeyringBuilderForType = function _KeyringController_getKeyringBuilderForType(type) {
1236
1086
  return __classPrivateFieldGet(this, _KeyringController_keyringBuilders, "f").find((keyringBuilder) => keyringBuilder.type === type);
1237
- }, _KeyringController_getKeyringV2BuilderForType = function _KeyringController_getKeyringV2BuilderForType(type) {
1238
- return __classPrivateFieldGet(this, _KeyringController_keyringV2Builders, "f").find((builder) => builder.type === type);
1239
1087
  }, _KeyringController_createNewVaultWithKeyring =
1240
1088
  /**
1241
1089
  * Create new vault with an initial keyring
@@ -1559,8 +1407,8 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
1559
1407
  * @throws If the keyring includes duplicated accounts.
1560
1408
  */
1561
1409
  async function _KeyringController_newKeyring(type, data) {
1562
- const { keyring, keyringV2, metadata } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1563
- __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({ keyring, keyringV2, metadata });
1410
+ const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1411
+ __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({ keyring, metadata: getDefaultKeyringMetadata() });
1564
1412
  return keyring;
1565
1413
  }, _KeyringController_createKeyring =
1566
1414
  /**
@@ -1577,13 +1425,11 @@ async function _KeyringController_newKeyring(type, data) {
1577
1425
  *
1578
1426
  * @param type - The type of keyring to add.
1579
1427
  * @param data - Keyring initialization options.
1580
- * @param metadata - Keyring metadata if available.
1581
1428
  * @returns The new keyring.
1582
1429
  * @throws If the keyring includes duplicated accounts.
1583
1430
  */
1584
- async function _KeyringController_createKeyring(type, data, metadata) {
1431
+ async function _KeyringController_createKeyring(type, data) {
1585
1432
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1586
- const keyringMetadata = metadata ?? getDefaultKeyringMetadata();
1587
1433
  const keyringBuilder = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringBuilderForType).call(this, type);
1588
1434
  if (!keyringBuilder) {
1589
1435
  throw new KeyringControllerError(`${KeyringControllerErrorMessage.NoKeyringBuilder}. Keyring type: ${type}`);
@@ -1607,13 +1453,7 @@ async function _KeyringController_createKeyring(type, data, metadata) {
1607
1453
  await keyring.generateRandomMnemonic();
1608
1454
  await keyring.addAccounts(1);
1609
1455
  }
1610
- // We now create the keyring V2 wrappers and store them in memory.
1611
- const keyringBuilderV2 = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringV2BuilderForType).call(this, type);
1612
- let keyringV2;
1613
- if (keyringBuilderV2) {
1614
- keyringV2 = keyringBuilderV2(keyring, keyringMetadata);
1615
- }
1616
- return { keyring, keyringV2, metadata: keyringMetadata };
1456
+ return keyring;
1617
1457
  }, _KeyringController_clearKeyrings =
1618
1458
  /**
1619
1459
  * Remove all managed keyrings, destroying all their
@@ -1621,8 +1461,8 @@ async function _KeyringController_createKeyring(type, data, metadata) {
1621
1461
  */
1622
1462
  async function _KeyringController_clearKeyrings() {
1623
1463
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1624
- for (const { keyring, keyringV2 } of __classPrivateFieldGet(this, _KeyringController_keyrings, "f")) {
1625
- await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring, keyringV2);
1464
+ for (const { keyring } of __classPrivateFieldGet(this, _KeyringController_keyrings, "f")) {
1465
+ await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
1626
1466
  }
1627
1467
  __classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
1628
1468
  __classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
@@ -1640,22 +1480,21 @@ async function _KeyringController_restoreKeyring(serialized) {
1640
1480
  const { type, data, metadata: serializedMetadata } = serialized;
1641
1481
  let newMetadata = false;
1642
1482
  let metadata = serializedMetadata;
1483
+ const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1484
+ await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoDuplicateAccounts).call(this, [keyring]);
1643
1485
  // If metadata is missing, assume the data is from an installation before
1644
1486
  // we had keyring metadata.
1645
1487
  if (!metadata) {
1646
1488
  newMetadata = true;
1647
1489
  metadata = getDefaultKeyringMetadata();
1648
1490
  }
1649
- const { keyring, keyringV2 } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data, metadata);
1650
- await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoDuplicateAccounts).call(this, [keyring]);
1651
1491
  // The keyring is added to the keyrings array only if it's successfully restored
1652
1492
  // and the metadata is successfully added to the controller
1653
1493
  __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({
1654
1494
  keyring,
1655
- keyringV2,
1656
1495
  metadata,
1657
1496
  });
1658
- return { keyring, keyringV2, metadata, newMetadata };
1497
+ return { keyring, metadata, newMetadata };
1659
1498
  }
1660
1499
  catch (error) {
1661
1500
  console.error(error);
@@ -1671,13 +1510,9 @@ async function _KeyringController_restoreKeyring(serialized) {
1671
1510
  * clears the keyring bridge iframe from the DOM.
1672
1511
  *
1673
1512
  * @param keyring - The keyring to destroy.
1674
- * @param keyringV2 - The keyring v2 to destroy (if any).
1675
1513
  */
1676
- async function _KeyringController_destroyKeyring(keyring, keyringV2) {
1514
+ async function _KeyringController_destroyKeyring(keyring) {
1677
1515
  await keyring.destroy?.();
1678
- if (keyringV2) {
1679
- await keyringV2.destroy?.();
1680
- }
1681
1516
  }, _KeyringController_assertNoDuplicateAccounts =
1682
1517
  /**
1683
1518
  * Assert that there are no duplicate accounts in the keyrings.