{"version":3,"file":"KeyringController.cjs","sourceRoot":"","sources":["../src/KeyringController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAAiE;AACjE,+DAA2D;AAE3D,6DAAqD;AACrD,oDAAuE;AACvE,yDAAmE;AACnE,sFAAyD;AACzD,wDAAmF;AAiBnF,2CAWyB;AACzB,6CAAoC;AAEpC,uEAAoE;AAEpE,mCAAmC;AACnC,sHAAsH;AACtH,+BAA4B;AAE5B,+CAA4D;AAC5D,yCAAkD;AASlD,MAAM,IAAI,GAAG,mBAAmB,CAAC;AAEjC,MAAM,yBAAyB,GAAG;IAChC,aAAa;IACb,0BAA0B;IAC1B,qBAAqB;IACrB,iBAAiB;IACjB,kBAAkB;IAClB,gBAAgB;IAChB,wBAAwB;IACxB,aAAa;IACb,mBAAmB;IACnB,sBAAsB;IACtB,oBAAoB;IACpB,sBAAsB;IACtB,oBAAoB;IACpB,mBAAmB;IACnB,eAAe;IACf,gBAAgB;IAChB,aAAa;IACb,mBAAmB;IACnB,eAAe;IACf,qBAAqB;IACrB,eAAe;IACf,2BAA2B;IAC3B,0BAA0B;IAC1B,eAAe;IACf,YAAY;IACZ,kBAAkB;IAClB,gBAAgB;IAChB,eAAe;IACf,qBAAqB;IACrB,uBAAuB;IACvB,2BAA2B;IAC3B,WAAW;IACX,qBAAqB;IACrB,gBAAgB;IAChB,gBAAgB;CACR,CAAC;AAEX;;;;;;GAMG;AACH,IAAY,YAcX;AAdD,WAAY,YAAY;IACtB,6EAA6E;IAC7E,uDAAuD;IACvD,yDAAyD;IACzD,0CAA0B,CAAA;IAC1B,kCAAkB,CAAA;IAClB,gDAAgC,CAAA;IAChC,0CAA0B,CAAA;IAC1B,0CAA0B,CAAA;IAC1B,0CAA0B,CAAA;IAC1B,4CAA4B,CAAA;IAC5B,qCAAqB,CAAA;IACrB,uCAAuB,CAAA;IACvB,wDAAwD;AAC1D,CAAC,EAdW,YAAY,4BAAZ,YAA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Data } from '@ethereumjs/tx';\nimport { isValidPrivate, getBinarySize } from '@ethereumjs/util';\nimport { BaseController } from '@metamask/base-controller';\nimport type * as encryptorUtils from '@metamask/browser-passworder';\nimport { HdKeyring } from '@metamask/eth-hd-keyring';\nimport { HdKeyring as HdKeyringV2 } from '@metamask/eth-hd-keyring/v2';\nimport { normalize as ethNormalize } from '@metamask/eth-sig-util';\nimport SimpleKeyring from '@metamask/eth-simple-keyring';\nimport { SimpleKeyring as SimpleKeyringV2 } from '@metamask/eth-simple-keyring/v2';\nimport type {\n  KeyringExecutionContext,\n  EthBaseTransaction,\n  EthBaseUserOperation,\n  EthUserOperation,\n  EthUserOperationPatch,\n  KeyringAccount,\n} from '@metamask/keyring-api';\nimport type {\n  Keyring as KeyringV2,\n  KeyringType,\n} from '@metamask/keyring-api/v2';\nimport type { EthKeyring } from '@metamask/keyring-internal-api';\nimport type { Keyring, KeyringClass } from '@metamask/keyring-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Eip1024EncryptedData, Hex, Json } from '@metamask/utils';\nimport {\n  add0x,\n  assertIsStrictHexString,\n  bytesToHex,\n  hasProperty,\n  hexToBytes,\n  isObject,\n  isStrictHexString,\n  isValidHexAddress,\n  isValidJson,\n  remove0x,\n} from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\nimport type { MutexInterface } from 'async-mutex';\nimport Wallet, { thirdparty as importers } from 'ethereumjs-wallet';\nimport type { Patch } from 'immer';\nimport { cloneDeep } from 'lodash';\n// When generating a ULID within the same millisecond, monotonicFactory provides some guarantees regarding sort order.\nimport { ulid } from 'ulid';\n\nimport { KeyringControllerErrorMessage } from './constants';\nimport { KeyringControllerError } from './errors';\nimport type { KeyringControllerMethodActions } from './KeyringController-method-action-types';\nimport type {\n  Eip7702AuthorizationParams,\n  Credentials,\n  PersonalMessageParams,\n  TypedMessageParams,\n} from './types';\n\nconst name = 'KeyringController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n  'signMessage',\n  'signEip7702Authorization',\n  'signPersonalMessage',\n  'signTransaction',\n  'signTypedMessage',\n  'decryptMessage',\n  'getEncryptionPublicKey',\n  'getAccounts',\n  'getKeyringsByType',\n  'getKeyringForAccount',\n  'persistAllKeyrings',\n  'prepareUserOperation',\n  'patchUserOperation',\n  'signUserOperation',\n  'addNewAccount',\n  'withController',\n  'withKeyring',\n  'withKeyringUnsafe',\n  'withKeyringV2',\n  'withKeyringV2Unsafe',\n  'addNewKeyring',\n  'createNewVaultAndKeychain',\n  'createNewVaultAndRestore',\n  'removeAccount',\n  'isUnlocked',\n  'exportSeedPhrase',\n  'changePassword',\n  'exportAccount',\n  'exportEncryptionKey',\n  'getAccountKeyringType',\n  'importAccountWithStrategy',\n  'setLocked',\n  'submitEncryptionKey',\n  'submitPassword',\n  'verifyPassword',\n] as const;\n\n/**\n * Available keyring types\n *\n * @deprecated Use `KeyringType` from `@metamask/keyring-api/v2` instead. This enum will be removed\n * in a future release once V2 is fully adopted. Only use it if the keyring you are trying to access\n * has no V2 builder available yet.\n */\nexport enum KeyringTypes {\n  // Changing this would be a breaking change, and not worth the effort at this\n  // time, so we disable the linting rule for this block.\n  /* eslint-disable @typescript-eslint/naming-convention */\n  simple = 'Simple Key Pair',\n  hd = 'HD Key Tree',\n  qr = 'QR Hardware Wallet Device',\n  trezor = 'Trezor Hardware',\n  oneKey = 'OneKey Hardware',\n  ledger = 'Ledger Hardware',\n  lattice = 'Lattice Hardware',\n  snap = 'Snap Keyring',\n  money = 'Money Keyring',\n  /* eslint-enable @typescript-eslint/naming-convention */\n}\n\n/**\n * Custody keyring types are a special case, as they are not a single type\n * but they all start with the prefix \"Custody\".\n *\n * @param keyringType - The type of the keyring.\n * @returns Whether the keyring type is a custody keyring.\n */\nexport const isCustodyKeyring = (keyringType: string): boolean => {\n  return keyringType.startsWith('Custody');\n};\n\n/**\n * The KeyringController state\n */\nexport type KeyringControllerState = {\n  /**\n   * Encrypted array of serialized keyrings data.\n   */\n  vault?: string;\n  /**\n   * Whether the vault has been decrypted successfully and\n   * keyrings contained within are deserialized and available.\n   */\n  isUnlocked: boolean;\n  /**\n   * Representations of managed keyrings.\n   */\n  keyrings: KeyringObject[];\n  /**\n   * The encryption key derived from the password and used to encrypt\n   * the vault. This is only stored if the `cacheEncryptionKey` option\n   * is enabled.\n   */\n  encryptionKey?: string;\n  /**\n   * The salt used to derive the encryption key from the password.\n   */\n  encryptionSalt?: string;\n};\n\nexport type KeyringControllerMemState = Omit<\n  KeyringControllerState,\n  'vault' | 'encryptionKey' | 'encryptionSalt'\n>;\n\nexport type KeyringControllerGetStateAction = {\n  type: `${typeof name}:getState`;\n  handler: () => KeyringControllerState;\n};\n\nexport type KeyringControllerStateChangeEvent = {\n  type: `${typeof name}:stateChange`;\n  payload: [KeyringControllerState, Patch[]];\n};\n\nexport type KeyringControllerAccountRemovedEvent = {\n  type: `${typeof name}:accountRemoved`;\n  payload: [string];\n};\n\nexport type KeyringControllerLockEvent = {\n  type: `${typeof name}:lock`;\n  payload: [];\n};\n\nexport type KeyringControllerUnlockEvent = {\n  type: `${typeof name}:unlock`;\n  payload: [];\n};\n\nexport type KeyringControllerActions =\n  | KeyringControllerGetStateAction\n  | KeyringControllerMethodActions;\n\nexport type KeyringControllerEvents =\n  | KeyringControllerStateChangeEvent\n  | KeyringControllerLockEvent\n  | KeyringControllerUnlockEvent\n  | KeyringControllerAccountRemovedEvent;\n\nexport type KeyringControllerMessenger = Messenger<\n  typeof name,\n  KeyringControllerActions,\n  KeyringControllerEvents\n>;\n\nexport type KeyringControllerOptions<\n  EncryptionKey = encryptorUtils.EncryptionKey | CryptoKey,\n  SupportedKeyDerivationOptions = encryptorUtils.KeyDerivationOptions,\n  EncryptionResult extends\n    EncryptionResultConstraint<SupportedKeyDerivationOptions> =\n    DefaultEncryptionResult<SupportedKeyDerivationOptions>,\n> = {\n  keyringBuilders?: { (): EthKeyring; type: string }[];\n  keyringV2Builders?: KeyringV2Builder[];\n  messenger: KeyringControllerMessenger;\n  state?: { vault?: string; keyringsMetadata?: KeyringMetadata[] };\n  encryptor: Encryptor<\n    EncryptionKey,\n    SupportedKeyDerivationOptions,\n    EncryptionResult\n  >;\n};\n\n/**\n * A keyring object representation.\n */\nexport type KeyringObject = {\n  /**\n   * Accounts associated with the keyring.\n   */\n  accounts: string[];\n  /**\n   * Keyring type.\n   */\n  type: string;\n  /**\n   * Additional data associated with the keyring.\n   */\n  metadata: KeyringMetadata;\n};\n\n/**\n * Additional information related to a keyring.\n */\nexport type KeyringMetadata = {\n  /**\n   * Keyring ID\n   */\n  id: string;\n  /**\n   * Keyring name\n   */\n  name: string;\n};\n\n/**\n * A keyring entry, including the keyring instance (+ v2 instance) and its metadata.\n */\nexport type KeyringEntry = {\n  /**\n   * The keyring instance.\n   */\n  keyring: EthKeyring;\n\n  /**\n   * The keyring V2 instance, if available.\n   */\n  keyringV2?: KeyringV2;\n\n  /**\n   * The keyring metadata.\n   */\n  metadata: KeyringMetadata;\n};\n\n/**\n * A restricted view of the {@link KeyringController} exposed to the callback\n * passed to {@link KeyringController.withController}.\n *\n * It provides a read-only live view of all keyrings and the ability to stage\n * keyring additions and removals atomically within a single transaction.\n */\nexport type RestrictedController = {\n  /**\n   * Read-only live view of all keyrings in the current transaction (original\n   * keyrings plus any added, minus any removed so far in this callback).\n   */\n  readonly keyrings: readonly KeyringEntry[];\n  /**\n   * Create a new keyring of the given type and stage it for commit. The new\n   * entry is immediately visible in {@link RestrictedController.keyrings}.\n   *\n   * @param type - The type of keyring to create.\n   * @param opts - Optional data to pass to the keyring builder.\n   * @returns The newly created `{ keyring, metadata }` entry.\n   */\n  addNewKeyring(type: string, opts?: unknown): Promise<KeyringEntry>;\n  /**\n   * Stage the keyring with the given id for removal. The keyring is\n   * immediately removed from {@link RestrictedController.keyrings}.\n   *\n   * @param id - The id of the keyring to remove.\n   */\n  removeKeyring(id: string): Promise<void>;\n};\n\n/**\n * A strategy for importing an account\n */\nexport enum AccountImportStrategy {\n  // Changing this would be a breaking change, and not worth the effort at this\n  // time, so we disable the linting rule for this block.\n  /* eslint-disable @typescript-eslint/naming-convention */\n  privateKey = 'privateKey',\n  json = 'json',\n  /* eslint-enable @typescript-eslint/naming-convention */\n}\n\n/**\n * The `signTypedMessage` version\n *\n * @see https://docs.metamask.io/guide/signing-data.html\n */\nexport enum SignTypedDataVersion {\n  V1 = 'V1',\n  V3 = 'V3',\n  V4 = 'V4',\n}\n\n/**\n * A serialized keyring object.\n */\nexport type SerializedKeyring = {\n  type: string;\n  data: Json;\n  metadata?: KeyringMetadata;\n};\n\n/**\n * Cached encryption key used to encrypt/decrypt the vault.\n */\ntype CachedEncryptionKey = {\n  /**\n   * The serialized encryption key.\n   */\n  serialized: string;\n  /**\n   * The salt used to derive the encryption key.\n   */\n  salt: string;\n};\n\n/**\n * State/data that can be updated during a `withKeyring` operation.\n */\ntype SessionState = {\n  keyrings: SerializedKeyring[];\n  encryptionKey?: CachedEncryptionKey;\n};\n\nexport type EncryptionResultConstraint<SupportedKeyMetadata> = {\n  salt?: string;\n  keyMetadata?: SupportedKeyMetadata;\n};\n\nexport type DefaultEncryptionResult<SupportedKeyMetadata> = {\n  data: string;\n  iv: string;\n  salt?: string;\n  keyMetadata?: SupportedKeyMetadata;\n};\n\n/**\n * An encryptor interface that supports encrypting and decrypting\n * serializable data with a password, and exporting and importing keys.\n */\nexport type Encryptor<\n  EncryptionKey = encryptorUtils.EncryptionKey | CryptoKey,\n  SupportedKeyDerivationParams = encryptorUtils.KeyDerivationOptions,\n  EncryptionResult extends\n    EncryptionResultConstraint<SupportedKeyDerivationParams> =\n    DefaultEncryptionResult<SupportedKeyDerivationParams>,\n> = {\n  /**\n   * Encrypts the given object with the given password.\n   *\n   * @param password - The password to encrypt with.\n   * @param object - The object to encrypt.\n   * @returns The encrypted string.\n   */\n  encrypt: (password: string, object: Json) => Promise<string>;\n  /**\n   * Decrypts the given encrypted string with the given password.\n   *\n   * @param password - The password to decrypt with.\n   * @param encryptedString - The encrypted string to decrypt.\n   * @returns The decrypted object.\n   */\n  decrypt: (password: string, encryptedString: string) => Promise<unknown>;\n  /**\n   * Optional vault migration helper. Checks if the provided vault is up to date\n   * with the desired encryption algorithm.\n   *\n   * @param vault - The encrypted string to check.\n   * @param targetDerivationParams - The desired target derivation params.\n   * @returns The updated encrypted string.\n   */\n  isVaultUpdated?: (\n    vault: string,\n    targetDerivationParams?: encryptorUtils.KeyDerivationOptions,\n  ) => boolean;\n  /**\n   * Encrypts the given object with the given encryption key.\n   *\n   * @param key - The encryption key to encrypt with.\n   * @param object - The object to encrypt.\n   * @returns The encryption result.\n   */\n  encryptWithKey: (\n    key: EncryptionKey,\n    object: Json,\n  ) => Promise<EncryptionResult>;\n  /**\n   * Encrypts the given object with the given password, and returns the\n   * encryption result and the serialized key string.\n   *\n   * @param password - The password to encrypt with.\n   * @param object - The object to encrypt.\n   * @param salt - The optional salt to use for encryption.\n   * @returns The encrypted string and the serialized key string.\n   */\n  encryptWithDetail: (\n    password: string,\n    object: Json,\n    salt?: string,\n  ) => Promise<encryptorUtils.DetailedEncryptionResult>;\n  /**\n   * Decrypts the given encrypted string with the given encryption key.\n   *\n   * @param key - The encryption key to decrypt with.\n   * @param encryptedObject - The encrypted string to decrypt.\n   * @returns The decrypted object.\n   */\n  decryptWithKey: (\n    key: EncryptionKey,\n    encryptedObject: EncryptionResult,\n  ) => Promise<unknown>;\n  /**\n   * Decrypts the given encrypted string with the given password, and returns\n   * the decrypted object and the salt and serialized key string used for\n   * encryption.\n   *\n   * @param password - The password to decrypt with.\n   * @param encryptedString - The encrypted string to decrypt.\n   * @returns The decrypted object and the salt and serialized key string used for\n   * encryption.\n   */\n  decryptWithDetail: (\n    password: string,\n    encryptedString: string,\n  ) => Promise<encryptorUtils.DetailedDecryptResult>;\n  /**\n   * Generates an encryption key from a serialized key.\n   *\n   * @param key - The serialized key string.\n   * @returns The encryption key.\n   */\n  importKey: (key: string) => Promise<EncryptionKey>;\n  /**\n   * Exports the encryption key as a string.\n   *\n   * @param key - The encryption key to export.\n   * @returns The serialized key string.\n   */\n  exportKey: (key: EncryptionKey) => Promise<string>;\n  /**\n   * Derives an encryption key from a password.\n   *\n   * @param password - The password to derive the key from.\n   * @param salt - The salt to use for key derivation.\n   * @param exportable - Whether the key should be exportable or not.\n   * @param options - Optional key derivation options.\n   * @returns The derived encryption key.\n   */\n  keyFromPassword: (\n    password: string,\n    salt: string,\n    exportable?: boolean,\n    keyDerivationOptions?: SupportedKeyDerivationParams,\n  ) => Promise<EncryptionKey>;\n  /**\n   * Generates a random salt for key derivation.\n   */\n  generateSalt: typeof encryptorUtils.generateSalt;\n};\n\n/**\n * Keyring selector used for `withKeyring`.\n */\nexport type KeyringSelector<SelectedKeyring extends EthKeyring = EthKeyring> =\n  | {\n      type: string;\n      index?: number;\n    }\n  | {\n      address: Hex;\n    }\n  | {\n      id: string;\n    }\n  | {\n      /**\n       * A predicate function used to select a keyring. The first keyring for\n       * which this function returns `true` will be selected.\n       *\n       * NOTE: The caller must not mutate the keyring instance passed to this\n       * function. Mutations bypass the controller's state management\n       * safeguards and will lead to inconsistent state. The instance is not\n       * frozen for performance reasons, but treating it as read-only is a\n       * firm requirement — any mutation is a bug in the caller.\n       */\n      filter:\n        | ((keyring: EthKeyring, metadata: KeyringMetadata) => boolean)\n        // Variant of the `filter` function that also acts as a type\n        // guard, allowing callers to narrow the keyring type within the\n        // callback.\n        | ((\n            keyring: EthKeyring,\n            metadata: KeyringMetadata,\n          ) => keyring is SelectedKeyring);\n    };\n\n/**\n * Keyring selector used for `withKeyringV2` (see {@link KeyringController#withKeyringV2} and {@link KeyringSelector}).\n */\nexport type KeyringSelectorV2<SelectedKeyring extends KeyringV2 = KeyringV2> =\n  | {\n      type: `${KeyringType}`;\n      index?: number;\n    }\n  | {\n      address: KeyringAccount['address'];\n    }\n  | {\n      id: KeyringMetadata['id'];\n    }\n  | {\n      /** Similar to {@link KeyringSelector.filter} but for `KeyringV2` instances. */\n      filter:\n        | ((keyring: KeyringV2, metadata: KeyringMetadata) => boolean)\n        | ((\n            keyring: KeyringV2,\n            metadata: KeyringMetadata,\n          ) => keyring is SelectedKeyring);\n    };\n\n/**\n * Keyring builder.\n */\nexport type KeyringBuilder = {\n  (): Keyring;\n  type: string;\n};\n\n/**\n * A builder that wraps a legacy `Keyring` into a `KeyringV2` adapter.\n *\n * The controller calls the builder once when the V1 keyring is created\n * or restored; the resulting wrapper is cached for the keyring's lifetime.\n */\nexport type KeyringV2Builder = {\n  (keyring: Keyring, metadata: KeyringMetadata): KeyringV2;\n  type: string;\n};\n\n/**\n * A function executed within a mutually exclusive lock, with\n * a mutex releaser in its option bag.\n *\n * @param releaseLock - A function to release the lock.\n */\ntype MutuallyExclusiveCallback<Result> = ({\n  releaseLock,\n}: {\n  releaseLock: MutexInterface.Releaser;\n}) => Promise<Result>;\n\n/**\n * Get builder function for `Keyring`\n *\n * Returns a builder function for `Keyring` with a `type` property.\n *\n * @param KeyringConstructor - The Keyring class for the builder.\n * @returns A builder function for the given Keyring.\n */\nexport function keyringBuilderFactory(\n  KeyringConstructor: KeyringClass,\n): KeyringBuilder {\n  const builder: KeyringBuilder = (): Keyring => new KeyringConstructor();\n\n  builder.type = KeyringConstructor.type;\n\n  return builder;\n}\n\nconst defaultKeyringBuilders = [\n  // todo: keyring types are mismatched, this should be fixed in they keyrings themselves\n  // @ts-expect-error keyring types are mismatched\n  keyringBuilderFactory(SimpleKeyring),\n  keyringBuilderFactory(HdKeyring),\n];\n\nconst hdKeyringV2Builder: KeyringV2Builder = Object.assign(\n  (keyring: Keyring, metadata: KeyringMetadata): KeyringV2 =>\n    new HdKeyringV2({\n      legacyKeyring: keyring as HdKeyring,\n      entropySource: metadata.id,\n    }),\n  { type: KeyringTypes.hd as string },\n);\n\nconst simpleKeyringV2Builder: KeyringV2Builder = Object.assign(\n  (keyring: Keyring): KeyringV2 =>\n    new SimpleKeyringV2({\n      legacyKeyring: keyring as SimpleKeyring,\n    }),\n  { type: KeyringTypes.simple as string },\n);\n\nconst defaultKeyringV2Builders: KeyringV2Builder[] = [\n  simpleKeyringV2Builder,\n  hdKeyringV2Builder,\n];\n\nexport const getDefaultKeyringState = (): KeyringControllerState => {\n  return {\n    isUnlocked: false,\n    keyrings: [],\n  };\n};\n\n/**\n * Assert that the given keyring has an exportable\n * mnemonic.\n *\n * @param keyring - The keyring to check\n * @throws When the keyring does not have a mnemonic\n */\nfunction assertHasUint8ArrayMnemonic(\n  keyring: EthKeyring,\n): asserts keyring is EthKeyring & { mnemonic: Uint8Array } {\n  if (\n    !(\n      hasProperty(keyring, 'mnemonic') && keyring.mnemonic instanceof Uint8Array\n    )\n  ) {\n    throw new KeyringControllerError(\"Can't get mnemonic bytes from keyring\");\n  }\n}\n\n/**\n * Assert that the provided password is a valid non-empty string.\n *\n * @param password - The password to check.\n * @throws If the password is not a valid string.\n */\nfunction assertIsValidPassword(password: unknown): asserts password is string {\n  if (typeof password !== 'string') {\n    throw new KeyringControllerError(\n      KeyringControllerErrorMessage.WrongPasswordType,\n    );\n  }\n\n  if (!password?.length) {\n    throw new KeyringControllerError(\n      KeyringControllerErrorMessage.InvalidEmptyPassword,\n    );\n  }\n}\n\n/**\n * Assert that the provided encryption key is a valid non-empty string.\n *\n * @param encryptionKey - The encryption key to check.\n * @throws If the encryption key is not a valid string.\n */\nfunction assertIsEncryptionKeySet(\n  encryptionKey: string | undefined,\n): asserts encryptionKey is string {\n  if (!encryptionKey) {\n    throw new KeyringControllerError(\n      KeyringControllerErrorMessage.EncryptionKeyNotSet,\n    );\n  }\n}\n\n/**\n * Checks if the provided value is a serialized keyrings array.\n *\n * @param array - The value to check.\n * @returns True if the value is a serialized keyrings array.\n */\nfunction isSerializedKeyringsArray(\n  array: unknown,\n): array is SerializedKeyring[] {\n  return (\n    typeof array === 'object' &&\n    Array.isArray(array) &&\n    array.every((value) => value.type && isValidJson(value.data))\n  );\n}\n\n/**\n * Display For Keyring\n *\n * Is used for adding the current keyrings to the state object.\n *\n * @param keyringWithMetadata - The keyring and its metadata.\n * @param keyringWithMetadata.keyring - The keyring to display.\n * @param keyringWithMetadata.metadata - The metadata of the keyring.\n * @returns A keyring display object, with type and accounts properties.\n */\nasync function displayForKeyring({\n  keyring,\n  metadata,\n}: KeyringEntry): Promise<KeyringObject> {\n  const accounts = await keyring.getAccounts();\n\n  return {\n    type: keyring.type,\n    // Cast to `string[]` here is safe here because `accounts` has no nullish\n    // values, and `normalize` returns `string` unless given a nullish value\n    accounts: accounts.map(normalize) as string[],\n    metadata,\n  };\n}\n\n/**\n * Check if address is an ethereum address\n *\n * @param address - An address.\n * @returns Returns true if the address is an ethereum one, false otherwise.\n */\nfunction isEthAddress(address: string): boolean {\n  // We first check if it's a matching `Hex` string, so that is narrows down\n  // `address` as an `Hex` type, allowing us to use `isValidHexAddress`\n  return (\n    // NOTE: This function only checks for lowercased strings\n    isStrictHexString(address.toLowerCase()) &&\n    // This checks for lowercased addresses and checksum addresses too\n    isValidHexAddress(address as Hex)\n  );\n}\n\n/**\n * Normalize ethereum or non-EVM address.\n *\n * @param address - Ethereum or non-EVM address.\n * @returns The normalized address.\n */\nfunction normalize(address: string): string | undefined {\n  // Since the `KeyringController` is only dealing with address, we have\n  // no other way to get the associated account type with this address. So we\n  // are down to check the actual address format for now\n  // TODO: Find a better way to not have those runtime checks based on the\n  //       address value!\n  return isEthAddress(address) ? ethNormalize(address) : address;\n}\n\n/**\n * Controller responsible for establishing and managing user identity.\n *\n * This class is a wrapper around the `eth-keyring-controller` package. The\n * `eth-keyring-controller` manages the \"vault\", which is an encrypted store of private keys, and\n * it manages the wallet \"lock\" state. This wrapper class has convenience methods for interacting\n * with the internal keyring controller and handling certain complex operations that involve the\n * keyrings.\n */\nexport class KeyringController<\n  EncryptionKey = encryptorUtils.EncryptionKey | CryptoKey,\n  SupportedKeyDerivationOptions = encryptorUtils.KeyDerivationOptions,\n  EncryptionResult extends\n    EncryptionResultConstraint<SupportedKeyDerivationOptions> =\n    DefaultEncryptionResult<SupportedKeyDerivationOptions>,\n> extends BaseController<\n  typeof name,\n  KeyringControllerState,\n  KeyringControllerMessenger\n> {\n  readonly #controllerOperationMutex = new Mutex();\n\n  readonly #vaultOperationMutex = new Mutex();\n\n  readonly #keyringBuilders: { (): EthKeyring; type: string }[];\n\n  readonly #keyringV2Builders: KeyringV2Builder[];\n\n  readonly #encryptor: Encryptor<\n    EncryptionKey,\n    SupportedKeyDerivationOptions,\n    EncryptionResult\n  >;\n\n  #keyrings: KeyringEntry[];\n\n  #unsupportedKeyrings: SerializedKeyring[];\n\n  #encryptionKey?: CachedEncryptionKey;\n\n  /**\n   * Creates a KeyringController instance.\n   *\n   * @param options - Initial options used to configure this controller\n   * @param options.encryptor - An optional object for defining encryption schemes.\n   * @param options.keyringBuilders - Set a new name for account.\n   * @param options.cacheEncryptionKey - Whether to cache or not encryption key.\n   * @param options.messenger - A restricted messenger.\n   * @param options.state - Initial state to set on this controller.\n   */\n  constructor(\n    options: KeyringControllerOptions<\n      EncryptionKey,\n      SupportedKeyDerivationOptions,\n      EncryptionResult\n    >,\n  ) {\n    const { encryptor, keyringBuilders, keyringV2Builders, messenger, state } =\n      options;\n\n    super({\n      name,\n      metadata: {\n        vault: {\n          includeInStateLogs: false,\n          persist: true,\n          includeInDebugSnapshot: false,\n          usedInUi: false,\n        },\n        isUnlocked: {\n          includeInStateLogs: true,\n          persist: false,\n          includeInDebugSnapshot: true,\n          usedInUi: true,\n        },\n        keyrings: {\n          includeInStateLogs: true,\n          persist: false,\n          includeInDebugSnapshot: false,\n          usedInUi: true,\n        },\n        encryptionKey: {\n          includeInStateLogs: false,\n          persist: false,\n          includeInDebugSnapshot: false,\n          usedInUi: false,\n        },\n        encryptionSalt: {\n          includeInStateLogs: false,\n          persist: false,\n          includeInDebugSnapshot: false,\n          usedInUi: false,\n        },\n      },\n      messenger,\n      state: {\n        ...getDefaultKeyringState(),\n        ...state,\n      },\n    });\n\n    this.#keyringBuilders = keyringBuilders\n      ? keyringBuilders.concat(defaultKeyringBuilders)\n      : defaultKeyringBuilders;\n\n    this.#keyringV2Builders = keyringV2Builders\n      ? keyringV2Builders.concat(defaultKeyringV2Builders)\n      : defaultKeyringV2Builders;\n\n    this.#encryptor = encryptor;\n    this.#keyrings = [];\n    this.#unsupportedKeyrings = [];\n\n    this.#registerMessageHandlers();\n  }\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   */\n  async addNewAccount(accountCount?: number): Promise<string> {\n    this.#assertIsUnlocked();\n\n    return this.#persistOrRollback(async () => {\n      const primaryKeyring = this.getKeyringsByType('HD Key Tree')[0] as\n        | EthKeyring\n        | undefined;\n      if (!primaryKeyring) {\n        throw new KeyringControllerError('No HD keyring found');\n      }\n      const oldAccounts = await primaryKeyring.getAccounts();\n\n      if (accountCount && oldAccounts.length !== accountCount) {\n        if (accountCount > oldAccounts.length) {\n          throw new KeyringControllerError('Account out of sequence');\n        }\n        // we return the account already existing at index `accountCount`\n        const existingAccount = oldAccounts[accountCount];\n\n        if (!existingAccount) {\n          throw new KeyringControllerError(\n            `Can't find account at index ${accountCount}`,\n          );\n        }\n\n        return existingAccount;\n      }\n\n      const [addedAccountAddress] = await primaryKeyring.addAccounts(1);\n      await this.#verifySeedPhrase();\n\n      return addedAccountAddress;\n    });\n  }\n\n  /**\n   * Adds a new account to the specified keyring.\n   *\n   * @param keyring - Keyring to add the account to.\n   * @param accountCount - Number of accounts before adding a new one, used to make the method idempotent.\n   * @returns Promise resolving to the added account address\n   */\n  async addNewAccountForKeyring(\n    keyring: EthKeyring,\n    accountCount?: number,\n  ): Promise<Hex> {\n    // READ THIS CAREFULLY:\n    // We still uses `Hex` here, since we are not using this method when creating\n    // and account using a \"Snap Keyring\". This function assume the `keyring` is\n    // ethereum compatible, but \"Snap Keyring\" might not be.\n    this.#assertIsUnlocked();\n\n    return this.#persistOrRollback(async () => {\n      const oldAccounts = await this.#getAccountsFromKeyrings();\n\n      if (accountCount && oldAccounts.length !== accountCount) {\n        if (accountCount > oldAccounts.length) {\n          throw new KeyringControllerError('Account out of sequence');\n        }\n\n        const existingAccount = oldAccounts[accountCount];\n        assertIsStrictHexString(existingAccount);\n\n        return existingAccount;\n      }\n\n      await keyring.addAccounts(1);\n\n      const addedAccountAddress = (await this.#getAccountsFromKeyrings()).find(\n        (selectedAddress) => !oldAccounts.includes(selectedAddress),\n      );\n      assertIsStrictHexString(addedAccountAddress);\n\n      return addedAccountAddress;\n    });\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   */\n  async createNewVaultAndRestore(\n    password: string,\n    seed: Uint8Array,\n  ): Promise<void> {\n    return this.#persistOrRollback(async () => {\n      assertIsValidPassword(password);\n\n      await this.#createNewVaultWithKeyring(password, {\n        type: KeyringTypes.hd,\n        opts: {\n          mnemonic: seed,\n          numberOfAccounts: 1,\n        },\n      });\n    });\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   */\n  async createNewVaultAndKeychain(password: string): Promise<void> {\n    return this.#persistOrRollback(async () => {\n      const accounts = await this.#getAccountsFromKeyrings();\n      if (!accounts.length) {\n        await this.#createNewVaultWithKeyring(password, {\n          type: KeyringTypes.hd,\n        });\n      }\n    });\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   */\n  async addNewKeyring(\n    type: KeyringTypes | string,\n    opts?: unknown,\n  ): Promise<KeyringMetadata> {\n    this.#assertIsUnlocked();\n\n    return this.#getKeyringMetadata(\n      await this.#persistOrRollback(async () => this.#newKeyring(type, opts)),\n    );\n  }\n\n  /**\n   * Method to verify a given password validity. Throws an\n   * error if the password is invalid.\n   *\n   * @param password - Password of the keyring.\n   */\n  async verifyPassword(password: string): Promise<void> {\n    if (!this.state.vault) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.VaultError,\n      );\n    }\n    await this.#encryptor.decrypt(password, this.state.vault);\n  }\n\n  /**\n   * Method to verify a given encryption key validity. Throws an error if the\n   * encryption key is invalid, i.e. it cannot decrypt the vault.\n   *\n   * @param encryptionKey - Serialized vault encryption key.\n   * @param encryptionSalt - Optional salt to verify against the vault. When\n   * omitted, the salt serialized alongside the vault is used.\n   */\n  async #verifyEncryptionKey(\n    encryptionKey: string,\n    encryptionSalt?: string,\n  ): Promise<void> {\n    if (!this.state.vault) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.VaultError,\n      );\n    }\n\n    const parsedEncryptedVault = JSON.parse(this.state.vault);\n    const salt = encryptionSalt ?? parsedEncryptedVault.salt;\n\n    if (parsedEncryptedVault.salt !== salt) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.ExpiredCredentials,\n      );\n    }\n\n    const key = await this.#encryptor.importKey(encryptionKey);\n    await this.#encryptor.decryptWithKey(key, parsedEncryptedVault);\n  }\n\n  /**\n   * Verifies export credentials by checking either the wallet password or the\n   * vault encryption key.\n   *\n   * @param credentials - Object holding either the `password` or the vault\n   * `encryptionKey`.\n   */\n  async #verifyCredentials(credentials: Credentials): Promise<void> {\n    // eslint-disable-next-line no-restricted-syntax\n    if ('password' in credentials) {\n      await this.verifyPassword(credentials.password);\n    } else {\n      await this.#verifyEncryptionKey(\n        credentials.encryptionKey,\n        credentials.encryptionSalt,\n      );\n    }\n  }\n\n  /**\n   * Returns the status of the vault.\n   *\n   * @returns Boolean returning true if the vault is unlocked.\n   */\n  isUnlocked(): boolean {\n    return this.state.isUnlocked;\n  }\n\n  /**\n   * Gets the seed phrase of the HD keyring.\n   *\n   * @param credentials - Object holding either the `password` or the vault\n   * `encryptionKey`.\n   * @param keyringId - The id of the keyring.\n   * @returns Promise resolving to the seed phrase.\n   */\n  async exportSeedPhrase(\n    credentials: Credentials,\n    keyringId?: string,\n  ): Promise<Uint8Array> {\n    this.#assertIsUnlocked();\n\n    await this.#verifyCredentials(credentials);\n\n    const selectedKeyring = this.#getKeyringByIdOrDefault(keyringId);\n    if (!selectedKeyring) {\n      throw new KeyringControllerError('Keyring not found');\n    }\n    assertHasUint8ArrayMnemonic(selectedKeyring);\n\n    return selectedKeyring.mnemonic;\n  }\n\n  /**\n   * Gets the private key from the keyring controlling an address.\n   *\n   * @param credentials - Object holding either the `password` or the vault\n   * `encryptionKey`.\n   * @param address - Address to export.\n   * @returns Promise resolving to the private key for an address.\n   */\n  async exportAccount(\n    credentials: Credentials,\n    address: string,\n  ): Promise<string> {\n    this.#assertIsUnlocked();\n\n    await this.#verifyCredentials(credentials);\n\n    const keyring = (await this.getKeyringForAccount(address)) as EthKeyring;\n    if (!keyring.exportAccount) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.UnsupportedExportAccount,\n      );\n    }\n\n    return await keyring.exportAccount(normalize(address) as Hex);\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   */\n  async getAccounts(): Promise<string[]> {\n    this.#assertIsUnlocked();\n    return this.state.keyrings.reduce<string[]>(\n      (accounts, keyring) => accounts.concat(keyring.accounts),\n      [],\n    );\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   */\n  async getEncryptionPublicKey(\n    account: string,\n    opts?: Record<string, unknown>,\n  ): Promise<string> {\n    this.#assertIsUnlocked();\n    const address = ethNormalize(account) as Hex;\n    const keyring = (await this.getKeyringForAccount(account)) as EthKeyring;\n    if (!keyring.getEncryptionPublicKey) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.UnsupportedGetEncryptionPublicKey,\n      );\n    }\n\n    return await keyring.getEncryptionPublicKey(address, opts);\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   */\n  async decryptMessage(messageParams: {\n    from: string;\n    data: Eip1024EncryptedData;\n  }): Promise<string> {\n    this.#assertIsUnlocked();\n    const address = ethNormalize(messageParams.from) as Hex;\n    const keyring = (await this.getKeyringForAccount(address)) as EthKeyring;\n    if (!keyring.decryptMessage) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.UnsupportedDecryptMessage,\n      );\n    }\n\n    return keyring.decryptMessage(address, messageParams.data);\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   */\n  async getKeyringForAccount(account: string): Promise<unknown> {\n    this.#assertIsUnlocked();\n    const keyring = await this.#getKeyringForAccount(account);\n    if (keyring) {\n      return keyring;\n    }\n\n    if (this.#keyrings.length === 0) {\n      throw new KeyringControllerError(KeyringControllerErrorMessage.NoKeyring);\n    }\n\n    throw new KeyringControllerError(\n      KeyringControllerErrorMessage.KeyringNotFound,\n    );\n  }\n\n  async #getKeyringForAccount(\n    account: string,\n  ): Promise<EthKeyring | undefined> {\n    this.#assertIsUnlocked();\n    const entry = await this.#getKeyringEntryForAccount(account);\n    return entry?.keyring;\n  }\n\n  async #getKeyringEntryForAccount(\n    account: string,\n  ): Promise<KeyringEntry | undefined> {\n    this.#assertIsUnlocked();\n    const keyringIndex = await this.#findKeyringIndexForAccount(account);\n    if (keyringIndex > -1) {\n      return this.#keyrings[keyringIndex];\n    }\n    return undefined;\n  }\n\n  async #findKeyringIndexForAccount(account: string): Promise<number> {\n    this.#assertIsUnlocked();\n    const address = account.toLowerCase();\n    const accountsPerKeyring = await Promise.all(\n      this.#keyrings.map(({ keyring }) => keyring.getAccounts()),\n    );\n    return accountsPerKeyring.findIndex((accounts) =>\n      accounts.map((a) => a.toLowerCase()).includes(address),\n    );\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   */\n  getKeyringsByType(type: KeyringTypes | string): unknown[] {\n    this.#assertIsUnlocked();\n    return this.#getKeyringEntriesByType({ v2: false, type }).map(\n      ({ keyring }) => keyring,\n    );\n  }\n\n  #getKeyringEntriesByType({\n    v2,\n    type,\n  }:\n    | {\n        v2: false;\n        type: KeyringTypes | string;\n      }\n    | {\n        v2: true;\n        type: `${KeyringType}`;\n      }): KeyringEntry[] {\n    this.#assertIsUnlocked();\n    return this.#keyrings.filter(({ keyring, keyringV2 }) =>\n      v2 ? keyringV2?.type === type : keyring.type === type,\n    );\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   */\n  async persistAllKeyrings(): Promise<boolean> {\n    return this.#withRollback(async () => {\n      this.#assertIsUnlocked();\n\n      await this.#updateVault();\n      return true;\n    });\n  }\n\n  /**\n   * Imports an account with the specified import strategy.\n   *\n   * @param strategy - Import strategy name.\n   * @param args - Array of arguments to pass to the underlying stategy.\n   * @throws Will throw when passed an unrecognized strategy.\n   * @returns Promise resolving to the imported account address.\n   */\n  async importAccountWithStrategy(\n    strategy: AccountImportStrategy,\n    // TODO: Replace `any` with type\n    // eslint-disable-next-line @typescript-eslint/no-explicit-any\n    args: any[],\n  ): Promise<string> {\n    this.#assertIsUnlocked();\n    return this.#persistOrRollback(async () => {\n      let privateKey;\n      switch (strategy) {\n        case AccountImportStrategy.privateKey: {\n          const [importedKey] = args;\n          if (!importedKey) {\n            throw new KeyringControllerError('Cannot import an empty key.');\n          }\n          const prefixed = add0x(importedKey);\n\n          let bufferedPrivateKey;\n          try {\n            bufferedPrivateKey = hexToBytes(prefixed);\n          } catch {\n            throw new KeyringControllerError(\n              'Cannot import invalid private key.',\n            );\n          }\n\n          if (\n            !isValidPrivate(bufferedPrivateKey) ||\n            // ensures that the key is 64 bytes long\n            getBinarySize(prefixed) !== 64 + '0x'.length\n          ) {\n            throw new KeyringControllerError(\n              'Cannot import invalid private key.',\n            );\n          }\n\n          privateKey = remove0x(prefixed);\n          break;\n        }\n        case AccountImportStrategy.json: {\n          let wallet;\n          const [input, password] = args;\n          try {\n            wallet = importers.fromEtherWallet(input, password);\n          } catch {\n            wallet = wallet ?? (await Wallet.fromV3(input, password, true));\n          }\n          privateKey = bytesToHex(new Uint8Array(wallet.getPrivateKey()));\n          break;\n        }\n        default:\n          throw new KeyringControllerError(\n            `Unexpected import strategy: '${String(strategy)}'`,\n          );\n      }\n      const newKeyring = await this.#newKeyring(KeyringTypes.simple, [\n        privateKey,\n      ]);\n      const accounts = await newKeyring.getAccounts();\n      return accounts[0];\n    });\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   */\n  async removeAccount(address: string): Promise<void> {\n    this.#assertIsUnlocked();\n\n    await this.#persistOrRollback(async () => {\n      const keyringIndex = await this.#findKeyringIndexForAccount(address);\n\n      if (keyringIndex === -1) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.NoKeyring,\n        );\n      }\n\n      const { keyring, keyringV2 } = this.#keyrings[keyringIndex];\n\n      const isPrimaryKeyring = keyringIndex === 0;\n      const shouldRemoveKeyring = (await keyring.getAccounts()).length === 1;\n\n      // Primary keyring should never be removed, so we need to keep at least one account in it\n      if (isPrimaryKeyring && shouldRemoveKeyring) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.LastAccountInPrimaryKeyring,\n        );\n      }\n\n      // Not all the keyrings support this, so we have to check\n      if (!keyring.removeAccount) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.UnsupportedRemoveAccount,\n        );\n      }\n\n      // FIXME #1: We do cast to `Hex` to make the type checker happy here, and\n      // because `Keyring<State>.removeAccount` requires address to be `Hex`.\n      // Those types would need to be updated for a full non-EVM support.\n      //\n      // FIXME #2: The `removeAccount` method of snaps keyring is async. We have\n      // to update the interface of the other keyrings to be async as well.\n      // eslint-disable-next-line @typescript-eslint/await-thenable\n      await keyring.removeAccount(address as Hex);\n\n      if (shouldRemoveKeyring) {\n        this.#keyrings.splice(keyringIndex, 1);\n        await this.#destroyKeyring(keyring, keyringV2);\n      }\n    });\n\n    this.messenger.publish(`${name}:accountRemoved`, address);\n  }\n\n  /**\n   * Deallocates all secrets and locks the wallet.\n   *\n   * @returns Promise resolving when the operation completes.\n   */\n  async setLocked(): Promise<void> {\n    this.#assertIsUnlocked();\n\n    return this.#withRollback(async () => {\n      this.#encryptionKey = undefined;\n      await this.#clearKeyrings();\n\n      this.update((state) => {\n        state.isUnlocked = false;\n        state.keyrings = [];\n        delete state.encryptionKey;\n        delete state.encryptionSalt;\n      });\n\n      this.messenger.publish(`${name}:lock`);\n    });\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   */\n  async signMessage(messageParams: PersonalMessageParams): Promise<string> {\n    this.#assertIsUnlocked();\n\n    if (!messageParams.data) {\n      throw new KeyringControllerError(\"Can't sign an empty message\");\n    }\n\n    const address = ethNormalize(messageParams.from) as Hex;\n    const keyring = (await this.getKeyringForAccount(address)) as EthKeyring;\n    if (!keyring.signMessage) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.UnsupportedSignMessage,\n      );\n    }\n\n    return await keyring.signMessage(address, messageParams.data);\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   */\n  async signEip7702Authorization(\n    params: Eip7702AuthorizationParams,\n  ): Promise<string> {\n    const from = ethNormalize(params.from) as Hex;\n\n    const keyring = (await this.getKeyringForAccount(from)) as EthKeyring;\n\n    if (!keyring.signEip7702Authorization) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.UnsupportedSignEip7702Authorization,\n      );\n    }\n\n    const { chainId, nonce } = params;\n    const contractAddress = ethNormalize(params.contractAddress) as\n      | Hex\n      | undefined;\n\n    if (contractAddress === undefined) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.MissingEip7702AuthorizationContractAddress,\n      );\n    }\n\n    return await keyring.signEip7702Authorization(from, [\n      chainId,\n      contractAddress,\n      nonce,\n    ]);\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   */\n  async signPersonalMessage(\n    messageParams: PersonalMessageParams,\n  ): Promise<string> {\n    this.#assertIsUnlocked();\n    const address = ethNormalize(messageParams.from) as Hex;\n    const keyring = (await this.getKeyringForAccount(address)) as EthKeyring;\n    if (!keyring.signPersonalMessage) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.UnsupportedSignPersonalMessage,\n      );\n    }\n\n    const normalizedData = normalize(messageParams.data) as Hex;\n\n    return await keyring.signPersonalMessage(address, normalizedData);\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   */\n  async signTypedMessage(\n    messageParams: TypedMessageParams,\n    version: SignTypedDataVersion,\n  ): Promise<string> {\n    this.#assertIsUnlocked();\n\n    try {\n      if (\n        ![\n          SignTypedDataVersion.V1,\n          SignTypedDataVersion.V3,\n          SignTypedDataVersion.V4,\n        ].includes(version)\n      ) {\n        throw new KeyringControllerError(\n          `Unexpected signTypedMessage version: '${version}'`,\n        );\n      }\n\n      // Cast to `Hex` here is safe here because `messageParams.from` is not nullish.\n      // `normalize` returns `Hex` unless given a nullish value.\n      const address = ethNormalize(messageParams.from) as Hex;\n      const keyring = (await this.getKeyringForAccount(address)) as EthKeyring;\n      if (!keyring.signTypedData) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.UnsupportedSignTypedMessage,\n        );\n      }\n\n      return await keyring.signTypedData(\n        address,\n        version !== SignTypedDataVersion.V1 &&\n          typeof messageParams.data === 'string'\n          ? JSON.parse(messageParams.data)\n          : messageParams.data,\n        { version },\n      );\n    } catch (error) {\n      const errorMessage =\n        error instanceof Error\n          ? `${error.name}: ${error.message}`\n          : String(error);\n      throw new KeyringControllerError(\n        `Keyring Controller signTypedMessage: ${errorMessage}`,\n        error instanceof Error ? error : undefined,\n      );\n    }\n  }\n\n  /**\n   * Signs a transaction by calling down into a specific keyring.\n   *\n   * @param transaction - Transaction object to sign. Must be a `ethereumjs-tx` transaction instance.\n   * @param from - Address to sign from, should be in keychain.\n   * @param opts - An optional options object.\n   * @returns Promise resolving to a signed transaction string.\n   */\n  async signTransaction(\n    transaction: TypedTransaction,\n    from: string,\n    opts?: Record<string, unknown>,\n  ): Promise<TypedTxData> {\n    this.#assertIsUnlocked();\n    const address = ethNormalize(from) as Hex;\n    const keyring = (await this.getKeyringForAccount(address)) as EthKeyring;\n    if (!keyring.signTransaction) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.UnsupportedSignTransaction,\n      );\n    }\n\n    return await keyring.signTransaction(address, transaction, opts);\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   */\n  async prepareUserOperation(\n    from: string,\n    transactions: EthBaseTransaction[],\n    executionContext: KeyringExecutionContext,\n  ): Promise<EthBaseUserOperation> {\n    this.#assertIsUnlocked();\n    const address = ethNormalize(from) as Hex;\n    const keyring = (await this.getKeyringForAccount(address)) as EthKeyring;\n\n    if (!keyring.prepareUserOperation) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.UnsupportedPrepareUserOperation,\n      );\n    }\n\n    return await keyring.prepareUserOperation(\n      address,\n      transactions,\n      executionContext,\n    );\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   */\n  async patchUserOperation(\n    from: string,\n    userOp: EthUserOperation,\n    executionContext: KeyringExecutionContext,\n  ): Promise<EthUserOperationPatch> {\n    this.#assertIsUnlocked();\n    const address = ethNormalize(from) as Hex;\n    const keyring = (await this.getKeyringForAccount(address)) as EthKeyring;\n\n    if (!keyring.patchUserOperation) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.UnsupportedPatchUserOperation,\n      );\n    }\n\n    return await keyring.patchUserOperation(address, userOp, executionContext);\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   */\n  async signUserOperation(\n    from: string,\n    userOp: EthUserOperation,\n    executionContext: KeyringExecutionContext,\n  ): Promise<string> {\n    this.#assertIsUnlocked();\n    const address = ethNormalize(from) as Hex;\n    const keyring = (await this.getKeyringForAccount(address)) as EthKeyring;\n\n    if (!keyring.signUserOperation) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.UnsupportedSignUserOperation,\n      );\n    }\n\n    return await keyring.signUserOperation(address, userOp, executionContext);\n  }\n\n  /**\n   * Changes the password used to encrypt the vault.\n   *\n   * @param password - The new password.\n   * @returns Promise resolving when the operation completes.\n   */\n  changePassword(password: string): Promise<void> {\n    this.#assertIsUnlocked();\n\n    return this.#persistOrRollback(async () => {\n      assertIsValidPassword(password);\n      await this.#deriveAndSetEncryptionKey(password, {\n        ignoreExistingVault: true,\n      });\n    });\n  }\n\n  /**\n   * Attempts to decrypt the current vault and load its keyrings, using the\n   * given encryption key and salt. The optional salt can be used to check for\n   * consistency with the vault salt.\n   *\n   * @param encryptionKey - Key to unlock the keychain.\n   * @param encryptionSalt - Optional salt to unlock the keychain.\n   * @returns Promise resolving when the operation completes.\n   */\n  async submitEncryptionKey(\n    encryptionKey: string,\n    encryptionSalt?: string,\n  ): Promise<void> {\n    const { hasChanged } = await this.#withRollback(async () => {\n      const result = await this.#unlockKeyrings({\n        encryptionKey,\n        encryptionSalt,\n      });\n      this.#setUnlocked();\n      return result;\n    });\n\n    try {\n      // if new metadata has been generated during login, we\n      // can attempt to upgrade the vault.\n      await this.#withRollback(async () => {\n        if (hasChanged) {\n          await this.#updateVault();\n        }\n      });\n    } catch (error) {\n      // We don't want to throw an error if the upgrade fails\n      // since the controller is already unlocked.\n      console.error('Failed to update vault during login:', error);\n    }\n  }\n\n  /**\n   * Exports the vault encryption key.\n   *\n   * @returns The vault encryption key.\n   */\n  async exportEncryptionKey(): Promise<string> {\n    this.#assertIsUnlocked();\n\n    return await this.#withControllerLock(async () => {\n      assertIsEncryptionKeySet(this.#encryptionKey?.serialized);\n      return this.#encryptionKey.serialized;\n    });\n  }\n\n  /**\n   * Attempts to decrypt the current vault and load its keyrings,\n   * using the given password.\n   *\n   * @param password - Password to unlock the keychain.\n   * @returns Promise resolving when the operation completes.\n   */\n  async submitPassword(password: string): Promise<void> {\n    const { hasChanged } = await this.#withRollback(async () => {\n      const result = await this.#unlockKeyrings({ password });\n      this.#setUnlocked();\n      return result;\n    });\n\n    try {\n      // If there are stronger encryption params available, or\n      // if the keyring state has changed during deserialization, we\n      // can attempt to upgrade the vault.\n      await this.#withRollback(async () => {\n        if (hasChanged || this.#isNewEncryptionAvailable()) {\n          await this.#deriveAndSetEncryptionKey(password, {\n            // If the vault is being upgraded, we want to ignore the metadata\n            // that is already in the vault, so we can effectively\n            // re-encrypt the vault with the new encryption config.\n            ignoreExistingVault: true,\n          });\n          await this.#updateVault();\n        }\n      });\n    } catch (error) {\n      // We don't want to throw an error if the upgrade fails\n      // since the controller is already unlocked.\n      console.error('Failed to update vault during login:', error);\n    }\n  }\n\n  /**\n   * Verifies the that the seed phrase restores the current keychain's accounts.\n   *\n   * @param keyringId - The id of the keyring to verify.\n   * @returns Promise resolving to the seed phrase as Uint8Array.\n   */\n  async verifySeedPhrase(keyringId?: string): Promise<Uint8Array> {\n    this.#assertIsUnlocked();\n\n    return this.#withControllerLock(async () =>\n      this.#verifySeedPhrase(keyringId),\n    );\n  }\n\n  /**\n   * Asserts a value is not a specific keyring instance, and throws an error if it is.\n   *\n   * @param value The value to check.\n   * @param keyring The keyring instance to check against.\n   * @throws If the value is the same instance as the keyring.\n   * @returns The original value if the check passes.\n   */\n  #assertNoUnsafeDirectKeyringAccess<Value, SelectedKeyring>(\n    value: Value,\n    keyring: SelectedKeyring,\n  ): Value {\n    if (Object.is(value, keyring)) {\n      // Access to a keyring instance outside of controller safeguards\n      // should be discouraged, as it can lead to unexpected behavior.\n      // This error is thrown to prevent consumers using `withKeyring`\n      // as a way to get a reference to a keyring instance.\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.UnsafeDirectKeyringAccess,\n      );\n    }\n\n    return value;\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   */\n  async withKeyring<\n    SelectedKeyring extends EthKeyring = EthKeyring,\n    CallbackResult = void,\n  >(\n    selector: KeyringSelector<SelectedKeyring>,\n    operation: ({ keyring, metadata }: KeyringEntry) => Promise<CallbackResult>,\n    // eslint-disable-next-line @typescript-eslint/unified-signatures\n    options:\n      | { createIfMissing?: false }\n      | { createIfMissing: true; createWithData?: unknown },\n  ): Promise<CallbackResult>;\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   * @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   */\n  async withKeyring<\n    SelectedKeyring extends EthKeyring = EthKeyring,\n    CallbackResult = void,\n  >(\n    selector: KeyringSelector<SelectedKeyring>,\n    operation: ({ keyring, metadata }: KeyringEntry) => Promise<CallbackResult>,\n  ): Promise<CallbackResult>;\n\n  async withKeyring<\n    SelectedKeyring extends EthKeyring = EthKeyring,\n    CallbackResult = void,\n  >(\n    selector: KeyringSelector<SelectedKeyring>,\n    operation: ({\n      keyring,\n      metadata,\n    }: {\n      keyring: SelectedKeyring;\n      metadata: KeyringMetadata;\n    }) => Promise<CallbackResult>,\n    options:\n      | { createIfMissing?: false }\n      | { createIfMissing: true; createWithData?: unknown } = {\n      createIfMissing: false,\n    },\n  ): Promise<CallbackResult> {\n    this.#assertIsUnlocked();\n\n    return this.#persistOrRollback(async () => {\n      let entry: KeyringEntry | undefined = await this.#selectKeyringEntry({\n        v2: false,\n        selector,\n      });\n\n      if (!entry && 'type' in selector && options.createIfMissing) {\n        const newKeyring = (await this.#newKeyring(\n          selector.type,\n          options.createWithData,\n        )) as SelectedKeyring;\n        entry = this.#keyrings.find(({ keyring }) => keyring === newKeyring);\n      }\n\n      if (!entry) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.KeyringNotFound,\n        );\n      }\n\n      const { metadata } = entry;\n      const keyring = entry.keyring as SelectedKeyring;\n\n      return this.#assertNoUnsafeDirectKeyringAccess(\n        await this.#cleanUpEmptiedKeyringsAfter(async () =>\n          operation({ keyring, metadata }),\n        ),\n        keyring,\n      );\n    });\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   */\n  async withKeyringUnsafe<\n    SelectedKeyring extends EthKeyring = EthKeyring,\n    CallbackResult = void,\n  >(\n    selector: KeyringSelector<SelectedKeyring>,\n    operation: ({\n      keyring,\n      metadata,\n    }: {\n      keyring: SelectedKeyring;\n      metadata: KeyringMetadata;\n    }) => Promise<CallbackResult>,\n  ): Promise<CallbackResult> {\n    this.#assertIsUnlocked();\n\n    const entry = await this.#selectKeyringEntry({ v2: false, selector });\n\n    if (!entry) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.KeyringNotFound,\n      );\n    }\n\n    const { metadata } = entry;\n    const keyring = entry.keyring as SelectedKeyring;\n\n    // Even if this method is \"unsafe\", we still want to prevent returning\n    // the keyring directly.\n    return this.#assertNoUnsafeDirectKeyringAccess(\n      await operation({ keyring, metadata }),\n      keyring,\n    );\n  }\n\n  /**\n   * Select a keyring using its `KeyringV2` adapter, and execute\n   * the given operation with the wrapped keyring as a mutually\n   * exclusive atomic operation.\n   *\n   * The cached `KeyringV2` adapter is retrieved from the keyring\n   * entry.\n   *\n   * A `KeyringV2Builder` for the selected keyring's type must exist\n   * (either as a default or registered via the `keyringV2Builders`\n   * constructor option); otherwise an error is thrown.\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 wrapped V2 keyring.\n   * @returns Promise resolving to the result of the function execution.\n   * @template CallbackResult - The type of the value resolved by the callback function.\n   */\n  async withKeyringV2<\n    SelectedKeyring extends KeyringV2 = KeyringV2,\n    CallbackResult = void,\n  >(\n    selector: KeyringSelectorV2<SelectedKeyring>,\n    operation: ({\n      keyring,\n      metadata,\n    }: {\n      keyring: SelectedKeyring;\n      metadata: KeyringMetadata;\n    }) => Promise<CallbackResult>,\n  ): Promise<CallbackResult> {\n    this.#assertIsUnlocked();\n\n    return this.#persistOrRollback(async () => {\n      const entry = await this.#selectKeyringEntry({\n        v2: true,\n        selector,\n      });\n\n      if (!entry) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.KeyringNotFound,\n        );\n      }\n\n      if (!entry.keyringV2) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.KeyringV2NotSupported,\n        );\n      }\n\n      const { metadata } = entry;\n      const keyring = entry.keyringV2 as SelectedKeyring;\n\n      return this.#assertNoUnsafeDirectKeyringAccess(\n        await this.#cleanUpEmptiedKeyringsAfter(async () =>\n          operation({\n            keyring,\n            metadata,\n          }),\n        ),\n        keyring,\n      );\n    });\n  }\n\n  /**\n   * Select a keyring, wrap it in a `KeyringV2` adapter, and execute\n   * the given read-only operation **without** acquiring the controller's\n   * 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 immutable fields from a `KeyringV2` adapter: data that is set\n   * during initialization and never mutated afterwards.\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 `withKeyringV2`.\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 wrapped V2 keyring.\n   * @returns Promise resolving to the result of the function execution.\n   * @template SelectedKeyring - The type of the selected V2 keyring.\n   * @template CallbackResult - The type of the value resolved by the callback function.\n   */\n  async withKeyringV2Unsafe<\n    SelectedKeyring extends KeyringV2 = KeyringV2,\n    CallbackResult = void,\n  >(\n    selector: KeyringSelectorV2<SelectedKeyring>,\n    operation: ({\n      keyring,\n      metadata,\n    }: {\n      keyring: SelectedKeyring;\n      metadata: KeyringMetadata;\n    }) => Promise<CallbackResult>,\n  ): Promise<CallbackResult> {\n    this.#assertIsUnlocked();\n\n    const entry = await this.#selectKeyringEntry({\n      v2: true,\n      selector,\n    });\n\n    if (!entry) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.KeyringNotFound,\n      );\n    }\n\n    if (!entry.keyringV2) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.KeyringV2NotSupported,\n      );\n    }\n\n    const { metadata } = entry;\n    const keyring = entry.keyringV2 as SelectedKeyring;\n\n    // Even if this method is \"unsafe\", we still want to prevent returning\n    // the keyring directly.\n    return this.#assertNoUnsafeDirectKeyringAccess(\n      await operation({ keyring, metadata }),\n      keyring,\n    );\n  }\n\n  /**\n   * Execute an operation against all keyrings as a mutually exclusive atomic\n   * operation. The operation receives a {@link RestrictedController} instance\n   * that exposes a read-only live view of all keyrings as well as\n   * `addNewKeyring` and `removeKeyring` methods to stage mutations.\n   *\n   * The method automatically persists changes at the end of the function\n   * execution, or rolls back the changes if an error is thrown.\n   *\n   * @param operation - Function to execute with the restricted controller.\n   * @returns Promise resolving to the result of the function execution.\n   * @template CallbackResult - The type of the value resolved by the callback function.\n   */\n  async withController<CallbackResult = void>(\n    operation: (\n      restrictedController: RestrictedController,\n    ) => Promise<CallbackResult>,\n  ): Promise<CallbackResult> {\n    this.#assertIsUnlocked();\n\n    return this.#persistOrRollback(async () => {\n      // Track created and removed keyrings during the operation execution.\n      const createdEntries = new Set<KeyringEntry>();\n      const removedEntries = new Set<KeyringEntry>();\n\n      // Copy of the current keyrings that is mutated during the operation execution.\n      const restrictedEntries = [...this.#keyrings];\n\n      // The restricted controller proxies the current keyrings and allows staging\n      // mutations that are only applied to the real keyrings if the operation\n      // completes successfully. This allows us to have a single source of truth\n      // for the keyrings during the operation execution, and to automatically\n      // roll back any changes if an error is thrown.\n      const restrictedController: RestrictedController = {\n        // We freeze the array to prevent direct mutations, but the keyring instances\n        // themselves are not frozen, allowing safe read-only access.\n        get keyrings() {\n          return Object.freeze([...restrictedEntries]);\n        },\n\n        // Method to create a new keyring and adds it to the restricted entries.\n        addNewKeyring: async (type: string, opts?: unknown) => {\n          const entry = await this.#createKeyring(type, opts);\n\n          restrictedEntries.push(entry);\n          createdEntries.add(entry);\n\n          return entry;\n        },\n\n        // Method to remove a keyring from the restricted entries.\n        removeKeyring: async (id: string) => {\n          const index = restrictedEntries.findIndex(\n            (entry) => entry.metadata.id === id,\n          );\n          if (index === -1) {\n            throw new KeyringControllerError(\n              KeyringControllerErrorMessage.KeyringNotFound,\n            );\n          }\n\n          this.#assertNotRemovingPrimaryKeyring(\n            restrictedEntries[index],\n            restrictedEntries,\n          );\n\n          const [removed] = restrictedEntries.splice(index, 1) as [\n            KeyringEntry,\n          ];\n          removedEntries.add(removed);\n        },\n      };\n\n      const destroyKeyrings = async (\n        entries: Iterable<KeyringEntry>,\n      ): Promise<void> => {\n        await Promise.all(\n          [...entries].map(({ keyring, keyringV2 }) =>\n            this.#destroyKeyring(keyring, keyringV2),\n          ),\n        );\n      };\n\n      let result: CallbackResult;\n      try {\n        result = await operation(restrictedController);\n      } catch (error) {\n        await destroyKeyrings(createdEntries);\n\n        throw error;\n      }\n\n      await destroyKeyrings(removedEntries);\n\n      // We update the real keyrings only after the operation completes successfully, so that\n      // they will be persisted in the vault.\n      this.#keyrings = restrictedEntries;\n\n      // As usual, we want to prevent returning direct references to keyring instances, so we check\n      // the result for any unsafe direct access before returning.\n      for (const { keyring, keyringV2 } of [\n        ...this.#keyrings,\n        // We also check for keyrings that got removed during the operation, since the result could\n        // still have references to them.\n        ...removedEntries,\n      ]) {\n        this.#assertNoUnsafeDirectKeyringAccess(result, keyring);\n        if (keyringV2) {\n          this.#assertNoUnsafeDirectKeyringAccess(result, keyringV2);\n        }\n      }\n\n      return result;\n    });\n  }\n\n  /**\n   * Gets the type of the keyring that manages the specified account.\n   *\n   * @param account - The account address to look up.\n   * @returns A promise that resolves to the type of the keyring managing the account.\n   */\n  async getAccountKeyringType(account: string): Promise<string> {\n    this.#assertIsUnlocked();\n\n    const keyring = (await this.getKeyringForAccount(account)) as EthKeyring;\n    return keyring.type;\n  }\n\n  /**\n   * Constructor helper for registering this controller's messeger\n   * actions.\n   */\n  #registerMessageHandlers(): void {\n    this.messenger.registerMethodActionHandlers(\n      this,\n      MESSENGER_EXPOSED_METHODS,\n    );\n  }\n\n  /**\n   * Select a keyring entry using a selector without acquiring the controller lock.\n   *\n   * @param options - Selection options.\n   * @param options.v2 - Tag to indicate whether the selector is for a V2 keyring.\n   * @param options.selector - Keyring selector object.\n   * @returns The selected keyring entry, or `undefined` if no match is found.\n   * @template SelectedKeyring - The expected type of the selected keyring.\n   * @template SelectedKeyringV2 - The expected type of the selected keyring (v2).\n   */\n  async #selectKeyringEntry<\n    SelectedKeyring extends EthKeyring,\n    SelectedKeyringV2 extends KeyringV2,\n  >({\n    v2,\n    selector,\n  }: // Use distinct union tags to ensure proper type narrowing of the selector object.\n    | {\n        v2: false;\n        selector: KeyringSelector<SelectedKeyring>;\n      }\n    | {\n        v2: true;\n        selector: KeyringSelectorV2<SelectedKeyringV2>;\n      }): Promise<KeyringEntry | undefined> {\n    let entry: KeyringEntry | undefined;\n\n    if ('address' in selector) {\n      entry = await this.#getKeyringEntryForAccount(selector.address);\n    } else if ('type' in selector) {\n      const entries = v2\n        ? this.#getKeyringEntriesByType({ v2: true, type: selector.type })\n        : this.#getKeyringEntriesByType({ v2: false, type: selector.type });\n      entry = entries[selector.index ?? 0];\n    } else if ('id' in selector) {\n      entry = this.#getKeyringEntryById(selector.id);\n    } else if ('filter' in selector) {\n      entry = this.#keyrings.find(({ keyring, keyringV2, metadata }) => {\n        // If v2, then we'll use the v2 selector which expects a `KeyringV2` instance.\n        if (v2) {\n          // However, some keyrings do not have a v2 wrapper, so we just skip them.\n          if (!keyringV2) {\n            return false;\n          }\n\n          return selector.filter(keyringV2, metadata);\n        }\n\n        return selector.filter(keyring, metadata);\n      });\n    }\n\n    return entry;\n  }\n\n  /**\n   * Get the keyring by id.\n   *\n   * @param keyringId - The id of the keyring.\n   * @returns The keyring.\n   */\n  #getKeyringById(keyringId: string): EthKeyring | undefined {\n    return this.#getKeyringEntryById(keyringId)?.keyring;\n  }\n\n  #getKeyringEntryById(keyringId: string): KeyringEntry | undefined {\n    return this.#keyrings.find(({ metadata }) => metadata.id === keyringId);\n  }\n\n  /**\n   * Get the keyring by id or return the first keyring if the id is not found.\n   *\n   * @param keyringId - The id of the keyring.\n   * @returns The keyring.\n   */\n  #getKeyringByIdOrDefault(keyringId?: string): EthKeyring | undefined {\n    if (!keyringId) {\n      return this.#keyrings[0]?.keyring;\n    }\n\n    return this.#getKeyringById(keyringId);\n  }\n\n  /**\n   * Get the metadata for the specified keyring.\n   *\n   * @param keyring - The keyring instance to get the metadata for.\n   * @returns The keyring metadata.\n   */\n  #getKeyringMetadata(keyring: unknown): KeyringMetadata {\n    const keyringWithMetadata = this.#keyrings.find(\n      (candidate) => candidate.keyring === keyring,\n    );\n    if (!keyringWithMetadata) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.KeyringNotFound,\n      );\n    }\n    return keyringWithMetadata.metadata;\n  }\n\n  /**\n   * Get the keyring builder for the given `type`.\n   *\n   * @param type - The type of keyring to get the builder for.\n   * @returns The keyring builder, or undefined if none exists.\n   */\n  #getKeyringBuilderForType(\n    type: string,\n  ): { (): EthKeyring; type: string } | undefined {\n    return this.#keyringBuilders.find(\n      (keyringBuilder) => keyringBuilder.type === type,\n    );\n  }\n\n  /**\n   * Get the V2 keyring builder for the given `type`.\n   *\n   * @param type - The type of keyring to get the builder for.\n   * @returns The V2 keyring builder, or undefined if none exists.\n   */\n  #getKeyringV2BuilderForType(type: string): KeyringV2Builder | undefined {\n    return this.#keyringV2Builders.find((builder) => builder.type === type);\n  }\n\n  /**\n   * Create new vault with an initial keyring\n   *\n   * Destroys any old encrypted storage,\n   * creates a new encrypted store with the given password,\n   * creates a new wallet with 1 account.\n   *\n   * @fires KeyringController:unlock\n   * @param password - The password to encrypt the vault with.\n   * @param keyring - A object containing the params to instantiate a new keyring.\n   * @param keyring.type - The keyring type.\n   * @param keyring.opts - Optional parameters required to instantiate the keyring.\n   * @returns A promise that resolves to the state.\n   */\n  async #createNewVaultWithKeyring(\n    password: string,\n    keyring: {\n      type: string;\n      opts?: unknown;\n    },\n  ): Promise<void> {\n    this.#assertControllerMutexIsLocked();\n\n    if (typeof password !== 'string') {\n      throw new TypeError(KeyringControllerErrorMessage.WrongPasswordType);\n    }\n\n    this.update((state) => {\n      delete state.encryptionKey;\n      delete state.encryptionSalt;\n    });\n\n    await this.#deriveAndSetEncryptionKey(password, {\n      ignoreExistingVault: true,\n    });\n\n    await this.#clearKeyrings();\n    await this.#createKeyringWithFirstAccount(keyring.type, keyring.opts);\n    this.#setUnlocked();\n  }\n\n  /**\n   * Derive the vault encryption key from the provided password, and\n   * assign it to the instance variable for later use with cryptographic\n   * functions.\n   *\n   * When the controller has a vault in its state, the key is derived\n   * using the salt from the vault. If the vault is empty, a new salt\n   * is generated and used to derive the key.\n   *\n   * If `options.ignoreExistingVault` is set to `true`, the existing\n   * vault is completely ignored: the new key won't be able to decrypt\n   * the existing vault, and should be used to re-encrypt it.\n   *\n   * @param password - The password to use for decryption or derivation.\n   * @param options - Options for the key derivation.\n   * @param options.ignoreExistingVault - Whether to ignore the existing vault salt and key metadata\n   */\n  async #deriveAndSetEncryptionKey(\n    password: string,\n    options: { ignoreExistingVault: boolean } = {\n      ignoreExistingVault: false,\n    },\n  ): Promise<void> {\n    this.#assertControllerMutexIsLocked();\n    const { vault } = this.state;\n\n    if (typeof password !== 'string') {\n      throw new TypeError(KeyringControllerErrorMessage.WrongPasswordType);\n    }\n\n    let serializedEncryptionKey: string, salt: string;\n    if (vault && !options.ignoreExistingVault) {\n      // The `decryptWithDetail` method is being used here instead of\n      // `keyFromPassword` + `exportKey` to let the encryptor handle\n      // any legacy encryption formats and metadata that might be\n      // present (or absent) in the vault.\n      const { exportedKeyString, salt: existingSalt } =\n        await this.#encryptor.decryptWithDetail(password, vault);\n      serializedEncryptionKey = exportedKeyString;\n      salt = existingSalt;\n    } else {\n      salt = this.#encryptor.generateSalt();\n      serializedEncryptionKey = await this.#encryptor.exportKey(\n        await this.#encryptor.keyFromPassword(password, salt, true),\n      );\n    }\n\n    this.#encryptionKey = {\n      salt,\n      serialized: serializedEncryptionKey,\n    };\n  }\n\n  /**\n   * Set the the `#encryptionKey` instance variable.\n   * This method is used when the user provides an encryption key and salt\n   * to unlock the keychain, instead of using a password.\n   *\n   * @param encryptionKey - The encryption key to use.\n   * @param keyDerivationSalt - The salt to use for the encryption key.\n   */\n  #setEncryptionKey(encryptionKey: string, keyDerivationSalt: string): void {\n    this.#assertControllerMutexIsLocked();\n\n    if (\n      typeof encryptionKey !== 'string' ||\n      typeof keyDerivationSalt !== 'string'\n    ) {\n      throw new TypeError(KeyringControllerErrorMessage.WrongEncryptionKeyType);\n    }\n\n    const { vault } = this.state;\n    if (vault && JSON.parse(vault).salt !== keyDerivationSalt) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.ExpiredCredentials,\n      );\n    }\n\n    this.#encryptionKey = {\n      salt: keyDerivationSalt,\n      serialized: encryptionKey,\n    };\n  }\n\n  /**\n   * Internal non-exclusive method to verify the seed phrase.\n   *\n   * @param keyringId - The id of the keyring to verify the seed phrase for.\n   * @returns A promise resolving to the seed phrase as Uint8Array.\n   */\n  async #verifySeedPhrase(keyringId?: string): Promise<Uint8Array> {\n    this.#assertControllerMutexIsLocked();\n\n    const keyring = this.#getKeyringByIdOrDefault(keyringId);\n\n    if (!keyring) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.KeyringNotFound,\n      );\n    }\n\n    if (keyring.type !== (KeyringTypes.hd as string)) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.UnsupportedVerifySeedPhrase,\n      );\n    }\n\n    assertHasUint8ArrayMnemonic(keyring);\n\n    const seedWords = keyring.mnemonic;\n    const accounts = await keyring.getAccounts();\n    /* istanbul ignore if */\n    if (accounts.length === 0) {\n      throw new KeyringControllerError('Cannot verify an empty keyring.');\n    }\n\n    // The HD Keyring Builder is a default keyring builder\n    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n    const hdKeyringBuilder = this.#getKeyringBuilderForType(KeyringTypes.hd)!;\n\n    const hdKeyring = hdKeyringBuilder();\n    // @ts-expect-error @metamask/eth-hd-keyring correctly handles\n    // Uint8Array seed phrases in the `deserialize` method.\n    await hdKeyring.deserialize({\n      mnemonic: seedWords,\n      numberOfAccounts: accounts.length,\n    });\n    const testAccounts = await hdKeyring.getAccounts();\n    /* istanbul ignore if */\n    if (testAccounts.length !== accounts.length) {\n      throw new KeyringControllerError(\n        'Seed phrase imported incorrect number of accounts.',\n      );\n    }\n\n    testAccounts.forEach((account: string, i: number) => {\n      /* istanbul ignore if */\n      if (account.toLowerCase() !== accounts[i].toLowerCase()) {\n        throw new KeyringControllerError(\n          'Seed phrase imported different accounts.',\n        );\n      }\n    });\n\n    return seedWords;\n  }\n\n  /**\n   * Get the updated array of each keyring's type and\n   * accounts list.\n   *\n   * @returns A promise resolving to the updated keyrings array.\n   */\n  async #getUpdatedKeyrings(): Promise<KeyringObject[]> {\n    return Promise.all(this.#keyrings.map(displayForKeyring));\n  }\n\n  /**\n   * Serialize the current array of keyring instances,\n   * including unsupported keyrings by default.\n   *\n   * @param options - Method options.\n   * @param options.includeUnsupported - Whether to include unsupported keyrings.\n   * @returns The serialized keyrings.\n   */\n  async #getSerializedKeyrings(\n    { includeUnsupported }: { includeUnsupported: boolean } = {\n      includeUnsupported: true,\n    },\n  ): Promise<SerializedKeyring[]> {\n    const serializedKeyrings: SerializedKeyring[] = await Promise.all(\n      this.#keyrings.map(async ({ keyring, metadata }) => {\n        return {\n          type: keyring.type,\n          data: await keyring.serialize(),\n          metadata,\n        };\n      }),\n    );\n\n    if (includeUnsupported) {\n      serializedKeyrings.push(...this.#unsupportedKeyrings);\n    }\n\n    return serializedKeyrings;\n  }\n\n  /**\n   * Get a snapshot of session data held by instance variables.\n   *\n   * @returns An object with serialized keyrings, keyrings metadata,\n   * and the user password.\n   */\n  async #getSessionState(): Promise<SessionState> {\n    return {\n      keyrings: await this.#getSerializedKeyrings(),\n      encryptionKey: this.#encryptionKey,\n    };\n  }\n\n  /**\n   * Restore a serialized keyrings array.\n   *\n   * @param serializedKeyrings - The serialized keyrings array.\n   * @returns The restored keyrings.\n   */\n  async #restoreSerializedKeyrings(\n    serializedKeyrings: SerializedKeyring[],\n  ): Promise<{\n    keyrings: { keyring: EthKeyring; metadata: KeyringMetadata }[];\n    hasChanged: boolean;\n  }> {\n    await this.#clearKeyrings();\n    const keyrings: { keyring: EthKeyring; metadata: KeyringMetadata }[] = [];\n    let hasChanged = false;\n\n    for (const serializedKeyring of serializedKeyrings) {\n      const result = await this.#restoreKeyring(serializedKeyring);\n      if (result) {\n        const { keyring, metadata } = result;\n        keyrings.push({ keyring, metadata });\n        if (result.hasChanged) {\n          hasChanged = true;\n        }\n      }\n    }\n\n    return { keyrings, hasChanged };\n  }\n\n  /**\n   * Unlock Keyrings, decrypting the vault and deserializing all\n   * keyrings contained in it, using a password or an encryption key with salt.\n   *\n   * @param credentials - The credentials to unlock the keyrings.\n   * @returns A promise resolving to the deserialized keyrings array.\n   */\n  async #unlockKeyrings(credentials: Credentials): Promise<{\n    keyrings: { keyring: EthKeyring; metadata: KeyringMetadata }[];\n    hasChanged: boolean;\n  }> {\n    return this.#withVaultLock(async () => {\n      if (!this.state.vault) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.VaultError,\n        );\n      }\n      const parsedEncryptedVault = JSON.parse(this.state.vault);\n\n      if ('password' in credentials) {\n        await this.#deriveAndSetEncryptionKey(credentials.password);\n      } else {\n        this.#setEncryptionKey(\n          credentials.encryptionKey,\n          credentials.encryptionSalt ?? parsedEncryptedVault.salt,\n        );\n      }\n\n      const encryptionKey = this.#encryptionKey?.serialized;\n      if (!encryptionKey) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.MissingCredentials,\n        );\n      }\n\n      const key = await this.#encryptor.importKey(encryptionKey);\n      const vault = await this.#encryptor.decryptWithKey(\n        key,\n        parsedEncryptedVault,\n      );\n\n      if (!isSerializedKeyringsArray(vault)) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.VaultDataError,\n        );\n      }\n\n      const { keyrings, hasChanged } =\n        await this.#restoreSerializedKeyrings(vault);\n\n      const updatedKeyrings = await this.#getUpdatedKeyrings();\n\n      this.update((state) => {\n        state.keyrings = updatedKeyrings;\n        state.encryptionKey = encryptionKey;\n        state.encryptionSalt = this.#encryptionKey?.salt;\n      });\n\n      return { keyrings, hasChanged };\n    });\n  }\n\n  /**\n   * Update the vault with the current keyrings.\n   *\n   * @returns A promise resolving to `true` if the operation is successful.\n   */\n  #updateVault(): Promise<boolean> {\n    return this.#withVaultLock(async () => {\n      // Ensure no duplicate accounts are persisted.\n      await this.#assertNoDuplicateAccounts();\n\n      if (!this.#encryptionKey) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.MissingCredentials,\n        );\n      }\n\n      const serializedKeyrings = await this.#getSerializedKeyrings();\n\n      if (\n        !serializedKeyrings.some(\n          (keyring) => keyring.type === (KeyringTypes.hd as string),\n        )\n      ) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.NoHdKeyring,\n        );\n      }\n\n      const key = await this.#encryptor.importKey(\n        this.#encryptionKey.serialized,\n      );\n      const encryptedVault = await this.#encryptor.encryptWithKey(\n        key,\n        serializedKeyrings,\n      );\n      // We need to include the salt used to derive\n      // the encryption key, to be able to derive it\n      // from password again.\n      encryptedVault.salt = this.#encryptionKey.salt;\n      const updatedState: Partial<KeyringControllerState> = {\n        vault: JSON.stringify(encryptedVault),\n        encryptionKey: this.#encryptionKey.serialized,\n        encryptionSalt: this.#encryptionKey.salt,\n      };\n\n      const updatedKeyrings = await this.#getUpdatedKeyrings();\n\n      this.update((state) => {\n        state.vault = updatedState.vault;\n        state.keyrings = updatedKeyrings;\n        state.encryptionKey = updatedState.encryptionKey;\n        state.encryptionSalt = updatedState.encryptionSalt;\n      });\n\n      return true;\n    });\n  }\n\n  /**\n   * Check if there are new encryption parameters available.\n   *\n   * @returns A promise resolving to `void`.\n   */\n  #isNewEncryptionAvailable(): boolean {\n    const { vault } = this.state;\n\n    if (!vault || !this.#encryptor.isVaultUpdated) {\n      return false;\n    }\n\n    return !this.#encryptor.isVaultUpdated(vault);\n  }\n\n  /**\n   * Retrieves all the accounts from keyrings instances\n   * that are currently in memory.\n   *\n   * @param additionalKeyrings - Additional keyrings to include in the search.\n   * @returns A promise resolving to an array of accounts.\n   */\n  async #getAccountsFromKeyrings(\n    additionalKeyrings: EthKeyring[] = [],\n  ): Promise<string[]> {\n    const keyrings = this.#keyrings.map(({ keyring }) => keyring);\n\n    const keyringArrays = await Promise.all(\n      [...keyrings, ...additionalKeyrings].map(async (keyring) =>\n        keyring.getAccounts(),\n      ),\n    );\n    const addresses = keyringArrays.reduce((res, arr) => {\n      return res.concat(arr);\n    }, []);\n\n    // Cast to `string[]` here is safe here because `addresses` has no nullish\n    // values, and `normalize` returns `string` unless given a nullish value\n    return addresses.map(normalize) as string[];\n  }\n\n  /**\n   * Create a new keyring, ensuring that the first account is\n   * also created.\n   *\n   * @param type - Keyring type to instantiate.\n   * @param opts - Optional parameters required to instantiate the keyring.\n   * @returns A promise that resolves if the operation is successful.\n   */\n  async #createKeyringWithFirstAccount(\n    type: string,\n    opts?: unknown,\n  ): Promise<Hex> {\n    this.#assertControllerMutexIsLocked();\n\n    const keyring = await this.#newKeyring(type, opts);\n\n    const [firstAccount] = await keyring.getAccounts();\n    if (!firstAccount) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.NoFirstAccount,\n      );\n    }\n    return firstAccount;\n  }\n\n  /**\n   * Instantiate, initialize and return a new keyring of the given `type`,\n   * using the given `opts`. The keyring is built using the keyring builder\n   * registered for the given `type`.\n   *\n   * The internal keyring and keyring metadata arrays are updated with the new\n   * keyring as well.\n   *\n   * @param type - The type of keyring to add.\n   * @param data - Keyring initialization options.\n   * @returns The new keyring.\n   * @throws If the keyring includes duplicated accounts.\n   */\n  async #newKeyring(type: string, data?: unknown): Promise<EthKeyring> {\n    const { keyring, keyringV2, metadata } = await this.#createKeyring(\n      type,\n      data,\n    );\n\n    this.#keyrings.push({ keyring, keyringV2, metadata });\n\n    return keyring;\n  }\n\n  /**\n   * Instantiate, initialize and return a keyring of the given `type` using the\n   * given `opts`. The keyring is built using the keyring builder registered\n   * for the given `type`.\n   *\n   * The keyring might be new, or it might be restored from the vault. This\n   * function should only be called from `#newKeyring` or `#restoreKeyring`,\n   * for the \"new\" and \"restore\" cases respectively.\n   *\n   * The internal keyring and keyring metadata arrays are *not* updated, the\n   * caller is expected to update them.\n   *\n   * @param type - The type of keyring to add.\n   * @param data - Keyring initialization options.\n   * @param metadata - Keyring metadata if available.\n   * @returns The new keyring.\n   * @throws If the keyring includes duplicated accounts.\n   */\n  async #createKeyring(\n    type: string,\n    data?: unknown,\n    metadata?: KeyringMetadata,\n  ): Promise<KeyringEntry> {\n    this.#assertControllerMutexIsLocked();\n\n    const keyringMetadata = metadata ?? getDefaultKeyringMetadata();\n\n    const keyringBuilder = this.#getKeyringBuilderForType(type);\n    if (!keyringBuilder) {\n      throw new KeyringControllerError(\n        `${KeyringControllerErrorMessage.NoKeyringBuilder}. Keyring type: ${type}`,\n      );\n    }\n\n    const keyring = keyringBuilder();\n    if (data) {\n      // @ts-expect-error Enforce data type after updating clients\n      await keyring.deserialize(data);\n    }\n\n    if (keyring.init) {\n      await keyring.init();\n    }\n\n    if (\n      type === (KeyringTypes.hd as string) &&\n      (!isObject(data) || !data.mnemonic)\n    ) {\n      if (!keyring.generateRandomMnemonic) {\n        throw new KeyringControllerError(\n          KeyringControllerErrorMessage.UnsupportedGenerateRandomMnemonic,\n        );\n      }\n\n      // NOTE: Not all keyrings implement this method in a asynchronous-way. Using `await` for\n      // non-thenable will still be valid (despite not being really useful). It allows us to cover both\n      // cases and allow retro-compatibility too.\n      await keyring.generateRandomMnemonic();\n      await keyring.addAccounts(1);\n    }\n\n    // We now create the keyring V2 wrappers and store them in memory.\n    const keyringBuilderV2 = this.#getKeyringV2BuilderForType(type);\n    let keyringV2: KeyringV2 | undefined;\n    if (keyringBuilderV2) {\n      keyringV2 = keyringBuilderV2(keyring, keyringMetadata);\n    }\n\n    return { keyring, keyringV2, metadata: keyringMetadata };\n  }\n\n  /**\n   * Run the given operation and afterwards clean up any keyring whose\n   * account list transitioned from non-empty to empty during the operation.\n   *\n   * This mirrors the cleanup behavior of {@link KeyringController.removeAccount}\n   * for code paths where the consumer mutates a keyring directly via\n   * {@link KeyringController.withKeyring} or\n   * {@link KeyringController.withKeyringV2}: if the consumer drains the last\n   * account from a keyring, the now-empty keyring is removed from\n   * {@link KeyringController.#keyrings} and destroyed before persistence runs.\n   *\n   * Pre-existing empty keyrings (e.g. those created intentionally via\n   * {@link KeyringController.addNewKeyring} without subsequent account\n   * creation) are left alone, as are keyrings created within the operation\n   * itself (they are not part of the pre-operation snapshot). The primary\n   * keyring (see {@link KeyringController.#isPrimaryKeyring}) is also preserved\n   * unconditionally to keep `removeAccount`'s primary-keyring invariant intact.\n   *\n   * @param operation - The operation to execute.\n   * @returns The result of the operation.\n   * @template Result - The type of the value resolved by the operation.\n   */\n  async #cleanUpEmptiedKeyringsAfter<Result>(\n    operation: () => Promise<Result>,\n  ): Promise<Result> {\n    // Only the primary keyring exists, which is never auto-removed, so there\n    // is nothing to clean up regardless of what the operation does.\n    if (this.#keyrings.length <= 1) {\n      return operation();\n    }\n\n    const wasNonEmpty = new WeakSet<EthKeyring>();\n    await Promise.all(\n      this.#keyrings.map(async ({ keyring }) => {\n        if ((await keyring.getAccounts()).length > 0) {\n          wasNonEmpty.add(keyring);\n        }\n      }),\n    );\n\n    const result = await operation();\n\n    const isNowEmpty = await Promise.all(\n      this.#keyrings.map(\n        async ({ keyring }) => (await keyring.getAccounts()).length === 0,\n      ),\n    );\n\n    const emptied = this.#keyrings.filter(\n      (entry, index) =>\n        !this.#isPrimaryKeyring(entry, this.#keyrings) &&\n        wasNonEmpty.has(entry.keyring) &&\n        isNowEmpty[index],\n    );\n\n    if (emptied.length > 0) {\n      const removed = new Set(emptied);\n      this.#keyrings = this.#keyrings.filter((entry) => !removed.has(entry));\n      await Promise.all(\n        emptied.map(({ keyring, keyringV2 }) =>\n          this.#destroyKeyring(keyring, keyringV2),\n        ),\n      );\n    }\n\n    return result;\n  }\n\n  /**\n   * Remove all managed keyrings, destroying all their\n   * instances in memory.\n   */\n  async #clearKeyrings(): Promise<void> {\n    this.#assertControllerMutexIsLocked();\n    for (const { keyring, keyringV2 } of this.#keyrings) {\n      await this.#destroyKeyring(keyring, keyringV2);\n    }\n    this.#keyrings = [];\n    this.#unsupportedKeyrings = [];\n  }\n\n  /**\n   * Restore a Keyring from a provided serialized payload.\n   * On success, returns the resulting keyring instance.\n   *\n   * @param serialized - The serialized keyring.\n   * @returns The deserialized keyring or undefined if the keyring type is unsupported.\n   */\n  async #restoreKeyring(serialized: SerializedKeyring): Promise<\n    | (KeyringEntry & {\n        hasChanged: boolean;\n      })\n    | undefined\n  > {\n    this.#assertControllerMutexIsLocked();\n\n    try {\n      const { type, data, metadata: serializedMetadata } = serialized;\n\n      // Track if we need to trigger a vault update.\n      let hasChanged = false;\n\n      // If metadata is missing, assume the data is from an installation before we had\n      // keyring metadata.\n      let metadata = serializedMetadata;\n      if (!metadata) {\n        hasChanged = true;\n        metadata = getDefaultKeyringMetadata();\n      }\n\n      const oldState = JSON.stringify(data);\n      const { keyring, keyringV2 } = await this.#createKeyring(\n        type,\n        data,\n        metadata,\n      );\n      const newState = JSON.stringify(await keyring.serialize());\n      hasChanged ||= oldState !== newState;\n\n      await this.#assertNoDuplicateAccounts([keyring]);\n\n      // The keyring is added to the keyrings array only if it's successfully restored\n      // and the metadata is successfully added to the controller\n      this.#keyrings.push({\n        keyring,\n        keyringV2,\n        metadata,\n      });\n\n      return { keyring, keyringV2, metadata, hasChanged };\n    } catch (error) {\n      console.error(error);\n      this.#unsupportedKeyrings.push(serialized);\n      return undefined;\n    }\n  }\n\n  /**\n   * Destroy Keyring\n   *\n   * Some keyrings support a method called `destroy`, that destroys the\n   * keyring along with removing all its event listeners and, in some cases,\n   * clears the keyring bridge iframe from the DOM.\n   *\n   * @param keyring - The keyring to destroy.\n   * @param keyringV2 - The keyring v2 to destroy (if any).\n   */\n  async #destroyKeyring(\n    keyring: EthKeyring,\n    keyringV2?: KeyringV2,\n  ): Promise<void> {\n    await keyring.destroy?.();\n    if (keyringV2) {\n      await keyringV2.destroy?.();\n    }\n  }\n\n  /**\n   * Assert that there are no duplicate accounts in the keyrings.\n   *\n   * @param additionalKeyrings - Additional keyrings to include in the check.\n   * @throws If there are duplicate accounts.\n   */\n  async #assertNoDuplicateAccounts(\n    additionalKeyrings: EthKeyring[] = [],\n  ): Promise<void> {\n    const accounts = await this.#getAccountsFromKeyrings(additionalKeyrings);\n\n    if (new Set(accounts).size !== accounts.length) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.DuplicatedAccount,\n      );\n    }\n  }\n\n  /**\n   * Set the `isUnlocked` to true and notify listeners\n   * through the messenger.\n   *\n   * @fires KeyringController:unlock\n   */\n  #setUnlocked(): void {\n    this.#assertControllerMutexIsLocked();\n\n    this.update((state) => {\n      state.isUnlocked = true;\n    });\n    this.messenger.publish(`${name}:unlock`);\n  }\n\n  /**\n   * Assert that the controller is unlocked.\n   *\n   * @throws If the controller is locked.\n   */\n  #assertIsUnlocked(): void {\n    if (!this.state.isUnlocked) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.ControllerLocked,\n      );\n    }\n  }\n\n  /**\n   * Execute the given function after acquiring the controller lock\n   * and save the vault to state after it (only if needed), or rollback to their\n   * previous state in case of error.\n   *\n   * @param callback - The function to execute.\n   * @returns The result of the function.\n   */\n  async #persistOrRollback<Result>(\n    callback: MutuallyExclusiveCallback<Result>,\n  ): Promise<Result> {\n    return this.#withRollback(async ({ releaseLock }) => {\n      const oldState = JSON.stringify(await this.#getSessionState());\n      const callbackResult = await callback({ releaseLock });\n      const newState = JSON.stringify(await this.#getSessionState());\n\n      // State is committed only if the operation is successful and need to trigger a vault update.\n      if (oldState !== newState) {\n        await this.#updateVault();\n      }\n\n      return callbackResult;\n    });\n  }\n\n  /**\n   * Execute the given function after acquiring the controller lock\n   * and rollback keyrings and password states in case of error.\n   *\n   * @param callback - The function to execute atomically.\n   * @returns The result of the function.\n   */\n  async #withRollback<Result>(\n    callback: MutuallyExclusiveCallback<Result>,\n  ): Promise<Result> {\n    return this.#withControllerLock(async ({ releaseLock }) => {\n      const currentSerializedKeyrings = await this.#getSerializedKeyrings();\n      const currentEncryptionKey = cloneDeep(this.#encryptionKey);\n\n      try {\n        return await callback({ releaseLock });\n      } catch (error) {\n        // Keyrings and encryption credentials are restored to their previous state\n        this.#encryptionKey = currentEncryptionKey;\n        await this.#restoreSerializedKeyrings(currentSerializedKeyrings);\n\n        throw error;\n      }\n    });\n  }\n\n  /**\n   * Assert that the controller mutex is locked.\n   *\n   * @throws If the controller mutex is not locked.\n   */\n  #assertControllerMutexIsLocked(): void {\n    if (!this.#controllerOperationMutex.isLocked()) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.ControllerLockRequired,\n      );\n    }\n  }\n\n  /**\n   * Check whether the given keyring entry is the primary keyring.\n   *\n   * The primary keyring is the first HD keyring in the given list. Both the\n   * position (index 0) and the keyring type are checked so that the definition\n   * of \"primary\" lives in one place and does not rely on positional index\n   * alone, which could misidentify the primary keyring in the event of a bug.\n   *\n   * @param entry - The keyring entry to check.\n   * @param keyrings - The list of keyring entries `entry` belongs to.\n   * @returns Whether the entry is the primary keyring.\n   */\n  #isPrimaryKeyring(entry: KeyringEntry, keyrings: KeyringEntry[]): boolean {\n    return (\n      keyrings[0] === entry &&\n      entry.keyring.type === (KeyringTypes.hd as string)\n    );\n  }\n\n  /**\n   * Assert that the given keyring entry is not the primary HD keyring.\n   *\n   * @param entry - The keyring entry to check.\n   * @param keyrings - The current list of keyring entries.\n   * @throws If the entry is the primary keyring.\n   */\n  #assertNotRemovingPrimaryKeyring(\n    entry: KeyringEntry,\n    keyrings: KeyringEntry[],\n  ): void {\n    if (this.#isPrimaryKeyring(entry, keyrings)) {\n      throw new KeyringControllerError(\n        KeyringControllerErrorMessage.CannotRemovePrimaryKeyring,\n      );\n    }\n  }\n\n  /**\n   * Lock the controller mutex before executing the given function,\n   * and release it after the function is resolved or after an\n   * error is thrown.\n   *\n   * This wrapper ensures that each mutable operation that interacts with the\n   * controller and that changes its state is executed in a mutually exclusive way,\n   * preventing unsafe concurrent access that could lead to unpredictable behavior.\n   *\n   * @param callback - The function to execute while the controller mutex is locked.\n   * @returns The result of the function.\n   */\n  async #withControllerLock<Result>(\n    callback: MutuallyExclusiveCallback<Result>,\n  ): Promise<Result> {\n    return withLock(this.#controllerOperationMutex, callback);\n  }\n\n  /**\n   * Lock the vault mutex before executing the given function,\n   * and release it after the function is resolved or after an\n   * error is thrown.\n   *\n   * This ensures that each operation that interacts with the vault\n   * is executed in a mutually exclusive way.\n   *\n   * @param callback - The function to execute while the vault mutex is locked.\n   * @returns The result of the function.\n   */\n  async #withVaultLock<Result>(\n    callback: MutuallyExclusiveCallback<Result>,\n  ): Promise<Result> {\n    this.#assertControllerMutexIsLocked();\n\n    return withLock(this.#vaultOperationMutex, callback);\n  }\n}\n\n/**\n * Lock the given mutex before executing the given function,\n * and release it after the function is resolved or after an\n * error is thrown.\n *\n * @param mutex - The mutex to lock.\n * @param callback - The function to execute while the mutex is locked.\n * @returns The result of the function.\n */\nasync function withLock<Result>(\n  mutex: Mutex,\n  callback: MutuallyExclusiveCallback<Result>,\n): Promise<Result> {\n  const releaseLock = await mutex.acquire();\n\n  try {\n    return await callback({ releaseLock });\n  } finally {\n    releaseLock();\n  }\n}\n\n/**\n * Generate a new keyring metadata object.\n *\n * @returns Keyring metadata.\n */\nfunction getDefaultKeyringMetadata(): KeyringMetadata {\n  return { id: ulid(), name: '' };\n}\n\nexport default KeyringController;\n"]}