@metamask-previews/keyring-controller 25.2.0-preview-548bdd1d9 → 25.2.0-preview-60aa3d02f

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.
@@ -36,16 +36,14 @@ 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, _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_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;
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;
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");
43
43
  const base_controller_1 = require("@metamask/base-controller");
44
44
  const eth_hd_keyring_1 = require("@metamask/eth-hd-keyring");
45
- const v2_1 = require("@metamask/eth-hd-keyring/v2");
46
45
  const eth_sig_util_1 = require("@metamask/eth-sig-util");
47
46
  const eth_simple_keyring_1 = __importDefault(require("@metamask/eth-simple-keyring"));
48
- const v2_2 = require("@metamask/eth-simple-keyring/v2");
49
47
  const utils_1 = require("@metamask/utils");
50
48
  const async_mutex_1 = require("async-mutex");
51
49
  const ethereumjs_wallet_1 = __importStar(require("ethereumjs-wallet"));
@@ -73,8 +71,6 @@ const MESSENGER_EXPOSED_METHODS = [
73
71
  'addNewAccount',
74
72
  'withKeyring',
75
73
  'withKeyringUnsafe',
76
- 'withKeyringV2',
77
- 'withKeyringV2Unsafe',
78
74
  'addNewKeyring',
79
75
  'createNewVaultAndKeychain',
80
76
  'createNewVaultAndRestore',
@@ -153,17 +149,6 @@ const defaultKeyringBuilders = [
153
149
  keyringBuilderFactory(eth_simple_keyring_1.default),
154
150
  keyringBuilderFactory(eth_hd_keyring_1.HdKeyring),
155
151
  ];
156
- const hdKeyringV2Builder = Object.assign((keyring, metadata) => new v2_1.HdKeyring({
157
- legacyKeyring: keyring,
158
- entropySource: metadata.id,
159
- }), { type: KeyringTypes.hd });
160
- const simpleKeyringV2Builder = Object.assign((keyring) => new v2_2.SimpleKeyring({
161
- legacyKeyring: keyring,
162
- }), { type: KeyringTypes.simple });
163
- const defaultKeyringV2Builders = [
164
- simpleKeyringV2Builder,
165
- hdKeyringV2Builder,
166
- ];
167
152
  const getDefaultKeyringState = () => {
168
153
  return {
169
154
  isUnlocked: false,
@@ -289,7 +274,7 @@ class KeyringController extends base_controller_1.BaseController {
289
274
  * @param options.state - Initial state to set on this controller.
290
275
  */
291
276
  constructor(options) {
292
- const { encryptor, keyringBuilders, keyringV2Builders, messenger, state } = options;
277
+ const { encryptor, keyringBuilders, messenger, state } = options;
293
278
  super({
294
279
  name,
295
280
  metadata: {
@@ -334,7 +319,6 @@ class KeyringController extends base_controller_1.BaseController {
334
319
  _KeyringController_controllerOperationMutex.set(this, new async_mutex_1.Mutex());
335
320
  _KeyringController_vaultOperationMutex.set(this, new async_mutex_1.Mutex());
336
321
  _KeyringController_keyringBuilders.set(this, void 0);
337
- _KeyringController_keyringV2Builders.set(this, void 0);
338
322
  _KeyringController_encryptor.set(this, void 0);
339
323
  _KeyringController_keyrings.set(this, void 0);
340
324
  _KeyringController_unsupportedKeyrings.set(this, void 0);
@@ -342,9 +326,6 @@ class KeyringController extends base_controller_1.BaseController {
342
326
  __classPrivateFieldSet(this, _KeyringController_keyringBuilders, keyringBuilders
343
327
  ? keyringBuilders.concat(defaultKeyringBuilders)
344
328
  : defaultKeyringBuilders, "f");
345
- __classPrivateFieldSet(this, _KeyringController_keyringV2Builders, keyringV2Builders
346
- ? keyringV2Builders.concat(defaultKeyringV2Builders)
347
- : defaultKeyringV2Builders, "f");
348
329
  __classPrivateFieldSet(this, _KeyringController_encryptor, encryptor, "f");
349
330
  __classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
350
331
  __classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
@@ -589,7 +570,9 @@ class KeyringController extends base_controller_1.BaseController {
589
570
  */
590
571
  getKeyringsByType(type) {
591
572
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
592
- 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);
593
576
  }
594
577
  /**
595
578
  * Persist all serialized keyrings in the vault.
@@ -678,7 +661,7 @@ class KeyringController extends base_controller_1.BaseController {
678
661
  if (keyringIndex === -1) {
679
662
  throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.NoKeyring);
680
663
  }
681
- const { keyring, keyringV2 } = __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex];
664
+ const { keyring } = __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex];
682
665
  const isPrimaryKeyring = keyringIndex === 0;
683
666
  const shouldRemoveKeyring = (await keyring.getAccounts()).length === 1;
684
667
  // Primary keyring should never be removed, so we need to keep at least one account in it
@@ -699,7 +682,7 @@ class KeyringController extends base_controller_1.BaseController {
699
682
  await keyring.removeAccount(address);
700
683
  if (shouldRemoveKeyring) {
701
684
  __classPrivateFieldGet(this, _KeyringController_keyrings, "f").splice(keyringIndex, 1);
702
- await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring, keyringV2);
685
+ await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
703
686
  }
704
687
  });
705
688
  this.messenger.publish(`${name}:accountRemoved`, address);
@@ -912,7 +895,7 @@ class KeyringController extends base_controller_1.BaseController {
912
895
  * @returns Promise resolving when the operation completes.
913
896
  */
914
897
  async submitEncryptionKey(encryptionKey, encryptionSalt) {
915
- const { hasChanged } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
898
+ const { newMetadata } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
916
899
  const result = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_unlockKeyrings).call(this, {
917
900
  encryptionKey,
918
901
  encryptionSalt,
@@ -924,7 +907,7 @@ class KeyringController extends base_controller_1.BaseController {
924
907
  // if new metadata has been generated during login, we
925
908
  // can attempt to upgrade the vault.
926
909
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
927
- if (hasChanged) {
910
+ if (newMetadata) {
928
911
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
929
912
  }
930
913
  });
@@ -955,17 +938,17 @@ class KeyringController extends base_controller_1.BaseController {
955
938
  * @returns Promise resolving when the operation completes.
956
939
  */
957
940
  async submitPassword(password) {
958
- const { hasChanged } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
941
+ const { newMetadata } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
959
942
  const result = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_unlockKeyrings).call(this, { password });
960
943
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_setUnlocked).call(this);
961
944
  return result;
962
945
  });
963
946
  try {
964
947
  // If there are stronger encryption params available, or
965
- // if the keyring state has changed during deserialization, we
948
+ // if new metadata has been generated during login, we
966
949
  // can attempt to upgrade the vault.
967
950
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withRollback).call(this, async () => {
968
- if (hasChanged || __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_isNewEncryptionAvailable).call(this)) {
951
+ if (newMetadata || __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_isNewEncryptionAvailable).call(this)) {
969
952
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_deriveAndSetEncryptionKey).call(this, password, {
970
953
  // If the vault is being upgraded, we want to ignore the metadata
971
954
  // that is already in the vault, so we can effectively
@@ -997,20 +980,17 @@ class KeyringController extends base_controller_1.BaseController {
997
980
  }) {
998
981
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
999
982
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
1000
- let entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, {
1001
- v2: false,
1002
- selector,
1003
- });
1004
- if (!entry && 'type' in selector && options.createIfMissing) {
1005
- const newKeyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, selector.type, options.createWithData));
1006
- entry = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ keyring }) => keyring === newKeyring);
983
+ let keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyring).call(this, selector);
984
+ if (!keyring && 'type' in selector && options.createIfMissing) {
985
+ keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_newKeyring).call(this, selector.type, options.createWithData));
1007
986
  }
1008
- if (!entry) {
987
+ if (!keyring) {
1009
988
  throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringNotFound);
1010
989
  }
1011
- const { metadata } = entry;
1012
- const keyring = entry.keyring;
1013
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoUnsafeDirectKeyringAccess).call(this, await operation({ keyring, metadata }), keyring);
990
+ return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoUnsafeDirectKeyringAccess).call(this, await operation({
991
+ keyring,
992
+ metadata: __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringMetadata).call(this, keyring),
993
+ }), keyring);
1014
994
  });
