import { SchemeNetworkServer, Network, MoneyParser, Price, AssetAmount, PaymentRequirements } from '@x402/core/types'; import { b as X402xPublicEvmClient } from './signer-Clo2kGD1.js'; import { P as PermitType } from './types-CoWeJxFg.js'; type ExactX402xEvmServerAssetConfig = { address: `0x${string}`; decimals: number; /** * 可选:写入 requirements.extra,用于客户端/促进方签名与校验 * (缺失时,本包的 client/facilitator 会尝试链上读取) */ name?: string; version?: string; /** * 可选:显式指定该资产要使用的签名类型(写入 requirements.extra.permitType)。 * * 如果同时存在 permitTypes,则 permitType 优先级更高。 */ permitType?: PermitType; /** * 可选:声明该 token 支持的签名类型集合(用于自动选择)。 * * 选择优先级:eip3009 > permit > permit2(或列表中其它项)。 */ permitTypes?: PermitType[]; }; /** * x402x EVM server implementation for x402 "exact" scheme. * * 重点:提供资产注册能力(BSC/USD1 等)。 */ declare class ExactX402xEvmServer implements SchemeNetworkServer { private static readonly PERMIT_TYPE_PRIORITY; readonly scheme: "exact:eip7702"; private moneyParsers; private readonly assets; private readonly defaultAssetByNetwork; private readonly publicClientsByNetwork; private readonly permitTypeCache; /** * 注册一个 network 对应的公共链读客户端(用于自动探测 token 支持的 permitType)。 * * - 若未注册,则当资产未配置 permitType/permitTypes 时会回退到默认优先级推断(不做链上检查) * - 若已注册,则会在首次遇到 token 时做一次链上探测并缓存 * * @param network - CAIP-2 网络,如 "eip155:56" * @param client - 具备 readContract 的公共读客户端 * @returns this */ registerPublicClient(network: Network, client: X402xPublicEvmClient): this; /** * 注册一个网络默认资产(用于 Money 价格转换)。 * * @param network - CAIP-2 网络,如 "eip155:56" * @param symbol - 资产符号(仅用于本地 key) * @param config - 资产配置 * @returns The server instance for chaining */ registerAsset(network: Network, symbol: string, config: ExactX402xEvmServerAssetConfig): this; /** * 设置某个网络的默认资产符号(必须已 registerAsset)。 * * @param network - CAIP-2 网络,如 "eip155:56" * @param symbol - 资产符号 * @returns The server instance for chaining */ setDefaultAsset(network: Network, symbol: string): this; /** * 注册一个 Money 价格转换器。 * * @param parser - 价格转换器 * @returns The server instance for chaining */ registerMoneyParser(parser: MoneyParser): this; /** * 解析一个价格并转换为资产金额。 * * @param price - 价格 * @param network - CAIP-2 网络 * @returns The asset amount */ parsePrice(price: Price, network: Network): Promise; /** * Build payment requirements for this scheme/network combination * * @param paymentRequirements - The base payment requirements * @param supportedKind - The supported kind from facilitator (unused) * @param supportedKind.x402Version - The x402 version * @param supportedKind.scheme - The logical payment scheme * @param supportedKind.network - The network identifier in CAIP-2 format * @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details * @param extensionKeys - Extension keys supported by the facilitator (unused) * @returns Payment requirements ready to be sent to clients */ enhancePaymentRequirements(paymentRequirements: PaymentRequirements, supportedKind: { x402Version: number; scheme: string; network: Network; extra?: Record; }, extensionKeys: string[]): Promise; /** * 将资产注册信息(name/version/permitType)注入到 AssetAmount.extra。 * * @param assetAmount - 解析出的资产金额 * @param network - CAIP-2 网络 * @returns 注入 extra 后的 AssetAmount */ private injectAssetExtra; /** * 根据资产配置选择 permitType(优先级:eip3009 > permit > permit2)。 * * @param cfg - 资产配置 * @returns 选中的 permitType(如果能确定) */ private resolvePermitType; /** * 当资产未显式声明 permitType/permitTypes 时,尝试链上探测 token 支持情况。 * * @param network - CAIP-2 网络 * @param token - token 合约地址 * @returns 探测结果(若探测失败则返回 undefined) */ private detectPermitType; /** * 在当前 network 的资产注册表里,按 token address 反查资产配置。 * * @param network - CAIP-2 网络 * @param address - token 合约地址(不强制类型,以兼容上游 AssetAmount.asset 为 string 的情况) * @returns 资产配置(找不到则 undefined) */ private findAssetConfigByAddress; /** * Parse money to decimal. * * @param money - The money to parse (e.g., "$1.50") * @returns The amount in decimal */ private parseMoneyToDecimal; /** * Default money conversion implementation. * * @param amount - The amount in decimal (e.g., 1.50) * @param network - The network identifier in CAIP-2 format * @returns The asset amount */ private defaultMoneyConversion; /** * Convert decimal amount to token amount. * * @param decimalAmount - The amount in decimal (e.g., 1.50) * @param decimals - The number of decimals * @returns The amount in token */ private convertToTokenAmount; /** * Get the asset config for a network and symbol. * * @param network - The network identifier in CAIP-2 format * @param symbol - The symbol of the asset * @returns The asset config */ private getAsset; /** * Generate a unique asset key for a network and symbol. * * @param network - The network identifier in CAIP-2 format * @param symbol - The symbol of the asset * @returns The asset key */ private assetKey; } export { ExactX402xEvmServer as E, type ExactX402xEvmServerAssetConfig as a };