@metamask/accounts-controller 33.0.0 → 33.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [33.1.0]
11
+
12
+ ### Added
13
+
14
+ - Add two new controller state metadata properties: `includeInStateLogs` and `usedInUi` ([#6470](https://github.com/MetaMask/core/pull/6470))
15
+
16
+ ### Changed
17
+
18
+ - Bump `@metamask/base-controller` from `^8.1.0` to `^8.3.0` ([#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465))
19
+ - Bump `@metamask/keyring-api` from `^20.1.0` to `^21.0.0` ([#6560](https://github.com/MetaMask/core/pull/6560))
20
+ - Bump `@metamask/keyring-internal-api` from `^8.1.0` to `^9.0.0` ([#6560](https://github.com/MetaMask/core/pull/6560))
21
+ - Bump `@metamask/eth-snap-keyring` from `^16.1.0` to `^17.0.0` ([#6560](https://github.com/MetaMask/core/pull/6560))
22
+
23
+ ### Fixed
24
+
25
+ - Now publish `:accountAdded` before `:selectedAccountChange` on `KeyringController:stateChange` ([#6567](https://github.com/MetaMask/core/pull/6567))
26
+ - This was preventing the `AccountTreeController` to properly create its account group before trying to select it.
27
+
10
28
  ## [33.0.0]
11
29
 
12
30
  ### Changed
@@ -601,7 +619,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
601
619
 
602
620
  - Initial release ([#1637](https://github.com/MetaMask/core/pull/1637))
603
621
 
604
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@33.0.0...HEAD
622
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@33.1.0...HEAD
623
+ [33.1.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@33.0.0...@metamask/accounts-controller@33.1.0
605
624
  [33.0.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@32.0.2...@metamask/accounts-controller@33.0.0
606
625
  [32.0.2]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@32.0.1...@metamask/accounts-controller@32.0.2
607
626
  [32.0.1]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@32.0.0...@metamask/accounts-controller@32.0.1
@@ -18,8 +18,10 @@ const utils_2 = require("./utils.cjs");
18
18
  const controllerName = 'AccountsController';
19
19
  const accountsControllerMetadata = {
20
20
  internalAccounts: {
21
+ includeInStateLogs: true,
21
22
  persist: true,
22
23
  anonymous: false,
24
+ usedInUi: true,
23
25
  },
24
26
  };
25
27
  const defaultState = {
@@ -228,14 +230,8 @@ class AccountsController extends base_controller_1.BaseController {
228
230
  },
229
231
  };
230
232
  __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_update).call(this, (state) => {
231
- // FIXME: Using the state as-is cause the following error: "Type instantiation is excessively
232
- // deep and possibly infinite.ts(2589)" (https://github.com/MetaMask/utils/issues/168)
233
- // Using a type-cast workaround this error and is slightly better than using a @ts-expect-error
234
- // which sometimes fail when compiling locally.
235
- state.internalAccounts.accounts[account.id] =
236
- internalAccount;
237
- state.internalAccounts.selectedAccount =
238
- account.id;
233
+ state.internalAccounts.accounts[account.id] = internalAccount;
234
+ state.internalAccounts.selectedAccount = account.id;
239
235
  });
240
236
  this.messagingSystem.publish('AccountsController:accountRenamed', internalAccount);
241
237
  }
@@ -255,12 +251,7 @@ class AccountsController extends base_controller_1.BaseController {
255
251
  metadata: { ...account.metadata, ...metadata },
256
252
  };
257
253
  __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_update).call(this, (state) => {
258
- // FIXME: Using the state as-is cause the following error: "Type instantiation is excessively
259
- // deep and possibly infinite.ts(2589)" (https://github.com/MetaMask/utils/issues/168)
260
- // Using a type-cast workaround this error and is slightly better than using a @ts-expect-error
261
- // which sometimes fail when compiling locally.
262
- state.internalAccounts.accounts[accountId] =
263
- internalAccount;
254
+ state.internalAccounts.accounts[accountId] = internalAccount;
264
255
  });
265
256
  if (metadata.name) {
266
257
  this.messagingSystem.publish('AccountsController:accountRenamed', internalAccount);
@@ -535,17 +526,21 @@ _AccountsController_instances = new WeakSet(), _AccountsController_assertAccount
535
526
  }
536
527
  }
537
528
  }
529
+ },
530
+ // Will get executed after the update, but before re-selecting an account in case
531
+ // the current one is not valid anymore.
532
+ () => {
533
+ // Now publish events
534
+ for (const id of diff.removed) {
535
+ this.messagingSystem.publish('AccountsController:accountRemoved', id);
536
+ }
537
+ for (const account of diff.added) {
538
+ this.messagingSystem.publish('AccountsController:accountAdded', account);
539
+ }
538
540
  });
539
- // Now publish events
540
- for (const id of diff.removed) {
541
- this.messagingSystem.publish('AccountsController:accountRemoved', id);
542
- }
543
- for (const account of diff.added) {
544
- this.messagingSystem.publish('AccountsController:accountAdded', account);
545
- }
546
541
  // NOTE: Since we also track "updated" accounts with our patches, we could fire a new event
547
542
  // like `accountUpdated` (we would still need to check if anything really changed on the account).
548
- }, _AccountsController_update = function _AccountsController_update(callback) {
543
+ }, _AccountsController_update = function _AccountsController_update(callback, beforeAutoSelectAccount) {
549
544
  // The currently selected account might get deleted during the update, so keep track
550
545
  // of it before doing any change.
551
546
  const previouslySelectedAccount = this.state.internalAccounts.selectedAccount;
@@ -567,6 +562,8 @@ _AccountsController_instances = new WeakSet(), _AccountsController_assertAccount
567
562
  }
568
563
  }
569
564
  });
565
+ // We might want to do some pre-work before selecting a new account.
566
+ beforeAutoSelectAccount?.();
570
567
  // Now, we compare the newly selected account, and we send event if different.
571
568
  const { selectedAccount } = this.state.internalAccounts;
572
569
  if (selectedAccount && selectedAccount !== previouslySelectedAccount) {
@@ -1 +1 @@
1
- {"version":3,"file":"AccountsController.cjs","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+DAMmC;AACnC,iEAKoC;AAEpC,uDAM+B;AAE/B,qEAMsC;AAEtC,2DAA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BAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CACnC,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,+BAA+B,EAChD,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,IAAI,CAAC,CAC7C,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,sBAAsB,EACvC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CACpC,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,8BAA8B,EAC/C,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,CAC5C,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,+BAA+B,EAC/B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAC3B,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,0CAA0C,EAC1C,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CACtC,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type ExtractEventPayload,\n type RestrictedMessenger,\n BaseController,\n} from '@metamask/base-controller';\nimport {\n type SnapKeyringAccountAssetListUpdatedEvent,\n type SnapKeyringAccountBalancesUpdatedEvent,\n type SnapKeyringAccountTransactionsUpdatedEvent,\n SnapKeyring,\n} from '@metamask/eth-snap-keyring';\nimport type { KeyringAccountEntropyOptions } from '@metamask/keyring-api';\nimport {\n EthAccountType,\n EthMethod,\n EthScope,\n isEvmAccountType,\n KeyringAccountEntropyTypeOption,\n} from '@metamask/keyring-api';\nimport type { KeyringObject } from '@metamask/keyring-controller';\nimport {\n type KeyringControllerState,\n type KeyringControllerGetKeyringsByTypeAction,\n type KeyringControllerStateChangeEvent,\n type KeyringControllerGetStateAction,\n KeyringTypes,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { isScopeEqualToAny } from '@metamask/keyring-utils';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n SnapControllerState,\n SnapStateChange,\n} from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { type CaipChainId, isCaipChainId } from '@metamask/utils';\nimport type { WritableDraft } from 'immer/dist/internal.js';\nimport { cloneDeep } from 'lodash';\n\nimport type { MultichainNetworkControllerNetworkDidChangeEvent } from './types';\nimport type { HdSnapKeyringAccount } from './utils';\nimport {\n getEvmDerivationPathForIndex,\n getEvmGroupIndexFromAddressIndex,\n getUUIDFromAddressOfNormalAccount,\n isHdKeyringType,\n isHdSnapKeyringAccount,\n isSimpleKeyringType,\n isSnapKeyringType,\n keyringTypeToName,\n} from './utils';\n\nconst controllerName = 'AccountsController';\n\nexport type AccountId = string;\n\nexport type AccountsControllerState = {\n internalAccounts: {\n accounts: Record<AccountId, InternalAccount>;\n selectedAccount: string; // id of the selected account\n };\n};\n\nexport type AccountsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AccountsControllerState\n>;\n\nexport type AccountsControllerSetSelectedAccountAction = {\n type: `${typeof controllerName}:setSelectedAccount`;\n handler: AccountsController['setSelectedAccount'];\n};\n\nexport type AccountsControllerSetAccountNameAction = {\n type: `${typeof controllerName}:setAccountName`;\n handler: AccountsController['setAccountName'];\n};\n\nexport type AccountsControllerSetAccountNameAndSelectAccountAction = {\n type: `${typeof controllerName}:setAccountNameAndSelectAccount`;\n handler: AccountsController['setAccountNameAndSelectAccount'];\n};\n\nexport type AccountsControllerListAccountsAction = {\n type: `${typeof controllerName}:listAccounts`;\n handler: AccountsController['listAccounts'];\n};\n\nexport type AccountsControllerListMultichainAccountsAction = {\n type: `${typeof controllerName}:listMultichainAccounts`;\n handler: AccountsController['listMultichainAccounts'];\n};\n\nexport type AccountsControllerUpdateAccountsAction = {\n type: `${typeof controllerName}:updateAccounts`;\n handler: AccountsController['updateAccounts'];\n};\n\nexport type AccountsControllerGetSelectedAccountAction = {\n type: `${typeof controllerName}:getSelectedAccount`;\n handler: AccountsController['getSelectedAccount'];\n};\n\nexport type AccountsControllerGetSelectedMultichainAccountAction = {\n type: `${typeof controllerName}:getSelectedMultichainAccount`;\n handler: AccountsController['getSelectedMultichainAccount'];\n};\n\nexport type AccountsControllerGetAccountByAddressAction = {\n type: `${typeof controllerName}:getAccountByAddress`;\n handler: AccountsController['getAccountByAddress'];\n};\n\nexport type AccountsControllerGetNextAvailableAccountNameAction = {\n type: `${typeof controllerName}:getNextAvailableAccountName`;\n handler: AccountsController['getNextAvailableAccountName'];\n};\n\nexport type AccountsControllerGetAccountAction = {\n type: `${typeof controllerName}:getAccount`;\n handler: AccountsController['getAccount'];\n};\n\nexport type AccountsControllerUpdateAccountMetadataAction = {\n type: `${typeof controllerName}:updateAccountMetadata`;\n handler: AccountsController['updateAccountMetadata'];\n};\n\nexport type AllowedActions =\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetStateAction;\n\nexport type AccountsControllerActions =\n | AccountsControllerGetStateAction\n | AccountsControllerSetSelectedAccountAction\n | AccountsControllerListAccountsAction\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerSetAccountNameAction\n | AccountsControllerSetAccountNameAndSelectAccountAction\n | AccountsControllerUpdateAccountsAction\n | AccountsControllerGetAccountByAddressAction\n | AccountsControllerGetSelectedAccountAction\n | AccountsControllerGetNextAvailableAccountNameAction\n | AccountsControllerGetAccountAction\n | AccountsControllerGetSelectedMultichainAccountAction\n | AccountsControllerUpdateAccountMetadataAction;\n\nexport type AccountsControllerChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AccountsControllerState\n>;\n\nexport type AccountsControllerSelectedAccountChangeEvent = {\n type: `${typeof controllerName}:selectedAccountChange`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerSelectedEvmAccountChangeEvent = {\n type: `${typeof controllerName}:selectedEvmAccountChange`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountAddedEvent = {\n type: `${typeof controllerName}:accountAdded`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountRemovedEvent = {\n type: `${typeof controllerName}:accountRemoved`;\n payload: [AccountId];\n};\n\nexport type AccountsControllerAccountRenamedEvent = {\n type: `${typeof controllerName}:accountRenamed`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountBalancesUpdatesEvent = {\n type: `${typeof controllerName}:accountBalancesUpdated`;\n payload: SnapKeyringAccountBalancesUpdatedEvent['payload'];\n};\n\nexport type AccountsControllerAccountTransactionsUpdatedEvent = {\n type: `${typeof controllerName}:accountTransactionsUpdated`;\n payload: SnapKeyringAccountTransactionsUpdatedEvent['payload'];\n};\n\nexport type AccountsControllerAccountAssetListUpdatedEvent = {\n type: `${typeof controllerName}:accountAssetListUpdated`;\n payload: SnapKeyringAccountAssetListUpdatedEvent['payload'];\n};\n\nexport type AllowedEvents =\n | SnapStateChange\n | KeyringControllerStateChangeEvent\n | SnapKeyringAccountAssetListUpdatedEvent\n | SnapKeyringAccountBalancesUpdatedEvent\n | SnapKeyringAccountTransactionsUpdatedEvent\n | MultichainNetworkControllerNetworkDidChangeEvent;\n\nexport type AccountsControllerEvents =\n | AccountsControllerChangeEvent\n | AccountsControllerSelectedAccountChangeEvent\n | AccountsControllerSelectedEvmAccountChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountRenamedEvent\n | AccountsControllerAccountBalancesUpdatesEvent\n | AccountsControllerAccountTransactionsUpdatedEvent\n | AccountsControllerAccountAssetListUpdatedEvent;\n\nexport type AccountsControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n AccountsControllerActions | AllowedActions,\n AccountsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\nconst accountsControllerMetadata = {\n internalAccounts: {\n persist: true,\n anonymous: false,\n },\n};\n\nconst defaultState: AccountsControllerState = {\n internalAccounts: {\n accounts: {},\n selectedAccount: '',\n },\n};\n\nexport const EMPTY_ACCOUNT = {\n id: '',\n address: '',\n options: {},\n methods: [],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: '',\n keyring: {\n type: '',\n },\n importTime: 0,\n },\n};\n\n/**\n * Controller that manages internal accounts.\n * The accounts controller is responsible for creating and managing internal accounts.\n * It also provides convenience methods for accessing and updating the internal accounts.\n * The accounts controller also listens for keyring state changes and updates the internal accounts accordingly.\n * The accounts controller also listens for snap state changes and updates the internal accounts accordingly.\n *\n */\nexport class AccountsController extends BaseController<\n typeof controllerName,\n AccountsControllerState,\n AccountsControllerMessenger\n> {\n /**\n * Constructor for AccountsController.\n *\n * @param options - The controller options.\n * @param options.messenger - The messenger object.\n * @param options.state - Initial state to set on this controller\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: AccountsControllerMessenger;\n state: AccountsControllerState;\n }) {\n super({\n messenger,\n name: controllerName,\n metadata: accountsControllerMetadata,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.#subscribeToMessageEvents();\n this.#registerMessageHandlers();\n }\n\n /**\n * Returns the internal account object for the given account ID, if it exists.\n *\n * @param accountId - The ID of the account to retrieve.\n * @returns The internal account object, or undefined if the account does not exist.\n */\n getAccount(accountId: string): InternalAccount | undefined {\n return this.state.internalAccounts.accounts[accountId];\n }\n\n /**\n * Returns an array of all evm internal accounts.\n *\n * @returns An array of InternalAccount objects.\n */\n listAccounts(): InternalAccount[] {\n const accounts = Object.values(this.state.internalAccounts.accounts);\n return accounts.filter((account) => isEvmAccountType(account.type));\n }\n\n /**\n * Returns an array of all internal accounts.\n *\n * @param chainId - The chain ID.\n * @returns An array of InternalAccount objects.\n */\n listMultichainAccounts(chainId?: CaipChainId): InternalAccount[] {\n const accounts = Object.values(this.state.internalAccounts.accounts);\n if (!chainId) {\n return accounts;\n }\n\n if (!isCaipChainId(chainId)) {\n throw new Error(`Invalid CAIP-2 chain ID: ${String(chainId)}`);\n }\n\n return accounts.filter((account) =>\n isScopeEqualToAny(chainId, account.scopes),\n );\n }\n\n /**\n * Returns the internal account object for the given account ID.\n *\n * @param accountId - The ID of the account to retrieve.\n * @returns The internal account object.\n * @throws An error if the account ID is not found.\n */\n getAccountExpect(accountId: string): InternalAccount {\n const account = this.getAccount(accountId);\n if (account === undefined) {\n throw new Error(`Account Id \"${accountId}\" not found`);\n }\n return account;\n }\n\n /**\n * Returns the last selected EVM account.\n *\n * @returns The selected internal account.\n */\n getSelectedAccount(): InternalAccount {\n const {\n internalAccounts: { selectedAccount },\n } = this.state;\n\n // Edge case where the extension is setup but the srp is not yet created\n // certain ui elements will query the selected address before any accounts are created.\n if (selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n const account = this.getAccountExpect(selectedAccount);\n if (isEvmAccountType(account.type)) {\n return account;\n }\n\n const accounts = this.listAccounts();\n if (!accounts.length) {\n // ! Should never reach this.\n throw new Error('No EVM accounts');\n }\n\n // This will never be undefined because we have already checked if accounts.length is > 0\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.#getLastSelectedAccount(accounts)!;\n }\n\n /**\n * __WARNING The return value may be undefined if there isn't an account for that chain id.__\n *\n * Retrieves the last selected account by chain ID.\n *\n * @param chainId - The chain ID to filter the accounts.\n * @returns The last selected account compatible with the specified chain ID or undefined.\n */\n getSelectedMultichainAccount(\n chainId?: CaipChainId,\n ): InternalAccount | undefined {\n const {\n internalAccounts: { selectedAccount },\n } = this.state;\n\n // Edge case where the extension is setup but the srp is not yet created\n // certain ui elements will query the selected address before any accounts are created.\n if (selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n if (!chainId) {\n return this.getAccountExpect(selectedAccount);\n }\n\n const accounts = this.listMultichainAccounts(chainId);\n return this.#getLastSelectedAccount(accounts);\n }\n\n /**\n * Returns the account with the specified address.\n * ! This method will only return the first account that matches the address\n *\n * @param address - The address of the account to retrieve.\n * @returns The account with the specified address, or undefined if not found.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n return this.listMultichainAccounts().find(\n (account) => account.address.toLowerCase() === address.toLowerCase(),\n );\n }\n\n /**\n * Sets the selected account by its ID.\n *\n * @param accountId - The ID of the account to be selected.\n */\n setSelectedAccount(accountId: string): void {\n const account = this.getAccountExpect(accountId);\n\n if (this.state.internalAccounts.selectedAccount === account.id) {\n return;\n }\n\n this.#update((state) => {\n const { internalAccounts } = state;\n\n internalAccounts.accounts[account.id].metadata.lastSelected = Date.now();\n internalAccounts.selectedAccount = account.id;\n });\n }\n\n /**\n * Sets the name of the account with the given ID.\n *\n * @param accountId - The ID of the account to set the name for.\n * @param accountName - The new name for the account.\n * @throws An error if an account with the same name already exists.\n */\n setAccountName(accountId: string, accountName: string): void {\n // This will check for name uniqueness and fire the `accountRenamed` event\n // if the account has been renamed.\n this.updateAccountMetadata(accountId, {\n name: accountName,\n nameLastUpdatedAt: Date.now(),\n });\n }\n\n /**\n * Sets the name of the account with the given ID and select it.\n *\n * @param accountId - The ID of the account to set the name for and select.\n * @param accountName - The new name for the account.\n * @throws An error if an account with the same name already exists.\n */\n setAccountNameAndSelectAccount(accountId: string, accountName: string): void {\n const account = this.getAccountExpect(accountId);\n\n this.#assertAccountCanBeRenamed(account, accountName);\n\n const internalAccount = {\n ...account,\n metadata: {\n ...account.metadata,\n name: accountName,\n nameLastUpdatedAt: Date.now(),\n lastSelected: this.#getLastSelectedIndex(),\n },\n };\n\n this.#update((state) => {\n // FIXME: Using the state as-is cause the following error: \"Type instantiation is excessively\n // deep and possibly infinite.ts(2589)\" (https://github.com/MetaMask/utils/issues/168)\n // Using a type-cast workaround this error and is slightly better than using a @ts-expect-error\n // which sometimes fail when compiling locally.\n (state as AccountsControllerState).internalAccounts.accounts[account.id] =\n internalAccount;\n (state as AccountsControllerState).internalAccounts.selectedAccount =\n account.id;\n });\n\n this.messagingSystem.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\n }\n\n #assertAccountCanBeRenamed(account: InternalAccount, accountName: string) {\n if (\n this.listMultichainAccounts().find(\n (internalAccount) =>\n internalAccount.metadata.name === accountName &&\n internalAccount.id !== account.id,\n )\n ) {\n throw new Error('Account name already exists');\n }\n }\n\n /**\n * Updates the metadata of the account with the given ID.\n *\n * @param accountId - The ID of the account for which the metadata will be updated.\n * @param metadata - The new metadata for the account.\n */\n updateAccountMetadata(\n accountId: string,\n metadata: Partial<InternalAccount['metadata']>,\n ): void {\n const account = this.getAccountExpect(accountId);\n\n if (metadata.name) {\n this.#assertAccountCanBeRenamed(account, metadata.name);\n }\n\n const internalAccount = {\n ...account,\n metadata: { ...account.metadata, ...metadata },\n };\n\n this.#update((state) => {\n // FIXME: Using the state as-is cause the following error: \"Type instantiation is excessively\n // deep and possibly infinite.ts(2589)\" (https://github.com/MetaMask/utils/issues/168)\n // Using a type-cast workaround this error and is slightly better than using a @ts-expect-error\n // which sometimes fail when compiling locally.\n (state as AccountsControllerState).internalAccounts.accounts[accountId] =\n internalAccount;\n });\n\n if (metadata.name) {\n this.messagingSystem.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\n }\n }\n\n /**\n * Updates the internal accounts list by retrieving normal and snap accounts,\n * removing duplicates, and updating the metadata of each account.\n *\n * @returns A Promise that resolves when the accounts have been updated.\n */\n async updateAccounts(): Promise<void> {\n const keyringAccountIndexes = new Map<string, number>();\n\n const existingInternalAccounts = this.state.internalAccounts.accounts;\n const internalAccounts: AccountsControllerState['internalAccounts']['accounts'] =\n {};\n\n const { keyrings } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n for (const keyring of keyrings) {\n const keyringTypeName = keyringTypeToName(keyring.type);\n\n for (const address of keyring.accounts) {\n const internalAccount = this.#getInternalAccountFromAddressAndType(\n address,\n keyring,\n );\n\n // This should never really happen, but if for some reason we're not\n // able to get the Snap keyring reference, this would return an\n // undefined account.\n // So we just skip it, even though, this should not really happen.\n if (!internalAccount) {\n continue;\n }\n\n // Get current index for this keyring (we use human indexing, so start at 1).\n const keyringAccountIndex =\n keyringAccountIndexes.get(keyringTypeName) ?? 1;\n\n const existingAccount = existingInternalAccounts[internalAccount.id];\n internalAccounts[internalAccount.id] = {\n ...internalAccount,\n\n metadata: {\n ...internalAccount.metadata,\n\n // Re-use existing metadata if any.\n name:\n existingAccount?.metadata.name ??\n `${keyringTypeName} ${keyringAccountIndex}`,\n importTime: existingAccount?.metadata.importTime ?? Date.now(),\n lastSelected: existingAccount?.metadata.lastSelected ?? 0,\n },\n };\n\n // Increment the account index for this keyring.\n keyringAccountIndexes.set(keyringTypeName, keyringAccountIndex + 1);\n }\n }\n\n this.#update((state) => {\n state.internalAccounts.accounts = internalAccounts;\n });\n }\n\n /**\n * Loads the backup state of the accounts controller.\n *\n * @param backup - The backup state to load.\n */\n loadBackup(backup: AccountsControllerState): void {\n if (backup.internalAccounts) {\n this.update((currentState) => {\n currentState.internalAccounts = backup.internalAccounts;\n });\n }\n }\n\n /**\n * Gets an internal account representation for a non-Snap account.\n *\n * @param address - The address of the account.\n * @param keyring - The keyring object of the account.\n * @returns The generated internal account.\n */\n #getInternalAccountForNonSnapAccount(\n address: string,\n keyring: KeyringObject,\n ): InternalAccount {\n const id = getUUIDFromAddressOfNormalAccount(address);\n\n // We might have an account for this ID already, so we'll just re-use\n // the same metadata\n const account = this.getAccount(id);\n const metadata: InternalAccount['metadata'] = {\n name: account?.metadata.name ?? '',\n ...(account?.metadata.nameLastUpdatedAt\n ? {\n nameLastUpdatedAt: account?.metadata.nameLastUpdatedAt,\n }\n : {}),\n importTime: account?.metadata.importTime ?? Date.now(),\n lastSelected: account?.metadata.lastSelected ?? 0,\n keyring: {\n type: keyring.type,\n },\n };\n\n let options: InternalAccount['options'] = {};\n if (isHdKeyringType(keyring.type)) {\n // We need to find the account index from its HD keyring.\n const groupIndex = getEvmGroupIndexFromAddressIndex(keyring, address);\n\n // If for some reason, we cannot find this address, then the caller made a mistake\n // and it did not use the proper keyring object. For now, we do not fail and just\n // consider this account as \"simple account\".\n if (groupIndex !== undefined) {\n // NOTE: We are not using the `hdPath` from the associated keyring here and\n // getting the keyring instance here feels a bit overkill.\n // This will be naturally fixed once every keyring start using `KeyringAccount` and implement the keyring API.\n const derivationPath = getEvmDerivationPathForIndex(groupIndex);\n\n // Those are \"legacy options\" and they were used before `KeyringAccount` added\n // support for type options. We keep those temporarily until we update everything\n // to use the new typed options.\n const legacyOptions = {\n entropySource: keyring.metadata.id,\n derivationPath,\n groupIndex,\n };\n\n // New typed entropy options. This is required for multichain accounts.\n const entropyOptions: { entropy: KeyringAccountEntropyOptions } = {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: keyring.metadata.id,\n derivationPath,\n groupIndex,\n },\n };\n\n options = {\n ...legacyOptions,\n ...entropyOptions,\n };\n }\n }\n\n return {\n id,\n address,\n options,\n methods: [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n ],\n scopes: [EthScope.Eoa],\n type: EthAccountType.Eoa,\n metadata,\n };\n }\n\n /**\n * Get Snap keyring from the keyring controller.\n *\n * @returns The Snap keyring if available.\n */\n #getSnapKeyring(): SnapKeyring | undefined {\n const [snapKeyring] = this.messagingSystem.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n\n // Snap keyring is not available until the first account is created in the keyring\n // controller, so this might be undefined.\n return snapKeyring as SnapKeyring | undefined;\n }\n\n /**\n * Re-publish an account event.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @param payload - The event payload. The type of the parameters for each event handler must\n * match the type of this payload.\n * @template EventType - A Snap keyring event type.\n */\n #handleOnSnapKeyringAccountEvent<\n EventType extends AccountsControllerEvents['type'],\n >(\n event: EventType,\n ...payload: ExtractEventPayload<AccountsControllerEvents, EventType>\n ): void {\n this.messagingSystem.publish(event, ...payload);\n }\n\n /**\n * Handles changes in the keyring state, specifically when new accounts are added or removed.\n *\n * @param keyringState - The new state of the keyring controller.\n * @param keyringState.isUnlocked - True if the keyrings are unlocked, false otherwise.\n * @param keyringState.keyrings - List of all keyrings.\n */\n #handleOnKeyringStateChange({\n isUnlocked,\n keyrings,\n }: KeyringControllerState): void {\n // TODO: Change when accountAdded event is added to the keyring controller.\n\n // We check for keyrings length to be greater than 0 because the extension client may try execute\n // submit password twice and clear the keyring state.\n // https://github.com/MetaMask/KeyringController/blob/2d73a4deed8d013913f6ef0c9f5c0bb7c614f7d3/src/KeyringController.ts#L910\n if (!isUnlocked || keyrings.length === 0) {\n return;\n }\n\n // State patches.\n const generatePatch = () => {\n return {\n previous: {} as Record<string, InternalAccount>,\n added: [] as {\n address: string;\n keyring: KeyringObject;\n }[],\n updated: [] as InternalAccount[],\n removed: [] as InternalAccount[],\n };\n };\n const patches = {\n snap: generatePatch(),\n normal: generatePatch(),\n };\n\n // Gets the patch object based on the keyring type (since Snap accounts and other accounts\n // are handled differently).\n const patchOf = (type: string) => {\n if (isSnapKeyringType(type)) {\n return patches.snap;\n }\n return patches.normal;\n };\n\n // Create a map (with lower-cased addresses) of all existing accounts.\n for (const account of this.listMultichainAccounts()) {\n const address = account.address.toLowerCase();\n const patch = patchOf(account.metadata.keyring.type);\n\n patch.previous[address] = account;\n }\n\n // Go over all keyring changes and create patches out of it.\n const addresses = new Set<string>();\n for (const keyring of keyrings) {\n const patch = patchOf(keyring.type);\n\n for (const accountAddress of keyring.accounts) {\n // Lower-case address to use it in the `previous` map.\n const address = accountAddress.toLowerCase();\n const account = patch.previous[address];\n\n if (account) {\n // If the account exists before, this might be an update.\n patch.updated.push(account);\n } else {\n // Otherwise, that's a new account.\n patch.added.push({\n address,\n keyring,\n });\n }\n\n // Keep track of those address to check for removed accounts later.\n addresses.add(address);\n }\n }\n\n // We might have accounts associated with removed keyrings, so we iterate\n // over all previous known accounts and check against the keyring addresses.\n for (const patch of [patches.snap, patches.normal]) {\n for (const [address, account] of Object.entries(patch.previous)) {\n // If a previous address is not part of the new addesses, then it got removed.\n if (!addresses.has(address)) {\n patch.removed.push(account);\n }\n }\n }\n\n // Diff that we will use to publish events afterward.\n const diff = {\n removed: [] as string[],\n added: [] as InternalAccount[],\n };\n\n this.#update((state) => {\n const { internalAccounts } = state;\n\n for (const patch of [patches.snap, patches.normal]) {\n for (const account of patch.removed) {\n delete internalAccounts.accounts[account.id];\n\n diff.removed.push(account.id);\n }\n\n for (const added of patch.added) {\n const account = this.#getInternalAccountFromAddressAndType(\n added.address,\n added.keyring,\n );\n\n if (account) {\n // Re-compute the list of accounts everytime, so we can make sure new names\n // are also considered.\n const accounts = Object.values(\n internalAccounts.accounts,\n ) as InternalAccount[];\n\n // Get next account name available for this given keyring.\n const name = this.getNextAvailableAccountName(\n account.metadata.keyring.type,\n accounts,\n );\n\n // If it's the first account, we need to select it.\n const lastSelected =\n accounts.length === 0 ? this.#getLastSelectedIndex() : 0;\n\n internalAccounts.accounts[account.id] = {\n ...account,\n metadata: {\n ...account.metadata,\n name,\n importTime: Date.now(),\n lastSelected,\n },\n };\n\n diff.added.push(internalAccounts.accounts[account.id]);\n }\n }\n }\n });\n\n // Now publish events\n for (const id of diff.removed) {\n this.messagingSystem.publish('AccountsController:accountRemoved', id);\n }\n\n for (const account of diff.added) {\n this.messagingSystem.publish('AccountsController:accountAdded', account);\n }\n\n // NOTE: Since we also track \"updated\" accounts with our patches, we could fire a new event\n // like `accountUpdated` (we would still need to check if anything really changed on the account).\n }\n\n /**\n * Update the state and fixup the currently selected account.\n *\n * @param callback - Callback for updating state, passed a draft state object.\n */\n #update(callback: (state: WritableDraft<AccountsControllerState>) => void) {\n // The currently selected account might get deleted during the update, so keep track\n // of it before doing any change.\n const previouslySelectedAccount =\n this.state.internalAccounts.selectedAccount;\n\n this.update((state) => {\n callback(state);\n\n // If the account no longer exists (or none is selected), we need to re-select another one.\n const { internalAccounts } = state;\n if (!internalAccounts.accounts[previouslySelectedAccount]) {\n const accounts = Object.values(\n internalAccounts.accounts,\n ) as InternalAccount[];\n\n // Get the lastly selected account (according to the current accounts).\n const lastSelectedAccount = this.#getLastSelectedAccount(accounts);\n if (lastSelectedAccount) {\n internalAccounts.selectedAccount = lastSelectedAccount.id;\n internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n } else {\n // It will be undefined if there are no accounts.\n internalAccounts.selectedAccount = '';\n }\n }\n });\n\n // Now, we compare the newly selected account, and we send event if different.\n const { selectedAccount } = this.state.internalAccounts;\n if (selectedAccount && selectedAccount !== previouslySelectedAccount) {\n const account = this.getSelectedMultichainAccount();\n\n // The account should always be defined at this point, since we have already checked for\n // `selectedAccount` to be non-empty.\n if (account) {\n if (isEvmAccountType(account.type)) {\n this.messagingSystem.publish(\n 'AccountsController:selectedEvmAccountChange',\n account,\n );\n }\n this.messagingSystem.publish(\n 'AccountsController:selectedAccountChange',\n account,\n );\n }\n }\n }\n\n /**\n * Handles the change in SnapControllerState by updating the metadata of accounts that have a snap enabled.\n *\n * @param snapState - The new SnapControllerState.\n */\n #handleOnSnapStateChange(snapState: SnapControllerState) {\n // Only check if Snaps changed in status.\n const { snaps } = snapState;\n\n const accounts: { id: string; enabled: boolean }[] = [];\n for (const account of this.listMultichainAccounts()) {\n if (account.metadata.snap) {\n const snap = snaps[account.metadata.snap.id as SnapId];\n\n if (snap) {\n const enabled = snap.enabled && !snap.blocked;\n const metadata = account.metadata.snap;\n\n if (metadata.enabled !== enabled) {\n accounts.push({ id: account.id, enabled });\n }\n } else {\n // If Snap could not be found on the state, we consider it disabled.\n accounts.push({ id: account.id, enabled: false });\n }\n }\n }\n\n if (accounts.length > 0) {\n this.update((state) => {\n for (const { id, enabled } of accounts) {\n const account = state.internalAccounts.accounts[id];\n\n if (account.metadata.snap) {\n account.metadata.snap.enabled = enabled;\n }\n }\n });\n }\n }\n\n /**\n * Returns the list of accounts for a given keyring type.\n *\n * @param keyringType - The type of keyring.\n * @param accounts - Accounts to filter by keyring type.\n * @returns The list of accounts associcated with this keyring type.\n */\n #getAccountsByKeyringType(keyringType: string, accounts?: InternalAccount[]) {\n return (accounts ?? this.listMultichainAccounts()).filter(\n (internalAccount) => {\n // We do consider `hd` and `simple` keyrings to be of same type. So we check those 2 types\n // to group those accounts together!\n if (isHdKeyringType(keyringType) || isSimpleKeyringType(keyringType)) {\n return (\n isHdKeyringType(internalAccount.metadata.keyring.type) ||\n isSimpleKeyringType(internalAccount.metadata.keyring.type)\n );\n }\n\n return internalAccount.metadata.keyring.type === keyringType;\n },\n );\n }\n\n /**\n * Returns the last selected account from the given array of accounts.\n *\n * @param accounts - An array of InternalAccount objects.\n * @returns The InternalAccount object that was last selected, or undefined if the array is empty.\n */\n #getLastSelectedAccount(\n accounts: InternalAccount[],\n ): InternalAccount | undefined {\n const [accountToSelect] = accounts.sort((accountA, accountB) => {\n // sort by lastSelected descending\n return (\n (accountB.metadata.lastSelected ?? 0) -\n (accountA.metadata.lastSelected ?? 0)\n );\n });\n\n return accountToSelect;\n }\n\n /**\n * Returns the next account number for a given keyring type.\n *\n * @param keyringType - The type of keyring.\n * @param accounts - Existing accounts to check for the next available account number.\n * @returns An object containing the account prefix and index to use.\n */\n getNextAvailableAccountName(\n keyringType: string = KeyringTypes.hd,\n accounts?: InternalAccount[],\n ): string {\n const keyringName = keyringTypeToName(keyringType);\n const keyringAccounts = this.#getAccountsByKeyringType(\n keyringType,\n accounts,\n );\n const lastDefaultIndexUsedForKeyringType = keyringAccounts.reduce(\n (maxInternalAccountIndex, internalAccount) => {\n // We **DO NOT USE** `\\d+` here to only consider valid \"human\"\n // number (rounded decimal number)\n const match = new RegExp(`${keyringName} ([0-9]+)$`, 'u').exec(\n internalAccount.metadata.name,\n );\n\n if (match) {\n // Quoting `RegExp.exec` documentation:\n // > The returned array has the matched text as the first item, and then one item for\n // > each capturing group of the matched text.\n // So use `match[1]` to get the captured value\n const internalAccountIndex = parseInt(match[1], 10);\n return Math.max(maxInternalAccountIndex, internalAccountIndex);\n }\n\n return maxInternalAccountIndex;\n },\n 0,\n );\n\n const index = Math.max(\n keyringAccounts.length + 1,\n lastDefaultIndexUsedForKeyringType + 1,\n );\n\n return `${keyringName} ${index}`;\n }\n\n /**\n * Retrieves the index value for `metadata.lastSelected`.\n *\n * @returns The index value.\n */\n #getLastSelectedIndex() {\n // NOTE: For now we use the current date, since we know this value\n // will always be higher than any already selected account index.\n return Date.now();\n }\n\n /**\n * Get an internal account given an address and a keyring type.\n *\n * If the account is not a Snap Keyring account, generates an internal account for it and adds it to the controller.\n * If the account is a Snap Keyring account, retrieves the account from the keyring and adds it to the controller.\n *\n * @param address - The address of the new account.\n * @param keyring - The keyring object of that new account.\n * @returns The newly generated/retrieved internal account.\n */\n #getInternalAccountFromAddressAndType(\n address: string,\n keyring: KeyringObject,\n ): InternalAccount | undefined {\n if (isSnapKeyringType(keyring.type)) {\n const snapKeyring = this.#getSnapKeyring();\n\n // We need the Snap keyring to retrieve the account from its address.\n if (!snapKeyring) {\n return undefined;\n }\n\n // This might be undefined if the Snap deleted the account before\n // reaching that point.\n let account = snapKeyring.getAccountByAddress(address);\n if (account) {\n // We force the copy here, to avoid mutating the reference returned by the Snap keyring.\n account = cloneDeep(account);\n\n // MIGRATION: To avoid any existing Snap account migration, we are\n // just \"adding\" the new typed options that we need for multichain\n // accounts. Ultimately, we would need a real Snap account migrations\n // (being handled by each Snaps).\n if (isHdSnapKeyringAccount(account)) {\n const options: HdSnapKeyringAccount['options'] = {\n ...account.options,\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: account.options.entropySource,\n groupIndex: account.options.index,\n derivationPath: account.options.derivationPath,\n },\n };\n // Inject the new typed options to the internal account copy.\n account.options = options;\n }\n }\n\n return account;\n }\n\n return this.#getInternalAccountForNonSnapAccount(address, keyring);\n }\n\n /**\n * Handles the change in multichain network by updating the selected account.\n *\n * @param id - The EVM client ID or non-EVM chain ID that changed.\n */\n #handleOnMultichainNetworkDidChange(id: NetworkClientId | CaipChainId) {\n let accountId: string;\n\n // We only support non-EVM Caip chain IDs at the moment. Ex Solana and Bitcoin\n // MultichainNetworkController will handle throwing an error if the Caip chain ID is not supported\n if (isCaipChainId(id)) {\n // Update selected account to non evm account\n const lastSelectedNonEvmAccount = this.getSelectedMultichainAccount(id);\n // @ts-expect-error - This should never be undefined, otherwise it's a bug that should be handled\n accountId = lastSelectedNonEvmAccount.id;\n } else {\n // Update selected account to evm account\n const lastSelectedEvmAccount = this.getSelectedAccount();\n accountId = lastSelectedEvmAccount.id;\n }\n\n if (this.state.internalAccounts.selectedAccount === accountId) {\n return;\n }\n\n this.update((currentState) => {\n currentState.internalAccounts.accounts[accountId].metadata.lastSelected =\n Date.now();\n currentState.internalAccounts.selectedAccount = accountId;\n });\n\n // DO NOT publish AccountsController:setSelectedAccount to prevent circular listener loops\n }\n\n /**\n * Subscribes to message events.\n */\n #subscribeToMessageEvents() {\n this.messagingSystem.subscribe(\n 'SnapController:stateChange',\n (snapStateState) => this.#handleOnSnapStateChange(snapStateState),\n );\n\n this.messagingSystem.subscribe(\n 'KeyringController:stateChange',\n (keyringState) => this.#handleOnKeyringStateChange(keyringState),\n );\n\n this.messagingSystem.subscribe(\n 'SnapKeyring:accountAssetListUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountAssetListUpdated',\n snapAccountEvent,\n ),\n );\n\n this.messagingSystem.subscribe(\n 'SnapKeyring:accountBalancesUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountBalancesUpdated',\n snapAccountEvent,\n ),\n );\n\n this.messagingSystem.subscribe(\n 'SnapKeyring:accountTransactionsUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountTransactionsUpdated',\n snapAccountEvent,\n ),\n );\n\n // Handle account change when multichain network is changed\n this.messagingSystem.subscribe(\n 'MultichainNetworkController:networkDidChange',\n (id) => this.#handleOnMultichainNetworkDidChange(id),\n );\n }\n\n /**\n * Registers message handlers for the AccountsController.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setSelectedAccount`,\n this.setSelectedAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:listAccounts`,\n this.listAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:listMultichainAccounts`,\n this.listMultichainAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setAccountName`,\n this.setAccountName.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setAccountNameAndSelectAccount`,\n this.setAccountNameAndSelectAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateAccounts`,\n this.updateAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getSelectedAccount`,\n this.getSelectedAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getSelectedMultichainAccount`,\n this.getSelectedMultichainAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getAccountByAddress`,\n this.getAccountByAddress.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getNextAvailableAccountName`,\n this.getNextAvailableAccountName.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `AccountsController:getAccount`,\n this.getAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `AccountsController:updateAccountMetadata`,\n this.updateAccountMetadata.bind(this),\n );\n }\n}\n"]}
1
+ {"version":3,"file":"AccountsController.cjs","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+DAMmC;AACnC,iEAKoC;AAEpC,uDAM+B;AAE/B,qEAMsC;AAEtC,2DAA4D;AAO5D,2CAAkE;AAElE,mCAAmC;AAKnC,uCASiB;AAEjB,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAuK5C,MAAM,0BA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,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,+BAA+B,EAChD,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,IAAI,CAAC,CAC7C,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,sBAAsB,EACvC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CACpC,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,8BAA8B,EAC/C,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,CAC5C,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,+BAA+B,EAC/B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAC3B,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,0CAA0C,EAC1C,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CACtC,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type ExtractEventPayload,\n type RestrictedMessenger,\n BaseController,\n} from '@metamask/base-controller';\nimport {\n type SnapKeyringAccountAssetListUpdatedEvent,\n type SnapKeyringAccountBalancesUpdatedEvent,\n type SnapKeyringAccountTransactionsUpdatedEvent,\n SnapKeyring,\n} from '@metamask/eth-snap-keyring';\nimport type { KeyringAccountEntropyOptions } from '@metamask/keyring-api';\nimport {\n EthAccountType,\n EthMethod,\n EthScope,\n isEvmAccountType,\n KeyringAccountEntropyTypeOption,\n} from '@metamask/keyring-api';\nimport type { KeyringObject } from '@metamask/keyring-controller';\nimport {\n type KeyringControllerState,\n type KeyringControllerGetKeyringsByTypeAction,\n type KeyringControllerStateChangeEvent,\n type KeyringControllerGetStateAction,\n KeyringTypes,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { isScopeEqualToAny } from '@metamask/keyring-utils';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n SnapControllerState,\n SnapStateChange,\n} from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { type CaipChainId, isCaipChainId } from '@metamask/utils';\nimport type { WritableDraft } from 'immer/dist/internal.js';\nimport { cloneDeep } from 'lodash';\n\nimport type { MultichainNetworkControllerNetworkDidChangeEvent } from './types';\nimport type { AccountsControllerStrictState } from './typing';\nimport type { HdSnapKeyringAccount } from './utils';\nimport {\n getEvmDerivationPathForIndex,\n getEvmGroupIndexFromAddressIndex,\n getUUIDFromAddressOfNormalAccount,\n isHdKeyringType,\n isHdSnapKeyringAccount,\n isSimpleKeyringType,\n isSnapKeyringType,\n keyringTypeToName,\n} from './utils';\n\nconst controllerName = 'AccountsController';\n\nexport type AccountId = string;\n\nexport type AccountsControllerState = {\n internalAccounts: {\n accounts: Record<AccountId, InternalAccount>;\n selectedAccount: string; // id of the selected account\n };\n};\n\nexport type AccountsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AccountsControllerState\n>;\n\nexport type AccountsControllerSetSelectedAccountAction = {\n type: `${typeof controllerName}:setSelectedAccount`;\n handler: AccountsController['setSelectedAccount'];\n};\n\nexport type AccountsControllerSetAccountNameAction = {\n type: `${typeof controllerName}:setAccountName`;\n handler: AccountsController['setAccountName'];\n};\n\nexport type AccountsControllerSetAccountNameAndSelectAccountAction = {\n type: `${typeof controllerName}:setAccountNameAndSelectAccount`;\n handler: AccountsController['setAccountNameAndSelectAccount'];\n};\n\nexport type AccountsControllerListAccountsAction = {\n type: `${typeof controllerName}:listAccounts`;\n handler: AccountsController['listAccounts'];\n};\n\nexport type AccountsControllerListMultichainAccountsAction = {\n type: `${typeof controllerName}:listMultichainAccounts`;\n handler: AccountsController['listMultichainAccounts'];\n};\n\nexport type AccountsControllerUpdateAccountsAction = {\n type: `${typeof controllerName}:updateAccounts`;\n handler: AccountsController['updateAccounts'];\n};\n\nexport type AccountsControllerGetSelectedAccountAction = {\n type: `${typeof controllerName}:getSelectedAccount`;\n handler: AccountsController['getSelectedAccount'];\n};\n\nexport type AccountsControllerGetSelectedMultichainAccountAction = {\n type: `${typeof controllerName}:getSelectedMultichainAccount`;\n handler: AccountsController['getSelectedMultichainAccount'];\n};\n\nexport type AccountsControllerGetAccountByAddressAction = {\n type: `${typeof controllerName}:getAccountByAddress`;\n handler: AccountsController['getAccountByAddress'];\n};\n\nexport type AccountsControllerGetNextAvailableAccountNameAction = {\n type: `${typeof controllerName}:getNextAvailableAccountName`;\n handler: AccountsController['getNextAvailableAccountName'];\n};\n\nexport type AccountsControllerGetAccountAction = {\n type: `${typeof controllerName}:getAccount`;\n handler: AccountsController['getAccount'];\n};\n\nexport type AccountsControllerUpdateAccountMetadataAction = {\n type: `${typeof controllerName}:updateAccountMetadata`;\n handler: AccountsController['updateAccountMetadata'];\n};\n\nexport type AllowedActions =\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetStateAction;\n\nexport type AccountsControllerActions =\n | AccountsControllerGetStateAction\n | AccountsControllerSetSelectedAccountAction\n | AccountsControllerListAccountsAction\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerSetAccountNameAction\n | AccountsControllerSetAccountNameAndSelectAccountAction\n | AccountsControllerUpdateAccountsAction\n | AccountsControllerGetAccountByAddressAction\n | AccountsControllerGetSelectedAccountAction\n | AccountsControllerGetNextAvailableAccountNameAction\n | AccountsControllerGetAccountAction\n | AccountsControllerGetSelectedMultichainAccountAction\n | AccountsControllerUpdateAccountMetadataAction;\n\nexport type AccountsControllerChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AccountsControllerState\n>;\n\nexport type AccountsControllerSelectedAccountChangeEvent = {\n type: `${typeof controllerName}:selectedAccountChange`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerSelectedEvmAccountChangeEvent = {\n type: `${typeof controllerName}:selectedEvmAccountChange`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountAddedEvent = {\n type: `${typeof controllerName}:accountAdded`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountRemovedEvent = {\n type: `${typeof controllerName}:accountRemoved`;\n payload: [AccountId];\n};\n\nexport type AccountsControllerAccountRenamedEvent = {\n type: `${typeof controllerName}:accountRenamed`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountBalancesUpdatesEvent = {\n type: `${typeof controllerName}:accountBalancesUpdated`;\n payload: SnapKeyringAccountBalancesUpdatedEvent['payload'];\n};\n\nexport type AccountsControllerAccountTransactionsUpdatedEvent = {\n type: `${typeof controllerName}:accountTransactionsUpdated`;\n payload: SnapKeyringAccountTransactionsUpdatedEvent['payload'];\n};\n\nexport type AccountsControllerAccountAssetListUpdatedEvent = {\n type: `${typeof controllerName}:accountAssetListUpdated`;\n payload: SnapKeyringAccountAssetListUpdatedEvent['payload'];\n};\n\nexport type AllowedEvents =\n | SnapStateChange\n | KeyringControllerStateChangeEvent\n | SnapKeyringAccountAssetListUpdatedEvent\n | SnapKeyringAccountBalancesUpdatedEvent\n | SnapKeyringAccountTransactionsUpdatedEvent\n | MultichainNetworkControllerNetworkDidChangeEvent;\n\nexport type AccountsControllerEvents =\n | AccountsControllerChangeEvent\n | AccountsControllerSelectedAccountChangeEvent\n | AccountsControllerSelectedEvmAccountChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountRenamedEvent\n | AccountsControllerAccountBalancesUpdatesEvent\n | AccountsControllerAccountTransactionsUpdatedEvent\n | AccountsControllerAccountAssetListUpdatedEvent;\n\nexport type AccountsControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n AccountsControllerActions | AllowedActions,\n AccountsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\nconst accountsControllerMetadata = {\n internalAccounts: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n};\n\nconst defaultState: AccountsControllerState = {\n internalAccounts: {\n accounts: {},\n selectedAccount: '',\n },\n};\n\nexport const EMPTY_ACCOUNT = {\n id: '',\n address: '',\n options: {},\n methods: [],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: '',\n keyring: {\n type: '',\n },\n importTime: 0,\n },\n};\n\n/**\n * Controller that manages internal accounts.\n * The accounts controller is responsible for creating and managing internal accounts.\n * It also provides convenience methods for accessing and updating the internal accounts.\n * The accounts controller also listens for keyring state changes and updates the internal accounts accordingly.\n * The accounts controller also listens for snap state changes and updates the internal accounts accordingly.\n *\n */\nexport class AccountsController extends BaseController<\n typeof controllerName,\n AccountsControllerState,\n AccountsControllerMessenger\n> {\n /**\n * Constructor for AccountsController.\n *\n * @param options - The controller options.\n * @param options.messenger - The messenger object.\n * @param options.state - Initial state to set on this controller\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: AccountsControllerMessenger;\n state: AccountsControllerState;\n }) {\n super({\n messenger,\n name: controllerName,\n metadata: accountsControllerMetadata,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.#subscribeToMessageEvents();\n this.#registerMessageHandlers();\n }\n\n /**\n * Returns the internal account object for the given account ID, if it exists.\n *\n * @param accountId - The ID of the account to retrieve.\n * @returns The internal account object, or undefined if the account does not exist.\n */\n getAccount(accountId: string): InternalAccount | undefined {\n return this.state.internalAccounts.accounts[accountId];\n }\n\n /**\n * Returns an array of all evm internal accounts.\n *\n * @returns An array of InternalAccount objects.\n */\n listAccounts(): InternalAccount[] {\n const accounts = Object.values(this.state.internalAccounts.accounts);\n return accounts.filter((account) => isEvmAccountType(account.type));\n }\n\n /**\n * Returns an array of all internal accounts.\n *\n * @param chainId - The chain ID.\n * @returns An array of InternalAccount objects.\n */\n listMultichainAccounts(chainId?: CaipChainId): InternalAccount[] {\n const accounts = Object.values(this.state.internalAccounts.accounts);\n if (!chainId) {\n return accounts;\n }\n\n if (!isCaipChainId(chainId)) {\n throw new Error(`Invalid CAIP-2 chain ID: ${String(chainId)}`);\n }\n\n return accounts.filter((account) =>\n isScopeEqualToAny(chainId, account.scopes),\n );\n }\n\n /**\n * Returns the internal account object for the given account ID.\n *\n * @param accountId - The ID of the account to retrieve.\n * @returns The internal account object.\n * @throws An error if the account ID is not found.\n */\n getAccountExpect(accountId: string): InternalAccount {\n const account = this.getAccount(accountId);\n if (account === undefined) {\n throw new Error(`Account Id \"${accountId}\" not found`);\n }\n return account;\n }\n\n /**\n * Returns the last selected EVM account.\n *\n * @returns The selected internal account.\n */\n getSelectedAccount(): InternalAccount {\n const {\n internalAccounts: { selectedAccount },\n } = this.state;\n\n // Edge case where the extension is setup but the srp is not yet created\n // certain ui elements will query the selected address before any accounts are created.\n if (selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n const account = this.getAccountExpect(selectedAccount);\n if (isEvmAccountType(account.type)) {\n return account;\n }\n\n const accounts = this.listAccounts();\n if (!accounts.length) {\n // ! Should never reach this.\n throw new Error('No EVM accounts');\n }\n\n // This will never be undefined because we have already checked if accounts.length is > 0\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.#getLastSelectedAccount(accounts)!;\n }\n\n /**\n * __WARNING The return value may be undefined if there isn't an account for that chain id.__\n *\n * Retrieves the last selected account by chain ID.\n *\n * @param chainId - The chain ID to filter the accounts.\n * @returns The last selected account compatible with the specified chain ID or undefined.\n */\n getSelectedMultichainAccount(\n chainId?: CaipChainId,\n ): InternalAccount | undefined {\n const {\n internalAccounts: { selectedAccount },\n } = this.state;\n\n // Edge case where the extension is setup but the srp is not yet created\n // certain ui elements will query the selected address before any accounts are created.\n if (selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n if (!chainId) {\n return this.getAccountExpect(selectedAccount);\n }\n\n const accounts = this.listMultichainAccounts(chainId);\n return this.#getLastSelectedAccount(accounts);\n }\n\n /**\n * Returns the account with the specified address.\n * ! This method will only return the first account that matches the address\n *\n * @param address - The address of the account to retrieve.\n * @returns The account with the specified address, or undefined if not found.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n return this.listMultichainAccounts().find(\n (account) => account.address.toLowerCase() === address.toLowerCase(),\n );\n }\n\n /**\n * Sets the selected account by its ID.\n *\n * @param accountId - The ID of the account to be selected.\n */\n setSelectedAccount(accountId: string): void {\n const account = this.getAccountExpect(accountId);\n\n if (this.state.internalAccounts.selectedAccount === account.id) {\n return;\n }\n\n this.#update((state) => {\n const { internalAccounts } = state;\n\n internalAccounts.accounts[account.id].metadata.lastSelected = Date.now();\n internalAccounts.selectedAccount = account.id;\n });\n }\n\n /**\n * Sets the name of the account with the given ID.\n *\n * @param accountId - The ID of the account to set the name for.\n * @param accountName - The new name for the account.\n * @throws An error if an account with the same name already exists.\n */\n setAccountName(accountId: string, accountName: string): void {\n // This will check for name uniqueness and fire the `accountRenamed` event\n // if the account has been renamed.\n this.updateAccountMetadata(accountId, {\n name: accountName,\n nameLastUpdatedAt: Date.now(),\n });\n }\n\n /**\n * Sets the name of the account with the given ID and select it.\n *\n * @param accountId - The ID of the account to set the name for and select.\n * @param accountName - The new name for the account.\n * @throws An error if an account with the same name already exists.\n */\n setAccountNameAndSelectAccount(accountId: string, accountName: string): void {\n const account = this.getAccountExpect(accountId);\n\n this.#assertAccountCanBeRenamed(account, accountName);\n\n const internalAccount = {\n ...account,\n metadata: {\n ...account.metadata,\n name: accountName,\n nameLastUpdatedAt: Date.now(),\n lastSelected: this.#getLastSelectedIndex(),\n },\n };\n\n this.#update((state) => {\n state.internalAccounts.accounts[account.id] = internalAccount;\n state.internalAccounts.selectedAccount = account.id;\n });\n\n this.messagingSystem.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\n }\n\n #assertAccountCanBeRenamed(account: InternalAccount, accountName: string) {\n if (\n this.listMultichainAccounts().find(\n (internalAccount) =>\n internalAccount.metadata.name === accountName &&\n internalAccount.id !== account.id,\n )\n ) {\n throw new Error('Account name already exists');\n }\n }\n\n /**\n * Updates the metadata of the account with the given ID.\n *\n * @param accountId - The ID of the account for which the metadata will be updated.\n * @param metadata - The new metadata for the account.\n */\n updateAccountMetadata(\n accountId: string,\n metadata: Partial<InternalAccount['metadata']>,\n ): void {\n const account = this.getAccountExpect(accountId);\n\n if (metadata.name) {\n this.#assertAccountCanBeRenamed(account, metadata.name);\n }\n\n const internalAccount = {\n ...account,\n metadata: { ...account.metadata, ...metadata },\n };\n\n this.#update((state) => {\n state.internalAccounts.accounts[accountId] = internalAccount;\n });\n\n if (metadata.name) {\n this.messagingSystem.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\n }\n }\n\n /**\n * Updates the internal accounts list by retrieving normal and snap accounts,\n * removing duplicates, and updating the metadata of each account.\n *\n * @returns A Promise that resolves when the accounts have been updated.\n */\n async updateAccounts(): Promise<void> {\n const keyringAccountIndexes = new Map<string, number>();\n\n const existingInternalAccounts = this.state.internalAccounts.accounts;\n const internalAccounts: AccountsControllerState['internalAccounts']['accounts'] =\n {};\n\n const { keyrings } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n for (const keyring of keyrings) {\n const keyringTypeName = keyringTypeToName(keyring.type);\n\n for (const address of keyring.accounts) {\n const internalAccount = this.#getInternalAccountFromAddressAndType(\n address,\n keyring,\n );\n\n // This should never really happen, but if for some reason we're not\n // able to get the Snap keyring reference, this would return an\n // undefined account.\n // So we just skip it, even though, this should not really happen.\n if (!internalAccount) {\n continue;\n }\n\n // Get current index for this keyring (we use human indexing, so start at 1).\n const keyringAccountIndex =\n keyringAccountIndexes.get(keyringTypeName) ?? 1;\n\n const existingAccount = existingInternalAccounts[internalAccount.id];\n internalAccounts[internalAccount.id] = {\n ...internalAccount,\n\n metadata: {\n ...internalAccount.metadata,\n\n // Re-use existing metadata if any.\n name:\n existingAccount?.metadata.name ??\n `${keyringTypeName} ${keyringAccountIndex}`,\n importTime: existingAccount?.metadata.importTime ?? Date.now(),\n lastSelected: existingAccount?.metadata.lastSelected ?? 0,\n },\n };\n\n // Increment the account index for this keyring.\n keyringAccountIndexes.set(keyringTypeName, keyringAccountIndex + 1);\n }\n }\n\n this.#update((state) => {\n state.internalAccounts.accounts = internalAccounts;\n });\n }\n\n /**\n * Loads the backup state of the accounts controller.\n *\n * @param backup - The backup state to load.\n */\n loadBackup(backup: AccountsControllerState): void {\n if (backup.internalAccounts) {\n this.update(\n (currentState: WritableDraft<AccountsControllerStrictState>) => {\n currentState.internalAccounts = backup.internalAccounts;\n },\n );\n }\n }\n\n /**\n * Gets an internal account representation for a non-Snap account.\n *\n * @param address - The address of the account.\n * @param keyring - The keyring object of the account.\n * @returns The generated internal account.\n */\n #getInternalAccountForNonSnapAccount(\n address: string,\n keyring: KeyringObject,\n ): InternalAccount {\n const id = getUUIDFromAddressOfNormalAccount(address);\n\n // We might have an account for this ID already, so we'll just re-use\n // the same metadata\n const account = this.getAccount(id);\n const metadata: InternalAccount['metadata'] = {\n name: account?.metadata.name ?? '',\n ...(account?.metadata.nameLastUpdatedAt\n ? {\n nameLastUpdatedAt: account?.metadata.nameLastUpdatedAt,\n }\n : {}),\n importTime: account?.metadata.importTime ?? Date.now(),\n lastSelected: account?.metadata.lastSelected ?? 0,\n keyring: {\n type: keyring.type,\n },\n };\n\n let options: InternalAccount['options'] = {};\n if (isHdKeyringType(keyring.type)) {\n // We need to find the account index from its HD keyring.\n const groupIndex = getEvmGroupIndexFromAddressIndex(keyring, address);\n\n // If for some reason, we cannot find this address, then the caller made a mistake\n // and it did not use the proper keyring object. For now, we do not fail and just\n // consider this account as \"simple account\".\n if (groupIndex !== undefined) {\n // NOTE: We are not using the `hdPath` from the associated keyring here and\n // getting the keyring instance here feels a bit overkill.\n // This will be naturally fixed once every keyring start using `KeyringAccount` and implement the keyring API.\n const derivationPath = getEvmDerivationPathForIndex(groupIndex);\n\n // Those are \"legacy options\" and they were used before `KeyringAccount` added\n // support for type options. We keep those temporarily until we update everything\n // to use the new typed options.\n const legacyOptions = {\n entropySource: keyring.metadata.id,\n derivationPath,\n groupIndex,\n };\n\n // New typed entropy options. This is required for multichain accounts.\n const entropyOptions: { entropy: KeyringAccountEntropyOptions } = {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: keyring.metadata.id,\n derivationPath,\n groupIndex,\n },\n };\n\n options = {\n ...legacyOptions,\n ...entropyOptions,\n };\n }\n }\n\n return {\n id,\n address,\n options,\n methods: [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n ],\n scopes: [EthScope.Eoa],\n type: EthAccountType.Eoa,\n metadata,\n };\n }\n\n /**\n * Get Snap keyring from the keyring controller.\n *\n * @returns The Snap keyring if available.\n */\n #getSnapKeyring(): SnapKeyring | undefined {\n const [snapKeyring] = this.messagingSystem.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n\n // Snap keyring is not available until the first account is created in the keyring\n // controller, so this might be undefined.\n return snapKeyring as SnapKeyring | undefined;\n }\n\n /**\n * Re-publish an account event.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @param payload - The event payload. The type of the parameters for each event handler must\n * match the type of this payload.\n * @template EventType - A Snap keyring event type.\n */\n #handleOnSnapKeyringAccountEvent<\n EventType extends AccountsControllerEvents['type'],\n >(\n event: EventType,\n ...payload: ExtractEventPayload<AccountsControllerEvents, EventType>\n ): void {\n this.messagingSystem.publish(event, ...payload);\n }\n\n /**\n * Handles changes in the keyring state, specifically when new accounts are added or removed.\n *\n * @param keyringState - The new state of the keyring controller.\n * @param keyringState.isUnlocked - True if the keyrings are unlocked, false otherwise.\n * @param keyringState.keyrings - List of all keyrings.\n */\n #handleOnKeyringStateChange({\n isUnlocked,\n keyrings,\n }: KeyringControllerState): void {\n // TODO: Change when accountAdded event is added to the keyring controller.\n\n // We check for keyrings length to be greater than 0 because the extension client may try execute\n // submit password twice and clear the keyring state.\n // https://github.com/MetaMask/KeyringController/blob/2d73a4deed8d013913f6ef0c9f5c0bb7c614f7d3/src/KeyringController.ts#L910\n if (!isUnlocked || keyrings.length === 0) {\n return;\n }\n\n // State patches.\n const generatePatch = () => {\n return {\n previous: {} as Record<string, InternalAccount>,\n added: [] as {\n address: string;\n keyring: KeyringObject;\n }[],\n updated: [] as InternalAccount[],\n removed: [] as InternalAccount[],\n };\n };\n const patches = {\n snap: generatePatch(),\n normal: generatePatch(),\n };\n\n // Gets the patch object based on the keyring type (since Snap accounts and other accounts\n // are handled differently).\n const patchOf = (type: string) => {\n if (isSnapKeyringType(type)) {\n return patches.snap;\n }\n return patches.normal;\n };\n\n // Create a map (with lower-cased addresses) of all existing accounts.\n for (const account of this.listMultichainAccounts()) {\n const address = account.address.toLowerCase();\n const patch = patchOf(account.metadata.keyring.type);\n\n patch.previous[address] = account;\n }\n\n // Go over all keyring changes and create patches out of it.\n const addresses = new Set<string>();\n for (const keyring of keyrings) {\n const patch = patchOf(keyring.type);\n\n for (const accountAddress of keyring.accounts) {\n // Lower-case address to use it in the `previous` map.\n const address = accountAddress.toLowerCase();\n const account = patch.previous[address];\n\n if (account) {\n // If the account exists before, this might be an update.\n patch.updated.push(account);\n } else {\n // Otherwise, that's a new account.\n patch.added.push({\n address,\n keyring,\n });\n }\n\n // Keep track of those address to check for removed accounts later.\n addresses.add(address);\n }\n }\n\n // We might have accounts associated with removed keyrings, so we iterate\n // over all previous known accounts and check against the keyring addresses.\n for (const patch of [patches.snap, patches.normal]) {\n for (const [address, account] of Object.entries(patch.previous)) {\n // If a previous address is not part of the new addesses, then it got removed.\n if (!addresses.has(address)) {\n patch.removed.push(account);\n }\n }\n }\n\n // Diff that we will use to publish events afterward.\n const diff = {\n removed: [] as string[],\n added: [] as InternalAccount[],\n };\n\n this.#update(\n (state) => {\n const { internalAccounts } = state;\n\n for (const patch of [patches.snap, patches.normal]) {\n for (const account of patch.removed) {\n delete internalAccounts.accounts[account.id];\n\n diff.removed.push(account.id);\n }\n\n for (const added of patch.added) {\n const account = this.#getInternalAccountFromAddressAndType(\n added.address,\n added.keyring,\n );\n\n if (account) {\n // Re-compute the list of accounts everytime, so we can make sure new names\n // are also considered.\n const accounts = Object.values(\n internalAccounts.accounts,\n ) as InternalAccount[];\n\n // Get next account name available for this given keyring.\n const name = this.getNextAvailableAccountName(\n account.metadata.keyring.type,\n accounts,\n );\n\n // If it's the first account, we need to select it.\n const lastSelected =\n accounts.length === 0 ? this.#getLastSelectedIndex() : 0;\n\n internalAccounts.accounts[account.id] = {\n ...account,\n metadata: {\n ...account.metadata,\n name,\n importTime: Date.now(),\n lastSelected,\n },\n };\n\n diff.added.push(internalAccounts.accounts[account.id]);\n }\n }\n }\n },\n // Will get executed after the update, but before re-selecting an account in case\n // the current one is not valid anymore.\n () => {\n // Now publish events\n for (const id of diff.removed) {\n this.messagingSystem.publish('AccountsController:accountRemoved', id);\n }\n\n for (const account of diff.added) {\n this.messagingSystem.publish(\n 'AccountsController:accountAdded',\n account,\n );\n }\n },\n );\n\n // NOTE: Since we also track \"updated\" accounts with our patches, we could fire a new event\n // like `accountUpdated` (we would still need to check if anything really changed on the account).\n }\n\n /**\n * Update the state and fixup the currently selected account.\n *\n * @param callback - Callback for updating state, passed a draft state object.\n * @param beforeAutoSelectAccount - Callback to be executed before auto-selecting an account\n * if the current one is no longer available.\n */\n #update(\n callback: (state: WritableDraft<AccountsControllerStrictState>) => void,\n beforeAutoSelectAccount?: () => void,\n ) {\n // The currently selected account might get deleted during the update, so keep track\n // of it before doing any change.\n const previouslySelectedAccount =\n this.state.internalAccounts.selectedAccount;\n\n this.update((state: WritableDraft<AccountsControllerStrictState>) => {\n callback(state);\n\n // If the account no longer exists (or none is selected), we need to re-select another one.\n const { internalAccounts } = state;\n if (!internalAccounts.accounts[previouslySelectedAccount]) {\n const accounts = Object.values(\n internalAccounts.accounts,\n ) as InternalAccount[];\n\n // Get the lastly selected account (according to the current accounts).\n const lastSelectedAccount = this.#getLastSelectedAccount(accounts);\n if (lastSelectedAccount) {\n internalAccounts.selectedAccount = lastSelectedAccount.id;\n internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n } else {\n // It will be undefined if there are no accounts.\n internalAccounts.selectedAccount = '';\n }\n }\n });\n\n // We might want to do some pre-work before selecting a new account.\n beforeAutoSelectAccount?.();\n\n // Now, we compare the newly selected account, and we send event if different.\n const { selectedAccount } = this.state.internalAccounts;\n if (selectedAccount && selectedAccount !== previouslySelectedAccount) {\n const account = this.getSelectedMultichainAccount();\n\n // The account should always be defined at this point, since we have already checked for\n // `selectedAccount` to be non-empty.\n if (account) {\n if (isEvmAccountType(account.type)) {\n this.messagingSystem.publish(\n 'AccountsController:selectedEvmAccountChange',\n account,\n );\n }\n this.messagingSystem.publish(\n 'AccountsController:selectedAccountChange',\n account,\n );\n }\n }\n }\n\n /**\n * Handles the change in SnapControllerState by updating the metadata of accounts that have a snap enabled.\n *\n * @param snapState - The new SnapControllerState.\n */\n #handleOnSnapStateChange(snapState: SnapControllerState) {\n // Only check if Snaps changed in status.\n const { snaps } = snapState;\n\n const accounts: { id: string; enabled: boolean }[] = [];\n for (const account of this.listMultichainAccounts()) {\n if (account.metadata.snap) {\n const snap = snaps[account.metadata.snap.id as SnapId];\n\n if (snap) {\n const enabled = snap.enabled && !snap.blocked;\n const metadata = account.metadata.snap;\n\n if (metadata.enabled !== enabled) {\n accounts.push({ id: account.id, enabled });\n }\n } else {\n // If Snap could not be found on the state, we consider it disabled.\n accounts.push({ id: account.id, enabled: false });\n }\n }\n }\n\n if (accounts.length > 0) {\n this.update((state) => {\n for (const { id, enabled } of accounts) {\n const account = state.internalAccounts.accounts[id];\n\n if (account.metadata.snap) {\n account.metadata.snap.enabled = enabled;\n }\n }\n });\n }\n }\n\n /**\n * Returns the list of accounts for a given keyring type.\n *\n * @param keyringType - The type of keyring.\n * @param accounts - Accounts to filter by keyring type.\n * @returns The list of accounts associcated with this keyring type.\n */\n #getAccountsByKeyringType(keyringType: string, accounts?: InternalAccount[]) {\n return (accounts ?? this.listMultichainAccounts()).filter(\n (internalAccount) => {\n // We do consider `hd` and `simple` keyrings to be of same type. So we check those 2 types\n // to group those accounts together!\n if (isHdKeyringType(keyringType) || isSimpleKeyringType(keyringType)) {\n return (\n isHdKeyringType(internalAccount.metadata.keyring.type) ||\n isSimpleKeyringType(internalAccount.metadata.keyring.type)\n );\n }\n\n return internalAccount.metadata.keyring.type === keyringType;\n },\n );\n }\n\n /**\n * Returns the last selected account from the given array of accounts.\n *\n * @param accounts - An array of InternalAccount objects.\n * @returns The InternalAccount object that was last selected, or undefined if the array is empty.\n */\n #getLastSelectedAccount(\n accounts: InternalAccount[],\n ): InternalAccount | undefined {\n const [accountToSelect] = accounts.sort((accountA, accountB) => {\n // sort by lastSelected descending\n return (\n (accountB.metadata.lastSelected ?? 0) -\n (accountA.metadata.lastSelected ?? 0)\n );\n });\n\n return accountToSelect;\n }\n\n /**\n * Returns the next account number for a given keyring type.\n *\n * @param keyringType - The type of keyring.\n * @param accounts - Existing accounts to check for the next available account number.\n * @returns An object containing the account prefix and index to use.\n */\n getNextAvailableAccountName(\n keyringType: string = KeyringTypes.hd,\n accounts?: InternalAccount[],\n ): string {\n const keyringName = keyringTypeToName(keyringType);\n const keyringAccounts = this.#getAccountsByKeyringType(\n keyringType,\n accounts,\n );\n const lastDefaultIndexUsedForKeyringType = keyringAccounts.reduce(\n (maxInternalAccountIndex, internalAccount) => {\n // We **DO NOT USE** `\\d+` here to only consider valid \"human\"\n // number (rounded decimal number)\n const match = new RegExp(`${keyringName} ([0-9]+)$`, 'u').exec(\n internalAccount.metadata.name,\n );\n\n if (match) {\n // Quoting `RegExp.exec` documentation:\n // > The returned array has the matched text as the first item, and then one item for\n // > each capturing group of the matched text.\n // So use `match[1]` to get the captured value\n const internalAccountIndex = parseInt(match[1], 10);\n return Math.max(maxInternalAccountIndex, internalAccountIndex);\n }\n\n return maxInternalAccountIndex;\n },\n 0,\n );\n\n const index = Math.max(\n keyringAccounts.length + 1,\n lastDefaultIndexUsedForKeyringType + 1,\n );\n\n return `${keyringName} ${index}`;\n }\n\n /**\n * Retrieves the index value for `metadata.lastSelected`.\n *\n * @returns The index value.\n */\n #getLastSelectedIndex() {\n // NOTE: For now we use the current date, since we know this value\n // will always be higher than any already selected account index.\n return Date.now();\n }\n\n /**\n * Get an internal account given an address and a keyring type.\n *\n * If the account is not a Snap Keyring account, generates an internal account for it and adds it to the controller.\n * If the account is a Snap Keyring account, retrieves the account from the keyring and adds it to the controller.\n *\n * @param address - The address of the new account.\n * @param keyring - The keyring object of that new account.\n * @returns The newly generated/retrieved internal account.\n */\n #getInternalAccountFromAddressAndType(\n address: string,\n keyring: KeyringObject,\n ): InternalAccount | undefined {\n if (isSnapKeyringType(keyring.type)) {\n const snapKeyring = this.#getSnapKeyring();\n\n // We need the Snap keyring to retrieve the account from its address.\n if (!snapKeyring) {\n return undefined;\n }\n\n // This might be undefined if the Snap deleted the account before\n // reaching that point.\n let account = snapKeyring.getAccountByAddress(address);\n if (account) {\n // We force the copy here, to avoid mutating the reference returned by the Snap keyring.\n account = cloneDeep(account);\n\n // MIGRATION: To avoid any existing Snap account migration, we are\n // just \"adding\" the new typed options that we need for multichain\n // accounts. Ultimately, we would need a real Snap account migrations\n // (being handled by each Snaps).\n if (isHdSnapKeyringAccount(account)) {\n const options: HdSnapKeyringAccount['options'] = {\n ...account.options,\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: account.options.entropySource,\n groupIndex: account.options.index,\n derivationPath: account.options.derivationPath,\n },\n };\n // Inject the new typed options to the internal account copy.\n account.options = options;\n }\n }\n\n return account;\n }\n\n return this.#getInternalAccountForNonSnapAccount(address, keyring);\n }\n\n /**\n * Handles the change in multichain network by updating the selected account.\n *\n * @param id - The EVM client ID or non-EVM chain ID that changed.\n */\n #handleOnMultichainNetworkDidChange(id: NetworkClientId | CaipChainId) {\n let accountId: string;\n\n // We only support non-EVM Caip chain IDs at the moment. Ex Solana and Bitcoin\n // MultichainNetworkController will handle throwing an error if the Caip chain ID is not supported\n if (isCaipChainId(id)) {\n // Update selected account to non evm account\n const lastSelectedNonEvmAccount = this.getSelectedMultichainAccount(id);\n // @ts-expect-error - This should never be undefined, otherwise it's a bug that should be handled\n accountId = lastSelectedNonEvmAccount.id;\n } else {\n // Update selected account to evm account\n const lastSelectedEvmAccount = this.getSelectedAccount();\n accountId = lastSelectedEvmAccount.id;\n }\n\n if (this.state.internalAccounts.selectedAccount === accountId) {\n return;\n }\n\n this.update((currentState) => {\n currentState.internalAccounts.accounts[accountId].metadata.lastSelected =\n Date.now();\n currentState.internalAccounts.selectedAccount = accountId;\n });\n\n // DO NOT publish AccountsController:setSelectedAccount to prevent circular listener loops\n }\n\n /**\n * Subscribes to message events.\n */\n #subscribeToMessageEvents() {\n this.messagingSystem.subscribe(\n 'SnapController:stateChange',\n (snapStateState) => this.#handleOnSnapStateChange(snapStateState),\n );\n\n this.messagingSystem.subscribe(\n 'KeyringController:stateChange',\n (keyringState) => this.#handleOnKeyringStateChange(keyringState),\n );\n\n this.messagingSystem.subscribe(\n 'SnapKeyring:accountAssetListUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountAssetListUpdated',\n snapAccountEvent,\n ),\n );\n\n this.messagingSystem.subscribe(\n 'SnapKeyring:accountBalancesUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountBalancesUpdated',\n snapAccountEvent,\n ),\n );\n\n this.messagingSystem.subscribe(\n 'SnapKeyring:accountTransactionsUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountTransactionsUpdated',\n snapAccountEvent,\n ),\n );\n\n // Handle account change when multichain network is changed\n this.messagingSystem.subscribe(\n 'MultichainNetworkController:networkDidChange',\n (id) => this.#handleOnMultichainNetworkDidChange(id),\n );\n }\n\n /**\n * Registers message handlers for the AccountsController.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setSelectedAccount`,\n this.setSelectedAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:listAccounts`,\n this.listAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:listMultichainAccounts`,\n this.listMultichainAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setAccountName`,\n this.setAccountName.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setAccountNameAndSelectAccount`,\n this.setAccountNameAndSelectAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateAccounts`,\n this.updateAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getSelectedAccount`,\n this.getSelectedAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getSelectedMultichainAccount`,\n this.getSelectedMultichainAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getAccountByAddress`,\n this.getAccountByAddress.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getNextAvailableAccountName`,\n this.getNextAvailableAccountName.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `AccountsController:getAccount`,\n this.getAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `AccountsController:updateAccountMetadata`,\n this.updateAccountMetadata.bind(this),\n );\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"AccountsController.d.cts","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAE/B,KAAK,mBAAmB,EACxB,cAAc,EACf,kCAAkC;AACnC,OAAO,EACL,KAAK,uCAAuC,EAC5C,KAAK,sCAAsC,EAC3C,KAAK,0CAA0C,EAEhD,mCAAmC;AAEpC,OAAO,EACL,cAAc,EAEd,QAAQ,EAGT,8BAA8B;AAE/B,OAAO,EAEL,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C,SAAS,EAAE,MAAM,GAAG,IAAI;IAe3C;;;;;;OAMG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAS5D;;;;;;OAMG;IACH,8BAA8B,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAsC5E;;;;;OAKG;IACH,qBAAqB,CACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,GAC7C,IAAI;IAwBP;;;;;OAKG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAyDrC;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI;IAgcjD;;;;;;OAMG;IACH,2BAA2B,CACzB,WAAW,GAAE,MAAwB,EACrC,QAAQ,CAAC,EAAE,eAAe,EAAE,GAC3B,MAAM;CAuPV"}
@@ -16,8 +16,10 @@ import { getEvmDerivationPathForIndex, getEvmGroupIndexFromAddressIndex, getUUID
16
16
  const controllerName = 'AccountsController';
17
17
  const accountsControllerMetadata = {
18
18
  internalAccounts: {
19
+ includeInStateLogs: true,
19
20
  persist: true,
20
21
  anonymous: false,
22
+ usedInUi: true,
21
23
  },
22
24
  };
23
25
  const defaultState = {
@@ -226,14 +228,8 @@ export class AccountsController extends BaseController {
226
228
  },
227
229
  };
228
230
  __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_update).call(this, (state) => {
229
- // FIXME: Using the state as-is cause the following error: "Type instantiation is excessively
230
- // deep and possibly infinite.ts(2589)" (https://github.com/MetaMask/utils/issues/168)
231
- // Using a type-cast workaround this error and is slightly better than using a @ts-expect-error
232
- // which sometimes fail when compiling locally.
233
- state.internalAccounts.accounts[account.id] =
234
- internalAccount;
235
- state.internalAccounts.selectedAccount =
236
- account.id;
231
+ state.internalAccounts.accounts[account.id] = internalAccount;
232
+ state.internalAccounts.selectedAccount = account.id;
237
233
  });
238
234
  this.messagingSystem.publish('AccountsController:accountRenamed', internalAccount);
239
235
  }
@@ -253,12 +249,7 @@ export class AccountsController extends BaseController {
253
249
  metadata: { ...account.metadata, ...metadata },
254
250
  };
255
251
  __classPrivateFieldGet(this, _AccountsController_instances, "m", _AccountsController_update).call(this, (state) => {
256
- // FIXME: Using the state as-is cause the following error: "Type instantiation is excessively
257
- // deep and possibly infinite.ts(2589)" (https://github.com/MetaMask/utils/issues/168)
258
- // Using a type-cast workaround this error and is slightly better than using a @ts-expect-error
259
- // which sometimes fail when compiling locally.
260
- state.internalAccounts.accounts[accountId] =
261
- internalAccount;
252
+ state.internalAccounts.accounts[accountId] = internalAccount;
262
253
  });
263
254
  if (metadata.name) {
264
255
  this.messagingSystem.publish('AccountsController:accountRenamed', internalAccount);
@@ -532,17 +523,21 @@ _AccountsController_instances = new WeakSet(), _AccountsController_assertAccount
532
523
  }
533
524
  }
534
525
  }
526
+ },
527
+ // Will get executed after the update, but before re-selecting an account in case
528
+ // the current one is not valid anymore.
529
+ () => {
530
+ // Now publish events
531
+ for (const id of diff.removed) {
532
+ this.messagingSystem.publish('AccountsController:accountRemoved', id);
533
+ }
534
+ for (const account of diff.added) {
535
+ this.messagingSystem.publish('AccountsController:accountAdded', account);
536
+ }
535
537
  });
536
- // Now publish events
537
- for (const id of diff.removed) {
538
- this.messagingSystem.publish('AccountsController:accountRemoved', id);
539
- }
540
- for (const account of diff.added) {
541
- this.messagingSystem.publish('AccountsController:accountAdded', account);
542
- }
543
538
  // NOTE: Since we also track "updated" accounts with our patches, we could fire a new event
544
539
  // like `accountUpdated` (we would still need to check if anything really changed on the account).
545
- }, _AccountsController_update = function _AccountsController_update(callback) {
540
+ }, _AccountsController_update = function _AccountsController_update(callback, beforeAutoSelectAccount) {
546
541
  // The currently selected account might get deleted during the update, so keep track
547
542
  // of it before doing any change.
548
543
  const previouslySelectedAccount = this.state.internalAccounts.selectedAccount;
@@ -564,6 +559,8 @@ _AccountsController_instances = new WeakSet(), _AccountsController_assertAccount
564
559
  }