1015
995
  }
1016
996
  /**
@@ -1049,109 +1029,16 @@ class KeyringController extends base_controller_1.BaseController {
1049
1029
  */
1050
1030
  async withKeyringUnsafe(selector, operation) {
1051
1031
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1052
- const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, { v2: false, selector });
1053
- if (!entry) {
1054
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringNotFound);
1055
- }
1056
- const { metadata } = entry;
1057
- const keyring = entry.keyring;
1058
- // Even if this method is "unsafe", we still want to prevent returning
1059
- // the keyring directly.
1060
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoUnsafeDirectKeyringAccess).call(this, await operation({ keyring, metadata }), keyring);
1061
- }
1062
- /**
1063
- * Select a keyring using its `KeyringV2` adapter, and execute
1064
- * the given operation with the wrapped keyring as a mutually
1065
- * exclusive atomic operation.
1066
- *
1067
- * The cached `KeyringV2` adapter is retrieved from the keyring
1068
- * entry.
1069
- *
1070
- * A `KeyringV2Builder` for the selected keyring's type must exist
1071
- * (either as a default or registered via the `keyringV2Builders`
1072
- * constructor option); otherwise an error is thrown.
1073
- *
1074
- * The method automatically persists changes at the end of the
1075
- * function execution, or rolls back the changes if an error
1076
- * is thrown.
1077
- *
1078
- * @param selector - Keyring selector object.
1079
- * @param operation - Function to execute with the wrapped V2 keyring.
1080
- * @returns Promise resolving to the result of the function execution.
1081
- * @template CallbackResult - The type of the value resolved by the callback function.
1082
- */
1083
- async withKeyringV2(selector, operation) {
1084
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1085
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_persistOrRollback).call(this, async () => {
1086
- const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, {
1087
- v2: true,
1088
- selector,
1089
- });
1090
- if (!entry) {
1091
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringNotFound);
1092
- }
1093
- if (!entry.keyringV2) {
1094
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringV2NotSupported);
1095
- }
1096
- const { metadata } = entry;
1097
- const keyring = entry.keyringV2;
1098
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoUnsafeDirectKeyringAccess).call(this, await operation({
1099
- keyring,
1100
- metadata,
1101
- }), keyring);
1102
- });
1103
- }
1104
- /**
1105
- * Select a keyring, wrap it in a `KeyringV2` adapter, and execute
1106
- * the given read-only operation **without** acquiring the controller's
1107
- * mutual exclusion lock.
1108
- *
1109
- * ## When to use this method
1110
- *
1111
- * This method is an escape hatch for read-only access to keyring data that
1112
- * is immutable once the keyring is initialized. A typical safe use case is
1113
- * reading immutable fields from a `KeyringV2` adapter: data that is set
1114
- * during initialization and never mutated afterwards.
1115
- *
1116
- * ## Why it is "unsafe"
1117
- *
1118
- * The "unsafe" designation mirrors the semantics of `unsafe { }` blocks in
1119
- * Rust: the method itself does not enforce thread-safety guarantees. By
1120
- * calling this method the **caller** explicitly takes responsibility for
1121
- * ensuring that:
1122
- *
1123
- * - The operation is **read-only** — no state is mutated.
1124
- * - The data being read is **immutable** after the keyring is initialized,
1125
- * so concurrent locked operations cannot alter it while this callback
1126
- * runs.
1127
- *
1128
- * Do **not** use this method to:
1129
- * - Mutate keyring state (add accounts, sign, etc.) — use `withKeyringV2`.
1130
- * - Read mutable fields that could change during concurrent operations.
1131
- *
1132
- * @param selector - Keyring selector object.
1133
- * @param operation - Read-only function to execute with the wrapped V2 keyring.
1134
- * @returns Promise resolving to the result of the function execution.
1135
- * @template SelectedKeyring - The type of the selected V2 keyring.
1136
- * @template CallbackResult - The type of the value resolved by the callback function.
1137
- */
1138
- async withKeyringV2Unsafe(selector, operation) {
1139
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1140
- const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyringEntry).call(this, {
1141
- v2: true,
1142
- selector,
1143
- });
1144
- if (!entry) {
1032
+ const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_selectKeyring).call(this, selector);
1033
+ if (!keyring) {
1145
1034
  throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringNotFound);
