@metamask/accounts-controller 20.0.0 → 20.0.2
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +27 -1
- package/dist/AccountsController.cjs.map +1 -1
- package/dist/AccountsController.d.cts +1 -1
- package/dist/AccountsController.d.cts.map +1 -1
- package/dist/AccountsController.d.mts +1 -1
- package/dist/AccountsController.d.mts.map +1 -1
- package/dist/AccountsController.mjs +2 -4
- package/dist/AccountsController.mjs.map +1 -1
- package/dist/tests/mocks.cjs.map +1 -1
- package/dist/tests/mocks.d.cts +1 -1
- package/dist/tests/mocks.d.cts.map +1 -1
- package/dist/tests/mocks.d.mts +1 -1
- package/dist/tests/mocks.d.mts.map +1 -1
- package/dist/tests/mocks.mjs +1 -2
- package/dist/tests/mocks.mjs.map +1 -1
- package/dist/utils.mjs +1 -2
- package/dist/utils.mjs.map +1 -1
- package/package.json +11 -6
package/CHANGELOG.md
CHANGED
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [20.0.2]
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
|
14
|
+
- Use new `@metamask/keyring-internal-api@^1.0.0` ([#4695](https://github.com/MetaMask/core/pull/4695))
|
15
|
+
- This package has been split out from the Keyring API.
|
16
|
+
- Bump `@metamask/keyring-api` from `^10.1.0` to `^12.0.0` ([#4695](https://github.com/MetaMask/core/pull/4695))
|
17
|
+
- Bump `@metamask/eth-snap-keyring` from `^5.0.1` to `^7.0.0` ([#4695](https://github.com/MetaMask/core/pull/4695))
|
18
|
+
- ESM/CommonJS support.
|
19
|
+
|
20
|
+
## [20.0.1]
|
21
|
+
|
22
|
+
### Fixed
|
23
|
+
|
24
|
+
- Make implicit peer dependencies explicit ([#4974](https://github.com/MetaMask/core/pull/4974))
|
25
|
+
- Add the following packages as peer dependencies of this package to satisfy peer dependency requirements from other dependencies:
|
26
|
+
- `@metamask/providers` `^18.1.0` (required by `@metamask/keyring-api`)
|
27
|
+
- `webextension-polyfill` `^0.10.0 || ^0.11.0 || ^0.12.0` (required by `@metamask/providers`)
|
28
|
+
- These dependencies really should be present in projects that consume this package (e.g. MetaMask clients), and this change ensures that they now are.
|
29
|
+
- Furthermore, we are assuming that clients already use these dependencies, since otherwise it would be impossible to consume this package in its entirety or even create a working build. Hence, the addition of these peer dependencies is really a formality and should not be breaking.
|
30
|
+
- Correct ESM-compatible build so that imports of the following packages that re-export other modules via `export *` are no longer corrupted: ([#5011](https://github.com/MetaMask/core/pull/5011))
|
31
|
+
- `@metamask/keyring-api`
|
32
|
+
- `@metamask/eth-snap-keyring`
|
33
|
+
|
10
34
|
## [20.0.0]
|
11
35
|
|
12
36
|
### Changed
|
@@ -354,7 +378,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
354
378
|
|
355
379
|
- Initial release ([#1637](https://github.com/MetaMask/core/pull/1637))
|
356
380
|
|
357
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@20.0.
|
381
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@20.0.2...HEAD
|
382
|
+
[20.0.2]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@20.0.1...@metamask/accounts-controller@20.0.2
|
383
|
+
[20.0.1]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@20.0.0...@metamask/accounts-controller@20.0.1
|
358
384
|
[20.0.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@19.0.0...@metamask/accounts-controller@20.0.0
|
359
385
|
[19.0.0]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@18.2.3...@metamask/accounts-controller@19.0.0
|
360
386
|
[18.2.3]: https://github.com/MetaMask/core/compare/@metamask/accounts-controller@18.2.2...@metamask/accounts-controller@18.2.3
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AccountsController.cjs","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":";;;;;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C/B,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,qBAAqB,EACtC,IAAI,CAAC,kBAAkB,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 type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type { InternalAccount } from '@metamask/keyring-api';\nimport {\n EthAccountType,\n EthMethod,\n isEvmAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type {\n KeyringControllerState,\n KeyringControllerGetKeyringForAccountAction,\n KeyringControllerGetKeyringsByTypeAction,\n KeyringControllerGetAccountsAction,\n KeyringControllerStateChangeEvent,\n} from '@metamask/keyring-controller';\nimport type {\n SnapControllerState,\n SnapStateChange,\n} from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport type { CaipChainId } from '@metamask/utils';\nimport {\n type Keyring,\n type Json,\n isCaipChainId,\n parseCaipChainId,\n} from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport {\n getUUIDFromAddressOfNormalAccount,\n isNormalKeyringType,\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 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 | KeyringControllerGetKeyringForAccountAction\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetAccountsAction;\n\nexport type AccountsControllerActions =\n | AccountsControllerGetStateAction\n | AccountsControllerSetSelectedAccountAction\n | AccountsControllerListAccountsAction\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerSetAccountNameAction\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 AllowedEvents = SnapStateChange | KeyringControllerStateChangeEvent;\n\nexport type AccountsControllerEvents =\n | AccountsControllerChangeEvent\n | AccountsControllerSelectedAccountChangeEvent\n | AccountsControllerSelectedEvmAccountChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountRenamedEvent;\n\nexport type AccountsControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n AccountsControllerActions | AllowedActions,\n AccountsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\ntype AddressAndKeyringTypeObject = {\n address: string;\n type: string;\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 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.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.#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 this.#isAccountCompatibleWithChain(account, chainId),\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 // 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 (this.state.internalAccounts.selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n const selectedAccount = this.getAccountExpect(\n this.state.internalAccounts.selectedAccount,\n );\n if (isEvmAccountType(selectedAccount.type)) {\n return selectedAccount;\n }\n\n const accounts = this.listAccounts();\n\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 // 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 (this.state.internalAccounts.selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n if (!chainId) {\n return this.getAccountExpect(this.state.internalAccounts.selectedAccount);\n }\n\n if (!isCaipChainId(chainId)) {\n throw new Error(`Invalid CAIP-2 chain ID: ${chainId as string}`);\n }\n\n const accounts = Object.values(this.state.internalAccounts.accounts).filter(\n (account) => this.#isAccountCompatibleWithChain(account, chainId),\n );\n\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 * @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 this.update((currentState: Draft<AccountsControllerState>) => {\n currentState.internalAccounts.accounts[account.id].metadata.lastSelected =\n Date.now();\n currentState.internalAccounts.selectedAccount = account.id;\n });\n\n this.#publishAccountChangeEvent(account);\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 * 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 (\n metadata.name &&\n this.listMultichainAccounts().find(\n (internalAccount) =>\n internalAccount.metadata.name === metadata.name &&\n internalAccount.id !== accountId,\n )\n ) {\n throw new Error('Account name already exists');\n }\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n const internalAccount = {\n ...account,\n metadata: { ...account.metadata, ...metadata },\n };\n // Do not remove this comment - This error is flaky: Comment out or restore the `ts-expect-error` directive below as needed.\n // See: https://github.com/MetaMask/utils/issues/168\n // @ts-expect-error Known issue - `Json` causes recursive error in immer `Draft`/`WritableDraft` types\n currentState.internalAccounts.accounts[accountId] = internalAccount;\n\n if (metadata.name) {\n this.messagingSystem.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\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 snapAccounts = await this.#listSnapAccounts();\n const normalAccounts = await this.#listNormalAccounts();\n\n // keyring type map.\n const keyringTypes = new Map<string, number>();\n const previousAccounts = this.state.internalAccounts.accounts;\n\n const accounts: Record<string, InternalAccount> = [\n ...normalAccounts,\n ...snapAccounts,\n ].reduce((internalAccountMap, internalAccount) => {\n const keyringTypeName = keyringTypeToName(\n internalAccount.metadata.keyring.type,\n );\n const keyringAccountIndex = keyringTypes.get(keyringTypeName) ?? 0;\n if (keyringAccountIndex) {\n keyringTypes.set(keyringTypeName, keyringAccountIndex + 1);\n } else {\n keyringTypes.set(keyringTypeName, 1);\n }\n\n const existingAccount = previousAccounts[internalAccount.id];\n\n internalAccountMap[internalAccount.id] = {\n ...internalAccount,\n\n metadata: {\n ...internalAccount.metadata,\n name:\n this.#populateExistingMetadata(existingAccount?.id, 'name') ??\n `${keyringTypeName} ${keyringAccountIndex + 1}`,\n importTime:\n this.#populateExistingMetadata(existingAccount?.id, 'importTime') ??\n Date.now(),\n lastSelected:\n this.#populateExistingMetadata(\n existingAccount?.id,\n 'lastSelected',\n ) ?? 0,\n },\n };\n\n return internalAccountMap;\n }, {} as Record<string, InternalAccount>);\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n currentState.internalAccounts.accounts = accounts;\n\n if (\n !currentState.internalAccounts.accounts[\n currentState.internalAccounts.selectedAccount\n ]\n ) {\n const lastSelectedAccount = this.#getLastSelectedAccount(\n Object.values(accounts),\n );\n\n if (lastSelectedAccount) {\n currentState.internalAccounts.selectedAccount =\n lastSelectedAccount.id;\n currentState.internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n this.#publishAccountChangeEvent(lastSelectedAccount);\n } else {\n // It will be undefined if there are no accounts\n currentState.internalAccounts.selectedAccount = '';\n }\n }\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: Draft<AccountsControllerState>) => {\n currentState.internalAccounts = backup.internalAccounts;\n });\n }\n }\n\n /**\n * Generates an internal account for a non-Snap account.\n * @param address - The address of the account.\n * @param type - The type of the account.\n * @returns The generated internal account.\n */\n #generateInternalAccountForNonSnapAccount(\n address: string,\n type: string,\n ): InternalAccount {\n return {\n id: getUUIDFromAddressOfNormalAccount(address),\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 type: EthAccountType.Eoa,\n metadata: {\n name: '',\n importTime: Date.now(),\n keyring: {\n type,\n },\n },\n };\n }\n\n /**\n * Returns a list of internal accounts created using the SnapKeyring.\n *\n * @returns A promise that resolves to an array of InternalAccount objects.\n */\n async #listSnapAccounts(): Promise<InternalAccount[]> {\n const [snapKeyring] = this.messagingSystem.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n // snap keyring is not available until the first account is created in the keyring controller\n if (!snapKeyring) {\n return [];\n }\n\n const snapAccounts = (snapKeyring as SnapKeyring).listAccounts();\n\n return snapAccounts;\n }\n\n /**\n * Returns a list of normal accounts.\n * Note: listNormalAccounts is a temporary method until the keyrings all implement the InternalAccount interface.\n * Once all keyrings implement the InternalAccount interface, this method can be removed and getAccounts can be used instead.\n *\n * @returns A Promise that resolves to an array of InternalAccount objects.\n */\n async #listNormalAccounts(): Promise<InternalAccount[]> {\n const addresses = await this.messagingSystem.call(\n 'KeyringController:getAccounts',\n );\n const internalAccounts: InternalAccount[] = [];\n for (const address of addresses) {\n const keyring = await this.messagingSystem.call(\n 'KeyringController:getKeyringForAccount',\n address,\n );\n\n const keyringType = (keyring as Keyring<Json>).type;\n if (!isNormalKeyringType(keyringType as KeyringTypes)) {\n // We only consider \"normal accounts\" here, so keep looping\n continue;\n }\n\n const id = getUUIDFromAddressOfNormalAccount(address);\n\n const nameLastUpdatedAt = this.#populateExistingMetadata(\n id,\n 'nameLastUpdatedAt',\n );\n\n internalAccounts.push({\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 type: EthAccountType.Eoa,\n metadata: {\n name: this.#populateExistingMetadata(id, 'name') ?? '',\n ...(nameLastUpdatedAt && { nameLastUpdatedAt }),\n importTime:\n this.#populateExistingMetadata(id, 'importTime') ?? Date.now(),\n lastSelected: this.#populateExistingMetadata(id, 'lastSelected') ?? 0,\n keyring: {\n type: (keyring as Keyring<Json>).type,\n },\n },\n });\n }\n\n return internalAccounts;\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 */\n #handleOnKeyringStateChange(keyringState: KeyringControllerState): void {\n // check if there are any new accounts added\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 (keyringState.isUnlocked && keyringState.keyrings.length > 0) {\n const updatedNormalKeyringAddresses: AddressAndKeyringTypeObject[] = [];\n const updatedSnapKeyringAddresses: AddressAndKeyringTypeObject[] = [];\n\n for (const keyring of keyringState.keyrings) {\n if (keyring.type === KeyringTypes.snap) {\n updatedSnapKeyringAddresses.push(\n ...keyring.accounts.map((address) => {\n return {\n address,\n type: keyring.type,\n };\n }),\n );\n } else {\n updatedNormalKeyringAddresses.push(\n ...keyring.accounts.map((address) => {\n return {\n address,\n type: keyring.type,\n };\n }),\n );\n }\n }\n\n const { previousNormalInternalAccounts, previousSnapInternalAccounts } =\n this.listMultichainAccounts().reduce(\n (accumulator, account) => {\n if (account.metadata.keyring.type === KeyringTypes.snap) {\n accumulator.previousSnapInternalAccounts.push(account);\n } else {\n accumulator.previousNormalInternalAccounts.push(account);\n }\n return accumulator;\n },\n {\n previousNormalInternalAccounts: [] as InternalAccount[],\n previousSnapInternalAccounts: [] as InternalAccount[],\n },\n );\n\n const addedAccounts: AddressAndKeyringTypeObject[] = [];\n const deletedAccounts: InternalAccount[] = [];\n\n // snap account ids are random uuid while normal accounts\n // are determininistic based on the address\n\n // ^NOTE: This will be removed when normal accounts also implement internal accounts\n // finding all the normal accounts that were added\n for (const account of updatedNormalKeyringAddresses) {\n if (\n !this.state.internalAccounts.accounts[\n getUUIDFromAddressOfNormalAccount(account.address)\n ]\n ) {\n addedAccounts.push(account);\n }\n }\n\n // finding all the snap accounts that were added\n for (const account of updatedSnapKeyringAddresses) {\n if (\n !previousSnapInternalAccounts.find(\n (internalAccount: InternalAccount) =>\n internalAccount.address.toLowerCase() ===\n account.address.toLowerCase(),\n )\n ) {\n addedAccounts.push(account);\n }\n }\n\n // finding all the normal accounts that were deleted\n for (const account of previousNormalInternalAccounts) {\n if (\n !updatedNormalKeyringAddresses.find(\n ({ address }) =>\n address.toLowerCase() === account.address.toLowerCase(),\n )\n ) {\n deletedAccounts.push(account);\n }\n }\n\n // finding all the snap accounts that were deleted\n for (const account of previousSnapInternalAccounts) {\n if (\n !updatedSnapKeyringAddresses.find(\n ({ address }) =>\n address.toLowerCase() === account.address.toLowerCase(),\n )\n ) {\n deletedAccounts.push(account);\n }\n }\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n if (deletedAccounts.length > 0) {\n for (const account of deletedAccounts) {\n currentState.internalAccounts.accounts = this.#handleAccountRemoved(\n currentState.internalAccounts.accounts,\n account.id,\n );\n }\n }\n\n if (addedAccounts.length > 0) {\n for (const account of addedAccounts) {\n currentState.internalAccounts.accounts =\n this.#handleNewAccountAdded(\n currentState.internalAccounts.accounts,\n account,\n );\n }\n }\n\n // We don't use list accounts because it is not the updated state yet.\n const existingAccounts = Object.values(\n currentState.internalAccounts.accounts,\n );\n\n // handle if the selected account was deleted\n if (\n !currentState.internalAccounts.accounts[\n this.state.internalAccounts.selectedAccount\n ]\n ) {\n const lastSelectedAccount =\n this.#getLastSelectedAccount(existingAccounts);\n\n if (lastSelectedAccount) {\n currentState.internalAccounts.selectedAccount =\n lastSelectedAccount.id;\n currentState.internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n this.#publishAccountChangeEvent(lastSelectedAccount);\n } else {\n // It will be undefined if there are no accounts\n currentState.internalAccounts.selectedAccount = '';\n }\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 const accounts = this.listMultichainAccounts().filter(\n (account) => account.metadata.snap,\n );\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n accounts.forEach((account) => {\n const currentAccount =\n currentState.internalAccounts.accounts[account.id];\n if (currentAccount.metadata.snap) {\n const snapId = currentAccount.metadata.snap.id;\n const storedSnap: Snap = snaps[snapId as SnapId];\n if (storedSnap) {\n currentAccount.metadata.snap.enabled =\n storedSnap.enabled && !storedSnap.blocked;\n }\n }\n });\n });\n }\n\n /**\n * Returns the list of accounts for a given keyring type.\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 (\n keyringType === KeyringTypes.hd ||\n keyringType === KeyringTypes.simple\n ) {\n return (\n internalAccount.metadata.keyring.type === KeyringTypes.hd ||\n internalAccount.metadata.keyring.type === KeyringTypes.simple\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 * @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 // ESLint is confused; this is a number.\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n lastDefaultIndexUsedForKeyringType + 1,\n );\n\n return `${keyringName} ${index}`;\n }\n\n /**\n * Checks if an account is compatible with a given chain namespace.\n * @private\n * @param account - The account to check compatibility for.\n * @param chainId - The CAIP2 to check compatibility with.\n * @returns Returns true if the account is compatible with the chain namespace, otherwise false.\n */\n #isAccountCompatibleWithChain(\n account: InternalAccount,\n chainId: CaipChainId,\n ): boolean {\n // TODO: Change this logic to not use account's type\n // Because we currently only use type, we can only use namespace for now.\n return account.type.startsWith(parseCaipChainId(chainId).namespace);\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 * Handles the addition of a new account to the controller.\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 * @param accountsState - AccountsController accounts state that is to be mutated.\n * @param account - The address and keyring type object of the new account.\n * @returns The updated AccountsController accounts state.\n */\n #handleNewAccountAdded(\n accountsState: AccountsControllerState['internalAccounts']['accounts'],\n account: AddressAndKeyringTypeObject,\n ): AccountsControllerState['internalAccounts']['accounts'] {\n let newAccount: InternalAccount;\n if (account.type !== KeyringTypes.snap) {\n newAccount = this.#generateInternalAccountForNonSnapAccount(\n account.address,\n account.type,\n );\n } else {\n const [snapKeyring] = this.messagingSystem.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n\n newAccount = (snapKeyring as SnapKeyring).getAccountByAddress(\n account.address,\n ) as InternalAccount;\n\n // The snap deleted the account before the keyring controller could add it\n if (!newAccount) {\n return accountsState;\n }\n }\n\n const isFirstAccount = Object.keys(accountsState).length === 0;\n\n // Get next account name available for this given keyring\n const accountName = this.getNextAvailableAccountName(\n newAccount.metadata.keyring.type,\n Object.values(accountsState),\n );\n\n const newAccountWithUpdatedMetadata = {\n ...newAccount,\n metadata: {\n ...newAccount.metadata,\n name: accountName,\n importTime: Date.now(),\n lastSelected: isFirstAccount ? this.#getLastSelectedIndex() : 0,\n },\n };\n accountsState[newAccount.id] = newAccountWithUpdatedMetadata;\n\n this.messagingSystem.publish(\n 'AccountsController:accountAdded',\n newAccountWithUpdatedMetadata,\n );\n\n return accountsState;\n }\n\n #publishAccountChangeEvent(account: InternalAccount) {\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 * Handles the removal of an account from the internal accounts list.\n * @param accountsState - AccountsController accounts state that is to be mutated.\n * @param accountId - The ID of the account to be removed.\n * @returns The updated AccountsController state.\n */\n #handleAccountRemoved(\n accountsState: AccountsControllerState['internalAccounts']['accounts'],\n accountId: string,\n ): AccountsControllerState['internalAccounts']['accounts'] {\n delete accountsState[accountId];\n\n this.messagingSystem.publish(\n 'AccountsController:accountRemoved',\n accountId,\n );\n\n return accountsState;\n }\n\n /**\n * Retrieves the value of a specific metadata key for an existing account.\n * @param accountId - The ID of the account.\n * @param metadataKey - The key of the metadata to retrieve.\n * @param account - The account object to retrieve the metadata key from.\n * @returns The value of the specified metadata key, or undefined if the account or metadata key does not exist.\n */\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n #populateExistingMetadata<T extends keyof InternalAccount['metadata']>(\n accountId: string,\n metadataKey: T,\n account?: InternalAccount,\n ): InternalAccount['metadata'][T] | undefined {\n const internalAccount = account ?? this.getAccount(accountId);\n return internalAccount ? internalAccount.metadata[metadataKey] : undefined;\n }\n\n /**\n * Registers message handlers for the AccountsController.\n * @private\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}: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":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IAAI,CAAC,CAC/B,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,qBAAqB,EACtC,IAAI,CAAC,kBAAkB,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 type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport {\n EthAccountType,\n EthMethod,\n isEvmAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type {\n KeyringControllerState,\n KeyringControllerGetKeyringForAccountAction,\n KeyringControllerGetKeyringsByTypeAction,\n KeyringControllerGetAccountsAction,\n KeyringControllerStateChangeEvent,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type {\n SnapControllerState,\n SnapStateChange,\n} from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport type { CaipChainId } from '@metamask/utils';\nimport {\n type Keyring,\n type Json,\n isCaipChainId,\n parseCaipChainId,\n} from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport {\n getUUIDFromAddressOfNormalAccount,\n isNormalKeyringType,\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 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 | KeyringControllerGetKeyringForAccountAction\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetAccountsAction;\n\nexport type AccountsControllerActions =\n | AccountsControllerGetStateAction\n | AccountsControllerSetSelectedAccountAction\n | AccountsControllerListAccountsAction\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerSetAccountNameAction\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 AllowedEvents = SnapStateChange | KeyringControllerStateChangeEvent;\n\nexport type AccountsControllerEvents =\n | AccountsControllerChangeEvent\n | AccountsControllerSelectedAccountChangeEvent\n | AccountsControllerSelectedEvmAccountChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountRenamedEvent;\n\nexport type AccountsControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n AccountsControllerActions | AllowedActions,\n AccountsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\ntype AddressAndKeyringTypeObject = {\n address: string;\n type: string;\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 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.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.#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 this.#isAccountCompatibleWithChain(account, chainId),\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 // 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 (this.state.internalAccounts.selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n const selectedAccount = this.getAccountExpect(\n this.state.internalAccounts.selectedAccount,\n );\n if (isEvmAccountType(selectedAccount.type)) {\n return selectedAccount;\n }\n\n const accounts = this.listAccounts();\n\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 // 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 (this.state.internalAccounts.selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n if (!chainId) {\n return this.getAccountExpect(this.state.internalAccounts.selectedAccount);\n }\n\n if (!isCaipChainId(chainId)) {\n throw new Error(`Invalid CAIP-2 chain ID: ${chainId as string}`);\n }\n\n const accounts = Object.values(this.state.internalAccounts.accounts).filter(\n (account) => this.#isAccountCompatibleWithChain(account, chainId),\n );\n\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 * @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 this.update((currentState: Draft<AccountsControllerState>) => {\n currentState.internalAccounts.accounts[account.id].metadata.lastSelected =\n Date.now();\n currentState.internalAccounts.selectedAccount = account.id;\n });\n\n this.#publishAccountChangeEvent(account);\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 * 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 (\n metadata.name &&\n this.listMultichainAccounts().find(\n (internalAccount) =>\n internalAccount.metadata.name === metadata.name &&\n internalAccount.id !== accountId,\n )\n ) {\n throw new Error('Account name already exists');\n }\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n const internalAccount = {\n ...account,\n metadata: { ...account.metadata, ...metadata },\n };\n // Do not remove this comment - This error is flaky: Comment out or restore the `ts-expect-error` directive below as needed.\n // See: https://github.com/MetaMask/utils/issues/168\n // @ts-expect-error Known issue - `Json` causes recursive error in immer `Draft`/`WritableDraft` types\n currentState.internalAccounts.accounts[accountId] = internalAccount;\n\n if (metadata.name) {\n this.messagingSystem.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\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 snapAccounts = await this.#listSnapAccounts();\n const normalAccounts = await this.#listNormalAccounts();\n\n // keyring type map.\n const keyringTypes = new Map<string, number>();\n const previousAccounts = this.state.internalAccounts.accounts;\n\n const accounts: Record<string, InternalAccount> = [\n ...normalAccounts,\n ...snapAccounts,\n ].reduce((internalAccountMap, internalAccount) => {\n const keyringTypeName = keyringTypeToName(\n internalAccount.metadata.keyring.type,\n );\n const keyringAccountIndex = keyringTypes.get(keyringTypeName) ?? 0;\n if (keyringAccountIndex) {\n keyringTypes.set(keyringTypeName, keyringAccountIndex + 1);\n } else {\n keyringTypes.set(keyringTypeName, 1);\n }\n\n const existingAccount = previousAccounts[internalAccount.id];\n\n internalAccountMap[internalAccount.id] = {\n ...internalAccount,\n\n metadata: {\n ...internalAccount.metadata,\n name:\n this.#populateExistingMetadata(existingAccount?.id, 'name') ??\n `${keyringTypeName} ${keyringAccountIndex + 1}`,\n importTime:\n this.#populateExistingMetadata(existingAccount?.id, 'importTime') ??\n Date.now(),\n lastSelected:\n this.#populateExistingMetadata(\n existingAccount?.id,\n 'lastSelected',\n ) ?? 0,\n },\n };\n\n return internalAccountMap;\n }, {} as Record<string, InternalAccount>);\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n currentState.internalAccounts.accounts = accounts;\n\n if (\n !currentState.internalAccounts.accounts[\n currentState.internalAccounts.selectedAccount\n ]\n ) {\n const lastSelectedAccount = this.#getLastSelectedAccount(\n Object.values(accounts),\n );\n\n if (lastSelectedAccount) {\n currentState.internalAccounts.selectedAccount =\n lastSelectedAccount.id;\n currentState.internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n this.#publishAccountChangeEvent(lastSelectedAccount);\n } else {\n // It will be undefined if there are no accounts\n currentState.internalAccounts.selectedAccount = '';\n }\n }\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: Draft<AccountsControllerState>) => {\n currentState.internalAccounts = backup.internalAccounts;\n });\n }\n }\n\n /**\n * Generates an internal account for a non-Snap account.\n * @param address - The address of the account.\n * @param type - The type of the account.\n * @returns The generated internal account.\n */\n #generateInternalAccountForNonSnapAccount(\n address: string,\n type: string,\n ): InternalAccount {\n return {\n id: getUUIDFromAddressOfNormalAccount(address),\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 type: EthAccountType.Eoa,\n metadata: {\n name: '',\n importTime: Date.now(),\n keyring: {\n type,\n },\n },\n };\n }\n\n /**\n * Returns a list of internal accounts created using the SnapKeyring.\n *\n * @returns A promise that resolves to an array of InternalAccount objects.\n */\n async #listSnapAccounts(): Promise<InternalAccount[]> {\n const [snapKeyring] = this.messagingSystem.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n // snap keyring is not available until the first account is created in the keyring controller\n if (!snapKeyring) {\n return [];\n }\n\n const snapAccounts = (snapKeyring as SnapKeyring).listAccounts();\n\n return snapAccounts;\n }\n\n /**\n * Returns a list of normal accounts.\n * Note: listNormalAccounts is a temporary method until the keyrings all implement the InternalAccount interface.\n * Once all keyrings implement the InternalAccount interface, this method can be removed and getAccounts can be used instead.\n *\n * @returns A Promise that resolves to an array of InternalAccount objects.\n */\n async #listNormalAccounts(): Promise<InternalAccount[]> {\n const addresses = await this.messagingSystem.call(\n 'KeyringController:getAccounts',\n );\n const internalAccounts: InternalAccount[] = [];\n for (const address of addresses) {\n const keyring = await this.messagingSystem.call(\n 'KeyringController:getKeyringForAccount',\n address,\n );\n\n const keyringType = (keyring as Keyring<Json>).type;\n if (!isNormalKeyringType(keyringType as KeyringTypes)) {\n // We only consider \"normal accounts\" here, so keep looping\n continue;\n }\n\n const id = getUUIDFromAddressOfNormalAccount(address);\n\n const nameLastUpdatedAt = this.#populateExistingMetadata(\n id,\n 'nameLastUpdatedAt',\n );\n\n internalAccounts.push({\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 type: EthAccountType.Eoa,\n metadata: {\n name: this.#populateExistingMetadata(id, 'name') ?? '',\n ...(nameLastUpdatedAt && { nameLastUpdatedAt }),\n importTime:\n this.#populateExistingMetadata(id, 'importTime') ?? Date.now(),\n lastSelected: this.#populateExistingMetadata(id, 'lastSelected') ?? 0,\n keyring: {\n type: (keyring as Keyring<Json>).type,\n },\n },\n });\n }\n\n return internalAccounts;\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 */\n #handleOnKeyringStateChange(keyringState: KeyringControllerState): void {\n // check if there are any new accounts added\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 (keyringState.isUnlocked && keyringState.keyrings.length > 0) {\n const updatedNormalKeyringAddresses: AddressAndKeyringTypeObject[] = [];\n const updatedSnapKeyringAddresses: AddressAndKeyringTypeObject[] = [];\n\n for (const keyring of keyringState.keyrings) {\n if (keyring.type === KeyringTypes.snap) {\n updatedSnapKeyringAddresses.push(\n ...keyring.accounts.map((address) => {\n return {\n address,\n type: keyring.type,\n };\n }),\n );\n } else {\n updatedNormalKeyringAddresses.push(\n ...keyring.accounts.map((address) => {\n return {\n address,\n type: keyring.type,\n };\n }),\n );\n }\n }\n\n const { previousNormalInternalAccounts, previousSnapInternalAccounts } =\n this.listMultichainAccounts().reduce(\n (accumulator, account) => {\n if (account.metadata.keyring.type === KeyringTypes.snap) {\n accumulator.previousSnapInternalAccounts.push(account);\n } else {\n accumulator.previousNormalInternalAccounts.push(account);\n }\n return accumulator;\n },\n {\n previousNormalInternalAccounts: [] as InternalAccount[],\n previousSnapInternalAccounts: [] as InternalAccount[],\n },\n );\n\n const addedAccounts: AddressAndKeyringTypeObject[] = [];\n const deletedAccounts: InternalAccount[] = [];\n\n // snap account ids are random uuid while normal accounts\n // are determininistic based on the address\n\n // ^NOTE: This will be removed when normal accounts also implement internal accounts\n // finding all the normal accounts that were added\n for (const account of updatedNormalKeyringAddresses) {\n if (\n !this.state.internalAccounts.accounts[\n getUUIDFromAddressOfNormalAccount(account.address)\n ]\n ) {\n addedAccounts.push(account);\n }\n }\n\n // finding all the snap accounts that were added\n for (const account of updatedSnapKeyringAddresses) {\n if (\n !previousSnapInternalAccounts.find(\n (internalAccount: InternalAccount) =>\n internalAccount.address.toLowerCase() ===\n account.address.toLowerCase(),\n )\n ) {\n addedAccounts.push(account);\n }\n }\n\n // finding all the normal accounts that were deleted\n for (const account of previousNormalInternalAccounts) {\n if (\n !updatedNormalKeyringAddresses.find(\n ({ address }) =>\n address.toLowerCase() === account.address.toLowerCase(),\n )\n ) {\n deletedAccounts.push(account);\n }\n }\n\n // finding all the snap accounts that were deleted\n for (const account of previousSnapInternalAccounts) {\n if (\n !updatedSnapKeyringAddresses.find(\n ({ address }) =>\n address.toLowerCase() === account.address.toLowerCase(),\n )\n ) {\n deletedAccounts.push(account);\n }\n }\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n if (deletedAccounts.length > 0) {\n for (const account of deletedAccounts) {\n currentState.internalAccounts.accounts = this.#handleAccountRemoved(\n currentState.internalAccounts.accounts,\n account.id,\n );\n }\n }\n\n if (addedAccounts.length > 0) {\n for (const account of addedAccounts) {\n currentState.internalAccounts.accounts =\n this.#handleNewAccountAdded(\n currentState.internalAccounts.accounts,\n account,\n );\n }\n }\n\n // We don't use list accounts because it is not the updated state yet.\n const existingAccounts = Object.values(\n currentState.internalAccounts.accounts,\n );\n\n // handle if the selected account was deleted\n if (\n !currentState.internalAccounts.accounts[\n this.state.internalAccounts.selectedAccount\n ]\n ) {\n const lastSelectedAccount =\n this.#getLastSelectedAccount(existingAccounts);\n\n if (lastSelectedAccount) {\n currentState.internalAccounts.selectedAccount =\n lastSelectedAccount.id;\n currentState.internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n this.#publishAccountChangeEvent(lastSelectedAccount);\n } else {\n // It will be undefined if there are no accounts\n currentState.internalAccounts.selectedAccount = '';\n }\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 const accounts = this.listMultichainAccounts().filter(\n (account) => account.metadata.snap,\n );\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n accounts.forEach((account) => {\n const currentAccount =\n currentState.internalAccounts.accounts[account.id];\n if (currentAccount.metadata.snap) {\n const snapId = currentAccount.metadata.snap.id;\n const storedSnap: Snap = snaps[snapId as SnapId];\n if (storedSnap) {\n currentAccount.metadata.snap.enabled =\n storedSnap.enabled && !storedSnap.blocked;\n }\n }\n });\n });\n }\n\n /**\n * Returns the list of accounts for a given keyring type.\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 (\n keyringType === KeyringTypes.hd ||\n keyringType === KeyringTypes.simple\n ) {\n return (\n internalAccount.metadata.keyring.type === KeyringTypes.hd ||\n internalAccount.metadata.keyring.type === KeyringTypes.simple\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 * @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 // ESLint is confused; this is a number.\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n lastDefaultIndexUsedForKeyringType + 1,\n );\n\n return `${keyringName} ${index}`;\n }\n\n /**\n * Checks if an account is compatible with a given chain namespace.\n * @private\n * @param account - The account to check compatibility for.\n * @param chainId - The CAIP2 to check compatibility with.\n * @returns Returns true if the account is compatible with the chain namespace, otherwise false.\n */\n #isAccountCompatibleWithChain(\n account: InternalAccount,\n chainId: CaipChainId,\n ): boolean {\n // TODO: Change this logic to not use account's type\n // Because we currently only use type, we can only use namespace for now.\n return account.type.startsWith(parseCaipChainId(chainId).namespace);\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 * Handles the addition of a new account to the controller.\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 * @param accountsState - AccountsController accounts state that is to be mutated.\n * @param account - The address and keyring type object of the new account.\n * @returns The updated AccountsController accounts state.\n */\n #handleNewAccountAdded(\n accountsState: AccountsControllerState['internalAccounts']['accounts'],\n account: AddressAndKeyringTypeObject,\n ): AccountsControllerState['internalAccounts']['accounts'] {\n let newAccount: InternalAccount;\n if (account.type !== KeyringTypes.snap) {\n newAccount = this.#generateInternalAccountForNonSnapAccount(\n account.address,\n account.type,\n );\n } else {\n const [snapKeyring] = this.messagingSystem.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n\n newAccount = (snapKeyring as SnapKeyring).getAccountByAddress(\n account.address,\n ) as InternalAccount;\n\n // The snap deleted the account before the keyring controller could add it\n if (!newAccount) {\n return accountsState;\n }\n }\n\n const isFirstAccount = Object.keys(accountsState).length === 0;\n\n // Get next account name available for this given keyring\n const accountName = this.getNextAvailableAccountName(\n newAccount.metadata.keyring.type,\n Object.values(accountsState),\n );\n\n const newAccountWithUpdatedMetadata = {\n ...newAccount,\n metadata: {\n ...newAccount.metadata,\n name: accountName,\n importTime: Date.now(),\n lastSelected: isFirstAccount ? this.#getLastSelectedIndex() : 0,\n },\n };\n accountsState[newAccount.id] = newAccountWithUpdatedMetadata;\n\n this.messagingSystem.publish(\n 'AccountsController:accountAdded',\n newAccountWithUpdatedMetadata,\n );\n\n return accountsState;\n }\n\n #publishAccountChangeEvent(account: InternalAccount) {\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 * Handles the removal of an account from the internal accounts list.\n * @param accountsState - AccountsController accounts state that is to be mutated.\n * @param accountId - The ID of the account to be removed.\n * @returns The updated AccountsController state.\n */\n #handleAccountRemoved(\n accountsState: AccountsControllerState['internalAccounts']['accounts'],\n accountId: string,\n ): AccountsControllerState['internalAccounts']['accounts'] {\n delete accountsState[accountId];\n\n this.messagingSystem.publish(\n 'AccountsController:accountRemoved',\n accountId,\n );\n\n return accountsState;\n }\n\n /**\n * Retrieves the value of a specific metadata key for an existing account.\n * @param accountId - The ID of the account.\n * @param metadataKey - The key of the metadata to retrieve.\n * @param account - The account object to retrieve the metadata key from.\n * @returns The value of the specified metadata key, or undefined if the account or metadata key does not exist.\n */\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n #populateExistingMetadata<T extends keyof InternalAccount['metadata']>(\n accountId: string,\n metadataKey: T,\n account?: InternalAccount,\n ): InternalAccount['metadata'][T] | undefined {\n const internalAccount = account ?? this.getAccount(accountId);\n return internalAccount ? internalAccount.metadata[metadataKey] : undefined;\n }\n\n /**\n * Registers message handlers for the AccountsController.\n * @private\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}: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,8 +1,8 @@
|
|
1
1
|
import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedControllerMessenger } from "@metamask/base-controller";
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
3
|
-
import type { InternalAccount } from "@metamask/keyring-api";
|
4
3
|
import { EthAccountType } from "@metamask/keyring-api";
|
5
4
|
import type { KeyringControllerGetKeyringForAccountAction, KeyringControllerGetKeyringsByTypeAction, KeyringControllerGetAccountsAction, KeyringControllerStateChangeEvent } from "@metamask/keyring-controller";
|
5
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
6
6
|
import type { SnapStateChange } from "@metamask/snaps-controllers";
|
7
7
|
import type { CaipChainId } from "@metamask/utils";
|
8
8
|
declare const controllerName = "AccountsController";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AccountsController.d.cts","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAC9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,
|
1
|
+
{"version":3,"file":"AccountsController.d.cts","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAC9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,EACL,cAAc,EAGf,8BAA8B;AAE/B,OAAO,KAAK,EAEV,2CAA2C,EAC3C,wCAAwC,EACxC,kCAAkC,EAClC,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAEV,eAAe,EAChB,oCAAoC;AAGrC,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAenD,QAAA,MAAM,cAAc,uBAAuB,CAAC;AAE5C,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,MAAM,MAAM,uBAAuB,GAAG;IACp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;;;;;OAKG;IACH,sBAAsB,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,eAAe,EAAE;IAehE;;;;;;OAMG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe;IAQpD;;;;OAIG;IACH,kBAAkB,IAAI,eAAe;IA0BrC;;;;;;;OAOG;IACH,4BAA4B,CAC1B,OAAO,CAAC,EAAE,WAAW,GACpB,eAAe,GAAG,SAAS;IAsB9B;;;;;OAKG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAMjE;;;;OAIG;IACH,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAY3C;;;;;;OAMG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAS5D;;;;;OAKG;IACH,qBAAqB,CACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,GAC7C,IAAI;IAiCP;;;;;OAKG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAyErC;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI;IAkWjD;;;;;OAKG;IACH,2BAA2B,CACzB,WAAW,GAAE,MAAwB,EACrC,QAAQ,CAAC,EAAE,eAAe,EAAE,GAC3B,MAAM;CA6OV"}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedControllerMessenger } from "@metamask/base-controller";
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
3
|
-
import type { InternalAccount } from "@metamask/keyring-api";
|
4
3
|
import { EthAccountType } from "@metamask/keyring-api";
|
5
4
|
import type { KeyringControllerGetKeyringForAccountAction, KeyringControllerGetKeyringsByTypeAction, KeyringControllerGetAccountsAction, KeyringControllerStateChangeEvent } from "@metamask/keyring-controller";
|
5
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
6
6
|
import type { SnapStateChange } from "@metamask/snaps-controllers";
|
7
7
|
import type { CaipChainId } from "@metamask/utils";
|
8
8
|
declare const controllerName = "AccountsController";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AccountsController.d.mts","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAC9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,
|
1
|
+
{"version":3,"file":"AccountsController.d.mts","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAC9B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,EACL,cAAc,EAGf,8BAA8B;AAE/B,OAAO,KAAK,EAEV,2CAA2C,EAC3C,wCAAwC,EACxC,kCAAkC,EAClC,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAEV,eAAe,EAChB,oCAAoC;AAGrC,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB;AAenD,QAAA,MAAM,cAAc,uBAAuB,CAAC;AAE5C,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,MAAM,MAAM,uBAAuB,GAAG;IACpC,gBAAgB,EAAE;QAChB,QAAQ,EAAE,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAC7C,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG,wBAAwB,CACrE,OAAO,cAAc,EACrB,uBAAuB,CACxB,CAAC;AAEF,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,GAAG,OAAO,cAAc,qBAAqB,CAA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BAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAMjE;;;;OAIG;IACH,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAY3C;;;;;;OAMG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAS5D;;;;;OAKG;IACH,qBAAqB,CACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,GAC7C,IAAI;IAiCP;;;;;OAKG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAyErC;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI;IAkWjD;;;;;OAKG;IACH,2BAA2B,CACzB,WAAW,GAAE,MAAwB,EACrC,QAAQ,CAAC,EAAE,eAAe,EAAE,GAC3B,MAAM;CA6OV"}
|
@@ -5,10 +5,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
5
5
|
};
|
6
6
|
var _AccountsController_instances, _AccountsController_generateInternalAccountForNonSnapAccount, _AccountsController_listSnapAccounts, _AccountsController_listNormalAccounts, _AccountsController_handleOnKeyringStateChange, _AccountsController_handleOnSnapStateChange, _AccountsController_getAccountsByKeyringType, _AccountsController_getLastSelectedAccount, _AccountsController_isAccountCompatibleWithChain, _AccountsController_getLastSelectedIndex, _AccountsController_handleNewAccountAdded, _AccountsController_publishAccountChangeEvent, _AccountsController_handleAccountRemoved, _AccountsController_populateExistingMetadata, _AccountsController_registerMessageHandlers;
|
7
7
|
import { BaseController } from "@metamask/base-controller";
|
8
|
-
import
|
9
|
-
|
10
|
-
import $metamaskkeyringapi from "@metamask/keyring-api";
|
11
|
-
const { EthAccountType, EthMethod, isEvmAccountType } = $metamaskkeyringapi;
|
8
|
+
import { SnapKeyring } from "@metamask/eth-snap-keyring";
|
9
|
+
import { EthAccountType, EthMethod, isEvmAccountType } from "@metamask/keyring-api";
|
12
10
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
13
11
|
import { isCaipChainId, parseCaipChainId } from "@metamask/utils";
|
14
12
|
import { getUUIDFromAddressOfNormalAccount, isNormalKeyringType, keyringTypeToName } from "./utils.mjs";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AccountsController.mjs","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;;;;;AAQ3D,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAe5D,OAAO,EAGL,aAAa,EACb,gBAAgB,EACjB,wBAAwB;AAGzB,OAAO,EACL,iCAAiC,EACjC,mBAAmB,EACnB,iBAAiB,EAClB,oBAAgB;AAEjB,MAAM,cAAc,GAAG,oBAAoB,CAAC;AA+I5C,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,QAAQ,EAAE;QACR,IAAI,EAAE,EAAE;QACR,OAAO,EAAE;YACP,IAAI,EAAE,EAAE;SACT;QACD,UAAU,EAAE,CAAC;KACd;CACF,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,kBAAmB,SAAQ,cAIvC;IACC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAIN;QACC,KAAK,CAAC;YACJ,SAAS;YACT,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,0BAA0B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IAAI,CAAC,CACvC,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,iBAAiB,EAClC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAC/B,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,iBAAiB,EAClC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAC/B,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,qBAAqB,EACtC,IAAI,CAAC,kBAAkB,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 type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type { InternalAccount } from '@metamask/keyring-api';\nimport {\n EthAccountType,\n EthMethod,\n isEvmAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type {\n KeyringControllerState,\n KeyringControllerGetKeyringForAccountAction,\n KeyringControllerGetKeyringsByTypeAction,\n KeyringControllerGetAccountsAction,\n KeyringControllerStateChangeEvent,\n} from '@metamask/keyring-controller';\nimport type {\n SnapControllerState,\n SnapStateChange,\n} from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport type { CaipChainId } from '@metamask/utils';\nimport {\n type Keyring,\n type Json,\n isCaipChainId,\n parseCaipChainId,\n} from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport {\n getUUIDFromAddressOfNormalAccount,\n isNormalKeyringType,\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 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 | KeyringControllerGetKeyringForAccountAction\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetAccountsAction;\n\nexport type AccountsControllerActions =\n | AccountsControllerGetStateAction\n | AccountsControllerSetSelectedAccountAction\n | AccountsControllerListAccountsAction\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerSetAccountNameAction\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 AllowedEvents = SnapStateChange | KeyringControllerStateChangeEvent;\n\nexport type AccountsControllerEvents =\n | AccountsControllerChangeEvent\n | AccountsControllerSelectedAccountChangeEvent\n | AccountsControllerSelectedEvmAccountChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountRenamedEvent;\n\nexport type AccountsControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n AccountsControllerActions | AllowedActions,\n AccountsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\ntype AddressAndKeyringTypeObject = {\n address: string;\n type: string;\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 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.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.#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 this.#isAccountCompatibleWithChain(account, chainId),\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 // 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 (this.state.internalAccounts.selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n const selectedAccount = this.getAccountExpect(\n this.state.internalAccounts.selectedAccount,\n );\n if (isEvmAccountType(selectedAccount.type)) {\n return selectedAccount;\n }\n\n const accounts = this.listAccounts();\n\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 // 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 (this.state.internalAccounts.selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n if (!chainId) {\n return this.getAccountExpect(this.state.internalAccounts.selectedAccount);\n }\n\n if (!isCaipChainId(chainId)) {\n throw new Error(`Invalid CAIP-2 chain ID: ${chainId as string}`);\n }\n\n const accounts = Object.values(this.state.internalAccounts.accounts).filter(\n (account) => this.#isAccountCompatibleWithChain(account, chainId),\n );\n\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 * @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 this.update((currentState: Draft<AccountsControllerState>) => {\n currentState.internalAccounts.accounts[account.id].metadata.lastSelected =\n Date.now();\n currentState.internalAccounts.selectedAccount = account.id;\n });\n\n this.#publishAccountChangeEvent(account);\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 * 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 (\n metadata.name &&\n this.listMultichainAccounts().find(\n (internalAccount) =>\n internalAccount.metadata.name === metadata.name &&\n internalAccount.id !== accountId,\n )\n ) {\n throw new Error('Account name already exists');\n }\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n const internalAccount = {\n ...account,\n metadata: { ...account.metadata, ...metadata },\n };\n // Do not remove this comment - This error is flaky: Comment out or restore the `ts-expect-error` directive below as needed.\n // See: https://github.com/MetaMask/utils/issues/168\n // @ts-expect-error Known issue - `Json` causes recursive error in immer `Draft`/`WritableDraft` types\n currentState.internalAccounts.accounts[accountId] = internalAccount;\n\n if (metadata.name) {\n this.messagingSystem.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\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 snapAccounts = await this.#listSnapAccounts();\n const normalAccounts = await this.#listNormalAccounts();\n\n // keyring type map.\n const keyringTypes = new Map<string, number>();\n const previousAccounts = this.state.internalAccounts.accounts;\n\n const accounts: Record<string, InternalAccount> = [\n ...normalAccounts,\n ...snapAccounts,\n ].reduce((internalAccountMap, internalAccount) => {\n const keyringTypeName = keyringTypeToName(\n internalAccount.metadata.keyring.type,\n );\n const keyringAccountIndex = keyringTypes.get(keyringTypeName) ?? 0;\n if (keyringAccountIndex) {\n keyringTypes.set(keyringTypeName, keyringAccountIndex + 1);\n } else {\n keyringTypes.set(keyringTypeName, 1);\n }\n\n const existingAccount = previousAccounts[internalAccount.id];\n\n internalAccountMap[internalAccount.id] = {\n ...internalAccount,\n\n metadata: {\n ...internalAccount.metadata,\n name:\n this.#populateExistingMetadata(existingAccount?.id, 'name') ??\n `${keyringTypeName} ${keyringAccountIndex + 1}`,\n importTime:\n this.#populateExistingMetadata(existingAccount?.id, 'importTime') ??\n Date.now(),\n lastSelected:\n this.#populateExistingMetadata(\n existingAccount?.id,\n 'lastSelected',\n ) ?? 0,\n },\n };\n\n return internalAccountMap;\n }, {} as Record<string, InternalAccount>);\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n currentState.internalAccounts.accounts = accounts;\n\n if (\n !currentState.internalAccounts.accounts[\n currentState.internalAccounts.selectedAccount\n ]\n ) {\n const lastSelectedAccount = this.#getLastSelectedAccount(\n Object.values(accounts),\n );\n\n if (lastSelectedAccount) {\n currentState.internalAccounts.selectedAccount =\n lastSelectedAccount.id;\n currentState.internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n this.#publishAccountChangeEvent(lastSelectedAccount);\n } else {\n // It will be undefined if there are no accounts\n currentState.internalAccounts.selectedAccount = '';\n }\n }\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: Draft<AccountsControllerState>) => {\n currentState.internalAccounts = backup.internalAccounts;\n });\n }\n }\n\n /**\n * Generates an internal account for a non-Snap account.\n * @param address - The address of the account.\n * @param type - The type of the account.\n * @returns The generated internal account.\n */\n #generateInternalAccountForNonSnapAccount(\n address: string,\n type: string,\n ): InternalAccount {\n return {\n id: getUUIDFromAddressOfNormalAccount(address),\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 type: EthAccountType.Eoa,\n metadata: {\n name: '',\n importTime: Date.now(),\n keyring: {\n type,\n },\n },\n };\n }\n\n /**\n * Returns a list of internal accounts created using the SnapKeyring.\n *\n * @returns A promise that resolves to an array of InternalAccount objects.\n */\n async #listSnapAccounts(): Promise<InternalAccount[]> {\n const [snapKeyring] = this.messagingSystem.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n // snap keyring is not available until the first account is created in the keyring controller\n if (!snapKeyring) {\n return [];\n }\n\n const snapAccounts = (snapKeyring as SnapKeyring).listAccounts();\n\n return snapAccounts;\n }\n\n /**\n * Returns a list of normal accounts.\n * Note: listNormalAccounts is a temporary method until the keyrings all implement the InternalAccount interface.\n * Once all keyrings implement the InternalAccount interface, this method can be removed and getAccounts can be used instead.\n *\n * @returns A Promise that resolves to an array of InternalAccount objects.\n */\n async #listNormalAccounts(): Promise<InternalAccount[]> {\n const addresses = await this.messagingSystem.call(\n 'KeyringController:getAccounts',\n );\n const internalAccounts: InternalAccount[] = [];\n for (const address of addresses) {\n const keyring = await this.messagingSystem.call(\n 'KeyringController:getKeyringForAccount',\n address,\n );\n\n const keyringType = (keyring as Keyring<Json>).type;\n if (!isNormalKeyringType(keyringType as KeyringTypes)) {\n // We only consider \"normal accounts\" here, so keep looping\n continue;\n }\n\n const id = getUUIDFromAddressOfNormalAccount(address);\n\n const nameLastUpdatedAt = this.#populateExistingMetadata(\n id,\n 'nameLastUpdatedAt',\n );\n\n internalAccounts.push({\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 type: EthAccountType.Eoa,\n metadata: {\n name: this.#populateExistingMetadata(id, 'name') ?? '',\n ...(nameLastUpdatedAt && { nameLastUpdatedAt }),\n importTime:\n this.#populateExistingMetadata(id, 'importTime') ?? Date.now(),\n lastSelected: this.#populateExistingMetadata(id, 'lastSelected') ?? 0,\n keyring: {\n type: (keyring as Keyring<Json>).type,\n },\n },\n });\n }\n\n return internalAccounts;\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 */\n #handleOnKeyringStateChange(keyringState: KeyringControllerState): void {\n // check if there are any new accounts added\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 (keyringState.isUnlocked && keyringState.keyrings.length > 0) {\n const updatedNormalKeyringAddresses: AddressAndKeyringTypeObject[] = [];\n const updatedSnapKeyringAddresses: AddressAndKeyringTypeObject[] = [];\n\n for (const keyring of keyringState.keyrings) {\n if (keyring.type === KeyringTypes.snap) {\n updatedSnapKeyringAddresses.push(\n ...keyring.accounts.map((address) => {\n return {\n address,\n type: keyring.type,\n };\n }),\n );\n } else {\n updatedNormalKeyringAddresses.push(\n ...keyring.accounts.map((address) => {\n return {\n address,\n type: keyring.type,\n };\n }),\n );\n }\n }\n\n const { previousNormalInternalAccounts, previousSnapInternalAccounts } =\n this.listMultichainAccounts().reduce(\n (accumulator, account) => {\n if (account.metadata.keyring.type === KeyringTypes.snap) {\n accumulator.previousSnapInternalAccounts.push(account);\n } else {\n accumulator.previousNormalInternalAccounts.push(account);\n }\n return accumulator;\n },\n {\n previousNormalInternalAccounts: [] as InternalAccount[],\n previousSnapInternalAccounts: [] as InternalAccount[],\n },\n );\n\n const addedAccounts: AddressAndKeyringTypeObject[] = [];\n const deletedAccounts: InternalAccount[] = [];\n\n // snap account ids are random uuid while normal accounts\n // are determininistic based on the address\n\n // ^NOTE: This will be removed when normal accounts also implement internal accounts\n // finding all the normal accounts that were added\n for (const account of updatedNormalKeyringAddresses) {\n if (\n !this.state.internalAccounts.accounts[\n getUUIDFromAddressOfNormalAccount(account.address)\n ]\n ) {\n addedAccounts.push(account);\n }\n }\n\n // finding all the snap accounts that were added\n for (const account of updatedSnapKeyringAddresses) {\n if (\n !previousSnapInternalAccounts.find(\n (internalAccount: InternalAccount) =>\n internalAccount.address.toLowerCase() ===\n account.address.toLowerCase(),\n )\n ) {\n addedAccounts.push(account);\n }\n }\n\n // finding all the normal accounts that were deleted\n for (const account of previousNormalInternalAccounts) {\n if (\n !updatedNormalKeyringAddresses.find(\n ({ address }) =>\n address.toLowerCase() === account.address.toLowerCase(),\n )\n ) {\n deletedAccounts.push(account);\n }\n }\n\n // finding all the snap accounts that were deleted\n for (const account of previousSnapInternalAccounts) {\n if (\n !updatedSnapKeyringAddresses.find(\n ({ address }) =>\n address.toLowerCase() === account.address.toLowerCase(),\n )\n ) {\n deletedAccounts.push(account);\n }\n }\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n if (deletedAccounts.length > 0) {\n for (const account of deletedAccounts) {\n currentState.internalAccounts.accounts = this.#handleAccountRemoved(\n currentState.internalAccounts.accounts,\n account.id,\n );\n }\n }\n\n if (addedAccounts.length > 0) {\n for (const account of addedAccounts) {\n currentState.internalAccounts.accounts =\n this.#handleNewAccountAdded(\n currentState.internalAccounts.accounts,\n account,\n );\n }\n }\n\n // We don't use list accounts because it is not the updated state yet.\n const existingAccounts = Object.values(\n currentState.internalAccounts.accounts,\n );\n\n // handle if the selected account was deleted\n if (\n !currentState.internalAccounts.accounts[\n this.state.internalAccounts.selectedAccount\n ]\n ) {\n const lastSelectedAccount =\n this.#getLastSelectedAccount(existingAccounts);\n\n if (lastSelectedAccount) {\n currentState.internalAccounts.selectedAccount =\n lastSelectedAccount.id;\n currentState.internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n this.#publishAccountChangeEvent(lastSelectedAccount);\n } else {\n // It will be undefined if there are no accounts\n currentState.internalAccounts.selectedAccount = '';\n }\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 const accounts = this.listMultichainAccounts().filter(\n (account) => account.metadata.snap,\n );\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n accounts.forEach((account) => {\n const currentAccount =\n currentState.internalAccounts.accounts[account.id];\n if (currentAccount.metadata.snap) {\n const snapId = currentAccount.metadata.snap.id;\n const storedSnap: Snap = snaps[snapId as SnapId];\n if (storedSnap) {\n currentAccount.metadata.snap.enabled =\n storedSnap.enabled && !storedSnap.blocked;\n }\n }\n });\n });\n }\n\n /**\n * Returns the list of accounts for a given keyring type.\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 (\n keyringType === KeyringTypes.hd ||\n keyringType === KeyringTypes.simple\n ) {\n return (\n internalAccount.metadata.keyring.type === KeyringTypes.hd ||\n internalAccount.metadata.keyring.type === KeyringTypes.simple\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 * @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 // ESLint is confused; this is a number.\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n lastDefaultIndexUsedForKeyringType + 1,\n );\n\n return `${keyringName} ${index}`;\n }\n\n /**\n * Checks if an account is compatible with a given chain namespace.\n * @private\n * @param account - The account to check compatibility for.\n * @param chainId - The CAIP2 to check compatibility with.\n * @returns Returns true if the account is compatible with the chain namespace, otherwise false.\n */\n #isAccountCompatibleWithChain(\n account: InternalAccount,\n chainId: CaipChainId,\n ): boolean {\n // TODO: Change this logic to not use account's type\n // Because we currently only use type, we can only use namespace for now.\n return account.type.startsWith(parseCaipChainId(chainId).namespace);\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 * Handles the addition of a new account to the controller.\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 * @param accountsState - AccountsController accounts state that is to be mutated.\n * @param account - The address and keyring type object of the new account.\n * @returns The updated AccountsController accounts state.\n */\n #handleNewAccountAdded(\n accountsState: AccountsControllerState['internalAccounts']['accounts'],\n account: AddressAndKeyringTypeObject,\n ): AccountsControllerState['internalAccounts']['accounts'] {\n let newAccount: InternalAccount;\n if (account.type !== KeyringTypes.snap) {\n newAccount = this.#generateInternalAccountForNonSnapAccount(\n account.address,\n account.type,\n );\n } else {\n const [snapKeyring] = this.messagingSystem.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n\n newAccount = (snapKeyring as SnapKeyring).getAccountByAddress(\n account.address,\n ) as InternalAccount;\n\n // The snap deleted the account before the keyring controller could add it\n if (!newAccount) {\n return accountsState;\n }\n }\n\n const isFirstAccount = Object.keys(accountsState).length === 0;\n\n // Get next account name available for this given keyring\n const accountName = this.getNextAvailableAccountName(\n newAccount.metadata.keyring.type,\n Object.values(accountsState),\n );\n\n const newAccountWithUpdatedMetadata = {\n ...newAccount,\n metadata: {\n ...newAccount.metadata,\n name: accountName,\n importTime: Date.now(),\n lastSelected: isFirstAccount ? this.#getLastSelectedIndex() : 0,\n },\n };\n accountsState[newAccount.id] = newAccountWithUpdatedMetadata;\n\n this.messagingSystem.publish(\n 'AccountsController:accountAdded',\n newAccountWithUpdatedMetadata,\n );\n\n return accountsState;\n }\n\n #publishAccountChangeEvent(account: InternalAccount) {\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 * Handles the removal of an account from the internal accounts list.\n * @param accountsState - AccountsController accounts state that is to be mutated.\n * @param accountId - The ID of the account to be removed.\n * @returns The updated AccountsController state.\n */\n #handleAccountRemoved(\n accountsState: AccountsControllerState['internalAccounts']['accounts'],\n accountId: string,\n ): AccountsControllerState['internalAccounts']['accounts'] {\n delete accountsState[accountId];\n\n this.messagingSystem.publish(\n 'AccountsController:accountRemoved',\n accountId,\n );\n\n return accountsState;\n }\n\n /**\n * Retrieves the value of a specific metadata key for an existing account.\n * @param accountId - The ID of the account.\n * @param metadataKey - The key of the metadata to retrieve.\n * @param account - The account object to retrieve the metadata key from.\n * @returns The value of the specified metadata key, or undefined if the account or metadata key does not exist.\n */\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n #populateExistingMetadata<T extends keyof InternalAccount['metadata']>(\n accountId: string,\n metadataKey: T,\n account?: InternalAccount,\n ): InternalAccount['metadata'][T] | undefined {\n const internalAccount = account ?? this.getAccount(accountId);\n return internalAccount ? internalAccount.metadata[metadataKey] : undefined;\n }\n\n /**\n * Registers message handlers for the AccountsController.\n * @private\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}: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":";;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,WAAW,EAAE,mCAAmC;AACzD,OAAO,EACL,cAAc,EACd,SAAS,EACT,gBAAgB,EACjB,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAgB5D,OAAO,EAGL,aAAa,EACb,gBAAgB,EACjB,wBAAwB;AAGzB,OAAO,EACL,iCAAiC,EACjC,mBAAmB,EACnB,iBAAiB,EAClB,oBAAgB;AAEjB,MAAM,cAAc,GAAG,oBAAoB,CAAC;AA+I5C,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,QAAQ,EAAE;QACR,IAAI,EAAE,EAAE;QACR,OAAO,EAAE;YACP,IAAI,EAAE,EAAE;SACT;QACD,UAAU,EAAE,CAAC;KACd;CACF,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,kBAAmB,SAAQ,cAIvC;IACC;;;;;;OAMG;IACH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StateChangeEvent,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport {\n EthAccountType,\n EthMethod,\n isEvmAccountType,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type {\n KeyringControllerState,\n KeyringControllerGetKeyringForAccountAction,\n KeyringControllerGetKeyringsByTypeAction,\n KeyringControllerGetAccountsAction,\n KeyringControllerStateChangeEvent,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type {\n SnapControllerState,\n SnapStateChange,\n} from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { Snap } from '@metamask/snaps-utils';\nimport type { CaipChainId } from '@metamask/utils';\nimport {\n type Keyring,\n type Json,\n isCaipChainId,\n parseCaipChainId,\n} from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport {\n getUUIDFromAddressOfNormalAccount,\n isNormalKeyringType,\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 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 | KeyringControllerGetKeyringForAccountAction\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetAccountsAction;\n\nexport type AccountsControllerActions =\n | AccountsControllerGetStateAction\n | AccountsControllerSetSelectedAccountAction\n | AccountsControllerListAccountsAction\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerSetAccountNameAction\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 AllowedEvents = SnapStateChange | KeyringControllerStateChangeEvent;\n\nexport type AccountsControllerEvents =\n | AccountsControllerChangeEvent\n | AccountsControllerSelectedAccountChangeEvent\n | AccountsControllerSelectedEvmAccountChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountRenamedEvent;\n\nexport type AccountsControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n AccountsControllerActions | AllowedActions,\n AccountsControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\ntype AddressAndKeyringTypeObject = {\n address: string;\n type: string;\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 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.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.#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 this.#isAccountCompatibleWithChain(account, chainId),\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 // 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 (this.state.internalAccounts.selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n const selectedAccount = this.getAccountExpect(\n this.state.internalAccounts.selectedAccount,\n );\n if (isEvmAccountType(selectedAccount.type)) {\n return selectedAccount;\n }\n\n const accounts = this.listAccounts();\n\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 // 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 (this.state.internalAccounts.selectedAccount === '') {\n return EMPTY_ACCOUNT;\n }\n\n if (!chainId) {\n return this.getAccountExpect(this.state.internalAccounts.selectedAccount);\n }\n\n if (!isCaipChainId(chainId)) {\n throw new Error(`Invalid CAIP-2 chain ID: ${chainId as string}`);\n }\n\n const accounts = Object.values(this.state.internalAccounts.accounts).filter(\n (account) => this.#isAccountCompatibleWithChain(account, chainId),\n );\n\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 * @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 this.update((currentState: Draft<AccountsControllerState>) => {\n currentState.internalAccounts.accounts[account.id].metadata.lastSelected =\n Date.now();\n currentState.internalAccounts.selectedAccount = account.id;\n });\n\n this.#publishAccountChangeEvent(account);\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 * 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 (\n metadata.name &&\n this.listMultichainAccounts().find(\n (internalAccount) =>\n internalAccount.metadata.name === metadata.name &&\n internalAccount.id !== accountId,\n )\n ) {\n throw new Error('Account name already exists');\n }\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n const internalAccount = {\n ...account,\n metadata: { ...account.metadata, ...metadata },\n };\n // Do not remove this comment - This error is flaky: Comment out or restore the `ts-expect-error` directive below as needed.\n // See: https://github.com/MetaMask/utils/issues/168\n // @ts-expect-error Known issue - `Json` causes recursive error in immer `Draft`/`WritableDraft` types\n currentState.internalAccounts.accounts[accountId] = internalAccount;\n\n if (metadata.name) {\n this.messagingSystem.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\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 snapAccounts = await this.#listSnapAccounts();\n const normalAccounts = await this.#listNormalAccounts();\n\n // keyring type map.\n const keyringTypes = new Map<string, number>();\n const previousAccounts = this.state.internalAccounts.accounts;\n\n const accounts: Record<string, InternalAccount> = [\n ...normalAccounts,\n ...snapAccounts,\n ].reduce((internalAccountMap, internalAccount) => {\n const keyringTypeName = keyringTypeToName(\n internalAccount.metadata.keyring.type,\n );\n const keyringAccountIndex = keyringTypes.get(keyringTypeName) ?? 0;\n if (keyringAccountIndex) {\n keyringTypes.set(keyringTypeName, keyringAccountIndex + 1);\n } else {\n keyringTypes.set(keyringTypeName, 1);\n }\n\n const existingAccount = previousAccounts[internalAccount.id];\n\n internalAccountMap[internalAccount.id] = {\n ...internalAccount,\n\n metadata: {\n ...internalAccount.metadata,\n name:\n this.#populateExistingMetadata(existingAccount?.id, 'name') ??\n `${keyringTypeName} ${keyringAccountIndex + 1}`,\n importTime:\n this.#populateExistingMetadata(existingAccount?.id, 'importTime') ??\n Date.now(),\n lastSelected:\n this.#populateExistingMetadata(\n existingAccount?.id,\n 'lastSelected',\n ) ?? 0,\n },\n };\n\n return internalAccountMap;\n }, {} as Record<string, InternalAccount>);\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n currentState.internalAccounts.accounts = accounts;\n\n if (\n !currentState.internalAccounts.accounts[\n currentState.internalAccounts.selectedAccount\n ]\n ) {\n const lastSelectedAccount = this.#getLastSelectedAccount(\n Object.values(accounts),\n );\n\n if (lastSelectedAccount) {\n currentState.internalAccounts.selectedAccount =\n lastSelectedAccount.id;\n currentState.internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n this.#publishAccountChangeEvent(lastSelectedAccount);\n } else {\n // It will be undefined if there are no accounts\n currentState.internalAccounts.selectedAccount = '';\n }\n }\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: Draft<AccountsControllerState>) => {\n currentState.internalAccounts = backup.internalAccounts;\n });\n }\n }\n\n /**\n * Generates an internal account for a non-Snap account.\n * @param address - The address of the account.\n * @param type - The type of the account.\n * @returns The generated internal account.\n */\n #generateInternalAccountForNonSnapAccount(\n address: string,\n type: string,\n ): InternalAccount {\n return {\n id: getUUIDFromAddressOfNormalAccount(address),\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 type: EthAccountType.Eoa,\n metadata: {\n name: '',\n importTime: Date.now(),\n keyring: {\n type,\n },\n },\n };\n }\n\n /**\n * Returns a list of internal accounts created using the SnapKeyring.\n *\n * @returns A promise that resolves to an array of InternalAccount objects.\n */\n async #listSnapAccounts(): Promise<InternalAccount[]> {\n const [snapKeyring] = this.messagingSystem.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n // snap keyring is not available until the first account is created in the keyring controller\n if (!snapKeyring) {\n return [];\n }\n\n const snapAccounts = (snapKeyring as SnapKeyring).listAccounts();\n\n return snapAccounts;\n }\n\n /**\n * Returns a list of normal accounts.\n * Note: listNormalAccounts is a temporary method until the keyrings all implement the InternalAccount interface.\n * Once all keyrings implement the InternalAccount interface, this method can be removed and getAccounts can be used instead.\n *\n * @returns A Promise that resolves to an array of InternalAccount objects.\n */\n async #listNormalAccounts(): Promise<InternalAccount[]> {\n const addresses = await this.messagingSystem.call(\n 'KeyringController:getAccounts',\n );\n const internalAccounts: InternalAccount[] = [];\n for (const address of addresses) {\n const keyring = await this.messagingSystem.call(\n 'KeyringController:getKeyringForAccount',\n address,\n );\n\n const keyringType = (keyring as Keyring<Json>).type;\n if (!isNormalKeyringType(keyringType as KeyringTypes)) {\n // We only consider \"normal accounts\" here, so keep looping\n continue;\n }\n\n const id = getUUIDFromAddressOfNormalAccount(address);\n\n const nameLastUpdatedAt = this.#populateExistingMetadata(\n id,\n 'nameLastUpdatedAt',\n );\n\n internalAccounts.push({\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 type: EthAccountType.Eoa,\n metadata: {\n name: this.#populateExistingMetadata(id, 'name') ?? '',\n ...(nameLastUpdatedAt && { nameLastUpdatedAt }),\n importTime:\n this.#populateExistingMetadata(id, 'importTime') ?? Date.now(),\n lastSelected: this.#populateExistingMetadata(id, 'lastSelected') ?? 0,\n keyring: {\n type: (keyring as Keyring<Json>).type,\n },\n },\n });\n }\n\n return internalAccounts;\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 */\n #handleOnKeyringStateChange(keyringState: KeyringControllerState): void {\n // check if there are any new accounts added\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 (keyringState.isUnlocked && keyringState.keyrings.length > 0) {\n const updatedNormalKeyringAddresses: AddressAndKeyringTypeObject[] = [];\n const updatedSnapKeyringAddresses: AddressAndKeyringTypeObject[] = [];\n\n for (const keyring of keyringState.keyrings) {\n if (keyring.type === KeyringTypes.snap) {\n updatedSnapKeyringAddresses.push(\n ...keyring.accounts.map((address) => {\n return {\n address,\n type: keyring.type,\n };\n }),\n );\n } else {\n updatedNormalKeyringAddresses.push(\n ...keyring.accounts.map((address) => {\n return {\n address,\n type: keyring.type,\n };\n }),\n );\n }\n }\n\n const { previousNormalInternalAccounts, previousSnapInternalAccounts } =\n this.listMultichainAccounts().reduce(\n (accumulator, account) => {\n if (account.metadata.keyring.type === KeyringTypes.snap) {\n accumulator.previousSnapInternalAccounts.push(account);\n } else {\n accumulator.previousNormalInternalAccounts.push(account);\n }\n return accumulator;\n },\n {\n previousNormalInternalAccounts: [] as InternalAccount[],\n previousSnapInternalAccounts: [] as InternalAccount[],\n },\n );\n\n const addedAccounts: AddressAndKeyringTypeObject[] = [];\n const deletedAccounts: InternalAccount[] = [];\n\n // snap account ids are random uuid while normal accounts\n // are determininistic based on the address\n\n // ^NOTE: This will be removed when normal accounts also implement internal accounts\n // finding all the normal accounts that were added\n for (const account of updatedNormalKeyringAddresses) {\n if (\n !this.state.internalAccounts.accounts[\n getUUIDFromAddressOfNormalAccount(account.address)\n ]\n ) {\n addedAccounts.push(account);\n }\n }\n\n // finding all the snap accounts that were added\n for (const account of updatedSnapKeyringAddresses) {\n if (\n !previousSnapInternalAccounts.find(\n (internalAccount: InternalAccount) =>\n internalAccount.address.toLowerCase() ===\n account.address.toLowerCase(),\n )\n ) {\n addedAccounts.push(account);\n }\n }\n\n // finding all the normal accounts that were deleted\n for (const account of previousNormalInternalAccounts) {\n if (\n !updatedNormalKeyringAddresses.find(\n ({ address }) =>\n address.toLowerCase() === account.address.toLowerCase(),\n )\n ) {\n deletedAccounts.push(account);\n }\n }\n\n // finding all the snap accounts that were deleted\n for (const account of previousSnapInternalAccounts) {\n if (\n !updatedSnapKeyringAddresses.find(\n ({ address }) =>\n address.toLowerCase() === account.address.toLowerCase(),\n )\n ) {\n deletedAccounts.push(account);\n }\n }\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n if (deletedAccounts.length > 0) {\n for (const account of deletedAccounts) {\n currentState.internalAccounts.accounts = this.#handleAccountRemoved(\n currentState.internalAccounts.accounts,\n account.id,\n );\n }\n }\n\n if (addedAccounts.length > 0) {\n for (const account of addedAccounts) {\n currentState.internalAccounts.accounts =\n this.#handleNewAccountAdded(\n currentState.internalAccounts.accounts,\n account,\n );\n }\n }\n\n // We don't use list accounts because it is not the updated state yet.\n const existingAccounts = Object.values(\n currentState.internalAccounts.accounts,\n );\n\n // handle if the selected account was deleted\n if (\n !currentState.internalAccounts.accounts[\n this.state.internalAccounts.selectedAccount\n ]\n ) {\n const lastSelectedAccount =\n this.#getLastSelectedAccount(existingAccounts);\n\n if (lastSelectedAccount) {\n currentState.internalAccounts.selectedAccount =\n lastSelectedAccount.id;\n currentState.internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n this.#publishAccountChangeEvent(lastSelectedAccount);\n } else {\n // It will be undefined if there are no accounts\n currentState.internalAccounts.selectedAccount = '';\n }\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 const accounts = this.listMultichainAccounts().filter(\n (account) => account.metadata.snap,\n );\n\n this.update((currentState: Draft<AccountsControllerState>) => {\n accounts.forEach((account) => {\n const currentAccount =\n currentState.internalAccounts.accounts[account.id];\n if (currentAccount.metadata.snap) {\n const snapId = currentAccount.metadata.snap.id;\n const storedSnap: Snap = snaps[snapId as SnapId];\n if (storedSnap) {\n currentAccount.metadata.snap.enabled =\n storedSnap.enabled && !storedSnap.blocked;\n }\n }\n });\n });\n }\n\n /**\n * Returns the list of accounts for a given keyring type.\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 (\n keyringType === KeyringTypes.hd ||\n keyringType === KeyringTypes.simple\n ) {\n return (\n internalAccount.metadata.keyring.type === KeyringTypes.hd ||\n internalAccount.metadata.keyring.type === KeyringTypes.simple\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 * @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 // ESLint is confused; this is a number.\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n lastDefaultIndexUsedForKeyringType + 1,\n );\n\n return `${keyringName} ${index}`;\n }\n\n /**\n * Checks if an account is compatible with a given chain namespace.\n * @private\n * @param account - The account to check compatibility for.\n * @param chainId - The CAIP2 to check compatibility with.\n * @returns Returns true if the account is compatible with the chain namespace, otherwise false.\n */\n #isAccountCompatibleWithChain(\n account: InternalAccount,\n chainId: CaipChainId,\n ): boolean {\n // TODO: Change this logic to not use account's type\n // Because we currently only use type, we can only use namespace for now.\n return account.type.startsWith(parseCaipChainId(chainId).namespace);\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 * Handles the addition of a new account to the controller.\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 * @param accountsState - AccountsController accounts state that is to be mutated.\n * @param account - The address and keyring type object of the new account.\n * @returns The updated AccountsController accounts state.\n */\n #handleNewAccountAdded(\n accountsState: AccountsControllerState['internalAccounts']['accounts'],\n account: AddressAndKeyringTypeObject,\n ): AccountsControllerState['internalAccounts']['accounts'] {\n let newAccount: InternalAccount;\n if (account.type !== KeyringTypes.snap) {\n newAccount = this.#generateInternalAccountForNonSnapAccount(\n account.address,\n account.type,\n );\n } else {\n const [snapKeyring] = this.messagingSystem.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n\n newAccount = (snapKeyring as SnapKeyring).getAccountByAddress(\n account.address,\n ) as InternalAccount;\n\n // The snap deleted the account before the keyring controller could add it\n if (!newAccount) {\n return accountsState;\n }\n }\n\n const isFirstAccount = Object.keys(accountsState).length === 0;\n\n // Get next account name available for this given keyring\n const accountName = this.getNextAvailableAccountName(\n newAccount.metadata.keyring.type,\n Object.values(accountsState),\n );\n\n const newAccountWithUpdatedMetadata = {\n ...newAccount,\n metadata: {\n ...newAccount.metadata,\n name: accountName,\n importTime: Date.now(),\n lastSelected: isFirstAccount ? this.#getLastSelectedIndex() : 0,\n },\n };\n accountsState[newAccount.id] = newAccountWithUpdatedMetadata;\n\n this.messagingSystem.publish(\n 'AccountsController:accountAdded',\n newAccountWithUpdatedMetadata,\n );\n\n return accountsState;\n }\n\n #publishAccountChangeEvent(account: InternalAccount) {\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 * Handles the removal of an account from the internal accounts list.\n * @param accountsState - AccountsController accounts state that is to be mutated.\n * @param accountId - The ID of the account to be removed.\n * @returns The updated AccountsController state.\n */\n #handleAccountRemoved(\n accountsState: AccountsControllerState['internalAccounts']['accounts'],\n accountId: string,\n ): AccountsControllerState['internalAccounts']['accounts'] {\n delete accountsState[accountId];\n\n this.messagingSystem.publish(\n 'AccountsController:accountRemoved',\n accountId,\n );\n\n return accountsState;\n }\n\n /**\n * Retrieves the value of a specific metadata key for an existing account.\n * @param accountId - The ID of the account.\n * @param metadataKey - The key of the metadata to retrieve.\n * @param account - The account object to retrieve the metadata key from.\n * @returns The value of the specified metadata key, or undefined if the account or metadata key does not exist.\n */\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n #populateExistingMetadata<T extends keyof InternalAccount['metadata']>(\n accountId: string,\n metadataKey: T,\n account?: InternalAccount,\n ): InternalAccount['metadata'][T] | undefined {\n const internalAccount = account ?? this.getAccount(accountId);\n return internalAccount ? internalAccount.metadata[metadataKey] : undefined;\n }\n\n /**\n * Registers message handlers for the AccountsController.\n * @private\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}: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"]}
|
package/dist/tests/mocks.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mocks.cjs","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"mocks.cjs","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":";;;AAAA,uDAK+B;AAC/B,qEAA4D;AAK5D,+BAA0B;AAEnB,MAAM,yBAAyB,GAAG,CAAC,EACxC,EAAE,GAAG,IAAA,SAAE,GAAE,EACT,OAAO,GAAG,4CAA4C,EACtD,IAAI,GAAG,4BAAc,CAAC,GAAG,EACzB,IAAI,GAAG,WAAW,EAClB,WAAW,GAAG,iCAAY,CAAC,EAAE,EAC7B,IAAI,EACJ,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,EACvB,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,MAcvB,EAAE,EAAmB,EAAE;IACzB,IAAI,OAAO,CAAC;IAEZ,QAAQ,IAAI,EAAE;QACZ,KAAK,4BAAc,CAAC,GAAG;YACrB,OAAO,GAAG;gBACR,uBAAS,CAAC,YAAY;gBACtB,uBAAS,CAAC,IAAI;gBACd,uBAAS,CAAC,eAAe;gBACzB,uBAAS,CAAC,eAAe;gBACzB,uBAAS,CAAC,eAAe;gBACzB,uBAAS,CAAC,eAAe;aAC1B,CAAC;YACF,MAAM;QACR,KAAK,4BAAc,CAAC,OAAO;YACzB,OAAO,GAAG;gBACR,uBAAS,CAAC,kBAAkB;gBAC5B,uBAAS,CAAC,oBAAoB;gBAC9B,uBAAS,CAAC,iBAAiB;aAC5B,CAAC;YACF,MAAM;QACR,KAAK,4BAAc,CAAC,MAAM;YACxB,OAAO,GAAG,CAAC,uBAAS,CAAC,WAAW,CAAC,CAAC;YAClC,MAAM;QACR;YACE,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAc,EAAE,CAAC,CAAC;KAC9D;IAED,OAAO;QACL,EAAE;QACF,OAAO;QACP,OAAO,EAAE,EAAE;QACX,OAAO;QACP,IAAI;QACJ,QAAQ,EAAE;YACR,IAAI;YACJ,OAAO,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YAC9B,UAAU;YACV,YAAY;YACZ,IAAI;SACL;KACiB,CAAC;AACvB,CAAC,CAAC;AAhEW,QAAA,yBAAyB,6BAgEpC","sourcesContent":["import {\n BtcAccountType,\n EthAccountType,\n BtcMethod,\n EthMethod,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type {\n InternalAccount,\n InternalAccountType,\n} from '@metamask/keyring-internal-api';\nimport { v4 } from 'uuid';\n\nexport const createMockInternalAccount = ({\n id = v4(),\n address = '0x2990079bcdee240329a520d2444386fc119da21a',\n type = EthAccountType.Eoa,\n name = 'Account 1',\n keyringType = KeyringTypes.hd,\n snap,\n importTime = Date.now(),\n lastSelected = Date.now(),\n}: {\n id?: string;\n address?: string;\n type?: InternalAccountType;\n name?: string;\n keyringType?: KeyringTypes;\n snap?: {\n id: string;\n enabled: boolean;\n name: string;\n };\n importTime?: number;\n lastSelected?: number;\n} = {}): InternalAccount => {\n let methods;\n\n switch (type) {\n case EthAccountType.Eoa:\n methods = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n ];\n break;\n case EthAccountType.Erc4337:\n methods = [\n EthMethod.PatchUserOperation,\n EthMethod.PrepareUserOperation,\n EthMethod.SignUserOperation,\n ];\n break;\n case BtcAccountType.P2wpkh:\n methods = [BtcMethod.SendBitcoin];\n break;\n default:\n throw new Error(`Unknown account type: ${type as string}`);\n }\n\n return {\n id,\n address,\n options: {},\n methods,\n type,\n metadata: {\n name,\n keyring: { type: keyringType },\n importTime,\n lastSelected,\n snap,\n },\n } as InternalAccount;\n};\n"]}
|
package/dist/tests/mocks.d.cts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import type { InternalAccount, InternalAccountType } from "@metamask/keyring-api";
|
2
1
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
2
|
+
import type { InternalAccount, InternalAccountType } from "@metamask/keyring-internal-api";
|
3
3
|
export declare const createMockInternalAccount: ({ id, address, type, name, keyringType, snap, importTime, lastSelected, }?: {
|
4
4
|
id?: string | undefined;
|
5
5
|
address?: string | undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mocks.d.cts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"mocks.d.cts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAC5D,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACpB,uCAAuC;AAGxC,eAAO,MAAM,yBAAyB;;;;;;;YAgB9B,MAAM;iBACD,OAAO;cACV,MAAM;;;;MAIP,eA0CR,CAAC"}
|
package/dist/tests/mocks.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import type { InternalAccount, InternalAccountType } from "@metamask/keyring-api";
|
2
1
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
2
|
+
import type { InternalAccount, InternalAccountType } from "@metamask/keyring-internal-api";
|
3
3
|
export declare const createMockInternalAccount: ({ id, address, type, name, keyringType, snap, importTime, lastSelected, }?: {
|
4
4
|
id?: string | undefined;
|
5
5
|
address?: string | undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mocks.d.mts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"mocks.d.mts","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAC5D,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACpB,uCAAuC;AAGxC,eAAO,MAAM,yBAAyB;;;;;;;YAgB9B,MAAM;iBACD,OAAO;cACV,MAAM;;;;MAIP,eA0CR,CAAC"}
|
package/dist/tests/mocks.mjs
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import
|
2
|
-
const { BtcAccountType, BtcMethod, EthAccountType, EthMethod } = $metamaskkeyringapi;
|
1
|
+
import { BtcAccountType, EthAccountType, BtcMethod, EthMethod } from "@metamask/keyring-api";
|
3
2
|
import { KeyringTypes } from "@metamask/keyring-controller";
|
4
3
|
import { v4 } from "uuid";
|
5
4
|
export const createMockInternalAccount = ({ id = v4(), address = '0x2990079bcdee240329a520d2444386fc119da21a', type = EthAccountType.Eoa, name = 'Account 1', keyringType = KeyringTypes.hd, snap, importTime = Date.now(), lastSelected = Date.now(), } = {}) => {
|
package/dist/tests/mocks.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mocks.mjs","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"mocks.mjs","sourceRoot":"","sources":["../../src/tests/mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,SAAS,EACT,SAAS,EACV,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAK5D,OAAO,EAAE,EAAE,EAAE,aAAa;AAE1B,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,EACxC,EAAE,GAAG,EAAE,EAAE,EACT,OAAO,GAAG,4CAA4C,EACtD,IAAI,GAAG,cAAc,CAAC,GAAG,EACzB,IAAI,GAAG,WAAW,EAClB,WAAW,GAAG,YAAY,CAAC,EAAE,EAC7B,IAAI,EACJ,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,EACvB,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,MAcvB,EAAE,EAAmB,EAAE;IACzB,IAAI,OAAO,CAAC;IAEZ,QAAQ,IAAI,EAAE;QACZ,KAAK,cAAc,CAAC,GAAG;YACrB,OAAO,GAAG;gBACR,SAAS,CAAC,YAAY;gBACtB,SAAS,CAAC,IAAI;gBACd,SAAS,CAAC,eAAe;gBACzB,SAAS,CAAC,eAAe;gBACzB,SAAS,CAAC,eAAe;gBACzB,SAAS,CAAC,eAAe;aAC1B,CAAC;YACF,MAAM;QACR,KAAK,cAAc,CAAC,OAAO;YACzB,OAAO,GAAG;gBACR,SAAS,CAAC,kBAAkB;gBAC5B,SAAS,CAAC,oBAAoB;gBAC9B,SAAS,CAAC,iBAAiB;aAC5B,CAAC;YACF,MAAM;QACR,KAAK,cAAc,CAAC,MAAM;YACxB,OAAO,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;YAClC,MAAM;QACR;YACE,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAc,EAAE,CAAC,CAAC;KAC9D;IAED,OAAO;QACL,EAAE;QACF,OAAO;QACP,OAAO,EAAE,EAAE;QACX,OAAO;QACP,IAAI;QACJ,QAAQ,EAAE;YACR,IAAI;YACJ,OAAO,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YAC9B,UAAU;YACV,YAAY;YACZ,IAAI;SACL;KACiB,CAAC;AACvB,CAAC,CAAC","sourcesContent":["import {\n BtcAccountType,\n EthAccountType,\n BtcMethod,\n EthMethod,\n} from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type {\n InternalAccount,\n InternalAccountType,\n} from '@metamask/keyring-internal-api';\nimport { v4 } from 'uuid';\n\nexport const createMockInternalAccount = ({\n id = v4(),\n address = '0x2990079bcdee240329a520d2444386fc119da21a',\n type = EthAccountType.Eoa,\n name = 'Account 1',\n keyringType = KeyringTypes.hd,\n snap,\n importTime = Date.now(),\n lastSelected = Date.now(),\n}: {\n id?: string;\n address?: string;\n type?: InternalAccountType;\n name?: string;\n keyringType?: KeyringTypes;\n snap?: {\n id: string;\n enabled: boolean;\n name: string;\n };\n importTime?: number;\n lastSelected?: number;\n} = {}): InternalAccount => {\n let methods;\n\n switch (type) {\n case EthAccountType.Eoa:\n methods = [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n ];\n break;\n case EthAccountType.Erc4337:\n methods = [\n EthMethod.PatchUserOperation,\n EthMethod.PrepareUserOperation,\n EthMethod.SignUserOperation,\n ];\n break;\n case BtcAccountType.P2wpkh:\n methods = [BtcMethod.SendBitcoin];\n break;\n default:\n throw new Error(`Unknown account type: ${type as string}`);\n }\n\n return {\n id,\n address,\n options: {},\n methods,\n type,\n metadata: {\n name,\n keyring: { type: keyringType },\n importTime,\n lastSelected,\n snap,\n },\n } as InternalAccount;\n};\n"]}
|
package/dist/utils.mjs
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import
|
2
|
-
const { toBuffer } = $ethereumjsutil;
|
1
|
+
import { toBuffer } from "@ethereumjs/util";
|
3
2
|
import { isCustodyKeyring, KeyringTypes } from "@metamask/keyring-controller";
|
4
3
|
import { sha256 } from "ethereum-cryptography/sha256";
|
5
4
|
import { v4 as uuid } from "uuid";
|
package/dist/utils.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,E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,OAAO,IAAI,CAAC,wCAAwC,CAAC,OAAO,CAAC,CAAC,CAAC;AACjE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,WAAyB;IAC3D,gFAAgF;IAChF,oDAAoD;IACpD,OAAO,WAAW,KAAK,YAAY,CAAC,IAAI,CAAC;AAC3C,CAAC","sourcesContent":["import { toBuffer } from '@ethereumjs/util';\nimport { isCustodyKeyring, KeyringTypes } from '@metamask/keyring-controller';\nimport { sha256 } from 'ethereum-cryptography/sha256';\nimport type { V4Options } from 'uuid';\nimport { v4 as uuid } from 'uuid';\n\n/**\n * Returns the name of the keyring type.\n *\n * @param keyringType - The type of the keyring.\n * @returns The name of the keyring type.\n */\nexport function keyringTypeToName(keyringType: string): string {\n // Custody keyrings are a special case, as they are not a single type\n // they just start with the prefix `Custody`\n if (isCustodyKeyring(keyringType)) {\n return 'Custody';\n }\n\n switch (keyringType) {\n case KeyringTypes.simple: {\n return 'Account';\n }\n case KeyringTypes.hd: {\n return 'Account';\n }\n case KeyringTypes.trezor: {\n return 'Trezor';\n }\n case KeyringTypes.ledger: {\n return 'Ledger';\n }\n case KeyringTypes.lattice: {\n return 'Lattice';\n }\n case KeyringTypes.qr: {\n return 'QR';\n }\n case KeyringTypes.snap: {\n return 'Snap Account';\n }\n default: {\n throw new Error(`Unknown keyring ${keyringType}`);\n }\n }\n}\n\n/**\n * Generates a UUID v4 options from a given Ethereum address.\n * @param address - The Ethereum address to generate the UUID from.\n * @returns The UUID v4 options.\n */\nexport function getUUIDOptionsFromAddressOfNormalAccount(\n address: string,\n): V4Options {\n const v4options = {\n random: sha256(toBuffer(address)).slice(0, 16),\n };\n\n return v4options;\n}\n\n/**\n * Generates a UUID from a given Ethereum address.\n * @param address - The Ethereum address to generate the UUID from.\n * @returns The generated UUID.\n */\nexport function getUUIDFromAddressOfNormalAccount(address: string): string {\n return uuid(getUUIDOptionsFromAddressOfNormalAccount(address));\n}\n\n/**\n * Check if a keyring type is considered a \"normal\" keyring.\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is considered a \"normal\" keyring, false otherwise.\n */\nexport function isNormalKeyringType(keyringType: KeyringTypes): boolean {\n // Right now, we only have to \"exclude\" Snap accounts, but this might need to be\n // adapted later on if we have new kind of keyrings!\n return keyringType !== KeyringTypes.snap;\n}\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@metamask/accounts-controller",
|
3
|
-
"version": "20.0.
|
3
|
+
"version": "20.0.2",
|
4
4
|
"description": "Manages internal accounts",
|
5
5
|
"keywords": [
|
6
6
|
"MetaMask",
|
@@ -49,8 +49,9 @@
|
|
49
49
|
"dependencies": {
|
50
50
|
"@ethereumjs/util": "^8.1.0",
|
51
51
|
"@metamask/base-controller": "^7.0.2",
|
52
|
-
"@metamask/eth-snap-keyring": "^
|
53
|
-
"@metamask/keyring-api": "^
|
52
|
+
"@metamask/eth-snap-keyring": "^7.0.0",
|
53
|
+
"@metamask/keyring-api": "^12.0.0",
|
54
|
+
"@metamask/keyring-internal-api": "^1.0.0",
|
54
55
|
"@metamask/snaps-sdk": "^6.7.0",
|
55
56
|
"@metamask/snaps-utils": "^8.3.0",
|
56
57
|
"@metamask/utils": "^10.0.0",
|
@@ -61,7 +62,8 @@
|
|
61
62
|
},
|
62
63
|
"devDependencies": {
|
63
64
|
"@metamask/auto-changelog": "^3.4.4",
|
64
|
-
"@metamask/keyring-controller": "^19.0.
|
65
|
+
"@metamask/keyring-controller": "^19.0.2",
|
66
|
+
"@metamask/providers": "^18.1.1",
|
65
67
|
"@metamask/snaps-controllers": "^9.10.0",
|
66
68
|
"@types/jest": "^27.4.1",
|
67
69
|
"@types/readable-stream": "^2.3.0",
|
@@ -69,11 +71,14 @@
|
|
69
71
|
"ts-jest": "^27.1.4",
|
70
72
|
"typedoc": "^0.24.8",
|
71
73
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
72
|
-
"typescript": "~5.2.2"
|
74
|
+
"typescript": "~5.2.2",
|
75
|
+
"webextension-polyfill": "^0.12.0"
|
73
76
|
},
|
74
77
|
"peerDependencies": {
|
75
78
|
"@metamask/keyring-controller": "^19.0.0",
|
76
|
-
"@metamask/
|
79
|
+
"@metamask/providers": "^18.1.0",
|
80
|
+
"@metamask/snaps-controllers": "^9.7.0",
|
81
|
+
"webextension-polyfill": "^0.10.0 || ^0.11.0 || ^0.12.0"
|
77
82
|
},
|
78
83
|
"engines": {
|
79
84
|
"node": "^18.18 || >=20"
|