@metamask-previews/network-enablement-controller 4.2.0-preview-cd2daacf2 → 4.2.0-preview-d3b0814a7
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 +0 -19
- package/dist/NetworkEnablementController.cjs +0 -13
- package/dist/NetworkEnablementController.cjs.map +1 -1
- package/dist/NetworkEnablementController.d.cts +21 -2
- package/dist/NetworkEnablementController.d.cts.map +1 -1
- package/dist/NetworkEnablementController.d.mts +21 -2
- package/dist/NetworkEnablementController.d.mts.map +1 -1
- package/dist/NetworkEnablementController.mjs +0 -13
- package/dist/NetworkEnablementController.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -5
- package/dist/NetworkEnablementController-method-action-types.cjs +0 -7
- package/dist/NetworkEnablementController-method-action-types.cjs.map +0 -1
- package/dist/NetworkEnablementController-method-action-types.d.cts +0 -171
- package/dist/NetworkEnablementController-method-action-types.d.cts.map +0 -1
- package/dist/NetworkEnablementController-method-action-types.d.mts +0 -171
- package/dist/NetworkEnablementController-method-action-types.d.mts.map +0 -1
- package/dist/NetworkEnablementController-method-action-types.mjs +0 -6
- package/dist/NetworkEnablementController-method-action-types.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,25 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- Expose missing public `NetworkEnablementController` methods through its messenger ([#8164](https://github.com/MetaMask/core/pull/8164))
|
|
13
|
-
- The following actions are now available:
|
|
14
|
-
- `NetworkEnablementController:init`
|
|
15
|
-
- `NetworkEnablementController:initNativeAssetIdentifiers`
|
|
16
|
-
- `NetworkEnablementController:enableNetworkInNamespace`
|
|
17
|
-
- `NetworkEnablementController:enableAllPopularNetworks`
|
|
18
|
-
- `NetworkEnablementController:isNetworkEnabled`
|
|
19
|
-
- Corresponding action type (`NetworkEnablementControllerIsNetworkEnabledAction`) is available as well.
|
|
20
|
-
|
|
21
|
-
### Changed
|
|
22
|
-
|
|
23
|
-
- **BREAKING:** Standardize names of `NetworkEnablementController` messenger action types ([#8164](https://github.com/MetaMask/core/pull/8164))
|
|
24
|
-
- The `NetworkEnablementController` action `NetworkEnablementControllerSetEnabledNetworksAction` has been renamed to `NetworkEnablementControllerEnableNetworkAction` so it matches the method name.
|
|
25
|
-
- These changes only affect the types. The action type strings themselves have not changed, so you do not need to update the list of actions you pass when initializing `NetworkEnablementController` messengers.
|
|
26
|
-
- Bump `@metamask/multichain-network-controller` from `^3.0.4` to `^3.0.5` ([#8140](https://github.com/MetaMask/core/pull/8140))
|
|
27
|
-
- Bump `@metamask/transaction-controller` from `^62.20.0` to `^62.21.0` ([#8140](https://github.com/MetaMask/core/pull/8140))
|
|
28
|
-
|
|
29
10
|
## [4.2.0]
|
|
30
11
|
|
|
31
12
|
### Added
|
|
@@ -16,18 +16,6 @@ const constants_1 = require("./constants.cjs");
|
|
|
16
16
|
const services_1 = require("./services/index.cjs");
|
|
17
17
|
const utils_2 = require("./utils.cjs");
|
|
18
18
|
const controllerName = 'NetworkEnablementController';
|
|
19
|
-
const MESSENGER_EXPOSED_METHODS = [
|
|
20
|
-
'init',
|
|
21
|
-
'initNativeAssetIdentifiers',
|
|
22
|
-
'enableNetwork',
|
|
23
|
-
'disableNetwork',
|
|
24
|
-
'enableNetworkInNamespace',
|
|
25
|
-
'enableAllPopularNetworks',
|
|
26
|
-
'isNetworkEnabled',
|
|
27
|
-
'listPopularNetworks',
|
|
28
|
-
'listPopularEvmNetworks',
|
|
29
|
-
'listPopularMultichainNetworks',
|
|
30
|
-
];
|
|
31
19
|
/**
|
|
32
20
|
* Builds a native asset identifier in CAIP-19-like format.
|
|
33
21
|
*
|
|
@@ -118,7 +106,6 @@ class NetworkEnablementController extends base_controller_1.BaseController {
|
|
|
118
106
|
},
|
|
119
107
|
});
|
|
120
108
|
_NetworkEnablementController_instances.add(this);
|
|
121
|
-
messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
122
109
|
messenger.subscribe('NetworkController:networkAdded', ({ chainId }) => {
|
|
123
110
|
// eslint-disable-next-line no-void
|
|
124
111
|
void __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_onAddNetwork).call(this, chainId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkEnablementController.cjs","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+DAA2D;AAK3D,iEAAyE;AACzE,uDAAqE;AAGrE,2FAA2E;AAS3E,2CAAqD;AAErD,+CAA+C;AAE/C,mDAA2C;AAC3C,uCAIiB;AAEjB,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAErD,MAAM,yBAAyB,GAAG;IAChC,MAAM;IACN,4BAA4B;IAC5B,eAAe;IACf,gBAAgB;IAChB,0BAA0B;IAC1B,0BAA0B;IAC1B,kBAAkB;IAClB,qBAAqB;IACrB,wBAAwB;IACxB,+BAA+B;CACvB,CAAC;AAuFX;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,WAAwB,EACxB,cAAsB;IAEtB,OAAO,GAAG,WAAW,WAAW,cAAc,EAAE,CAAC;AACnD,CAAC;AAWD;;;;GAIG;AACH,MAAM,0CAA0C,GAC9C,GAAqC,EAAE,CAAC,CAAC;IACvC,iBAAiB,EAAE;QACjB,CAAC,0BAAkB,CAAC,MAAM,CAAC,EAAE;YAC3B,CAAC,0BAAO,CAAC,qCAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI;YAC3C,CAAC,0BAAO,CAAC,qCAAkB,CAAC,YAAY,CAAC,CAAC,EAAE,IAA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CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;gBAClD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;oBACvD,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,GAAwB,CAAC,GAAG,KAAK,CAAC;gBAChE,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YACH,iCAAiC;YACjC,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;QACxD,CAAC;QAED,iEAAiE;QACjE,KAAK,CAAC,sBAAsB,CAAC,WAAW,CAAC,GAAG,0BAA0B,CACpE,WAAW,EACX,cAAc,CACf,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BuiltInNetworkName, ChainId } from '@metamask/controller-utils';\nimport { BtcScope, SolScope, TrxScope } from '@metamask/keyring-api';\nimport type { Messenger } from '@metamask/messenger';\nimport type { MultichainNetworkControllerGetStateAction } from '@metamask/multichain-network-controller';\nimport { toEvmCaipChainId } from '@metamask/multichain-network-controller';\nimport type {\n NetworkControllerGetStateAction,\n NetworkControllerNetworkAddedEvent,\n NetworkControllerNetworkRemovedEvent,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport type { TransactionControllerTransactionSubmittedEvent } from '@metamask/transaction-controller';\nimport type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';\nimport { KnownCaipNamespace } from '@metamask/utils';\n\nimport { POPULAR_NETWORKS } from './constants';\nimport type { NetworkEnablementControllerMethodActions } from './NetworkEnablementController-method-action-types';\nimport { Slip44Service } from './services';\nimport {\n deriveKeys,\n isOnlyNetworkEnabledInNamespace,\n isPopularNetwork,\n} from './utils';\n\nconst controllerName = 'NetworkEnablementController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'init',\n 'initNativeAssetIdentifiers',\n 'enableNetwork',\n 'disableNetwork',\n 'enableNetworkInNamespace',\n 'enableAllPopularNetworks',\n 'isNetworkEnabled',\n 'listPopularNetworks',\n 'listPopularEvmNetworks',\n 'listPopularMultichainNetworks',\n] as const;\n\n/**\n * Information about an ordered network.\n */\nexport type NetworksInfo = {\n /**\n * The network's chain id\n */\n networkId: CaipChainId;\n};\n\n/**\n * A map of enabled networks by CAIP namespace and chain ID.\n * For EIP-155 networks, the keys are Hex chain IDs.\n * For other networks, the keys are CAIP chain IDs.\n */\ntype EnabledMap = Record<CaipNamespace, Record<CaipChainId | Hex, boolean>>;\n\n/**\n * A native asset identifier in CAIP-19-like format.\n * Format: `{caip2ChainId}/slip44:{coinType}`\n *\n * @example\n * - `eip155:1/slip44:60` for Ethereum mainnet (ETH)\n * - `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501` for Solana mainnet (SOL)\n * - `bip122:000000000019d6689c085ae165831e93/slip44:0` for Bitcoin mainnet (BTC)\n */\nexport type NativeAssetIdentifier = `${CaipChainId}/slip44:${number}`;\n\n/**\n * A map of CAIP-2 chain IDs to their native asset identifiers.\n * Uses CAIP-19-like format to identify the native asset for each chain.\n *\n * @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md\n */\nexport type NativeAssetIdentifiersMap = Record<\n CaipChainId,\n NativeAssetIdentifier\n>;\n\n// State shape for NetworkEnablementController\nexport type NetworkEnablementControllerState = {\n enabledNetworkMap: EnabledMap;\n nativeAssetIdentifiers: NativeAssetIdentifiersMap;\n};\n\nexport type NetworkEnablementControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NetworkEnablementControllerState\n >;\n/**\n * All actions that {@link NetworkEnablementController} calls internally.\n */\nexport type AllowedActions =\n | NetworkControllerGetStateAction\n | MultichainNetworkControllerGetStateAction;\n\nexport type NetworkEnablementControllerActions =\n | NetworkEnablementControllerGetStateAction\n | NetworkEnablementControllerMethodActions;\n\nexport type NetworkEnablementControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NetworkEnablementControllerState\n >;\n\nexport type NetworkEnablementControllerEvents =\n NetworkEnablementControllerStateChangeEvent;\n\n/**\n * All events that {@link NetworkEnablementController} subscribes to internally.\n */\nexport type AllowedEvents =\n | NetworkControllerNetworkAddedEvent\n | NetworkControllerNetworkRemovedEvent\n | NetworkControllerStateChangeEvent\n | TransactionControllerTransactionSubmittedEvent;\n\nexport type NetworkEnablementControllerMessenger = Messenger<\n typeof controllerName,\n NetworkEnablementControllerActions | AllowedActions,\n NetworkEnablementControllerEvents | AllowedEvents\n>;\n\n/**\n * Builds a native asset identifier in CAIP-19-like format.\n *\n * @param caipChainId - The CAIP-2 chain ID (e.g., 'eip155:1', 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')\n * @param slip44CoinType - The SLIP-44 coin type number\n * @returns The native asset identifier string (e.g., 'eip155:1/slip44:60')\n */\nfunction buildNativeAssetIdentifier(\n caipChainId: CaipChainId,\n slip44CoinType: number,\n): NativeAssetIdentifier {\n return `${caipChainId}/slip44:${slip44CoinType}`;\n}\n\n/**\n * Network configuration with chain ID and native currency symbol.\n * Used to initialize native asset identifiers.\n */\nexport type NetworkConfig = {\n chainId: CaipChainId;\n nativeCurrency: string;\n};\n\n/**\n * Gets the default state for the NetworkEnablementController.\n *\n * @returns The default state with pre-enabled networks.\n */\nconst getDefaultNetworkEnablementControllerState =\n (): NetworkEnablementControllerState => ({\n enabledNetworkMap: {\n [KnownCaipNamespace.Eip155]: {\n [ChainId[BuiltInNetworkName.Mainnet]]: true,\n [ChainId[BuiltInNetworkName.LineaMainnet]]: true,\n [ChainId[BuiltInNetworkName.BaseMainnet]]: true,\n [ChainId[BuiltInNetworkName.ArbitrumOne]]: true,\n [ChainId[BuiltInNetworkName.BscMainnet]]: true,\n [ChainId[BuiltInNetworkName.OptimismMainnet]]: true,\n [ChainId[BuiltInNetworkName.PolygonMainnet]]: true,\n [ChainId[BuiltInNetworkName.SeiMainnet]]: true,\n },\n [KnownCaipNamespace.Solana]: {\n [SolScope.Mainnet]: true,\n [SolScope.Testnet]: false,\n [SolScope.Devnet]: false,\n },\n [KnownCaipNamespace.Bip122]: {\n [BtcScope.Mainnet]: true,\n [BtcScope.Testnet]: false,\n [BtcScope.Signet]: false,\n },\n [KnownCaipNamespace.Tron]: {\n [TrxScope.Mainnet]: true,\n [TrxScope.Nile]: false,\n [TrxScope.Shasta]: false,\n },\n },\n // nativeAssetIdentifiers is initialized as empty and should be populated\n // by the client using initNativeAssetIdentifiers() during controller init\n nativeAssetIdentifiers: {},\n });\n\n// Metadata for the controller state\nconst metadata = {\n enabledNetworkMap: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n nativeAssetIdentifiers: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\n/**\n * Controller responsible for managing network enablement state across different blockchain networks.\n *\n * This controller tracks which networks are enabled/disabled for the user and provides methods\n * to toggle network states. It supports both EVM (EIP-155) and non-EVM networks like Solana.\n *\n * The controller maintains a map of enabled networks organized by namespace (e.g., 'eip155', 'solana')\n * and provides methods to query and modify network enablement states.\n */\nexport class NetworkEnablementController extends BaseController<\n typeof controllerName,\n NetworkEnablementControllerState,\n NetworkEnablementControllerMessenger\n> {\n /**\n * Creates a NetworkEnablementController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: NetworkEnablementControllerMessenger;\n state?: Partial<NetworkEnablementControllerState>;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: {\n ...getDefaultNetworkEnablementControllerState(),\n ...state,\n },\n });\n\n messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);\n\n messenger.subscribe('NetworkController:networkAdded', ({ chainId }) => {\n // eslint-disable-next-line no-void\n void this.#onAddNetwork(chainId);\n });\n\n messenger.subscribe('NetworkController:networkRemoved', ({ chainId }) => {\n this.#removeNetworkEntry(chainId);\n });\n }\n\n /**\n * Enables or disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally. This dual parameter support allows for backward\n * compatibility with existing EVM chain ID formats while supporting newer\n * multi-chain standards.\n *\n * When enabling a non-popular network, this method will disable all other networks\n * to ensure only one network is active at a time (exclusive mode).\n *\n * @param chainId - The chain ID of the network to enable or disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\n enableNetwork(chainId: Hex | CaipChainId): void {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n this.update((state) => {\n // disable all networks in all namespaces first\n Object.keys(state.enabledNetworkMap).forEach((ns) => {\n Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {\n state.enabledNetworkMap[ns][key as CaipChainId | Hex] = false;\n });\n });\n\n // if the namespace bucket does not exist, return\n // new nemespace are added only when a new network is added\n if (!state.enabledNetworkMap[namespace]) {\n return;\n }\n\n // enable the network\n state.enabledNetworkMap[namespace][storageKey] = true;\n });\n }\n\n /**\n * Enables a network for the user within a specific namespace.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and enables it within the specified namespace.\n * The method validates that the chainId belongs to the specified namespace for safety.\n *\n * Before enabling the target network, this method disables all other networks\n * in the same namespace to ensure exclusive behavior within the namespace.\n *\n * @param chainId - The chain ID of the network to enable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @param namespace - The CAIP namespace where the network should be enabled\n * @throws Error if the chainId's derived namespace doesn't match the provided namespace\n */\n enableNetworkInNamespace(\n chainId: Hex | CaipChainId,\n namespace: CaipNamespace,\n ): void {\n const { namespace: derivedNamespace, storageKey } = deriveKeys(chainId);\n\n // Validate that the derived namespace matches the provided namespace\n if (derivedNamespace !== namespace) {\n throw new Error(\n `Chain ID ${chainId} belongs to namespace ${derivedNamespace}, but namespace ${namespace} was specified`,\n );\n }\n\n this.update((state) => {\n // Ensure the namespace bucket exists\n this.#ensureNamespaceBucket(state, namespace);\n\n // Disable all networks in the specified namespace first\n if (state.enabledNetworkMap[namespace]) {\n Object.keys(state.enabledNetworkMap[namespace]).forEach((key) => {\n state.enabledNetworkMap[namespace][key as CaipChainId | Hex] = false;\n });\n }\n\n // Enable the target network in the specified namespace\n state.enabledNetworkMap[namespace][storageKey] = true;\n });\n }\n\n /**\n * Enables all popular networks and Solana mainnet.\n *\n * This method first disables all networks across all namespaces, then enables\n * all networks defined in POPULAR_NETWORKS (EVM networks), Solana mainnet, and\n * Bitcoin mainnet. This provides exclusive behavior - only popular networks will\n * be enabled after calling this method.\n *\n * Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.\n */\n enableAllPopularNetworks(): void {\n this.update((state) => {\n // First disable all networks across all namespaces\n Object.keys(state.enabledNetworkMap).forEach((ns) => {\n Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {\n state.enabledNetworkMap[ns][key as CaipChainId | Hex] = false;\n });\n });\n\n // Get current network configurations to check if networks exist\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n const multichainState = this.messenger.call(\n 'MultichainNetworkController:getState',\n );\n\n // Enable all popular EVM networks that exist in NetworkController configurations\n POPULAR_NETWORKS.forEach((chainId) => {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n // Check if network exists in NetworkController configurations\n if (networkControllerState.networkConfigurationsByChainId[chainId]) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, namespace);\n // Enable the network\n state.enabledNetworkMap[namespace][storageKey] = true;\n }\n });\n\n // Enable Solana mainnet if it exists in MultichainNetworkController configurations\n const solanaKeys = deriveKeys(SolScope.Mainnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n SolScope.Mainnet\n ]\n ) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, solanaKeys.namespace);\n // Enable Solana mainnet\n state.enabledNetworkMap[solanaKeys.namespace][solanaKeys.storageKey] =\n true;\n }\n\n // Enable Bitcoin mainnet if it exists in MultichainNetworkController configurations\n const bitcoinKeys = deriveKeys(BtcScope.Mainnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n BtcScope.Mainnet\n ]\n ) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, bitcoinKeys.namespace);\n // Enable Bitcoin mainnet\n state.enabledNetworkMap[bitcoinKeys.namespace][bitcoinKeys.storageKey] =\n true;\n }\n\n // Enable Tron mainnet if it exists in MultichainNetworkController configurations\n const tronKeys = deriveKeys(TrxScope.Mainnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n TrxScope.Mainnet\n ]\n ) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, tronKeys.namespace);\n // Enable Tron mainnet\n state.enabledNetworkMap[tronKeys.namespace][tronKeys.storageKey] = true;\n }\n });\n }\n\n /**\n * Initializes the network enablement state from network controller configurations.\n *\n * This method reads the current network configurations from both NetworkController\n * and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.\n * It ensures proper namespace buckets exist for all configured networks and only\n * adds missing networks with a default value of false, preserving existing user settings.\n *\n * This method should be called after the NetworkController and MultichainNetworkController\n * have been initialized and their configurations are available.\n */\n async init(): Promise<void> {\n // Get network configurations from NetworkController (EVM networks)\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n\n // Get network configurations from MultichainNetworkController (all networks)\n const multichainState = this.messenger.call(\n 'MultichainNetworkController:getState',\n );\n\n // Build nativeAssetIdentifiers for EVM networks using chainid.network\n const evmNativeAssetUpdates: {\n caipChainId: CaipChainId;\n identifier: NativeAssetIdentifier;\n }[] = [];\n\n for (const [chainId] of Object.entries(\n networkControllerState.networkConfigurationsByChainId,\n )) {\n const { caipChainId } = deriveKeys(chainId as Hex);\n\n // Skip if already in state\n if (this.state.nativeAssetIdentifiers[caipChainId] !== undefined) {\n continue;\n }\n\n // Parse hex chainId to number for chainid.network lookup\n const numericChainId = parseInt(chainId, 16);\n\n // EVM networks: use getEvmSlip44 (chainid.network data)\n const slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);\n\n evmNativeAssetUpdates.push({\n caipChainId,\n identifier: buildNativeAssetIdentifier(caipChainId, slip44CoinType),\n });\n }\n\n // Update state synchronously\n this.update((state) => {\n // Initialize namespace buckets for EVM networks from NetworkController\n Object.entries(\n networkControllerState.networkConfigurationsByChainId,\n ).forEach(([chainId]) => {\n const { namespace, storageKey } = deriveKeys(chainId as Hex);\n this.#ensureNamespaceBucket(state, namespace);\n\n // Only add network if it doesn't already exist in state (preserves user settings)\n state.enabledNetworkMap[namespace][storageKey] ??= false;\n });\n\n // Apply nativeAssetIdentifier updates\n for (const { caipChainId, identifier } of evmNativeAssetUpdates) {\n state.nativeAssetIdentifiers[caipChainId] = identifier;\n }\n\n // Initialize namespace buckets for all networks from MultichainNetworkController\n Object.keys(\n multichainState.multichainNetworkConfigurationsByChainId,\n ).forEach((chainId) => {\n const { namespace, storageKey } = deriveKeys(chainId as CaipChainId);\n this.#ensureNamespaceBucket(state, namespace);\n\n // Only add network if it doesn't already exist in state (preserves user settings)\n state.enabledNetworkMap[namespace][storageKey] ??= false;\n });\n });\n }\n\n /**\n * Initializes the native asset identifiers from network configurations.\n * This method should be called from the client during controller initialization\n * to populate the nativeAssetIdentifiers state based on actual network configurations.\n *\n * @param networks - Array of network configurations with chainId and nativeCurrency\n * @example\n * ```typescript\n * const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)\n * .map(config => ({\n * chainId: toEvmCaipChainId(config.chainId),\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)\n * .map(config => ({\n * chainId: config.chainId,\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * await controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);\n * ```\n */\n async initNativeAssetIdentifiers(networks: NetworkConfig[]): Promise<void> {\n // Process networks and collect updates\n const updates: {\n chainId: CaipChainId;\n identifier: NativeAssetIdentifier;\n }[] = [];\n\n for (const { chainId, nativeCurrency } of networks) {\n // Check if nativeCurrency is already in CAIP-19 format (e.g., \"bip122:.../slip44:0\")\n // Non-EVM networks from MultichainNetworkController use this format\n if (nativeCurrency.includes('/slip44:')) {\n updates.push({\n chainId,\n identifier: nativeCurrency as NativeAssetIdentifier,\n });\n continue;\n }\n\n // Extract namespace from CAIP-2 chainId\n const [namespace, reference] = chainId.split(':');\n let slip44CoinType: number | undefined;\n\n if (namespace === 'eip155') {\n // EVM networks: use getEvmSlip44 (chainid.network data)\n const numericChainId = parseInt(reference, 10);\n slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);\n } else {\n // Non-EVM networks: use getSlip44BySymbol (@metamask/slip44 package)\n slip44CoinType = Slip44Service.getSlip44BySymbol(nativeCurrency);\n }\n\n if (slip44CoinType !== undefined) {\n updates.push({\n chainId,\n identifier: buildNativeAssetIdentifier(chainId, slip44CoinType),\n });\n }\n }\n\n // Apply all updates synchronously\n this.update((state) => {\n for (const { chainId, identifier } of updates) {\n state.nativeAssetIdentifiers[chainId] = identifier;\n }\n });\n }\n\n /**\n * Disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally.\n *\n * Note: This method will prevent disabling the last remaining enabled network\n * to ensure at least one network is always available.\n *\n * @param chainId - The chain ID of the network to disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\n disableNetwork(chainId: Hex | CaipChainId): void {\n const derivedKeys = deriveKeys(chainId);\n const { namespace, storageKey } = derivedKeys;\n\n this.update((state) => {\n state.enabledNetworkMap[namespace][storageKey] = false;\n });\n }\n\n /**\n * Checks if a network is enabled.\n *\n * @param chainId - The chain ID of the network to check. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @returns True if the network is enabled, false otherwise\n */\n isNetworkEnabled(chainId: Hex | CaipChainId): boolean {\n const derivedKeys = deriveKeys(chainId);\n const { namespace, storageKey } = derivedKeys;\n return this.state.enabledNetworkMap[namespace]?.[storageKey] ?? false;\n }\n\n /**\n * Ensures that a namespace bucket exists in the state.\n *\n * This method creates the namespace entry in the enabledNetworkMap if it doesn't\n * already exist. This is used to prepare the state structure before adding\n * network entries.\n *\n * @param state - The current controller state\n * @param ns - The CAIP namespace to ensure exists\n */\n #ensureNamespaceBucket(\n state: NetworkEnablementControllerState,\n ns: CaipNamespace,\n ): void {\n if (!state.enabledNetworkMap[ns]) {\n state.enabledNetworkMap[ns] = {};\n }\n }\n\n /**\n * Checks if popular networks mode is active (more than 2 popular networks enabled).\n *\n * This method counts how many networks defined in POPULAR_NETWORKS are currently\n * enabled in the state and returns true if more than 2 are enabled. It only checks\n * networks that actually exist in the NetworkController configurations.\n *\n * @returns True if more than 2 popular networks are enabled, false otherwise\n */\n #isInPopularNetworksMode(): boolean {\n // Get current network configurations to check which popular networks exist\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n\n // Count how many popular networks are enabled\n const enabledPopularNetworksCount = POPULAR_NETWORKS.reduce(\n (count, chainId) => {\n // Only check networks that actually exist in NetworkController configurations\n if (!networkControllerState.networkConfigurationsByChainId[chainId]) {\n return count; // Skip networks that don't exist\n }\n\n const { namespace, storageKey } = deriveKeys(chainId);\n const isEnabled = this.state.enabledNetworkMap[namespace]?.[storageKey];\n return isEnabled ? count + 1 : count;\n },\n 0,\n );\n\n // Return true if more than 2 popular networks are enabled\n return enabledPopularNetworksCount > 1;\n }\n\n /**\n * Removes a network entry from the state.\n *\n * This method is called when a network is removed from the system. It cleans up\n * the network entry from both enabledNetworkMap and nativeAssetIdentifiers, and ensures that\n * at least one network remains enabled.\n *\n * @param chainId - The chain ID to remove (Hex or CAIP-2 format)\n */\n #removeNetworkEntry(chainId: Hex | CaipChainId): void {\n const derivedKeys = deriveKeys(chainId);\n const { namespace, storageKey, caipChainId } = derivedKeys;\n\n this.update((state) => {\n // fallback and enable ethereum mainnet\n if (isOnlyNetworkEnabledInNamespace(this.state, derivedKeys)) {\n state.enabledNetworkMap[namespace][\n ChainId[BuiltInNetworkName.Mainnet]\n ] = true;\n }\n\n if (namespace in state.enabledNetworkMap) {\n delete state.enabledNetworkMap[namespace][storageKey];\n }\n\n // Remove from nativeAssetIdentifiers as well\n delete state.nativeAssetIdentifiers[caipChainId];\n });\n }\n\n /**\n * Handles the addition of a new EVM network to the controller.\n *\n * @param chainId - The chain ID to add (Hex format)\n *\n * @description\n * - If in popular networks mode (>2 popular networks enabled) AND adding a popular network:\n * - Keep current selection (add but don't enable the new network)\n * - Otherwise:\n * - Switch to the newly added network (disable all others, enable this one)\n * - Also updates the nativeAssetIdentifiers with the CAIP-19-like identifier\n */\n async #onAddNetwork(chainId: Hex): Promise<void> {\n const { namespace, storageKey, reference, caipChainId } =\n deriveKeys(chainId);\n\n // Parse reference (decimal string from CAIP-2) to number for chainid.network lookup\n const numericChainId = parseInt(reference, 10);\n\n // EVM networks: use getEvmSlip44 (chainid.network data)\n const slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);\n\n this.update((state) => {\n // Ensure the namespace bucket exists\n this.#ensureNamespaceBucket(state, namespace);\n\n // Check if popular networks mode is active (>2 popular networks enabled)\n const inPopularNetworksMode = this.#isInPopularNetworksMode();\n\n // Check if the network being added is a popular network\n const isAddedNetworkPopular = isPopularNetwork(reference);\n\n // Keep current selection only if in popular networks mode AND adding a popular network\n const shouldKeepCurrentSelection =\n inPopularNetworksMode && isAddedNetworkPopular;\n\n if (shouldKeepCurrentSelection) {\n // Add the popular network but don't enable it (keep current selection)\n state.enabledNetworkMap[namespace][storageKey] = true;\n } else {\n // Switch to the newly added network (disable all others, enable this one)\n Object.keys(state.enabledNetworkMap).forEach((ns) => {\n Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {\n state.enabledNetworkMap[ns][key as CaipChainId | Hex] = false;\n });\n });\n // Enable the newly added network\n state.enabledNetworkMap[namespace][storageKey] = true;\n }\n\n // Update nativeAssetIdentifiers with the CAIP-19-like identifier\n state.nativeAssetIdentifiers[caipChainId] = buildNativeAssetIdentifier(\n caipChainId,\n slip44CoinType,\n );\n });\n }\n\n /**\n * Returns popular EVM network chain IDs in hex form, restricted to networks\n * that exist in NetworkController (networkConfigurationsByChainId). Source list\n * is POPULAR_NETWORKS.\n *\n * @returns Hex chain IDs for popular EVM networks that are configured.\n */\n listPopularEvmNetworks(): Hex[] {\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n return POPULAR_NETWORKS.filter(\n (chainIdHex) =>\n networkControllerState.networkConfigurationsByChainId[chainIdHex],\n );\n }\n\n /**\n * Returns popular multichain (Bitcoin, Solana, Tron) mainnet chain IDs in\n * CAIP-2 form, restricted to networks that exist in MultichainNetworkController\n * (multichainNetworkConfigurationsByChainId).\n *\n * @returns CAIP-2 chain IDs for Bitcoin, Solana, and Tron mainnets that are configured.\n */\n listPopularMultichainNetworks(): CaipChainId[] {\n const multichainState = this.messenger.call(\n 'MultichainNetworkController:getState',\n );\n const multichainMainnets = [\n BtcScope.Mainnet,\n SolScope.Mainnet,\n TrxScope.Mainnet,\n ] as const;\n return multichainMainnets.filter(\n (chainId) =>\n multichainState.multichainNetworkConfigurationsByChainId[chainId],\n );\n }\n\n /**\n * Returns the list of popular network chain IDs in CAIP-2 form, restricted to\n * networks that exist in NetworkController (networkConfigurationsByChainId) and\n * MultichainNetworkController (multichainNetworkConfigurationsByChainId). EVM\n * popular networks come from POPULAR_NETWORKS; multichain popular are Bitcoin,\n * Solana, and Tron mainnets.\n *\n * @returns CAIP-2 chain IDs for popular EVM networks and multichain mainnets that are configured.\n */\n listPopularNetworks(): CaipChainId[] {\n const evmHex = this.listPopularEvmNetworks();\n const evmCaip = evmHex.map((chainIdHex) => toEvmCaipChainId(chainIdHex));\n return [...evmCaip, ...this.listPopularMultichainNetworks()];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NetworkEnablementController.cjs","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+DAA2D;AAK3D,iEAAyE;AACzE,uDAAqE;AAGrE,2FAA2E;AAS3E,2CAAqD;AAErD,+CAA+C;AAC/C,mDAA2C;AAC3C,uCAIiB;AAEjB,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAqHrD;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,WAAwB,EACxB,cAAsB;IAEtB,OAAO,GAAG,WAAW,WAAW,cAAc,EAAE,CAAC;AACnD,CAAC;AAWD;;;;GAIG;AACH,MAAM,0CAA0C,GAC9C,GAAqC,EAAE,CAAC,CAAC;IACvC,iBAAiB,EAAE;QACjB,CAAC,0BAAkB,CAAC,MAAM,CAAC,EAAE;YAC3B,CAAC,0BAAO,CAAC,qCAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI;YAC3C,CAAC,0BAAO,CAAC,qCAAkB,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI;YAChD,CAAC,0BAAO,CAAC,qCAAkB,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI;YAC/C,CAAC,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CAAC,CAAC,GAAG,EAAE,EAAE;oBACvD,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,GAAwB,CAAC,GAAG,KAAK,CAAC;gBAChE,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YACH,iCAAiC;YACjC,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;QACxD,CAAC;QAED,iEAAiE;QACjE,KAAK,CAAC,sBAAsB,CAAC,WAAW,CAAC,GAAG,0BAA0B,CACpE,WAAW,EACX,cAAc,CACf,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BuiltInNetworkName, ChainId } from '@metamask/controller-utils';\nimport { BtcScope, SolScope, TrxScope } from '@metamask/keyring-api';\nimport type { Messenger } from '@metamask/messenger';\nimport type { MultichainNetworkControllerGetStateAction } from '@metamask/multichain-network-controller';\nimport { toEvmCaipChainId } from '@metamask/multichain-network-controller';\nimport type {\n NetworkControllerGetStateAction,\n NetworkControllerNetworkAddedEvent,\n NetworkControllerNetworkRemovedEvent,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport type { TransactionControllerTransactionSubmittedEvent } from '@metamask/transaction-controller';\nimport type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';\nimport { KnownCaipNamespace } from '@metamask/utils';\n\nimport { POPULAR_NETWORKS } from './constants';\nimport { Slip44Service } from './services';\nimport {\n deriveKeys,\n isOnlyNetworkEnabledInNamespace,\n isPopularNetwork,\n} from './utils';\n\nconst controllerName = 'NetworkEnablementController';\n\n/**\n * Information about an ordered network.\n */\nexport type NetworksInfo = {\n /**\n * The network's chain id\n */\n networkId: CaipChainId;\n};\n\n/**\n * A map of enabled networks by CAIP namespace and chain ID.\n * For EIP-155 networks, the keys are Hex chain IDs.\n * For other networks, the keys are CAIP chain IDs.\n */\ntype EnabledMap = Record<CaipNamespace, Record<CaipChainId | Hex, boolean>>;\n\n/**\n * A native asset identifier in CAIP-19-like format.\n * Format: `{caip2ChainId}/slip44:{coinType}`\n *\n * @example\n * - `eip155:1/slip44:60` for Ethereum mainnet (ETH)\n * - `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501` for Solana mainnet (SOL)\n * - `bip122:000000000019d6689c085ae165831e93/slip44:0` for Bitcoin mainnet (BTC)\n */\nexport type NativeAssetIdentifier = `${CaipChainId}/slip44:${number}`;\n\n/**\n * A map of CAIP-2 chain IDs to their native asset identifiers.\n * Uses CAIP-19-like format to identify the native asset for each chain.\n *\n * @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md\n */\nexport type NativeAssetIdentifiersMap = Record<\n CaipChainId,\n NativeAssetIdentifier\n>;\n\n// State shape for NetworkEnablementController\nexport type NetworkEnablementControllerState = {\n enabledNetworkMap: EnabledMap;\n nativeAssetIdentifiers: NativeAssetIdentifiersMap;\n};\n\nexport type NetworkEnablementControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NetworkEnablementControllerState\n >;\n\nexport type NetworkEnablementControllerSetEnabledNetworksAction = {\n type: `${typeof controllerName}:enableNetwork`;\n handler: NetworkEnablementController['enableNetwork'];\n};\n\nexport type NetworkEnablementControllerDisableNetworkAction = {\n type: `${typeof controllerName}:disableNetwork`;\n handler: NetworkEnablementController['disableNetwork'];\n};\n\nexport type NetworkEnablementControllerListPopularNetworksAction = {\n type: `${typeof controllerName}:listPopularNetworks`;\n handler: NetworkEnablementController['listPopularNetworks'];\n};\n\nexport type NetworkEnablementControllerListPopularEvmNetworksAction = {\n type: `${typeof controllerName}:listPopularEvmNetworks`;\n handler: NetworkEnablementController['listPopularEvmNetworks'];\n};\n\nexport type NetworkEnablementControllerListPopularMultichainNetworksAction = {\n type: `${typeof controllerName}:listPopularMultichainNetworks`;\n handler: NetworkEnablementController['listPopularMultichainNetworks'];\n};\n\n/**\n * All actions that {@link NetworkEnablementController} calls internally.\n */\nexport type AllowedActions =\n | NetworkControllerGetStateAction\n | MultichainNetworkControllerGetStateAction;\n\nexport type NetworkEnablementControllerActions =\n | NetworkEnablementControllerGetStateAction\n | NetworkEnablementControllerSetEnabledNetworksAction\n | NetworkEnablementControllerDisableNetworkAction\n | NetworkEnablementControllerListPopularNetworksAction\n | NetworkEnablementControllerListPopularEvmNetworksAction\n | NetworkEnablementControllerListPopularMultichainNetworksAction;\n\nexport type NetworkEnablementControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NetworkEnablementControllerState\n >;\n\nexport type NetworkEnablementControllerEvents =\n NetworkEnablementControllerStateChangeEvent;\n\n/**\n * All events that {@link NetworkEnablementController} subscribes to internally.\n */\nexport type AllowedEvents =\n | NetworkControllerNetworkAddedEvent\n | NetworkControllerNetworkRemovedEvent\n | NetworkControllerStateChangeEvent\n | TransactionControllerTransactionSubmittedEvent;\n\nexport type NetworkEnablementControllerMessenger = Messenger<\n typeof controllerName,\n NetworkEnablementControllerActions | AllowedActions,\n NetworkEnablementControllerEvents | AllowedEvents\n>;\n\n/**\n * Builds a native asset identifier in CAIP-19-like format.\n *\n * @param caipChainId - The CAIP-2 chain ID (e.g., 'eip155:1', 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')\n * @param slip44CoinType - The SLIP-44 coin type number\n * @returns The native asset identifier string (e.g., 'eip155:1/slip44:60')\n */\nfunction buildNativeAssetIdentifier(\n caipChainId: CaipChainId,\n slip44CoinType: number,\n): NativeAssetIdentifier {\n return `${caipChainId}/slip44:${slip44CoinType}`;\n}\n\n/**\n * Network configuration with chain ID and native currency symbol.\n * Used to initialize native asset identifiers.\n */\nexport type NetworkConfig = {\n chainId: CaipChainId;\n nativeCurrency: string;\n};\n\n/**\n * Gets the default state for the NetworkEnablementController.\n *\n * @returns The default state with pre-enabled networks.\n */\nconst getDefaultNetworkEnablementControllerState =\n (): NetworkEnablementControllerState => ({\n enabledNetworkMap: {\n [KnownCaipNamespace.Eip155]: {\n [ChainId[BuiltInNetworkName.Mainnet]]: true,\n [ChainId[BuiltInNetworkName.LineaMainnet]]: true,\n [ChainId[BuiltInNetworkName.BaseMainnet]]: true,\n [ChainId[BuiltInNetworkName.ArbitrumOne]]: true,\n [ChainId[BuiltInNetworkName.BscMainnet]]: true,\n [ChainId[BuiltInNetworkName.OptimismMainnet]]: true,\n [ChainId[BuiltInNetworkName.PolygonMainnet]]: true,\n [ChainId[BuiltInNetworkName.SeiMainnet]]: true,\n },\n [KnownCaipNamespace.Solana]: {\n [SolScope.Mainnet]: true,\n [SolScope.Testnet]: false,\n [SolScope.Devnet]: false,\n },\n [KnownCaipNamespace.Bip122]: {\n [BtcScope.Mainnet]: true,\n [BtcScope.Testnet]: false,\n [BtcScope.Signet]: false,\n },\n [KnownCaipNamespace.Tron]: {\n [TrxScope.Mainnet]: true,\n [TrxScope.Nile]: false,\n [TrxScope.Shasta]: false,\n },\n },\n // nativeAssetIdentifiers is initialized as empty and should be populated\n // by the client using initNativeAssetIdentifiers() during controller init\n nativeAssetIdentifiers: {},\n });\n\n// Metadata for the controller state\nconst metadata = {\n enabledNetworkMap: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n nativeAssetIdentifiers: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\n/**\n * Controller responsible for managing network enablement state across different blockchain networks.\n *\n * This controller tracks which networks are enabled/disabled for the user and provides methods\n * to toggle network states. It supports both EVM (EIP-155) and non-EVM networks like Solana.\n *\n * The controller maintains a map of enabled networks organized by namespace (e.g., 'eip155', 'solana')\n * and provides methods to query and modify network enablement states.\n */\nexport class NetworkEnablementController extends BaseController<\n typeof controllerName,\n NetworkEnablementControllerState,\n NetworkEnablementControllerMessenger\n> {\n /**\n * Creates a NetworkEnablementController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: NetworkEnablementControllerMessenger;\n state?: Partial<NetworkEnablementControllerState>;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: {\n ...getDefaultNetworkEnablementControllerState(),\n ...state,\n },\n });\n\n messenger.subscribe('NetworkController:networkAdded', ({ chainId }) => {\n // eslint-disable-next-line no-void\n void this.#onAddNetwork(chainId);\n });\n\n messenger.subscribe('NetworkController:networkRemoved', ({ chainId }) => {\n this.#removeNetworkEntry(chainId);\n });\n }\n\n /**\n * Enables or disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally. This dual parameter support allows for backward\n * compatibility with existing EVM chain ID formats while supporting newer\n * multi-chain standards.\n *\n * When enabling a non-popular network, this method will disable all other networks\n * to ensure only one network is active at a time (exclusive mode).\n *\n * @param chainId - The chain ID of the network to enable or disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\n enableNetwork(chainId: Hex | CaipChainId): void {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n this.update((state) => {\n // disable all networks in all namespaces first\n Object.keys(state.enabledNetworkMap).forEach((ns) => {\n Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {\n state.enabledNetworkMap[ns][key as CaipChainId | Hex] = false;\n });\n });\n\n // if the namespace bucket does not exist, return\n // new nemespace are added only when a new network is added\n if (!state.enabledNetworkMap[namespace]) {\n return;\n }\n\n // enable the network\n state.enabledNetworkMap[namespace][storageKey] = true;\n });\n }\n\n /**\n * Enables a network for the user within a specific namespace.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and enables it within the specified namespace.\n * The method validates that the chainId belongs to the specified namespace for safety.\n *\n * Before enabling the target network, this method disables all other networks\n * in the same namespace to ensure exclusive behavior within the namespace.\n *\n * @param chainId - The chain ID of the network to enable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @param namespace - The CAIP namespace where the network should be enabled\n * @throws Error if the chainId's derived namespace doesn't match the provided namespace\n */\n enableNetworkInNamespace(\n chainId: Hex | CaipChainId,\n namespace: CaipNamespace,\n ): void {\n const { namespace: derivedNamespace, storageKey } = deriveKeys(chainId);\n\n // Validate that the derived namespace matches the provided namespace\n if (derivedNamespace !== namespace) {\n throw new Error(\n `Chain ID ${chainId} belongs to namespace ${derivedNamespace}, but namespace ${namespace} was specified`,\n );\n }\n\n this.update((state) => {\n // Ensure the namespace bucket exists\n this.#ensureNamespaceBucket(state, namespace);\n\n // Disable all networks in the specified namespace first\n if (state.enabledNetworkMap[namespace]) {\n Object.keys(state.enabledNetworkMap[namespace]).forEach((key) => {\n state.enabledNetworkMap[namespace][key as CaipChainId | Hex] = false;\n });\n }\n\n // Enable the target network in the specified namespace\n state.enabledNetworkMap[namespace][storageKey] = true;\n });\n }\n\n /**\n * Enables all popular networks and Solana mainnet.\n *\n * This method first disables all networks across all namespaces, then enables\n * all networks defined in POPULAR_NETWORKS (EVM networks), Solana mainnet, and\n * Bitcoin mainnet. This provides exclusive behavior - only popular networks will\n * be enabled after calling this method.\n *\n * Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.\n */\n enableAllPopularNetworks(): void {\n this.update((state) => {\n // First disable all networks across all namespaces\n Object.keys(state.enabledNetworkMap).forEach((ns) => {\n Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {\n state.enabledNetworkMap[ns][key as CaipChainId | Hex] = false;\n });\n });\n\n // Get current network configurations to check if networks exist\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n const multichainState = this.messenger.call(\n 'MultichainNetworkController:getState',\n );\n\n // Enable all popular EVM networks that exist in NetworkController configurations\n POPULAR_NETWORKS.forEach((chainId) => {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n // Check if network exists in NetworkController configurations\n if (networkControllerState.networkConfigurationsByChainId[chainId]) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, namespace);\n // Enable the network\n state.enabledNetworkMap[namespace][storageKey] = true;\n }\n });\n\n // Enable Solana mainnet if it exists in MultichainNetworkController configurations\n const solanaKeys = deriveKeys(SolScope.Mainnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n SolScope.Mainnet\n ]\n ) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, solanaKeys.namespace);\n // Enable Solana mainnet\n state.enabledNetworkMap[solanaKeys.namespace][solanaKeys.storageKey] =\n true;\n }\n\n // Enable Bitcoin mainnet if it exists in MultichainNetworkController configurations\n const bitcoinKeys = deriveKeys(BtcScope.Mainnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n BtcScope.Mainnet\n ]\n ) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, bitcoinKeys.namespace);\n // Enable Bitcoin mainnet\n state.enabledNetworkMap[bitcoinKeys.namespace][bitcoinKeys.storageKey] =\n true;\n }\n\n // Enable Tron mainnet if it exists in MultichainNetworkController configurations\n const tronKeys = deriveKeys(TrxScope.Mainnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n TrxScope.Mainnet\n ]\n ) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, tronKeys.namespace);\n // Enable Tron mainnet\n state.enabledNetworkMap[tronKeys.namespace][tronKeys.storageKey] = true;\n }\n });\n }\n\n /**\n * Initializes the network enablement state from network controller configurations.\n *\n * This method reads the current network configurations from both NetworkController\n * and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.\n * It ensures proper namespace buckets exist for all configured networks and only\n * adds missing networks with a default value of false, preserving existing user settings.\n *\n * This method should be called after the NetworkController and MultichainNetworkController\n * have been initialized and their configurations are available.\n */\n async init(): Promise<void> {\n // Get network configurations from NetworkController (EVM networks)\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n\n // Get network configurations from MultichainNetworkController (all networks)\n const multichainState = this.messenger.call(\n 'MultichainNetworkController:getState',\n );\n\n // Build nativeAssetIdentifiers for EVM networks using chainid.network\n const evmNativeAssetUpdates: {\n caipChainId: CaipChainId;\n identifier: NativeAssetIdentifier;\n }[] = [];\n\n for (const [chainId] of Object.entries(\n networkControllerState.networkConfigurationsByChainId,\n )) {\n const { caipChainId } = deriveKeys(chainId as Hex);\n\n // Skip if already in state\n if (this.state.nativeAssetIdentifiers[caipChainId] !== undefined) {\n continue;\n }\n\n // Parse hex chainId to number for chainid.network lookup\n const numericChainId = parseInt(chainId, 16);\n\n // EVM networks: use getEvmSlip44 (chainid.network data)\n const slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);\n\n evmNativeAssetUpdates.push({\n caipChainId,\n identifier: buildNativeAssetIdentifier(caipChainId, slip44CoinType),\n });\n }\n\n // Update state synchronously\n this.update((state) => {\n // Initialize namespace buckets for EVM networks from NetworkController\n Object.entries(\n networkControllerState.networkConfigurationsByChainId,\n ).forEach(([chainId]) => {\n const { namespace, storageKey } = deriveKeys(chainId as Hex);\n this.#ensureNamespaceBucket(state, namespace);\n\n // Only add network if it doesn't already exist in state (preserves user settings)\n state.enabledNetworkMap[namespace][storageKey] ??= false;\n });\n\n // Apply nativeAssetIdentifier updates\n for (const { caipChainId, identifier } of evmNativeAssetUpdates) {\n state.nativeAssetIdentifiers[caipChainId] = identifier;\n }\n\n // Initialize namespace buckets for all networks from MultichainNetworkController\n Object.keys(\n multichainState.multichainNetworkConfigurationsByChainId,\n ).forEach((chainId) => {\n const { namespace, storageKey } = deriveKeys(chainId as CaipChainId);\n this.#ensureNamespaceBucket(state, namespace);\n\n // Only add network if it doesn't already exist in state (preserves user settings)\n state.enabledNetworkMap[namespace][storageKey] ??= false;\n });\n });\n }\n\n /**\n * Initializes the native asset identifiers from network configurations.\n * This method should be called from the client during controller initialization\n * to populate the nativeAssetIdentifiers state based on actual network configurations.\n *\n * @param networks - Array of network configurations with chainId and nativeCurrency\n * @example\n * ```typescript\n * const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)\n * .map(config => ({\n * chainId: toEvmCaipChainId(config.chainId),\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)\n * .map(config => ({\n * chainId: config.chainId,\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * await controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);\n * ```\n */\n async initNativeAssetIdentifiers(networks: NetworkConfig[]): Promise<void> {\n // Process networks and collect updates\n const updates: {\n chainId: CaipChainId;\n identifier: NativeAssetIdentifier;\n }[] = [];\n\n for (const { chainId, nativeCurrency } of networks) {\n // Check if nativeCurrency is already in CAIP-19 format (e.g., \"bip122:.../slip44:0\")\n // Non-EVM networks from MultichainNetworkController use this format\n if (nativeCurrency.includes('/slip44:')) {\n updates.push({\n chainId,\n identifier: nativeCurrency as NativeAssetIdentifier,\n });\n continue;\n }\n\n // Extract namespace from CAIP-2 chainId\n const [namespace, reference] = chainId.split(':');\n let slip44CoinType: number | undefined;\n\n if (namespace === 'eip155') {\n // EVM networks: use getEvmSlip44 (chainid.network data)\n const numericChainId = parseInt(reference, 10);\n slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);\n } else {\n // Non-EVM networks: use getSlip44BySymbol (@metamask/slip44 package)\n slip44CoinType = Slip44Service.getSlip44BySymbol(nativeCurrency);\n }\n\n if (slip44CoinType !== undefined) {\n updates.push({\n chainId,\n identifier: buildNativeAssetIdentifier(chainId, slip44CoinType),\n });\n }\n }\n\n // Apply all updates synchronously\n this.update((state) => {\n for (const { chainId, identifier } of updates) {\n state.nativeAssetIdentifiers[chainId] = identifier;\n }\n });\n }\n\n /**\n * Disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally.\n *\n * Note: This method will prevent disabling the last remaining enabled network\n * to ensure at least one network is always available.\n *\n * @param chainId - The chain ID of the network to disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\n disableNetwork(chainId: Hex | CaipChainId): void {\n const derivedKeys = deriveKeys(chainId);\n const { namespace, storageKey } = derivedKeys;\n\n this.update((state) => {\n state.enabledNetworkMap[namespace][storageKey] = false;\n });\n }\n\n /**\n * Checks if a network is enabled.\n *\n * @param chainId - The chain ID of the network to check. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @returns True if the network is enabled, false otherwise\n */\n isNetworkEnabled(chainId: Hex | CaipChainId): boolean {\n const derivedKeys = deriveKeys(chainId);\n const { namespace, storageKey } = derivedKeys;\n return this.state.enabledNetworkMap[namespace]?.[storageKey] ?? false;\n }\n\n /**\n * Ensures that a namespace bucket exists in the state.\n *\n * This method creates the namespace entry in the enabledNetworkMap if it doesn't\n * already exist. This is used to prepare the state structure before adding\n * network entries.\n *\n * @param state - The current controller state\n * @param ns - The CAIP namespace to ensure exists\n */\n #ensureNamespaceBucket(\n state: NetworkEnablementControllerState,\n ns: CaipNamespace,\n ): void {\n if (!state.enabledNetworkMap[ns]) {\n state.enabledNetworkMap[ns] = {};\n }\n }\n\n /**\n * Checks if popular networks mode is active (more than 2 popular networks enabled).\n *\n * This method counts how many networks defined in POPULAR_NETWORKS are currently\n * enabled in the state and returns true if more than 2 are enabled. It only checks\n * networks that actually exist in the NetworkController configurations.\n *\n * @returns True if more than 2 popular networks are enabled, false otherwise\n */\n #isInPopularNetworksMode(): boolean {\n // Get current network configurations to check which popular networks exist\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n\n // Count how many popular networks are enabled\n const enabledPopularNetworksCount = POPULAR_NETWORKS.reduce(\n (count, chainId) => {\n // Only check networks that actually exist in NetworkController configurations\n if (!networkControllerState.networkConfigurationsByChainId[chainId]) {\n return count; // Skip networks that don't exist\n }\n\n const { namespace, storageKey } = deriveKeys(chainId);\n const isEnabled = this.state.enabledNetworkMap[namespace]?.[storageKey];\n return isEnabled ? count + 1 : count;\n },\n 0,\n );\n\n // Return true if more than 2 popular networks are enabled\n return enabledPopularNetworksCount > 1;\n }\n\n /**\n * Removes a network entry from the state.\n *\n * This method is called when a network is removed from the system. It cleans up\n * the network entry from both enabledNetworkMap and nativeAssetIdentifiers, and ensures that\n * at least one network remains enabled.\n *\n * @param chainId - The chain ID to remove (Hex or CAIP-2 format)\n */\n #removeNetworkEntry(chainId: Hex | CaipChainId): void {\n const derivedKeys = deriveKeys(chainId);\n const { namespace, storageKey, caipChainId } = derivedKeys;\n\n this.update((state) => {\n // fallback and enable ethereum mainnet\n if (isOnlyNetworkEnabledInNamespace(this.state, derivedKeys)) {\n state.enabledNetworkMap[namespace][\n ChainId[BuiltInNetworkName.Mainnet]\n ] = true;\n }\n\n if (namespace in state.enabledNetworkMap) {\n delete state.enabledNetworkMap[namespace][storageKey];\n }\n\n // Remove from nativeAssetIdentifiers as well\n delete state.nativeAssetIdentifiers[caipChainId];\n });\n }\n\n /**\n * Handles the addition of a new EVM network to the controller.\n *\n * @param chainId - The chain ID to add (Hex format)\n *\n * @description\n * - If in popular networks mode (>2 popular networks enabled) AND adding a popular network:\n * - Keep current selection (add but don't enable the new network)\n * - Otherwise:\n * - Switch to the newly added network (disable all others, enable this one)\n * - Also updates the nativeAssetIdentifiers with the CAIP-19-like identifier\n */\n async #onAddNetwork(chainId: Hex): Promise<void> {\n const { namespace, storageKey, reference, caipChainId } =\n deriveKeys(chainId);\n\n // Parse reference (decimal string from CAIP-2) to number for chainid.network lookup\n const numericChainId = parseInt(reference, 10);\n\n // EVM networks: use getEvmSlip44 (chainid.network data)\n const slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);\n\n this.update((state) => {\n // Ensure the namespace bucket exists\n this.#ensureNamespaceBucket(state, namespace);\n\n // Check if popular networks mode is active (>2 popular networks enabled)\n const inPopularNetworksMode = this.#isInPopularNetworksMode();\n\n // Check if the network being added is a popular network\n const isAddedNetworkPopular = isPopularNetwork(reference);\n\n // Keep current selection only if in popular networks mode AND adding a popular network\n const shouldKeepCurrentSelection =\n inPopularNetworksMode && isAddedNetworkPopular;\n\n if (shouldKeepCurrentSelection) {\n // Add the popular network but don't enable it (keep current selection)\n state.enabledNetworkMap[namespace][storageKey] = true;\n } else {\n // Switch to the newly added network (disable all others, enable this one)\n Object.keys(state.enabledNetworkMap).forEach((ns) => {\n Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {\n state.enabledNetworkMap[ns][key as CaipChainId | Hex] = false;\n });\n });\n // Enable the newly added network\n state.enabledNetworkMap[namespace][storageKey] = true;\n }\n\n // Update nativeAssetIdentifiers with the CAIP-19-like identifier\n state.nativeAssetIdentifiers[caipChainId] = buildNativeAssetIdentifier(\n caipChainId,\n slip44CoinType,\n );\n });\n }\n\n /**\n * Returns popular EVM network chain IDs in hex form, restricted to networks\n * that exist in NetworkController (networkConfigurationsByChainId). Source list\n * is POPULAR_NETWORKS.\n *\n * @returns Hex chain IDs for popular EVM networks that are configured.\n */\n listPopularEvmNetworks(): Hex[] {\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n return POPULAR_NETWORKS.filter(\n (chainIdHex) =>\n networkControllerState.networkConfigurationsByChainId[chainIdHex],\n );\n }\n\n /**\n * Returns popular multichain (Bitcoin, Solana, Tron) mainnet chain IDs in\n * CAIP-2 form, restricted to networks that exist in MultichainNetworkController\n * (multichainNetworkConfigurationsByChainId).\n *\n * @returns CAIP-2 chain IDs for Bitcoin, Solana, and Tron mainnets that are configured.\n */\n listPopularMultichainNetworks(): CaipChainId[] {\n const multichainState = this.messenger.call(\n 'MultichainNetworkController:getState',\n );\n const multichainMainnets = [\n BtcScope.Mainnet,\n SolScope.Mainnet,\n TrxScope.Mainnet,\n ] as const;\n return multichainMainnets.filter(\n (chainId) =>\n multichainState.multichainNetworkConfigurationsByChainId[chainId],\n );\n }\n\n /**\n * Returns the list of popular network chain IDs in CAIP-2 form, restricted to\n * networks that exist in NetworkController (networkConfigurationsByChainId) and\n * MultichainNetworkController (multichainNetworkConfigurationsByChainId). EVM\n * popular networks come from POPULAR_NETWORKS; multichain popular are Bitcoin,\n * Solana, and Tron mainnets.\n *\n * @returns CAIP-2 chain IDs for popular EVM networks and multichain mainnets that are configured.\n */\n listPopularNetworks(): CaipChainId[] {\n const evmHex = this.listPopularEvmNetworks();\n const evmCaip = evmHex.map((chainIdHex) => toEvmCaipChainId(chainIdHex));\n return [...evmCaip, ...this.listPopularMultichainNetworks()];\n }\n}\n"]}
|
|
@@ -5,7 +5,6 @@ import type { MultichainNetworkControllerGetStateAction } from "@metamask/multic
|
|
|
5
5
|
import type { NetworkControllerGetStateAction, NetworkControllerNetworkAddedEvent, NetworkControllerNetworkRemovedEvent, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
|
|
6
6
|
import type { TransactionControllerTransactionSubmittedEvent } from "@metamask/transaction-controller";
|
|
7
7
|
import type { CaipChainId, CaipNamespace, Hex } from "@metamask/utils";
|
|
8
|
-
import type { NetworkEnablementControllerMethodActions } from "./NetworkEnablementController-method-action-types.cjs";
|
|
9
8
|
declare const controllerName = "NetworkEnablementController";
|
|
10
9
|
/**
|
|
11
10
|
* Information about an ordered network.
|
|
@@ -44,11 +43,31 @@ export type NetworkEnablementControllerState = {
|
|
|
44
43
|
nativeAssetIdentifiers: NativeAssetIdentifiersMap;
|
|
45
44
|
};
|
|
46
45
|
export type NetworkEnablementControllerGetStateAction = ControllerGetStateAction<typeof controllerName, NetworkEnablementControllerState>;
|
|
46
|
+
export type NetworkEnablementControllerSetEnabledNetworksAction = {
|
|
47
|
+
type: `${typeof controllerName}:enableNetwork`;
|
|
48
|
+
handler: NetworkEnablementController['enableNetwork'];
|
|
49
|
+
};
|
|
50
|
+
export type NetworkEnablementControllerDisableNetworkAction = {
|
|
51
|
+
type: `${typeof controllerName}:disableNetwork`;
|
|
52
|
+
handler: NetworkEnablementController['disableNetwork'];
|
|
53
|
+
};
|
|
54
|
+
export type NetworkEnablementControllerListPopularNetworksAction = {
|
|
55
|
+
type: `${typeof controllerName}:listPopularNetworks`;
|
|
56
|
+
handler: NetworkEnablementController['listPopularNetworks'];
|
|
57
|
+
};
|
|
58
|
+
export type NetworkEnablementControllerListPopularEvmNetworksAction = {
|
|
59
|
+
type: `${typeof controllerName}:listPopularEvmNetworks`;
|
|
60
|
+
handler: NetworkEnablementController['listPopularEvmNetworks'];
|
|
61
|
+
};
|
|
62
|
+
export type NetworkEnablementControllerListPopularMultichainNetworksAction = {
|
|
63
|
+
type: `${typeof controllerName}:listPopularMultichainNetworks`;
|
|
64
|
+
handler: NetworkEnablementController['listPopularMultichainNetworks'];
|
|
65
|
+
};
|
|
47
66
|
/**
|
|
48
67
|
* All actions that {@link NetworkEnablementController} calls internally.
|
|
49
68
|
*/
|
|
50
69
|
export type AllowedActions = NetworkControllerGetStateAction | MultichainNetworkControllerGetStateAction;
|
|
51
|
-
export type NetworkEnablementControllerActions = NetworkEnablementControllerGetStateAction |
|
|
70
|
+
export type NetworkEnablementControllerActions = NetworkEnablementControllerGetStateAction | NetworkEnablementControllerSetEnabledNetworksAction | NetworkEnablementControllerDisableNetworkAction | NetworkEnablementControllerListPopularNetworksAction | NetworkEnablementControllerListPopularEvmNetworksAction | NetworkEnablementControllerListPopularMultichainNetworksAction;
|
|
52
71
|
export type NetworkEnablementControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, NetworkEnablementControllerState>;
|
|
53
72
|
export type NetworkEnablementControllerEvents = NetworkEnablementControllerStateChangeEvent;
|
|
54
73
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkEnablementController.d.cts","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,yCAAyC,EAAE,gDAAgD;AAEzG,OAAO,KAAK,EACV,+BAA+B,EAC/B,kCAAkC,EAClC,oCAAoC,EACpC,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,KAAK,EAAE,8CAA8C,EAAE,yCAAyC;AACvG,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"NetworkEnablementController.d.cts","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,yCAAyC,EAAE,gDAAgD;AAEzG,OAAO,KAAK,EACV,+BAA+B,EAC/B,kCAAkC,EAClC,oCAAoC,EACpC,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,KAAK,EAAE,8CAA8C,EAAE,yCAAyC;AACvG,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAWvE,QAAA,MAAM,cAAc,gCAAgC,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,SAAS,EAAE,WAAW,CAAC;CACxB,CAAC;AAE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IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAsE3B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,0BAA0B,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA+C1E;;;;;;;;;;;;;OAaG;IACH,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,IAAI;IAShD;;;;;;;OAOG;IACH,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,OAAO;IAmJrD;;;;;;OAMG;IACH,sBAAsB,IAAI,GAAG,EAAE;IAU/B;;;;;;OAMG;IACH,6BAA6B,IAAI,WAAW,EAAE;IAe9C;;;;;;;;OAQG;IACH,mBAAmB,IAAI,WAAW,EAAE;CAKrC"}
|
|
@@ -5,7 +5,6 @@ import type { MultichainNetworkControllerGetStateAction } from "@metamask/multic
|
|
|
5
5
|
import type { NetworkControllerGetStateAction, NetworkControllerNetworkAddedEvent, NetworkControllerNetworkRemovedEvent, NetworkControllerStateChangeEvent } from "@metamask/network-controller";
|
|
6
6
|
import type { TransactionControllerTransactionSubmittedEvent } from "@metamask/transaction-controller";
|
|
7
7
|
import type { CaipChainId, CaipNamespace, Hex } from "@metamask/utils";
|
|
8
|
-
import type { NetworkEnablementControllerMethodActions } from "./NetworkEnablementController-method-action-types.mjs";
|
|
9
8
|
declare const controllerName = "NetworkEnablementController";
|
|
10
9
|
/**
|
|
11
10
|
* Information about an ordered network.
|
|
@@ -44,11 +43,31 @@ export type NetworkEnablementControllerState = {
|
|
|
44
43
|
nativeAssetIdentifiers: NativeAssetIdentifiersMap;
|
|
45
44
|
};
|
|
46
45
|
export type NetworkEnablementControllerGetStateAction = ControllerGetStateAction<typeof controllerName, NetworkEnablementControllerState>;
|
|
46
|
+
export type NetworkEnablementControllerSetEnabledNetworksAction = {
|
|
47
|
+
type: `${typeof controllerName}:enableNetwork`;
|
|
48
|
+
handler: NetworkEnablementController['enableNetwork'];
|
|
49
|
+
};
|
|
50
|
+
export type NetworkEnablementControllerDisableNetworkAction = {
|
|
51
|
+
type: `${typeof controllerName}:disableNetwork`;
|
|
52
|
+
handler: NetworkEnablementController['disableNetwork'];
|
|
53
|
+
};
|
|
54
|
+
export type NetworkEnablementControllerListPopularNetworksAction = {
|
|
55
|
+
type: `${typeof controllerName}:listPopularNetworks`;
|
|
56
|
+
handler: NetworkEnablementController['listPopularNetworks'];
|
|
57
|
+
};
|
|
58
|
+
export type NetworkEnablementControllerListPopularEvmNetworksAction = {
|
|
59
|
+
type: `${typeof controllerName}:listPopularEvmNetworks`;
|
|
60
|
+
handler: NetworkEnablementController['listPopularEvmNetworks'];
|
|
61
|
+
};
|
|
62
|
+
export type NetworkEnablementControllerListPopularMultichainNetworksAction = {
|
|
63
|
+
type: `${typeof controllerName}:listPopularMultichainNetworks`;
|
|
64
|
+
handler: NetworkEnablementController['listPopularMultichainNetworks'];
|
|
65
|
+
};
|
|
47
66
|
/**
|
|
48
67
|
* All actions that {@link NetworkEnablementController} calls internally.
|
|
49
68
|
*/
|
|
50
69
|
export type AllowedActions = NetworkControllerGetStateAction | MultichainNetworkControllerGetStateAction;
|
|
51
|
-
export type NetworkEnablementControllerActions = NetworkEnablementControllerGetStateAction |
|
|
70
|
+
export type NetworkEnablementControllerActions = NetworkEnablementControllerGetStateAction | NetworkEnablementControllerSetEnabledNetworksAction | NetworkEnablementControllerDisableNetworkAction | NetworkEnablementControllerListPopularNetworksAction | NetworkEnablementControllerListPopularEvmNetworksAction | NetworkEnablementControllerListPopularMultichainNetworksAction;
|
|
52
71
|
export type NetworkEnablementControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, NetworkEnablementControllerState>;
|
|
53
72
|
export type NetworkEnablementControllerEvents = NetworkEnablementControllerStateChangeEvent;
|
|
54
73
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkEnablementController.d.mts","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,yCAAyC,EAAE,gDAAgD;AAEzG,OAAO,KAAK,EACV,+BAA+B,EAC/B,kCAAkC,EAClC,oCAAoC,EACpC,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,KAAK,EAAE,8CAA8C,EAAE,yCAAyC;AACvG,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"NetworkEnablementController.d.mts","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AAGnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,yCAAyC,EAAE,gDAAgD;AAEzG,OAAO,KAAK,EACV,+BAA+B,EAC/B,kCAAkC,EAClC,oCAAoC,EACpC,iCAAiC,EAClC,qCAAqC;AACtC,OAAO,KAAK,EAAE,8CAA8C,EAAE,yCAAyC;AACvG,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAWvE,QAAA,MAAM,cAAc,gCAAgC,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,SAAS,EAAE,WAAW,CAAC;CACxB,CAAC;AAEF;;;;GAIG;AACH,KAAK,UAAU,GAAG,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,WAAW,GAAG,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAE5E;;;;;;;;GAQG;AACH,MAAM,MAAM,qBAAqB,GAAG,GAAG,WAAW,WAAW,MAAM,E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OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,IAAI;IAShD;;;;;;;OAOG;IACH,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,OAAO;IAmJrD;;;;;;OAMG;IACH,sBAAsB,IAAI,GAAG,EAAE;IAU/B;;;;;;OAMG;IACH,6BAA6B,IAAI,WAAW,EAAE;IAe9C;;;;;;;;OAQG;IACH,mBAAmB,IAAI,WAAW,EAAE;CAKrC"}
|
|
@@ -13,18 +13,6 @@ import { POPULAR_NETWORKS } from "./constants.mjs";
|
|
|
13
13
|
import { Slip44Service } from "./services/index.mjs";
|
|
14
14
|
import { deriveKeys, isOnlyNetworkEnabledInNamespace, isPopularNetwork } from "./utils.mjs";
|
|
15
15
|
const controllerName = 'NetworkEnablementController';
|
|
16
|
-
const MESSENGER_EXPOSED_METHODS = [
|
|
17
|
-
'init',
|
|
18
|
-
'initNativeAssetIdentifiers',
|
|
19
|
-
'enableNetwork',
|
|
20
|
-
'disableNetwork',
|
|
21
|
-
'enableNetworkInNamespace',
|
|
22
|
-
'enableAllPopularNetworks',
|
|
23
|
-
'isNetworkEnabled',
|
|
24
|
-
'listPopularNetworks',
|
|
25
|
-
'listPopularEvmNetworks',
|
|
26
|
-
'listPopularMultichainNetworks',
|
|
27
|
-
];
|
|
28
16
|
/**
|
|
29
17
|
* Builds a native asset identifier in CAIP-19-like format.
|
|
30
18
|
*
|
|
@@ -115,7 +103,6 @@ export class NetworkEnablementController extends BaseController {
|
|
|
115
103
|
},
|
|
116
104
|
});
|
|
117
105
|
_NetworkEnablementController_instances.add(this);
|
|
118
|
-
messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
119
106
|
messenger.subscribe('NetworkController:networkAdded', ({ chainId }) => {
|
|
120
107
|
// eslint-disable-next-line no-void
|
|
121
108
|
void __classPrivateFieldGet(this, _NetworkEnablementController_instances, "m", _NetworkEnablementController_onAddNetwork).call(this, chainId);
|
|
@@ -1 +1 @@
|
|
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CAAC,CAAC;YACH,iCAAiC;YACjC,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;QACxD,CAAC;QAED,iEAAiE;QACjE,KAAK,CAAC,sBAAsB,CAAC,WAAW,CAAC,GAAG,0BAA0B,CACpE,WAAW,EACX,cAAc,CACf,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BuiltInNetworkName, ChainId } from '@metamask/controller-utils';\nimport { BtcScope, SolScope, TrxScope } from '@metamask/keyring-api';\nimport type { Messenger } from '@metamask/messenger';\nimport type { MultichainNetworkControllerGetStateAction } from '@metamask/multichain-network-controller';\nimport { toEvmCaipChainId } from '@metamask/multichain-network-controller';\nimport type {\n NetworkControllerGetStateAction,\n NetworkControllerNetworkAddedEvent,\n NetworkControllerNetworkRemovedEvent,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport type { TransactionControllerTransactionSubmittedEvent } from '@metamask/transaction-controller';\nimport type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';\nimport { KnownCaipNamespace } from '@metamask/utils';\n\nimport { POPULAR_NETWORKS } from './constants';\nimport type { NetworkEnablementControllerMethodActions } from './NetworkEnablementController-method-action-types';\nimport { Slip44Service } from './services';\nimport {\n deriveKeys,\n isOnlyNetworkEnabledInNamespace,\n isPopularNetwork,\n} from './utils';\n\nconst controllerName = 'NetworkEnablementController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'init',\n 'initNativeAssetIdentifiers',\n 'enableNetwork',\n 'disableNetwork',\n 'enableNetworkInNamespace',\n 'enableAllPopularNetworks',\n 'isNetworkEnabled',\n 'listPopularNetworks',\n 'listPopularEvmNetworks',\n 'listPopularMultichainNetworks',\n] as const;\n\n/**\n * Information about an ordered network.\n */\nexport type NetworksInfo = {\n /**\n * The network's chain id\n */\n networkId: CaipChainId;\n};\n\n/**\n * A map of enabled networks by CAIP namespace and chain ID.\n * For EIP-155 networks, the keys are Hex chain IDs.\n * For other networks, the keys are CAIP chain IDs.\n */\ntype EnabledMap = Record<CaipNamespace, Record<CaipChainId | Hex, boolean>>;\n\n/**\n * A native asset identifier in CAIP-19-like format.\n * Format: `{caip2ChainId}/slip44:{coinType}`\n *\n * @example\n * - `eip155:1/slip44:60` for Ethereum mainnet (ETH)\n * - `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501` for Solana mainnet (SOL)\n * - `bip122:000000000019d6689c085ae165831e93/slip44:0` for Bitcoin mainnet (BTC)\n */\nexport type NativeAssetIdentifier = `${CaipChainId}/slip44:${number}`;\n\n/**\n * A map of CAIP-2 chain IDs to their native asset identifiers.\n * Uses CAIP-19-like format to identify the native asset for each chain.\n *\n * @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md\n */\nexport type NativeAssetIdentifiersMap = Record<\n CaipChainId,\n NativeAssetIdentifier\n>;\n\n// State shape for NetworkEnablementController\nexport type NetworkEnablementControllerState = {\n enabledNetworkMap: EnabledMap;\n nativeAssetIdentifiers: NativeAssetIdentifiersMap;\n};\n\nexport type NetworkEnablementControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NetworkEnablementControllerState\n >;\n/**\n * All actions that {@link NetworkEnablementController} calls internally.\n */\nexport type AllowedActions =\n | NetworkControllerGetStateAction\n | MultichainNetworkControllerGetStateAction;\n\nexport type NetworkEnablementControllerActions =\n | NetworkEnablementControllerGetStateAction\n | NetworkEnablementControllerMethodActions;\n\nexport type NetworkEnablementControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NetworkEnablementControllerState\n >;\n\nexport type NetworkEnablementControllerEvents =\n NetworkEnablementControllerStateChangeEvent;\n\n/**\n * All events that {@link NetworkEnablementController} subscribes to internally.\n */\nexport type AllowedEvents =\n | NetworkControllerNetworkAddedEvent\n | NetworkControllerNetworkRemovedEvent\n | NetworkControllerStateChangeEvent\n | TransactionControllerTransactionSubmittedEvent;\n\nexport type NetworkEnablementControllerMessenger = Messenger<\n typeof controllerName,\n NetworkEnablementControllerActions | AllowedActions,\n NetworkEnablementControllerEvents | AllowedEvents\n>;\n\n/**\n * Builds a native asset identifier in CAIP-19-like format.\n *\n * @param caipChainId - The CAIP-2 chain ID (e.g., 'eip155:1', 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')\n * @param slip44CoinType - The SLIP-44 coin type number\n * @returns The native asset identifier string (e.g., 'eip155:1/slip44:60')\n */\nfunction buildNativeAssetIdentifier(\n caipChainId: CaipChainId,\n slip44CoinType: number,\n): NativeAssetIdentifier {\n return `${caipChainId}/slip44:${slip44CoinType}`;\n}\n\n/**\n * Network configuration with chain ID and native currency symbol.\n * Used to initialize native asset identifiers.\n */\nexport type NetworkConfig = {\n chainId: CaipChainId;\n nativeCurrency: string;\n};\n\n/**\n * Gets the default state for the NetworkEnablementController.\n *\n * @returns The default state with pre-enabled networks.\n */\nconst getDefaultNetworkEnablementControllerState =\n (): NetworkEnablementControllerState => ({\n enabledNetworkMap: {\n [KnownCaipNamespace.Eip155]: {\n [ChainId[BuiltInNetworkName.Mainnet]]: true,\n [ChainId[BuiltInNetworkName.LineaMainnet]]: true,\n [ChainId[BuiltInNetworkName.BaseMainnet]]: true,\n [ChainId[BuiltInNetworkName.ArbitrumOne]]: true,\n [ChainId[BuiltInNetworkName.BscMainnet]]: true,\n [ChainId[BuiltInNetworkName.OptimismMainnet]]: true,\n [ChainId[BuiltInNetworkName.PolygonMainnet]]: true,\n [ChainId[BuiltInNetworkName.SeiMainnet]]: true,\n },\n [KnownCaipNamespace.Solana]: {\n [SolScope.Mainnet]: true,\n [SolScope.Testnet]: false,\n [SolScope.Devnet]: false,\n },\n [KnownCaipNamespace.Bip122]: {\n [BtcScope.Mainnet]: true,\n [BtcScope.Testnet]: false,\n [BtcScope.Signet]: false,\n },\n [KnownCaipNamespace.Tron]: {\n [TrxScope.Mainnet]: true,\n [TrxScope.Nile]: false,\n [TrxScope.Shasta]: false,\n },\n },\n // nativeAssetIdentifiers is initialized as empty and should be populated\n // by the client using initNativeAssetIdentifiers() during controller init\n nativeAssetIdentifiers: {},\n });\n\n// Metadata for the controller state\nconst metadata = {\n enabledNetworkMap: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n nativeAssetIdentifiers: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\n/**\n * Controller responsible for managing network enablement state across different blockchain networks.\n *\n * This controller tracks which networks are enabled/disabled for the user and provides methods\n * to toggle network states. It supports both EVM (EIP-155) and non-EVM networks like Solana.\n *\n * The controller maintains a map of enabled networks organized by namespace (e.g., 'eip155', 'solana')\n * and provides methods to query and modify network enablement states.\n */\nexport class NetworkEnablementController extends BaseController<\n typeof controllerName,\n NetworkEnablementControllerState,\n NetworkEnablementControllerMessenger\n> {\n /**\n * Creates a NetworkEnablementController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: NetworkEnablementControllerMessenger;\n state?: Partial<NetworkEnablementControllerState>;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: {\n ...getDefaultNetworkEnablementControllerState(),\n ...state,\n },\n });\n\n messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);\n\n messenger.subscribe('NetworkController:networkAdded', ({ chainId }) => {\n // eslint-disable-next-line no-void\n void this.#onAddNetwork(chainId);\n });\n\n messenger.subscribe('NetworkController:networkRemoved', ({ chainId }) => {\n this.#removeNetworkEntry(chainId);\n });\n }\n\n /**\n * Enables or disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally. This dual parameter support allows for backward\n * compatibility with existing EVM chain ID formats while supporting newer\n * multi-chain standards.\n *\n * When enabling a non-popular network, this method will disable all other networks\n * to ensure only one network is active at a time (exclusive mode).\n *\n * @param chainId - The chain ID of the network to enable or disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\n enableNetwork(chainId: Hex | CaipChainId): void {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n this.update((state) => {\n // disable all networks in all namespaces first\n Object.keys(state.enabledNetworkMap).forEach((ns) => {\n Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {\n state.enabledNetworkMap[ns][key as CaipChainId | Hex] = false;\n });\n });\n\n // if the namespace bucket does not exist, return\n // new nemespace are added only when a new network is added\n if (!state.enabledNetworkMap[namespace]) {\n return;\n }\n\n // enable the network\n state.enabledNetworkMap[namespace][storageKey] = true;\n });\n }\n\n /**\n * Enables a network for the user within a specific namespace.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and enables it within the specified namespace.\n * The method validates that the chainId belongs to the specified namespace for safety.\n *\n * Before enabling the target network, this method disables all other networks\n * in the same namespace to ensure exclusive behavior within the namespace.\n *\n * @param chainId - The chain ID of the network to enable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @param namespace - The CAIP namespace where the network should be enabled\n * @throws Error if the chainId's derived namespace doesn't match the provided namespace\n */\n enableNetworkInNamespace(\n chainId: Hex | CaipChainId,\n namespace: CaipNamespace,\n ): void {\n const { namespace: derivedNamespace, storageKey } = deriveKeys(chainId);\n\n // Validate that the derived namespace matches the provided namespace\n if (derivedNamespace !== namespace) {\n throw new Error(\n `Chain ID ${chainId} belongs to namespace ${derivedNamespace}, but namespace ${namespace} was specified`,\n );\n }\n\n this.update((state) => {\n // Ensure the namespace bucket exists\n this.#ensureNamespaceBucket(state, namespace);\n\n // Disable all networks in the specified namespace first\n if (state.enabledNetworkMap[namespace]) {\n Object.keys(state.enabledNetworkMap[namespace]).forEach((key) => {\n state.enabledNetworkMap[namespace][key as CaipChainId | Hex] = false;\n });\n }\n\n // Enable the target network in the specified namespace\n state.enabledNetworkMap[namespace][storageKey] = true;\n });\n }\n\n /**\n * Enables all popular networks and Solana mainnet.\n *\n * This method first disables all networks across all namespaces, then enables\n * all networks defined in POPULAR_NETWORKS (EVM networks), Solana mainnet, and\n * Bitcoin mainnet. This provides exclusive behavior - only popular networks will\n * be enabled after calling this method.\n *\n * Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.\n */\n enableAllPopularNetworks(): void {\n this.update((state) => {\n // First disable all networks across all namespaces\n Object.keys(state.enabledNetworkMap).forEach((ns) => {\n Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {\n state.enabledNetworkMap[ns][key as CaipChainId | Hex] = false;\n });\n });\n\n // Get current network configurations to check if networks exist\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n const multichainState = this.messenger.call(\n 'MultichainNetworkController:getState',\n );\n\n // Enable all popular EVM networks that exist in NetworkController configurations\n POPULAR_NETWORKS.forEach((chainId) => {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n // Check if network exists in NetworkController configurations\n if (networkControllerState.networkConfigurationsByChainId[chainId]) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, namespace);\n // Enable the network\n state.enabledNetworkMap[namespace][storageKey] = true;\n }\n });\n\n // Enable Solana mainnet if it exists in MultichainNetworkController configurations\n const solanaKeys = deriveKeys(SolScope.Mainnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n SolScope.Mainnet\n ]\n ) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, solanaKeys.namespace);\n // Enable Solana mainnet\n state.enabledNetworkMap[solanaKeys.namespace][solanaKeys.storageKey] =\n true;\n }\n\n // Enable Bitcoin mainnet if it exists in MultichainNetworkController configurations\n const bitcoinKeys = deriveKeys(BtcScope.Mainnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n BtcScope.Mainnet\n ]\n ) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, bitcoinKeys.namespace);\n // Enable Bitcoin mainnet\n state.enabledNetworkMap[bitcoinKeys.namespace][bitcoinKeys.storageKey] =\n true;\n }\n\n // Enable Tron mainnet if it exists in MultichainNetworkController configurations\n const tronKeys = deriveKeys(TrxScope.Mainnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n TrxScope.Mainnet\n ]\n ) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, tronKeys.namespace);\n // Enable Tron mainnet\n state.enabledNetworkMap[tronKeys.namespace][tronKeys.storageKey] = true;\n }\n });\n }\n\n /**\n * Initializes the network enablement state from network controller configurations.\n *\n * This method reads the current network configurations from both NetworkController\n * and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.\n * It ensures proper namespace buckets exist for all configured networks and only\n * adds missing networks with a default value of false, preserving existing user settings.\n *\n * This method should be called after the NetworkController and MultichainNetworkController\n * have been initialized and their configurations are available.\n */\n async init(): Promise<void> {\n // Get network configurations from NetworkController (EVM networks)\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n\n // Get network configurations from MultichainNetworkController (all networks)\n const multichainState = this.messenger.call(\n 'MultichainNetworkController:getState',\n );\n\n // Build nativeAssetIdentifiers for EVM networks using chainid.network\n const evmNativeAssetUpdates: {\n caipChainId: CaipChainId;\n identifier: NativeAssetIdentifier;\n }[] = [];\n\n for (const [chainId] of Object.entries(\n networkControllerState.networkConfigurationsByChainId,\n )) {\n const { caipChainId } = deriveKeys(chainId as Hex);\n\n // Skip if already in state\n if (this.state.nativeAssetIdentifiers[caipChainId] !== undefined) {\n continue;\n }\n\n // Parse hex chainId to number for chainid.network lookup\n const numericChainId = parseInt(chainId, 16);\n\n // EVM networks: use getEvmSlip44 (chainid.network data)\n const slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);\n\n evmNativeAssetUpdates.push({\n caipChainId,\n identifier: buildNativeAssetIdentifier(caipChainId, slip44CoinType),\n });\n }\n\n // Update state synchronously\n this.update((state) => {\n // Initialize namespace buckets for EVM networks from NetworkController\n Object.entries(\n networkControllerState.networkConfigurationsByChainId,\n ).forEach(([chainId]) => {\n const { namespace, storageKey } = deriveKeys(chainId as Hex);\n this.#ensureNamespaceBucket(state, namespace);\n\n // Only add network if it doesn't already exist in state (preserves user settings)\n state.enabledNetworkMap[namespace][storageKey] ??= false;\n });\n\n // Apply nativeAssetIdentifier updates\n for (const { caipChainId, identifier } of evmNativeAssetUpdates) {\n state.nativeAssetIdentifiers[caipChainId] = identifier;\n }\n\n // Initialize namespace buckets for all networks from MultichainNetworkController\n Object.keys(\n multichainState.multichainNetworkConfigurationsByChainId,\n ).forEach((chainId) => {\n const { namespace, storageKey } = deriveKeys(chainId as CaipChainId);\n this.#ensureNamespaceBucket(state, namespace);\n\n // Only add network if it doesn't already exist in state (preserves user settings)\n state.enabledNetworkMap[namespace][storageKey] ??= false;\n });\n });\n }\n\n /**\n * Initializes the native asset identifiers from network configurations.\n * This method should be called from the client during controller initialization\n * to populate the nativeAssetIdentifiers state based on actual network configurations.\n *\n * @param networks - Array of network configurations with chainId and nativeCurrency\n * @example\n * ```typescript\n * const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)\n * .map(config => ({\n * chainId: toEvmCaipChainId(config.chainId),\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)\n * .map(config => ({\n * chainId: config.chainId,\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * await controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);\n * ```\n */\n async initNativeAssetIdentifiers(networks: NetworkConfig[]): Promise<void> {\n // Process networks and collect updates\n const updates: {\n chainId: CaipChainId;\n identifier: NativeAssetIdentifier;\n }[] = [];\n\n for (const { chainId, nativeCurrency } of networks) {\n // Check if nativeCurrency is already in CAIP-19 format (e.g., \"bip122:.../slip44:0\")\n // Non-EVM networks from MultichainNetworkController use this format\n if (nativeCurrency.includes('/slip44:')) {\n updates.push({\n chainId,\n identifier: nativeCurrency as NativeAssetIdentifier,\n });\n continue;\n }\n\n // Extract namespace from CAIP-2 chainId\n const [namespace, reference] = chainId.split(':');\n let slip44CoinType: number | undefined;\n\n if (namespace === 'eip155') {\n // EVM networks: use getEvmSlip44 (chainid.network data)\n const numericChainId = parseInt(reference, 10);\n slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);\n } else {\n // Non-EVM networks: use getSlip44BySymbol (@metamask/slip44 package)\n slip44CoinType = Slip44Service.getSlip44BySymbol(nativeCurrency);\n }\n\n if (slip44CoinType !== undefined) {\n updates.push({\n chainId,\n identifier: buildNativeAssetIdentifier(chainId, slip44CoinType),\n });\n }\n }\n\n // Apply all updates synchronously\n this.update((state) => {\n for (const { chainId, identifier } of updates) {\n state.nativeAssetIdentifiers[chainId] = identifier;\n }\n });\n }\n\n /**\n * Disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally.\n *\n * Note: This method will prevent disabling the last remaining enabled network\n * to ensure at least one network is always available.\n *\n * @param chainId - The chain ID of the network to disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\n disableNetwork(chainId: Hex | CaipChainId): void {\n const derivedKeys = deriveKeys(chainId);\n const { namespace, storageKey } = derivedKeys;\n\n this.update((state) => {\n state.enabledNetworkMap[namespace][storageKey] = false;\n });\n }\n\n /**\n * Checks if a network is enabled.\n *\n * @param chainId - The chain ID of the network to check. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @returns True if the network is enabled, false otherwise\n */\n isNetworkEnabled(chainId: Hex | CaipChainId): boolean {\n const derivedKeys = deriveKeys(chainId);\n const { namespace, storageKey } = derivedKeys;\n return this.state.enabledNetworkMap[namespace]?.[storageKey] ?? false;\n }\n\n /**\n * Ensures that a namespace bucket exists in the state.\n *\n * This method creates the namespace entry in the enabledNetworkMap if it doesn't\n * already exist. This is used to prepare the state structure before adding\n * network entries.\n *\n * @param state - The current controller state\n * @param ns - The CAIP namespace to ensure exists\n */\n #ensureNamespaceBucket(\n state: NetworkEnablementControllerState,\n ns: CaipNamespace,\n ): void {\n if (!state.enabledNetworkMap[ns]) {\n state.enabledNetworkMap[ns] = {};\n }\n }\n\n /**\n * Checks if popular networks mode is active (more than 2 popular networks enabled).\n *\n * This method counts how many networks defined in POPULAR_NETWORKS are currently\n * enabled in the state and returns true if more than 2 are enabled. It only checks\n * networks that actually exist in the NetworkController configurations.\n *\n * @returns True if more than 2 popular networks are enabled, false otherwise\n */\n #isInPopularNetworksMode(): boolean {\n // Get current network configurations to check which popular networks exist\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n\n // Count how many popular networks are enabled\n const enabledPopularNetworksCount = POPULAR_NETWORKS.reduce(\n (count, chainId) => {\n // Only check networks that actually exist in NetworkController configurations\n if (!networkControllerState.networkConfigurationsByChainId[chainId]) {\n return count; // Skip networks that don't exist\n }\n\n const { namespace, storageKey } = deriveKeys(chainId);\n const isEnabled = this.state.enabledNetworkMap[namespace]?.[storageKey];\n return isEnabled ? count + 1 : count;\n },\n 0,\n );\n\n // Return true if more than 2 popular networks are enabled\n return enabledPopularNetworksCount > 1;\n }\n\n /**\n * Removes a network entry from the state.\n *\n * This method is called when a network is removed from the system. It cleans up\n * the network entry from both enabledNetworkMap and nativeAssetIdentifiers, and ensures that\n * at least one network remains enabled.\n *\n * @param chainId - The chain ID to remove (Hex or CAIP-2 format)\n */\n #removeNetworkEntry(chainId: Hex | CaipChainId): void {\n const derivedKeys = deriveKeys(chainId);\n const { namespace, storageKey, caipChainId } = derivedKeys;\n\n this.update((state) => {\n // fallback and enable ethereum mainnet\n if (isOnlyNetworkEnabledInNamespace(this.state, derivedKeys)) {\n state.enabledNetworkMap[namespace][\n ChainId[BuiltInNetworkName.Mainnet]\n ] = true;\n }\n\n if (namespace in state.enabledNetworkMap) {\n delete state.enabledNetworkMap[namespace][storageKey];\n }\n\n // Remove from nativeAssetIdentifiers as well\n delete state.nativeAssetIdentifiers[caipChainId];\n });\n }\n\n /**\n * Handles the addition of a new EVM network to the controller.\n *\n * @param chainId - The chain ID to add (Hex format)\n *\n * @description\n * - If in popular networks mode (>2 popular networks enabled) AND adding a popular network:\n * - Keep current selection (add but don't enable the new network)\n * - Otherwise:\n * - Switch to the newly added network (disable all others, enable this one)\n * - Also updates the nativeAssetIdentifiers with the CAIP-19-like identifier\n */\n async #onAddNetwork(chainId: Hex): Promise<void> {\n const { namespace, storageKey, reference, caipChainId } =\n deriveKeys(chainId);\n\n // Parse reference (decimal string from CAIP-2) to number for chainid.network lookup\n const numericChainId = parseInt(reference, 10);\n\n // EVM networks: use getEvmSlip44 (chainid.network data)\n const slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);\n\n this.update((state) => {\n // Ensure the namespace bucket exists\n this.#ensureNamespaceBucket(state, namespace);\n\n // Check if popular networks mode is active (>2 popular networks enabled)\n const inPopularNetworksMode = this.#isInPopularNetworksMode();\n\n // Check if the network being added is a popular network\n const isAddedNetworkPopular = isPopularNetwork(reference);\n\n // Keep current selection only if in popular networks mode AND adding a popular network\n const shouldKeepCurrentSelection =\n inPopularNetworksMode && isAddedNetworkPopular;\n\n if (shouldKeepCurrentSelection) {\n // Add the popular network but don't enable it (keep current selection)\n state.enabledNetworkMap[namespace][storageKey] = true;\n } else {\n // Switch to the newly added network (disable all others, enable this one)\n Object.keys(state.enabledNetworkMap).forEach((ns) => {\n Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {\n state.enabledNetworkMap[ns][key as CaipChainId | Hex] = false;\n });\n });\n // Enable the newly added network\n state.enabledNetworkMap[namespace][storageKey] = true;\n }\n\n // Update nativeAssetIdentifiers with the CAIP-19-like identifier\n state.nativeAssetIdentifiers[caipChainId] = buildNativeAssetIdentifier(\n caipChainId,\n slip44CoinType,\n );\n });\n }\n\n /**\n * Returns popular EVM network chain IDs in hex form, restricted to networks\n * that exist in NetworkController (networkConfigurationsByChainId). Source list\n * is POPULAR_NETWORKS.\n *\n * @returns Hex chain IDs for popular EVM networks that are configured.\n */\n listPopularEvmNetworks(): Hex[] {\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n return POPULAR_NETWORKS.filter(\n (chainIdHex) =>\n networkControllerState.networkConfigurationsByChainId[chainIdHex],\n );\n }\n\n /**\n * Returns popular multichain (Bitcoin, Solana, Tron) mainnet chain IDs in\n * CAIP-2 form, restricted to networks that exist in MultichainNetworkController\n * (multichainNetworkConfigurationsByChainId).\n *\n * @returns CAIP-2 chain IDs for Bitcoin, Solana, and Tron mainnets that are configured.\n */\n listPopularMultichainNetworks(): CaipChainId[] {\n const multichainState = this.messenger.call(\n 'MultichainNetworkController:getState',\n );\n const multichainMainnets = [\n BtcScope.Mainnet,\n SolScope.Mainnet,\n TrxScope.Mainnet,\n ] as const;\n return multichainMainnets.filter(\n (chainId) =>\n multichainState.multichainNetworkConfigurationsByChainId[chainId],\n );\n }\n\n /**\n * Returns the list of popular network chain IDs in CAIP-2 form, restricted to\n * networks that exist in NetworkController (networkConfigurationsByChainId) and\n * MultichainNetworkController (multichainNetworkConfigurationsByChainId). EVM\n * popular networks come from POPULAR_NETWORKS; multichain popular are Bitcoin,\n * Solana, and Tron mainnets.\n *\n * @returns CAIP-2 chain IDs for popular EVM networks and multichain mainnets that are configured.\n */\n listPopularNetworks(): CaipChainId[] {\n const evmHex = this.listPopularEvmNetworks();\n const evmCaip = evmHex.map((chainIdHex) => toEvmCaipChainId(chainIdHex));\n return [...evmCaip, ...this.listPopularMultichainNetworks()];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NetworkEnablementController.mjs","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAK3D,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,mCAAmC;AACzE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,8BAA8B;AAGrE,OAAO,EAAE,gBAAgB,EAAE,gDAAgD;AAS3E,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,gBAAgB,EAAE,wBAAoB;AAC/C,OAAO,EAAE,aAAa,EAAE,6BAAmB;AAC3C,OAAO,EACL,UAAU,EACV,+BAA+B,EAC/B,gBAAgB,EACjB,oBAAgB;AAEjB,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAqHrD;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,WAAwB,EACxB,cAAsB;IAEtB,OAAO,GAAG,WAAW,WAAW,cAAc,EAAE,CAAC;AACnD,CAAC;AAWD;;;;GAIG;AACH,MAAM,0CAA0C,GAC9C,GAAqC,EAAE,CAAC,CAAC;IACvC,iBAAiB,EAAE;QACjB,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE;YAC3B,CAAC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI;YAC3C,CAAC,OAAO,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI;YAChD,CAAC,OAAO,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC,EAAE,IAAI;YAC/C,CAAC,OAAO,CAAC,kBAAkB,CAAC,WAAW,CAAC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AC,SAAS,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;QACxD,CAAC;QAED,iEAAiE;QACjE,KAAK,CAAC,sBAAsB,CAAC,WAAW,CAAC,GAAG,0BAA0B,CACpE,WAAW,EACX,cAAc,CACf,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BuiltInNetworkName, ChainId } from '@metamask/controller-utils';\nimport { BtcScope, SolScope, TrxScope } from '@metamask/keyring-api';\nimport type { Messenger } from '@metamask/messenger';\nimport type { MultichainNetworkControllerGetStateAction } from '@metamask/multichain-network-controller';\nimport { toEvmCaipChainId } from '@metamask/multichain-network-controller';\nimport type {\n NetworkControllerGetStateAction,\n NetworkControllerNetworkAddedEvent,\n NetworkControllerNetworkRemovedEvent,\n NetworkControllerStateChangeEvent,\n} from '@metamask/network-controller';\nimport type { TransactionControllerTransactionSubmittedEvent } from '@metamask/transaction-controller';\nimport type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';\nimport { KnownCaipNamespace } from '@metamask/utils';\n\nimport { POPULAR_NETWORKS } from './constants';\nimport { Slip44Service } from './services';\nimport {\n deriveKeys,\n isOnlyNetworkEnabledInNamespace,\n isPopularNetwork,\n} from './utils';\n\nconst controllerName = 'NetworkEnablementController';\n\n/**\n * Information about an ordered network.\n */\nexport type NetworksInfo = {\n /**\n * The network's chain id\n */\n networkId: CaipChainId;\n};\n\n/**\n * A map of enabled networks by CAIP namespace and chain ID.\n * For EIP-155 networks, the keys are Hex chain IDs.\n * For other networks, the keys are CAIP chain IDs.\n */\ntype EnabledMap = Record<CaipNamespace, Record<CaipChainId | Hex, boolean>>;\n\n/**\n * A native asset identifier in CAIP-19-like format.\n * Format: `{caip2ChainId}/slip44:{coinType}`\n *\n * @example\n * - `eip155:1/slip44:60` for Ethereum mainnet (ETH)\n * - `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501` for Solana mainnet (SOL)\n * - `bip122:000000000019d6689c085ae165831e93/slip44:0` for Bitcoin mainnet (BTC)\n */\nexport type NativeAssetIdentifier = `${CaipChainId}/slip44:${number}`;\n\n/**\n * A map of CAIP-2 chain IDs to their native asset identifiers.\n * Uses CAIP-19-like format to identify the native asset for each chain.\n *\n * @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md\n */\nexport type NativeAssetIdentifiersMap = Record<\n CaipChainId,\n NativeAssetIdentifier\n>;\n\n// State shape for NetworkEnablementController\nexport type NetworkEnablementControllerState = {\n enabledNetworkMap: EnabledMap;\n nativeAssetIdentifiers: NativeAssetIdentifiersMap;\n};\n\nexport type NetworkEnablementControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NetworkEnablementControllerState\n >;\n\nexport type NetworkEnablementControllerSetEnabledNetworksAction = {\n type: `${typeof controllerName}:enableNetwork`;\n handler: NetworkEnablementController['enableNetwork'];\n};\n\nexport type NetworkEnablementControllerDisableNetworkAction = {\n type: `${typeof controllerName}:disableNetwork`;\n handler: NetworkEnablementController['disableNetwork'];\n};\n\nexport type NetworkEnablementControllerListPopularNetworksAction = {\n type: `${typeof controllerName}:listPopularNetworks`;\n handler: NetworkEnablementController['listPopularNetworks'];\n};\n\nexport type NetworkEnablementControllerListPopularEvmNetworksAction = {\n type: `${typeof controllerName}:listPopularEvmNetworks`;\n handler: NetworkEnablementController['listPopularEvmNetworks'];\n};\n\nexport type NetworkEnablementControllerListPopularMultichainNetworksAction = {\n type: `${typeof controllerName}:listPopularMultichainNetworks`;\n handler: NetworkEnablementController['listPopularMultichainNetworks'];\n};\n\n/**\n * All actions that {@link NetworkEnablementController} calls internally.\n */\nexport type AllowedActions =\n | NetworkControllerGetStateAction\n | MultichainNetworkControllerGetStateAction;\n\nexport type NetworkEnablementControllerActions =\n | NetworkEnablementControllerGetStateAction\n | NetworkEnablementControllerSetEnabledNetworksAction\n | NetworkEnablementControllerDisableNetworkAction\n | NetworkEnablementControllerListPopularNetworksAction\n | NetworkEnablementControllerListPopularEvmNetworksAction\n | NetworkEnablementControllerListPopularMultichainNetworksAction;\n\nexport type NetworkEnablementControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NetworkEnablementControllerState\n >;\n\nexport type NetworkEnablementControllerEvents =\n NetworkEnablementControllerStateChangeEvent;\n\n/**\n * All events that {@link NetworkEnablementController} subscribes to internally.\n */\nexport type AllowedEvents =\n | NetworkControllerNetworkAddedEvent\n | NetworkControllerNetworkRemovedEvent\n | NetworkControllerStateChangeEvent\n | TransactionControllerTransactionSubmittedEvent;\n\nexport type NetworkEnablementControllerMessenger = Messenger<\n typeof controllerName,\n NetworkEnablementControllerActions | AllowedActions,\n NetworkEnablementControllerEvents | AllowedEvents\n>;\n\n/**\n * Builds a native asset identifier in CAIP-19-like format.\n *\n * @param caipChainId - The CAIP-2 chain ID (e.g., 'eip155:1', 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')\n * @param slip44CoinType - The SLIP-44 coin type number\n * @returns The native asset identifier string (e.g., 'eip155:1/slip44:60')\n */\nfunction buildNativeAssetIdentifier(\n caipChainId: CaipChainId,\n slip44CoinType: number,\n): NativeAssetIdentifier {\n return `${caipChainId}/slip44:${slip44CoinType}`;\n}\n\n/**\n * Network configuration with chain ID and native currency symbol.\n * Used to initialize native asset identifiers.\n */\nexport type NetworkConfig = {\n chainId: CaipChainId;\n nativeCurrency: string;\n};\n\n/**\n * Gets the default state for the NetworkEnablementController.\n *\n * @returns The default state with pre-enabled networks.\n */\nconst getDefaultNetworkEnablementControllerState =\n (): NetworkEnablementControllerState => ({\n enabledNetworkMap: {\n [KnownCaipNamespace.Eip155]: {\n [ChainId[BuiltInNetworkName.Mainnet]]: true,\n [ChainId[BuiltInNetworkName.LineaMainnet]]: true,\n [ChainId[BuiltInNetworkName.BaseMainnet]]: true,\n [ChainId[BuiltInNetworkName.ArbitrumOne]]: true,\n [ChainId[BuiltInNetworkName.BscMainnet]]: true,\n [ChainId[BuiltInNetworkName.OptimismMainnet]]: true,\n [ChainId[BuiltInNetworkName.PolygonMainnet]]: true,\n [ChainId[BuiltInNetworkName.SeiMainnet]]: true,\n },\n [KnownCaipNamespace.Solana]: {\n [SolScope.Mainnet]: true,\n [SolScope.Testnet]: false,\n [SolScope.Devnet]: false,\n },\n [KnownCaipNamespace.Bip122]: {\n [BtcScope.Mainnet]: true,\n [BtcScope.Testnet]: false,\n [BtcScope.Signet]: false,\n },\n [KnownCaipNamespace.Tron]: {\n [TrxScope.Mainnet]: true,\n [TrxScope.Nile]: false,\n [TrxScope.Shasta]: false,\n },\n },\n // nativeAssetIdentifiers is initialized as empty and should be populated\n // by the client using initNativeAssetIdentifiers() during controller init\n nativeAssetIdentifiers: {},\n });\n\n// Metadata for the controller state\nconst metadata = {\n enabledNetworkMap: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n nativeAssetIdentifiers: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\n/**\n * Controller responsible for managing network enablement state across different blockchain networks.\n *\n * This controller tracks which networks are enabled/disabled for the user and provides methods\n * to toggle network states. It supports both EVM (EIP-155) and non-EVM networks like Solana.\n *\n * The controller maintains a map of enabled networks organized by namespace (e.g., 'eip155', 'solana')\n * and provides methods to query and modify network enablement states.\n */\nexport class NetworkEnablementController extends BaseController<\n typeof controllerName,\n NetworkEnablementControllerState,\n NetworkEnablementControllerMessenger\n> {\n /**\n * Creates a NetworkEnablementController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: NetworkEnablementControllerMessenger;\n state?: Partial<NetworkEnablementControllerState>;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: {\n ...getDefaultNetworkEnablementControllerState(),\n ...state,\n },\n });\n\n messenger.subscribe('NetworkController:networkAdded', ({ chainId }) => {\n // eslint-disable-next-line no-void\n void this.#onAddNetwork(chainId);\n });\n\n messenger.subscribe('NetworkController:networkRemoved', ({ chainId }) => {\n this.#removeNetworkEntry(chainId);\n });\n }\n\n /**\n * Enables or disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally. This dual parameter support allows for backward\n * compatibility with existing EVM chain ID formats while supporting newer\n * multi-chain standards.\n *\n * When enabling a non-popular network, this method will disable all other networks\n * to ensure only one network is active at a time (exclusive mode).\n *\n * @param chainId - The chain ID of the network to enable or disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\n enableNetwork(chainId: Hex | CaipChainId): void {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n this.update((state) => {\n // disable all networks in all namespaces first\n Object.keys(state.enabledNetworkMap).forEach((ns) => {\n Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {\n state.enabledNetworkMap[ns][key as CaipChainId | Hex] = false;\n });\n });\n\n // if the namespace bucket does not exist, return\n // new nemespace are added only when a new network is added\n if (!state.enabledNetworkMap[namespace]) {\n return;\n }\n\n // enable the network\n state.enabledNetworkMap[namespace][storageKey] = true;\n });\n }\n\n /**\n * Enables a network for the user within a specific namespace.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and enables it within the specified namespace.\n * The method validates that the chainId belongs to the specified namespace for safety.\n *\n * Before enabling the target network, this method disables all other networks\n * in the same namespace to ensure exclusive behavior within the namespace.\n *\n * @param chainId - The chain ID of the network to enable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @param namespace - The CAIP namespace where the network should be enabled\n * @throws Error if the chainId's derived namespace doesn't match the provided namespace\n */\n enableNetworkInNamespace(\n chainId: Hex | CaipChainId,\n namespace: CaipNamespace,\n ): void {\n const { namespace: derivedNamespace, storageKey } = deriveKeys(chainId);\n\n // Validate that the derived namespace matches the provided namespace\n if (derivedNamespace !== namespace) {\n throw new Error(\n `Chain ID ${chainId} belongs to namespace ${derivedNamespace}, but namespace ${namespace} was specified`,\n );\n }\n\n this.update((state) => {\n // Ensure the namespace bucket exists\n this.#ensureNamespaceBucket(state, namespace);\n\n // Disable all networks in the specified namespace first\n if (state.enabledNetworkMap[namespace]) {\n Object.keys(state.enabledNetworkMap[namespace]).forEach((key) => {\n state.enabledNetworkMap[namespace][key as CaipChainId | Hex] = false;\n });\n }\n\n // Enable the target network in the specified namespace\n state.enabledNetworkMap[namespace][storageKey] = true;\n });\n }\n\n /**\n * Enables all popular networks and Solana mainnet.\n *\n * This method first disables all networks across all namespaces, then enables\n * all networks defined in POPULAR_NETWORKS (EVM networks), Solana mainnet, and\n * Bitcoin mainnet. This provides exclusive behavior - only popular networks will\n * be enabled after calling this method.\n *\n * Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.\n */\n enableAllPopularNetworks(): void {\n this.update((state) => {\n // First disable all networks across all namespaces\n Object.keys(state.enabledNetworkMap).forEach((ns) => {\n Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {\n state.enabledNetworkMap[ns][key as CaipChainId | Hex] = false;\n });\n });\n\n // Get current network configurations to check if networks exist\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n const multichainState = this.messenger.call(\n 'MultichainNetworkController:getState',\n );\n\n // Enable all popular EVM networks that exist in NetworkController configurations\n POPULAR_NETWORKS.forEach((chainId) => {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n // Check if network exists in NetworkController configurations\n if (networkControllerState.networkConfigurationsByChainId[chainId]) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, namespace);\n // Enable the network\n state.enabledNetworkMap[namespace][storageKey] = true;\n }\n });\n\n // Enable Solana mainnet if it exists in MultichainNetworkController configurations\n const solanaKeys = deriveKeys(SolScope.Mainnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n SolScope.Mainnet\n ]\n ) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, solanaKeys.namespace);\n // Enable Solana mainnet\n state.enabledNetworkMap[solanaKeys.namespace][solanaKeys.storageKey] =\n true;\n }\n\n // Enable Bitcoin mainnet if it exists in MultichainNetworkController configurations\n const bitcoinKeys = deriveKeys(BtcScope.Mainnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n BtcScope.Mainnet\n ]\n ) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, bitcoinKeys.namespace);\n // Enable Bitcoin mainnet\n state.enabledNetworkMap[bitcoinKeys.namespace][bitcoinKeys.storageKey] =\n true;\n }\n\n // Enable Tron mainnet if it exists in MultichainNetworkController configurations\n const tronKeys = deriveKeys(TrxScope.Mainnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n TrxScope.Mainnet\n ]\n ) {\n // Ensure namespace bucket exists\n this.#ensureNamespaceBucket(state, tronKeys.namespace);\n // Enable Tron mainnet\n state.enabledNetworkMap[tronKeys.namespace][tronKeys.storageKey] = true;\n }\n });\n }\n\n /**\n * Initializes the network enablement state from network controller configurations.\n *\n * This method reads the current network configurations from both NetworkController\n * and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.\n * It ensures proper namespace buckets exist for all configured networks and only\n * adds missing networks with a default value of false, preserving existing user settings.\n *\n * This method should be called after the NetworkController and MultichainNetworkController\n * have been initialized and their configurations are available.\n */\n async init(): Promise<void> {\n // Get network configurations from NetworkController (EVM networks)\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n\n // Get network configurations from MultichainNetworkController (all networks)\n const multichainState = this.messenger.call(\n 'MultichainNetworkController:getState',\n );\n\n // Build nativeAssetIdentifiers for EVM networks using chainid.network\n const evmNativeAssetUpdates: {\n caipChainId: CaipChainId;\n identifier: NativeAssetIdentifier;\n }[] = [];\n\n for (const [chainId] of Object.entries(\n networkControllerState.networkConfigurationsByChainId,\n )) {\n const { caipChainId } = deriveKeys(chainId as Hex);\n\n // Skip if already in state\n if (this.state.nativeAssetIdentifiers[caipChainId] !== undefined) {\n continue;\n }\n\n // Parse hex chainId to number for chainid.network lookup\n const numericChainId = parseInt(chainId, 16);\n\n // EVM networks: use getEvmSlip44 (chainid.network data)\n const slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);\n\n evmNativeAssetUpdates.push({\n caipChainId,\n identifier: buildNativeAssetIdentifier(caipChainId, slip44CoinType),\n });\n }\n\n // Update state synchronously\n this.update((state) => {\n // Initialize namespace buckets for EVM networks from NetworkController\n Object.entries(\n networkControllerState.networkConfigurationsByChainId,\n ).forEach(([chainId]) => {\n const { namespace, storageKey } = deriveKeys(chainId as Hex);\n this.#ensureNamespaceBucket(state, namespace);\n\n // Only add network if it doesn't already exist in state (preserves user settings)\n state.enabledNetworkMap[namespace][storageKey] ??= false;\n });\n\n // Apply nativeAssetIdentifier updates\n for (const { caipChainId, identifier } of evmNativeAssetUpdates) {\n state.nativeAssetIdentifiers[caipChainId] = identifier;\n }\n\n // Initialize namespace buckets for all networks from MultichainNetworkController\n Object.keys(\n multichainState.multichainNetworkConfigurationsByChainId,\n ).forEach((chainId) => {\n const { namespace, storageKey } = deriveKeys(chainId as CaipChainId);\n this.#ensureNamespaceBucket(state, namespace);\n\n // Only add network if it doesn't already exist in state (preserves user settings)\n state.enabledNetworkMap[namespace][storageKey] ??= false;\n });\n });\n }\n\n /**\n * Initializes the native asset identifiers from network configurations.\n * This method should be called from the client during controller initialization\n * to populate the nativeAssetIdentifiers state based on actual network configurations.\n *\n * @param networks - Array of network configurations with chainId and nativeCurrency\n * @example\n * ```typescript\n * const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)\n * .map(config => ({\n * chainId: toEvmCaipChainId(config.chainId),\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)\n * .map(config => ({\n * chainId: config.chainId,\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * await controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);\n * ```\n */\n async initNativeAssetIdentifiers(networks: NetworkConfig[]): Promise<void> {\n // Process networks and collect updates\n const updates: {\n chainId: CaipChainId;\n identifier: NativeAssetIdentifier;\n }[] = [];\n\n for (const { chainId, nativeCurrency } of networks) {\n // Check if nativeCurrency is already in CAIP-19 format (e.g., \"bip122:.../slip44:0\")\n // Non-EVM networks from MultichainNetworkController use this format\n if (nativeCurrency.includes('/slip44:')) {\n updates.push({\n chainId,\n identifier: nativeCurrency as NativeAssetIdentifier,\n });\n continue;\n }\n\n // Extract namespace from CAIP-2 chainId\n const [namespace, reference] = chainId.split(':');\n let slip44CoinType: number | undefined;\n\n if (namespace === 'eip155') {\n // EVM networks: use getEvmSlip44 (chainid.network data)\n const numericChainId = parseInt(reference, 10);\n slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);\n } else {\n // Non-EVM networks: use getSlip44BySymbol (@metamask/slip44 package)\n slip44CoinType = Slip44Service.getSlip44BySymbol(nativeCurrency);\n }\n\n if (slip44CoinType !== undefined) {\n updates.push({\n chainId,\n identifier: buildNativeAssetIdentifier(chainId, slip44CoinType),\n });\n }\n }\n\n // Apply all updates synchronously\n this.update((state) => {\n for (const { chainId, identifier } of updates) {\n state.nativeAssetIdentifiers[chainId] = identifier;\n }\n });\n }\n\n /**\n * Disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally.\n *\n * Note: This method will prevent disabling the last remaining enabled network\n * to ensure at least one network is always available.\n *\n * @param chainId - The chain ID of the network to disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\n disableNetwork(chainId: Hex | CaipChainId): void {\n const derivedKeys = deriveKeys(chainId);\n const { namespace, storageKey } = derivedKeys;\n\n this.update((state) => {\n state.enabledNetworkMap[namespace][storageKey] = false;\n });\n }\n\n /**\n * Checks if a network is enabled.\n *\n * @param chainId - The chain ID of the network to check. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @returns True if the network is enabled, false otherwise\n */\n isNetworkEnabled(chainId: Hex | CaipChainId): boolean {\n const derivedKeys = deriveKeys(chainId);\n const { namespace, storageKey } = derivedKeys;\n return this.state.enabledNetworkMap[namespace]?.[storageKey] ?? false;\n }\n\n /**\n * Ensures that a namespace bucket exists in the state.\n *\n * This method creates the namespace entry in the enabledNetworkMap if it doesn't\n * already exist. This is used to prepare the state structure before adding\n * network entries.\n *\n * @param state - The current controller state\n * @param ns - The CAIP namespace to ensure exists\n */\n #ensureNamespaceBucket(\n state: NetworkEnablementControllerState,\n ns: CaipNamespace,\n ): void {\n if (!state.enabledNetworkMap[ns]) {\n state.enabledNetworkMap[ns] = {};\n }\n }\n\n /**\n * Checks if popular networks mode is active (more than 2 popular networks enabled).\n *\n * This method counts how many networks defined in POPULAR_NETWORKS are currently\n * enabled in the state and returns true if more than 2 are enabled. It only checks\n * networks that actually exist in the NetworkController configurations.\n *\n * @returns True if more than 2 popular networks are enabled, false otherwise\n */\n #isInPopularNetworksMode(): boolean {\n // Get current network configurations to check which popular networks exist\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n\n // Count how many popular networks are enabled\n const enabledPopularNetworksCount = POPULAR_NETWORKS.reduce(\n (count, chainId) => {\n // Only check networks that actually exist in NetworkController configurations\n if (!networkControllerState.networkConfigurationsByChainId[chainId]) {\n return count; // Skip networks that don't exist\n }\n\n const { namespace, storageKey } = deriveKeys(chainId);\n const isEnabled = this.state.enabledNetworkMap[namespace]?.[storageKey];\n return isEnabled ? count + 1 : count;\n },\n 0,\n );\n\n // Return true if more than 2 popular networks are enabled\n return enabledPopularNetworksCount > 1;\n }\n\n /**\n * Removes a network entry from the state.\n *\n * This method is called when a network is removed from the system. It cleans up\n * the network entry from both enabledNetworkMap and nativeAssetIdentifiers, and ensures that\n * at least one network remains enabled.\n *\n * @param chainId - The chain ID to remove (Hex or CAIP-2 format)\n */\n #removeNetworkEntry(chainId: Hex | CaipChainId): void {\n const derivedKeys = deriveKeys(chainId);\n const { namespace, storageKey, caipChainId } = derivedKeys;\n\n this.update((state) => {\n // fallback and enable ethereum mainnet\n if (isOnlyNetworkEnabledInNamespace(this.state, derivedKeys)) {\n state.enabledNetworkMap[namespace][\n ChainId[BuiltInNetworkName.Mainnet]\n ] = true;\n }\n\n if (namespace in state.enabledNetworkMap) {\n delete state.enabledNetworkMap[namespace][storageKey];\n }\n\n // Remove from nativeAssetIdentifiers as well\n delete state.nativeAssetIdentifiers[caipChainId];\n });\n }\n\n /**\n * Handles the addition of a new EVM network to the controller.\n *\n * @param chainId - The chain ID to add (Hex format)\n *\n * @description\n * - If in popular networks mode (>2 popular networks enabled) AND adding a popular network:\n * - Keep current selection (add but don't enable the new network)\n * - Otherwise:\n * - Switch to the newly added network (disable all others, enable this one)\n * - Also updates the nativeAssetIdentifiers with the CAIP-19-like identifier\n */\n async #onAddNetwork(chainId: Hex): Promise<void> {\n const { namespace, storageKey, reference, caipChainId } =\n deriveKeys(chainId);\n\n // Parse reference (decimal string from CAIP-2) to number for chainid.network lookup\n const numericChainId = parseInt(reference, 10);\n\n // EVM networks: use getEvmSlip44 (chainid.network data)\n const slip44CoinType = await Slip44Service.getEvmSlip44(numericChainId);\n\n this.update((state) => {\n // Ensure the namespace bucket exists\n this.#ensureNamespaceBucket(state, namespace);\n\n // Check if popular networks mode is active (>2 popular networks enabled)\n const inPopularNetworksMode = this.#isInPopularNetworksMode();\n\n // Check if the network being added is a popular network\n const isAddedNetworkPopular = isPopularNetwork(reference);\n\n // Keep current selection only if in popular networks mode AND adding a popular network\n const shouldKeepCurrentSelection =\n inPopularNetworksMode && isAddedNetworkPopular;\n\n if (shouldKeepCurrentSelection) {\n // Add the popular network but don't enable it (keep current selection)\n state.enabledNetworkMap[namespace][storageKey] = true;\n } else {\n // Switch to the newly added network (disable all others, enable this one)\n Object.keys(state.enabledNetworkMap).forEach((ns) => {\n Object.keys(state.enabledNetworkMap[ns]).forEach((key) => {\n state.enabledNetworkMap[ns][key as CaipChainId | Hex] = false;\n });\n });\n // Enable the newly added network\n state.enabledNetworkMap[namespace][storageKey] = true;\n }\n\n // Update nativeAssetIdentifiers with the CAIP-19-like identifier\n state.nativeAssetIdentifiers[caipChainId] = buildNativeAssetIdentifier(\n caipChainId,\n slip44CoinType,\n );\n });\n }\n\n /**\n * Returns popular EVM network chain IDs in hex form, restricted to networks\n * that exist in NetworkController (networkConfigurationsByChainId). Source list\n * is POPULAR_NETWORKS.\n *\n * @returns Hex chain IDs for popular EVM networks that are configured.\n */\n listPopularEvmNetworks(): Hex[] {\n const networkControllerState = this.messenger.call(\n 'NetworkController:getState',\n );\n return POPULAR_NETWORKS.filter(\n (chainIdHex) =>\n networkControllerState.networkConfigurationsByChainId[chainIdHex],\n );\n }\n\n /**\n * Returns popular multichain (Bitcoin, Solana, Tron) mainnet chain IDs in\n * CAIP-2 form, restricted to networks that exist in MultichainNetworkController\n * (multichainNetworkConfigurationsByChainId).\n *\n * @returns CAIP-2 chain IDs for Bitcoin, Solana, and Tron mainnets that are configured.\n */\n listPopularMultichainNetworks(): CaipChainId[] {\n const multichainState = this.messenger.call(\n 'MultichainNetworkController:getState',\n );\n const multichainMainnets = [\n BtcScope.Mainnet,\n SolScope.Mainnet,\n TrxScope.Mainnet,\n ] as const;\n return multichainMainnets.filter(\n (chainId) =>\n multichainState.multichainNetworkConfigurationsByChainId[chainId],\n );\n }\n\n /**\n * Returns the list of popular network chain IDs in CAIP-2 form, restricted to\n * networks that exist in NetworkController (networkConfigurationsByChainId) and\n * MultichainNetworkController (multichainNetworkConfigurationsByChainId). EVM\n * popular networks come from POPULAR_NETWORKS; multichain popular are Bitcoin,\n * Solana, and Tron mainnets.\n *\n * @returns CAIP-2 chain IDs for popular EVM networks and multichain mainnets that are configured.\n */\n listPopularNetworks(): CaipChainId[] {\n const evmHex = this.listPopularEvmNetworks();\n const evmCaip = evmHex.map((chainIdHex) => toEvmCaipChainId(chainIdHex));\n return [...evmCaip, ...this.listPopularMultichainNetworks()];\n }\n}\n"]}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iFAA4E;AAAnE,0IAAA,2BAA2B,OAAA;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iFAA4E;AAAnE,0IAAA,2BAA2B,OAAA;AAgBpC,6CAQqB;AAPnB,oHAAA,uBAAuB,OAAA;AACvB,mHAAA,sBAAsB,OAAA;AACtB,yIAAA,4CAA4C,OAAA;AAC5C,qHAAA,wBAAwB,OAAA;AACxB,uHAAA,0BAA0B,OAAA;AAC1B,qHAAA,wBAAwB,OAAA;AACxB,wHAAA,2BAA2B,OAAA;AAG7B,iDAA4E;AAAnE,yGAAA,aAAa,OAAA;AAAE,wGAAA,YAAY,OAAA;AAAE,6GAAA,iBAAiB,OAAA","sourcesContent":["export { NetworkEnablementController } from './NetworkEnablementController';\n\nexport type {\n NetworkEnablementControllerState,\n NetworkEnablementControllerGetStateAction,\n NetworkEnablementControllerActions,\n NetworkEnablementControllerEvents,\n NetworkEnablementControllerMessenger,\n NetworkEnablementControllerListPopularNetworksAction,\n NetworkEnablementControllerListPopularEvmNetworksAction,\n NetworkEnablementControllerListPopularMultichainNetworksAction,\n NativeAssetIdentifier,\n NativeAssetIdentifiersMap,\n NetworkConfig,\n} from './NetworkEnablementController';\n\nexport {\n selectEnabledNetworkMap,\n selectIsNetworkEnabled,\n createSelectorForEnabledNetworksForNamespace,\n selectAllEnabledNetworks,\n selectEnabledNetworksCount,\n selectEnabledEvmNetworks,\n selectEnabledSolanaNetworks,\n} from './selectors';\n\nexport { Slip44Service, getEvmSlip44, getSlip44BySymbol } from './services';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { NetworkEnablementController } from "./NetworkEnablementController.cjs";
|
|
2
|
-
export type { NetworkEnablementControllerState, NetworkEnablementControllerGetStateAction, NetworkEnablementControllerActions, NetworkEnablementControllerEvents, NetworkEnablementControllerMessenger, NativeAssetIdentifier, NativeAssetIdentifiersMap, NetworkConfig, } from "./NetworkEnablementController.cjs";
|
|
3
|
-
export type { NetworkEnablementControllerEnableNetworkAction, NetworkEnablementControllerEnableNetworkInNamespaceAction, NetworkEnablementControllerEnableAllPopularNetworksAction, NetworkEnablementControllerInitAction, NetworkEnablementControllerInitNativeAssetIdentifiersAction, NetworkEnablementControllerDisableNetworkAction, NetworkEnablementControllerIsNetworkEnabledAction, NetworkEnablementControllerListPopularEvmNetworksAction, NetworkEnablementControllerListPopularMultichainNetworksAction, NetworkEnablementControllerListPopularNetworksAction, } from "./NetworkEnablementController-method-action-types.cjs";
|
|
2
|
+
export type { NetworkEnablementControllerState, NetworkEnablementControllerGetStateAction, NetworkEnablementControllerActions, NetworkEnablementControllerEvents, NetworkEnablementControllerMessenger, NetworkEnablementControllerListPopularNetworksAction, NetworkEnablementControllerListPopularEvmNetworksAction, NetworkEnablementControllerListPopularMultichainNetworksAction, NativeAssetIdentifier, NativeAssetIdentifiersMap, NetworkConfig, } from "./NetworkEnablementController.cjs";
|
|
4
3
|
export { selectEnabledNetworkMap, selectIsNetworkEnabled, createSelectorForEnabledNetworksForNamespace, selectAllEnabledNetworks, selectEnabledNetworksCount, selectEnabledEvmNetworks, selectEnabledSolanaNetworks, } from "./selectors.cjs";
|
|
5
4
|
export { Slip44Service, getEvmSlip44, getSlip44BySymbol } from "./services/index.cjs";
|
|
6
5
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,0CAAsC;AAE5E,YAAY,EACV,gCAAgC,EAChC,yCAAyC,EACzC,kCAAkC,EAClC,iCAAiC,EACjC,oCAAoC,EACpC,qBAAqB,EACrB,yBAAyB,EACzB,aAAa,GACd,0CAAsC;AAEvC,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,0CAAsC;AAE5E,YAAY,EACV,gCAAgC,EAChC,yCAAyC,EACzC,kCAAkC,EAClC,iCAAiC,EACjC,oCAAoC,EACpC,oDAAoD,EACpD,uDAAuD,EACvD,8DAA8D,EAC9D,qBAAqB,EACrB,yBAAyB,EACzB,aAAa,GACd,0CAAsC;AAEvC,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,4CAA4C,EAC5C,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,GAC5B,wBAAoB;AAErB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,6BAAmB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { NetworkEnablementController } from "./NetworkEnablementController.mjs";
|
|
2
|
-
export type { NetworkEnablementControllerState, NetworkEnablementControllerGetStateAction, NetworkEnablementControllerActions, NetworkEnablementControllerEvents, NetworkEnablementControllerMessenger, NativeAssetIdentifier, NativeAssetIdentifiersMap, NetworkConfig, } from "./NetworkEnablementController.mjs";
|
|
3
|
-
export type { NetworkEnablementControllerEnableNetworkAction, NetworkEnablementControllerEnableNetworkInNamespaceAction, NetworkEnablementControllerEnableAllPopularNetworksAction, NetworkEnablementControllerInitAction, NetworkEnablementControllerInitNativeAssetIdentifiersAction, NetworkEnablementControllerDisableNetworkAction, NetworkEnablementControllerIsNetworkEnabledAction, NetworkEnablementControllerListPopularEvmNetworksAction, NetworkEnablementControllerListPopularMultichainNetworksAction, NetworkEnablementControllerListPopularNetworksAction, } from "./NetworkEnablementController-method-action-types.mjs";
|
|
2
|
+
export type { NetworkEnablementControllerState, NetworkEnablementControllerGetStateAction, NetworkEnablementControllerActions, NetworkEnablementControllerEvents, NetworkEnablementControllerMessenger, NetworkEnablementControllerListPopularNetworksAction, NetworkEnablementControllerListPopularEvmNetworksAction, NetworkEnablementControllerListPopularMultichainNetworksAction, NativeAssetIdentifier, NativeAssetIdentifiersMap, NetworkConfig, } from "./NetworkEnablementController.mjs";
|
|
4
3
|
export { selectEnabledNetworkMap, selectIsNetworkEnabled, createSelectorForEnabledNetworksForNamespace, selectAllEnabledNetworks, selectEnabledNetworksCount, selectEnabledEvmNetworks, selectEnabledSolanaNetworks, } from "./selectors.mjs";
|
|
5
4
|
export { Slip44Service, getEvmSlip44, getSlip44BySymbol } from "./services/index.mjs";
|
|
6
5
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,0CAAsC;AAE5E,YAAY,EACV,gCAAgC,EAChC,yCAAyC,EACzC,kCAAkC,EAClC,iCAAiC,EACjC,oCAAoC,EACpC,qBAAqB,EACrB,yBAAyB,EACzB,aAAa,GACd,0CAAsC;AAEvC,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,0CAAsC;AAE5E,YAAY,EACV,gCAAgC,EAChC,yCAAyC,EACzC,kCAAkC,EAClC,iCAAiC,EACjC,oCAAoC,EACpC,oDAAoD,EACpD,uDAAuD,EACvD,8DAA8D,EAC9D,qBAAqB,EACrB,yBAAyB,EACzB,aAAa,GACd,0CAAsC;AAEvC,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,4CAA4C,EAC5C,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,GAC5B,wBAAoB;AAErB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,6BAAmB"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,0CAAsC;
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,0CAAsC;AAgB5E,OAAO,EACL,uBAAuB,EACvB,sBAAsB,EACtB,4CAA4C,EAC5C,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,2BAA2B,EAC5B,wBAAoB;AAErB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,6BAAmB","sourcesContent":["export { NetworkEnablementController } from './NetworkEnablementController';\n\nexport type {\n NetworkEnablementControllerState,\n NetworkEnablementControllerGetStateAction,\n NetworkEnablementControllerActions,\n NetworkEnablementControllerEvents,\n NetworkEnablementControllerMessenger,\n NetworkEnablementControllerListPopularNetworksAction,\n NetworkEnablementControllerListPopularEvmNetworksAction,\n NetworkEnablementControllerListPopularMultichainNetworksAction,\n NativeAssetIdentifier,\n NativeAssetIdentifiersMap,\n NetworkConfig,\n} from './NetworkEnablementController';\n\nexport {\n selectEnabledNetworkMap,\n selectIsNetworkEnabled,\n createSelectorForEnabledNetworksForNamespace,\n selectAllEnabledNetworks,\n selectEnabledNetworksCount,\n selectEnabledEvmNetworks,\n selectEnabledSolanaNetworks,\n} from './selectors';\n\nexport { Slip44Service, getEvmSlip44, getSlip44BySymbol } from './services';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/network-enablement-controller",
|
|
3
|
-
"version": "4.2.0-preview-
|
|
3
|
+
"version": "4.2.0-preview-d3b0814a7",
|
|
4
4
|
"description": "Provides an interface to the currently enabled network using a MetaMask-compatible provider object",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -40,7 +40,6 @@
|
|
|
40
40
|
"build:docs": "typedoc",
|
|
41
41
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/network-enablement-controller",
|
|
42
42
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/network-enablement-controller",
|
|
43
|
-
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
|
|
44
43
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
45
44
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
46
45
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
@@ -52,10 +51,10 @@
|
|
|
52
51
|
"@metamask/controller-utils": "^11.19.0",
|
|
53
52
|
"@metamask/keyring-api": "^21.5.0",
|
|
54
53
|
"@metamask/messenger": "^0.3.0",
|
|
55
|
-
"@metamask/multichain-network-controller": "^3.0.
|
|
54
|
+
"@metamask/multichain-network-controller": "^3.0.4",
|
|
56
55
|
"@metamask/network-controller": "^30.0.0",
|
|
57
56
|
"@metamask/slip44": "^4.3.0",
|
|
58
|
-
"@metamask/transaction-controller": "^62.
|
|
57
|
+
"@metamask/transaction-controller": "^62.20.0",
|
|
59
58
|
"@metamask/utils": "^11.9.0",
|
|
60
59
|
"reselect": "^5.1.1"
|
|
61
60
|
},
|
|
@@ -66,7 +65,6 @@
|
|
|
66
65
|
"deepmerge": "^4.2.2",
|
|
67
66
|
"jest": "^29.7.0",
|
|
68
67
|
"ts-jest": "^29.2.5",
|
|
69
|
-
"tsx": "^4.20.5",
|
|
70
68
|
"typedoc": "^0.25.13",
|
|
71
69
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
72
70
|
"typescript": "~5.3.3"
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
4
|
-
* Do not edit manually.
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
//# sourceMappingURL=NetworkEnablementController-method-action-types.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkEnablementController-method-action-types.cjs","sourceRoot":"","sources":["../src/NetworkEnablementController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { NetworkEnablementController } from './NetworkEnablementController';\n\n/**\n * Enables or disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally. This dual parameter support allows for backward\n * compatibility with existing EVM chain ID formats while supporting newer\n * multi-chain standards.\n *\n * When enabling a non-popular network, this method will disable all other networks\n * to ensure only one network is active at a time (exclusive mode).\n *\n * @param chainId - The chain ID of the network to enable or disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\nexport type NetworkEnablementControllerEnableNetworkAction = {\n type: `NetworkEnablementController:enableNetwork`;\n handler: NetworkEnablementController['enableNetwork'];\n};\n\n/**\n * Enables a network for the user within a specific namespace.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and enables it within the specified namespace.\n * The method validates that the chainId belongs to the specified namespace for safety.\n *\n * Before enabling the target network, this method disables all other networks\n * in the same namespace to ensure exclusive behavior within the namespace.\n *\n * @param chainId - The chain ID of the network to enable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @param namespace - The CAIP namespace where the network should be enabled\n * @throws Error if the chainId's derived namespace doesn't match the provided namespace\n */\nexport type NetworkEnablementControllerEnableNetworkInNamespaceAction = {\n type: `NetworkEnablementController:enableNetworkInNamespace`;\n handler: NetworkEnablementController['enableNetworkInNamespace'];\n};\n\n/**\n * Enables all popular networks and Solana mainnet.\n *\n * This method first disables all networks across all namespaces, then enables\n * all networks defined in POPULAR_NETWORKS (EVM networks), Solana mainnet, and\n * Bitcoin mainnet. This provides exclusive behavior - only popular networks will\n * be enabled after calling this method.\n *\n * Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.\n */\nexport type NetworkEnablementControllerEnableAllPopularNetworksAction = {\n type: `NetworkEnablementController:enableAllPopularNetworks`;\n handler: NetworkEnablementController['enableAllPopularNetworks'];\n};\n\n/**\n * Initializes the network enablement state from network controller configurations.\n *\n * This method reads the current network configurations from both NetworkController\n * and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.\n * It ensures proper namespace buckets exist for all configured networks and only\n * adds missing networks with a default value of false, preserving existing user settings.\n *\n * This method should be called after the NetworkController and MultichainNetworkController\n * have been initialized and their configurations are available.\n */\nexport type NetworkEnablementControllerInitAction = {\n type: `NetworkEnablementController:init`;\n handler: NetworkEnablementController['init'];\n};\n\n/**\n * Initializes the native asset identifiers from network configurations.\n * This method should be called from the client during controller initialization\n * to populate the nativeAssetIdentifiers state based on actual network configurations.\n *\n * @param networks - Array of network configurations with chainId and nativeCurrency\n * @example\n * ```typescript\n * const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)\n * .map(config => ({\n * chainId: toEvmCaipChainId(config.chainId),\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)\n * .map(config => ({\n * chainId: config.chainId,\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * await controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);\n * ```\n */\nexport type NetworkEnablementControllerInitNativeAssetIdentifiersAction = {\n type: `NetworkEnablementController:initNativeAssetIdentifiers`;\n handler: NetworkEnablementController['initNativeAssetIdentifiers'];\n};\n\n/**\n * Disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally.\n *\n * Note: This method will prevent disabling the last remaining enabled network\n * to ensure at least one network is always available.\n *\n * @param chainId - The chain ID of the network to disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\nexport type NetworkEnablementControllerDisableNetworkAction = {\n type: `NetworkEnablementController:disableNetwork`;\n handler: NetworkEnablementController['disableNetwork'];\n};\n\n/**\n * Checks if a network is enabled.\n *\n * @param chainId - The chain ID of the network to check. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @returns True if the network is enabled, false otherwise\n */\nexport type NetworkEnablementControllerIsNetworkEnabledAction = {\n type: `NetworkEnablementController:isNetworkEnabled`;\n handler: NetworkEnablementController['isNetworkEnabled'];\n};\n\n/**\n * Returns popular EVM network chain IDs in hex form, restricted to networks\n * that exist in NetworkController (networkConfigurationsByChainId). Source list\n * is POPULAR_NETWORKS.\n *\n * @returns Hex chain IDs for popular EVM networks that are configured.\n */\nexport type NetworkEnablementControllerListPopularEvmNetworksAction = {\n type: `NetworkEnablementController:listPopularEvmNetworks`;\n handler: NetworkEnablementController['listPopularEvmNetworks'];\n};\n\n/**\n * Returns popular multichain (Bitcoin, Solana, Tron) mainnet chain IDs in\n * CAIP-2 form, restricted to networks that exist in MultichainNetworkController\n * (multichainNetworkConfigurationsByChainId).\n *\n * @returns CAIP-2 chain IDs for Bitcoin, Solana, and Tron mainnets that are configured.\n */\nexport type NetworkEnablementControllerListPopularMultichainNetworksAction = {\n type: `NetworkEnablementController:listPopularMultichainNetworks`;\n handler: NetworkEnablementController['listPopularMultichainNetworks'];\n};\n\n/**\n * Returns the list of popular network chain IDs in CAIP-2 form, restricted to\n * networks that exist in NetworkController (networkConfigurationsByChainId) and\n * MultichainNetworkController (multichainNetworkConfigurationsByChainId). EVM\n * popular networks come from POPULAR_NETWORKS; multichain popular are Bitcoin,\n * Solana, and Tron mainnets.\n *\n * @returns CAIP-2 chain IDs for popular EVM networks and multichain mainnets that are configured.\n */\nexport type NetworkEnablementControllerListPopularNetworksAction = {\n type: `NetworkEnablementController:listPopularNetworks`;\n handler: NetworkEnablementController['listPopularNetworks'];\n};\n\n/**\n * Union of all NetworkEnablementController action types.\n */\nexport type NetworkEnablementControllerMethodActions =\n | NetworkEnablementControllerEnableNetworkAction\n | NetworkEnablementControllerEnableNetworkInNamespaceAction\n | NetworkEnablementControllerEnableAllPopularNetworksAction\n | NetworkEnablementControllerInitAction\n | NetworkEnablementControllerInitNativeAssetIdentifiersAction\n | NetworkEnablementControllerDisableNetworkAction\n | NetworkEnablementControllerIsNetworkEnabledAction\n | NetworkEnablementControllerListPopularEvmNetworksAction\n | NetworkEnablementControllerListPopularMultichainNetworksAction\n | NetworkEnablementControllerListPopularNetworksAction;\n"]}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
-
* Do not edit manually.
|
|
4
|
-
*/
|
|
5
|
-
import type { NetworkEnablementController } from "./NetworkEnablementController.cjs";
|
|
6
|
-
/**
|
|
7
|
-
* Enables or disables a network for the user.
|
|
8
|
-
*
|
|
9
|
-
* This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID
|
|
10
|
-
* (for any blockchain network). The method will automatically convert Hex chain IDs
|
|
11
|
-
* to CAIP-2 format internally. This dual parameter support allows for backward
|
|
12
|
-
* compatibility with existing EVM chain ID formats while supporting newer
|
|
13
|
-
* multi-chain standards.
|
|
14
|
-
*
|
|
15
|
-
* When enabling a non-popular network, this method will disable all other networks
|
|
16
|
-
* to ensure only one network is active at a time (exclusive mode).
|
|
17
|
-
*
|
|
18
|
-
* @param chainId - The chain ID of the network to enable or disable. Can be either:
|
|
19
|
-
* - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks
|
|
20
|
-
* - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)
|
|
21
|
-
*/
|
|
22
|
-
export type NetworkEnablementControllerEnableNetworkAction = {
|
|
23
|
-
type: `NetworkEnablementController:enableNetwork`;
|
|
24
|
-
handler: NetworkEnablementController['enableNetwork'];
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Enables a network for the user within a specific namespace.
|
|
28
|
-
*
|
|
29
|
-
* This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID
|
|
30
|
-
* (for any blockchain network) and enables it within the specified namespace.
|
|
31
|
-
* The method validates that the chainId belongs to the specified namespace for safety.
|
|
32
|
-
*
|
|
33
|
-
* Before enabling the target network, this method disables all other networks
|
|
34
|
-
* in the same namespace to ensure exclusive behavior within the namespace.
|
|
35
|
-
*
|
|
36
|
-
* @param chainId - The chain ID of the network to enable. Can be either:
|
|
37
|
-
* - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks
|
|
38
|
-
* - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)
|
|
39
|
-
* @param namespace - The CAIP namespace where the network should be enabled
|
|
40
|
-
* @throws Error if the chainId's derived namespace doesn't match the provided namespace
|
|
41
|
-
*/
|
|
42
|
-
export type NetworkEnablementControllerEnableNetworkInNamespaceAction = {
|
|
43
|
-
type: `NetworkEnablementController:enableNetworkInNamespace`;
|
|
44
|
-
handler: NetworkEnablementController['enableNetworkInNamespace'];
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Enables all popular networks and Solana mainnet.
|
|
48
|
-
*
|
|
49
|
-
* This method first disables all networks across all namespaces, then enables
|
|
50
|
-
* all networks defined in POPULAR_NETWORKS (EVM networks), Solana mainnet, and
|
|
51
|
-
* Bitcoin mainnet. This provides exclusive behavior - only popular networks will
|
|
52
|
-
* be enabled after calling this method.
|
|
53
|
-
*
|
|
54
|
-
* Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.
|
|
55
|
-
*/
|
|
56
|
-
export type NetworkEnablementControllerEnableAllPopularNetworksAction = {
|
|
57
|
-
type: `NetworkEnablementController:enableAllPopularNetworks`;
|
|
58
|
-
handler: NetworkEnablementController['enableAllPopularNetworks'];
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Initializes the network enablement state from network controller configurations.
|
|
62
|
-
*
|
|
63
|
-
* This method reads the current network configurations from both NetworkController
|
|
64
|
-
* and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.
|
|
65
|
-
* It ensures proper namespace buckets exist for all configured networks and only
|
|
66
|
-
* adds missing networks with a default value of false, preserving existing user settings.
|
|
67
|
-
*
|
|
68
|
-
* This method should be called after the NetworkController and MultichainNetworkController
|
|
69
|
-
* have been initialized and their configurations are available.
|
|
70
|
-
*/
|
|
71
|
-
export type NetworkEnablementControllerInitAction = {
|
|
72
|
-
type: `NetworkEnablementController:init`;
|
|
73
|
-
handler: NetworkEnablementController['init'];
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Initializes the native asset identifiers from network configurations.
|
|
77
|
-
* This method should be called from the client during controller initialization
|
|
78
|
-
* to populate the nativeAssetIdentifiers state based on actual network configurations.
|
|
79
|
-
*
|
|
80
|
-
* @param networks - Array of network configurations with chainId and nativeCurrency
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)
|
|
84
|
-
* .map(config => ({
|
|
85
|
-
* chainId: toEvmCaipChainId(config.chainId),
|
|
86
|
-
* nativeCurrency: config.nativeCurrency,
|
|
87
|
-
* }));
|
|
88
|
-
*
|
|
89
|
-
* const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)
|
|
90
|
-
* .map(config => ({
|
|
91
|
-
* chainId: config.chainId,
|
|
92
|
-
* nativeCurrency: config.nativeCurrency,
|
|
93
|
-
* }));
|
|
94
|
-
*
|
|
95
|
-
* await controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
export type NetworkEnablementControllerInitNativeAssetIdentifiersAction = {
|
|
99
|
-
type: `NetworkEnablementController:initNativeAssetIdentifiers`;
|
|
100
|
-
handler: NetworkEnablementController['initNativeAssetIdentifiers'];
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Disables a network for the user.
|
|
104
|
-
*
|
|
105
|
-
* This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID
|
|
106
|
-
* (for any blockchain network). The method will automatically convert Hex chain IDs
|
|
107
|
-
* to CAIP-2 format internally.
|
|
108
|
-
*
|
|
109
|
-
* Note: This method will prevent disabling the last remaining enabled network
|
|
110
|
-
* to ensure at least one network is always available.
|
|
111
|
-
*
|
|
112
|
-
* @param chainId - The chain ID of the network to disable. Can be either:
|
|
113
|
-
* - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks
|
|
114
|
-
* - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)
|
|
115
|
-
*/
|
|
116
|
-
export type NetworkEnablementControllerDisableNetworkAction = {
|
|
117
|
-
type: `NetworkEnablementController:disableNetwork`;
|
|
118
|
-
handler: NetworkEnablementController['disableNetwork'];
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* Checks if a network is enabled.
|
|
122
|
-
*
|
|
123
|
-
* @param chainId - The chain ID of the network to check. Can be either:
|
|
124
|
-
* - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks
|
|
125
|
-
* - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)
|
|
126
|
-
* @returns True if the network is enabled, false otherwise
|
|
127
|
-
*/
|
|
128
|
-
export type NetworkEnablementControllerIsNetworkEnabledAction = {
|
|
129
|
-
type: `NetworkEnablementController:isNetworkEnabled`;
|
|
130
|
-
handler: NetworkEnablementController['isNetworkEnabled'];
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Returns popular EVM network chain IDs in hex form, restricted to networks
|
|
134
|
-
* that exist in NetworkController (networkConfigurationsByChainId). Source list
|
|
135
|
-
* is POPULAR_NETWORKS.
|
|
136
|
-
*
|
|
137
|
-
* @returns Hex chain IDs for popular EVM networks that are configured.
|
|
138
|
-
*/
|
|
139
|
-
export type NetworkEnablementControllerListPopularEvmNetworksAction = {
|
|
140
|
-
type: `NetworkEnablementController:listPopularEvmNetworks`;
|
|
141
|
-
handler: NetworkEnablementController['listPopularEvmNetworks'];
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* Returns popular multichain (Bitcoin, Solana, Tron) mainnet chain IDs in
|
|
145
|
-
* CAIP-2 form, restricted to networks that exist in MultichainNetworkController
|
|
146
|
-
* (multichainNetworkConfigurationsByChainId).
|
|
147
|
-
*
|
|
148
|
-
* @returns CAIP-2 chain IDs for Bitcoin, Solana, and Tron mainnets that are configured.
|
|
149
|
-
*/
|
|
150
|
-
export type NetworkEnablementControllerListPopularMultichainNetworksAction = {
|
|
151
|
-
type: `NetworkEnablementController:listPopularMultichainNetworks`;
|
|
152
|
-
handler: NetworkEnablementController['listPopularMultichainNetworks'];
|
|
153
|
-
};
|
|
154
|
-
/**
|
|
155
|
-
* Returns the list of popular network chain IDs in CAIP-2 form, restricted to
|
|
156
|
-
* networks that exist in NetworkController (networkConfigurationsByChainId) and
|
|
157
|
-
* MultichainNetworkController (multichainNetworkConfigurationsByChainId). EVM
|
|
158
|
-
* popular networks come from POPULAR_NETWORKS; multichain popular are Bitcoin,
|
|
159
|
-
* Solana, and Tron mainnets.
|
|
160
|
-
*
|
|
161
|
-
* @returns CAIP-2 chain IDs for popular EVM networks and multichain mainnets that are configured.
|
|
162
|
-
*/
|
|
163
|
-
export type NetworkEnablementControllerListPopularNetworksAction = {
|
|
164
|
-
type: `NetworkEnablementController:listPopularNetworks`;
|
|
165
|
-
handler: NetworkEnablementController['listPopularNetworks'];
|
|
166
|
-
};
|
|
167
|
-
/**
|
|
168
|
-
* Union of all NetworkEnablementController action types.
|
|
169
|
-
*/
|
|
170
|
-
export type NetworkEnablementControllerMethodActions = NetworkEnablementControllerEnableNetworkAction | NetworkEnablementControllerEnableNetworkInNamespaceAction | NetworkEnablementControllerEnableAllPopularNetworksAction | NetworkEnablementControllerInitAction | NetworkEnablementControllerInitNativeAssetIdentifiersAction | NetworkEnablementControllerDisableNetworkAction | NetworkEnablementControllerIsNetworkEnabledAction | NetworkEnablementControllerListPopularEvmNetworksAction | NetworkEnablementControllerListPopularMultichainNetworksAction | NetworkEnablementControllerListPopularNetworksAction;
|
|
171
|
-
//# sourceMappingURL=NetworkEnablementController-method-action-types.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkEnablementController-method-action-types.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G;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,2BAA2B,CAAC,wBAAwB,CAAC,CAAC;CAChE,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,8DAA8D,GAAG;IAC3E,IAAI,EAAE,2DAA2D,CAAC;IAClE,OAAO,EAAE,2BAA2B,CAAC,+BAA+B,CAAC,CAAC;CACvE,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,2BAA2B,CAAC,qBAAqB,CAAC,CAAC;CAC7D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wCAAwC,GAChD,8CAA8C,GAC9C,yDAAyD,GACzD,yDAAyD,GACzD,qCAAqC,GACrC,2DAA2D,GAC3D,+CAA+C,GAC/C,iDAAiD,GACjD,uDAAuD,GACvD,8DAA8D,GAC9D,oDAAoD,CAAC"}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
-
* Do not edit manually.
|
|
4
|
-
*/
|
|
5
|
-
import type { NetworkEnablementController } from "./NetworkEnablementController.mjs";
|
|
6
|
-
/**
|
|
7
|
-
* Enables or disables a network for the user.
|
|
8
|
-
*
|
|
9
|
-
* This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID
|
|
10
|
-
* (for any blockchain network). The method will automatically convert Hex chain IDs
|
|
11
|
-
* to CAIP-2 format internally. This dual parameter support allows for backward
|
|
12
|
-
* compatibility with existing EVM chain ID formats while supporting newer
|
|
13
|
-
* multi-chain standards.
|
|
14
|
-
*
|
|
15
|
-
* When enabling a non-popular network, this method will disable all other networks
|
|
16
|
-
* to ensure only one network is active at a time (exclusive mode).
|
|
17
|
-
*
|
|
18
|
-
* @param chainId - The chain ID of the network to enable or disable. Can be either:
|
|
19
|
-
* - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks
|
|
20
|
-
* - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)
|
|
21
|
-
*/
|
|
22
|
-
export type NetworkEnablementControllerEnableNetworkAction = {
|
|
23
|
-
type: `NetworkEnablementController:enableNetwork`;
|
|
24
|
-
handler: NetworkEnablementController['enableNetwork'];
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Enables a network for the user within a specific namespace.
|
|
28
|
-
*
|
|
29
|
-
* This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID
|
|
30
|
-
* (for any blockchain network) and enables it within the specified namespace.
|
|
31
|
-
* The method validates that the chainId belongs to the specified namespace for safety.
|
|
32
|
-
*
|
|
33
|
-
* Before enabling the target network, this method disables all other networks
|
|
34
|
-
* in the same namespace to ensure exclusive behavior within the namespace.
|
|
35
|
-
*
|
|
36
|
-
* @param chainId - The chain ID of the network to enable. Can be either:
|
|
37
|
-
* - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks
|
|
38
|
-
* - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)
|
|
39
|
-
* @param namespace - The CAIP namespace where the network should be enabled
|
|
40
|
-
* @throws Error if the chainId's derived namespace doesn't match the provided namespace
|
|
41
|
-
*/
|
|
42
|
-
export type NetworkEnablementControllerEnableNetworkInNamespaceAction = {
|
|
43
|
-
type: `NetworkEnablementController:enableNetworkInNamespace`;
|
|
44
|
-
handler: NetworkEnablementController['enableNetworkInNamespace'];
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Enables all popular networks and Solana mainnet.
|
|
48
|
-
*
|
|
49
|
-
* This method first disables all networks across all namespaces, then enables
|
|
50
|
-
* all networks defined in POPULAR_NETWORKS (EVM networks), Solana mainnet, and
|
|
51
|
-
* Bitcoin mainnet. This provides exclusive behavior - only popular networks will
|
|
52
|
-
* be enabled after calling this method.
|
|
53
|
-
*
|
|
54
|
-
* Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.
|
|
55
|
-
*/
|
|
56
|
-
export type NetworkEnablementControllerEnableAllPopularNetworksAction = {
|
|
57
|
-
type: `NetworkEnablementController:enableAllPopularNetworks`;
|
|
58
|
-
handler: NetworkEnablementController['enableAllPopularNetworks'];
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Initializes the network enablement state from network controller configurations.
|
|
62
|
-
*
|
|
63
|
-
* This method reads the current network configurations from both NetworkController
|
|
64
|
-
* and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.
|
|
65
|
-
* It ensures proper namespace buckets exist for all configured networks and only
|
|
66
|
-
* adds missing networks with a default value of false, preserving existing user settings.
|
|
67
|
-
*
|
|
68
|
-
* This method should be called after the NetworkController and MultichainNetworkController
|
|
69
|
-
* have been initialized and their configurations are available.
|
|
70
|
-
*/
|
|
71
|
-
export type NetworkEnablementControllerInitAction = {
|
|
72
|
-
type: `NetworkEnablementController:init`;
|
|
73
|
-
handler: NetworkEnablementController['init'];
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Initializes the native asset identifiers from network configurations.
|
|
77
|
-
* This method should be called from the client during controller initialization
|
|
78
|
-
* to populate the nativeAssetIdentifiers state based on actual network configurations.
|
|
79
|
-
*
|
|
80
|
-
* @param networks - Array of network configurations with chainId and nativeCurrency
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)
|
|
84
|
-
* .map(config => ({
|
|
85
|
-
* chainId: toEvmCaipChainId(config.chainId),
|
|
86
|
-
* nativeCurrency: config.nativeCurrency,
|
|
87
|
-
* }));
|
|
88
|
-
*
|
|
89
|
-
* const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)
|
|
90
|
-
* .map(config => ({
|
|
91
|
-
* chainId: config.chainId,
|
|
92
|
-
* nativeCurrency: config.nativeCurrency,
|
|
93
|
-
* }));
|
|
94
|
-
*
|
|
95
|
-
* await controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
export type NetworkEnablementControllerInitNativeAssetIdentifiersAction = {
|
|
99
|
-
type: `NetworkEnablementController:initNativeAssetIdentifiers`;
|
|
100
|
-
handler: NetworkEnablementController['initNativeAssetIdentifiers'];
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Disables a network for the user.
|
|
104
|
-
*
|
|
105
|
-
* This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID
|
|
106
|
-
* (for any blockchain network). The method will automatically convert Hex chain IDs
|
|
107
|
-
* to CAIP-2 format internally.
|
|
108
|
-
*
|
|
109
|
-
* Note: This method will prevent disabling the last remaining enabled network
|
|
110
|
-
* to ensure at least one network is always available.
|
|
111
|
-
*
|
|
112
|
-
* @param chainId - The chain ID of the network to disable. Can be either:
|
|
113
|
-
* - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks
|
|
114
|
-
* - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)
|
|
115
|
-
*/
|
|
116
|
-
export type NetworkEnablementControllerDisableNetworkAction = {
|
|
117
|
-
type: `NetworkEnablementController:disableNetwork`;
|
|
118
|
-
handler: NetworkEnablementController['disableNetwork'];
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* Checks if a network is enabled.
|
|
122
|
-
*
|
|
123
|
-
* @param chainId - The chain ID of the network to check. Can be either:
|
|
124
|
-
* - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks
|
|
125
|
-
* - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)
|
|
126
|
-
* @returns True if the network is enabled, false otherwise
|
|
127
|
-
*/
|
|
128
|
-
export type NetworkEnablementControllerIsNetworkEnabledAction = {
|
|
129
|
-
type: `NetworkEnablementController:isNetworkEnabled`;
|
|
130
|
-
handler: NetworkEnablementController['isNetworkEnabled'];
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Returns popular EVM network chain IDs in hex form, restricted to networks
|
|
134
|
-
* that exist in NetworkController (networkConfigurationsByChainId). Source list
|
|
135
|
-
* is POPULAR_NETWORKS.
|
|
136
|
-
*
|
|
137
|
-
* @returns Hex chain IDs for popular EVM networks that are configured.
|
|
138
|
-
*/
|
|
139
|
-
export type NetworkEnablementControllerListPopularEvmNetworksAction = {
|
|
140
|
-
type: `NetworkEnablementController:listPopularEvmNetworks`;
|
|
141
|
-
handler: NetworkEnablementController['listPopularEvmNetworks'];
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* Returns popular multichain (Bitcoin, Solana, Tron) mainnet chain IDs in
|
|
145
|
-
* CAIP-2 form, restricted to networks that exist in MultichainNetworkController
|
|
146
|
-
* (multichainNetworkConfigurationsByChainId).
|
|
147
|
-
*
|
|
148
|
-
* @returns CAIP-2 chain IDs for Bitcoin, Solana, and Tron mainnets that are configured.
|
|
149
|
-
*/
|
|
150
|
-
export type NetworkEnablementControllerListPopularMultichainNetworksAction = {
|
|
151
|
-
type: `NetworkEnablementController:listPopularMultichainNetworks`;
|
|
152
|
-
handler: NetworkEnablementController['listPopularMultichainNetworks'];
|
|
153
|
-
};
|
|
154
|
-
/**
|
|
155
|
-
* Returns the list of popular network chain IDs in CAIP-2 form, restricted to
|
|
156
|
-
* networks that exist in NetworkController (networkConfigurationsByChainId) and
|
|
157
|
-
* MultichainNetworkController (multichainNetworkConfigurationsByChainId). EVM
|
|
158
|
-
* popular networks come from POPULAR_NETWORKS; multichain popular are Bitcoin,
|
|
159
|
-
* Solana, and Tron mainnets.
|
|
160
|
-
*
|
|
161
|
-
* @returns CAIP-2 chain IDs for popular EVM networks and multichain mainnets that are configured.
|
|
162
|
-
*/
|
|
163
|
-
export type NetworkEnablementControllerListPopularNetworksAction = {
|
|
164
|
-
type: `NetworkEnablementController:listPopularNetworks`;
|
|
165
|
-
handler: NetworkEnablementController['listPopularNetworks'];
|
|
166
|
-
};
|
|
167
|
-
/**
|
|
168
|
-
* Union of all NetworkEnablementController action types.
|
|
169
|
-
*/
|
|
170
|
-
export type NetworkEnablementControllerMethodActions = NetworkEnablementControllerEnableNetworkAction | NetworkEnablementControllerEnableNetworkInNamespaceAction | NetworkEnablementControllerEnableAllPopularNetworksAction | NetworkEnablementControllerInitAction | NetworkEnablementControllerInitNativeAssetIdentifiersAction | NetworkEnablementControllerDisableNetworkAction | NetworkEnablementControllerIsNetworkEnabledAction | NetworkEnablementControllerListPopularEvmNetworksAction | NetworkEnablementControllerListPopularMultichainNetworksAction | NetworkEnablementControllerListPopularNetworksAction;
|
|
171
|
-
//# sourceMappingURL=NetworkEnablementController-method-action-types.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkEnablementController-method-action-types.d.mts","sourceRoot":"","sources":["../src/NetworkEnablementController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,2BAA2B,EAAE,0CAAsC;AAEjF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,2BAA2B,CAAC,eAAe,CAAC,CAAC;CACvD,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,yDAAyD,GAAG;IACtE,IAAI,EAAE,sDAAsD,CAAC;IAC7D,OAAO,EAAE,2BAA2B,CAAC,0BAA0B,CAAC,CAAC;CAClE,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,yDAAyD,GAAG;IACtE,IAAI,EAAE,sDAAsD,CAAC;IAC7D,OAAO,EAAE,2BAA2B,CAAC,0BAA0B,CAAC,CAAC;CAClE,CAAC;AAEF;;;;;;;;;;GAUG;A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oD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkEnablementController-method-action-types.mjs","sourceRoot":"","sources":["../src/NetworkEnablementController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { NetworkEnablementController } from './NetworkEnablementController';\n\n/**\n * Enables or disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally. This dual parameter support allows for backward\n * compatibility with existing EVM chain ID formats while supporting newer\n * multi-chain standards.\n *\n * When enabling a non-popular network, this method will disable all other networks\n * to ensure only one network is active at a time (exclusive mode).\n *\n * @param chainId - The chain ID of the network to enable or disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\nexport type NetworkEnablementControllerEnableNetworkAction = {\n type: `NetworkEnablementController:enableNetwork`;\n handler: NetworkEnablementController['enableNetwork'];\n};\n\n/**\n * Enables a network for the user within a specific namespace.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and enables it within the specified namespace.\n * The method validates that the chainId belongs to the specified namespace for safety.\n *\n * Before enabling the target network, this method disables all other networks\n * in the same namespace to ensure exclusive behavior within the namespace.\n *\n * @param chainId - The chain ID of the network to enable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @param namespace - The CAIP namespace where the network should be enabled\n * @throws Error if the chainId's derived namespace doesn't match the provided namespace\n */\nexport type NetworkEnablementControllerEnableNetworkInNamespaceAction = {\n type: `NetworkEnablementController:enableNetworkInNamespace`;\n handler: NetworkEnablementController['enableNetworkInNamespace'];\n};\n\n/**\n * Enables all popular networks and Solana mainnet.\n *\n * This method first disables all networks across all namespaces, then enables\n * all networks defined in POPULAR_NETWORKS (EVM networks), Solana mainnet, and\n * Bitcoin mainnet. This provides exclusive behavior - only popular networks will\n * be enabled after calling this method.\n *\n * Popular networks that don't exist in NetworkController or MultichainNetworkController configurations will be skipped silently.\n */\nexport type NetworkEnablementControllerEnableAllPopularNetworksAction = {\n type: `NetworkEnablementController:enableAllPopularNetworks`;\n handler: NetworkEnablementController['enableAllPopularNetworks'];\n};\n\n/**\n * Initializes the network enablement state from network controller configurations.\n *\n * This method reads the current network configurations from both NetworkController\n * and MultichainNetworkController and syncs the enabled network map and nativeAssetIdentifiers accordingly.\n * It ensures proper namespace buckets exist for all configured networks and only\n * adds missing networks with a default value of false, preserving existing user settings.\n *\n * This method should be called after the NetworkController and MultichainNetworkController\n * have been initialized and their configurations are available.\n */\nexport type NetworkEnablementControllerInitAction = {\n type: `NetworkEnablementController:init`;\n handler: NetworkEnablementController['init'];\n};\n\n/**\n * Initializes the native asset identifiers from network configurations.\n * This method should be called from the client during controller initialization\n * to populate the nativeAssetIdentifiers state based on actual network configurations.\n *\n * @param networks - Array of network configurations with chainId and nativeCurrency\n * @example\n * ```typescript\n * const evmNetworks = Object.values(networkControllerState.networkConfigurationsByChainId)\n * .map(config => ({\n * chainId: toEvmCaipChainId(config.chainId),\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * const multichainNetworks = Object.values(multichainState.multichainNetworkConfigurationsByChainId)\n * .map(config => ({\n * chainId: config.chainId,\n * nativeCurrency: config.nativeCurrency,\n * }));\n *\n * await controller.initNativeAssetIdentifiers([...evmNetworks, ...multichainNetworks]);\n * ```\n */\nexport type NetworkEnablementControllerInitNativeAssetIdentifiersAction = {\n type: `NetworkEnablementController:initNativeAssetIdentifiers`;\n handler: NetworkEnablementController['initNativeAssetIdentifiers'];\n};\n\n/**\n * Disables a network for the user.\n *\n * This method accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network). The method will automatically convert Hex chain IDs\n * to CAIP-2 format internally.\n *\n * Note: This method will prevent disabling the last remaining enabled network\n * to ensure at least one network is always available.\n *\n * @param chainId - The chain ID of the network to disable. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n */\nexport type NetworkEnablementControllerDisableNetworkAction = {\n type: `NetworkEnablementController:disableNetwork`;\n handler: NetworkEnablementController['disableNetwork'];\n};\n\n/**\n * Checks if a network is enabled.\n *\n * @param chainId - The chain ID of the network to check. Can be either:\n * - A Hex string (e.g., '0x1' for Ethereum mainnet) for EVM networks\n * - A CAIP-2 chain ID (e.g., 'eip155:1' for Ethereum mainnet, 'solana:mainnet' for Solana)\n * @returns True if the network is enabled, false otherwise\n */\nexport type NetworkEnablementControllerIsNetworkEnabledAction = {\n type: `NetworkEnablementController:isNetworkEnabled`;\n handler: NetworkEnablementController['isNetworkEnabled'];\n};\n\n/**\n * Returns popular EVM network chain IDs in hex form, restricted to networks\n * that exist in NetworkController (networkConfigurationsByChainId). Source list\n * is POPULAR_NETWORKS.\n *\n * @returns Hex chain IDs for popular EVM networks that are configured.\n */\nexport type NetworkEnablementControllerListPopularEvmNetworksAction = {\n type: `NetworkEnablementController:listPopularEvmNetworks`;\n handler: NetworkEnablementController['listPopularEvmNetworks'];\n};\n\n/**\n * Returns popular multichain (Bitcoin, Solana, Tron) mainnet chain IDs in\n * CAIP-2 form, restricted to networks that exist in MultichainNetworkController\n * (multichainNetworkConfigurationsByChainId).\n *\n * @returns CAIP-2 chain IDs for Bitcoin, Solana, and Tron mainnets that are configured.\n */\nexport type NetworkEnablementControllerListPopularMultichainNetworksAction = {\n type: `NetworkEnablementController:listPopularMultichainNetworks`;\n handler: NetworkEnablementController['listPopularMultichainNetworks'];\n};\n\n/**\n * Returns the list of popular network chain IDs in CAIP-2 form, restricted to\n * networks that exist in NetworkController (networkConfigurationsByChainId) and\n * MultichainNetworkController (multichainNetworkConfigurationsByChainId). EVM\n * popular networks come from POPULAR_NETWORKS; multichain popular are Bitcoin,\n * Solana, and Tron mainnets.\n *\n * @returns CAIP-2 chain IDs for popular EVM networks and multichain mainnets that are configured.\n */\nexport type NetworkEnablementControllerListPopularNetworksAction = {\n type: `NetworkEnablementController:listPopularNetworks`;\n handler: NetworkEnablementController['listPopularNetworks'];\n};\n\n/**\n * Union of all NetworkEnablementController action types.\n */\nexport type NetworkEnablementControllerMethodActions =\n | NetworkEnablementControllerEnableNetworkAction\n | NetworkEnablementControllerEnableNetworkInNamespaceAction\n | NetworkEnablementControllerEnableAllPopularNetworksAction\n | NetworkEnablementControllerInitAction\n | NetworkEnablementControllerInitNativeAssetIdentifiersAction\n | NetworkEnablementControllerDisableNetworkAction\n | NetworkEnablementControllerIsNetworkEnabledAction\n | NetworkEnablementControllerListPopularEvmNetworksAction\n | NetworkEnablementControllerListPopularMultichainNetworksAction\n | NetworkEnablementControllerListPopularNetworksAction;\n"]}
|