1146
1035
  }
1147
- if (!entry.keyringV2) {
1148
- throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.KeyringV2NotSupported);
1149
- }
1150
- const { metadata } = entry;
1151
- const keyring = entry.keyringV2;
1152
1036
  // Even if this method is "unsafe", we still want to prevent returning
1153
1037
  // the keyring directly.
1154
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoUnsafeDirectKeyringAccess).call(this, await operation({ keyring, metadata }), keyring);
1038
+ return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoUnsafeDirectKeyringAccess).call(this, await operation({
1039
+ keyring,
1040
+ metadata: __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringMetadata).call(this, keyring),
1041
+ }), keyring);
1155
1042
  }
1156
1043
  async getAccountKeyringType(account) {
1157
1044
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
@@ -1160,15 +1047,11 @@ class KeyringController extends base_controller_1.BaseController {
1160
1047
  }
1161
1048
  }
1162
1049
  exports.KeyringController = KeyringController;
1163
- _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) {
1164
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1165
- const entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryForAccount).call(this, account);
1166
- return entry?.keyring;
1167
- }, _KeyringController_getKeyringEntryForAccount = async function _KeyringController_getKeyringEntryForAccount(account) {
1050
+ _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) {
1168
1051
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1169
1052
  const keyringIndex = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_findKeyringIndexForAccount).call(this, account);
