@x402/evm 2.1.0 → 2.2.0
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/dist/cjs/exact/server/index.d.ts +5 -20
- package/dist/cjs/exact/server/index.js +14 -48
- package/dist/cjs/exact/server/index.js.map +1 -1
- package/dist/esm/exact/server/index.d.mts +5 -20
- package/dist/esm/exact/server/index.mjs +14 -48
- package/dist/esm/exact/server/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -67,18 +67,18 @@ declare class ExactEvmScheme implements SchemeNetworkServer {
|
|
|
67
67
|
private parseMoneyToDecimal;
|
|
68
68
|
/**
|
|
69
69
|
* Default money conversion implementation.
|
|
70
|
-
* Converts decimal amount to
|
|
70
|
+
* Converts decimal amount to the default stablecoin on the specified network.
|
|
71
71
|
*
|
|
72
72
|
* @param amount - The decimal amount (e.g., 1.50)
|
|
73
73
|
* @param network - The network to use
|
|
74
|
-
* @returns The parsed asset amount in
|
|
74
|
+
* @returns The parsed asset amount in the default stablecoin
|
|
75
75
|
*/
|
|
76
76
|
private defaultMoneyConversion;
|
|
77
77
|
/**
|
|
78
|
-
* Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal
|
|
78
|
+
* Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal tokens)
|
|
79
79
|
*
|
|
80
80
|
* @param decimalAmount - The decimal amount to convert
|
|
81
|
-
* @param
|
|
81
|
+
* @param decimals - The number of decimals for the token
|
|
82
82
|
* @returns The token amount as a string
|
|
83
83
|
*/
|
|
84
84
|
private convertToTokenAmount;
|
|
@@ -86,24 +86,9 @@ declare class ExactEvmScheme implements SchemeNetworkServer {
|
|
|
86
86
|
* Get the default asset info for a network (typically USDC)
|
|
87
87
|
*
|
|
88
88
|
* @param network - The network to get asset info for
|
|
89
|
-
* @returns The asset information including address, name, and
|
|
89
|
+
* @returns The asset information including address, name, version, and decimals
|
|
90
90
|
*/
|
|
91
91
|
private getDefaultAsset;
|
|
92
|
-
/**
|
|
93
|
-
* Get asset info for a given symbol on a network
|
|
94
|
-
*
|
|
95
|
-
* @param symbol - The asset symbol
|
|
96
|
-
* @param network - The network to use
|
|
97
|
-
* @returns The asset information including address, name, and version
|
|
98
|
-
*/
|
|
99
|
-
private getAssetInfo;
|
|
100
|
-
/**
|
|
101
|
-
* Get the number of decimals for the asset
|
|
102
|
-
*
|
|
103
|
-
* @param _ - The network to use (unused)
|
|
104
|
-
* @returns The number of decimals for the asset
|
|
105
|
-
*/
|
|
106
|
-
private getAssetDecimals;
|
|
107
92
|
}
|
|
108
93
|
|
|
109
94
|
/**
|
|
@@ -122,15 +122,15 @@ var ExactEvmScheme = class {
|
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
124
124
|
* Default money conversion implementation.
|
|
125
|
-
* Converts decimal amount to
|
|
125
|
+
* Converts decimal amount to the default stablecoin on the specified network.
|
|
126
126
|
*
|
|
127
127
|
* @param amount - The decimal amount (e.g., 1.50)
|
|
128
128
|
* @param network - The network to use
|
|
129
|
-
* @returns The parsed asset amount in
|
|
129
|
+
* @returns The parsed asset amount in the default stablecoin
|
|
130
130
|
*/
|
|
131
131
|
defaultMoneyConversion(amount, network) {
|
|
132
|
-
const tokenAmount = this.convertToTokenAmount(amount.toString(), network);
|
|
133
132
|
const assetInfo = this.getDefaultAsset(network);
|
|
133
|
+
const tokenAmount = this.convertToTokenAmount(amount.toString(), assetInfo.decimals);
|
|
134
134
|
return {
|
|
135
135
|
amount: tokenAmount,
|
|
136
136
|
asset: assetInfo.address,
|
|
@@ -141,14 +141,13 @@ var ExactEvmScheme = class {
|
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
|
-
* Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal
|
|
144
|
+
* Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal tokens)
|
|
145
145
|
*
|
|
146
146
|
* @param decimalAmount - The decimal amount to convert
|
|
147
|
-
* @param
|
|
147
|
+
* @param decimals - The number of decimals for the token
|
|
148
148
|
* @returns The token amount as a string
|
|
149
149
|
*/
|
|
150
|
-
convertToTokenAmount(decimalAmount,
|
|
151
|
-
const decimals = this.getAssetDecimals(network);
|
|
150
|
+
convertToTokenAmount(decimalAmount, decimals) {
|
|
152
151
|
const amount = parseFloat(decimalAmount);
|
|
153
152
|
if (isNaN(amount)) {
|
|
154
153
|
throw new Error(`Invalid amount: ${decimalAmount}`);
|
|
@@ -162,64 +161,31 @@ var ExactEvmScheme = class {
|
|
|
162
161
|
* Get the default asset info for a network (typically USDC)
|
|
163
162
|
*
|
|
164
163
|
* @param network - The network to get asset info for
|
|
165
|
-
* @returns The asset information including address, name, and
|
|
164
|
+
* @returns The asset information including address, name, version, and decimals
|
|
166
165
|
*/
|
|
167
166
|
getDefaultAsset(network) {
|
|
168
|
-
const
|
|
167
|
+
const stablecoins = {
|
|
169
168
|
"eip155:8453": {
|
|
170
169
|
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
171
170
|
name: "USD Coin",
|
|
172
|
-
version: "2"
|
|
171
|
+
version: "2",
|
|
172
|
+
decimals: 6
|
|
173
173
|
},
|
|
174
174
|
// Base mainnet USDC
|
|
175
175
|
"eip155:84532": {
|
|
176
176
|
address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
177
177
|
name: "USDC",
|
|
178
|
-
version: "2"
|
|
179
|
-
|
|
180
|
-
// Base Sepolia USDC
|
|
181
|
-
"eip155:1": {
|
|
182
|
-
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
183
|
-
name: "USD Coin",
|
|
184
|
-
version: "2"
|
|
185
|
-
},
|
|
186
|
-
// Ethereum mainnet USDC
|
|
187
|
-
"eip155:11155111": {
|
|
188
|
-
address: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
|
|
189
|
-
name: "USDC",
|
|
190
|
-
version: "2"
|
|
178
|
+
version: "2",
|
|
179
|
+
decimals: 6
|
|
191
180
|
}
|
|
192
|
-
// Sepolia USDC
|
|
181
|
+
// Base Sepolia USDC
|
|
193
182
|
};
|
|
194
|
-
const assetInfo =
|
|
183
|
+
const assetInfo = stablecoins[network];
|
|
195
184
|
if (!assetInfo) {
|
|
196
185
|
throw new Error(`No default asset configured for network ${network}`);
|
|
197
186
|
}
|
|
198
187
|
return assetInfo;
|
|
199
188
|
}
|
|
200
|
-
/**
|
|
201
|
-
* Get asset info for a given symbol on a network
|
|
202
|
-
*
|
|
203
|
-
* @param symbol - The asset symbol
|
|
204
|
-
* @param network - The network to use
|
|
205
|
-
* @returns The asset information including address, name, and version
|
|
206
|
-
*/
|
|
207
|
-
getAssetInfo(symbol, network) {
|
|
208
|
-
const upperSymbol = symbol.toUpperCase();
|
|
209
|
-
if (upperSymbol === "USDC" || upperSymbol === "USD") {
|
|
210
|
-
return this.getDefaultAsset(network);
|
|
211
|
-
}
|
|
212
|
-
throw new Error(`Unsupported asset: ${symbol} on network ${network}`);
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Get the number of decimals for the asset
|
|
216
|
-
*
|
|
217
|
-
* @param _ - The network to use (unused)
|
|
218
|
-
* @returns The number of decimals for the asset
|
|
219
|
-
*/
|
|
220
|
-
getAssetDecimals(_) {
|
|
221
|
-
return 6;
|
|
222
|
-
}
|
|
223
189
|
};
|
|
224
190
|
|
|
225
191
|
// src/exact/server/register.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/exact/server/index.ts","../../../../src/exact/server/scheme.ts","../../../../src/exact/server/register.ts"],"sourcesContent":["export { ExactEvmScheme } from \"./scheme\";\nexport { registerExactEvmScheme } from \"./register\";\nexport type { EvmResourceServerConfig } from \"./register\";\n","import {\n AssetAmount,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@x402/core/types\";\n\n/**\n * EVM server implementation for the Exact payment scheme.\n */\nexport class ExactEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"exact\";\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Register a custom money parser in the parser chain.\n * Multiple parsers can be registered - they will be tried in registration order.\n * Each parser receives a decimal amount (e.g., 1.50 for $1.50).\n * If a parser returns null, the next parser in the chain will be tried.\n * The default parser is always the final fallback.\n *\n * @param parser - Custom function to convert amount to AssetAmount (or null to skip)\n * @returns The server instance for chaining\n *\n * @example\n * evmServer.registerMoneyParser(async (amount, network) => {\n * // Custom conversion logic\n * if (amount > 100) {\n * // Use different token for large amounts\n * return { amount: (amount * 1e18).toString(), asset: \"0xCustomToken\" };\n * }\n * return null; // Use next parser\n * });\n */\n registerMoneyParser(parser: MoneyParser): ExactEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Parses a price into an asset amount.\n * If price is already an AssetAmount, returns it directly.\n * If price is Money (string | number), parses to decimal and tries custom parsers.\n * Falls back to default conversion if all custom parsers return null.\n *\n * @param price - The price to parse\n * @param network - The network to use\n * @returns Promise that resolves to the parsed asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n // If already an AssetAmount, return it directly\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n // Parse Money to decimal number\n const amount = this.parseMoneyToDecimal(price);\n\n // Try each custom money parser in order\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n // All custom parsers returned null, use default conversion\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Build payment requirements for this scheme/network combination\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported kind from facilitator (unused)\n * @param supportedKind.x402Version - The x402 version\n * @param supportedKind.scheme - The logical payment scheme\n * @param supportedKind.network - The network identifier in CAIP-2 format\n * @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details\n * @param extensionKeys - Extension keys supported by the facilitator (unused)\n * @returns Payment requirements ready to be sent to clients\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n // Mark unused parameters to satisfy linter\n void supportedKind;\n void extensionKeys;\n return Promise.resolve(paymentRequirements);\n }\n\n /**\n * Parse Money (string | number) to a decimal number.\n * Handles formats like \"$1.50\", \"1.50\", 1.50, etc.\n *\n * @param money - The money value to parse\n * @returns Decimal number\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n // Remove $ sign and whitespace, then parse\n const cleanMoney = money.replace(/^\\$/, \"\").trim();\n const amount = parseFloat(cleanMoney);\n\n if (isNaN(amount)) {\n throw new Error(`Invalid money format: ${money}`);\n }\n\n return amount;\n }\n\n /**\n * Default money conversion implementation.\n * Converts decimal amount to USDC on the specified network.\n *\n * @param amount - The decimal amount (e.g., 1.50)\n * @param network - The network to use\n * @returns The parsed asset amount in USDC\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n // Convert decimal amount to token amount (USDC has 6 decimals)\n const tokenAmount = this.convertToTokenAmount(amount.toString(), network);\n const assetInfo = this.getDefaultAsset(network);\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n name: assetInfo.name,\n version: assetInfo.version,\n },\n };\n }\n\n /**\n * Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal USDC)\n *\n * @param decimalAmount - The decimal amount to convert\n * @param network - The network to use\n * @returns The token amount as a string\n */\n private convertToTokenAmount(decimalAmount: string, network: Network): string {\n const decimals = this.getAssetDecimals(network);\n const amount = parseFloat(decimalAmount);\n if (isNaN(amount)) {\n throw new Error(`Invalid amount: ${decimalAmount}`);\n }\n // Convert to smallest unit (e.g., for USDC with 6 decimals: 0.10 * 10^6 = 100000)\n const [intPart, decPart = \"\"] = String(amount).split(\".\");\n const paddedDec = decPart.padEnd(decimals, \"0\").slice(0, decimals);\n const tokenAmount = (intPart + paddedDec).replace(/^0+/, \"\") || \"0\";\n return tokenAmount;\n }\n\n /**\n * Get the default asset info for a network (typically USDC)\n *\n * @param network - The network to get asset info for\n * @returns The asset information including address, name, and version\n */\n private getDefaultAsset(network: Network): { address: string; name: string; version: string } {\n // Map of network to USDC info including EIP-712 domain parameters\n const usdcInfo: Record<string, { address: string; name: string; version: string }> = {\n \"eip155:8453\": {\n address: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n name: \"USD Coin\",\n version: \"2\",\n }, // Base mainnet USDC\n \"eip155:84532\": {\n address: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n name: \"USDC\",\n version: \"2\",\n }, // Base Sepolia USDC\n \"eip155:1\": {\n address: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n name: \"USD Coin\",\n version: \"2\",\n }, // Ethereum mainnet USDC\n \"eip155:11155111\": {\n address: \"0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238\",\n name: \"USDC\",\n version: \"2\",\n }, // Sepolia USDC\n };\n\n const assetInfo = usdcInfo[network];\n if (!assetInfo) {\n throw new Error(`No default asset configured for network ${network}`);\n }\n\n return assetInfo;\n }\n\n /**\n * Get asset info for a given symbol on a network\n *\n * @param symbol - The asset symbol\n * @param network - The network to use\n * @returns The asset information including address, name, and version\n */\n private getAssetInfo(\n symbol: string,\n network: Network,\n ): { address: string; name: string; version: string } {\n const upperSymbol = symbol.toUpperCase();\n\n // For now, only support USDC\n if (upperSymbol === \"USDC\" || upperSymbol === \"USD\") {\n return this.getDefaultAsset(network);\n }\n\n // Could extend to support other tokens\n throw new Error(`Unsupported asset: ${symbol} on network ${network}`);\n }\n\n /**\n * Get the number of decimals for the asset\n *\n * @param _ - The network to use (unused)\n * @returns The number of decimals for the asset\n */\n private getAssetDecimals(_: Network): number {\n // USDC has 6 decimals on all EVM chains\n return 6;\n }\n}\n","import { x402ResourceServer } from \"@x402/core/server\";\nimport { Network } from \"@x402/core/types\";\nimport { ExactEvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering EVM schemes to an x402ResourceServer\n */\nexport interface EvmResourceServerConfig {\n /**\n * Optional specific networks to register\n * If not provided, registers wildcard support (eip155:*)\n */\n networks?: Network[];\n}\n\n/**\n * Registers EVM exact payment schemes to an x402ResourceServer instance.\n *\n * This function registers:\n * - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)\n *\n * @param server - The x402ResourceServer instance to register schemes to\n * @param config - Configuration for EVM resource server registration\n * @returns The server instance for chaining\n *\n * @example\n * ```typescript\n * import { registerExactEvmScheme } from \"@x402/evm/exact/server/register\";\n * import { x402ResourceServer } from \"@x402/core/server\";\n *\n * const server = new x402ResourceServer(facilitatorClient);\n * registerExactEvmScheme(server, {});\n * ```\n */\nexport function registerExactEvmScheme(\n server: x402ResourceServer,\n config: EvmResourceServerConfig = {},\n): x402ResourceServer {\n // Register V2 scheme\n if (config.networks && config.networks.length > 0) {\n // Register specific networks\n config.networks.forEach(network => {\n server.register(network, new ExactEvmScheme());\n });\n } else {\n // Register wildcard for all EVM chains\n server.register(\"eip155:*\", new ExactEvmScheme());\n }\n\n return server;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYO,IAAM,iBAAN,MAAoD;AAAA,EAApD;AACL,SAAS,SAAS;AAClB,SAAQ,eAA8B,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBvC,oBAAoB,QAAqC;AACvD,SAAK,aAAa,KAAK,MAAM;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AAM,cAAc,OAAO,YAAY;AAGvC,QAAI,gBAAgB,UAAU,gBAAgB,OAAO;AACnD,aAAO,KAAK,gBAAgB,OAAO;AAAA,IACrC;AAGA,UAAM,IAAI,MAAM,sBAAsB,MAAM,eAAe,OAAO,EAAE;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,iBAAiB,GAAoB;AAE3C,WAAO;AAAA,EACT;AACF;;;AClNO,SAAS,uBACd,QACA,SAAkC,CAAC,GACf;AAEpB,MAAI,OAAO,YAAY,OAAO,SAAS,SAAS,GAAG;AAEjD,WAAO,SAAS,QAAQ,aAAW;AACjC,aAAO,SAAS,SAAS,IAAI,eAAe,CAAC;AAAA,IAC/C,CAAC;AAAA,EACH,OAAO;AAEL,WAAO,SAAS,YAAY,IAAI,eAAe,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/exact/server/index.ts","../../../../src/exact/server/scheme.ts","../../../../src/exact/server/register.ts"],"sourcesContent":["export { ExactEvmScheme } from \"./scheme\";\nexport { registerExactEvmScheme } from \"./register\";\nexport type { EvmResourceServerConfig } from \"./register\";\n","import {\n AssetAmount,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@x402/core/types\";\n\n/**\n * EVM server implementation for the Exact payment scheme.\n */\nexport class ExactEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"exact\";\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Register a custom money parser in the parser chain.\n * Multiple parsers can be registered - they will be tried in registration order.\n * Each parser receives a decimal amount (e.g., 1.50 for $1.50).\n * If a parser returns null, the next parser in the chain will be tried.\n * The default parser is always the final fallback.\n *\n * @param parser - Custom function to convert amount to AssetAmount (or null to skip)\n * @returns The server instance for chaining\n *\n * @example\n * evmServer.registerMoneyParser(async (amount, network) => {\n * // Custom conversion logic\n * if (amount > 100) {\n * // Use different token for large amounts\n * return { amount: (amount * 1e18).toString(), asset: \"0xCustomToken\" };\n * }\n * return null; // Use next parser\n * });\n */\n registerMoneyParser(parser: MoneyParser): ExactEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Parses a price into an asset amount.\n * If price is already an AssetAmount, returns it directly.\n * If price is Money (string | number), parses to decimal and tries custom parsers.\n * Falls back to default conversion if all custom parsers return null.\n *\n * @param price - The price to parse\n * @param network - The network to use\n * @returns Promise that resolves to the parsed asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n // If already an AssetAmount, return it directly\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n // Parse Money to decimal number\n const amount = this.parseMoneyToDecimal(price);\n\n // Try each custom money parser in order\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n // All custom parsers returned null, use default conversion\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Build payment requirements for this scheme/network combination\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported kind from facilitator (unused)\n * @param supportedKind.x402Version - The x402 version\n * @param supportedKind.scheme - The logical payment scheme\n * @param supportedKind.network - The network identifier in CAIP-2 format\n * @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details\n * @param extensionKeys - Extension keys supported by the facilitator (unused)\n * @returns Payment requirements ready to be sent to clients\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n // Mark unused parameters to satisfy linter\n void supportedKind;\n void extensionKeys;\n return Promise.resolve(paymentRequirements);\n }\n\n /**\n * Parse Money (string | number) to a decimal number.\n * Handles formats like \"$1.50\", \"1.50\", 1.50, etc.\n *\n * @param money - The money value to parse\n * @returns Decimal number\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n // Remove $ sign and whitespace, then parse\n const cleanMoney = money.replace(/^\\$/, \"\").trim();\n const amount = parseFloat(cleanMoney);\n\n if (isNaN(amount)) {\n throw new Error(`Invalid money format: ${money}`);\n }\n\n return amount;\n }\n\n /**\n * Default money conversion implementation.\n * Converts decimal amount to the default stablecoin on the specified network.\n *\n * @param amount - The decimal amount (e.g., 1.50)\n * @param network - The network to use\n * @returns The parsed asset amount in the default stablecoin\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const assetInfo = this.getDefaultAsset(network);\n const tokenAmount = this.convertToTokenAmount(amount.toString(), assetInfo.decimals);\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n name: assetInfo.name,\n version: assetInfo.version,\n },\n };\n }\n\n /**\n * Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal tokens)\n *\n * @param decimalAmount - The decimal amount to convert\n * @param decimals - The number of decimals for the token\n * @returns The token amount as a string\n */\n private convertToTokenAmount(decimalAmount: string, decimals: number): string {\n const amount = parseFloat(decimalAmount);\n if (isNaN(amount)) {\n throw new Error(`Invalid amount: ${decimalAmount}`);\n }\n // Convert to smallest unit (e.g., for USDC with 6 decimals: 0.10 * 10^6 = 100000)\n const [intPart, decPart = \"\"] = String(amount).split(\".\");\n const paddedDec = decPart.padEnd(decimals, \"0\").slice(0, decimals);\n const tokenAmount = (intPart + paddedDec).replace(/^0+/, \"\") || \"0\";\n return tokenAmount;\n }\n\n /**\n * Get the default asset info for a network (typically USDC)\n *\n * @param network - The network to get asset info for\n * @returns The asset information including address, name, version, and decimals\n */\n private getDefaultAsset(network: Network): {\n address: string;\n name: string;\n version: string;\n decimals: number;\n } {\n // Map of network to USDC info including EIP-712 domain parameters\n // Each network has the right to determine its own default stablecoin that can be expressed as a USD string by calling servers\n // NOTE: Currently only EIP-3009 supporting stablecoins can be used with this scheme\n // Generic ERC20 support via EIP-2612/permit2 is planned, but not yet implemented.\n const stablecoins: Record<\n string,\n { address: string; name: string; version: string; decimals: number }\n > = {\n \"eip155:8453\": {\n address: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Base mainnet USDC\n \"eip155:84532\": {\n address: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Base Sepolia USDC\n };\n\n const assetInfo = stablecoins[network];\n if (!assetInfo) {\n throw new Error(`No default asset configured for network ${network}`);\n }\n\n return assetInfo;\n }\n}\n","import { x402ResourceServer } from \"@x402/core/server\";\nimport { Network } from \"@x402/core/types\";\nimport { ExactEvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering EVM schemes to an x402ResourceServer\n */\nexport interface EvmResourceServerConfig {\n /**\n * Optional specific networks to register\n * If not provided, registers wildcard support (eip155:*)\n */\n networks?: Network[];\n}\n\n/**\n * Registers EVM exact payment schemes to an x402ResourceServer instance.\n *\n * This function registers:\n * - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)\n *\n * @param server - The x402ResourceServer instance to register schemes to\n * @param config - Configuration for EVM resource server registration\n * @returns The server instance for chaining\n *\n * @example\n * ```typescript\n * import { registerExactEvmScheme } from \"@x402/evm/exact/server/register\";\n * import { x402ResourceServer } from \"@x402/core/server\";\n *\n * const server = new x402ResourceServer(facilitatorClient);\n * registerExactEvmScheme(server, {});\n * ```\n */\nexport function registerExactEvmScheme(\n server: x402ResourceServer,\n config: EvmResourceServerConfig = {},\n): x402ResourceServer {\n // Register V2 scheme\n if (config.networks && config.networks.length > 0) {\n // Register specific networks\n config.networks.forEach(network => {\n server.register(network, new ExactEvmScheme());\n });\n } else {\n // Register wildcard for all EVM chains\n server.register(\"eip155:*\", new ExactEvmScheme());\n }\n\n return server;\n}\n"],"mappings":";;;;;;;;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;AAAA;AAAA,IACF;AAEA,UAAM,YAAY,YAAY,OAAO;AACrC,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,MAAM,2CAA2C,OAAO,EAAE;AAAA,IACtE;AAEA,WAAO;AAAA,EACT;AACF;;;AClLO,SAAS,uBACd,QACA,SAAkC,CAAC,GACf;AAEpB,MAAI,OAAO,YAAY,OAAO,SAAS,SAAS,GAAG;AAEjD,WAAO,SAAS,QAAQ,aAAW;AACjC,aAAO,SAAS,SAAS,IAAI,eAAe,CAAC;AAAA,IAC/C,CAAC;AAAA,EACH,OAAO;AAEL,WAAO,SAAS,YAAY,IAAI,eAAe,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -67,18 +67,18 @@ declare class ExactEvmScheme implements SchemeNetworkServer {
|
|
|
67
67
|
private parseMoneyToDecimal;
|
|
68
68
|
/**
|
|
69
69
|
* Default money conversion implementation.
|
|
70
|
-
* Converts decimal amount to
|
|
70
|
+
* Converts decimal amount to the default stablecoin on the specified network.
|
|
71
71
|
*
|
|
72
72
|
* @param amount - The decimal amount (e.g., 1.50)
|
|
73
73
|
* @param network - The network to use
|
|
74
|
-
* @returns The parsed asset amount in
|
|
74
|
+
* @returns The parsed asset amount in the default stablecoin
|
|
75
75
|
*/
|
|
76
76
|
private defaultMoneyConversion;
|
|
77
77
|
/**
|
|
78
|
-
* Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal
|
|
78
|
+
* Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal tokens)
|
|
79
79
|
*
|
|
80
80
|
* @param decimalAmount - The decimal amount to convert
|
|
81
|
-
* @param
|
|
81
|
+
* @param decimals - The number of decimals for the token
|
|
82
82
|
* @returns The token amount as a string
|
|
83
83
|
*/
|
|
84
84
|
private convertToTokenAmount;
|
|
@@ -86,24 +86,9 @@ declare class ExactEvmScheme implements SchemeNetworkServer {
|
|
|
86
86
|
* Get the default asset info for a network (typically USDC)
|
|
87
87
|
*
|
|
88
88
|
* @param network - The network to get asset info for
|
|
89
|
-
* @returns The asset information including address, name, and
|
|
89
|
+
* @returns The asset information including address, name, version, and decimals
|
|
90
90
|
*/
|
|
91
91
|
private getDefaultAsset;
|
|
92
|
-
/**
|
|
93
|
-
* Get asset info for a given symbol on a network
|
|
94
|
-
*
|
|
95
|
-
* @param symbol - The asset symbol
|
|
96
|
-
* @param network - The network to use
|
|
97
|
-
* @returns The asset information including address, name, and version
|
|
98
|
-
*/
|
|
99
|
-
private getAssetInfo;
|
|
100
|
-
/**
|
|
101
|
-
* Get the number of decimals for the asset
|
|
102
|
-
*
|
|
103
|
-
* @param _ - The network to use (unused)
|
|
104
|
-
* @returns The number of decimals for the asset
|
|
105
|
-
*/
|
|
106
|
-
private getAssetDecimals;
|
|
107
92
|
}
|
|
108
93
|
|
|
109
94
|
/**
|
|
@@ -95,15 +95,15 @@ var ExactEvmScheme = class {
|
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
97
|
* Default money conversion implementation.
|
|
98
|
-
* Converts decimal amount to
|
|
98
|
+
* Converts decimal amount to the default stablecoin on the specified network.
|
|
99
99
|
*
|
|
100
100
|
* @param amount - The decimal amount (e.g., 1.50)
|
|
101
101
|
* @param network - The network to use
|
|
102
|
-
* @returns The parsed asset amount in
|
|
102
|
+
* @returns The parsed asset amount in the default stablecoin
|
|
103
103
|
*/
|
|
104
104
|
defaultMoneyConversion(amount, network) {
|
|
105
|
-
const tokenAmount = this.convertToTokenAmount(amount.toString(), network);
|
|
106
105
|
const assetInfo = this.getDefaultAsset(network);
|
|
106
|
+
const tokenAmount = this.convertToTokenAmount(amount.toString(), assetInfo.decimals);
|
|
107
107
|
return {
|
|
108
108
|
amount: tokenAmount,
|
|
109
109
|
asset: assetInfo.address,
|
|
@@ -114,14 +114,13 @@ var ExactEvmScheme = class {
|
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
|
-
* Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal
|
|
117
|
+
* Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal tokens)
|
|
118
118
|
*
|
|
119
119
|
* @param decimalAmount - The decimal amount to convert
|
|
120
|
-
* @param
|
|
120
|
+
* @param decimals - The number of decimals for the token
|
|
121
121
|
* @returns The token amount as a string
|
|
122
122
|
*/
|
|
123
|
-
convertToTokenAmount(decimalAmount,
|
|
124
|
-
const decimals = this.getAssetDecimals(network);
|
|
123
|
+
convertToTokenAmount(decimalAmount, decimals) {
|
|
125
124
|
const amount = parseFloat(decimalAmount);
|
|
126
125
|
if (isNaN(amount)) {
|
|
127
126
|
throw new Error(`Invalid amount: ${decimalAmount}`);
|
|
@@ -135,64 +134,31 @@ var ExactEvmScheme = class {
|
|
|
135
134
|
* Get the default asset info for a network (typically USDC)
|
|
136
135
|
*
|
|
137
136
|
* @param network - The network to get asset info for
|
|
138
|
-
* @returns The asset information including address, name, and
|
|
137
|
+
* @returns The asset information including address, name, version, and decimals
|
|
139
138
|
*/
|
|
140
139
|
getDefaultAsset(network) {
|
|
141
|
-
const
|
|
140
|
+
const stablecoins = {
|
|
142
141
|
"eip155:8453": {
|
|
143
142
|
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
144
143
|
name: "USD Coin",
|
|
145
|
-
version: "2"
|
|
144
|
+
version: "2",
|
|
145
|
+
decimals: 6
|
|
146
146
|
},
|
|
147
147
|
// Base mainnet USDC
|
|
148
148
|
"eip155:84532": {
|
|
149
149
|
address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
150
150
|
name: "USDC",
|
|
151
|
-
version: "2"
|
|
152
|
-
|
|
153
|
-
// Base Sepolia USDC
|
|
154
|
-
"eip155:1": {
|
|
155
|
-
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
156
|
-
name: "USD Coin",
|
|
157
|
-
version: "2"
|
|
158
|
-
},
|
|
159
|
-
// Ethereum mainnet USDC
|
|
160
|
-
"eip155:11155111": {
|
|
161
|
-
address: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
|
|
162
|
-
name: "USDC",
|
|
163
|
-
version: "2"
|
|
151
|
+
version: "2",
|
|
152
|
+
decimals: 6
|
|
164
153
|
}
|
|
165
|
-
// Sepolia USDC
|
|
154
|
+
// Base Sepolia USDC
|
|
166
155
|
};
|
|
167
|
-
const assetInfo =
|
|
156
|
+
const assetInfo = stablecoins[network];
|
|
168
157
|
if (!assetInfo) {
|
|
169
158
|
throw new Error(`No default asset configured for network ${network}`);
|
|
170
159
|
}
|
|
171
160
|
return assetInfo;
|
|
172
161
|
}
|
|
173
|
-
/**
|
|
174
|
-
* Get asset info for a given symbol on a network
|
|
175
|
-
*
|
|
176
|
-
* @param symbol - The asset symbol
|
|
177
|
-
* @param network - The network to use
|
|
178
|
-
* @returns The asset information including address, name, and version
|
|
179
|
-
*/
|
|
180
|
-
getAssetInfo(symbol, network) {
|
|
181
|
-
const upperSymbol = symbol.toUpperCase();
|
|
182
|
-
if (upperSymbol === "USDC" || upperSymbol === "USD") {
|
|
183
|
-
return this.getDefaultAsset(network);
|
|
184
|
-
}
|
|
185
|
-
throw new Error(`Unsupported asset: ${symbol} on network ${network}`);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Get the number of decimals for the asset
|
|
189
|
-
*
|
|
190
|
-
* @param _ - The network to use (unused)
|
|
191
|
-
* @returns The number of decimals for the asset
|
|
192
|
-
*/
|
|
193
|
-
getAssetDecimals(_) {
|
|
194
|
-
return 6;
|
|
195
|
-
}
|
|
196
162
|
};
|
|
197
163
|
|
|
198
164
|
// src/exact/server/register.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/exact/server/scheme.ts","../../../../src/exact/server/register.ts"],"sourcesContent":["import {\n AssetAmount,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@x402/core/types\";\n\n/**\n * EVM server implementation for the Exact payment scheme.\n */\nexport class ExactEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"exact\";\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Register a custom money parser in the parser chain.\n * Multiple parsers can be registered - they will be tried in registration order.\n * Each parser receives a decimal amount (e.g., 1.50 for $1.50).\n * If a parser returns null, the next parser in the chain will be tried.\n * The default parser is always the final fallback.\n *\n * @param parser - Custom function to convert amount to AssetAmount (or null to skip)\n * @returns The server instance for chaining\n *\n * @example\n * evmServer.registerMoneyParser(async (amount, network) => {\n * // Custom conversion logic\n * if (amount > 100) {\n * // Use different token for large amounts\n * return { amount: (amount * 1e18).toString(), asset: \"0xCustomToken\" };\n * }\n * return null; // Use next parser\n * });\n */\n registerMoneyParser(parser: MoneyParser): ExactEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Parses a price into an asset amount.\n * If price is already an AssetAmount, returns it directly.\n * If price is Money (string | number), parses to decimal and tries custom parsers.\n * Falls back to default conversion if all custom parsers return null.\n *\n * @param price - The price to parse\n * @param network - The network to use\n * @returns Promise that resolves to the parsed asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n // If already an AssetAmount, return it directly\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n // Parse Money to decimal number\n const amount = this.parseMoneyToDecimal(price);\n\n // Try each custom money parser in order\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n // All custom parsers returned null, use default conversion\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Build payment requirements for this scheme/network combination\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported kind from facilitator (unused)\n * @param supportedKind.x402Version - The x402 version\n * @param supportedKind.scheme - The logical payment scheme\n * @param supportedKind.network - The network identifier in CAIP-2 format\n * @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details\n * @param extensionKeys - Extension keys supported by the facilitator (unused)\n * @returns Payment requirements ready to be sent to clients\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n // Mark unused parameters to satisfy linter\n void supportedKind;\n void extensionKeys;\n return Promise.resolve(paymentRequirements);\n }\n\n /**\n * Parse Money (string | number) to a decimal number.\n * Handles formats like \"$1.50\", \"1.50\", 1.50, etc.\n *\n * @param money - The money value to parse\n * @returns Decimal number\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n // Remove $ sign and whitespace, then parse\n const cleanMoney = money.replace(/^\\$/, \"\").trim();\n const amount = parseFloat(cleanMoney);\n\n if (isNaN(amount)) {\n throw new Error(`Invalid money format: ${money}`);\n }\n\n return amount;\n }\n\n /**\n * Default money conversion implementation.\n * Converts decimal amount to USDC on the specified network.\n *\n * @param amount - The decimal amount (e.g., 1.50)\n * @param network - The network to use\n * @returns The parsed asset amount in USDC\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n // Convert decimal amount to token amount (USDC has 6 decimals)\n const tokenAmount = this.convertToTokenAmount(amount.toString(), network);\n const assetInfo = this.getDefaultAsset(network);\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n name: assetInfo.name,\n version: assetInfo.version,\n },\n };\n }\n\n /**\n * Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal USDC)\n *\n * @param decimalAmount - The decimal amount to convert\n * @param network - The network to use\n * @returns The token amount as a string\n */\n private convertToTokenAmount(decimalAmount: string, network: Network): string {\n const decimals = this.getAssetDecimals(network);\n const amount = parseFloat(decimalAmount);\n if (isNaN(amount)) {\n throw new Error(`Invalid amount: ${decimalAmount}`);\n }\n // Convert to smallest unit (e.g., for USDC with 6 decimals: 0.10 * 10^6 = 100000)\n const [intPart, decPart = \"\"] = String(amount).split(\".\");\n const paddedDec = decPart.padEnd(decimals, \"0\").slice(0, decimals);\n const tokenAmount = (intPart + paddedDec).replace(/^0+/, \"\") || \"0\";\n return tokenAmount;\n }\n\n /**\n * Get the default asset info for a network (typically USDC)\n *\n * @param network - The network to get asset info for\n * @returns The asset information including address, name, and version\n */\n private getDefaultAsset(network: Network): { address: string; name: string; version: string } {\n // Map of network to USDC info including EIP-712 domain parameters\n const usdcInfo: Record<string, { address: string; name: string; version: string }> = {\n \"eip155:8453\": {\n address: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n name: \"USD Coin\",\n version: \"2\",\n }, // Base mainnet USDC\n \"eip155:84532\": {\n address: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n name: \"USDC\",\n version: \"2\",\n }, // Base Sepolia USDC\n \"eip155:1\": {\n address: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n name: \"USD Coin\",\n version: \"2\",\n }, // Ethereum mainnet USDC\n \"eip155:11155111\": {\n address: \"0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238\",\n name: \"USDC\",\n version: \"2\",\n }, // Sepolia USDC\n };\n\n const assetInfo = usdcInfo[network];\n if (!assetInfo) {\n throw new Error(`No default asset configured for network ${network}`);\n }\n\n return assetInfo;\n }\n\n /**\n * Get asset info for a given symbol on a network\n *\n * @param symbol - The asset symbol\n * @param network - The network to use\n * @returns The asset information including address, name, and version\n */\n private getAssetInfo(\n symbol: string,\n network: Network,\n ): { address: string; name: string; version: string } {\n const upperSymbol = symbol.toUpperCase();\n\n // For now, only support USDC\n if (upperSymbol === \"USDC\" || upperSymbol === \"USD\") {\n return this.getDefaultAsset(network);\n }\n\n // Could extend to support other tokens\n throw new Error(`Unsupported asset: ${symbol} on network ${network}`);\n }\n\n /**\n * Get the number of decimals for the asset\n *\n * @param _ - The network to use (unused)\n * @returns The number of decimals for the asset\n */\n private getAssetDecimals(_: Network): number {\n // USDC has 6 decimals on all EVM chains\n return 6;\n }\n}\n","import { x402ResourceServer } from \"@x402/core/server\";\nimport { Network } from \"@x402/core/types\";\nimport { ExactEvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering EVM schemes to an x402ResourceServer\n */\nexport interface EvmResourceServerConfig {\n /**\n * Optional specific networks to register\n * If not provided, registers wildcard support (eip155:*)\n */\n networks?: Network[];\n}\n\n/**\n * Registers EVM exact payment schemes to an x402ResourceServer instance.\n *\n * This function registers:\n * - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)\n *\n * @param server - The x402ResourceServer instance to register schemes to\n * @param config - Configuration for EVM resource server registration\n * @returns The server instance for chaining\n *\n * @example\n * ```typescript\n * import { registerExactEvmScheme } from \"@x402/evm/exact/server/register\";\n * import { x402ResourceServer } from \"@x402/core/server\";\n *\n * const server = new x402ResourceServer(facilitatorClient);\n * registerExactEvmScheme(server, {});\n * ```\n */\nexport function registerExactEvmScheme(\n server: x402ResourceServer,\n config: EvmResourceServerConfig = {},\n): x402ResourceServer {\n // Register V2 scheme\n if (config.networks && config.networks.length > 0) {\n // Register specific networks\n config.networks.forEach(network => {\n server.register(network, new ExactEvmScheme());\n });\n } else {\n // Register wildcard for all EVM chains\n server.register(\"eip155:*\", new ExactEvmScheme());\n }\n\n return server;\n}\n"],"mappings":";AAYO,IAAM,iBAAN,MAAoD;AAAA,EAApD;AACL,SAAS,SAAS;AAClB,SAAQ,eAA8B,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBvC,oBAAoB,QAAqC;AACvD,SAAK,aAAa,KAAK,MAAM;AAC7B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,WAAW,OAAc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gBAAgB,UAAU,gBAAgB,OAAO;AACnD,aAAO,KAAK,gBAAgB,OAAO;AAAA,IACrC;AAGA,UAAM,IAAI,MAAM,sBAAsB,MAAM,eAAe,OAAO,EAAE;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,iBAAiB,GAAoB;AAE3C,WAAO;AAAA,EACT;AACF;;;AClNO,SAAS,uBACd,QACA,SAAkC,CAAC,GACf;AAEpB,MAAI,OAAO,YAAY,OAAO,SAAS,SAAS,GAAG;AAEjD,WAAO,SAAS,QAAQ,aAAW;AACjC,aAAO,SAAS,SAAS,IAAI,eAAe,CAAC;AAAA,IAC/C,CAAC;AAAA,EACH,OAAO;AAEL,WAAO,SAAS,YAAY,IAAI,eAAe,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/exact/server/scheme.ts","../../../../src/exact/server/register.ts"],"sourcesContent":["import {\n AssetAmount,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@x402/core/types\";\n\n/**\n * EVM server implementation for the Exact payment scheme.\n */\nexport class ExactEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"exact\";\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Register a custom money parser in the parser chain.\n * Multiple parsers can be registered - they will be tried in registration order.\n * Each parser receives a decimal amount (e.g., 1.50 for $1.50).\n * If a parser returns null, the next parser in the chain will be tried.\n * The default parser is always the final fallback.\n *\n * @param parser - Custom function to convert amount to AssetAmount (or null to skip)\n * @returns The server instance for chaining\n *\n * @example\n * evmServer.registerMoneyParser(async (amount, network) => {\n * // Custom conversion logic\n * if (amount > 100) {\n * // Use different token for large amounts\n * return { amount: (amount * 1e18).toString(), asset: \"0xCustomToken\" };\n * }\n * return null; // Use next parser\n * });\n */\n registerMoneyParser(parser: MoneyParser): ExactEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Parses a price into an asset amount.\n * If price is already an AssetAmount, returns it directly.\n * If price is Money (string | number), parses to decimal and tries custom parsers.\n * Falls back to default conversion if all custom parsers return null.\n *\n * @param price - The price to parse\n * @param network - The network to use\n * @returns Promise that resolves to the parsed asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n // If already an AssetAmount, return it directly\n if (typeof price === \"object\" && price !== null && \"amount\" in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n };\n }\n\n // Parse Money to decimal number\n const amount = this.parseMoneyToDecimal(price);\n\n // Try each custom money parser in order\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n // All custom parsers returned null, use default conversion\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Build payment requirements for this scheme/network combination\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported kind from facilitator (unused)\n * @param supportedKind.x402Version - The x402 version\n * @param supportedKind.scheme - The logical payment scheme\n * @param supportedKind.network - The network identifier in CAIP-2 format\n * @param supportedKind.extra - Optional extra metadata regarding scheme/network implementation details\n * @param extensionKeys - Extension keys supported by the facilitator (unused)\n * @returns Payment requirements ready to be sent to clients\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n // Mark unused parameters to satisfy linter\n void supportedKind;\n void extensionKeys;\n return Promise.resolve(paymentRequirements);\n }\n\n /**\n * Parse Money (string | number) to a decimal number.\n * Handles formats like \"$1.50\", \"1.50\", 1.50, etc.\n *\n * @param money - The money value to parse\n * @returns Decimal number\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n // Remove $ sign and whitespace, then parse\n const cleanMoney = money.replace(/^\\$/, \"\").trim();\n const amount = parseFloat(cleanMoney);\n\n if (isNaN(amount)) {\n throw new Error(`Invalid money format: ${money}`);\n }\n\n return amount;\n }\n\n /**\n * Default money conversion implementation.\n * Converts decimal amount to the default stablecoin on the specified network.\n *\n * @param amount - The decimal amount (e.g., 1.50)\n * @param network - The network to use\n * @returns The parsed asset amount in the default stablecoin\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const assetInfo = this.getDefaultAsset(network);\n const tokenAmount = this.convertToTokenAmount(amount.toString(), assetInfo.decimals);\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n name: assetInfo.name,\n version: assetInfo.version,\n },\n };\n }\n\n /**\n * Convert decimal amount to token units (e.g., 0.10 -> 100000 for 6-decimal tokens)\n *\n * @param decimalAmount - The decimal amount to convert\n * @param decimals - The number of decimals for the token\n * @returns The token amount as a string\n */\n private convertToTokenAmount(decimalAmount: string, decimals: number): string {\n const amount = parseFloat(decimalAmount);\n if (isNaN(amount)) {\n throw new Error(`Invalid amount: ${decimalAmount}`);\n }\n // Convert to smallest unit (e.g., for USDC with 6 decimals: 0.10 * 10^6 = 100000)\n const [intPart, decPart = \"\"] = String(amount).split(\".\");\n const paddedDec = decPart.padEnd(decimals, \"0\").slice(0, decimals);\n const tokenAmount = (intPart + paddedDec).replace(/^0+/, \"\") || \"0\";\n return tokenAmount;\n }\n\n /**\n * Get the default asset info for a network (typically USDC)\n *\n * @param network - The network to get asset info for\n * @returns The asset information including address, name, version, and decimals\n */\n private getDefaultAsset(network: Network): {\n address: string;\n name: string;\n version: string;\n decimals: number;\n } {\n // Map of network to USDC info including EIP-712 domain parameters\n // Each network has the right to determine its own default stablecoin that can be expressed as a USD string by calling servers\n // NOTE: Currently only EIP-3009 supporting stablecoins can be used with this scheme\n // Generic ERC20 support via EIP-2612/permit2 is planned, but not yet implemented.\n const stablecoins: Record<\n string,\n { address: string; name: string; version: string; decimals: number }\n > = {\n \"eip155:8453\": {\n address: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Base mainnet USDC\n \"eip155:84532\": {\n address: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Base Sepolia USDC\n };\n\n const assetInfo = stablecoins[network];\n if (!assetInfo) {\n throw new Error(`No default asset configured for network ${network}`);\n }\n\n return assetInfo;\n }\n}\n","import { x402ResourceServer } from \"@x402/core/server\";\nimport { Network } from \"@x402/core/types\";\nimport { ExactEvmScheme } from \"./scheme\";\n\n/**\n * Configuration options for registering EVM schemes to an x402ResourceServer\n */\nexport interface EvmResourceServerConfig {\n /**\n * Optional specific networks to register\n * If not provided, registers wildcard support (eip155:*)\n */\n networks?: Network[];\n}\n\n/**\n * Registers EVM exact payment schemes to an x402ResourceServer instance.\n *\n * This function registers:\n * - V2: eip155:* wildcard scheme with ExactEvmScheme (or specific networks if provided)\n *\n * @param server - The x402ResourceServer instance to register schemes to\n * @param config - Configuration for EVM resource server registration\n * @returns The server instance for chaining\n *\n * @example\n * ```typescript\n * import { registerExactEvmScheme } from \"@x402/evm/exact/server/register\";\n * import { x402ResourceServer } from \"@x402/core/server\";\n *\n * const server = new x402ResourceServer(facilitatorClient);\n * registerExactEvmScheme(server, {});\n * ```\n */\nexport function registerExactEvmScheme(\n server: x402ResourceServer,\n config: EvmResourceServerConfig = {},\n): x402ResourceServer {\n // Register V2 scheme\n if (config.networks && config.networks.length > 0) {\n // Register specific networks\n config.networks.forEach(network => {\n server.register(network, new ExactEvmScheme());\n });\n } else {\n // Register wildcard for all EVM chains\n server.register(\"eip155:*\", new ExactEvmScheme());\n }\n\n return server;\n}\n"],"mappings":";AAYO,IAAM,iBAAN,MAAoD;AAAA,EAApD;AACL,SAAS,SAAS;AAClB,SAAQ,eAA8B,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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B,MAAI,OAAO,YAAY,OAAO,SAAS,SAAS,GAAG;AAEjD,WAAO,SAAS,QAAQ,aAAW;AACjC,aAAO,SAAS,SAAS,IAAI,eAAe,CAAC;AAAA,IAC/C,CAAC;AAAA,EACH,OAAO;AAEL,WAAO,SAAS,YAAY,IAAI,eAAe,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x402/evm",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/cjs/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"viem": "^2.39.3",
|
|
37
37
|
"zod": "^3.24.2",
|
|
38
|
-
"@x402/core": "2.
|
|
38
|
+
"@x402/core": "^2.2.0"
|
|
39
39
|
},
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|