@metamask-previews/network-enablement-controller 5.6.0-preview-ec4680201 → 5.6.0-preview-40d5fb1e2
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 -6
- package/dist/NetworkEnablementController-method-action-types.cjs.map +1 -1
- package/dist/NetworkEnablementController-method-action-types.d.cts +2 -2
- package/dist/NetworkEnablementController-method-action-types.d.cts.map +1 -1
- package/dist/NetworkEnablementController-method-action-types.d.mts +2 -2
- package/dist/NetworkEnablementController-method-action-types.d.mts.map +1 -1
- package/dist/NetworkEnablementController-method-action-types.mjs.map +1 -1
- package/dist/NetworkEnablementController.cjs +30 -50
- package/dist/NetworkEnablementController.cjs.map +1 -1
- package/dist/NetworkEnablementController.d.cts +3 -4
- package/dist/NetworkEnablementController.d.cts.map +1 -1
- package/dist/NetworkEnablementController.d.mts +3 -4
- package/dist/NetworkEnablementController.d.mts.map +1 -1
- package/dist/NetworkEnablementController.mjs +10 -30
- package/dist/NetworkEnablementController.mjs.map +1 -1
- package/dist/index.cjs +14 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.cjs +2 -2
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs.map +1 -1
- package/dist/services/index.cjs +4 -4
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts.map +1 -1
- package/dist/services/index.d.mts.map +1 -1
- package/dist/services/index.mjs.map +1 -1
- package/dist/utils.cjs +19 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -0
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +7 -0
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +17 -0
- package/dist/utils.mjs.map +1 -1
- package/package.json +7 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NetworkEnablementController.mjs","sourceRoot":"","sources":["../src/NetworkEnablementController.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAM3D,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,KAAK,EAAE,mCAAmC;AAChF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,8BAA8B;AAG/E,OAAO,EAAE,gBAAgB,EAAE,gDAAgD;AAS3E,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,wBAAwB;AAEvE,OAAO,EAAE,gBAAgB,EAAE,wBAAuB;AAElD,OAAO,EAAE,aAAa,EAAE,6BAA4B;AACpD,OAAO,EAAE,UAAU,EAAE,+BAA+B,EAAE,oBAAmB;AAEzE,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;AAwFX;;;;;;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,WAA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AAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACpD,GAAG,uBAAA,IAAI,0GAA+B,MAAnC,IAAI,CAAiC;SACzC,CAAC;KACH,CAAC;AACJ,CAAC","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport type { ConfigRegistryControllerGetStateAction } from '@metamask/config-registry-controller';\nimport { BuiltInNetworkName, ChainId, toHex } from '@metamask/controller-utils';\nimport { BtcScope, SolScope, TrxScope, XlmScope } 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, parseCaipChainId } from '@metamask/utils';\n\nimport { POPULAR_NETWORKS } from './constants.js';\nimport type { NetworkEnablementControllerMethodActions } from './NetworkEnablementController-method-action-types.js';\nimport { Slip44Service } from './services/index.js';\nimport { deriveKeys, isOnlyNetworkEnabledInNamespace } from './utils.js';\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 | ConfigRegistryControllerGetStateAction;\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 [ChainId[BuiltInNetworkName.MonadMainnet]]: 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 [KnownCaipNamespace.Stellar]: {\n [XlmScope.Pubnet]: true,\n [XlmScope.Testnet]: 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 this.#getPopularEvmChainIds().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 // Enable Stellar mainnet if it exists in MultichainNetworkController configurations\n const stellarKeys = deriveKeys(XlmScope.Pubnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n XlmScope.Pubnet\n ]\n ) {\n this.#ensureNamespaceBucket(state, stellarKeys.namespace);\n state.enabledNetworkMap[stellarKeys.namespace][stellarKeys.storageKey] =\n 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 * Restores the enabled network map to a previously snapshotted state.\n *\n * Not a general merge API: only updates keys already present in the current\n * map. Missing snapshot values default to `false`. Intended for callers with\n * direct controller access (e.g. extension) to undo `#onAddNetwork` filter\n * switches when adding a network without changing the active selection.\n *\n * @param enabledNetworkMap - Previously snapshotted enabledNetworkMap.\n */\n restoreEnabledNetworkMap(\n enabledNetworkMap: NetworkEnablementControllerState['enabledNetworkMap'],\n ): void {\n this.update((state) => {\n Object.entries(state.enabledNetworkMap).forEach(\n ([namespace, currentNetworks]) => {\n Object.keys(currentNetworks).forEach((chainId) => {\n const storageKey = chainId as CaipChainId | Hex;\n const previousValue = enabledNetworkMap[namespace]?.[storageKey];\n state.enabledNetworkMap[namespace][storageKey] =\n previousValue ?? false;\n });\n },\n );\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 = this.#getPopularEvmChainIds().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 =\n this.#getPopularEvmChainIds().includes(chainId);\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 the hex chain IDs of EVM networks the config registry currently\n * marks as \"popular\" (i.e. featured + active + non-testnet).\n *\n * @returns Hex chain IDs of registry-featured EVM networks.\n */\n #getRegistryPopularEvmChainIds(): Hex[] {\n const {\n configs: { networks },\n } = this.messenger.call('ConfigRegistryController:getState');\n return Object.values(networks).reduce<Hex[]>((popularChains, network) => {\n if (\n network.config.isFeatured &&\n network.config.isActive &&\n !network.config.isTestnet &&\n network.chainId.startsWith('eip155:')\n ) {\n const hexChainId = toHex(parseCaipChainId(network.chainId).reference);\n popularChains.push(hexChainId);\n }\n return popularChains;\n }, []);\n }\n\n /**\n * Returns the set of popular EVM chain IDs using registry configs as primary source\n * and the bundled `POPULAR_NETWORKS` as fallback. This ensures that the list of popular networks is always available,\n * even if the registry is unavailable or doesn't have any featured networks.\n *\n * @returns De-duplicated hex chain IDs considered popular.\n */\n #getPopularEvmChainIds(): Hex[] {\n return [\n ...new Set<Hex>([\n // `toHex` is used to normalize chain IDs from the bundled POPULAR_NETWORKS.\n ...POPULAR_NETWORKS.map((chainId) => toHex(chainId)),\n ...this.#getRegistryPopularEvmChainIds(),\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 is\n * the bundled `POPULAR_NETWORKS` unioned with registry-featured EVM chains.\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 this.#getPopularEvmChainIds().filter(\n (chainIdHex) =>\n networkControllerState.networkConfigurationsByChainId[chainIdHex],\n );\n }\n\n /**\n * Returns popular multichain (Bitcoin, Solana, Tron, Stellar) 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, Tron, and Stellar 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 XlmScope.Pubnet,\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, Tron, and Stellar 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,QAAQ,EAAE,8BAA8B;AAG/E,OAAO,EAAE,gBAAgB,EAAE,gDAAgD;AAS3E,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,gBAAgB,EAAE,wBAAoB;AAE/C,OAAO,EAAE,aAAa,EAAE,6BAAmB;AAC3C,OAAO,EACL,UAAU,EACV,+BAA+B,EAC/B,gBAAgB,EACjB,oBAAgB;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;IACx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,GAC9B,qBAAqB,IAAI,qBAAqB,CAAC;QAEjD,IAAI,0BAA0B,EAAE,CAAC;YAC/B,uEAAuE;YACvE,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;QACxD,CAAC;aAAM,CAAC;YACN,0EAA0E;YAC1E,MAAM,CAAC,IAAI,CAAC,KAAK,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, XlmScope } 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 [ChainId[BuiltInNetworkName.MonadMainnet]]: 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 [KnownCaipNamespace.Stellar]: {\n [XlmScope.Pubnet]: true,\n [XlmScope.Testnet]: 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 // Enable Stellar mainnet if it exists in MultichainNetworkController configurations\n const stellarKeys = deriveKeys(XlmScope.Pubnet as CaipChainId);\n if (\n multichainState.multichainNetworkConfigurationsByChainId[\n XlmScope.Pubnet\n ]\n ) {\n this.#ensureNamespaceBucket(state, stellarKeys.namespace);\n state.enabledNetworkMap[stellarKeys.namespace][stellarKeys.storageKey] =\n 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 * Restores the enabled network map to a previously snapshotted state.\n *\n * Not a general merge API: only updates keys already present in the current\n * map. Missing snapshot values default to `false`. Intended for callers with\n * direct controller access (e.g. extension) to undo `#onAddNetwork` filter\n * switches when adding a network without changing the active selection.\n *\n * @param enabledNetworkMap - Previously snapshotted enabledNetworkMap.\n */\n restoreEnabledNetworkMap(\n enabledNetworkMap: NetworkEnablementControllerState['enabledNetworkMap'],\n ): void {\n this.update((state) => {\n Object.entries(state.enabledNetworkMap).forEach(\n ([namespace, currentNetworks]) => {\n Object.keys(currentNetworks).forEach((chainId) => {\n const storageKey = chainId as CaipChainId | Hex;\n const previousValue = enabledNetworkMap[namespace]?.[storageKey];\n state.enabledNetworkMap[namespace][storageKey] =\n previousValue ?? false;\n });\n },\n );\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, Stellar) 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, Tron, and Stellar 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 XlmScope.Pubnet,\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, Tron, and Stellar 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
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSlip44BySymbol = exports.getEvmSlip44 = exports.Slip44Service = exports.selectEnabledSolanaNetworks = exports.selectEnabledEvmNetworks = exports.selectEnabledNetworksCount = exports.selectAllEnabledNetworks = exports.createSelectorForEnabledNetworksForNamespace = exports.selectIsNetworkEnabled = exports.selectEnabledNetworkMap = exports.NetworkEnablementController = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "NetworkEnablementController", { enumerable: true, get: function () { return
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "selectEnabledNetworkMap", { enumerable: true, get: function () { return
|
|
8
|
-
Object.defineProperty(exports, "selectIsNetworkEnabled", { enumerable: true, get: function () { return
|
|
9
|
-
Object.defineProperty(exports, "createSelectorForEnabledNetworksForNamespace", { enumerable: true, get: function () { return
|
|
10
|
-
Object.defineProperty(exports, "selectAllEnabledNetworks", { enumerable: true, get: function () { return
|
|
11
|
-
Object.defineProperty(exports, "selectEnabledNetworksCount", { enumerable: true, get: function () { return
|
|
12
|
-
Object.defineProperty(exports, "selectEnabledEvmNetworks", { enumerable: true, get: function () { return
|
|
13
|
-
Object.defineProperty(exports, "selectEnabledSolanaNetworks", { enumerable: true, get: function () { return
|
|
14
|
-
var
|
|
15
|
-
Object.defineProperty(exports, "Slip44Service", { enumerable: true, get: function () { return
|
|
16
|
-
Object.defineProperty(exports, "getEvmSlip44", { enumerable: true, get: function () { return
|
|
17
|
-
Object.defineProperty(exports, "getSlip44BySymbol", { enumerable: true, get: function () { return
|
|
4
|
+
var NetworkEnablementController_1 = require("./NetworkEnablementController.cjs");
|
|
5
|
+
Object.defineProperty(exports, "NetworkEnablementController", { enumerable: true, get: function () { return NetworkEnablementController_1.NetworkEnablementController; } });
|
|
6
|
+
var selectors_1 = require("./selectors.cjs");
|
|
7
|
+
Object.defineProperty(exports, "selectEnabledNetworkMap", { enumerable: true, get: function () { return selectors_1.selectEnabledNetworkMap; } });
|
|
8
|
+
Object.defineProperty(exports, "selectIsNetworkEnabled", { enumerable: true, get: function () { return selectors_1.selectIsNetworkEnabled; } });
|
|
9
|
+
Object.defineProperty(exports, "createSelectorForEnabledNetworksForNamespace", { enumerable: true, get: function () { return selectors_1.createSelectorForEnabledNetworksForNamespace; } });
|
|
10
|
+
Object.defineProperty(exports, "selectAllEnabledNetworks", { enumerable: true, get: function () { return selectors_1.selectAllEnabledNetworks; } });
|
|
11
|
+
Object.defineProperty(exports, "selectEnabledNetworksCount", { enumerable: true, get: function () { return selectors_1.selectEnabledNetworksCount; } });
|
|
12
|
+
Object.defineProperty(exports, "selectEnabledEvmNetworks", { enumerable: true, get: function () { return selectors_1.selectEnabledEvmNetworks; } });
|
|
13
|
+
Object.defineProperty(exports, "selectEnabledSolanaNetworks", { enumerable: true, get: function () { return selectors_1.selectEnabledSolanaNetworks; } });
|
|
14
|
+
var services_1 = require("./services/index.cjs");
|
|
15
|
+
Object.defineProperty(exports, "Slip44Service", { enumerable: true, get: function () { return services_1.Slip44Service; } });
|
|
16
|
+
Object.defineProperty(exports, "getEvmSlip44", { enumerable: true, get: function () { return services_1.getEvmSlip44; } });
|
|
17
|
+
Object.defineProperty(exports, "getSlip44BySymbol", { enumerable: true, get: function () { return services_1.getSlip44BySymbol; } });
|
|
18
18
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iFAA4E;AAAnE,0IAAA,2BAA2B,OAAA;AA2BpC,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 NetworkEnablementControllerStateChangeEvent,\n NetworkEnablementControllerMessenger,\n NativeAssetIdentifier,\n NativeAssetIdentifiersMap,\n NetworkConfig,\n} from './NetworkEnablementController';\n\nexport type {\n NetworkEnablementControllerEnableNetworkAction,\n NetworkEnablementControllerEnableNetworkInNamespaceAction,\n NetworkEnablementControllerEnableAllPopularNetworksAction,\n NetworkEnablementControllerInitAction,\n NetworkEnablementControllerInitNativeAssetIdentifiersAction,\n NetworkEnablementControllerDisableNetworkAction,\n NetworkEnablementControllerIsNetworkEnabledAction,\n NetworkEnablementControllerListPopularEvmNetworksAction,\n NetworkEnablementControllerListPopularMultichainNetworksAction,\n NetworkEnablementControllerListPopularNetworksAction,\n} from './NetworkEnablementController-method-action-types';\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
|
@@ -2,5 +2,5 @@ export { NetworkEnablementController } from "./NetworkEnablementController.cjs";
|
|
|
2
2
|
export type { NetworkEnablementControllerState, NetworkEnablementControllerGetStateAction, NetworkEnablementControllerActions, NetworkEnablementControllerEvents, NetworkEnablementControllerStateChangeEvent, NetworkEnablementControllerMessenger, NativeAssetIdentifier, NativeAssetIdentifiersMap, NetworkConfig, } from "./NetworkEnablementController.cjs";
|
|
3
3
|
export type { NetworkEnablementControllerEnableNetworkAction, NetworkEnablementControllerEnableNetworkInNamespaceAction, NetworkEnablementControllerEnableAllPopularNetworksAction, NetworkEnablementControllerInitAction, NetworkEnablementControllerInitNativeAssetIdentifiersAction, NetworkEnablementControllerDisableNetworkAction, NetworkEnablementControllerIsNetworkEnabledAction, NetworkEnablementControllerListPopularEvmNetworksAction, NetworkEnablementControllerListPopularMultichainNetworksAction, NetworkEnablementControllerListPopularNetworksAction, } from "./NetworkEnablementController-method-action-types.cjs";
|
|
4
4
|
export { selectEnabledNetworkMap, selectIsNetworkEnabled, createSelectorForEnabledNetworksForNamespace, selectAllEnabledNetworks, selectEnabledNetworksCount, selectEnabledEvmNetworks, selectEnabledSolanaNetworks, } from "./selectors.cjs";
|
|
5
|
-
export { Slip44Service, getEvmSlip44, getSlip44BySymbol
|
|
5
|
+
export { Slip44Service, getEvmSlip44, getSlip44BySymbol } from "./services/index.cjs";
|
|
6
6
|
//# 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,
|
|
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,2CAA2C,EAC3C,oCAAoC,EACpC,qBAAqB,EACrB,yBAAyB,EACzB,aAAa,GACd,0CAAsC;AAEvC,YAAY,EACV,8CAA8C,EAC9C,yDAAyD,EACzD,yDAAyD,EACzD,qCAAqC,EACrC,2DAA2D,EAC3D,+CAA+C,EAC/C,iDAAiD,EACjD,uDAAuD,EACvD,8DAA8D,EAC9D,oDAAoD,GACrD,8DAA0D;AAE3D,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
|
@@ -2,5 +2,5 @@ export { NetworkEnablementController } from "./NetworkEnablementController.mjs";
|
|
|
2
2
|
export type { NetworkEnablementControllerState, NetworkEnablementControllerGetStateAction, NetworkEnablementControllerActions, NetworkEnablementControllerEvents, NetworkEnablementControllerStateChangeEvent, NetworkEnablementControllerMessenger, NativeAssetIdentifier, NativeAssetIdentifiersMap, NetworkConfig, } from "./NetworkEnablementController.mjs";
|
|
3
3
|
export type { NetworkEnablementControllerEnableNetworkAction, NetworkEnablementControllerEnableNetworkInNamespaceAction, NetworkEnablementControllerEnableAllPopularNetworksAction, NetworkEnablementControllerInitAction, NetworkEnablementControllerInitNativeAssetIdentifiersAction, NetworkEnablementControllerDisableNetworkAction, NetworkEnablementControllerIsNetworkEnabledAction, NetworkEnablementControllerListPopularEvmNetworksAction, NetworkEnablementControllerListPopularMultichainNetworksAction, NetworkEnablementControllerListPopularNetworksAction, } from "./NetworkEnablementController-method-action-types.mjs";
|
|
4
4
|
export { selectEnabledNetworkMap, selectIsNetworkEnabled, createSelectorForEnabledNetworksForNamespace, selectAllEnabledNetworks, selectEnabledNetworksCount, selectEnabledEvmNetworks, selectEnabledSolanaNetworks, } from "./selectors.mjs";
|
|
5
|
-
export { Slip44Service, getEvmSlip44, getSlip44BySymbol
|
|
5
|
+
export { Slip44Service, getEvmSlip44, getSlip44BySymbol } from "./services/index.mjs";
|
|
6
6
|
//# 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,
|
|
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,2CAA2C,EAC3C,oCAAoC,EACpC,qBAAqB,EACrB,yBAAyB,EACzB,aAAa,GACd,0CAAsC;AAEvC,YAAY,EACV,8CAA8C,EAC9C,yDAAyD,EACzD,yDAAyD,EACzD,qCAAqC,EACrC,2DAA2D,EAC3D,+CAA+C,EAC/C,iDAAiD,EACjD,uDAAuD,EACvD,8DAA8D,EAC9D,oDAAoD,GACrD,8DAA0D;AAE3D,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,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,0CAAsC;AA2B5E,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 NetworkEnablementControllerStateChangeEvent,\n NetworkEnablementControllerMessenger,\n NativeAssetIdentifier,\n NativeAssetIdentifiersMap,\n NetworkConfig,\n} from './NetworkEnablementController';\n\nexport type {\n NetworkEnablementControllerEnableNetworkAction,\n NetworkEnablementControllerEnableNetworkInNamespaceAction,\n NetworkEnablementControllerEnableAllPopularNetworksAction,\n NetworkEnablementControllerInitAction,\n NetworkEnablementControllerInitNativeAssetIdentifiersAction,\n NetworkEnablementControllerDisableNetworkAction,\n NetworkEnablementControllerIsNetworkEnabledAction,\n NetworkEnablementControllerListPopularEvmNetworksAction,\n NetworkEnablementControllerListPopularMultichainNetworksAction,\n NetworkEnablementControllerListPopularNetworksAction,\n} from './NetworkEnablementController-method-action-types';\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/selectors.cjs
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.selectEnabledSolanaNetworks = exports.selectEnabledEvmNetworks = exports.selectEnabledNetworksCount = exports.selectAllEnabledNetworks = exports.createSelectorForEnabledNetworksForNamespace = exports.selectIsNetworkEnabled = exports.selectEnabledNetworkMap = void 0;
|
|
4
4
|
const utils_1 = require("@metamask/utils");
|
|
5
5
|
const reselect_1 = require("reselect");
|
|
6
|
-
const
|
|
6
|
+
const utils_2 = require("./utils.cjs");
|
|
7
7
|
/**
|
|
8
8
|
* Base selector to get the enabled network map from the controller state.
|
|
9
9
|
*
|
|
@@ -23,7 +23,7 @@ exports.selectEnabledNetworkMap = selectEnabledNetworkMap;
|
|
|
23
23
|
* @returns A selector function that returns true if the network is enabled, false otherwise
|
|
24
24
|
*/
|
|
25
25
|
const selectIsNetworkEnabled = (chainId) => (0, reselect_1.createSelector)(exports.selectEnabledNetworkMap, (enabledNetworkMap) => {
|
|
26
|
-
const { namespace, storageKey } = (0,
|
|
26
|
+
const { namespace, storageKey } = (0, utils_2.deriveKeys)(chainId);
|
|
27
27
|
return (namespace in enabledNetworkMap &&
|
|
28
28
|
storageKey in enabledNetworkMap[namespace] &&
|
|
29
29
|
enabledNetworkMap[namespace][storageKey]);
|
package/dist/selectors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;AACA,2CAAqD;AACrD,uCAA0C;AAG1C,
|
|
1
|
+
{"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;AACA,2CAAqD;AACrD,uCAA0C;AAG1C,uCAAqC;AAErC;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,KAAuC,EACvC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC;AAFhB,QAAA,uBAAuB,2BAEP;AAE7B;;;;;;;;;GASG;AACI,MAAM,sBAAsB,GAAG,CAAC,OAA0B,EAAE,EAAE,CACnE,IAAA,yBAAc,EAAC,+BAAuB,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C;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC,CACF,CAAC;AAEF;;;;GAIG;AACU,QAAA,0BAA0B,GAAG,IAAA,yBAAc,EACtD,gCAAwB,EACxB,CAAC,kBAAkB,EAAE,EAAE;IACrB,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC;AACzD,CAAC,CACF,CAAC;AAEF;;;;;;GAMG;AACU,QAAA,wBAAwB,GAAG,IAAA,yBAAc,EACpD,IAAA,oDAA4C,EAAC,0BAAkB,CAAC,MAAM,CAAC,EACvE,CAAC,kBAAkB,EAAE,EAAE,CAAC,kBAAkB,CAC3C,CAAC;AAEF;;;;;;GAMG;AACU,QAAA,2BAA2B,GAAG,IAAA,yBAAc,EACvD,IAAA,oDAA4C,EAAC,0BAAkB,CAAC,MAAM,CAAC,EACvE,CAAC,qBAAqB,EAAE,EAAE,CAAC,qBAAqB,CACjD,CAAC","sourcesContent":["import type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';\nimport { KnownCaipNamespace } from '@metamask/utils';\nimport { createSelector } from 'reselect';\n\nimport type { NetworkEnablementControllerState } from './NetworkEnablementController';\nimport { deriveKeys } from './utils';\n\n/**\n * Base selector to get the enabled network map from the controller state.\n *\n * @param state - The NetworkEnablementController state\n * @returns The enabled network map\n */\nexport const selectEnabledNetworkMap = (\n state: NetworkEnablementControllerState,\n) => state.enabledNetworkMap;\n\n/**\n * Selector to check if a specific network is enabled.\n *\n * This selector accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and returns whether the network is currently enabled.\n * It returns false for unknown networks or if there's an error parsing the chain ID.\n *\n * @param chainId - The chain ID to check (Hex or CAIP-2 format)\n * @returns A selector function that returns true if the network is enabled, false otherwise\n */\nexport const selectIsNetworkEnabled = (chainId: Hex | CaipChainId) =>\n createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n return (\n namespace in enabledNetworkMap &&\n storageKey in enabledNetworkMap[namespace] &&\n enabledNetworkMap[namespace][storageKey]\n );\n });\n\n/**\n * Selector builder to get all enabled networks for a specific namespace.\n *\n * The selector returned by this function returns an array of chain IDs (as strings) for all enabled networks\n * within the specified namespace (e.g., 'eip155' for EVM networks, 'solana' for Solana).\n *\n * @param namespace - The CAIP namespace to get enabled networks for (e.g., 'eip155', 'solana')\n * @returns A selector function that returns an array of chain ID strings for enabled networks in the namespace\n */\nexport const createSelectorForEnabledNetworksForNamespace = (\n namespace: CaipNamespace,\n) =>\n createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {\n return Object.entries(enabledNetworkMap[namespace] ?? {})\n .filter(([, enabled]) => enabled)\n .map(([id]) => id);\n });\n\n/**\n * Selector to get all enabled networks across all namespaces.\n *\n * This selector returns a record where keys are CAIP namespaces and values are arrays\n * of enabled chain IDs within each namespace.\n *\n * @returns A selector function that returns a record mapping namespace to array of enabled chain IDs\n */\nexport const selectAllEnabledNetworks = createSelector(\n selectEnabledNetworkMap,\n (enabledNetworkMap) => {\n return Object.keys(enabledNetworkMap).reduce<\n Record<CaipNamespace, string[]>\n >((acc, ns) => {\n acc[ns] = Object.entries(enabledNetworkMap[ns])\n .filter(([, enabled]) => enabled)\n .map(([id]) => id);\n return acc;\n }, {});\n },\n);\n\n/**\n * Selector to get the total count of enabled networks across all namespaces.\n *\n * @returns A selector function that returns the total number of enabled networks\n */\nexport const selectEnabledNetworksCount = createSelector(\n selectAllEnabledNetworks,\n (allEnabledNetworks) => {\n return Object.values(allEnabledNetworks).flat().length;\n },\n);\n\n/**\n * Selector to get all enabled EVM networks.\n *\n * This is a convenience selector that specifically targets EIP-155 networks.\n *\n * @returns A selector function that returns an array of enabled EVM chain IDs\n */\nexport const selectEnabledEvmNetworks = createSelector(\n createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Eip155),\n (enabledEvmNetworks) => enabledEvmNetworks,\n);\n\n/**\n * Selector to get all enabled Solana networks.\n *\n * This is a convenience selector that specifically targets Solana networks.\n *\n * @returns A selector function that returns an array of enabled Solana chain IDs\n */\nexport const selectEnabledSolanaNetworks = createSelector(\n createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Solana),\n (enabledSolanaNetworks) => enabledSolanaNetworks,\n);\n"]}
|
package/dist/selectors.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,
|
|
1
|
+
{"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,0CAAsC;AAGtF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,UAC3B,gCAAgC;;CACb,CAAC;AAE7B;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,YAAa,GAAG,GAAG,WAAW;;;;;;;;;;;;;;;;2BAbxD,gCAAgC;;;;;;;;;;CAsBrC,CAAC;AAEL;;;;;;;;GAQG;AACH,eAAO,MAAM,4CAA4C,cAC5C,aAAa;;;;;;;;;;;;;;;;2BAlCjB,gCAAgC;;;;;;;;;;CAwCrC,CAAC;AAEL;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;2BAlD5B,gCAAgC;;;;;;;;;;CA8DxC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BArE9B,gCAAgC;;;;;;;;;;;;;;;;;;CA0ExC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAnF5B,gCAAgC;;;;;;;;;;;;;;;;;;CAsFxC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BA/F/B,gCAAgC;;;;;;;;;;;;;;;;;;CAkGxC,CAAC"}
|
package/dist/selectors.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,
|
|
1
|
+
{"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAIvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,0CAAsC;AAGtF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,UAC3B,gCAAgC;;CACb,CAAC;AAE7B;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,YAAa,GAAG,GAAG,WAAW;;;;;;;;;;;;;;;;2BAbxD,gCAAgC;;;;;;;;;;CAsBrC,CAAC;AAEL;;;;;;;;GAQG;AACH,eAAO,MAAM,4CAA4C,cAC5C,aAAa;;;;;;;;;;;;;;;;2BAlCjB,gCAAgC;;;;;;;;;;CAwCrC,CAAC;AAEL;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;2BAlD5B,gCAAgC;;;;;;;;;;CA8DxC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BArE9B,gCAAgC;;;;;;;;;;;;;;;;;;CA0ExC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BAnF5B,gCAAgC;;;;;;;;;;;;;;;;;;CAsFxC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;+BA/F/B,gCAAgC;;;;;;;;;;;;;;;;;;CAkGxC,CAAC"}
|
package/dist/selectors.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,OAAO,EAAE,cAAc,EAAE,iBAAiB;AAG1C,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,OAAO,EAAE,cAAc,EAAE,iBAAiB;AAG1C,OAAO,EAAE,UAAU,EAAE,oBAAgB;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,KAAuC,EACvC,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC;AAE7B;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAA0B,EAAE,EAAE,CACnE,cAAc,CAAC,uBAAuB,EAAE,CAAC,iBAAiB,EAAE,EAAE;IAC5D,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAEtD,OAAO,CACL,SAAS,IAAI,iBAAiB;QAC9B,UAAU,IAAI,iBAAiB,CAAC,SAAS,CAAC;QAC1C,iBAAiB,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,CACzC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEL;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,4CAA4C,GAAG,CAC1D,SAAwB,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E,CAAC,kBAAkB,CAC3C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,cAAc,CACvD,4CAA4C,CAAC,kBAAkB,CAAC,MAAM,CAAC,EACvE,CAAC,qBAAqB,EAAE,EAAE,CAAC,qBAAqB,CACjD,CAAC","sourcesContent":["import type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';\nimport { KnownCaipNamespace } from '@metamask/utils';\nimport { createSelector } from 'reselect';\n\nimport type { NetworkEnablementControllerState } from './NetworkEnablementController';\nimport { deriveKeys } from './utils';\n\n/**\n * Base selector to get the enabled network map from the controller state.\n *\n * @param state - The NetworkEnablementController state\n * @returns The enabled network map\n */\nexport const selectEnabledNetworkMap = (\n state: NetworkEnablementControllerState,\n) => state.enabledNetworkMap;\n\n/**\n * Selector to check if a specific network is enabled.\n *\n * This selector accepts either a Hex chain ID (for EVM networks) or a CAIP-2 chain ID\n * (for any blockchain network) and returns whether the network is currently enabled.\n * It returns false for unknown networks or if there's an error parsing the chain ID.\n *\n * @param chainId - The chain ID to check (Hex or CAIP-2 format)\n * @returns A selector function that returns true if the network is enabled, false otherwise\n */\nexport const selectIsNetworkEnabled = (chainId: Hex | CaipChainId) =>\n createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {\n const { namespace, storageKey } = deriveKeys(chainId);\n\n return (\n namespace in enabledNetworkMap &&\n storageKey in enabledNetworkMap[namespace] &&\n enabledNetworkMap[namespace][storageKey]\n );\n });\n\n/**\n * Selector builder to get all enabled networks for a specific namespace.\n *\n * The selector returned by this function returns an array of chain IDs (as strings) for all enabled networks\n * within the specified namespace (e.g., 'eip155' for EVM networks, 'solana' for Solana).\n *\n * @param namespace - The CAIP namespace to get enabled networks for (e.g., 'eip155', 'solana')\n * @returns A selector function that returns an array of chain ID strings for enabled networks in the namespace\n */\nexport const createSelectorForEnabledNetworksForNamespace = (\n namespace: CaipNamespace,\n) =>\n createSelector(selectEnabledNetworkMap, (enabledNetworkMap) => {\n return Object.entries(enabledNetworkMap[namespace] ?? {})\n .filter(([, enabled]) => enabled)\n .map(([id]) => id);\n });\n\n/**\n * Selector to get all enabled networks across all namespaces.\n *\n * This selector returns a record where keys are CAIP namespaces and values are arrays\n * of enabled chain IDs within each namespace.\n *\n * @returns A selector function that returns a record mapping namespace to array of enabled chain IDs\n */\nexport const selectAllEnabledNetworks = createSelector(\n selectEnabledNetworkMap,\n (enabledNetworkMap) => {\n return Object.keys(enabledNetworkMap).reduce<\n Record<CaipNamespace, string[]>\n >((acc, ns) => {\n acc[ns] = Object.entries(enabledNetworkMap[ns])\n .filter(([, enabled]) => enabled)\n .map(([id]) => id);\n return acc;\n }, {});\n },\n);\n\n/**\n * Selector to get the total count of enabled networks across all namespaces.\n *\n * @returns A selector function that returns the total number of enabled networks\n */\nexport const selectEnabledNetworksCount = createSelector(\n selectAllEnabledNetworks,\n (allEnabledNetworks) => {\n return Object.values(allEnabledNetworks).flat().length;\n },\n);\n\n/**\n * Selector to get all enabled EVM networks.\n *\n * This is a convenience selector that specifically targets EIP-155 networks.\n *\n * @returns A selector function that returns an array of enabled EVM chain IDs\n */\nexport const selectEnabledEvmNetworks = createSelector(\n createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Eip155),\n (enabledEvmNetworks) => enabledEvmNetworks,\n);\n\n/**\n * Selector to get all enabled Solana networks.\n *\n * This is a convenience selector that specifically targets Solana networks.\n *\n * @returns A selector function that returns an array of enabled Solana chain IDs\n */\nexport const selectEnabledSolanaNetworks = createSelector(\n createSelectorForEnabledNetworksForNamespace(KnownCaipNamespace.Solana),\n (enabledSolanaNetworks) => enabledSolanaNetworks,\n);\n"]}
|
package/dist/services/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSlip44BySymbol = exports.getEvmSlip44 = exports.Slip44Service = void 0;
|
|
4
|
-
const
|
|
5
|
-
Object.defineProperty(exports, "Slip44Service", { enumerable: true, get: function () { return
|
|
4
|
+
const Slip44Service_1 = require("./Slip44Service.cjs");
|
|
5
|
+
Object.defineProperty(exports, "Slip44Service", { enumerable: true, get: function () { return Slip44Service_1.Slip44Service; } });
|
|
6
6
|
// Re-export static methods as standalone functions for convenience
|
|
7
7
|
// getEvmSlip44: For EVM networks (eip155) - uses chainId lookup, defaults to 60
|
|
8
|
-
exports.getEvmSlip44 =
|
|
8
|
+
exports.getEvmSlip44 = Slip44Service_1.Slip44Service.getEvmSlip44.bind(Slip44Service_1.Slip44Service);
|
|
9
9
|
// getSlip44BySymbol: For non-EVM networks (Bitcoin, Solana, Tron) - uses symbol lookup
|
|
10
|
-
exports.getSlip44BySymbol =
|
|
10
|
+
exports.getSlip44BySymbol = Slip44Service_1.Slip44Service.getSlip44BySymbol.bind(Slip44Service_1.Slip44Service);
|
|
11
11
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,uDAAgD;AAEvC,8FAFA,6BAAa,OAEA;AAEtB,mEAAmE;AACnE,gFAAgF;AACnE,QAAA,YAAY,GAAG,6BAAa,CAAC,YAAY,CAAC,IAAI,CAAC,6BAAa,CAAC,CAAC;AAC3E,uFAAuF;AAC1E,QAAA,iBAAiB,GAC5B,6BAAa,CAAC,iBAAiB,CAAC,IAAI,CAAC,6BAAa,CAAC,CAAC","sourcesContent":["import { Slip44Service } from './Slip44Service';\n\nexport { Slip44Service };\n\n// Re-export static methods as standalone functions for convenience\n// getEvmSlip44: For EVM networks (eip155) - uses chainId lookup, defaults to 60\nexport const getEvmSlip44 = Slip44Service.getEvmSlip44.bind(Slip44Service);\n// getSlip44BySymbol: For non-EVM networks (Bitcoin, Solana, Tron) - uses symbol lookup\nexport const getSlip44BySymbol =\n Slip44Service.getSlip44BySymbol.bind(Slip44Service);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD,OAAO,EAAE,aAAa,EAAE,CAAC;AAIzB,eAAO,MAAM,YAAY,mCAAiD,CAAC;AAE3E,eAAO,MAAM,iBAAiB,wCACuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD,OAAO,EAAE,aAAa,EAAE,CAAC;AAIzB,eAAO,MAAM,YAAY,mCAAiD,CAAC;AAE3E,eAAO,MAAM,iBAAiB,wCACuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,mEAAmE;AACnE,gFAAgF;AAChF,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AAC3E,uFAAuF;AACvF,MAAM,CAAC,MAAM,iBAAiB,GAC5B,aAAa,CAAC,iBAAiB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC","sourcesContent":["import { Slip44Service } from './Slip44Service';\n\nexport { Slip44Service };\n\n// Re-export static methods as standalone functions for convenience\n// getEvmSlip44: For EVM networks (eip155) - uses chainId lookup, defaults to 60\nexport const getEvmSlip44 = Slip44Service.getEvmSlip44.bind(Slip44Service);\n// getSlip44BySymbol: For non-EVM networks (Bitcoin, Solana, Tron) - uses symbol lookup\nexport const getSlip44BySymbol =\n Slip44Service.getSlip44BySymbol.bind(Slip44Service);\n"]}
|
package/dist/utils.cjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isOnlyNetworkEnabledInNamespace = exports.deriveKeys = void 0;
|
|
3
|
+
exports.isPopularNetwork = exports.isOnlyNetworkEnabledInNamespace = exports.deriveKeys = void 0;
|
|
4
4
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
5
5
|
const multichain_network_controller_1 = require("@metamask/multichain-network-controller");
|
|
6
6
|
const utils_1 = require("@metamask/utils");
|
|
7
|
+
const constants_1 = require("./constants.cjs");
|
|
7
8
|
/**
|
|
8
9
|
* Derives the namespace, storage key, and CAIP chain ID from a given chain ID.
|
|
9
10
|
*
|
|
@@ -59,4 +60,21 @@ function isOnlyNetworkEnabledInNamespace(state, derivedKeys) {
|
|
|
59
60
|
return false;
|
|
60
61
|
}
|
|
61
62
|
exports.isOnlyNetworkEnabledInNamespace = isOnlyNetworkEnabledInNamespace;
|
|
63
|
+
/**
|
|
64
|
+
* Checks if a network is considered popular based on its reference.
|
|
65
|
+
*
|
|
66
|
+
* @param reference - The network reference (typically the chain ID reference part)
|
|
67
|
+
* @returns True if the network is popular, false otherwise
|
|
68
|
+
*/
|
|
69
|
+
function isPopularNetwork(reference) {
|
|
70
|
+
try {
|
|
71
|
+
return constants_1.POPULAR_NETWORKS.includes((0, controller_utils_1.toHex)(reference));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// If toHex fails (e.g., for non-decimal references like Bitcoin hashes),
|
|
75
|
+
// the network is not popular
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.isPopularNetwork = isPopularNetwork;
|
|
62
80
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,iEAAmD;AACnD,2FAA2E;AAE3E,2CAKyB;
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,iEAAmD;AACnD,2FAA2E;AAE3E,2CAKyB;AAEzB,+CAA+C;AAa/C;;;;;;;;;;;GAWG;AACH,SAAgB,UAAU,CAAC,OAA0B;IACnD,MAAM,WAAW,GAAG,IAAA,qBAAa,EAAC,OAAO,CAAC;QACxC,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,IAAA,gDAAgB,EAAC,OAAO,CAAC,CAAC;IAE9B,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAAC;IAC/D,IAAI,UAAU,CAAC;IACf,IAAI,SAAS,KAAM,0BAAkB,CAAC,MAAiB,EAAE,CAAC;QACxD,UAAU,GAAG,IAAA,mBAAW,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAA,wBAAK,EAAC,SAAS,CAAC,CAAC;IACjE,CAAC;SAAM,CAAC;QACN,UAAU,GAAG,WAAW,CAAC;IAC3B,CAAC;IACD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;AAC3D,CAAC;AAbD,gCAaC;AAED;;;;;;;;;GASG;AACH,SAAgB,+BAA+B,CAC7C,KAAuC,EACvC,WAAwB;IAExB,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,WAAW,CAAC;IAE9C,0CAA0C;IAC1C,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAEpD,6CAA6C;IAC7C,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,CACrD,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,CAC1B,CAAC;IAEF,yEAAyE;IACzE,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,MAAM,CAAC,cAAc,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;QAC5C,OAAO,cAAc,KAAK,UAAU,CAAC;IACvC,CAAC;IAED,8DAA8D;IAC9D,OAAO,KAAK,CAAC;AACf,CAAC;AA1BD,0EA0BC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,SAAiB;IAChD,IAAI,CAAC;QACH,OAAO,4BAAgB,CAAC,QAAQ,CAAC,IAAA,wBAAK,EAAC,SAAS,CAAC,CAAC,CAAC;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,yEAAyE;QACzE,6BAA6B;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AARD,4CAQC","sourcesContent":["import { toHex } from '@metamask/controller-utils';\nimport { toEvmCaipChainId } from '@metamask/multichain-network-controller';\nimport type { CaipChainId, CaipNamespace, Hex } from '@metamask/utils';\nimport {\n isCaipChainId,\n isHexString,\n KnownCaipNamespace,\n parseCaipChainId,\n} from '@metamask/utils';\n\nimport { POPULAR_NETWORKS } from './constants';\nimport type { NetworkEnablementControllerState } from './NetworkEnablementController';\n\n/**\n * Represents the parsed keys derived from a chain ID.\n */\nexport type DerivedKeys = {\n namespace: CaipNamespace;\n storageKey: Hex | CaipChainId;\n caipChainId: CaipChainId;\n reference: string;\n};\n\n/**\n * Derives the namespace, storage key, and CAIP chain ID from a given chain ID.\n *\n * This utility function handles the conversion between different chain ID formats.\n * For EVM networks, it converts Hex chain IDs to CAIP-2 format and determines\n * the appropriate storage key. For non-EVM networks, it parses the CAIP-2 chain ID\n * and uses the full chain ID as the storage key.\n *\n * @param chainId - The chain ID to derive keys from (Hex or CAIP-2 format)\n * @returns An object containing namespace, storageKey, and caipId\n * @throws Error if the chain ID cannot be parsed\n */\nexport function deriveKeys(chainId: Hex | CaipChainId): DerivedKeys {\n const caipChainId = isCaipChainId(chainId)\n ? chainId\n : toEvmCaipChainId(chainId);\n\n const { namespace, reference } = parseCaipChainId(caipChainId);\n let storageKey;\n if (namespace === (KnownCaipNamespace.Eip155 as string)) {\n storageKey = isHexString(chainId) ? chainId : toHex(reference);\n } else {\n storageKey = caipChainId;\n }\n return { namespace, storageKey, caipChainId, reference };\n}\n\n/**\n * Checks if the specified network is the only enabled network in its namespace.\n *\n * This function is used to prevent unnecessary state updates when trying to enable\n * This method is used to prevent the last network in a namespace from being removed.\n *\n * @param state - The current controller state\n * @param derivedKeys - The parsed keys object containing namespace and storageKey\n * @returns True if the network is the only enabled network in the namespace, false otherwise\n */\nexport function isOnlyNetworkEnabledInNamespace(\n state: NetworkEnablementControllerState,\n derivedKeys: DerivedKeys,\n): boolean {\n const { namespace, storageKey } = derivedKeys;\n\n // Early return if namespace doesn't exist\n if (!state.enabledNetworkMap[namespace]) {\n return false;\n }\n\n const networks = state.enabledNetworkMap[namespace];\n\n // Get all enabled networks in this namespace\n const enabledNetworks = Object.entries(networks).filter(\n ([_, enabled]) => enabled,\n );\n\n // Check if there's exactly one enabled network and it matches our target\n if (enabledNetworks.length === 1) {\n const [onlyEnabledKey] = enabledNetworks[0];\n return onlyEnabledKey === storageKey;\n }\n\n // Return false if there are zero or multiple enabled networks\n return false;\n}\n\n/**\n * Checks if a network is considered popular based on its reference.\n *\n * @param reference - The network reference (typically the chain ID reference part)\n * @returns True if the network is popular, false otherwise\n */\nexport function isPopularNetwork(reference: string): boolean {\n try {\n return POPULAR_NETWORKS.includes(toHex(reference));\n } catch {\n // If toHex fails (e.g., for non-decimal references like Bitcoin hashes),\n // the network is not popular\n return false;\n }\n}\n"]}
|
package/dist/utils.d.cts
CHANGED
|
@@ -33,4 +33,11 @@ export declare function deriveKeys(chainId: Hex | CaipChainId): DerivedKeys;
|
|
|
33
33
|
* @returns True if the network is the only enabled network in the namespace, false otherwise
|
|
34
34
|
*/
|
|
35
35
|
export declare function isOnlyNetworkEnabledInNamespace(state: NetworkEnablementControllerState, derivedKeys: DerivedKeys): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a network is considered popular based on its reference.
|
|
38
|
+
*
|
|
39
|
+
* @param reference - The network reference (typically the chain ID reference part)
|
|
40
|
+
* @returns True if the network is popular, false otherwise
|
|
41
|
+
*/
|
|
42
|
+
export declare function isPopularNetwork(reference: string): boolean;
|
|
36
43
|
//# sourceMappingURL=utils.d.cts.map
|
package/dist/utils.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AASvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,0CAAsC;AAEtF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,GAAG,GAAG,WAAW,CAAC;IAC9B,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,WAAW,CAalE;AAED;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,gCAAgC,EACvC,WAAW,EAAE,WAAW,GACvB,OAAO,CAuBT;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAQ3D"}
|
package/dist/utils.d.mts
CHANGED
|
@@ -33,4 +33,11 @@ export declare function deriveKeys(chainId: Hex | CaipChainId): DerivedKeys;
|
|
|
33
33
|
* @returns True if the network is the only enabled network in the namespace, false otherwise
|
|
34
34
|
*/
|
|
35
35
|
export declare function isOnlyNetworkEnabledInNamespace(state: NetworkEnablementControllerState, derivedKeys: DerivedKeys): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if a network is considered popular based on its reference.
|
|
38
|
+
*
|
|
39
|
+
* @param reference - The network reference (typically the chain ID reference part)
|
|
40
|
+
* @returns True if the network is popular, false otherwise
|
|
41
|
+
*/
|
|
42
|
+
export declare function isPopularNetwork(reference: string): boolean;
|
|
36
43
|
//# sourceMappingURL=utils.d.mts.map
|
package/dist/utils.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AASvE,OAAO,KAAK,EAAE,gCAAgC,EAAE,0CAAsC;AAEtF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,aAAa,CAAC;IACzB,UAAU,EAAE,GAAG,GAAG,WAAW,CAAC;IAC9B,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,GAAG,GAAG,WAAW,GAAG,WAAW,CAalE;AAED;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,gCAAgC,EACvC,WAAW,EAAE,WAAW,GACvB,OAAO,CAuBT;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAQ3D"}
|