1170
1053
  if (keyringIndex > -1) {
1171
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex];
1054
+ return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[keyringIndex].keyring;
1172
1055
  }
1173
1056
  return undefined;
1174
1057
  }, _KeyringController_findKeyringIndexForAccount = async function _KeyringController_findKeyringIndexForAccount(account) {
@@ -1176,9 +1059,6 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
1176
1059
  const address = account.toLowerCase();
1177
1060
  const accountsPerKeyring = await Promise.all(__classPrivateFieldGet(this, _KeyringController_keyrings, "f").map(({ keyring }) => keyring.getAccounts()));
1178
1061
  return accountsPerKeyring.findIndex((accounts) => accounts.map((a) => a.toLowerCase()).includes(address));
1179
- }, _KeyringController_getKeyringEntriesByType = function _KeyringController_getKeyringEntriesByType(type) {
1180
- __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertIsUnlocked).call(this);
1181
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").filter(({ keyring }) => keyring.type === type);
1182
1062
  }, _KeyringController_assertNoUnsafeDirectKeyringAccess = function _KeyringController_assertNoUnsafeDirectKeyringAccess(value, keyring) {
1183
1063
  if (Object.is(value, keyring)) {
1184
1064
  // Access to a keyring instance outside of controller safeguards
@@ -1190,46 +1070,32 @@ _KeyringController_controllerOperationMutex = new WeakMap(), _KeyringController_
1190
1070
  return value;
1191
1071
  }, _KeyringController_registerMessageHandlers = function _KeyringController_registerMessageHandlers() {
1192
1072
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
1193
- }, _KeyringController_selectKeyringEntry =
1073
+ }, _KeyringController_selectKeyring =
1194
1074
  /**
1195
- * Select a keyring entry using a selector without acquiring the controller lock.
1075
+ * Select a keyring using a selector without acquiring the controller lock.
1196
1076
  *
1197
- * @param options - Selection options.
1198
- * @param options.v2 - Tag to indicate whether the selector is for a V2 keyring.
1199
- * @param options.selector - Keyring selector object.
1200
- * @returns The selected keyring entry, or `undefined` if no match is found.
1077
+ * @param selector - Keyring selector object.
1078
+ * @returns The selected keyring, or `undefined` if no match is found.
1201
1079
  * @template SelectedKeyring - The expected type of the selected keyring.
1202
- * @template SelectedKeyringV2 - The expected type of the selected keyring (v2).
1203
1080
  */
