@metamask-previews/accounts-controller 40.0.0-preview-5e76941 → 40.0.0-preview-2bc848240

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -11,9 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
 
12
12
  - Filter out MPC accounts when replicating `KeyringController` state ([#10577](https://github.com/MetaMask/core/pull/10577))
13
13
  - Those accounts are treated differently with their own "account-like" controller.
14
- - Add support for watch-only accounts (`KeyringType.WatchOnly`): watch-only accounts are now synced directly from the watch-only keyring (like Snap keyring v2 accounts), keeping the keyring's account IDs and their empty list of signing methods, instead of being re-created as EVM accounts without signing methods ([#10571](https://github.com/MetaMask/core/pull/10571))
15
- - Watch-only accounts are named "Watch-only Account" by default, and `keyringTypeToName` no longer throws for the watch-only keyring type
16
- - Export a new `isWatchOnlyKeyringType` utility
17
14
 
18
15
  ### Changed
19
16
 
@@ -1 +1 @@
1
- {"version":3,"file":"AccountsController.d.ts","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EACV,uCAAuC,EACvC,sCAAsC,EACtC,0CAA0C,EAC3C,MAAM,4BAA4B,CAAC;AAMpC,OAAO,EACL,cAAc,EAEd,QAAQ,EAGT,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAEV,wCAAwC,EACxC,iCAAiC,EACjC,+BAA+B,EAEhC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGtE,OAAO,KAAK,EAAE,SAAS,EAAuB,MAAM,qBAAqB,CAAC;AAG1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBA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;;;OAOG;IACH,sBAAsB,CAAC,OAAO,CAAC,EAAE,WAAW,GAAG,eAAe,EAAE,CAa/D;IAmBD;;;;;;OAMG;IACH,kBAAkB,IAAI,eAAe,CAyBpC;IAED;;;;;;;;;OASG;IACH,4BAA4B,CAC1B,OAAO,CAAC,EAAE,WAAW,GACpB,eAAe,GAAG,SAAS,CAiB7B;IAED;;;;;;;;OAQG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAkBhE;IAED;;;;;;OAMG;IACH,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAa1C;IAED;;;;;;;;OAQG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAO3D;IAED;;;;;;;;OAQG;IACH,8BAA8B,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAwB3E;IAiBD;;;;;;;OAOG;IACH,qBAAqB,CACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,GAC7C,IAAI,CAsBN;IAED;;;;;;;OAOG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAkEpC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI,CAYhD;IAED;;;;;OAKG;IACH,UAAU,IAAI,IAAI,CAajB;CAwjBF"}
@@ -7,7 +7,7 @@ import { isScopeEqualToAny } from '@metamask/keyring-utils';
7
7
  import { isCaipChainId } from '@metamask/utils';
8
8
  import { cloneDeep } from 'lodash-es';
9
9
  import { projectLogger as log } from './logger.js';
10
- import { constructAccountIdByAddress, getEvmDerivationPathForIndex, getEvmGroupIndexFromAddressIndex, getUUIDFromAddressOfNormalAccount, isHdKeyringType, isHdSnapKeyringAccount, isSkippedKeyringType, isSnapKeyringType, isSnapKeyringV2Type, isWatchOnlyKeyringType, keyringTypeToName, } from './utils.js';
10
+ import { constructAccountIdByAddress, getEvmDerivationPathForIndex, getEvmGroupIndexFromAddressIndex, getUUIDFromAddressOfNormalAccount, isHdKeyringType, isHdSnapKeyringAccount, isSkippedKeyringType, isSnapKeyringType, isSnapKeyringV2Type, keyringTypeToName, } from './utils.js';
11
11
  const controllerName = 'AccountsController';
12
12
  const MESSENGER_EXPOSED_METHODS = [
13
13
  'setSelectedAccount',
@@ -536,87 +536,47 @@ export class AccountsController extends BaseController {
536
536
  return snapKeyring.getAccountByAddress(address);
537
537
  }
538
538
  /**
539
- * Get an account from a v2 keyring, by iterating over all the keyrings of
540
- * the given type and looking up the account by address.
541
- *
542
- * NOTE: `:getKeyringsByType` will only return v1 instances, that's why we need to use their v1
543
- * adapter + `unwrap` method to get the reference to their v2 instance.
539
+ * Get an account from a Snap keyring v2.
544
540
  *
545
- * @param keyringType - The type of the keyrings to look into.
546
541
  * @param address - The address of the account to retrieve.
547
- * @param createAccount - Callback to create the final internal account, given the account
548
- * retrieved from the keyring and the keyring itself.
549
- * @returns The account if available.
550
- * @template KeyringV2WithLookup - The concrete type of the v2 keyring.
542
+ * @returns The Snap account if available.
551
543
  */
552
- #getAccountFromV2Keyrings(keyringType, address, createAccount) {
553
- const keyrings = this.messenger.call('KeyringController:getKeyringsByType', keyringType);
544
+ #getAccountFromSnapKeyringV2(address) {
545
+ const keyrings = this.messenger.call('KeyringController:getKeyringsByType', KeyringType.Snap);
546
+ // Snap keyring v2 are "per-Snaps" (and can be accessed using their v1 adapter), so we need to
547
+ // iterate over all of them to find the account.
548
+ // NOTE: `:getKeyringsByType` will only return v1 instances, that's why we need to use their v1
549
+ // adapter + `unwrap` method to get the reference to their v2 instance.
554
550
  for (const keyring of keyrings) {
555
551
  if (keyring instanceof KeyringV1Adapter) {
556
- // NOTE: We are already filtering by `keyringType`, so we are sure that those adapters
557
- // are wrapping a keyring of that type.
552
+ // NOTE: We already filtering by `KeyringType.Snap`, so we are sure that those adapters
553
+ // are wrapping a Snap keyring v2.
558
554
  const adapter = keyring;
559
555
  const keyringV2 = adapter.unwrap();
560
556
  // We use the synchronous method here since this method is used during `:stateChange` that are
561
557
  // use synchronous handlers.
562
558
  const account = keyringV2.lookupByAddress(address);
563
559
  if (account) {
564
- return createAccount(account, keyringV2);
560
+ return {
561
+ ...account,
562
+ // We still have to use internal account for now, so we inject some metadata.
563
+ metadata: {
564
+ name: '',
565
+ importTime: Date.now(),
566
+ lastSelected: 0,
567
+ keyring: {
568
+ type: KeyringType.Snap,
569
+ },
570
+ snap: {
571
+ id: keyringV2.snapId,
572
+ },
573
+ },
574
+ };
565
575
  }
566
576
  }
567
577
  }
568
578
  return undefined;
569
579
  }
570
- /**
571
- * Get an account from a Snap keyring v2.
572
- *
573
- * @param address - The address of the account to retrieve.
574
- * @returns The Snap account if available.
575
- */
576
- #getAccountFromSnapKeyringV2(address) {
577
- // Snap keyring v2 are "per-Snaps" (and can be accessed using their v1 adapter), so we need to
578
- // iterate over all of them to find the account.
579
- return this.#getAccountFromV2Keyrings(KeyringType.Snap, address, (account, keyringV2) => ({
580
- ...account,
581
- // We still have to use internal account for now, so we inject some metadata.
582
- metadata: {
583
- name: '',
584
- importTime: Date.now(),
585
- lastSelected: 0,
586
- keyring: {
587
- type: KeyringType.Snap,
588
- },
589
- snap: {
590
- id: keyringV2.snapId,
591
- },
592
- },
593
- }));
594
- }
595
- /**
596
- * Get an account from a watch-only keyring.
597
- *
598
- * @param address - The address of the account to retrieve.
599
- * @returns The watch-only account if available.
600
- */
601
- #getAccountFromWatchOnlyKeyring(address) {
602
- // There is usually only one watch-only keyring, but we iterate over all of
603
- // them to find the account, in case more than one was added.
604
- // The watch-only account is read from the keyring itself, keeping its ID
605
- // and its (empty) list of methods, so we don't re-create an EVM account
606
- // without signing methods.
607
- return this.#getAccountFromV2Keyrings(KeyringType.WatchOnly, address, (account) => ({
608
- ...account,
609
- // We still have to use internal account for now, so we inject some metadata.
610
- metadata: {
611
- name: '',
612
- importTime: Date.now(),
613
- lastSelected: 0,
614
- keyring: {
615
- type: KeyringType.WatchOnly,
616
- },
617
- },
618
- }));
619
- }
620
580
  /**
621
581
  * Re-publish an account event.
622
582
  *
@@ -856,12 +816,6 @@ export class AccountsController extends BaseController {
856
816
  }
857
817
  return account;
858
818
  }
859
- // Watch-only accounts are read from the watch-only keyring itself (like
860
- // Snap v2 accounts), so we don't re-create an EVM account without signing
861
- // methods for them.
862
- if (isWatchOnlyKeyringType(keyring.type)) {
863
- return this.#getAccountFromWatchOnlyKeyring(address);
864
- }
865
819
  return this.#getInternalAccountForNonSnapAccount(address, keyring);
866
820
  }
867
821
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"AccountsController.js","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAK3D,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAWzD,OAAO,EACL,cAAc,EACd,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,+BAA+B,GAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAUvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAE,aAAa,IAAI,GAAG,EAAE,MAAM,aAAa,CAAC;AASnD,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,gCAAgC,EAChC,iCAAiC,EACjC,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,MAAM,cAAc,GAAG,o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C,CAC/C,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,4CAA4C,EAC5C,CAAC,gBAAgB,EAAE,EAAE,CACnB,IAAI,CAAC,gCAAgC,CACnC,4CAA4C,EAC5C,gBAAgB,CACjB,CACJ,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,2CAA2C,EAC3C,CAAC,gBAAgB,EAAE,EAAE,CACnB,IAAI,CAAC,gCAAgC,CACnC,2CAA2C,EAC3C,gBAAgB,CACjB,CACJ,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,+CAA+C,EAC/C,CAAC,gBAAgB,EAAE,EAAE,CACnB,IAAI,CAAC,gCAAgC,CACnC,+CAA+C,EAC/C,gBAAgB,CACjB,CACJ,CAAC;QAEF,2DAA2D;QAC3D,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,8CAA8C,EAC9C,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,mCAAmC,CAAC,EAAE,CAAC,CACrD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type {\n SnapKeyringAccountAssetListUpdatedEvent,\n SnapKeyringAccountBalancesUpdatedEvent,\n SnapKeyringAccountTransactionsUpdatedEvent,\n} from '@metamask/eth-snap-keyring';\nimport { SnapKeyring as SnapKeyringV2 } from '@metamask/eth-snap-keyring/v2';\nimport type {\n KeyringAccount,\n KeyringAccountEntropyOptions,\n} from '@metamask/keyring-api';\nimport {\n EthAccountType,\n EthMethod,\n EthScope,\n isEvmAccountType,\n KeyringAccountEntropyTypeOption,\n} from '@metamask/keyring-api';\nimport { KeyringType } from '@metamask/keyring-api/v2';\nimport type { Keyring as KeyringV2 } from '@metamask/keyring-api/v2';\nimport type {\n KeyringControllerState,\n KeyringControllerGetKeyringsByTypeAction,\n KeyringControllerStateChangeEvent,\n KeyringControllerGetStateAction,\n KeyringObject,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringV1Adapter } from '@metamask/keyring-sdk/v2';\nimport { isScopeEqualToAny } from '@metamask/keyring-utils';\nimport type { Messenger, ExtractEventPayload } from '@metamask/messenger';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { isCaipChainId } from '@metamask/utils';\nimport type { CaipChainId } from '@metamask/utils';\nimport type { WritableDraft } from 'immer';\nimport { cloneDeep } from 'lodash-es';\n\nimport { AccountsControllerMethodActions } from './AccountsController-method-action-types.js';\nimport { projectLogger as log } from './logger.js';\nimport type {\n MultichainNetworkControllerNetworkDidChangeEvent,\n SnapAccountServiceAccountAssetListUpdatedEvent,\n SnapAccountServiceAccountBalancesUpdatedEvent,\n SnapAccountServiceAccountTransactionsUpdatedEvent,\n} from './types.js';\nimport type { AccountsControllerStrictState } from './typing.js';\nimport type { HdSnapKeyringAccount } from './utils.js';\nimport {\n constructAccountIdByAddress,\n getEvmDerivationPathForIndex,\n getEvmGroupIndexFromAddressIndex,\n getUUIDFromAddressOfNormalAccount,\n isHdKeyringType,\n isHdSnapKeyringAccount,\n isSkippedKeyringType,\n isSnapKeyringType,\n isSnapKeyringV2Type,\n isWatchOnlyKeyringType,\n keyringTypeToName,\n} from './utils.js';\n\nconst controllerName = 'AccountsController';\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountId = string;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerState = {\n internalAccounts: {\n accounts: Record<AccountId, InternalAccount>;\n selectedAccount: string; // id of the selected account\n };\n accountIdByAddress: Record<InternalAccount['address'], AccountId>;\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AccountsControllerState\n>;\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'setSelectedAccount',\n 'setAccountName',\n 'setAccountNameAndSelectAccount',\n 'listAccounts',\n 'listMultichainAccounts',\n 'updateAccounts',\n 'getSelectedAccount',\n 'getSelectedMultichainAccount',\n 'getAccountByAddress',\n 'getAccount',\n 'getAccounts',\n 'updateAccountMetadata',\n 'loadBackup',\n 'clearState',\n] as const;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AllowedActions =\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetStateAction;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerActions =\n | AccountsControllerGetStateAction\n | AccountsControllerMethodActions;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AccountsControllerState\n>;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerSelectedAccountChangeEvent = {\n type: `${typeof controllerName}:selectedAccountChange`;\n payload: [InternalAccount];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerSelectedEvmAccountChangeEvent = {\n type: `${typeof controllerName}:selectedEvmAccountChange`;\n payload: [InternalAccount];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerAccountAddedEvent = {\n type: `${typeof controllerName}:accountAdded`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountsAddedEvent = {\n type: `${typeof controllerName}:accountsAdded`;\n payload: [InternalAccount[]];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerAccountRemovedEvent = {\n type: `${typeof controllerName}:accountRemoved`;\n payload: [AccountId];\n};\n\nexport type AccountsControllerAccountsRemovedEvent = {\n type: `${typeof controllerName}:accountsRemoved`;\n payload: [AccountId[]];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerAccountRenamedEvent = {\n type: `${typeof controllerName}:accountRenamed`;\n payload: [InternalAccount];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerAccountBalancesUpdatesEvent = {\n type: `${typeof controllerName}:accountBalancesUpdated`;\n payload: SnapKeyringAccountBalancesUpdatedEvent['payload'];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerAccountTransactionsUpdatedEvent = {\n type: `${typeof controllerName}:accountTransactionsUpdated`;\n payload: SnapKeyringAccountTransactionsUpdatedEvent['payload'];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerAccountAssetListUpdatedEvent = {\n type: `${typeof controllerName}:accountAssetListUpdated`;\n payload: SnapKeyringAccountAssetListUpdatedEvent['payload'];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AllowedEvents =\n | KeyringControllerStateChangeEvent\n | SnapAccountServiceAccountAssetListUpdatedEvent\n | SnapAccountServiceAccountBalancesUpdatedEvent\n | SnapAccountServiceAccountTransactionsUpdatedEvent\n | MultichainNetworkControllerNetworkDidChangeEvent;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerEvents =\n | AccountsControllerChangeEvent\n | AccountsControllerSelectedAccountChangeEvent\n | AccountsControllerSelectedEvmAccountChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountsAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountsRemovedEvent\n | AccountsControllerAccountRenamedEvent\n | AccountsControllerAccountBalancesUpdatesEvent\n | AccountsControllerAccountTransactionsUpdatedEvent\n | AccountsControllerAccountAssetListUpdatedEvent;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerMessenger = Messenger<\n typeof controllerName,\n AccountsControllerActions | AllowedActions,\n AccountsControllerEvents | AllowedEvents\n>;\n\nconst accountsControllerMetadata = {\n internalAccounts: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n accountIdByAddress: {\n includeInStateLogs: false,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\n/**\n * Returns the default state for the AccountsController.\n *\n * @deprecated This function is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @returns The default AccountsController state.\n */\nexport function getDefaultAccountsControllerState(): AccountsControllerState {\n return {\n internalAccounts: {\n accounts: {},\n selectedAccount: '',\n },\n accountIdByAddress: {},\n };\n}\n\n/**\n * @deprecated This constant is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport const EMPTY_ACCOUNT = {\n id: '',\n address: '',\n options: {},\n methods: [],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: '',\n keyring: {\n type: '',\n },\n importTime: 0,\n },\n};\n\n/**\n * A patch representing a keyring state change.\n */\ntype StatePatch = {\n previous: Record<string, InternalAccount>;\n added: {\n address: string;\n keyring: KeyringObject;\n }[];\n updated: InternalAccount[];\n removed: InternalAccount[];\n};\n\n/**\n * A v2 keyring that supports looking up accounts by address synchronously.\n */\ntype KeyringWithLookup = KeyringV2 & {\n lookupByAddress(address: string): KeyringAccount | undefined;\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 * @deprecated This class is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\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 const accountIdByAddress = constructAccountIdByAddress(\n state?.internalAccounts?.accounts ?? {},\n );\n super({\n messenger,\n name: controllerName,\n metadata: accountsControllerMetadata,\n state: {\n ...getDefaultAccountsControllerState(),\n ...state,\n accountIdByAddress,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.#subscribeToMessageEvents();\n }\n\n /**\n * Returns the internal account object for the given account ID, if it exists.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\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 the internal account objects for the given account IDs, if they exist.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param accountIds - The IDs of the accounts to retrieve.\n * @returns The internal account objects, or undefined if the account(s) do not exist.\n */\n getAccounts(accountIds: string[]): (InternalAccount | undefined)[] {\n return accountIds.map((accountId) => this.getAccount(accountId));\n }\n\n /**\n * Returns an array of all evm internal accounts.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\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 * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param chainId - The chain ID.\n * @returns An array of InternalAccount objects.\n */\n listMultichainAccounts(chainId?: CaipChainId): InternalAccount[] {\n const accounts = Object.values(this.state.internalAccounts.accounts);\n if (!chainId) {\n return accounts;\n }\n\n if (!isCaipChainId(chainId)) {\n throw new Error(`Invalid CAIP-2 chain ID: ${String(chainId)}`);\n }\n\n return accounts.filter((account) =>\n isScopeEqualToAny(chainId, account.scopes),\n );\n }\n\n /**\n * Returns the internal account object for the given account ID.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\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 * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @returns The selected internal account.\n */\n getSelectedAccount(): InternalAccount {\n const {\n internalAccounts: { selectedAccount },\n } = this.state;\n\n // Edge case where the extension is setup but the srp is not yet created\n // certain ui elements will query the selected address before any accounts are created.\n if (!selectedAccount) {\n return EMPTY_ACCOUNT;\n }\n\n const account = this.#getAccountExpect(selectedAccount);\n if (isEvmAccountType(account.type)) {\n return account;\n }\n\n const accounts = this.listAccounts();\n if (!accounts.length) {\n // ! Should never reach this.\n throw new Error('No EVM accounts');\n }\n\n // This will never be undefined because we have already checked if accounts.length is > 0\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.#getLastSelectedAccount(accounts)!;\n }\n\n /**\n * __WARNING The return value may be undefined if there isn't an account for that chain id.__\n *\n * Retrieves the last selected account by chain ID.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param chainId - The chain ID to filter the accounts.\n * @returns The last selected account compatible with the specified chain ID or undefined.\n */\n getSelectedMultichainAccount(\n chainId?: CaipChainId,\n ): InternalAccount | undefined {\n const {\n internalAccounts: { selectedAccount },\n } = this.state;\n\n // Edge case where the extension is setup but the srp is not yet created\n // certain ui elements will query the selected address before any accounts are created.\n if (!selectedAccount) {\n return EMPTY_ACCOUNT;\n }\n\n if (!chainId) {\n return this.#getAccountExpect(selectedAccount);\n }\n\n const accounts = this.listMultichainAccounts(chainId);\n return this.#getLastSelectedAccount(accounts);\n }\n\n /**\n * Returns the account with the specified address.\n * ! This method will only return the first account that matches the address\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\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 // We need to have a fallback as a cache miss might be attributed to a checksummed address being passed.\n let accountId = this.state.accountIdByAddress[address];\n if (!accountId) {\n // FIXME: We should not need lower-cased addresses, but some consumers might\n // still be using non-normalized addresses. For now we keep it\n // for convenience, but we will need to remove this fallback\n // at some point.\n // NOTE: We should only hit that branch for EVM accounts only.\n const lowercasedAddress = address.toLowerCase();\n accountId = this.state.accountIdByAddress[lowercasedAddress];\n if (accountId) {\n log(\n `Cache missed for account ID: ${accountId}, received address: \"${address}\", matched address: \"${lowercasedAddress}\"`,\n );\n }\n }\n return accountId ? this.getAccount(accountId) : undefined;\n }\n\n /**\n * Sets the selected account by its ID.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param accountId - The ID of the account to be selected.\n */\n setSelectedAccount(accountId: string): void {\n const account = this.#getAccountExpect(accountId);\n\n if (this.state.internalAccounts.selectedAccount === account.id) {\n return;\n }\n\n this.#update((state) => {\n const { internalAccounts } = state;\n\n internalAccounts.accounts[account.id].metadata.lastSelected = Date.now();\n internalAccounts.selectedAccount = account.id;\n });\n }\n\n /**\n * Sets the name of the account with the given ID.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param accountId - The ID of the account to set the name for.\n * @param accountName - The new name for the account.\n * @throws An error if an account with the same name already exists.\n */\n setAccountName(accountId: string, accountName: string): void {\n // This will check for name uniqueness and fire the `accountRenamed` event\n // if the account has been renamed.\n this.updateAccountMetadata(accountId, {\n name: accountName,\n nameLastUpdatedAt: Date.now(),\n });\n }\n\n /**\n * Sets the name of the account with the given ID and select it.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param accountId - The ID of the account to set the name for and select.\n * @param accountName - The new name for the account.\n * @throws An error if an account with the same name already exists.\n */\n setAccountNameAndSelectAccount(accountId: string, accountName: string): void {\n const account = this.#getAccountExpect(accountId);\n\n this.#assertAccountCanBeRenamed(account, accountName);\n\n const internalAccount = {\n ...account,\n metadata: {\n ...account.metadata,\n name: accountName,\n nameLastUpdatedAt: Date.now(),\n lastSelected: this.#getLastSelectedIndex(),\n },\n };\n\n this.#update((state) => {\n state.internalAccounts.accounts[account.id] = internalAccount;\n state.internalAccounts.selectedAccount = account.id;\n });\n\n this.messenger.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\n }\n\n #assertAccountCanBeRenamed(\n account: InternalAccount,\n accountName: string,\n ): void {\n if (\n this.listMultichainAccounts().find(\n (internalAccount) =>\n internalAccount.metadata.name === accountName &&\n internalAccount.id !== account.id,\n )\n ) {\n throw new Error('Account name already exists');\n }\n }\n\n /**\n * Updates the metadata of the account with the given ID.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param accountId - The ID of the account for which the metadata will be updated.\n * @param metadata - The new metadata for the account.\n */\n updateAccountMetadata(\n accountId: string,\n metadata: Partial<InternalAccount['metadata']>,\n ): void {\n const account = this.#getAccountExpect(accountId);\n\n if (metadata.name) {\n this.#assertAccountCanBeRenamed(account, metadata.name);\n }\n\n const internalAccount = {\n ...account,\n metadata: { ...account.metadata, ...metadata },\n };\n\n this.#update((state) => {\n state.internalAccounts.accounts[accountId] = internalAccount;\n });\n\n if (metadata.name) {\n this.messenger.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\n }\n }\n\n /**\n * Updates the internal accounts list by retrieving normal and snap accounts,\n * removing duplicates, and updating the metadata of each account.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @returns A Promise that resolves when the accounts have been updated.\n */\n async updateAccounts(): Promise<void> {\n log('Synchronizing accounts with keyrings...');\n\n const keyringAccountIndexes = new Map<string, number>();\n\n const existingInternalAccounts = this.state.internalAccounts.accounts;\n const internalAccounts: AccountsControllerState['internalAccounts']['accounts'] =\n {};\n\n const { keyrings } = this.messenger.call('KeyringController:getState');\n for (const keyring of keyrings) {\n const { type } = keyring;\n\n // Skipped accounts (Money or MPC) are not treated as real accounts, they are owned by their\n // respective controllers, so we need to filter them out here.\n if (isSkippedKeyringType(type)) {\n continue;\n }\n\n const keyringTypeName = keyringTypeToName(keyring.type);\n\n for (const address of keyring.accounts) {\n const internalAccount = this.#getInternalAccountFromAddressAndType(\n address,\n keyring,\n );\n\n // This should never really happen, but if for some reason we're not\n // able to get the Snap keyring reference, this would return an\n // undefined account.\n // So we just skip it, even though, this should not really happen.\n if (!internalAccount) {\n continue;\n }\n\n // Get current index for this keyring (we use human indexing, so start at 1).\n const keyringAccountIndex =\n keyringAccountIndexes.get(keyringTypeName) ?? 1;\n\n const existingAccount = existingInternalAccounts[internalAccount.id];\n internalAccounts[internalAccount.id] = {\n ...internalAccount,\n\n metadata: {\n ...internalAccount.metadata,\n\n // Re-use existing metadata if any.\n name:\n existingAccount?.metadata.name ??\n `${keyringTypeName} ${keyringAccountIndex}`,\n importTime: existingAccount?.metadata.importTime ?? Date.now(),\n lastSelected: existingAccount?.metadata.lastSelected ?? 0,\n },\n };\n\n // Increment the account index for this keyring.\n keyringAccountIndexes.set(keyringTypeName, keyringAccountIndex + 1);\n }\n }\n\n this.#update((state) => {\n state.internalAccounts.accounts = internalAccounts;\n state.accountIdByAddress = constructAccountIdByAddress(internalAccounts);\n });\n\n log('Accounts synchronized!');\n }\n\n /**\n * Loads the backup state of the accounts controller.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param backup - The backup state to load.\n */\n loadBackup(backup: AccountsControllerState): void {\n if (backup.internalAccounts) {\n const accountIdByAddress = constructAccountIdByAddress(\n backup.internalAccounts.accounts,\n );\n this.update(\n (currentState: WritableDraft<AccountsControllerStrictState>) => {\n currentState.internalAccounts = backup.internalAccounts;\n currentState.accountIdByAddress = accountIdByAddress;\n },\n );\n }\n }\n\n /**\n * Clears the controller state and resets to default values.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\n clearState(): void {\n const removedIds = Object.keys(this.state.internalAccounts.accounts);\n\n this.update(() => {\n return getDefaultAccountsControllerState();\n });\n\n for (const id of removedIds) {\n this.messenger.publish('AccountsController:accountRemoved', id);\n }\n if (removedIds.length > 0) {\n this.messenger.publish('AccountsController:accountsRemoved', removedIds);\n }\n }\n\n /**\n * Gets an internal account representation for a non-Snap account.\n *\n * @param address - The address of the account.\n * @param keyring - The keyring object of the account.\n * @returns The generated internal account.\n */\n #getInternalAccountForNonSnapAccount(\n address: string,\n keyring: KeyringObject,\n ): InternalAccount {\n const id = getUUIDFromAddressOfNormalAccount(address);\n\n // We might have an account for this ID already, so we'll just re-use\n // the same metadata\n const account = this.getAccount(id);\n const metadata: InternalAccount['metadata'] = {\n name: account?.metadata.name ?? '',\n ...(account?.metadata.nameLastUpdatedAt\n ? {\n nameLastUpdatedAt: account?.metadata.nameLastUpdatedAt,\n }\n : {}),\n importTime: account?.metadata.importTime ?? Date.now(),\n lastSelected: account?.metadata.lastSelected ?? 0,\n keyring: {\n type: keyring.type,\n },\n };\n\n let options: InternalAccount['options'] = {};\n if (isHdKeyringType(keyring.type)) {\n // We need to find the account index from its HD keyring.\n const groupIndex = getEvmGroupIndexFromAddressIndex(keyring, address);\n\n // If for some reason, we cannot find this address, then the caller made a mistake\n // and it did not use the proper keyring object. For now, we do not fail and just\n // consider this account as \"simple account\".\n if (groupIndex !== undefined) {\n // NOTE: We are not using the `hdPath` from the associated keyring here and\n // getting the keyring instance here feels a bit overkill.\n // This will be naturally fixed once every keyring start using `KeyringAccount` and implement the keyring API.\n const derivationPath = getEvmDerivationPathForIndex(groupIndex);\n\n // Those are \"legacy options\" and they were used before `KeyringAccount` added\n // support for type options. We keep those temporarily until we update everything\n // to use the new typed options.\n const legacyOptions = {\n entropySource: keyring.metadata.id,\n derivationPath,\n groupIndex,\n };\n\n // New typed entropy options. This is required for multichain accounts.\n const entropyOptions: { entropy: KeyringAccountEntropyOptions } = {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: keyring.metadata.id,\n derivationPath,\n groupIndex,\n },\n };\n\n options = {\n ...legacyOptions,\n ...entropyOptions,\n };\n }\n }\n\n return {\n id,\n address,\n options,\n methods: [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n ],\n scopes: [EthScope.Eoa],\n type: EthAccountType.Eoa,\n metadata,\n };\n }\n\n /**\n * Get Snap keyring from the keyring controller.\n *\n * @returns The Snap keyring if available.\n */\n #getSnapKeyring(): SnapKeyring | undefined {\n const [snapKeyring] = this.messenger.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n\n // Snap keyring is not available until the first account is created in the keyring\n // controller, so this might be undefined.\n return snapKeyring as SnapKeyring | undefined;\n }\n\n /**\n * Get an account from a Snap keyring v1.\n *\n * @param address - The address of the account to retrieve.\n * @returns The Snap account if available.\n */\n #getAccountFromSnapKeyringV1(address: string): InternalAccount | undefined {\n const snapKeyring = this.#getSnapKeyring();\n\n // We need the Snap keyring to retrieve the account from its address.\n if (!snapKeyring) {\n return undefined;\n }\n\n // This might be undefined if the Snap deleted the account before\n // reaching that point.\n return snapKeyring.getAccountByAddress(address);\n }\n\n /**\n * Get an account from a v2 keyring, by iterating over all the keyrings of\n * the given type and looking up the account by address.\n *\n * NOTE: `:getKeyringsByType` will only return v1 instances, that's why we need to use their v1\n * adapter + `unwrap` method to get the reference to their v2 instance.\n *\n * @param keyringType - The type of the keyrings to look into.\n * @param address - The address of the account to retrieve.\n * @param createAccount - Callback to create the final internal account, given the account\n * retrieved from the keyring and the keyring itself.\n * @returns The account if available.\n * @template KeyringV2WithLookup - The concrete type of the v2 keyring.\n */\n #getAccountFromV2Keyrings<KeyringV2WithLookup extends KeyringWithLookup>(\n keyringType: KeyringType,\n address: string,\n createAccount: (\n account: KeyringAccount,\n keyringV2: KeyringV2WithLookup,\n ) => InternalAccount,\n ): InternalAccount | undefined {\n const keyrings = this.messenger.call(\n 'KeyringController:getKeyringsByType',\n keyringType,\n );\n\n for (const keyring of keyrings) {\n if (keyring instanceof KeyringV1Adapter) {\n // NOTE: We are already filtering by `keyringType`, so we are sure that those adapters\n // are wrapping a keyring of that type.\n const adapter = keyring as KeyringV1Adapter<KeyringV2WithLookup>;\n const keyringV2 = adapter.unwrap();\n\n // We use the synchronous method here since this method is used during `:stateChange` that are\n // use synchronous handlers.\n const account = keyringV2.lookupByAddress(address);\n if (account) {\n return createAccount(account, keyringV2);\n }\n }\n }\n\n return undefined;\n }\n\n /**\n * Get an account from a Snap keyring v2.\n *\n * @param address - The address of the account to retrieve.\n * @returns The Snap account if available.\n */\n #getAccountFromSnapKeyringV2(address: string): InternalAccount | undefined {\n // Snap keyring v2 are \"per-Snaps\" (and can be accessed using their v1 adapter), so we need to\n // iterate over all of them to find the account.\n return this.#getAccountFromV2Keyrings(\n KeyringType.Snap,\n address,\n (account, keyringV2: SnapKeyringV2) => ({\n ...account,\n // We still have to use internal account for now, so we inject some metadata.\n metadata: {\n name: '',\n importTime: Date.now(),\n lastSelected: 0,\n keyring: {\n type: KeyringType.Snap,\n },\n snap: {\n id: keyringV2.snapId,\n },\n },\n }),\n );\n }\n\n /**\n * Get an account from a watch-only keyring.\n *\n * @param address - The address of the account to retrieve.\n * @returns The watch-only account if available.\n */\n #getAccountFromWatchOnlyKeyring(\n address: string,\n ): InternalAccount | undefined {\n // There is usually only one watch-only keyring, but we iterate over all of\n // them to find the account, in case more than one was added.\n // The watch-only account is read from the keyring itself, keeping its ID\n // and its (empty) list of methods, so we don't re-create an EVM account\n // without signing methods.\n return this.#getAccountFromV2Keyrings(\n KeyringType.WatchOnly,\n address,\n (account) => ({\n ...account,\n // We still have to use internal account for now, so we inject some metadata.\n metadata: {\n name: '',\n importTime: Date.now(),\n lastSelected: 0,\n keyring: {\n type: KeyringType.WatchOnly,\n },\n },\n }),\n );\n }\n\n /**\n * Re-publish an account event.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @param payload - The event payload. The type of the parameters for each event handler must\n * match the type of this payload.\n * @template EventType - A Snap keyring event type.\n */\n #handleOnSnapKeyringAccountEvent<\n EventType extends AccountsControllerEvents['type'],\n >(\n event: EventType,\n ...payload: ExtractEventPayload<AccountsControllerEvents, EventType>\n ): void {\n this.messenger.publish(event, ...payload);\n }\n\n /**\n * Handles changes in the keyring state, specifically when new accounts are added or removed.\n *\n * @param keyringState - The new state of the keyring controller.\n * @param keyringState.isUnlocked - True if the keyrings are unlocked, false otherwise.\n * @param keyringState.keyrings - List of all keyrings.\n */\n #handleOnKeyringStateChange({\n isUnlocked,\n keyrings,\n }: KeyringControllerState): void {\n // TODO: Change when accountAdded event is added to the keyring controller.\n\n // We check for keyrings length to be greater than 0 because the extension client may try execute\n // submit password twice and clear the keyring state.\n // https://github.com/MetaMask/KeyringController/blob/2d73a4deed8d013913f6ef0c9f5c0bb7c614f7d3/src/KeyringController.ts#L910\n if (!isUnlocked || keyrings.length === 0) {\n return;\n }\n\n log('Synchronizing accounts with keyrings (through :stateChange)...');\n\n // State patches.\n const patch: StatePatch = {\n previous: {},\n added: [],\n updated: [],\n removed: [],\n };\n\n // Create a map (with lower-cased addresses) of all existing accounts.\n for (const account of this.listMultichainAccounts()) {\n const address = account.address.toLowerCase();\n\n patch.previous[address] = account;\n }\n\n // Go over all keyring changes and create patches out of it.\n const addresses = new Set<string>();\n for (const keyring of keyrings) {\n // Skipped accounts (Money or MPC) are not treated as real accounts, they are owned by their\n // respective controllers, so we need to filter them out here.\n if (isSkippedKeyringType(keyring.type)) {\n continue;\n }\n\n for (const accountAddress of keyring.accounts) {\n // Lower-case address to use it in the `previous` map.\n const address = accountAddress.toLowerCase();\n const account = patch.previous[address];\n\n if (account) {\n // If the account exists before, this might be an update.\n patch.updated.push(account);\n } else {\n // Otherwise, that's a new account.\n patch.added.push({\n address,\n keyring,\n });\n }\n\n // Keep track of those address to check for removed accounts later.\n addresses.add(address);\n }\n }\n\n // We might have accounts associated with removed keyrings, so we iterate\n // over all previous known accounts and check against the keyring addresses.\n for (const [address, account] of Object.entries(patch.previous)) {\n // If a previous address is not part of the new addesses, then it got removed.\n if (!addresses.has(address)) {\n patch.removed.push(account);\n }\n }\n\n // Diff that we will use to publish events afterward.\n const diff: { removed: string[]; added: InternalAccount[] } = {\n removed: [],\n added: [],\n };\n\n this.#update(\n (state) => {\n const { internalAccounts, accountIdByAddress } = state;\n\n for (const account of patch.removed) {\n delete internalAccounts.accounts[account.id];\n delete accountIdByAddress[account.address];\n\n diff.removed.push(account.id);\n }\n\n for (const added of patch.added) {\n const account = this.#getInternalAccountFromAddressAndType(\n added.address,\n added.keyring,\n );\n\n if (account) {\n const accounts = Object.values(internalAccounts.accounts);\n\n // If it's the first account, we need to select it.\n const lastSelected =\n accounts.length === 0 ? this.#getLastSelectedIndex() : 0;\n\n internalAccounts.accounts[account.id] = {\n ...account,\n metadata: {\n ...account.metadata,\n importTime: Date.now(),\n lastSelected,\n },\n };\n\n accountIdByAddress[account.address] = account.id;\n\n diff.added.push(internalAccounts.accounts[account.id]);\n }\n }\n },\n // Will get executed after the update, but before re-selecting an account in case\n // the current one is not valid anymore.\n () => {\n // Now publish events\n for (const id of diff.removed) {\n this.messenger.publish('AccountsController:accountRemoved', id);\n }\n if (diff.removed.length > 0) {\n this.messenger.publish(\n 'AccountsController:accountsRemoved',\n diff.removed,\n );\n }\n\n for (const account of diff.added) {\n this.messenger.publish('AccountsController:accountAdded', account);\n }\n if (diff.added.length > 0) {\n this.messenger.publish(\n 'AccountsController:accountsAdded',\n diff.added,\n );\n }\n },\n );\n\n log('Accounts synchronized (through :stateChange)!');\n\n // NOTE: Since we also track \"updated\" accounts with our patches, we could fire a new event\n // like `accountUpdated` (we would still need to check if anything really changed on the account).\n }\n\n /**\n * Update the state and fixup the currently selected account.\n *\n * @param callback - Callback for updating state, passed a draft state object.\n * @param beforeAutoSelectAccount - Callback to be executed before auto-selecting an account\n * if the current one is no longer available.\n */\n #update(\n callback: (state: WritableDraft<AccountsControllerStrictState>) => void,\n beforeAutoSelectAccount?: () => void,\n ): void {\n // The currently selected account might get deleted during the update, so keep track\n // of it before doing any change.\n const previouslySelectedAccount =\n this.state.internalAccounts.selectedAccount;\n\n this.update((state: WritableDraft<AccountsControllerStrictState>) => {\n callback(state);\n\n // If the account no longer exists (or none is selected), we need to re-select another one.\n const { internalAccounts } = state;\n if (!internalAccounts.accounts[previouslySelectedAccount]) {\n const accounts = Object.values(internalAccounts.accounts);\n\n // Get the lastly selected account (according to the current accounts).\n const lastSelectedAccount = this.#getLastSelectedAccount(accounts);\n if (lastSelectedAccount) {\n internalAccounts.selectedAccount = lastSelectedAccount.id;\n internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n } else {\n // It will be undefined if there are no accounts.\n internalAccounts.selectedAccount = '';\n }\n }\n });\n\n // We might want to do some pre-work before selecting a new account.\n beforeAutoSelectAccount?.();\n\n // Now, we compare the newly selected account, and we send event if different.\n const { selectedAccount } = this.state.internalAccounts;\n if (selectedAccount && selectedAccount !== previouslySelectedAccount) {\n const account = this.getSelectedMultichainAccount();\n\n // The account should always be defined at this point, since we have already checked for\n // `selectedAccount` to be non-empty.\n if (account) {\n if (isEvmAccountType(account.type)) {\n this.messenger.publish(\n 'AccountsController:selectedEvmAccountChange',\n account,\n );\n }\n this.messenger.publish(\n 'AccountsController:selectedAccountChange',\n account,\n );\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 * Retrieves the index value for `metadata.lastSelected`.\n *\n * @returns The index value.\n */\n #getLastSelectedIndex(): number {\n // NOTE: For now we use the current date, since we know this value\n // will always be higher than any already selected account index.\n return Date.now();\n }\n\n /**\n * Get an internal account given an address and a keyring type.\n *\n * If the account is not a Snap Keyring account, generates an internal account for it and adds it to the controller.\n * If the account is a Snap Keyring account, retrieves the account from the keyring and adds it to the controller.\n *\n * @param address - The address of the new account.\n * @param keyring - The keyring object of that new account.\n * @returns The newly generated/retrieved internal account.\n */\n #getInternalAccountFromAddressAndType(\n address: string,\n keyring: KeyringObject,\n ): InternalAccount | undefined {\n const isSnapKeyringV1 = isSnapKeyringType(keyring.type);\n const isSnapKeyringV2 = isSnapKeyringV2Type(keyring.type);\n\n if (isSnapKeyringV1 || isSnapKeyringV2) {\n let account: InternalAccount | undefined;\n\n if (isSnapKeyringV1) {\n account = this.#getAccountFromSnapKeyringV1(address);\n } else {\n account = this.#getAccountFromSnapKeyringV2(address);\n }\n\n if (account) {\n // We force the copy here, to avoid mutating the reference returned by the Snap keyring.\n account = cloneDeep(account);\n\n // MIGRATION: To avoid any existing Snap account migration, we are\n // just \"adding\" the new typed options that we need for multichain\n // accounts. Ultimately, we would need a real Snap account migrations\n // (being handled by each Snaps).\n if (isHdSnapKeyringAccount(account)) {\n const options: HdSnapKeyringAccount['options'] = {\n ...account.options,\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: account.options.entropySource,\n groupIndex: account.options.index,\n derivationPath: account.options.derivationPath,\n },\n };\n // Inject the new typed options to the internal account copy.\n account.options = options;\n }\n }\n\n return account;\n }\n\n // Watch-only accounts are read from the watch-only keyring itself (like\n // Snap v2 accounts), so we don't re-create an EVM account without signing\n // methods for them.\n if (isWatchOnlyKeyringType(keyring.type)) {\n return this.#getAccountFromWatchOnlyKeyring(address);\n }\n\n return this.#getInternalAccountForNonSnapAccount(address, keyring);\n }\n\n /**\n * Handles the change in multichain network by updating the selected account.\n *\n * @param id - The EVM client ID or non-EVM chain ID that changed.\n */\n #handleOnMultichainNetworkDidChange(id: NetworkClientId | CaipChainId): void {\n let accountId: string;\n\n // We only support non-EVM Caip chain IDs at the moment. Ex Solana and Bitcoin\n // MultichainNetworkController will handle throwing an error if the Caip chain ID is not supported\n if (isCaipChainId(id)) {\n // Update selected account to non evm account\n const lastSelectedNonEvmAccount = this.getSelectedMultichainAccount(id);\n // @ts-expect-error - This should never be undefined, otherwise it's a bug that should be handled\n accountId = lastSelectedNonEvmAccount.id;\n } else {\n // Update selected account to evm account\n const lastSelectedEvmAccount = this.getSelectedAccount();\n accountId = lastSelectedEvmAccount.id;\n }\n\n if (this.state.internalAccounts.selectedAccount === accountId) {\n return;\n }\n\n this.update((currentState) => {\n currentState.internalAccounts.accounts[accountId].metadata.lastSelected =\n Date.now();\n currentState.internalAccounts.selectedAccount = accountId;\n });\n\n // DO NOT publish AccountsController:setSelectedAccount to prevent circular listener loops\n }\n\n /**\n * Subscribes to message events.\n */\n #subscribeToMessageEvents(): void {\n this.messenger.subscribe('KeyringController:stateChange', (keyringState) =>\n this.#handleOnKeyringStateChange(keyringState),\n );\n\n this.messenger.subscribe(\n 'SnapAccountService:accountAssetListUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountAssetListUpdated',\n snapAccountEvent,\n ),\n );\n\n this.messenger.subscribe(\n 'SnapAccountService:accountBalancesUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountBalancesUpdated',\n snapAccountEvent,\n ),\n );\n\n this.messenger.subscribe(\n 'SnapAccountService:accountTransactionsUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountTransactionsUpdated',\n snapAccountEvent,\n ),\n );\n\n // Handle account change when multichain network is changed\n this.messenger.subscribe(\n 'MultichainNetworkController:networkDidChange',\n (id) => this.#handleOnMultichainNetworkDidChange(id),\n );\n }\n}\n"]}
1
+ {"version":3,"file":"AccountsController.js","sourceRoot":"","sources":["../src/AccountsController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAK3D,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAQzD,OAAO,EACL,cAAc,EACd,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,+BAA+B,GAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AASvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAE,aAAa,IAAI,GAAG,EAAE,MAAM,aAAa,CAAC;AASnD,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,gCAAgC,EAChC,iCAAiC,EACjC,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,MAAM,cAAc,GAAG,oBAAoB,CAAC;AA6B5C,MAAM,yBAAyB,GAAG;IAChC,oBAAoB;IACpB,gBAAgB;IAChB,gCAAgC;IAChC,cAAc;IACd,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,8BAA8B;IAC9B,qBAAqB;IACrB,YAAY;IACZ,aAAa;IACb,uBAAuB;IACvB,YAAY;IACZ,YAAY;CACJ,CAAC;AAmJX,MAAM,0BAA0B,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AS,CAAC,SAAS,CAAC,+BAA+B,EAAE,CAAC,YAAY,EAAE,EAAE,CACzE,IAAI,CAAC,2BAA2B,CAAC,YAAY,CAAC,CAC/C,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,4CAA4C,EAC5C,CAAC,gBAAgB,EAAE,EAAE,CACnB,IAAI,CAAC,gCAAgC,CACnC,4CAA4C,EAC5C,gBAAgB,CACjB,CACJ,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,2CAA2C,EAC3C,CAAC,gBAAgB,EAAE,EAAE,CACnB,IAAI,CAAC,gCAAgC,CACnC,2CAA2C,EAC3C,gBAAgB,CACjB,CACJ,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,+CAA+C,EAC/C,CAAC,gBAAgB,EAAE,EAAE,CACnB,IAAI,CAAC,gCAAgC,CACnC,+CAA+C,EAC/C,gBAAgB,CACjB,CACJ,CAAC;QAEF,2DAA2D;QAC3D,IAAI,CAAC,SAAS,CAAC,SAAS,CACtB,8CAA8C,EAC9C,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,mCAAmC,CAAC,EAAE,CAAC,CACrD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { SnapKeyring } from '@metamask/eth-snap-keyring';\nimport type {\n SnapKeyringAccountAssetListUpdatedEvent,\n SnapKeyringAccountBalancesUpdatedEvent,\n SnapKeyringAccountTransactionsUpdatedEvent,\n} from '@metamask/eth-snap-keyring';\nimport { SnapKeyring as SnapKeyringV2 } from '@metamask/eth-snap-keyring/v2';\nimport type { KeyringAccountEntropyOptions } from '@metamask/keyring-api';\nimport {\n EthAccountType,\n EthMethod,\n EthScope,\n isEvmAccountType,\n KeyringAccountEntropyTypeOption,\n} from '@metamask/keyring-api';\nimport { KeyringType } from '@metamask/keyring-api/v2';\nimport type {\n KeyringControllerState,\n KeyringControllerGetKeyringsByTypeAction,\n KeyringControllerStateChangeEvent,\n KeyringControllerGetStateAction,\n KeyringObject,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport { KeyringV1Adapter } from '@metamask/keyring-sdk/v2';\nimport { isScopeEqualToAny } from '@metamask/keyring-utils';\nimport type { Messenger, ExtractEventPayload } from '@metamask/messenger';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { isCaipChainId } from '@metamask/utils';\nimport type { CaipChainId } from '@metamask/utils';\nimport type { WritableDraft } from 'immer';\nimport { cloneDeep } from 'lodash-es';\n\nimport { AccountsControllerMethodActions } from './AccountsController-method-action-types.js';\nimport { projectLogger as log } from './logger.js';\nimport type {\n MultichainNetworkControllerNetworkDidChangeEvent,\n SnapAccountServiceAccountAssetListUpdatedEvent,\n SnapAccountServiceAccountBalancesUpdatedEvent,\n SnapAccountServiceAccountTransactionsUpdatedEvent,\n} from './types.js';\nimport type { AccountsControllerStrictState } from './typing.js';\nimport type { HdSnapKeyringAccount } from './utils.js';\nimport {\n constructAccountIdByAddress,\n getEvmDerivationPathForIndex,\n getEvmGroupIndexFromAddressIndex,\n getUUIDFromAddressOfNormalAccount,\n isHdKeyringType,\n isHdSnapKeyringAccount,\n isSkippedKeyringType,\n isSnapKeyringType,\n isSnapKeyringV2Type,\n keyringTypeToName,\n} from './utils.js';\n\nconst controllerName = 'AccountsController';\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountId = string;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerState = {\n internalAccounts: {\n accounts: Record<AccountId, InternalAccount>;\n selectedAccount: string; // id of the selected account\n };\n accountIdByAddress: Record<InternalAccount['address'], AccountId>;\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AccountsControllerState\n>;\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'setSelectedAccount',\n 'setAccountName',\n 'setAccountNameAndSelectAccount',\n 'listAccounts',\n 'listMultichainAccounts',\n 'updateAccounts',\n 'getSelectedAccount',\n 'getSelectedMultichainAccount',\n 'getAccountByAddress',\n 'getAccount',\n 'getAccounts',\n 'updateAccountMetadata',\n 'loadBackup',\n 'clearState',\n] as const;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AllowedActions =\n | KeyringControllerGetKeyringsByTypeAction\n | KeyringControllerGetStateAction;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerActions =\n | AccountsControllerGetStateAction\n | AccountsControllerMethodActions;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AccountsControllerState\n>;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerSelectedAccountChangeEvent = {\n type: `${typeof controllerName}:selectedAccountChange`;\n payload: [InternalAccount];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerSelectedEvmAccountChangeEvent = {\n type: `${typeof controllerName}:selectedEvmAccountChange`;\n payload: [InternalAccount];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerAccountAddedEvent = {\n type: `${typeof controllerName}:accountAdded`;\n payload: [InternalAccount];\n};\n\nexport type AccountsControllerAccountsAddedEvent = {\n type: `${typeof controllerName}:accountsAdded`;\n payload: [InternalAccount[]];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerAccountRemovedEvent = {\n type: `${typeof controllerName}:accountRemoved`;\n payload: [AccountId];\n};\n\nexport type AccountsControllerAccountsRemovedEvent = {\n type: `${typeof controllerName}:accountsRemoved`;\n payload: [AccountId[]];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerAccountRenamedEvent = {\n type: `${typeof controllerName}:accountRenamed`;\n payload: [InternalAccount];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerAccountBalancesUpdatesEvent = {\n type: `${typeof controllerName}:accountBalancesUpdated`;\n payload: SnapKeyringAccountBalancesUpdatedEvent['payload'];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerAccountTransactionsUpdatedEvent = {\n type: `${typeof controllerName}:accountTransactionsUpdated`;\n payload: SnapKeyringAccountTransactionsUpdatedEvent['payload'];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerAccountAssetListUpdatedEvent = {\n type: `${typeof controllerName}:accountAssetListUpdated`;\n payload: SnapKeyringAccountAssetListUpdatedEvent['payload'];\n};\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AllowedEvents =\n | KeyringControllerStateChangeEvent\n | SnapAccountServiceAccountAssetListUpdatedEvent\n | SnapAccountServiceAccountBalancesUpdatedEvent\n | SnapAccountServiceAccountTransactionsUpdatedEvent\n | MultichainNetworkControllerNetworkDidChangeEvent;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerEvents =\n | AccountsControllerChangeEvent\n | AccountsControllerSelectedAccountChangeEvent\n | AccountsControllerSelectedEvmAccountChangeEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountsAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerAccountsRemovedEvent\n | AccountsControllerAccountRenamedEvent\n | AccountsControllerAccountBalancesUpdatesEvent\n | AccountsControllerAccountTransactionsUpdatedEvent\n | AccountsControllerAccountAssetListUpdatedEvent;\n\n/**\n * @deprecated This type is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport type AccountsControllerMessenger = Messenger<\n typeof controllerName,\n AccountsControllerActions | AllowedActions,\n AccountsControllerEvents | AllowedEvents\n>;\n\nconst accountsControllerMetadata = {\n internalAccounts: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n accountIdByAddress: {\n includeInStateLogs: false,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\n/**\n * Returns the default state for the AccountsController.\n *\n * @deprecated This function is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @returns The default AccountsController state.\n */\nexport function getDefaultAccountsControllerState(): AccountsControllerState {\n return {\n internalAccounts: {\n accounts: {},\n selectedAccount: '',\n },\n accountIdByAddress: {},\n };\n}\n\n/**\n * @deprecated This constant is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\nexport const EMPTY_ACCOUNT = {\n id: '',\n address: '',\n options: {},\n methods: [],\n type: EthAccountType.Eoa,\n scopes: [EthScope.Eoa],\n metadata: {\n name: '',\n keyring: {\n type: '',\n },\n importTime: 0,\n },\n};\n\n/**\n * A patch representing a keyring state change.\n */\ntype StatePatch = {\n previous: Record<string, InternalAccount>;\n added: {\n address: string;\n keyring: KeyringObject;\n }[];\n updated: InternalAccount[];\n removed: InternalAccount[];\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 * @deprecated This class is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\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 const accountIdByAddress = constructAccountIdByAddress(\n state?.internalAccounts?.accounts ?? {},\n );\n super({\n messenger,\n name: controllerName,\n metadata: accountsControllerMetadata,\n state: {\n ...getDefaultAccountsControllerState(),\n ...state,\n accountIdByAddress,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.#subscribeToMessageEvents();\n }\n\n /**\n * Returns the internal account object for the given account ID, if it exists.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\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 the internal account objects for the given account IDs, if they exist.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param accountIds - The IDs of the accounts to retrieve.\n * @returns The internal account objects, or undefined if the account(s) do not exist.\n */\n getAccounts(accountIds: string[]): (InternalAccount | undefined)[] {\n return accountIds.map((accountId) => this.getAccount(accountId));\n }\n\n /**\n * Returns an array of all evm internal accounts.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\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 * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param chainId - The chain ID.\n * @returns An array of InternalAccount objects.\n */\n listMultichainAccounts(chainId?: CaipChainId): InternalAccount[] {\n const accounts = Object.values(this.state.internalAccounts.accounts);\n if (!chainId) {\n return accounts;\n }\n\n if (!isCaipChainId(chainId)) {\n throw new Error(`Invalid CAIP-2 chain ID: ${String(chainId)}`);\n }\n\n return accounts.filter((account) =>\n isScopeEqualToAny(chainId, account.scopes),\n );\n }\n\n /**\n * Returns the internal account object for the given account ID.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\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 * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @returns The selected internal account.\n */\n getSelectedAccount(): InternalAccount {\n const {\n internalAccounts: { selectedAccount },\n } = this.state;\n\n // Edge case where the extension is setup but the srp is not yet created\n // certain ui elements will query the selected address before any accounts are created.\n if (!selectedAccount) {\n return EMPTY_ACCOUNT;\n }\n\n const account = this.#getAccountExpect(selectedAccount);\n if (isEvmAccountType(account.type)) {\n return account;\n }\n\n const accounts = this.listAccounts();\n if (!accounts.length) {\n // ! Should never reach this.\n throw new Error('No EVM accounts');\n }\n\n // This will never be undefined because we have already checked if accounts.length is > 0\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return this.#getLastSelectedAccount(accounts)!;\n }\n\n /**\n * __WARNING The return value may be undefined if there isn't an account for that chain id.__\n *\n * Retrieves the last selected account by chain ID.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param chainId - The chain ID to filter the accounts.\n * @returns The last selected account compatible with the specified chain ID or undefined.\n */\n getSelectedMultichainAccount(\n chainId?: CaipChainId,\n ): InternalAccount | undefined {\n const {\n internalAccounts: { selectedAccount },\n } = this.state;\n\n // Edge case where the extension is setup but the srp is not yet created\n // certain ui elements will query the selected address before any accounts are created.\n if (!selectedAccount) {\n return EMPTY_ACCOUNT;\n }\n\n if (!chainId) {\n return this.#getAccountExpect(selectedAccount);\n }\n\n const accounts = this.listMultichainAccounts(chainId);\n return this.#getLastSelectedAccount(accounts);\n }\n\n /**\n * Returns the account with the specified address.\n * ! This method will only return the first account that matches the address\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\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 // We need to have a fallback as a cache miss might be attributed to a checksummed address being passed.\n let accountId = this.state.accountIdByAddress[address];\n if (!accountId) {\n // FIXME: We should not need lower-cased addresses, but some consumers might\n // still be using non-normalized addresses. For now we keep it\n // for convenience, but we will need to remove this fallback\n // at some point.\n // NOTE: We should only hit that branch for EVM accounts only.\n const lowercasedAddress = address.toLowerCase();\n accountId = this.state.accountIdByAddress[lowercasedAddress];\n if (accountId) {\n log(\n `Cache missed for account ID: ${accountId}, received address: \"${address}\", matched address: \"${lowercasedAddress}\"`,\n );\n }\n }\n return accountId ? this.getAccount(accountId) : undefined;\n }\n\n /**\n * Sets the selected account by its ID.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param accountId - The ID of the account to be selected.\n */\n setSelectedAccount(accountId: string): void {\n const account = this.#getAccountExpect(accountId);\n\n if (this.state.internalAccounts.selectedAccount === account.id) {\n return;\n }\n\n this.#update((state) => {\n const { internalAccounts } = state;\n\n internalAccounts.accounts[account.id].metadata.lastSelected = Date.now();\n internalAccounts.selectedAccount = account.id;\n });\n }\n\n /**\n * Sets the name of the account with the given ID.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param accountId - The ID of the account to set the name for.\n * @param accountName - The new name for the account.\n * @throws An error if an account with the same name already exists.\n */\n setAccountName(accountId: string, accountName: string): void {\n // This will check for name uniqueness and fire the `accountRenamed` event\n // if the account has been renamed.\n this.updateAccountMetadata(accountId, {\n name: accountName,\n nameLastUpdatedAt: Date.now(),\n });\n }\n\n /**\n * Sets the name of the account with the given ID and select it.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param accountId - The ID of the account to set the name for and select.\n * @param accountName - The new name for the account.\n * @throws An error if an account with the same name already exists.\n */\n setAccountNameAndSelectAccount(accountId: string, accountName: string): void {\n const account = this.#getAccountExpect(accountId);\n\n this.#assertAccountCanBeRenamed(account, accountName);\n\n const internalAccount = {\n ...account,\n metadata: {\n ...account.metadata,\n name: accountName,\n nameLastUpdatedAt: Date.now(),\n lastSelected: this.#getLastSelectedIndex(),\n },\n };\n\n this.#update((state) => {\n state.internalAccounts.accounts[account.id] = internalAccount;\n state.internalAccounts.selectedAccount = account.id;\n });\n\n this.messenger.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\n }\n\n #assertAccountCanBeRenamed(\n account: InternalAccount,\n accountName: string,\n ): void {\n if (\n this.listMultichainAccounts().find(\n (internalAccount) =>\n internalAccount.metadata.name === accountName &&\n internalAccount.id !== account.id,\n )\n ) {\n throw new Error('Account name already exists');\n }\n }\n\n /**\n * Updates the metadata of the account with the given ID.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param accountId - The ID of the account for which the metadata will be updated.\n * @param metadata - The new metadata for the account.\n */\n updateAccountMetadata(\n accountId: string,\n metadata: Partial<InternalAccount['metadata']>,\n ): void {\n const account = this.#getAccountExpect(accountId);\n\n if (metadata.name) {\n this.#assertAccountCanBeRenamed(account, metadata.name);\n }\n\n const internalAccount = {\n ...account,\n metadata: { ...account.metadata, ...metadata },\n };\n\n this.#update((state) => {\n state.internalAccounts.accounts[accountId] = internalAccount;\n });\n\n if (metadata.name) {\n this.messenger.publish(\n 'AccountsController:accountRenamed',\n internalAccount,\n );\n }\n }\n\n /**\n * Updates the internal accounts list by retrieving normal and snap accounts,\n * removing duplicates, and updating the metadata of each account.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @returns A Promise that resolves when the accounts have been updated.\n */\n async updateAccounts(): Promise<void> {\n log('Synchronizing accounts with keyrings...');\n\n const keyringAccountIndexes = new Map<string, number>();\n\n const existingInternalAccounts = this.state.internalAccounts.accounts;\n const internalAccounts: AccountsControllerState['internalAccounts']['accounts'] =\n {};\n\n const { keyrings } = this.messenger.call('KeyringController:getState');\n for (const keyring of keyrings) {\n const { type } = keyring;\n\n // Skipped accounts (Money or MPC) are not treated as real accounts, they are owned by their\n // respective controllers, so we need to filter them out here.\n if (isSkippedKeyringType(type)) {\n continue;\n }\n\n const keyringTypeName = keyringTypeToName(keyring.type);\n\n for (const address of keyring.accounts) {\n const internalAccount = this.#getInternalAccountFromAddressAndType(\n address,\n keyring,\n );\n\n // This should never really happen, but if for some reason we're not\n // able to get the Snap keyring reference, this would return an\n // undefined account.\n // So we just skip it, even though, this should not really happen.\n if (!internalAccount) {\n continue;\n }\n\n // Get current index for this keyring (we use human indexing, so start at 1).\n const keyringAccountIndex =\n keyringAccountIndexes.get(keyringTypeName) ?? 1;\n\n const existingAccount = existingInternalAccounts[internalAccount.id];\n internalAccounts[internalAccount.id] = {\n ...internalAccount,\n\n metadata: {\n ...internalAccount.metadata,\n\n // Re-use existing metadata if any.\n name:\n existingAccount?.metadata.name ??\n `${keyringTypeName} ${keyringAccountIndex}`,\n importTime: existingAccount?.metadata.importTime ?? Date.now(),\n lastSelected: existingAccount?.metadata.lastSelected ?? 0,\n },\n };\n\n // Increment the account index for this keyring.\n keyringAccountIndexes.set(keyringTypeName, keyringAccountIndex + 1);\n }\n }\n\n this.#update((state) => {\n state.internalAccounts.accounts = internalAccounts;\n state.accountIdByAddress = constructAccountIdByAddress(internalAccounts);\n });\n\n log('Accounts synchronized!');\n }\n\n /**\n * Loads the backup state of the accounts controller.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n * @param backup - The backup state to load.\n */\n loadBackup(backup: AccountsControllerState): void {\n if (backup.internalAccounts) {\n const accountIdByAddress = constructAccountIdByAddress(\n backup.internalAccounts.accounts,\n );\n this.update(\n (currentState: WritableDraft<AccountsControllerStrictState>) => {\n currentState.internalAccounts = backup.internalAccounts;\n currentState.accountIdByAddress = accountIdByAddress;\n },\n );\n }\n }\n\n /**\n * Clears the controller state and resets to default values.\n *\n * @deprecated This method is deprecated and will be removed in a future version.\n * Use `AccountTreeController`, `MultichainAccountService`, or the Keyring API v2 instead.\n */\n clearState(): void {\n const removedIds = Object.keys(this.state.internalAccounts.accounts);\n\n this.update(() => {\n return getDefaultAccountsControllerState();\n });\n\n for (const id of removedIds) {\n this.messenger.publish('AccountsController:accountRemoved', id);\n }\n if (removedIds.length > 0) {\n this.messenger.publish('AccountsController:accountsRemoved', removedIds);\n }\n }\n\n /**\n * Gets an internal account representation for a non-Snap account.\n *\n * @param address - The address of the account.\n * @param keyring - The keyring object of the account.\n * @returns The generated internal account.\n */\n #getInternalAccountForNonSnapAccount(\n address: string,\n keyring: KeyringObject,\n ): InternalAccount {\n const id = getUUIDFromAddressOfNormalAccount(address);\n\n // We might have an account for this ID already, so we'll just re-use\n // the same metadata\n const account = this.getAccount(id);\n const metadata: InternalAccount['metadata'] = {\n name: account?.metadata.name ?? '',\n ...(account?.metadata.nameLastUpdatedAt\n ? {\n nameLastUpdatedAt: account?.metadata.nameLastUpdatedAt,\n }\n : {}),\n importTime: account?.metadata.importTime ?? Date.now(),\n lastSelected: account?.metadata.lastSelected ?? 0,\n keyring: {\n type: keyring.type,\n },\n };\n\n let options: InternalAccount['options'] = {};\n if (isHdKeyringType(keyring.type)) {\n // We need to find the account index from its HD keyring.\n const groupIndex = getEvmGroupIndexFromAddressIndex(keyring, address);\n\n // If for some reason, we cannot find this address, then the caller made a mistake\n // and it did not use the proper keyring object. For now, we do not fail and just\n // consider this account as \"simple account\".\n if (groupIndex !== undefined) {\n // NOTE: We are not using the `hdPath` from the associated keyring here and\n // getting the keyring instance here feels a bit overkill.\n // This will be naturally fixed once every keyring start using `KeyringAccount` and implement the keyring API.\n const derivationPath = getEvmDerivationPathForIndex(groupIndex);\n\n // Those are \"legacy options\" and they were used before `KeyringAccount` added\n // support for type options. We keep those temporarily until we update everything\n // to use the new typed options.\n const legacyOptions = {\n entropySource: keyring.metadata.id,\n derivationPath,\n groupIndex,\n };\n\n // New typed entropy options. This is required for multichain accounts.\n const entropyOptions: { entropy: KeyringAccountEntropyOptions } = {\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: keyring.metadata.id,\n derivationPath,\n groupIndex,\n },\n };\n\n options = {\n ...legacyOptions,\n ...entropyOptions,\n };\n }\n }\n\n return {\n id,\n address,\n options,\n methods: [\n EthMethod.PersonalSign,\n EthMethod.Sign,\n EthMethod.SignTransaction,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n ],\n scopes: [EthScope.Eoa],\n type: EthAccountType.Eoa,\n metadata,\n };\n }\n\n /**\n * Get Snap keyring from the keyring controller.\n *\n * @returns The Snap keyring if available.\n */\n #getSnapKeyring(): SnapKeyring | undefined {\n const [snapKeyring] = this.messenger.call(\n 'KeyringController:getKeyringsByType',\n SnapKeyring.type,\n );\n\n // Snap keyring is not available until the first account is created in the keyring\n // controller, so this might be undefined.\n return snapKeyring as SnapKeyring | undefined;\n }\n\n /**\n * Get an account from a Snap keyring v1.\n *\n * @param address - The address of the account to retrieve.\n * @returns The Snap account if available.\n */\n #getAccountFromSnapKeyringV1(address: string): InternalAccount | undefined {\n const snapKeyring = this.#getSnapKeyring();\n\n // We need the Snap keyring to retrieve the account from its address.\n if (!snapKeyring) {\n return undefined;\n }\n\n // This might be undefined if the Snap deleted the account before\n // reaching that point.\n return snapKeyring.getAccountByAddress(address);\n }\n\n /**\n * Get an account from a Snap keyring v2.\n *\n * @param address - The address of the account to retrieve.\n * @returns The Snap account if available.\n */\n #getAccountFromSnapKeyringV2(address: string): InternalAccount | undefined {\n const keyrings = this.messenger.call(\n 'KeyringController:getKeyringsByType',\n KeyringType.Snap,\n );\n\n // Snap keyring v2 are \"per-Snaps\" (and can be accessed using their v1 adapter), so we need to\n // iterate over all of them to find the account.\n // NOTE: `:getKeyringsByType` will only return v1 instances, that's why we need to use their v1\n // adapter + `unwrap` method to get the reference to their v2 instance.\n for (const keyring of keyrings) {\n if (keyring instanceof KeyringV1Adapter) {\n // NOTE: We already filtering by `KeyringType.Snap`, so we are sure that those adapters\n // are wrapping a Snap keyring v2.\n const adapter = keyring as KeyringV1Adapter<SnapKeyringV2>;\n const keyringV2 = adapter.unwrap();\n\n // We use the synchronous method here since this method is used during `:stateChange` that are\n // use synchronous handlers.\n const account = keyringV2.lookupByAddress(address);\n if (account) {\n return {\n ...account,\n // We still have to use internal account for now, so we inject some metadata.\n metadata: {\n name: '',\n importTime: Date.now(),\n lastSelected: 0,\n keyring: {\n type: KeyringType.Snap,\n },\n snap: {\n id: keyringV2.snapId,\n },\n },\n };\n }\n }\n }\n\n return undefined;\n }\n\n /**\n * Re-publish an account event.\n *\n * @param event - The event type. This is a unique identifier for this event.\n * @param payload - The event payload. The type of the parameters for each event handler must\n * match the type of this payload.\n * @template EventType - A Snap keyring event type.\n */\n #handleOnSnapKeyringAccountEvent<\n EventType extends AccountsControllerEvents['type'],\n >(\n event: EventType,\n ...payload: ExtractEventPayload<AccountsControllerEvents, EventType>\n ): void {\n this.messenger.publish(event, ...payload);\n }\n\n /**\n * Handles changes in the keyring state, specifically when new accounts are added or removed.\n *\n * @param keyringState - The new state of the keyring controller.\n * @param keyringState.isUnlocked - True if the keyrings are unlocked, false otherwise.\n * @param keyringState.keyrings - List of all keyrings.\n */\n #handleOnKeyringStateChange({\n isUnlocked,\n keyrings,\n }: KeyringControllerState): void {\n // TODO: Change when accountAdded event is added to the keyring controller.\n\n // We check for keyrings length to be greater than 0 because the extension client may try execute\n // submit password twice and clear the keyring state.\n // https://github.com/MetaMask/KeyringController/blob/2d73a4deed8d013913f6ef0c9f5c0bb7c614f7d3/src/KeyringController.ts#L910\n if (!isUnlocked || keyrings.length === 0) {\n return;\n }\n\n log('Synchronizing accounts with keyrings (through :stateChange)...');\n\n // State patches.\n const patch: StatePatch = {\n previous: {},\n added: [],\n updated: [],\n removed: [],\n };\n\n // Create a map (with lower-cased addresses) of all existing accounts.\n for (const account of this.listMultichainAccounts()) {\n const address = account.address.toLowerCase();\n\n patch.previous[address] = account;\n }\n\n // Go over all keyring changes and create patches out of it.\n const addresses = new Set<string>();\n for (const keyring of keyrings) {\n // Skipped accounts (Money or MPC) are not treated as real accounts, they are owned by their\n // respective controllers, so we need to filter them out here.\n if (isSkippedKeyringType(keyring.type)) {\n continue;\n }\n\n for (const accountAddress of keyring.accounts) {\n // Lower-case address to use it in the `previous` map.\n const address = accountAddress.toLowerCase();\n const account = patch.previous[address];\n\n if (account) {\n // If the account exists before, this might be an update.\n patch.updated.push(account);\n } else {\n // Otherwise, that's a new account.\n patch.added.push({\n address,\n keyring,\n });\n }\n\n // Keep track of those address to check for removed accounts later.\n addresses.add(address);\n }\n }\n\n // We might have accounts associated with removed keyrings, so we iterate\n // over all previous known accounts and check against the keyring addresses.\n for (const [address, account] of Object.entries(patch.previous)) {\n // If a previous address is not part of the new addesses, then it got removed.\n if (!addresses.has(address)) {\n patch.removed.push(account);\n }\n }\n\n // Diff that we will use to publish events afterward.\n const diff: { removed: string[]; added: InternalAccount[] } = {\n removed: [],\n added: [],\n };\n\n this.#update(\n (state) => {\n const { internalAccounts, accountIdByAddress } = state;\n\n for (const account of patch.removed) {\n delete internalAccounts.accounts[account.id];\n delete accountIdByAddress[account.address];\n\n diff.removed.push(account.id);\n }\n\n for (const added of patch.added) {\n const account = this.#getInternalAccountFromAddressAndType(\n added.address,\n added.keyring,\n );\n\n if (account) {\n const accounts = Object.values(internalAccounts.accounts);\n\n // If it's the first account, we need to select it.\n const lastSelected =\n accounts.length === 0 ? this.#getLastSelectedIndex() : 0;\n\n internalAccounts.accounts[account.id] = {\n ...account,\n metadata: {\n ...account.metadata,\n importTime: Date.now(),\n lastSelected,\n },\n };\n\n accountIdByAddress[account.address] = account.id;\n\n diff.added.push(internalAccounts.accounts[account.id]);\n }\n }\n },\n // Will get executed after the update, but before re-selecting an account in case\n // the current one is not valid anymore.\n () => {\n // Now publish events\n for (const id of diff.removed) {\n this.messenger.publish('AccountsController:accountRemoved', id);\n }\n if (diff.removed.length > 0) {\n this.messenger.publish(\n 'AccountsController:accountsRemoved',\n diff.removed,\n );\n }\n\n for (const account of diff.added) {\n this.messenger.publish('AccountsController:accountAdded', account);\n }\n if (diff.added.length > 0) {\n this.messenger.publish(\n 'AccountsController:accountsAdded',\n diff.added,\n );\n }\n },\n );\n\n log('Accounts synchronized (through :stateChange)!');\n\n // NOTE: Since we also track \"updated\" accounts with our patches, we could fire a new event\n // like `accountUpdated` (we would still need to check if anything really changed on the account).\n }\n\n /**\n * Update the state and fixup the currently selected account.\n *\n * @param callback - Callback for updating state, passed a draft state object.\n * @param beforeAutoSelectAccount - Callback to be executed before auto-selecting an account\n * if the current one is no longer available.\n */\n #update(\n callback: (state: WritableDraft<AccountsControllerStrictState>) => void,\n beforeAutoSelectAccount?: () => void,\n ): void {\n // The currently selected account might get deleted during the update, so keep track\n // of it before doing any change.\n const previouslySelectedAccount =\n this.state.internalAccounts.selectedAccount;\n\n this.update((state: WritableDraft<AccountsControllerStrictState>) => {\n callback(state);\n\n // If the account no longer exists (or none is selected), we need to re-select another one.\n const { internalAccounts } = state;\n if (!internalAccounts.accounts[previouslySelectedAccount]) {\n const accounts = Object.values(internalAccounts.accounts);\n\n // Get the lastly selected account (according to the current accounts).\n const lastSelectedAccount = this.#getLastSelectedAccount(accounts);\n if (lastSelectedAccount) {\n internalAccounts.selectedAccount = lastSelectedAccount.id;\n internalAccounts.accounts[\n lastSelectedAccount.id\n ].metadata.lastSelected = this.#getLastSelectedIndex();\n } else {\n // It will be undefined if there are no accounts.\n internalAccounts.selectedAccount = '';\n }\n }\n });\n\n // We might want to do some pre-work before selecting a new account.\n beforeAutoSelectAccount?.();\n\n // Now, we compare the newly selected account, and we send event if different.\n const { selectedAccount } = this.state.internalAccounts;\n if (selectedAccount && selectedAccount !== previouslySelectedAccount) {\n const account = this.getSelectedMultichainAccount();\n\n // The account should always be defined at this point, since we have already checked for\n // `selectedAccount` to be non-empty.\n if (account) {\n if (isEvmAccountType(account.type)) {\n this.messenger.publish(\n 'AccountsController:selectedEvmAccountChange',\n account,\n );\n }\n this.messenger.publish(\n 'AccountsController:selectedAccountChange',\n account,\n );\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 * Retrieves the index value for `metadata.lastSelected`.\n *\n * @returns The index value.\n */\n #getLastSelectedIndex(): number {\n // NOTE: For now we use the current date, since we know this value\n // will always be higher than any already selected account index.\n return Date.now();\n }\n\n /**\n * Get an internal account given an address and a keyring type.\n *\n * If the account is not a Snap Keyring account, generates an internal account for it and adds it to the controller.\n * If the account is a Snap Keyring account, retrieves the account from the keyring and adds it to the controller.\n *\n * @param address - The address of the new account.\n * @param keyring - The keyring object of that new account.\n * @returns The newly generated/retrieved internal account.\n */\n #getInternalAccountFromAddressAndType(\n address: string,\n keyring: KeyringObject,\n ): InternalAccount | undefined {\n const isSnapKeyringV1 = isSnapKeyringType(keyring.type);\n const isSnapKeyringV2 = isSnapKeyringV2Type(keyring.type);\n\n if (isSnapKeyringV1 || isSnapKeyringV2) {\n let account: InternalAccount | undefined;\n\n if (isSnapKeyringV1) {\n account = this.#getAccountFromSnapKeyringV1(address);\n } else {\n account = this.#getAccountFromSnapKeyringV2(address);\n }\n\n if (account) {\n // We force the copy here, to avoid mutating the reference returned by the Snap keyring.\n account = cloneDeep(account);\n\n // MIGRATION: To avoid any existing Snap account migration, we are\n // just \"adding\" the new typed options that we need for multichain\n // accounts. Ultimately, we would need a real Snap account migrations\n // (being handled by each Snaps).\n if (isHdSnapKeyringAccount(account)) {\n const options: HdSnapKeyringAccount['options'] = {\n ...account.options,\n entropy: {\n type: KeyringAccountEntropyTypeOption.Mnemonic,\n id: account.options.entropySource,\n groupIndex: account.options.index,\n derivationPath: account.options.derivationPath,\n },\n };\n // Inject the new typed options to the internal account copy.\n account.options = options;\n }\n }\n\n return account;\n }\n\n return this.#getInternalAccountForNonSnapAccount(address, keyring);\n }\n\n /**\n * Handles the change in multichain network by updating the selected account.\n *\n * @param id - The EVM client ID or non-EVM chain ID that changed.\n */\n #handleOnMultichainNetworkDidChange(id: NetworkClientId | CaipChainId): void {\n let accountId: string;\n\n // We only support non-EVM Caip chain IDs at the moment. Ex Solana and Bitcoin\n // MultichainNetworkController will handle throwing an error if the Caip chain ID is not supported\n if (isCaipChainId(id)) {\n // Update selected account to non evm account\n const lastSelectedNonEvmAccount = this.getSelectedMultichainAccount(id);\n // @ts-expect-error - This should never be undefined, otherwise it's a bug that should be handled\n accountId = lastSelectedNonEvmAccount.id;\n } else {\n // Update selected account to evm account\n const lastSelectedEvmAccount = this.getSelectedAccount();\n accountId = lastSelectedEvmAccount.id;\n }\n\n if (this.state.internalAccounts.selectedAccount === accountId) {\n return;\n }\n\n this.update((currentState) => {\n currentState.internalAccounts.accounts[accountId].metadata.lastSelected =\n Date.now();\n currentState.internalAccounts.selectedAccount = accountId;\n });\n\n // DO NOT publish AccountsController:setSelectedAccount to prevent circular listener loops\n }\n\n /**\n * Subscribes to message events.\n */\n #subscribeToMessageEvents(): void {\n this.messenger.subscribe('KeyringController:stateChange', (keyringState) =>\n this.#handleOnKeyringStateChange(keyringState),\n );\n\n this.messenger.subscribe(\n 'SnapAccountService:accountAssetListUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountAssetListUpdated',\n snapAccountEvent,\n ),\n );\n\n this.messenger.subscribe(\n 'SnapAccountService:accountBalancesUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountBalancesUpdated',\n snapAccountEvent,\n ),\n );\n\n this.messenger.subscribe(\n 'SnapAccountService:accountTransactionsUpdated',\n (snapAccountEvent) =>\n this.#handleOnSnapKeyringAccountEvent(\n 'AccountsController:accountTransactionsUpdated',\n snapAccountEvent,\n ),\n );\n\n // Handle account change when multichain network is changed\n this.messenger.subscribe(\n 'MultichainNetworkController:networkDidChange',\n (id) => this.#handleOnMultichainNetworkDidChange(id),\n );\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export type { AccountId, AccountsControllerState, AccountsControllerGetStateAction, AllowedActions, AccountsControllerActions, AccountsControllerChangeEvent, AccountsControllerSelectedAccountChangeEvent, AccountsControllerSelectedEvmAccountChangeEvent, AccountsControllerAccountAddedEvent, AccountsControllerAccountsAddedEvent, AccountsControllerAccountRemovedEvent, AccountsControllerAccountsRemovedEvent, AccountsControllerAccountRenamedEvent, AccountsControllerAccountBalancesUpdatesEvent, AccountsControllerAccountTransactionsUpdatedEvent, AccountsControllerAccountAssetListUpdatedEvent, AllowedEvents, AccountsControllerEvents, AccountsControllerMessenger, } from './AccountsController.js';
2
2
  export type { AccountsControllerGetAccountAction, AccountsControllerGetAccountsAction, AccountsControllerListAccountsAction, AccountsControllerListMultichainAccountsAction, AccountsControllerGetSelectedAccountAction, AccountsControllerGetSelectedMultichainAccountAction, AccountsControllerGetAccountByAddressAction, AccountsControllerSetSelectedAccountAction, AccountsControllerSetAccountNameAction, AccountsControllerSetAccountNameAndSelectAccountAction, AccountsControllerUpdateAccountMetadataAction, AccountsControllerUpdateAccountsAction, AccountsControllerLoadBackupAction, AccountsControllerClearStateAction, } from './AccountsController-method-action-types.js';
3
3
  export { EMPTY_ACCOUNT, AccountsController, getDefaultAccountsControllerState, } from './AccountsController.js';
4
- export { keyringTypeToName, getUUIDOptionsFromAddressOfNormalAccount, getUUIDFromAddressOfNormalAccount, isNormalKeyringType, isWatchOnlyKeyringType, } from './utils.js';
4
+ export { keyringTypeToName, getUUIDOptionsFromAddressOfNormalAccount, getUUIDFromAddressOfNormalAccount, isNormalKeyringType, } from './utils.js';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,SAAS,EACT,uBAAuB,EACvB,gCAAgC,EAChC,cAAc,EACd,yBAAyB,EACzB,6BAA6B,EAC7B,4CAA4C,EAC5C,+CAA+C,EAC/C,mCAAmC,EACnC,oCAAoC,EACpC,qCAAqC,EACrC,sCAAsC,EACtC,qCAAqC,EACrC,6CAA6C,EAC7C,iDAAiD,EACjD,8CAA8C,EAC9C,aAAa,EACb,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,kCAAkC,EAClC,mCAAmC,EACnC,oCAAoC,EACpC,8CAA8C,EAC9C,0CAA0C,EAC1C,oDAAoD,EACpD,2CAA2C,EAC3C,0CAA0C,EAC1C,sCAAsC,EACtC,sDAAsD,EACtD,6CAA6C,EAC7C,sCAAsC,EACtC,kCAAkC,EAClC,kCAAkC,GACnC,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,iCAAiC,GAClC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,iBAAiB,EACjB,wCAAwC,EACxC,iCAAiC,EACjC,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,SAAS,EACT,uBAAuB,EACvB,gCAAgC,EAChC,cAAc,EACd,yBAAyB,EACzB,6BAA6B,EAC7B,4CAA4C,EAC5C,+CAA+C,EAC/C,mCAAmC,EACnC,oCAAoC,EACpC,qCAAqC,EACrC,sCAAsC,EACtC,qCAAqC,EACrC,6CAA6C,EAC7C,iDAAiD,EACjD,8CAA8C,EAC9C,aAAa,EACb,wBAAwB,EACxB,2BAA2B,GAC5B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,kCAAkC,EAClC,mCAAmC,EACnC,oCAAoC,EACpC,8CAA8C,EAC9C,0CAA0C,EAC1C,oDAAoD,EACpD,2CAA2C,EAC3C,0CAA0C,EAC1C,sCAAsC,EACtC,sDAAsD,EACtD,6CAA6C,EAC7C,sCAAsC,EACtC,kCAAkC,EAClC,kCAAkC,GACnC,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,iCAAiC,GAClC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,iBAAiB,EACjB,wCAAwC,EACxC,iCAAiC,EACjC,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { EMPTY_ACCOUNT, AccountsController, getDefaultAccountsControllerState, } from './AccountsController.js';
2
- export { keyringTypeToName, getUUIDOptionsFromAddressOfNormalAccount, getUUIDFromAddressOfNormalAccount, isNormalKeyringType, isWatchOnlyKeyringType, } from './utils.js';
2
+ export { keyringTypeToName, getUUIDOptionsFromAddressOfNormalAccount, getUUIDFromAddressOfNormalAccount, isNormalKeyringType, } from './utils.js';
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAqCA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,iCAAiC,GAClC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,iBAAiB,EACjB,wCAAwC,EACxC,iCAAiC,EACjC,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,YAAY,CAAC","sourcesContent":["export type {\n AccountId,\n AccountsControllerState,\n AccountsControllerGetStateAction,\n AllowedActions,\n AccountsControllerActions,\n AccountsControllerChangeEvent,\n AccountsControllerSelectedAccountChangeEvent,\n AccountsControllerSelectedEvmAccountChangeEvent,\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountsAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerAccountsRemovedEvent,\n AccountsControllerAccountRenamedEvent,\n AccountsControllerAccountBalancesUpdatesEvent,\n AccountsControllerAccountTransactionsUpdatedEvent,\n AccountsControllerAccountAssetListUpdatedEvent,\n AllowedEvents,\n AccountsControllerEvents,\n AccountsControllerMessenger,\n} from './AccountsController.js';\nexport type {\n AccountsControllerGetAccountAction,\n AccountsControllerGetAccountsAction,\n AccountsControllerListAccountsAction,\n AccountsControllerListMultichainAccountsAction,\n AccountsControllerGetSelectedAccountAction,\n AccountsControllerGetSelectedMultichainAccountAction,\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerSetSelectedAccountAction,\n AccountsControllerSetAccountNameAction,\n AccountsControllerSetAccountNameAndSelectAccountAction,\n AccountsControllerUpdateAccountMetadataAction,\n AccountsControllerUpdateAccountsAction,\n AccountsControllerLoadBackupAction,\n AccountsControllerClearStateAction,\n} from './AccountsController-method-action-types.js';\nexport {\n EMPTY_ACCOUNT,\n AccountsController,\n getDefaultAccountsControllerState,\n} from './AccountsController.js';\nexport {\n keyringTypeToName,\n getUUIDOptionsFromAddressOfNormalAccount,\n getUUIDFromAddressOfNormalAccount,\n isNormalKeyringType,\n isWatchOnlyKeyringType,\n} from './utils.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAqCA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,iCAAiC,GAClC,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,iBAAiB,EACjB,wCAAwC,EACxC,iCAAiC,EACjC,mBAAmB,GACpB,MAAM,YAAY,CAAC","sourcesContent":["export type {\n AccountId,\n AccountsControllerState,\n AccountsControllerGetStateAction,\n AllowedActions,\n AccountsControllerActions,\n AccountsControllerChangeEvent,\n AccountsControllerSelectedAccountChangeEvent,\n AccountsControllerSelectedEvmAccountChangeEvent,\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountsAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerAccountsRemovedEvent,\n AccountsControllerAccountRenamedEvent,\n AccountsControllerAccountBalancesUpdatesEvent,\n AccountsControllerAccountTransactionsUpdatedEvent,\n AccountsControllerAccountAssetListUpdatedEvent,\n AllowedEvents,\n AccountsControllerEvents,\n AccountsControllerMessenger,\n} from './AccountsController.js';\nexport type {\n AccountsControllerGetAccountAction,\n AccountsControllerGetAccountsAction,\n AccountsControllerListAccountsAction,\n AccountsControllerListMultichainAccountsAction,\n AccountsControllerGetSelectedAccountAction,\n AccountsControllerGetSelectedMultichainAccountAction,\n AccountsControllerGetAccountByAddressAction,\n AccountsControllerSetSelectedAccountAction,\n AccountsControllerSetAccountNameAction,\n AccountsControllerSetAccountNameAndSelectAccountAction,\n AccountsControllerUpdateAccountMetadataAction,\n AccountsControllerUpdateAccountsAction,\n AccountsControllerLoadBackupAction,\n AccountsControllerClearStateAction,\n} from './AccountsController-method-action-types.js';\nexport {\n EMPTY_ACCOUNT,\n AccountsController,\n getDefaultAccountsControllerState,\n} from './AccountsController.js';\nexport {\n keyringTypeToName,\n getUUIDOptionsFromAddressOfNormalAccount,\n getUUIDFromAddressOfNormalAccount,\n isNormalKeyringType,\n} from './utils.js';\n"]}
package/dist/utils.d.ts CHANGED
@@ -48,13 +48,6 @@ export declare function isSnapKeyringType(keyringType: KeyringTypes | string): b
48
48
  * @returns True if the keyring type is considered a Snap keyring, false otherwise.
49
49
  */
50
50
  export declare function isSnapKeyringV2Type(keyringType: KeyringTypes | KeyringType | string): boolean;
51
- /**
52
- * Check if a keyring type is a watch-only keyring.
53
- *
54
- * @param keyringType - The account's keyring type.
55
- * @returns True if the keyring type is considered a watch-only keyring, false otherwise.
56
- */
57
- export declare function isWatchOnlyKeyringType(keyringType: KeyringTypes | KeyringType | string): boolean;
58
51
  /**
59
52
  * Check if a keyring type is a simple keyring.
60
53
  *
@@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AAG,MAAM,GACjC,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,YAAY,GAAG,MAAM,GAAG,OAAO,CAE5E;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,YAAY,GAAG,MAAM,GACjC,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIlE;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CA8BpB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iCAAiC;;;;;;;;EAI5C,CAAC;AACH,MAAM,MAAM,2BAA2B,GAAG,KAAK,CAC7C,OAAO,iCAAiC,CACzC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG;IACnD,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,GAAG,2BAA2B,CAAC;CACnE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,eAAe,GACvB,OAAO,IAAI,oBAAoB,CAEjC;AAED,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,GAC9C,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAM3B"}
package/dist/utils.js CHANGED
@@ -37,9 +37,6 @@ export function keyringTypeToName(keyringType) {
37
37
  case KeyringTypes.snap: {
38
38
  return 'Snap Account';
39
39
  }
40
- case KeyringType.WatchOnly: {
41
- return 'Watch-only Account';
42
- }
43
40
  // NOTE: We don't use those keyrings/accounts within this controller. However, since this
44
41
  // function only use the keyring type to return a name, we still support it here in case
45
42
  // clients need it.
@@ -105,15 +102,6 @@ export function isSnapKeyringType(keyringType) {
105
102
  export function isSnapKeyringV2Type(keyringType) {
106
103
  return keyringType === KeyringType.Snap;
107
104
  }
108
- /**
109
- * Check if a keyring type is a watch-only keyring.
110
- *
111
- * @param keyringType - The account's keyring type.
112
- * @returns True if the keyring type is considered a watch-only keyring, false otherwise.
113
- */
114
- export function isWatchOnlyKeyringType(keyringType) {
115
- return keyringType === KeyringType.WatchOnly;
116
- }
117
105
  /**
118
106
  * Check if a keyring type is a simple keyring.
119
107
  *
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAOlC;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,WAAmB;IACnD,QAAQ,WAAW,EAAE,CAAC;QACpB,KAAK,YAAY,CAAC,MAAM,EAAE,CAAC;YACzB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,KAAK,YAAY,CAAC,EAAE,EAAE,CAAC;YACrB,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,KAAK,YAAY,CAAC,MAAM,EAAE,CAAC;YACzB,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,KAAK,YAAY,CAAC,MAAM,EAAE,CAAC;YACzB,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,KAAK,YAAY,CAAC,MAAM,EAAE,CAAC;YACzB,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,KAAK,YAAY,CAAC,OAAO,EAAE,CAAC;YAC1B,OAAO,SAA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from '@metamask/keyring-api/v2';\nimport type { KeyringObject } from '@metamask/keyring-controller';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { Infer } from '@metamask/superstruct';\nimport { is, number, string, type } from '@metamask/superstruct';\nimport { hexToBytes } from '@metamask/utils';\nimport { sha256 } from 'ethereum-cryptography/sha256';\nimport { v4 as uuid } from 'uuid';\n\nimport type { AccountId } from './AccountsController.js';\n\n// This is exported by the `uuid` package, but not importable in ESM.\ntype V4Options = Exclude<Parameters<typeof uuid>[0], undefined>;\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 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.oneKey: {\n return 'OneKey';\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 KeyringType.Snap:\n case KeyringTypes.snap: {\n return 'Snap Account';\n }\n case KeyringType.WatchOnly: {\n return 'Watch-only Account';\n }\n // NOTE: We don't use those keyrings/accounts within this controller. However, since this\n // function only use the keyring type to return a name, we still support it here in case\n // clients need it.\n // FIXME: This should probably live in the `KeyringController` package instead.\n case KeyringTypes.money: {\n return 'Money';\n }\n case KeyringTypes.mpc: {\n return 'MPC';\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 *\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(hexToBytes(address)).slice(0, 16),\n };\n\n return v4options;\n}\n\n/**\n * Generates a UUID from a given Ethereum address.\n *\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 *\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(\n keyringType: KeyringTypes | string,\n): boolean {\n return (\n !isSnapKeyringType(keyringType) &&\n !isSnapKeyringV2Type(keyringType) &&\n !isSkippedKeyringType(keyringType)\n );\n}\n\n/**\n * Check if a keyring type is a Snap keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is considered a Snap keyring, false otherwise.\n */\nexport function isSnapKeyringType(keyringType: KeyringTypes | string): boolean {\n return keyringType === (KeyringTypes.snap as string);\n}\n\n/**\n * Check if a keyring type is a Snap keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is considered a Snap keyring, false otherwise.\n */\nexport function isSnapKeyringV2Type(\n keyringType: KeyringTypes | KeyringType | string,\n): boolean {\n return keyringType === (KeyringType.Snap as string);\n}\n\n/**\n * Check if a keyring type is a watch-only keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is considered a watch-only keyring, false otherwise.\n */\nexport function isWatchOnlyKeyringType(\n keyringType: KeyringTypes | KeyringType | string,\n): boolean {\n return keyringType === (KeyringType.WatchOnly as string);\n}\n\n/**\n * Check if a keyring type is a simple keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is considered a simple keyring, false otherwise.\n */\nexport function isSimpleKeyringType(\n keyringType: KeyringTypes | string,\n): boolean {\n return keyringType === (KeyringTypes.simple as string);\n}\n\n/**\n * Check if a keyring is a HD keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring is a HD keyring, false otherwise.\n */\nexport function isHdKeyringType(keyringType: KeyringTypes | string): boolean {\n return keyringType === (KeyringTypes.hd as string);\n}\n\n/**\n * Check if a keyring type is a Money keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is a Money keyring, false otherwise.\n */\nexport function isMoneyKeyringType(\n keyringType: KeyringTypes | string,\n): boolean {\n return keyringType === (KeyringTypes.money as string);\n}\n\n/**\n * Check if a keyring type is a MPC keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is a MPC keyring, false otherwise.\n */\nexport function isMpcKeyringType(keyringType: KeyringTypes | string): boolean {\n return keyringType === (KeyringTypes.mpc as string);\n}\n\n/**\n * Check if a keyring type is a skipped keyring (Money or MPC keyring).\n *\n * A skipped keyring is one that should be ignored during account\n * re-synchronization with the `KeyringController` (through `:stateChange` events\n * or `updateAccounts` calls).\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is considered a skipped keyring, false otherwise.\n */\nexport function isSkippedKeyringType(\n keyringType: KeyringTypes | string,\n): boolean {\n return isMoneyKeyringType(keyringType) || isMpcKeyringType(keyringType);\n}\n\n/**\n * Get the derivation path for the index of an account within a EVM HD keyring.\n *\n * @param index - The account index.\n * @returns The derivation path.\n */\nexport function getEvmDerivationPathForIndex(index: number): string {\n const purpose = '44';\n const coinType = '60'; // Ethereum.\n return `m/${purpose}'/${coinType}'/0'/0/${index}`;\n}\n\n/**\n * Get the group index from a keyring object (EVM HD keyring only) and an address.\n *\n * @param keyring - The keyring object.\n * @param address - The address to match.\n * @returns The group index for that address, undefined if not able to match the address.\n */\nexport function getEvmGroupIndexFromAddressIndex(\n keyring: KeyringObject,\n address: string,\n): number | undefined {\n // TODO: Remove this function once EVM HD keyrings start using the new unified\n // keyring API.\n\n // NOTE: We mostly put that logic in a separate function so we can easily add coverage\n // for (supposedly) unreachable code path.\n\n if (!isHdKeyringType(keyring.type)) {\n // We cannot extract the group index from non-HD keyrings.\n return undefined;\n }\n\n // We need to find the account index from its HD keyring. We assume those\n // accounts are ordered, thus we can use their index to compute their\n // derivation path and group index.\n const groupIndex = keyring.accounts.findIndex(\n // NOTE: This is ok to use `toLowerCase` here, since we're only dealing\n // with EVM addresses.\n (accountAddress) => accountAddress.toLowerCase() === address.toLowerCase(),\n );\n\n // If for some reason, we cannot find this address, then the caller made a mistake\n // and it did not use the proper keyring object. For now, we do not fail and just\n // consider this account as \"simple account\".\n if (groupIndex === -1) {\n console.warn(`! Unable to get group index for HD account: \"${address}\"`);\n return undefined;\n }\n\n return groupIndex;\n}\n\n/**\n * HD keyring account for Snap accounts that handles non-EVM HD accounts. (e.g the\n * Solana Snap).\n *\n * NOTE: We use `superstruct.type` here `superstruct.object` since it allows\n * extra-properties than a Snap might add in its `options`.\n */\nexport const HdSnapKeyringAccountOptionsStruct = type({\n entropySource: string(),\n index: number(),\n derivationPath: string(),\n});\nexport type HdSnapKeyringAccountOptions = Infer<\n typeof HdSnapKeyringAccountOptionsStruct\n>;\n\n/**\n * HD keyring account for Snap accounts that handles non-EVM HD accounts.\n */\nexport type HdSnapKeyringAccount = InternalAccount & {\n options: InternalAccount['options'] & HdSnapKeyringAccountOptions;\n};\n\n/**\n * Check if an account is an HD Snap keyring account.\n *\n * @param account - Snap keyring account.\n * @returns True if valid, false otherwise.\n */\nexport function isHdSnapKeyringAccount(\n account: InternalAccount,\n): account is HdSnapKeyringAccount {\n return is(account.options, HdSnapKeyringAccountOptionsStruct);\n}\n\nexport function constructAccountIdByAddress(\n accountsMap: Record<AccountId, InternalAccount>,\n): Record<string, AccountId> {\n const accounts = Object.values(accountsMap);\n return accounts.reduce<Record<string, AccountId>>((acc, account) => {\n acc[account.address] = account.id;\n return acc;\n }, {});\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAG5D,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,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f,cAAc,EAAE,MAAM,EAAE;CACzB,CAAC,CAAC;AAYH;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAAwB;IAExB,OAAO,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,iCAAiC,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,WAA+C;IAE/C,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC5C,OAAO,QAAQ,CAAC,MAAM,CAA4B,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;QACjE,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import { KeyringType } from '@metamask/keyring-api/v2';\nimport type { KeyringObject } from '@metamask/keyring-controller';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { Infer } from '@metamask/superstruct';\nimport { is, number, string, type } from '@metamask/superstruct';\nimport { hexToBytes } from '@metamask/utils';\nimport { sha256 } from 'ethereum-cryptography/sha256';\nimport { v4 as uuid } from 'uuid';\n\nimport type { AccountId } from './AccountsController.js';\n\n// This is exported by the `uuid` package, but not importable in ESM.\ntype V4Options = Exclude<Parameters<typeof uuid>[0], undefined>;\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 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.oneKey: {\n return 'OneKey';\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 KeyringType.Snap:\n case KeyringTypes.snap: {\n return 'Snap Account';\n }\n // NOTE: We don't use those keyrings/accounts within this controller. However, since this\n // function only use the keyring type to return a name, we still support it here in case\n // clients need it.\n // FIXME: This should probably live in the `KeyringController` package instead.\n case KeyringTypes.money: {\n return 'Money';\n }\n case KeyringTypes.mpc: {\n return 'MPC';\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 *\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(hexToBytes(address)).slice(0, 16),\n };\n\n return v4options;\n}\n\n/**\n * Generates a UUID from a given Ethereum address.\n *\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 *\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(\n keyringType: KeyringTypes | string,\n): boolean {\n return (\n !isSnapKeyringType(keyringType) &&\n !isSnapKeyringV2Type(keyringType) &&\n !isSkippedKeyringType(keyringType)\n );\n}\n\n/**\n * Check if a keyring type is a Snap keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is considered a Snap keyring, false otherwise.\n */\nexport function isSnapKeyringType(keyringType: KeyringTypes | string): boolean {\n return keyringType === (KeyringTypes.snap as string);\n}\n\n/**\n * Check if a keyring type is a Snap keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is considered a Snap keyring, false otherwise.\n */\nexport function isSnapKeyringV2Type(\n keyringType: KeyringTypes | KeyringType | string,\n): boolean {\n return keyringType === (KeyringType.Snap as string);\n}\n\n/**\n * Check if a keyring type is a simple keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is considered a simple keyring, false otherwise.\n */\nexport function isSimpleKeyringType(\n keyringType: KeyringTypes | string,\n): boolean {\n return keyringType === (KeyringTypes.simple as string);\n}\n\n/**\n * Check if a keyring is a HD keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring is a HD keyring, false otherwise.\n */\nexport function isHdKeyringType(keyringType: KeyringTypes | string): boolean {\n return keyringType === (KeyringTypes.hd as string);\n}\n\n/**\n * Check if a keyring type is a Money keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is a Money keyring, false otherwise.\n */\nexport function isMoneyKeyringType(\n keyringType: KeyringTypes | string,\n): boolean {\n return keyringType === (KeyringTypes.money as string);\n}\n\n/**\n * Check if a keyring type is a MPC keyring.\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is a MPC keyring, false otherwise.\n */\nexport function isMpcKeyringType(keyringType: KeyringTypes | string): boolean {\n return keyringType === (KeyringTypes.mpc as string);\n}\n\n/**\n * Check if a keyring type is a skipped keyring (Money or MPC keyring).\n *\n * A skipped keyring is one that should be ignored during account\n * re-synchronization with the `KeyringController` (through `:stateChange` events\n * or `updateAccounts` calls).\n *\n * @param keyringType - The account's keyring type.\n * @returns True if the keyring type is considered a skipped keyring, false otherwise.\n */\nexport function isSkippedKeyringType(\n keyringType: KeyringTypes | string,\n): boolean {\n return isMoneyKeyringType(keyringType) || isMpcKeyringType(keyringType);\n}\n\n/**\n * Get the derivation path for the index of an account within a EVM HD keyring.\n *\n * @param index - The account index.\n * @returns The derivation path.\n */\nexport function getEvmDerivationPathForIndex(index: number): string {\n const purpose = '44';\n const coinType = '60'; // Ethereum.\n return `m/${purpose}'/${coinType}'/0'/0/${index}`;\n}\n\n/**\n * Get the group index from a keyring object (EVM HD keyring only) and an address.\n *\n * @param keyring - The keyring object.\n * @param address - The address to match.\n * @returns The group index for that address, undefined if not able to match the address.\n */\nexport function getEvmGroupIndexFromAddressIndex(\n keyring: KeyringObject,\n address: string,\n): number | undefined {\n // TODO: Remove this function once EVM HD keyrings start using the new unified\n // keyring API.\n\n // NOTE: We mostly put that logic in a separate function so we can easily add coverage\n // for (supposedly) unreachable code path.\n\n if (!isHdKeyringType(keyring.type)) {\n // We cannot extract the group index from non-HD keyrings.\n return undefined;\n }\n\n // We need to find the account index from its HD keyring. We assume those\n // accounts are ordered, thus we can use their index to compute their\n // derivation path and group index.\n const groupIndex = keyring.accounts.findIndex(\n // NOTE: This is ok to use `toLowerCase` here, since we're only dealing\n // with EVM addresses.\n (accountAddress) => accountAddress.toLowerCase() === address.toLowerCase(),\n );\n\n // If for some reason, we cannot find this address, then the caller made a mistake\n // and it did not use the proper keyring object. For now, we do not fail and just\n // consider this account as \"simple account\".\n if (groupIndex === -1) {\n console.warn(`! Unable to get group index for HD account: \"${address}\"`);\n return undefined;\n }\n\n return groupIndex;\n}\n\n/**\n * HD keyring account for Snap accounts that handles non-EVM HD accounts. (e.g the\n * Solana Snap).\n *\n * NOTE: We use `superstruct.type` here `superstruct.object` since it allows\n * extra-properties than a Snap might add in its `options`.\n */\nexport const HdSnapKeyringAccountOptionsStruct = type({\n entropySource: string(),\n index: number(),\n derivationPath: string(),\n});\nexport type HdSnapKeyringAccountOptions = Infer<\n typeof HdSnapKeyringAccountOptionsStruct\n>;\n\n/**\n * HD keyring account for Snap accounts that handles non-EVM HD accounts.\n */\nexport type HdSnapKeyringAccount = InternalAccount & {\n options: InternalAccount['options'] & HdSnapKeyringAccountOptions;\n};\n\n/**\n * Check if an account is an HD Snap keyring account.\n *\n * @param account - Snap keyring account.\n * @returns True if valid, false otherwise.\n */\nexport function isHdSnapKeyringAccount(\n account: InternalAccount,\n): account is HdSnapKeyringAccount {\n return is(account.options, HdSnapKeyringAccountOptionsStruct);\n}\n\nexport function constructAccountIdByAddress(\n accountsMap: Record<AccountId, InternalAccount>,\n): Record<string, AccountId> {\n const accounts = Object.values(accountsMap);\n return accounts.reduce<Record<string, AccountId>>((acc, account) => {\n acc[account.address] = account.id;\n return acc;\n }, {});\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/accounts-controller",
3
- "version": "40.0.0-preview-5e76941",
3
+ "version": "40.0.0-preview-2bc848240",
4
4
  "description": "Manages internal accounts",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -62,7 +62,6 @@
62
62
  "@metamask/network-controller": "^37.0.1",
63
63
  "@metamask/superstruct": "^3.4.1",
64
64
  "@metamask/utils": "^12.0.0",
65
- "@metamask/watch-only-keyring": "^0.0.0",
66
65
  "deepmerge": "^4.3.1",
67
66
  "ethereum-cryptography": "^2.2.1",
68
67
  "immer": "^11.1.18",