{"version":3,"file":"explorer-DClCq_90-BE3RJpsP.mjs","names":[],"sources":["../../adapter-evm-core/dist/explorer-DClCq_90.mjs"],"sourcesContent":["import { t as isValidEvmAddress } from \"./validation--Y5v5XOf.mjs\";\nimport { appConfigService, logger, userNetworkServiceConfigService } from \"@openzeppelin/ui-utils\";\nimport trimEnd from \"lodash-es/trimEnd.js\";\n\n//#region src/configuration/explorer.ts\n/**\n* Resolves the explorer API key from app configuration (without user overrides).\n* This is used by getDefaultServiceConfig to provide defaults for health checks.\n*\n* Priority order:\n* 1. For V2 API networks: Global Etherscan V2 API key\n* 2. Network-specific global service config API key\n* 3. Fallback to explorer API key by identifier\n*\n* @param networkConfig - EVM-compatible network configuration\n* @returns The resolved API key, or undefined if not configured\n*/\nfunction resolveExplorerApiKeyFromAppConfig(networkConfig) {\n\tif (networkConfig.supportsEtherscanV2 && networkConfig.primaryExplorerApiIdentifier === \"etherscan-v2\") {\n\t\tconst globalV2ApiKey = appConfigService.getGlobalServiceConfig(\"etherscanv2\")?.apiKey;\n\t\tif (globalV2ApiKey) return globalV2ApiKey;\n\t}\n\tif (networkConfig.primaryExplorerApiIdentifier) {\n\t\tconst apiKey = appConfigService.getGlobalServiceConfig(networkConfig.primaryExplorerApiIdentifier)?.apiKey ?? appConfigService.getExplorerApiKey(networkConfig.primaryExplorerApiIdentifier);\n\t\tif (apiKey) return apiKey;\n\t}\n}\n/**\n* Resolves the explorer configuration for a given EVM network.\n* Priority order:\n* 1. User-configured explorer (from UserExplorerConfigService)\n* 2. For V2 API networks: Global Etherscan V2 API key (from AppConfigService global service configs)\n* 3. App-configured explorer API key (from AppConfigService network service configs)\n* 4. Default network explorer (from NetworkConfig)\n*\n* @param networkConfig - EVM-compatible network configuration (works with any ecosystem).\n* @returns The resolved explorer configuration.\n*/\nfunction resolveExplorerConfig(networkConfig) {\n\tconst isV2 = networkConfig.supportsEtherscanV2 && networkConfig.primaryExplorerApiIdentifier === \"etherscan-v2\";\n\tconst globalV2ApiKey = isV2 ? appConfigService.getGlobalServiceConfig(\"etherscanv2\")?.apiKey : void 0;\n\tlet appApiKey;\n\tif (networkConfig.primaryExplorerApiIdentifier) appApiKey = appConfigService.getGlobalServiceConfig(networkConfig.primaryExplorerApiIdentifier)?.apiKey ?? appConfigService.getExplorerApiKey(networkConfig.primaryExplorerApiIdentifier);\n\tconst rawCfg = userNetworkServiceConfigService.get(networkConfig.id, \"explorer\");\n\tif (rawCfg && typeof rawCfg === \"object\") {\n\t\tconst userCfg = rawCfg;\n\t\tlogger.info(\"ExplorerConfig\", `Using user-configured explorer for ${networkConfig.name}`);\n\t\treturn {\n\t\t\texplorerUrl: userCfg.explorerUrl ?? networkConfig.explorerUrl,\n\t\t\tapiUrl: userCfg.apiUrl ?? networkConfig.apiUrl,\n\t\t\tapiKey: userCfg.apiKey ?? globalV2ApiKey ?? appApiKey,\n\t\t\tname: `${networkConfig.name} Explorer`,\n\t\t\tisCustom: true\n\t\t};\n\t}\n\tif (isV2 && globalV2ApiKey) {\n\t\tlogger.info(\"ExplorerConfig\", `Using global Etherscan V2 API key for ${networkConfig.name}`);\n\t\treturn {\n\t\t\texplorerUrl: networkConfig.explorerUrl,\n\t\t\tapiUrl: networkConfig.apiUrl,\n\t\t\tapiKey: globalV2ApiKey,\n\t\t\tname: `${networkConfig.name} Explorer (V2 API)`,\n\t\t\tisCustom: false\n\t\t};\n\t}\n\tif (appApiKey) {\n\t\tlogger.info(\"ExplorerConfig\", `Using app-configured API key for ${networkConfig.name}`);\n\t\treturn {\n\t\t\texplorerUrl: networkConfig.explorerUrl,\n\t\t\tapiUrl: networkConfig.apiUrl,\n\t\t\tapiKey: appApiKey,\n\t\t\tname: `${networkConfig.name} Explorer`,\n\t\t\tisCustom: false\n\t\t};\n\t}\n\tlogger.info(\"ExplorerConfig\", `Using default explorer for ${networkConfig.name} (no API key configured)`);\n\treturn {\n\t\texplorerUrl: networkConfig.explorerUrl,\n\t\tapiUrl: networkConfig.apiUrl,\n\t\tname: `${networkConfig.name} Explorer`,\n\t\tisCustom: false\n\t};\n}\n/**\n* Gets a blockchain explorer URL for an EVM address.\n* Uses the resolved explorer configuration.\n*\n* @param address - Contract or wallet address\n* @param networkConfig - EVM-compatible network configuration (works with any ecosystem)\n*/\nfunction getEvmExplorerAddressUrl(address, networkConfig) {\n\tif (!isValidEvmAddress(address)) return null;\n\tconst explorerConfig = resolveExplorerConfig(networkConfig);\n\tif (!explorerConfig.explorerUrl) return null;\n\treturn `${trimEnd(explorerConfig.explorerUrl, \"/\")}/address/${address}`;\n}\n/**\n* Gets a blockchain explorer URL for an EVM transaction.\n* Uses the resolved explorer configuration.\n*\n* @param txHash - Transaction hash\n* @param networkConfig - EVM-compatible network configuration (works with any ecosystem)\n*/\nfunction getEvmExplorerTxUrl(txHash, networkConfig) {\n\tif (!txHash) return null;\n\tconst explorerConfig = resolveExplorerConfig(networkConfig);\n\tif (!explorerConfig.explorerUrl) return null;\n\treturn `${trimEnd(explorerConfig.explorerUrl, \"/\")}/tx/${txHash}`;\n}\n/**\n* Validates an EVM explorer configuration.\n* Checks URL formats and API key format.\n*/\nfunction validateEvmExplorerConfig(explorerConfig) {\n\tif (explorerConfig.explorerUrl) try {\n\t\tnew URL(explorerConfig.explorerUrl);\n\t} catch {\n\t\treturn false;\n\t}\n\tif (explorerConfig.apiUrl) try {\n\t\tnew URL(explorerConfig.apiUrl);\n\t} catch {\n\t\treturn false;\n\t}\n\tif (explorerConfig.apiKey !== void 0 && explorerConfig.apiKey.trim().length === 0) return false;\n\treturn true;\n}\n/**\n* Tests the connection to an EVM explorer API.\n* Makes a test API call to verify the API key works.\n* Automatically uses V2 API testing for networks that support it.\n*\n* @param explorerConfig - Explorer configuration to test\n* @param networkConfig - Optional EVM-compatible network configuration (works with any ecosystem)\n*/\nasync function testEvmExplorerConnection(explorerConfig, networkConfig) {\n\tif (networkConfig) {\n\t\tconst { shouldUseV2Api, testEtherscanV2Connection } = await import(\"./etherscan-v2-CspKnH_1.mjs\");\n\t\tif (shouldUseV2Api(networkConfig)) {\n\t\t\tlogger.info(\"testEvmExplorerConnection\", `Using V2 API connection test for ${networkConfig.name}`);\n\t\t\treturn testEtherscanV2Connection(networkConfig, explorerConfig.apiKey);\n\t\t}\n\t}\n\tif ((networkConfig && \"requiresExplorerApiKey\" in networkConfig ? networkConfig.requiresExplorerApiKey !== false : true) && !explorerConfig.apiKey) return {\n\t\tsuccess: false,\n\t\terror: \"API key is required for testing connection to this explorer\"\n\t};\n\tlet apiUrl = explorerConfig.apiUrl;\n\tif (!apiUrl && networkConfig?.apiUrl) apiUrl = networkConfig.apiUrl;\n\tif (!apiUrl) return {\n\t\tsuccess: false,\n\t\terror: \"API URL is required for testing connection. Please provide an API URL or ensure the network has a default API URL configured.\"\n\t};\n\tconst startTime = Date.now();\n\ttry {\n\t\tconst url = new URL(apiUrl);\n\t\turl.searchParams.append(\"module\", \"proxy\");\n\t\turl.searchParams.append(\"action\", \"eth_blockNumber\");\n\t\tif (explorerConfig.apiKey) url.searchParams.append(\"apikey\", explorerConfig.apiKey);\n\t\tconst response = await fetch(url.toString());\n\t\tconst latency = Date.now() - startTime;\n\t\tif (!response.ok) return {\n\t\t\tsuccess: false,\n\t\t\terror: `HTTP ${response.status}: ${response.statusText}`,\n\t\t\tlatency\n\t\t};\n\t\tconst data = await response.json();\n\t\tif (data.status === \"0\" && data.message) return {\n\t\t\tsuccess: false,\n\t\t\terror: data.message,\n\t\t\tlatency\n\t\t};\n\t\treturn {\n\t\t\tsuccess: true,\n\t\t\tlatency\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: error instanceof Error ? error.message : \"Connection test failed\",\n\t\t\tlatency: Date.now() - startTime\n\t\t};\n\t}\n}\n\n//#endregion\nexport { testEvmExplorerConnection as a, resolveExplorerConfig as i, getEvmExplorerTxUrl as n, validateEvmExplorerConfig as o, resolveExplorerApiKeyFromAppConfig as r, getEvmExplorerAddressUrl as t };\n//# sourceMappingURL=explorer-DClCq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