1204
- async function _KeyringController_selectKeyringEntry({ v2, selector, }) {
1205
- let entry;
1081
+ async function _KeyringController_selectKeyring(selector) {
1082
+ let keyring;
1206
1083
  if ('address' in selector) {
1207
- entry = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryForAccount).call(this, selector.address);
1084
+ keyring = (await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringForAccount).call(this, selector.address));
1208
1085
  }
1209
1086
  else if ('type' in selector) {
1210
- entry = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntriesByType).call(this, selector.type)[selector.index ?? 0];
1087
+ keyring = this.getKeyringsByType(selector.type)[selector.index ?? 0];
1211
1088
  }
1212
1089
  else if ('id' in selector) {
1213
- entry = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryById).call(this, selector.id);
1090
+ keyring = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringById).call(this, selector.id);
1214
1091
  }
1215
1092
  else if ('filter' in selector) {
1216
- entry = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ keyring, keyringV2, metadata }) => {
1217
- // If v2, then we'll use the v2 selector which expects a `KeyringV2` instance.
1218
- if (v2) {
1219
- // However, some keyrings do not have a v2 wrapper, so we just skip them.
1220
- if (!keyringV2) {
1221
- return false;
1222
- }
1223
- return selector.filter(keyringV2, metadata);
1224
- }
1225
- return selector.filter(keyring, metadata);
1226
- });
1093
+ keyring = __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ keyring: filteredKeyring, metadata }) => selector.filter(filteredKeyring, metadata))?.keyring;
1227
1094
  }