565
560
  }
566
561
  });
562
+ // We might want to do some pre-work before selecting a new account.
563
+ beforeAutoSelectAccount?.();
567
564
  // Now, we compare the newly selected account, and we send event if different.
568
565
  const { selectedAccount } = this.state.internalAccounts;
569
566
  if (selectedAccount && selectedAccount !== previouslySelectedAccount) {
@@ -1 +1 @@
1
- {"version":3,"file":"AccountsController.mjs","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAKL,cAAc,EACf,kCAAkC;AACnC,OAAO,EAIL,WAAW,EACZ,mCAAmC;AAEpC,OAAO,EACL,cAAc,EACd,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,+BAA+B,EAChC,8BAA8B;AAE/B,OAAO,EAKL,YAAY,EACb,qCAAqC;AAEtC,OAAO,EAAE,iBAAiB,EAAE,gCAAgC;AAO5D,OAAO,EAAoB,aAAa,EAAE,wBAAwB;;;AAMlE,OAAO,EACL,4BAA4B,EAC5B,gCAAgC,EAChC,iCAAiC,EACjC,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EAClB,oBAAgB;AAEjB,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAuK5C,MAAM,0BAA0B,GAAG;IACjC,gBAAgB,EAAE;QAChB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AAEF,MAAM,YAAY,GAA4B;IAC5C,gBAAgB,EAAE;QAChB,QAAQ,EAAE,EAAE;QACZ,eAAe,EAAE,EAAE;KACpB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,EAAE,EAAE,EAAE;IACN,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,cAAc,CAAC,GAAG;IACxB,MAAM,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC;IACtB,QAAQ,EAAE;QACR,I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AACJ,CAAC","sourcesContent":["import {\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type ExtractEventPayload,\n type RestrictedMessenger,\n BaseController,\n} from '@metamask/base-controller';\nimport {\n type SnapKeyringAccountAssetListUpdatedEvent,\n type SnapKeyringAccountBalancesUpdatedEvent,\n type SnapKeyringAccountTransactionsUpdatedEvent,\n SnapKeyring,\n} from '@metamask/eth-snap-keyring';\nimport type { KeyringAccountEntropyOptions } from '@metamask/keyring-api';\nimport {\n EthAccountType,\n EthMethod,\n EthScope,\n isEvmAccountType,\n KeyringAccountEntropyTypeOption,\n} from '@metamask/keyring-api';\nimport type { KeyringObject } from '@metamask/keyring-controller';\nimport {\n type KeyringControllerState,\n type KeyringControllerGetKeyringsByTypeAction,\n type KeyringControllerStateChangeEvent,\n type KeyringControllerGetStateAction,\n KeyringTypes,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { isScopeEqualToAny } from '@metamask/keyring-utils';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n SnapControllerState,\n SnapStateChange,\n} from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { type CaipChainId, isCaipChainId } from '@metamask/utils';\nimport type { WritableDraft } from 'immer/dist/internal.js';\nimport { cloneDeep } from 'lodash';\n\nimport type { MultichainNetworkControllerNetworkDidChangeEvent } from './types';\nimport type { HdSnapKeyringAccount } from './utils';\nimport {\n getEvmDerivationPathForIndex,\n getEvmGroupIndexFromAddressIndex,\n getUUIDFromAddressOfNormalAccount,\n isHdKeyringType,\n isHdSnapKeyringAccount,\n isSimpleKeyringType,\n isSnapKeyringType,\n keyringTypeToName,\n} from './utils';\n\nconst controllerName = 'AccountsController';\n\nexport type AccountId = string;\n\nexport type AccountsControllerState = {\n internalAccounts: {\n accounts: Record<AccountId, InternalAccount>;\n selectedAccount: string; // id of the selected account\n };\n};\n\nexport type AccountsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AccountsControllerState\n>;\n\nexport type AccountsControllerSetSelectedAccountAction = {\n type: `${typeof controllerName}:setSelectedAccount`;\n handler: AccountsController['setSelectedAccount'];\n};\n\nexport type AccountsControllerSetAccountNameAction = {\n type: `${typeof controllerName}:setAccountName`;\n handler: AccountsController['setAccountName'];\n};\n\nexport type AccountsControllerSetAccountNameAndSelectAccountAction = {\n type: `${typeof controllerName}:setAccountNameAndSelectAccount`;\n handler: AccountsController['setAccountNameAndSelectAccount'];\n};\n\nexport type AccountsControllerListAccountsAction = {\n type: `${typeof controllerName}:listAccounts`;\n handler: AccountsController['listAccounts'];\n};\n\nexport type AccountsControllerListMultichainAccountsAction = {\n type: `${typeof controllerName}:listMultichainAccounts`;\n handler: AccountsController['listMultichainAccounts'];\n};\n\nexport type AccountsControllerUpdateAccountsAction = {\n type: `${typeof controllerName}:updateAccounts`;\n handler: AccountsController['updateAccounts'];\n};\n\nexport type AccountsControllerGetSelectedAccountAction = {\n type: `${typeof controllerName}:getSelectedAccount`;\n handler: AccountsController['getSelectedAccount'];\n};\n\nexport type AccountsControllerGetSelectedMultichainAccountAction = {\n type: `${typeof controllerName}:getSelectedMultichainAccount`;\n handler: AccountsController['getSelectedMultichainAccount'];\n};\n\nexport type AccountsControllerGetAccountByAddressAction = {\n type: `${typeof controllerName}:getAccountByAddress`;\n handler: AccountsController['getAccountByAddress'];\n};\n\nexport type AccountsControllerGetNextAvailableAccountNameAction = {\n type: `${typeof controllerName}:getNextAvailableAccountName`;\n handler: AccountsController['getNextAvailableAccountName'];\n};\n\nexport type AccountsControllerGetAccountAction = {\n type: `${typeof controllerName}:getAccount`;\n handler: AccountsController['getAccount'];\n};\n\nexport type AccountsControllerUpdateAccountMetadataAction = {\n type: `${typeof controllerName}:updateAccountMetadata`;\n handler: AccountsController['updateAccountMetadata'];\n};\n\nexport type AllowedActions =\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetStateAction;\n\nexport type AccountsControllerActions =\n | AccountsControllerGetStateAction\n | AccountsControllerSetSelectedAccountAction\n | AccountsControllerListAccountsAction\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerSetAccountNameAction\n | AccountsControllerSetAccountNameAndSelectAccountAction\n | AccountsControllerUpdateAccountsAction\n | AccountsControllerGetAccountByAddressAction\n | AccountsControllerGetSelectedAccountAction\n | AccountsControllerGetNextAvailableAccountNameAction\n | AccountsControllerGetAccountAction\n | AccountsControllerGetSelectedMultichainAccountAction\n | AccountsControllerUpdateAccountMetadataAction;\n\nexport type AccountsControllerChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AccountsControllerState\n>;\n\nexport type AccountsControllerSelectedAccountChangeEvent = {\n type: `${typeof controllerName}:selectedAccountChange`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerSelectedEvmAccountChangeEvent = {\n type: `${typeof controllerName}:selectedEvmAccountChange`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountAddedEvent = {\n type: `${typeof controllerName}:accountAdded`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountRemovedEvent = {\n type: `${typeof controllerName}:accountRemoved`;\n payload: [AccountId];\n};\n\nexport type AccountsControllerAccountRenamedEvent = {\n type: `${typeof controllerName}:accountRenamed`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountBalancesUpdatesEvent = {\n type: `${typeof controllerName}:accountBalancesUpdated`;\n payload: SnapKeyringAccountBalancesUpdatedEvent['payload'];\n};\n\nexport type AccountsControllerAccountTransactionsUpdatedEvent = {\n type: `${typeof controllerName}:accountTransactionsUpdated`;\n payload: SnapKeyringAccountTransactionsUpdatedEvent['payload'];\n};\n\nexport type AccountsControllerAccountAssetListUpdatedEvent = {\n type: `${typeof controllerName}:accountAssetListUpdated`;\n payload: SnapKeyringAccountAssetListUpdatedEvent['payload'];\n};\n\nexport type AllowedEvents =\n | SnapStateChange\n | KeyringControllerStateChangeEvent\n | SnapKeyringAccountAssetListUpdatedEvent\n | SnapKeyringAccountBalancesUpdatedEvent\n | SnapKeyringAccountTransactionsUpdatedEvent\n | MultichainNetworkControllerNetworkDidChangeEvent;\n\nexport type AccountsControllerEvents =\n | AccountsControllerChangeEvent\n | AccountsControllerSelectedAccountChangeEvent\n | AccountsControllerSelectedEvmAccountChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountRenamedEvent\n | AccountsControllerAccountBalancesUpdatesEvent\n | AccountsControllerAccountTransactionsUpdatedEvent\n | AccountsControllerAccountAssetListUpdatedEvent;\n\nexport type AccountsControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n AccountsControllerActions | AllowedActions,\n AccountsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\nconst accountsControllerMetadata = {\n internalAccounts: {\n persist: true,\n anonymous: false,\n },\n};\n\nconst defaultState: AccountsControllerState = {\n internalAccounts: {\n accounts: {},\n selectedAccount: '',\n },\n};\n\nexport const EMPTY_ACCOUNT = {\n id: '',\n address: '',\n options: {},\n methods: [],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: '',\n keyring: {\n type: '',\n },\n importTime: 0,\n },\n};\n\n/**\n * Controller that manages internal accounts.\n * The accounts controller is responsible for creating and managing internal accounts.\n * It also provides convenience methods for accessing and updating the internal accounts.\n * The accounts controller also listens for keyring state changes and updates the internal accounts accordingly.\n * The accounts controller also listens for snap state changes and updates the internal accounts accordingly.\n *\n */\nexport class AccountsController extends BaseController<\n typeof controllerName,\n AccountsControllerState,\n AccountsControllerMessenger\n> {\n /**\n * Constructor for AccountsController.\n *\n * @param options - The controller options.\n * @param options.messenger - The messenger object.\n * @param options.state - Initial state to set on this controller\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: AccountsControllerMessenger;\n state: AccountsControllerState;\n }) {\n super({\n messenger,\n name: controllerName,\n metadata: accountsControllerMetadata,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.#subscribeToMessageEvents();\n this.#registerMessageHandlers();\n }\n\n /**\n * Returns the internal account object for the given account ID, if it exists.\n *\n * @param accountId - The ID of the account to retrieve.\n * @returns The internal account object, or undefined if the account does not exist.\n */\n getAccount(accountId: string): InternalAccount | undefined {\n return this.state.internalAccounts.accounts[accountId];\n }\n\n /**\n * Returns an array of all evm internal accounts.\n *\n * @returns An array of InternalAccount objects.\n */\n listAccounts(): InternalAccount[] {\n const accounts = Object.values(this.state.internalAccounts.accounts);\n return accounts.filter((account) => isEvmAccountType(account.type));\n }\n\n /**\n * Returns an array of all internal accounts.\n *\n * @param chainId - The chain ID.\n * @returns An array of InternalAccount objects.\n */\n listMultichainAccounts(chainId?: CaipChainId): InternalAccount[] {\n const accounts = Object.values(this.state.internalAccounts.accounts);\n if (!chainId) {\n return accounts;\n }\n\n if (!isCaipChainId(chainId)) {\n throw new Error(`Invalid CAIP-2 chain ID: ${String(chainId)}`);\n }\n\n return accounts.filter((account) =>\n isScopeEqualToAny(chainId, account.scopes),\n );\n }\n\n /**\n * Returns the internal account object for the given account ID.\n *\n * @param accountId - The ID of the account to retrieve.\n * @returns The internal account object.\n * @throws An error if the account ID is not found.\n */\n getAccountExpect(accountId: string): InternalAccount {\n const account = this.getAccount(accountId);\n if (account === undefined) {\n throw new Error(`Account Id \"${accountId}\" not found`);\n }\n return account;\n }\n\n /**\n * Returns the last selected EVM account.\n *\n * @returns The selected internal account.\n */\n getSelectedAccount(): InternalAccount {\n const {\n internalAccounts: { selectedAccount },\n } = this.state;\n\n // Edge case where the extension is setup but the srp is not yet created\n // certain ui elements will query the selected address before any accounts are created.\n if (selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n const account = this.getAccountExpect(selectedAccount);\n if (isEvmAccountType(account.type)) {\n return account;\n }\n\n const accounts = this.listAccounts();\n if (!accounts.length) {\n // ! Should never reach this.\n throw new Error('No EVM accounts');\n }\n\n // This will never be undefined because we have already checked if accounts.length is > 0\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.#getLastSelectedAccount(accounts)!;\n }\n\n /**\n * __WARNING The return value may be undefined if there isn't an account for that chain id.__\n *\n * Retrieves the last selected account by chain ID.\n *\n * @param chainId - The chain ID to filter the accounts.\n * @returns The last selected account compatible with the specified chain ID or undefined.\n */\n getSelectedMultichainAccount(\n chainId?: CaipChainId,\n ): InternalAccount | undefined {\n const {\n internalAccounts: { selectedAccount },\n } = this.state;\n\n // Edge case where the extension is setup but the srp is not yet created\n // certain ui elements will query the selected address before any accounts are created.\n if (selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n if (!chainId) {\n return this.getAccountExpect(selectedAccount);\n }\n\n const accounts = this.listMultichainAccounts(chainId);\n return this.#getLastSelectedAccount(accounts);\n }\n\n /**\n * Returns the account with the specified address.\n * ! This method will only return the first account that matches the address\n *\n * @param address - The address of the account to retrieve.\n * @returns The account with the specified address, or undefined if not found.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n return this.listMultichainAccounts().find(\n (account) => account.address.toLowerCase() === address.toLowerCase(),\n );\n }\n\n /**\n * Sets the selected account by its ID.\n *\n * @param accountId - The ID of the account to be selected.\n */\n setSelectedAccount(accountId: string): void {\n const account = this.getAccountExpect(accountId);\n\n if (this.state.internalAccounts.selectedAccount === account.id) {\n return;\n }\n\n this.#update((state) => {\n const { internalAccounts } = state;\n\n internalAccounts.accounts[account.id].metadata.lastSelected = Date.now();\n internalAccounts.selectedAccount = account.id;\n });\n }\n\n /**\n * Sets the name of the account with the given ID.\n *\n * @param accountId - The ID of the account to set the name for.\n * @param accountName - The new name for the account.\n * @throws An error if an account with the same name already exists.\n */\n setAccountName(accountId: string, accountName: string): void {\n // This will check for name uniqueness and fire the `accountRenamed` event\n // if the account has been renamed.\n this.updateAccountMetadata(accountId, {\n name: accountName,\n nameLastUpdatedAt: Date.now(),\n });\n }\n\n /**\n * Sets the name of the account with the given ID and select it.\n *\n * @param accountId - The ID of the account to set the name for and select.\n * @param accountName - The new name for the account.\n * @throws An error if an account with the same name already exists.\n */\n setAccountNameAndSelectAccount(accountId: string, accountName: string): void {\n const account = this.getAccountExpect(accountId);\n\n this.#assertAccountCanBeRenamed(account, accountName);\n\n const internalAccount = {\n ...account,\n metadata: {\n ...account.metadata,\n name: accountName,\n nameLastUpdatedAt: Date.now(),\n lastSelected: this.#getLastSelectedIndex(),\n },\n };\n\n this.#update((state) => {\n // FIXME: Using the state as-is cause the following error: \"Type instantiation is excessively\n // deep and possibly infinite.ts(2589)\" (https://github.com/MetaMask/utils/issues/168)\n // Using a type-cast workaround this error and is slightly better than using a @ts-expect-error\n // which sometimes fail when compiling locally.\n (state as AccountsControllerState).internalAccounts.accounts[account.id] =\n internalAccount;\n (state as AccountsControllerState).internalAccounts.selectedAccount =\n account.id;\n });\n\n this.messagingSystem.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\n }\n\n #assertAccountCanBeRenamed(account: InternalAccount, accountName: string) {\n if (\n this.listMultichainAccounts().find(\n (internalAccount) =>\n internalAccount.metadata.name === accountName &&\n internalAccount.id !== account.id,\n )\n ) {\n throw new Error('Account name already exists');\n }\n }\n\n /**\n * Updates the metadata of the account with the given ID.\n *\n * @param accountId - The ID of the account for which the metadata will be updated.\n * @param metadata - The new metadata for the account.\n */\n updateAccountMetadata(\n accountId: string,\n metadata: Partial<InternalAccount['metadata']>,\n ): void {\n const account = this.getAccountExpect(accountId);\n\n if (metadata.name) {\n this.#assertAccountCanBeRenamed(account, metadata.name);\n }\n\n const internalAccount = {\n ...account,\n metadata: { ...account.metadata, ...metadata },\n };\n\n this.#update((state) => {\n // FIXME: Using the state as-is cause the following error: \"Type instantiation is excessively\n // deep and possibly infinite.ts(2589)\" (https://github.com/MetaMask/utils/issues/168)\n // Using a type-cast workaround this error and is slightly better than using a @ts-expect-error\n // which sometimes fail when compiling locally.\n (state as AccountsControllerState).internalAccounts.accounts[accountId] =\n internalAccount;\n });\n\n if (metadata.name) {\n this.messagingSystem.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\n }\n }\n\n /**\n * Updates the internal accounts list by retrieving normal and snap accounts,\n * removing duplicates, and updating the metadata of each account.\n *\n * @returns A Promise that resolves when the accounts have been updated.\n */\n async updateAccounts(): Promise<void> {\n const keyringAccountIndexes = new Map<string, number>();\n\n const existingInternalAccounts = this.state.internalAccounts.accounts;\n const internalAccounts: AccountsControllerState['internalAccounts']['accounts'] =\n {};\n\n const { keyrings } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n for (const keyring of keyrings) {\n const keyringTypeName = keyringTypeToName(keyring.type);\n\n for (const address of keyring.accounts) {\n const internalAccount = this.#getInternalAccountFromAddressAndType(\n address,\n keyring,\n );\n\n // This should never really happen, but if for some reason we're not\n // able to get the Snap keyring reference, this would return an\n // undefined account.\n // So we just skip it, even though, this should not really happen.\n if (!internalAccount) {\n continue;\n }\n\n // Get current index for this keyring (we use human indexing, so start at 1).\n const keyringAccountIndex =\n keyringAccountIndexes.get(keyringTypeName) ?? 1;\n\n const existingAccount = existingInternalAccounts[internalAccount.id];\n internalAccounts[internalAccount.id] = {\n ...internalAccount,\n\n metadata: {\n ...internalAccount.metadata,\n\n // Re-use existing metadata if any.\n name:\n existingAccount?.metadata.name ??\n `${keyringTypeName} ${keyringAccountIndex}`,\n importTime: existingAccount?.metadata.importTime ?? Date.now(),\n lastSelected: existingAccount?.metadata.lastSelected ?? 0,\n },\n };\n\n // Increment the account index for this keyring.\n keyringAccountIndexes.set(keyringTypeName, keyringAccountIndex + 1);\n }\n }\n\n this.#update((state) => {\n state.internalAccounts.accounts = internalAccounts;\n });\n }\n\n /**\n * Loads the backup state of the accounts controller.\n *\n * @param backup - The backup state to load.\n */\n loadBackup(backup: AccountsControllerState): void {\n if (backup.internalAccounts) {\n this.update((currentState) => {\n currentState.internalAccounts = backup.internalAccounts;\n });\n }\n }\n\n /**\n * Gets an internal account representation for a non-Snap account.\n *\n * @param address - The address of the account.\n * @param keyring - The keyring object of the account.\n * @returns The generated internal account.\n */\n #getInternalAccountForNonSnapAccount(\n address: string,\n keyring: KeyringObject,\n ): InternalAccount {\n const id = getUUIDFromAddressOfNormalAccount(address);\n\n // We might have an account for this ID already, so we'll just re-use\n // the same metadata\n const account = this.getAccount(id);\n const metadata: InternalAccount['metadata'] = {\n name: account?.metadata.name ?? '',\n ...(account?.metadata.nameLastUpdatedAt\n ? {\n nameLastUpdatedAt: account?.metadata.nameLastUpdatedAt,\n }\n : {}),\n importTime: account?.metadata.importTime ?? Date.now(),\n lastSelected: account?.metadata.lastSelected ?? 0,\n keyring: {\n type: keyring.type,\n },\n };\n\n let options: InternalAccount['options'] = {};\n if (isHdKeyringType(keyring.type)) {\n // We need to find the account index from its HD keyring.\n const groupIndex = getEvmGroupIndexFromAddressIndex(keyring, address);\n\n // If for some reason, we cannot find this address, then the caller made a mistake\n // and it did not use the proper keyring object. For now, we do not fail and just\n // consider this account as \"simple account\".\n if (groupIndex !== undefined) {\n // NOTE: We are not using the `hdPath` from the associated keyring here and\n // getting the keyring instance here feels a bit overkill.\n // This will be naturally fixed once every keyring start using `KeyringAccount` and implement the keyring API.\n const derivationPath = getEvmDerivationPathForIndex(groupIndex);\n\n // Those are \"legacy options\" and they were used before `KeyringAccount` added\n // support for type options. We keep those temporarily until we update everything\n // to use the new typed options.\n const legacyOptions = {\n entropySource: keyring.metadata.id,\n derivationPath,\n groupIndex,\n };\n\n // New typed entropy options. This is required for multichain accounts.\n const entropyOptions: { entropy: KeyringAccountEntropyOptions } = {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: keyring.metadata.id,\n derivationPath,\n groupIndex,\n },\n };\n\n options = {\n ...legacyOptions,\n ...entropyOptions,\n };\n }\n }\n\n return {\n id,\n address,\n options,\n methods: [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n ],\n scopes: [EthScope.Eoa],\n type: EthAccountType.Eoa,\n metadata,\n };\n }\n\n /**\n * Get Snap keyring from the keyring controller.\n *\n * @returns The Snap keyring if available.\n */\n #getSnapKeyring(): SnapKeyring | undefined {\n const [snapKeyring] = this.messagingSystem.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n\n // Snap keyring is not available until the first account is created in the keyring\n // controller, so this might be undefined.\n return snapKeyring as SnapKeyring | undefined;\n }\n\n /**\n * Re-publish an account event.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @param payload - The event payload. The type of the parameters for each event handler must\n * match the type of this payload.\n * @template EventType - A Snap keyring event type.\n */\n #handleOnSnapKeyringAccountEvent<\n EventType extends AccountsControllerEvents['type'],\n >(\n event: EventType,\n ...payload: ExtractEventPayload<AccountsControllerEvents, EventType>\n ): void {\n this.messagingSystem.publish(event, ...payload);\n }\n\n /**\n * Handles changes in the keyring state, specifically when new accounts are added or removed.\n *\n * @param keyringState - The new state of the keyring controller.\n * @param keyringState.isUnlocked - True if the keyrings are unlocked, false otherwise.\n * @param keyringState.keyrings - List of all keyrings.\n */\n #handleOnKeyringStateChange({\n isUnlocked,\n keyrings,\n }: KeyringControllerState): void {\n // TODO: Change when accountAdded event is added to the keyring controller.\n\n // We check for keyrings length to be greater than 0 because the extension client may try execute\n // submit password twice and clear the keyring state.\n // https://github.com/MetaMask/KeyringController/blob/2d73a4deed8d013913f6ef0c9f5c0bb7c614f7d3/src/KeyringController.ts#L910\n if (!isUnlocked || keyrings.length === 0) {\n return;\n }\n\n // State patches.\n const generatePatch = () => {\n return {\n previous: {} as Record<string, InternalAccount>,\n added: [] as {\n address: string;\n keyring: KeyringObject;\n }[],\n updated: [] as InternalAccount[],\n removed: [] as InternalAccount[],\n };\n };\n const patches = {\n snap: generatePatch(),\n normal: generatePatch(),\n };\n\n // Gets the patch object based on the keyring type (since Snap accounts and other accounts\n // are handled differently).\n const patchOf = (type: string) => {\n if (isSnapKeyringType(type)) {\n return patches.snap;\n }\n return patches.normal;\n };\n\n // Create a map (with lower-cased addresses) of all existing accounts.\n for (const account of this.listMultichainAccounts()) {\n const address = account.address.toLowerCase();\n const patch = patchOf(account.metadata.keyring.type);\n\n patch.previous[address] = account;\n }\n\n // Go over all keyring changes and create patches out of it.\n const addresses = new Set<string>();\n for (const keyring of keyrings) {\n const patch = patchOf(keyring.type);\n\n for (const accountAddress of keyring.accounts) {\n // Lower-case address to use it in the `previous` map.\n const address = accountAddress.toLowerCase();\n const account = patch.previous[address];\n\n if (account) {\n // If the account exists before, this might be an update.\n patch.updated.push(account);\n } else {\n // Otherwise, that's a new account.\n patch.added.push({\n address,\n keyring,\n });\n }\n\n // Keep track of those address to check for removed accounts later.\n addresses.add(address);\n }\n }\n\n // We might have accounts associated with removed keyrings, so we iterate\n // over all previous known accounts and check against the keyring addresses.\n for (const patch of [patches.snap, patches.normal]) {\n for (const [address, account] of Object.entries(patch.previous)) {\n // If a previous address is not part of the new addesses, then it got removed.\n if (!addresses.has(address)) {\n patch.removed.push(account);\n }\n }\n }\n\n // Diff that we will use to publish events afterward.\n const diff = {\n removed: [] as string[],\n added: [] as InternalAccount[],\n };\n\n this.#update((state) => {\n const { internalAccounts } = state;\n\n for (const patch of [patches.snap, patches.normal]) {\n for (const account of patch.removed) {\n delete internalAccounts.accounts[account.id];\n\n diff.removed.push(account.id);\n }\n\n for (const added of patch.added) {\n const account = this.#getInternalAccountFromAddressAndType(\n added.address,\n added.keyring,\n );\n\n if (account) {\n // Re-compute the list of accounts everytime, so we can make sure new names\n // are also considered.\n const accounts = Object.values(\n internalAccounts.accounts,\n ) as InternalAccount[];\n\n // Get next account name available for this given keyring.\n const name = this.getNextAvailableAccountName(\n account.metadata.keyring.type,\n accounts,\n );\n\n // If it's the first account, we need to select it.\n const lastSelected =\n accounts.length === 0 ? this.#getLastSelectedIndex() : 0;\n\n internalAccounts.accounts[account.id] = {\n ...account,\n metadata: {\n ...account.metadata,\n name,\n importTime: Date.now(),\n lastSelected,\n },\n };\n\n diff.added.push(internalAccounts.accounts[account.id]);\n }\n }\n }\n });\n\n // Now publish events\n for (const id of diff.removed) {\n this.messagingSystem.publish('AccountsController:accountRemoved', id);\n }\n\n for (const account of diff.added) {\n this.messagingSystem.publish('AccountsController:accountAdded', account);\n }\n\n // NOTE: Since we also track \"updated\" accounts with our patches, we could fire a new event\n // like `accountUpdated` (we would still need to check if anything really changed on the account).\n }\n\n /**\n * Update the state and fixup the currently selected account.\n *\n * @param callback - Callback for updating state, passed a draft state object.\n */\n #update(callback: (state: WritableDraft<AccountsControllerState>) => void) {\n // The currently selected account might get deleted during the update, so keep track\n // of it before doing any change.\n const previouslySelectedAccount =\n this.state.internalAccounts.selectedAccount;\n\n this.update((state) => {\n callback(state);\n\n // If the account no longer exists (or none is selected), we need to re-select another one.\n const { internalAccounts } = state;\n if (!internalAccounts.accounts[previouslySelectedAccount]) {\n const accounts = Object.values(\n internalAccounts.accounts,\n ) as InternalAccount[];\n\n // Get the lastly selected account (according to the current accounts).\n const lastSelectedAccount = this.#getLastSelectedAccount(accounts);\n if (lastSelectedAccount) {\n internalAccounts.selectedAccount = lastSelectedAccount.id;\n internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n } else {\n // It will be undefined if there are no accounts.\n internalAccounts.selectedAccount = '';\n }\n }\n });\n\n // Now, we compare the newly selected account, and we send event if different.\n const { selectedAccount } = this.state.internalAccounts;\n if (selectedAccount && selectedAccount !== previouslySelectedAccount) {\n const account = this.getSelectedMultichainAccount();\n\n // The account should always be defined at this point, since we have already checked for\n // `selectedAccount` to be non-empty.\n if (account) {\n if (isEvmAccountType(account.type)) {\n this.messagingSystem.publish(\n 'AccountsController:selectedEvmAccountChange',\n account,\n );\n }\n this.messagingSystem.publish(\n 'AccountsController:selectedAccountChange',\n account,\n );\n }\n }\n }\n\n /**\n * Handles the change in SnapControllerState by updating the metadata of accounts that have a snap enabled.\n *\n * @param snapState - The new SnapControllerState.\n */\n #handleOnSnapStateChange(snapState: SnapControllerState) {\n // Only check if Snaps changed in status.\n const { snaps } = snapState;\n\n const accounts: { id: string; enabled: boolean }[] = [];\n for (const account of this.listMultichainAccounts()) {\n if (account.metadata.snap) {\n const snap = snaps[account.metadata.snap.id as SnapId];\n\n if (snap) {\n const enabled = snap.enabled && !snap.blocked;\n const metadata = account.metadata.snap;\n\n if (metadata.enabled !== enabled) {\n accounts.push({ id: account.id, enabled });\n }\n } else {\n // If Snap could not be found on the state, we consider it disabled.\n accounts.push({ id: account.id, enabled: false });\n }\n }\n }\n\n if (accounts.length > 0) {\n this.update((state) => {\n for (const { id, enabled } of accounts) {\n const account = state.internalAccounts.accounts[id];\n\n if (account.metadata.snap) {\n account.metadata.snap.enabled = enabled;\n }\n }\n });\n }\n }\n\n /**\n * Returns the list of accounts for a given keyring type.\n *\n * @param keyringType - The type of keyring.\n * @param accounts - Accounts to filter by keyring type.\n * @returns The list of accounts associcated with this keyring type.\n */\n #getAccountsByKeyringType(keyringType: string, accounts?: InternalAccount[]) {\n return (accounts ?? this.listMultichainAccounts()).filter(\n (internalAccount) => {\n // We do consider `hd` and `simple` keyrings to be of same type. So we check those 2 types\n // to group those accounts together!\n if (isHdKeyringType(keyringType) || isSimpleKeyringType(keyringType)) {\n return (\n isHdKeyringType(internalAccount.metadata.keyring.type) ||\n isSimpleKeyringType(internalAccount.metadata.keyring.type)\n );\n }\n\n return internalAccount.metadata.keyring.type === keyringType;\n },\n );\n }\n\n /**\n * Returns the last selected account from the given array of accounts.\n *\n * @param accounts - An array of InternalAccount objects.\n * @returns The InternalAccount object that was last selected, or undefined if the array is empty.\n */\n #getLastSelectedAccount(\n accounts: InternalAccount[],\n ): InternalAccount | undefined {\n const [accountToSelect] = accounts.sort((accountA, accountB) => {\n // sort by lastSelected descending\n return (\n (accountB.metadata.lastSelected ?? 0) -\n (accountA.metadata.lastSelected ?? 0)\n );\n });\n\n return accountToSelect;\n }\n\n /**\n * Returns the next account number for a given keyring type.\n *\n * @param keyringType - The type of keyring.\n * @param accounts - Existing accounts to check for the next available account number.\n * @returns An object containing the account prefix and index to use.\n */\n getNextAvailableAccountName(\n keyringType: string = KeyringTypes.hd,\n accounts?: InternalAccount[],\n ): string {\n const keyringName = keyringTypeToName(keyringType);\n const keyringAccounts = this.#getAccountsByKeyringType(\n keyringType,\n accounts,\n );\n const lastDefaultIndexUsedForKeyringType = keyringAccounts.reduce(\n (maxInternalAccountIndex, internalAccount) => {\n // We **DO NOT USE** `\\d+` here to only consider valid \"human\"\n // number (rounded decimal number)\n const match = new RegExp(`${keyringName} ([0-9]+)$`, 'u').exec(\n internalAccount.metadata.name,\n );\n\n if (match) {\n // Quoting `RegExp.exec` documentation:\n // > The returned array has the matched text as the first item, and then one item for\n // > each capturing group of the matched text.\n // So use `match[1]` to get the captured value\n const internalAccountIndex = parseInt(match[1], 10);\n return Math.max(maxInternalAccountIndex, internalAccountIndex);\n }\n\n return maxInternalAccountIndex;\n },\n 0,\n );\n\n const index = Math.max(\n keyringAccounts.length + 1,\n lastDefaultIndexUsedForKeyringType + 1,\n );\n\n return `${keyringName} ${index}`;\n }\n\n /**\n * Retrieves the index value for `metadata.lastSelected`.\n *\n * @returns The index value.\n */\n #getLastSelectedIndex() {\n // NOTE: For now we use the current date, since we know this value\n // will always be higher than any already selected account index.\n return Date.now();\n }\n\n /**\n * Get an internal account given an address and a keyring type.\n *\n * If the account is not a Snap Keyring account, generates an internal account for it and adds it to the controller.\n * If the account is a Snap Keyring account, retrieves the account from the keyring and adds it to the controller.\n *\n * @param address - The address of the new account.\n * @param keyring - The keyring object of that new account.\n * @returns The newly generated/retrieved internal account.\n */\n #getInternalAccountFromAddressAndType(\n address: string,\n keyring: KeyringObject,\n ): InternalAccount | undefined {\n if (isSnapKeyringType(keyring.type)) {\n const snapKeyring = this.#getSnapKeyring();\n\n // We need the Snap keyring to retrieve the account from its address.\n if (!snapKeyring) {\n return undefined;\n }\n\n // This might be undefined if the Snap deleted the account before\n // reaching that point.\n let account = snapKeyring.getAccountByAddress(address);\n if (account) {\n // We force the copy here, to avoid mutating the reference returned by the Snap keyring.\n account = cloneDeep(account);\n\n // MIGRATION: To avoid any existing Snap account migration, we are\n // just \"adding\" the new typed options that we need for multichain\n // accounts. Ultimately, we would need a real Snap account migrations\n // (being handled by each Snaps).\n if (isHdSnapKeyringAccount(account)) {\n const options: HdSnapKeyringAccount['options'] = {\n ...account.options,\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: account.options.entropySource,\n groupIndex: account.options.index,\n derivationPath: account.options.derivationPath,\n },\n };\n // Inject the new typed options to the internal account copy.\n account.options = options;\n }\n }\n\n return account;\n }\n\n return this.#getInternalAccountForNonSnapAccount(address, keyring);\n }\n\n /**\n * Handles the change in multichain network by updating the selected account.\n *\n * @param id - The EVM client ID or non-EVM chain ID that changed.\n */\n #handleOnMultichainNetworkDidChange(id: NetworkClientId | CaipChainId) {\n let accountId: string;\n\n // We only support non-EVM Caip chain IDs at the moment. Ex Solana and Bitcoin\n // MultichainNetworkController will handle throwing an error if the Caip chain ID is not supported\n if (isCaipChainId(id)) {\n // Update selected account to non evm account\n const lastSelectedNonEvmAccount = this.getSelectedMultichainAccount(id);\n // @ts-expect-error - This should never be undefined, otherwise it's a bug that should be handled\n accountId = lastSelectedNonEvmAccount.id;\n } else {\n // Update selected account to evm account\n const lastSelectedEvmAccount = this.getSelectedAccount();\n accountId = lastSelectedEvmAccount.id;\n }\n\n if (this.state.internalAccounts.selectedAccount === accountId) {\n return;\n }\n\n this.update((currentState) => {\n currentState.internalAccounts.accounts[accountId].metadata.lastSelected =\n Date.now();\n currentState.internalAccounts.selectedAccount = accountId;\n });\n\n // DO NOT publish AccountsController:setSelectedAccount to prevent circular listener loops\n }\n\n /**\n * Subscribes to message events.\n */\n #subscribeToMessageEvents() {\n this.messagingSystem.subscribe(\n 'SnapController:stateChange',\n (snapStateState) => this.#handleOnSnapStateChange(snapStateState),\n );\n\n this.messagingSystem.subscribe(\n 'KeyringController:stateChange',\n (keyringState) => this.#handleOnKeyringStateChange(keyringState),\n );\n\n this.messagingSystem.subscribe(\n 'SnapKeyring:accountAssetListUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountAssetListUpdated',\n snapAccountEvent,\n ),\n );\n\n this.messagingSystem.subscribe(\n 'SnapKeyring:accountBalancesUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountBalancesUpdated',\n snapAccountEvent,\n ),\n );\n\n this.messagingSystem.subscribe(\n 'SnapKeyring:accountTransactionsUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountTransactionsUpdated',\n snapAccountEvent,\n ),\n );\n\n // Handle account change when multichain network is changed\n this.messagingSystem.subscribe(\n 'MultichainNetworkController:networkDidChange',\n (id) => this.#handleOnMultichainNetworkDidChange(id),\n );\n }\n\n /**\n * Registers message handlers for the AccountsController.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setSelectedAccount`,\n this.setSelectedAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:listAccounts`,\n this.listAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:listMultichainAccounts`,\n this.listMultichainAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setAccountName`,\n this.setAccountName.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setAccountNameAndSelectAccount`,\n this.setAccountNameAndSelectAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateAccounts`,\n this.updateAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getSelectedAccount`,\n this.getSelectedAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getSelectedMultichainAccount`,\n this.getSelectedMultichainAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getAccountByAddress`,\n this.getAccountByAddress.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getNextAvailableAccountName`,\n this.getNextAvailableAccountName.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `AccountsController:getAccount`,\n this.getAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `AccountsController:updateAccountMetadata`,\n this.updateAccountMetadata.bind(this),\n );\n }\n}\n"]}
1
+ {"version":3,"file":"AccountsController.mjs","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAKL,cAAc,EACf,kCAAkC;AACnC,OAAO,EAIL,WAAW,EACZ,mCAAmC;AAEpC,OAAO,EACL,cAAc,EACd,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,+BAA+B,EAChC,8BAA8B;AAE/B,OAAO,EAKL,YAAY,EACb,qCAAqC;AAEtC,OAAO,EAAE,iBAAiB,EAAE,gCAAgC;AAO5D,OAAO,EAAoB,aAAa,EAAE,wBAAwB;;;AAOlE,OAAO,EACL,4BAA4B,EAC5B,gCAAgC,EAChC,iCAAiC,EACjC,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EAClB,oBAAgB;AAEjB,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAuK5C,MAAM,0BAA0B,GAAG;IACjC,gBAAgB,EAAE;QAChB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,YAAY,GAA4B;IAC5C,gBAAgB,EAAE;QAChB,QAAQ,EAAE,EAAE;QACZ,eAAe,EAAE,EAAE;KACpB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,EAAE,EAAE,EAAE;IACN,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,EAAE;IACX,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qBAAqB,CACxC,0CAA0C,EAC1C,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CACtC,CAAC;AACJ,CAAC","sourcesContent":["import {\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type ExtractEventPayload,\n type RestrictedMessenger,\n BaseController,\n} from '@metamask/base-controller';\nimport {\n type SnapKeyringAccountAssetListUpdatedEvent,\n type SnapKeyringAccountBalancesUpdatedEvent,\n type SnapKeyringAccountTransactionsUpdatedEvent,\n SnapKeyring,\n} from '@metamask/eth-snap-keyring';\nimport type { KeyringAccountEntropyOptions } from '@metamask/keyring-api';\nimport {\n EthAccountType,\n EthMethod,\n EthScope,\n isEvmAccountType,\n KeyringAccountEntropyTypeOption,\n} from '@metamask/keyring-api';\nimport type { KeyringObject } from '@metamask/keyring-controller';\nimport {\n type KeyringControllerState,\n type KeyringControllerGetKeyringsByTypeAction,\n type KeyringControllerStateChangeEvent,\n type KeyringControllerGetStateAction,\n KeyringTypes,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { isScopeEqualToAny } from '@metamask/keyring-utils';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type {\n SnapControllerState,\n SnapStateChange,\n} from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { type CaipChainId, isCaipChainId } from '@metamask/utils';\nimport type { WritableDraft } from 'immer/dist/internal.js';\nimport { cloneDeep } from 'lodash';\n\nimport type { MultichainNetworkControllerNetworkDidChangeEvent } from './types';\nimport type { AccountsControllerStrictState } from './typing';\nimport type { HdSnapKeyringAccount } from './utils';\nimport {\n getEvmDerivationPathForIndex,\n getEvmGroupIndexFromAddressIndex,\n getUUIDFromAddressOfNormalAccount,\n isHdKeyringType,\n isHdSnapKeyringAccount,\n isSimpleKeyringType,\n isSnapKeyringType,\n keyringTypeToName,\n} from './utils';\n\nconst controllerName = 'AccountsController';\n\nexport type AccountId = string;\n\nexport type AccountsControllerState = {\n internalAccounts: {\n accounts: Record<AccountId, InternalAccount>;\n selectedAccount: string; // id of the selected account\n };\n};\n\nexport type AccountsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AccountsControllerState\n>;\n\nexport type AccountsControllerSetSelectedAccountAction = {\n type: `${typeof controllerName}:setSelectedAccount`;\n handler: AccountsController['setSelectedAccount'];\n};\n\nexport type AccountsControllerSetAccountNameAction = {\n type: `${typeof controllerName}:setAccountName`;\n handler: AccountsController['setAccountName'];\n};\n\nexport type AccountsControllerSetAccountNameAndSelectAccountAction = {\n type: `${typeof controllerName}:setAccountNameAndSelectAccount`;\n handler: AccountsController['setAccountNameAndSelectAccount'];\n};\n\nexport type AccountsControllerListAccountsAction = {\n type: `${typeof controllerName}:listAccounts`;\n handler: AccountsController['listAccounts'];\n};\n\nexport type AccountsControllerListMultichainAccountsAction = {\n type: `${typeof controllerName}:listMultichainAccounts`;\n handler: AccountsController['listMultichainAccounts'];\n};\n\nexport type AccountsControllerUpdateAccountsAction = {\n type: `${typeof controllerName}:updateAccounts`;\n handler: AccountsController['updateAccounts'];\n};\n\nexport type AccountsControllerGetSelectedAccountAction = {\n type: `${typeof controllerName}:getSelectedAccount`;\n handler: AccountsController['getSelectedAccount'];\n};\n\nexport type AccountsControllerGetSelectedMultichainAccountAction = {\n type: `${typeof controllerName}:getSelectedMultichainAccount`;\n handler: AccountsController['getSelectedMultichainAccount'];\n};\n\nexport type AccountsControllerGetAccountByAddressAction = {\n type: `${typeof controllerName}:getAccountByAddress`;\n handler: AccountsController['getAccountByAddress'];\n};\n\nexport type AccountsControllerGetNextAvailableAccountNameAction = {\n type: `${typeof controllerName}:getNextAvailableAccountName`;\n handler: AccountsController['getNextAvailableAccountName'];\n};\n\nexport type AccountsControllerGetAccountAction = {\n type: `${typeof controllerName}:getAccount`;\n handler: AccountsController['getAccount'];\n};\n\nexport type AccountsControllerUpdateAccountMetadataAction = {\n type: `${typeof controllerName}:updateAccountMetadata`;\n handler: AccountsController['updateAccountMetadata'];\n};\n\nexport type AllowedActions =\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetStateAction;\n\nexport type AccountsControllerActions =\n | AccountsControllerGetStateAction\n | AccountsControllerSetSelectedAccountAction\n | AccountsControllerListAccountsAction\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerSetAccountNameAction\n | AccountsControllerSetAccountNameAndSelectAccountAction\n | AccountsControllerUpdateAccountsAction\n | AccountsControllerGetAccountByAddressAction\n | AccountsControllerGetSelectedAccountAction\n | AccountsControllerGetNextAvailableAccountNameAction\n | AccountsControllerGetAccountAction\n | AccountsControllerGetSelectedMultichainAccountAction\n | AccountsControllerUpdateAccountMetadataAction;\n\nexport type AccountsControllerChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AccountsControllerState\n>;\n\nexport type AccountsControllerSelectedAccountChangeEvent = {\n type: `${typeof controllerName}:selectedAccountChange`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerSelectedEvmAccountChangeEvent = {\n type: `${typeof controllerName}:selectedEvmAccountChange`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountAddedEvent = {\n type: `${typeof controllerName}:accountAdded`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountRemovedEvent = {\n type: `${typeof controllerName}:accountRemoved`;\n payload: [AccountId];\n};\n\nexport type AccountsControllerAccountRenamedEvent = {\n type: `${typeof controllerName}:accountRenamed`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountBalancesUpdatesEvent = {\n type: `${typeof controllerName}:accountBalancesUpdated`;\n payload: SnapKeyringAccountBalancesUpdatedEvent['payload'];\n};\n\nexport type AccountsControllerAccountTransactionsUpdatedEvent = {\n type: `${typeof controllerName}:accountTransactionsUpdated`;\n payload: SnapKeyringAccountTransactionsUpdatedEvent['payload'];\n};\n\nexport type AccountsControllerAccountAssetListUpdatedEvent = {\n type: `${typeof controllerName}:accountAssetListUpdated`;\n payload: SnapKeyringAccountAssetListUpdatedEvent['payload'];\n};\n\nexport type AllowedEvents =\n | SnapStateChange\n | KeyringControllerStateChangeEvent\n | SnapKeyringAccountAssetListUpdatedEvent\n | SnapKeyringAccountBalancesUpdatedEvent\n | SnapKeyringAccountTransactionsUpdatedEvent\n | MultichainNetworkControllerNetworkDidChangeEvent;\n\nexport type AccountsControllerEvents =\n | AccountsControllerChangeEvent\n | AccountsControllerSelectedAccountChangeEvent\n | AccountsControllerSelectedEvmAccountChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountRenamedEvent\n | AccountsControllerAccountBalancesUpdatesEvent\n | AccountsControllerAccountTransactionsUpdatedEvent\n | AccountsControllerAccountAssetListUpdatedEvent;\n\nexport type AccountsControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n AccountsControllerActions | AllowedActions,\n AccountsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\nconst accountsControllerMetadata = {\n internalAccounts: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n};\n\nconst defaultState: AccountsControllerState = {\n internalAccounts: {\n accounts: {},\n selectedAccount: '',\n },\n};\n\nexport const EMPTY_ACCOUNT = {\n id: '',\n address: '',\n options: {},\n methods: [],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: '',\n keyring: {\n type: '',\n },\n importTime: 0,\n },\n};\n\n/**\n * Controller that manages internal accounts.\n * The accounts controller is responsible for creating and managing internal accounts.\n * It also provides convenience methods for accessing and updating the internal accounts.\n * The accounts controller also listens for keyring state changes and updates the internal accounts accordingly.\n * The accounts controller also listens for snap state changes and updates the internal accounts accordingly.\n *\n */\nexport class AccountsController extends BaseController<\n typeof controllerName,\n AccountsControllerState,\n AccountsControllerMessenger\n> {\n /**\n * Constructor for AccountsController.\n *\n * @param options - The controller options.\n * @param options.messenger - The messenger object.\n * @param options.state - Initial state to set on this controller\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: AccountsControllerMessenger;\n state: AccountsControllerState;\n }) {\n super({\n messenger,\n name: controllerName,\n metadata: accountsControllerMetadata,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n this.#subscribeToMessageEvents();\n this.#registerMessageHandlers();\n }\n\n /**\n * Returns the internal account object for the given account ID, if it exists.\n *\n * @param accountId - The ID of the account to retrieve.\n * @returns The internal account object, or undefined if the account does not exist.\n */\n getAccount(accountId: string): InternalAccount | undefined {\n return this.state.internalAccounts.accounts[accountId];\n }\n\n /**\n * Returns an array of all evm internal accounts.\n *\n * @returns An array of InternalAccount objects.\n */\n listAccounts(): InternalAccount[] {\n const accounts = Object.values(this.state.internalAccounts.accounts);\n return accounts.filter((account) => isEvmAccountType(account.type));\n }\n\n /**\n * Returns an array of all internal accounts.\n *\n * @param chainId - The chain ID.\n * @returns An array of InternalAccount objects.\n */\n listMultichainAccounts(chainId?: CaipChainId): InternalAccount[] {\n const accounts = Object.values(this.state.internalAccounts.accounts);\n if (!chainId) {\n return accounts;\n }\n\n if (!isCaipChainId(chainId)) {\n throw new Error(`Invalid CAIP-2 chain ID: ${String(chainId)}`);\n }\n\n return accounts.filter((account) =>\n isScopeEqualToAny(chainId, account.scopes),\n );\n }\n\n /**\n * Returns the internal account object for the given account ID.\n *\n * @param accountId - The ID of the account to retrieve.\n * @returns The internal account object.\n * @throws An error if the account ID is not found.\n */\n getAccountExpect(accountId: string): InternalAccount {\n const account = this.getAccount(accountId);\n if (account === undefined) {\n throw new Error(`Account Id \"${accountId}\" not found`);\n }\n return account;\n }\n\n /**\n * Returns the last selected EVM account.\n *\n * @returns The selected internal account.\n */\n getSelectedAccount(): InternalAccount {\n const {\n internalAccounts: { selectedAccount },\n } = this.state;\n\n // Edge case where the extension is setup but the srp is not yet created\n // certain ui elements will query the selected address before any accounts are created.\n if (selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n const account = this.getAccountExpect(selectedAccount);\n if (isEvmAccountType(account.type)) {\n return account;\n }\n\n const accounts = this.listAccounts();\n if (!accounts.length) {\n // ! Should never reach this.\n throw new Error('No EVM accounts');\n }\n\n // This will never be undefined because we have already checked if accounts.length is > 0\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.#getLastSelectedAccount(accounts)!;\n }\n\n /**\n * __WARNING The return value may be undefined if there isn't an account for that chain id.__\n *\n * Retrieves the last selected account by chain ID.\n *\n * @param chainId - The chain ID to filter the accounts.\n * @returns The last selected account compatible with the specified chain ID or undefined.\n */\n getSelectedMultichainAccount(\n chainId?: CaipChainId,\n ): InternalAccount | undefined {\n const {\n internalAccounts: { selectedAccount },\n } = this.state;\n\n // Edge case where the extension is setup but the srp is not yet created\n // certain ui elements will query the selected address before any accounts are created.\n if (selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n if (!chainId) {\n return this.getAccountExpect(selectedAccount);\n }\n\n const accounts = this.listMultichainAccounts(chainId);\n return this.#getLastSelectedAccount(accounts);\n }\n\n /**\n * Returns the account with the specified address.\n * ! This method will only return the first account that matches the address\n *\n * @param address - The address of the account to retrieve.\n * @returns The account with the specified address, or undefined if not found.\n */\n getAccountByAddress(address: string): InternalAccount | undefined {\n return this.listMultichainAccounts().find(\n (account) => account.address.toLowerCase() === address.toLowerCase(),\n );\n }\n\n /**\n * Sets the selected account by its ID.\n *\n * @param accountId - The ID of the account to be selected.\n */\n setSelectedAccount(accountId: string): void {\n const account = this.getAccountExpect(accountId);\n\n if (this.state.internalAccounts.selectedAccount === account.id) {\n return;\n }\n\n this.#update((state) => {\n const { internalAccounts } = state;\n\n internalAccounts.accounts[account.id].metadata.lastSelected = Date.now();\n internalAccounts.selectedAccount = account.id;\n });\n }\n\n /**\n * Sets the name of the account with the given ID.\n *\n * @param accountId - The ID of the account to set the name for.\n * @param accountName - The new name for the account.\n * @throws An error if an account with the same name already exists.\n */\n setAccountName(accountId: string, accountName: string): void {\n // This will check for name uniqueness and fire the `accountRenamed` event\n // if the account has been renamed.\n this.updateAccountMetadata(accountId, {\n name: accountName,\n nameLastUpdatedAt: Date.now(),\n });\n }\n\n /**\n * Sets the name of the account with the given ID and select it.\n *\n * @param accountId - The ID of the account to set the name for and select.\n * @param accountName - The new name for the account.\n * @throws An error if an account with the same name already exists.\n */\n setAccountNameAndSelectAccount(accountId: string, accountName: string): void {\n const account = this.getAccountExpect(accountId);\n\n this.#assertAccountCanBeRenamed(account, accountName);\n\n const internalAccount = {\n ...account,\n metadata: {\n ...account.metadata,\n name: accountName,\n nameLastUpdatedAt: Date.now(),\n lastSelected: this.#getLastSelectedIndex(),\n },\n };\n\n this.#update((state) => {\n state.internalAccounts.accounts[account.id] = internalAccount;\n state.internalAccounts.selectedAccount = account.id;\n });\n\n this.messagingSystem.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\n }\n\n #assertAccountCanBeRenamed(account: InternalAccount, accountName: string) {\n if (\n this.listMultichainAccounts().find(\n (internalAccount) =>\n internalAccount.metadata.name === accountName &&\n internalAccount.id !== account.id,\n )\n ) {\n throw new Error('Account name already exists');\n }\n }\n\n /**\n * Updates the metadata of the account with the given ID.\n *\n * @param accountId - The ID of the account for which the metadata will be updated.\n * @param metadata - The new metadata for the account.\n */\n updateAccountMetadata(\n accountId: string,\n metadata: Partial<InternalAccount['metadata']>,\n ): void {\n const account = this.getAccountExpect(accountId);\n\n if (metadata.name) {\n this.#assertAccountCanBeRenamed(account, metadata.name);\n }\n\n const internalAccount = {\n ...account,\n metadata: { ...account.metadata, ...metadata },\n };\n\n this.#update((state) => {\n state.internalAccounts.accounts[accountId] = internalAccount;\n });\n\n if (metadata.name) {\n this.messagingSystem.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\n }\n }\n\n /**\n * Updates the internal accounts list by retrieving normal and snap accounts,\n * removing duplicates, and updating the metadata of each account.\n *\n * @returns A Promise that resolves when the accounts have been updated.\n */\n async updateAccounts(): Promise<void> {\n const keyringAccountIndexes = new Map<string, number>();\n\n const existingInternalAccounts = this.state.internalAccounts.accounts;\n const internalAccounts: AccountsControllerState['internalAccounts']['accounts'] =\n {};\n\n const { keyrings } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n for (const keyring of keyrings) {\n const keyringTypeName = keyringTypeToName(keyring.type);\n\n for (const address of keyring.accounts) {\n const internalAccount = this.#getInternalAccountFromAddressAndType(\n address,\n keyring,\n );\n\n // This should never really happen, but if for some reason we're not\n // able to get the Snap keyring reference, this would return an\n // undefined account.\n // So we just skip it, even though, this should not really happen.\n if (!internalAccount) {\n continue;\n }\n\n // Get current index for this keyring (we use human indexing, so start at 1).\n const keyringAccountIndex =\n keyringAccountIndexes.get(keyringTypeName) ?? 1;\n\n const existingAccount = existingInternalAccounts[internalAccount.id];\n internalAccounts[internalAccount.id] = {\n ...internalAccount,\n\n metadata: {\n ...internalAccount.metadata,\n\n // Re-use existing metadata if any.\n name:\n existingAccount?.metadata.name ??\n `${keyringTypeName} ${keyringAccountIndex}`,\n importTime: existingAccount?.metadata.importTime ?? Date.now(),\n lastSelected: existingAccount?.metadata.lastSelected ?? 0,\n },\n };\n\n // Increment the account index for this keyring.\n keyringAccountIndexes.set(keyringTypeName, keyringAccountIndex + 1);\n }\n }\n\n this.#update((state) => {\n state.internalAccounts.accounts = internalAccounts;\n });\n }\n\n /**\n * Loads the backup state of the accounts controller.\n *\n * @param backup - The backup state to load.\n */\n loadBackup(backup: AccountsControllerState): void {\n if (backup.internalAccounts) {\n this.update(\n (currentState: WritableDraft<AccountsControllerStrictState>) => {\n currentState.internalAccounts = backup.internalAccounts;\n },\n );\n }\n }\n\n /**\n * Gets an internal account representation for a non-Snap account.\n *\n * @param address - The address of the account.\n * @param keyring - The keyring object of the account.\n * @returns The generated internal account.\n */\n #getInternalAccountForNonSnapAccount(\n address: string,\n keyring: KeyringObject,\n ): InternalAccount {\n const id = getUUIDFromAddressOfNormalAccount(address);\n\n // We might have an account for this ID already, so we'll just re-use\n // the same metadata\n const account = this.getAccount(id);\n const metadata: InternalAccount['metadata'] = {\n name: account?.metadata.name ?? '',\n ...(account?.metadata.nameLastUpdatedAt\n ? {\n nameLastUpdatedAt: account?.metadata.nameLastUpdatedAt,\n }\n : {}),\n importTime: account?.metadata.importTime ?? Date.now(),\n lastSelected: account?.metadata.lastSelected ?? 0,\n keyring: {\n type: keyring.type,\n },\n };\n\n let options: InternalAccount['options'] = {};\n if (isHdKeyringType(keyring.type)) {\n // We need to find the account index from its HD keyring.\n const groupIndex = getEvmGroupIndexFromAddressIndex(keyring, address);\n\n // If for some reason, we cannot find this address, then the caller made a mistake\n // and it did not use the proper keyring object. For now, we do not fail and just\n // consider this account as \"simple account\".\n if (groupIndex !== undefined) {\n // NOTE: We are not using the `hdPath` from the associated keyring here and\n // getting the keyring instance here feels a bit overkill.\n // This will be naturally fixed once every keyring start using `KeyringAccount` and implement the keyring API.\n const derivationPath = getEvmDerivationPathForIndex(groupIndex);\n\n // Those are \"legacy options\" and they were used before `KeyringAccount` added\n // support for type options. We keep those temporarily until we update everything\n // to use the new typed options.\n const legacyOptions = {\n entropySource: keyring.metadata.id,\n derivationPath,\n groupIndex,\n };\n\n // New typed entropy options. This is required for multichain accounts.\n const entropyOptions: { entropy: KeyringAccountEntropyOptions } = {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: keyring.metadata.id,\n derivationPath,\n groupIndex,\n },\n };\n\n options = {\n ...legacyOptions,\n ...entropyOptions,\n };\n }\n }\n\n return {\n id,\n address,\n options,\n methods: [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n ],\n scopes: [EthScope.Eoa],\n type: EthAccountType.Eoa,\n metadata,\n };\n }\n\n /**\n * Get Snap keyring from the keyring controller.\n *\n * @returns The Snap keyring if available.\n */\n #getSnapKeyring(): SnapKeyring | undefined {\n const [snapKeyring] = this.messagingSystem.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n\n // Snap keyring is not available until the first account is created in the keyring\n // controller, so this might be undefined.\n return snapKeyring as SnapKeyring | undefined;\n }\n\n /**\n * Re-publish an account event.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @param payload - The event payload. The type of the parameters for each event handler must\n * match the type of this payload.\n * @template EventType - A Snap keyring event type.\n */\n #handleOnSnapKeyringAccountEvent<\n EventType extends AccountsControllerEvents['type'],\n >(\n event: EventType,\n ...payload: ExtractEventPayload<AccountsControllerEvents, EventType>\n ): void {\n this.messagingSystem.publish(event, ...payload);\n }\n\n /**\n * Handles changes in the keyring state, specifically when new accounts are added or removed.\n *\n * @param keyringState - The new state of the keyring controller.\n * @param keyringState.isUnlocked - True if the keyrings are unlocked, false otherwise.\n * @param keyringState.keyrings - List of all keyrings.\n */\n #handleOnKeyringStateChange({\n isUnlocked,\n keyrings,\n }: KeyringControllerState): void {\n // TODO: Change when accountAdded event is added to the keyring controller.\n\n // We check for keyrings length to be greater than 0 because the extension client may try execute\n // submit password twice and clear the keyring state.\n // https://github.com/MetaMask/KeyringController/blob/2d73a4deed8d013913f6ef0c9f5c0bb7c614f7d3/src/KeyringController.ts#L910\n if (!isUnlocked || keyrings.length === 0) {\n return;\n }\n\n // State patches.\n const generatePatch = () => {\n return {\n previous: {} as Record<string, InternalAccount>,\n added: [] as {\n address: string;\n keyring: KeyringObject;\n }[],\n updated: [] as InternalAccount[],\n removed: [] as InternalAccount[],\n };\n };\n const patches = {\n snap: generatePatch(),\n normal: generatePatch(),\n };\n\n // Gets the patch object based on the keyring type (since Snap accounts and other accounts\n // are handled differently).\n const patchOf = (type: string) => {\n if (isSnapKeyringType(type)) {\n return patches.snap;\n }\n return patches.normal;\n };\n\n // Create a map (with lower-cased addresses) of all existing accounts.\n for (const account of this.listMultichainAccounts()) {\n const address = account.address.toLowerCase();\n const patch = patchOf(account.metadata.keyring.type);\n\n patch.previous[address] = account;\n }\n\n // Go over all keyring changes and create patches out of it.\n const addresses = new Set<string>();\n for (const keyring of keyrings) {\n const patch = patchOf(keyring.type);\n\n for (const accountAddress of keyring.accounts) {\n // Lower-case address to use it in the `previous` map.\n const address = accountAddress.toLowerCase();\n const account = patch.previous[address];\n\n if (account) {\n // If the account exists before, this might be an update.\n patch.updated.push(account);\n } else {\n // Otherwise, that's a new account.\n patch.added.push({\n address,\n keyring,\n });\n }\n\n // Keep track of those address to check for removed accounts later.\n addresses.add(address);\n }\n }\n\n // We might have accounts associated with removed keyrings, so we iterate\n // over all previous known accounts and check against the keyring addresses.\n for (const patch of [patches.snap, patches.normal]) {\n for (const [address, account] of Object.entries(patch.previous)) {\n // If a previous address is not part of the new addesses, then it got removed.\n if (!addresses.has(address)) {\n patch.removed.push(account);\n }\n }\n }\n\n // Diff that we will use to publish events afterward.\n const diff = {\n removed: [] as string[],\n added: [] as InternalAccount[],\n };\n\n this.#update(\n (state) => {\n const { internalAccounts } = state;\n\n for (const patch of [patches.snap, patches.normal]) {\n for (const account of patch.removed) {\n delete internalAccounts.accounts[account.id];\n\n diff.removed.push(account.id);\n }\n\n for (const added of patch.added) {\n const account = this.#getInternalAccountFromAddressAndType(\n added.address,\n added.keyring,\n );\n\n if (account) {\n // Re-compute the list of accounts everytime, so we can make sure new names\n // are also considered.\n const accounts = Object.values(\n internalAccounts.accounts,\n ) as InternalAccount[];\n\n // Get next account name available for this given keyring.\n const name = this.getNextAvailableAccountName(\n account.metadata.keyring.type,\n accounts,\n );\n\n // If it's the first account, we need to select it.\n const lastSelected =\n accounts.length === 0 ? this.#getLastSelectedIndex() : 0;\n\n internalAccounts.accounts[account.id] = {\n ...account,\n metadata: {\n ...account.metadata,\n name,\n importTime: Date.now(),\n lastSelected,\n },\n };\n\n diff.added.push(internalAccounts.accounts[account.id]);\n }\n }\n }\n },\n // Will get executed after the update, but before re-selecting an account in case\n // the current one is not valid anymore.\n () => {\n // Now publish events\n for (const id of diff.removed) {\n this.messagingSystem.publish('AccountsController:accountRemoved', id);\n }\n\n for (const account of diff.added) {\n this.messagingSystem.publish(\n 'AccountsController:accountAdded',\n account,\n );\n }\n },\n );\n\n // NOTE: Since we also track \"updated\" accounts with our patches, we could fire a new event\n // like `accountUpdated` (we would still need to check if anything really changed on the account).\n }\n\n /**\n * Update the state and fixup the currently selected account.\n *\n * @param callback - Callback for updating state, passed a draft state object.\n * @param beforeAutoSelectAccount - Callback to be executed before auto-selecting an account\n * if the current one is no longer available.\n */\n #update(\n callback: (state: WritableDraft<AccountsControllerStrictState>) => void,\n beforeAutoSelectAccount?: () => void,\n ) {\n // The currently selected account might get deleted during the update, so keep track\n // of it before doing any change.\n const previouslySelectedAccount =\n this.state.internalAccounts.selectedAccount;\n\n this.update((state: WritableDraft<AccountsControllerStrictState>) => {\n callback(state);\n\n // If the account no longer exists (or none is selected), we need to re-select another one.\n const { internalAccounts } = state;\n if (!internalAccounts.accounts[previouslySelectedAccount]) {\n const accounts = Object.values(\n internalAccounts.accounts,\n ) as InternalAccount[];\n\n // Get the lastly selected account (according to the current accounts).\n const lastSelectedAccount = this.#getLastSelectedAccount(accounts);\n if (lastSelectedAccount) {\n internalAccounts.selectedAccount = lastSelectedAccount.id;\n internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n } else {\n // It will be undefined if there are no accounts.\n internalAccounts.selectedAccount = '';\n }\n }\n });\n\n // We might want to do some pre-work before selecting a new account.\n beforeAutoSelectAccount?.();\n\n // Now, we compare the newly selected account, and we send event if different.\n const { selectedAccount } = this.state.internalAccounts;\n if (selectedAccount && selectedAccount !== previouslySelectedAccount) {\n const account = this.getSelectedMultichainAccount();\n\n // The account should always be defined at this point, since we have already checked for\n // `selectedAccount` to be non-empty.\n if (account) {\n if (isEvmAccountType(account.type)) {\n this.messagingSystem.publish(\n 'AccountsController:selectedEvmAccountChange',\n account,\n );\n }\n this.messagingSystem.publish(\n 'AccountsController:selectedAccountChange',\n account,\n );\n }\n }\n }\n\n /**\n * Handles the change in SnapControllerState by updating the metadata of accounts that have a snap enabled.\n *\n * @param snapState - The new SnapControllerState.\n */\n #handleOnSnapStateChange(snapState: SnapControllerState) {\n // Only check if Snaps changed in status.\n const { snaps } = snapState;\n\n const accounts: { id: string; enabled: boolean }[] = [];\n for (const account of this.listMultichainAccounts()) {\n if (account.metadata.snap) {\n const snap = snaps[account.metadata.snap.id as SnapId];\n\n if (snap) {\n const enabled = snap.enabled && !snap.blocked;\n const metadata = account.metadata.snap;\n\n if (metadata.enabled !== enabled) {\n accounts.push({ id: account.id, enabled });\n }\n } else {\n // If Snap could not be found on the state, we consider it disabled.\n accounts.push({ id: account.id, enabled: false });\n }\n }\n }\n\n if (accounts.length > 0) {\n this.update((state) => {\n for (const { id, enabled } of accounts) {\n const account = state.internalAccounts.accounts[id];\n\n if (account.metadata.snap) {\n account.metadata.snap.enabled = enabled;\n }\n }\n });\n }\n }\n\n /**\n * Returns the list of accounts for a given keyring type.\n *\n * @param keyringType - The type of keyring.\n * @param accounts - Accounts to filter by keyring type.\n * @returns The list of accounts associcated with this keyring type.\n */\n #getAccountsByKeyringType(keyringType: string, accounts?: InternalAccount[]) {\n return (accounts ?? this.listMultichainAccounts()).filter(\n (internalAccount) => {\n // We do consider `hd` and `simple` keyrings to be of same type. So we check those 2 types\n // to group those accounts together!\n if (isHdKeyringType(keyringType) || isSimpleKeyringType(keyringType)) {\n return (\n isHdKeyringType(internalAccount.metadata.keyring.type) ||\n isSimpleKeyringType(internalAccount.metadata.keyring.type)\n );\n }\n\n return internalAccount.metadata.keyring.type === keyringType;\n },\n );\n }\n\n /**\n * Returns the last selected account from the given array of accounts.\n *\n * @param accounts - An array of InternalAccount objects.\n * @returns The InternalAccount object that was last selected, or undefined if the array is empty.\n */\n #getLastSelectedAccount(\n accounts: InternalAccount[],\n ): InternalAccount | undefined {\n const [accountToSelect] = accounts.sort((accountA, accountB) => {\n // sort by lastSelected descending\n return (\n (accountB.metadata.lastSelected ?? 0) -\n (accountA.metadata.lastSelected ?? 0)\n );\n });\n\n return accountToSelect;\n }\n\n /**\n * Returns the next account number for a given keyring type.\n *\n * @param keyringType - The type of keyring.\n * @param accounts - Existing accounts to check for the next available account number.\n * @returns An object containing the account prefix and index to use.\n */\n getNextAvailableAccountName(\n keyringType: string = KeyringTypes.hd,\n accounts?: InternalAccount[],\n ): string {\n const keyringName = keyringTypeToName(keyringType);\n const keyringAccounts = this.#getAccountsByKeyringType(\n keyringType,\n accounts,\n );\n const lastDefaultIndexUsedForKeyringType = keyringAccounts.reduce(\n (maxInternalAccountIndex, internalAccount) => {\n // We **DO NOT USE** `\\d+` here to only consider valid \"human\"\n // number (rounded decimal number)\n const match = new RegExp(`${keyringName} ([0-9]+)$`, 'u').exec(\n internalAccount.metadata.name,\n );\n\n if (match) {\n // Quoting `RegExp.exec` documentation:\n // > The returned array has the matched text as the first item, and then one item for\n // > each capturing group of the matched text.\n // So use `match[1]` to get the captured value\n const internalAccountIndex = parseInt(match[1], 10);\n return Math.max(maxInternalAccountIndex, internalAccountIndex);\n }\n\n return maxInternalAccountIndex;\n },\n 0,\n );\n\n const index = Math.max(\n keyringAccounts.length + 1,\n lastDefaultIndexUsedForKeyringType + 1,\n );\n\n return `${keyringName} ${index}`;\n }\n\n /**\n * Retrieves the index value for `metadata.lastSelected`.\n *\n * @returns The index value.\n */\n #getLastSelectedIndex() {\n // NOTE: For now we use the current date, since we know this value\n // will always be higher than any already selected account index.\n return Date.now();\n }\n\n /**\n * Get an internal account given an address and a keyring type.\n *\n * If the account is not a Snap Keyring account, generates an internal account for it and adds it to the controller.\n * If the account is a Snap Keyring account, retrieves the account from the keyring and adds it to the controller.\n *\n * @param address - The address of the new account.\n * @param keyring - The keyring object of that new account.\n * @returns The newly generated/retrieved internal account.\n */\n #getInternalAccountFromAddressAndType(\n address: string,\n keyring: KeyringObject,\n ): InternalAccount | undefined {\n if (isSnapKeyringType(keyring.type)) {\n const snapKeyring = this.#getSnapKeyring();\n\n // We need the Snap keyring to retrieve the account from its address.\n if (!snapKeyring) {\n return undefined;\n }\n\n // This might be undefined if the Snap deleted the account before\n // reaching that point.\n let account = snapKeyring.getAccountByAddress(address);\n if (account) {\n // We force the copy here, to avoid mutating the reference returned by the Snap keyring.\n account = cloneDeep(account);\n\n // MIGRATION: To avoid any existing Snap account migration, we are\n // just \"adding\" the new typed options that we need for multichain\n // accounts. Ultimately, we would need a real Snap account migrations\n // (being handled by each Snaps).\n if (isHdSnapKeyringAccount(account)) {\n const options: HdSnapKeyringAccount['options'] = {\n ...account.options,\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: account.options.entropySource,\n groupIndex: account.options.index,\n derivationPath: account.options.derivationPath,\n },\n };\n // Inject the new typed options to the internal account copy.\n account.options = options;\n }\n }\n\n return account;\n }\n\n return this.#getInternalAccountForNonSnapAccount(address, keyring);\n }\n\n /**\n * Handles the change in multichain network by updating the selected account.\n *\n * @param id - The EVM client ID or non-EVM chain ID that changed.\n */\n #handleOnMultichainNetworkDidChange(id: NetworkClientId | CaipChainId) {\n let accountId: string;\n\n // We only support non-EVM Caip chain IDs at the moment. Ex Solana and Bitcoin\n // MultichainNetworkController will handle throwing an error if the Caip chain ID is not supported\n if (isCaipChainId(id)) {\n // Update selected account to non evm account\n const lastSelectedNonEvmAccount = this.getSelectedMultichainAccount(id);\n // @ts-expect-error - This should never be undefined, otherwise it's a bug that should be handled\n accountId = lastSelectedNonEvmAccount.id;\n } else {\n // Update selected account to evm account\n const lastSelectedEvmAccount = this.getSelectedAccount();\n accountId = lastSelectedEvmAccount.id;\n }\n\n if (this.state.internalAccounts.selectedAccount === accountId) {\n return;\n }\n\n this.update((currentState) => {\n currentState.internalAccounts.accounts[accountId].metadata.lastSelected =\n Date.now();\n currentState.internalAccounts.selectedAccount = accountId;\n });\n\n // DO NOT publish AccountsController:setSelectedAccount to prevent circular listener loops\n }\n\n /**\n * Subscribes to message events.\n */\n #subscribeToMessageEvents() {\n this.messagingSystem.subscribe(\n 'SnapController:stateChange',\n (snapStateState) => this.#handleOnSnapStateChange(snapStateState),\n );\n\n this.messagingSystem.subscribe(\n 'KeyringController:stateChange',\n (keyringState) => this.#handleOnKeyringStateChange(keyringState),\n );\n\n this.messagingSystem.subscribe(\n 'SnapKeyring:accountAssetListUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountAssetListUpdated',\n snapAccountEvent,\n ),\n );\n\n this.messagingSystem.subscribe(\n 'SnapKeyring:accountBalancesUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountBalancesUpdated',\n snapAccountEvent,\n ),\n );\n\n this.messagingSystem.subscribe(\n 'SnapKeyring:accountTransactionsUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountTransactionsUpdated',\n snapAccountEvent,\n ),\n );\n\n // Handle account change when multichain network is changed\n this.messagingSystem.subscribe(\n 'MultichainNetworkController:networkDidChange',\n (id) => this.#handleOnMultichainNetworkDidChange(id),\n );\n }\n\n /**\n * Registers message handlers for the AccountsController.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setSelectedAccount`,\n this.setSelectedAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:listAccounts`,\n this.listAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:listMultichainAccounts`,\n this.listMultichainAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setAccountName`,\n this.setAccountName.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:setAccountNameAndSelectAccount`,\n this.setAccountNameAndSelectAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateAccounts`,\n this.updateAccounts.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getSelectedAccount`,\n this.getSelectedAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getSelectedMultichainAccount`,\n this.getSelectedMultichainAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getAccountByAddress`,\n this.getAccountByAddress.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getNextAvailableAccountName`,\n this.getNextAvailableAccountName.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `AccountsController:getAccount`,\n this.getAccount.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `AccountsController:updateAccountMetadata`,\n this.updateAccountMetadata.bind(this),\n );\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=typing.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typing.cjs","sourceRoot":"","sources":["../src/typing.ts"],"names":[],"mappings":"","sourcesContent":["import type { KeyringAccountEntropyOptions } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountsControllerState } from './AccountsController';\n\n/**\n * Type constraint to ensure a type is compatible with {@link AccountsControllerState}.\n * If the constraint is not matching, this type will resolve to `never` and thus, fails\n * to compile.\n */\ntype IsAccountControllerState<Type extends AccountsControllerState> = Type;\n\n/**\n * A type compatible with {@link InternalAccount} which removes any use of recursive-type.\n */\nexport type StrictInternalAccount = Omit<InternalAccount, 'options'> & {\n // Use stricter options, which are relying on `Json` (which sometimes\n // cause compiler errors because of instanciation \"too deep\".\n // In anyway, we should rarely have to use those \"untyped\" options.\n options: {\n entropy?: KeyringAccountEntropyOptions;\n exportable?: boolean;\n };\n};\n\n/**\n * A type compatible with {@link AccountControllerState} which can be used to\n * avoid recursive-type issue with `internalAccounts`.\n */\nexport type AccountsControllerStrictState = IsAccountControllerState<{\n internalAccounts: {\n accounts: Record<InternalAccount['id'], StrictInternalAccount>;\n selectedAccount: InternalAccount['id'];\n };\n}>;\n"]}
@@ -0,0 +1,30 @@
1
+ import type { KeyringAccountEntropyOptions } from "@metamask/keyring-api";
2
+ import type { InternalAccount } from "@metamask/keyring-internal-api";
3
+ import type { AccountsControllerState } from "./AccountsController.cjs";
4
+ /**
5
+ * Type constraint to ensure a type is compatible with {@link AccountsControllerState}.
6
+ * If the constraint is not matching, this type will resolve to `never` and thus, fails
7
+ * to compile.
8
+ */
9
+ type IsAccountControllerState<Type extends AccountsControllerState> = Type;
10
+ /**
11
+ * A type compatible with {@link InternalAccount} which removes any use of recursive-type.
12
+ */
13
+ export type StrictInternalAccount = Omit<InternalAccount, 'options'> & {
14
+ options: {
15
+ entropy?: KeyringAccountEntropyOptions;
16
+ exportable?: boolean;
17
+ };
18
+ };
19
+ /**
20
+ * A type compatible with {@link AccountControllerState} which can be used to
21
+ * avoid recursive-type issue with `internalAccounts`.
22
+ */
23
+ export type AccountsControllerStrictState = IsAccountControllerState<{
24
+ internalAccounts: {
25
+ accounts: Record<InternalAccount['id'], StrictInternalAccount>;
26
+ selectedAccount: InternalAccount['id'];
27
+ };
28
+ }>;
29
+ export {};
30
+ //# sourceMappingURL=typing.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typing.d.cts","sourceRoot":"","sources":["../src/typing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,8BAA8B;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,uBAAuB,EAAE,iCAA6B;AAEpE;;;;GAIG;AACH,KAAK,wBAAwB,CAAC,IAAI,SAAS,uBAAuB,IAAI,IAAI,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,GAAG;IAIrE,OAAO,EAAE;QACP,OAAO,CAAC,EAAE,4BAA4B,CAAC;QACvC,UAAU,CAAC,EAAE,OAAO,CAAC;KACtB,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG,wBAAwB,CAAC;IACnE,gBAAgB,EAAE;QAChB,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,qBAAqB,CAAC,CAAC;QAC/D,eAAe,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;KACxC,CAAC;CACH,CAAC,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { KeyringAccountEntropyOptions } from "@metamask/keyring-api";
2
+ import type { InternalAccount } from "@metamask/keyring-internal-api";
3
+ import type { AccountsControllerState } from "./AccountsController.mjs";
4
+ /**
5
+ * Type constraint to ensure a type is compatible with {@link AccountsControllerState}.
6
+ * If the constraint is not matching, this type will resolve to `never` and thus, fails
7
+ * to compile.
8
+ */
9
+ type IsAccountControllerState<Type extends AccountsControllerState> = Type;
10
+ /**
11
+ * A type compatible with {@link InternalAccount} which removes any use of recursive-type.
12
+ */
13
+ export type StrictInternalAccount = Omit<InternalAccount, 'options'> & {
14
+ options: {
15
+ entropy?: KeyringAccountEntropyOptions;
16
+ exportable?: boolean;
17
+ };
18
+ };
19
+ /**
20
+ * A type compatible with {@link AccountControllerState} which can be used to
21
+ * avoid recursive-type issue with `internalAccounts`.
22
+ */
23
+ export type AccountsControllerStrictState = IsAccountControllerState<{
24
+ internalAccounts: {
25
+ accounts: Record<InternalAccount['id'], StrictInternalAccount>;
26
+ selectedAccount: InternalAccount['id'];
27
+ };
28
+ }>;
29
+ export {};
30
+ //# sourceMappingURL=typing.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typing.d.mts","sourceRoot":"","sources":["../src/typing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,8BAA8B;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,uBAAuB,EAAE,iCAA6B;AAEpE;;;;GAIG;AACH,KAAK,wBAAwB,CAAC,IAAI,SAAS,uBAAuB,IAAI,IAAI,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,GAAG;IAIrE,OAAO,EAAE;QACP,OAAO,CAAC,EAAE,4BAA4B,CAAC;QACvC,UAAU,CAAC,EAAE,OAAO,CAAC;KACtB,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG,wBAAwB,CAAC;IACnE,gBAAgB,EAAE;QAChB,QAAQ,EAAE,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,qBAAqB,CAAC,CAAC;QAC/D,eAAe,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;KACxC,CAAC;CACH,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=typing.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typing.mjs","sourceRoot":"","sources":["../src/typing.ts"],"names":[],"mappings":"","sourcesContent":["import type { KeyringAccountEntropyOptions } from '@metamask/keyring-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountsControllerState } from './AccountsController';\n\n/**\n * Type constraint to ensure a type is compatible with {@link AccountsControllerState}.\n * If the constraint is not matching, this type will resolve to `never` and thus, fails\n * to compile.\n */\ntype IsAccountControllerState<Type extends AccountsControllerState> = Type;\n\n/**\n * A type compatible with {@link InternalAccount} which removes any use of recursive-type.\n */\nexport type StrictInternalAccount = Omit<InternalAccount, 'options'> & {\n // Use stricter options, which are relying on `Json` (which sometimes\n // cause compiler errors because of instanciation \"too deep\".\n // In anyway, we should rarely have to use those \"untyped\" options.\n options: {\n entropy?: KeyringAccountEntropyOptions;\n exportable?: boolean;\n };\n};\n\n/**\n * A type compatible with {@link AccountControllerState} which can be used to\n * avoid recursive-type issue with `internalAccounts`.\n */\nexport type AccountsControllerStrictState = IsAccountControllerState<{\n internalAccounts: {\n accounts: Record<InternalAccount['id'], StrictInternalAccount>;\n selectedAccount: InternalAccount['id'];\n };\n}>;\n"]}
package/dist/utils.d.cts CHANGED
@@ -75,9 +75,9 @@ export declare function getEvmGroupIndexFromAddressIndex(keyring: KeyringObject,
75
75
  * extra-properties than a Snap might add in its `options`.
76
76
  */
77
77
  export declare const HdSnapKeyringAccountOptionsStruct: import("@metamask/superstruct").Struct<{
78
+ derivationPath: string;
78
79
  entropySource: string;
79
80
  index: number;
80
- derivationPath: string;
81
81
  }, {
82
82
  entropySource: import("@metamask/superstruct").Struct<string, null>;
83
83
  index: import("@metamask/superstruct").Struct<number, null>;
package/dist/utils.d.mts CHANGED
@@ -75,9 +75,9 @@ export declare function getEvmGroupIndexFromAddressIndex(keyring: KeyringObject,
75
75
  * extra-properties than a Snap might add in its `options`.
76
76
  */
77
77
  export declare const HdSnapKeyringAccountOptionsStruct: import("@metamask/superstruct").Struct<{
78
+ derivationPath: string;
78
79
  entropySource: string;
79
80
  index: number;
80
- derivationPath: string;
81
81
  }, {
82
82
  entropySource: import("@metamask/superstruct").Struct<string, null>;
83
83
  index: import("@metamask/superstruct").Struct<number, null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/accounts-controller",
3
- "version": "33.0.0",
3
+ "version": "33.1.0",
4
4
  "description": "Manages internal accounts",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -48,10 +48,10 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@ethereumjs/util": "^9.1.0",
51
- "@metamask/base-controller": "^8.1.0",
52
- "@metamask/eth-snap-keyring": "^16.1.0",
53
- "@metamask/keyring-api": "^20.1.0",
54
- "@metamask/keyring-internal-api": "^8.1.0",
51
+ "@metamask/base-controller": "^8.3.0",
52
+ "@metamask/eth-snap-keyring": "^17.0.0",
53
+ "@metamask/keyring-api": "^21.0.0",
54
+ "@metamask/keyring-internal-api": "^9.0.0",
55
55
  "@metamask/keyring-utils": "^3.1.0",
56
56
  "@metamask/snaps-sdk": "^9.0.0",
57
57
  "@metamask/snaps-utils": "^11.0.0",