1228
- return entry;
1095
+ return keyring;
1229
1096
  }, _KeyringController_getKeyringById = function _KeyringController_getKeyringById(keyringId) {
1230
- return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringEntryById).call(this, keyringId)?.keyring;
1231
- }, _KeyringController_getKeyringEntryById = function _KeyringController_getKeyringEntryById(keyringId) {
1232
- return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ metadata }) => metadata.id === keyringId);
1097
+ return __classPrivateFieldGet(this, _KeyringController_keyrings, "f").find(({ metadata }) => metadata.id === keyringId)
1098
+ ?.keyring;
1233
1099
  }, _KeyringController_getKeyringByIdOrDefault = function _KeyringController_getKeyringByIdOrDefault(keyringId) {
1234
1100
  if (!keyringId) {
1235
1101
  return __classPrivateFieldGet(this, _KeyringController_keyrings, "f")[0]?.keyring;
@@ -1243,8 +1109,6 @@ async function _KeyringController_selectKeyringEntry({ v2, selector, }) {
1243
1109
  return keyringWithMetadata.metadata;
1244
1110
  }, _KeyringController_getKeyringBuilderForType = function _KeyringController_getKeyringBuilderForType(type) {
1245
1111
  return __classPrivateFieldGet(this, _KeyringController_keyringBuilders, "f").find((keyringBuilder) => keyringBuilder.type === type);
1246
- }, _KeyringController_getKeyringV2BuilderForType = function _KeyringController_getKeyringV2BuilderForType(type) {
1247
- return __classPrivateFieldGet(this, _KeyringController_keyringV2Builders, "f").find((builder) => builder.type === type);
1248
1112
  }, _KeyringController_createNewVaultWithKeyring =
1249
1113
  /**
1250
1114
  * Create new vault with an initial keyring
@@ -1432,18 +1296,18 @@ async function _KeyringController_getSessionState() {
1432
1296
  async function _KeyringController_restoreSerializedKeyrings(serializedKeyrings) {
1433
1297
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_clearKeyrings).call(this);
1434
1298
  const keyrings = [];
1435
- let hasChanged = false;
1299
+ let newMetadata = false;
1436
1300
  for (const serializedKeyring of serializedKeyrings) {
1437
1301
  const result = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreKeyring).call(this, serializedKeyring);
1438
1302
  if (result) {
1439
1303
  const { keyring, metadata } = result;
1440
1304
  keyrings.push({ keyring, metadata });
1441
- if (result.hasChanged) {
1442
- hasChanged = true;
1305
+ if (result.newMetadata) {
1306
+ newMetadata = true;
1443
1307
  }
1444
1308
  }
1445
1309
  }
1446
- return { keyrings, hasChanged };
1310
+ return { keyrings, newMetadata };
1447
1311
  }, _KeyringController_unlockKeyrings =
1448
1312
  /**
1449
1313
  * Unlock Keyrings, decrypting the vault and deserializing all
@@ -1473,14 +1337,14 @@ async function _KeyringController_unlockKeyrings(credentials) {
1473
1337
  if (!isSerializedKeyringsArray(vault)) {
1474
1338
  throw new errors_1.KeyringControllerError(constants_1.KeyringControllerErrorMessage.VaultDataError);
1475
1339
  }
1476
- const { keyrings, hasChanged } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreSerializedKeyrings).call(this, vault);
1340
+ const { keyrings, newMetadata } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_restoreSerializedKeyrings).call(this, vault);
1477
1341
  const updatedKeyrings = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getUpdatedKeyrings).call(this);
1478
1342
  this.update((state) => {
1479
1343
  state.keyrings = updatedKeyrings;
1480
1344
  state.encryptionKey = encryptionKey;
1481
1345
  state.encryptionSalt = __classPrivateFieldGet(this, _KeyringController_encryptionKey, "f")?.salt;
1482
1346
  });
1483
- return { keyrings, hasChanged };
1347
+ return { keyrings, newMetadata };
1484
1348
  });
1485
1349
  }, _KeyringController_updateVault = function _KeyringController_updateVault() {
1486
1350
  return __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_withVaultLock).call(this, async () => {
@@ -1568,8 +1432,8 @@ async function _KeyringController_createKeyringWithFirstAccount(type, opts) {
1568
1432
  * @throws If the keyring includes duplicated accounts.
1569
1433
  */
1570
1434
  async function _KeyringController_newKeyring(type, data) {
1571
- const { keyring, keyringV2, metadata } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1572
- __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({ keyring, keyringV2, metadata });
1435
+ const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1436
+ __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({ keyring, metadata: getDefaultKeyringMetadata() });
1573
1437
  return keyring;
1574
1438
  }, _KeyringController_createKeyring =
1575
1439
  /**
@@ -1586,13 +1450,11 @@ async function _KeyringController_newKeyring(type, data) {
1586
1450
  *
1587
1451
  * @param type - The type of keyring to add.
1588
1452
  * @param data - Keyring initialization options.
1589
- * @param metadata - Keyring metadata if available.
1590
1453
  * @returns The new keyring.
1591
1454
  * @throws If the keyring includes duplicated accounts.
1592
1455
  */
1593
- async function _KeyringController_createKeyring(type, data, metadata) {
1456
+ async function _KeyringController_createKeyring(type, data) {
1594
1457
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1595
- const keyringMetadata = metadata ?? getDefaultKeyringMetadata();
1596
1458
  const keyringBuilder = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringBuilderForType).call(this, type);
1597
1459
  if (!keyringBuilder) {
1598
1460
  throw new errors_1.KeyringControllerError(`${constants_1.KeyringControllerErrorMessage.NoKeyringBuilder}. Keyring type: ${type}`);
@@ -1616,13 +1478,7 @@ async function _KeyringController_createKeyring(type, data, metadata) {
1616
1478
  await keyring.generateRandomMnemonic();
1617
1479
  await keyring.addAccounts(1);
1618
1480
  }
1619
- // We now create the keyring V2 wrappers and store them in memory.
1620
- const keyringBuilderV2 = __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getKeyringV2BuilderForType).call(this, type);
1621
- let keyringV2;
1622
- if (keyringBuilderV2) {
1623
- keyringV2 = keyringBuilderV2(keyring, keyringMetadata);
1624
- }
1625
- return { keyring, keyringV2, metadata: keyringMetadata };
1481
+ return keyring;
1626
1482
  }, _KeyringController_clearKeyrings =
1627
1483
  /**
1628
1484
  * Remove all managed keyrings, destroying all their
@@ -1630,8 +1486,8 @@ async function _KeyringController_createKeyring(type, data, metadata) {
1630
1486
  */
1631
1487
  async function _KeyringController_clearKeyrings() {
1632
1488
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1633
- for (const { keyring, keyringV2 } of __classPrivateFieldGet(this, _KeyringController_keyrings, "f")) {
1634
- await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring, keyringV2);
1489
+ for (const { keyring } of __classPrivateFieldGet(this, _KeyringController_keyrings, "f")) {
1490
+ await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_destroyKeyring).call(this, keyring);
1635
1491
  }
1636
1492
  __classPrivateFieldSet(this, _KeyringController_keyrings, [], "f");
1637
1493
  __classPrivateFieldSet(this, _KeyringController_unsupportedKeyrings, [], "f");
@@ -1647,28 +1503,23 @@ async function _KeyringController_restoreKeyring(serialized) {
1647
1503
  __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertControllerMutexIsLocked).call(this);
1648
1504
  try {
1649
1505
  const { type, data, metadata: serializedMetadata } = serialized;
1650
- // Track if we need to trigger a vault update.
1651
- let hasChanged = false;
1652
- // If metadata is missing, assume the data is from an installation before we had
1653
- // keyring metadata.
1506
+ let newMetadata = false;
1654
1507
  let metadata = serializedMetadata;
1508
+ const keyring = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data);
1509
+ await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoDuplicateAccounts).call(this, [keyring]);
1510
+ // If metadata is missing, assume the data is from an installation before
1511
+ // we had keyring metadata.
1655
1512
  if (!metadata) {
1656
- hasChanged = true;
1513
+ newMetadata = true;
1657
1514
  metadata = getDefaultKeyringMetadata();
1658
1515
  }
1659
- const oldState = JSON.stringify(data);
1660
- const { keyring, keyringV2 } = await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_createKeyring).call(this, type, data, metadata);
1661
- const newState = JSON.stringify(await keyring.serialize());
1662
- hasChanged || (hasChanged = oldState !== newState);
1663
- await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_assertNoDuplicateAccounts).call(this, [keyring]);
1664
1516
  // The keyring is added to the keyrings array only if it's successfully restored
1665
1517
  // and the metadata is successfully added to the controller
1666
1518
  __classPrivateFieldGet(this, _KeyringController_keyrings, "f").push({
1667
1519
  keyring,
1668
- keyringV2,
1669
1520
  metadata,
1670
1521
  });
1671
- return { keyring, keyringV2, metadata, hasChanged };
1522
+ return { keyring, metadata, newMetadata };
1672
1523
  }
1673
1524
  catch (error) {
1674
1525
  console.error(error);
@@ -1684,13 +1535,9 @@ async function _KeyringController_restoreKeyring(serialized) {
1684
1535
  * clears the keyring bridge iframe from the DOM.
1685
1536
  *
1686
1537
  * @param keyring - The keyring to destroy.
1687
- * @param keyringV2 - The keyring v2 to destroy (if any).
1688
1538
  */
1689
- async function _KeyringController_destroyKeyring(keyring, keyringV2) {
1539
+ async function _KeyringController_destroyKeyring(keyring) {
1690
1540
  await keyring.destroy?.();
1691
- if (keyringV2) {
1692
- await keyringV2.destroy?.();
1693
- }
1694
1541
  }, _KeyringController_assertNoDuplicateAccounts =
1695
1542
  /**
1696
1543
  * Assert that there are no duplicate accounts in the keyrings.
@@ -1728,7 +1575,7 @@ async function _KeyringController_persistOrRollback(callback) {
1728
1575
  const callbackResult = await callback({ releaseLock });
1729
1576
  const newState = JSON.stringify(await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_getSessionState).call(this));
1730
1577
  // State is committed only if the operation is successful and need to trigger a vault update.
1731
- if (oldState !== newState) {
1578
+ if (!(0, lodash_1.isEqual)(oldState, newState)) {
1732
1579
  await __classPrivateFieldGet(this, _KeyringController_instances, "m", _KeyringController_updateVault).call(this);
1733
1580
  }
1734
1581
  return callbackResult;