@x402x/extensions 2.0.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/index.d.mts +1891 -0
- package/dist/index.d.ts +1891 -0
- package/dist/index.js +1548 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1458 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +51 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1891 @@
|
|
|
1
|
+
import { Chain, Address as Address$1 } from 'viem';
|
|
2
|
+
import { PaymentRequirements, ResourceServerExtension, Network, SchemeNetworkFacilitator, PaymentPayload } from '@x402/core/types';
|
|
3
|
+
export { Network, PaymentPayload, PaymentRequirements } from '@x402/core/types';
|
|
4
|
+
import { x402ResourceServer } from '@x402/core/server';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Type definitions for @x402x/extensions
|
|
8
|
+
*
|
|
9
|
+
* Re-exports official x402 v2 types from @x402/core
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Signer interface for x402x
|
|
14
|
+
* Compatible with x402 v2 client signer patterns
|
|
15
|
+
*/
|
|
16
|
+
interface Signer {
|
|
17
|
+
address: string;
|
|
18
|
+
signTypedData?: (params: unknown) => Promise<string>;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Commitment calculation parameters
|
|
23
|
+
* All parameters must match exactly with SettlementRouter.sol
|
|
24
|
+
*/
|
|
25
|
+
interface CommitmentParams {
|
|
26
|
+
/** Chain ID (e.g., 84532 for Base Sepolia) */
|
|
27
|
+
chainId: number;
|
|
28
|
+
/** SettlementRouter contract address */
|
|
29
|
+
hub: string;
|
|
30
|
+
/** Asset contract address (ERC-3009 token, e.g., USDC) */
|
|
31
|
+
asset: string;
|
|
32
|
+
/** Payer address */
|
|
33
|
+
from: string;
|
|
34
|
+
/** Payment amount in asset's smallest unit */
|
|
35
|
+
value: string;
|
|
36
|
+
/** Authorization valid after timestamp */
|
|
37
|
+
validAfter: string;
|
|
38
|
+
/** Authorization valid before timestamp */
|
|
39
|
+
validBefore: string;
|
|
40
|
+
/** Unique salt for idempotency (32 bytes) */
|
|
41
|
+
salt: string;
|
|
42
|
+
/** Final recipient address */
|
|
43
|
+
payTo: string;
|
|
44
|
+
/** Facilitator fee amount */
|
|
45
|
+
facilitatorFee: string;
|
|
46
|
+
/** Hook contract address */
|
|
47
|
+
hook: string;
|
|
48
|
+
/** Encoded hook parameters */
|
|
49
|
+
hookData: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Gas model for different networks
|
|
53
|
+
*/
|
|
54
|
+
type GasModel = "eip1559" | "legacy";
|
|
55
|
+
/**
|
|
56
|
+
* Network metadata containing protocol-level information
|
|
57
|
+
*/
|
|
58
|
+
interface NetworkMetadata {
|
|
59
|
+
/** Gas pricing model used by the network */
|
|
60
|
+
gasModel: GasModel;
|
|
61
|
+
/** Native token symbol */
|
|
62
|
+
nativeToken: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Demo hooks configuration for showcase examples
|
|
66
|
+
*/
|
|
67
|
+
interface DemoHooks {
|
|
68
|
+
/** NFTMintHook contract address */
|
|
69
|
+
nftMint?: string;
|
|
70
|
+
/** RandomNFT contract address */
|
|
71
|
+
randomNFT?: string;
|
|
72
|
+
/** RewardHook contract address */
|
|
73
|
+
reward?: string;
|
|
74
|
+
/** RewardToken contract address */
|
|
75
|
+
rewardToken?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Network configuration for x402x
|
|
79
|
+
*/
|
|
80
|
+
interface NetworkConfig {
|
|
81
|
+
/** Chain ID */
|
|
82
|
+
chainId: number;
|
|
83
|
+
/** Network Name */
|
|
84
|
+
name: string;
|
|
85
|
+
/** Network Type */
|
|
86
|
+
type: "mainnet" | "testnet";
|
|
87
|
+
/** Network Address Explorer Base URL */
|
|
88
|
+
addressExplorerBaseUrl: string;
|
|
89
|
+
/** Network Transaction Explorer Base URL */
|
|
90
|
+
txExplorerBaseUrl: string;
|
|
91
|
+
/** SettlementRouter contract address */
|
|
92
|
+
settlementRouter: string;
|
|
93
|
+
/** Default asset configuration (ERC-3009 token, typically USDC) */
|
|
94
|
+
defaultAsset: {
|
|
95
|
+
/** Asset contract address */
|
|
96
|
+
address: string;
|
|
97
|
+
/** Asset decimals */
|
|
98
|
+
decimals: number;
|
|
99
|
+
/** EIP-712 domain info for signing */
|
|
100
|
+
eip712: {
|
|
101
|
+
/** Asset contract name (for EIP-712) */
|
|
102
|
+
name: string;
|
|
103
|
+
/** Asset contract version (for EIP-712) */
|
|
104
|
+
version: string;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
/** Builtin hook addresses */
|
|
108
|
+
hooks: {
|
|
109
|
+
/** TransferHook address */
|
|
110
|
+
transfer: string;
|
|
111
|
+
};
|
|
112
|
+
/** Demo hooks configuration (optional, for showcase examples) */
|
|
113
|
+
demoHooks?: DemoHooks;
|
|
114
|
+
/** Network metadata */
|
|
115
|
+
metadata?: NetworkMetadata;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Core settlement parameters (without EIP-712 domain info)
|
|
119
|
+
*/
|
|
120
|
+
interface SettlementExtraCore {
|
|
121
|
+
/** SettlementRouter contract address */
|
|
122
|
+
settlementRouter: string;
|
|
123
|
+
/** Unique salt for idempotency (32 bytes) */
|
|
124
|
+
salt: string;
|
|
125
|
+
/** Final recipient address */
|
|
126
|
+
payTo: string;
|
|
127
|
+
/** Facilitator fee amount */
|
|
128
|
+
facilitatorFee: string;
|
|
129
|
+
/** Hook contract address */
|
|
130
|
+
hook: string;
|
|
131
|
+
/** Encoded hook parameters */
|
|
132
|
+
hookData: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Settlement extra parameters for PaymentRequirements
|
|
136
|
+
* Includes EIP-712 domain info (name, version) for asset signature validation
|
|
137
|
+
*/
|
|
138
|
+
interface SettlementExtra extends SettlementExtraCore {
|
|
139
|
+
/** Asset contract name (for EIP-712) */
|
|
140
|
+
name: string;
|
|
141
|
+
/** Asset contract version (for EIP-712) */
|
|
142
|
+
version: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Error thrown when settlement extra parameters are invalid
|
|
146
|
+
*/
|
|
147
|
+
declare class SettlementExtraError extends Error {
|
|
148
|
+
constructor(message: string);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Money type - string or number representing USD amount
|
|
153
|
+
*/
|
|
154
|
+
type Money = string | number;
|
|
155
|
+
/**
|
|
156
|
+
* Resource information for payment required responses
|
|
157
|
+
*/
|
|
158
|
+
interface Resource {
|
|
159
|
+
url: string;
|
|
160
|
+
description?: string;
|
|
161
|
+
mimeType?: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Middleware utility functions for x402x v2 packages
|
|
166
|
+
*
|
|
167
|
+
* These utilities provide helpers for route matching, JSON encoding,
|
|
168
|
+
* and other common middleware operations.
|
|
169
|
+
*/
|
|
170
|
+
/**
|
|
171
|
+
* Route configuration for payment requirements
|
|
172
|
+
*/
|
|
173
|
+
interface RouteConfig {
|
|
174
|
+
price: string | number;
|
|
175
|
+
network?: string;
|
|
176
|
+
extra?: Record<string, unknown>;
|
|
177
|
+
extensions?: Record<string, unknown>;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Routes configuration - mapping of route patterns to configs
|
|
181
|
+
*/
|
|
182
|
+
type RoutesConfig = Record<string, RouteConfig | string | number>;
|
|
183
|
+
/**
|
|
184
|
+
* Compiled route pattern with regex
|
|
185
|
+
*/
|
|
186
|
+
interface RoutePattern {
|
|
187
|
+
verb: string;
|
|
188
|
+
pattern: RegExp;
|
|
189
|
+
config: RouteConfig;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Compute route patterns from routes config
|
|
193
|
+
*
|
|
194
|
+
* Converts route configuration into compiled patterns with regex matching.
|
|
195
|
+
*
|
|
196
|
+
* **Note**: When a route is specified as a simple price value (string or number),
|
|
197
|
+
* it is automatically converted to a RouteConfig with network defaulting to "base-sepolia".
|
|
198
|
+
* For production use, explicitly specify the network in your route configuration.
|
|
199
|
+
*
|
|
200
|
+
* @param routes - Routes configuration
|
|
201
|
+
* @returns Array of route patterns
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const routes = {
|
|
206
|
+
* 'GET /api/data': { price: '0.01', network: 'base-sepolia' },
|
|
207
|
+
* '/public/*': '0' // Defaults to base-sepolia network
|
|
208
|
+
* };
|
|
209
|
+
* const patterns = computeRoutePatterns(routes);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
declare function computeRoutePatterns(routes: RoutesConfig): RoutePattern[];
|
|
213
|
+
/**
|
|
214
|
+
* Find matching route for given path and method
|
|
215
|
+
*
|
|
216
|
+
* @param routePatterns - Compiled route patterns
|
|
217
|
+
* @param path - Request path
|
|
218
|
+
* @param method - HTTP method
|
|
219
|
+
* @returns Matching route pattern or undefined
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const route = findMatchingRoute(patterns, '/api/data', 'GET');
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
declare function findMatchingRoute(routePatterns: RoutePattern[], path: string, method: string): RoutePattern | undefined;
|
|
227
|
+
/**
|
|
228
|
+
* Find matching payment requirements from list
|
|
229
|
+
*
|
|
230
|
+
* This is a placeholder for finding requirements that match certain criteria.
|
|
231
|
+
* In v2, this logic is typically handled by the x402Client/x402ResourceServer classes.
|
|
232
|
+
*
|
|
233
|
+
* @param requirements - List of payment requirements
|
|
234
|
+
* @param network - Optional network filter
|
|
235
|
+
* @returns First matching requirement or undefined
|
|
236
|
+
*/
|
|
237
|
+
declare function findMatchingPaymentRequirements<T>(requirements: T[], network?: string): T | undefined;
|
|
238
|
+
/**
|
|
239
|
+
* Convert value to JSON-safe format
|
|
240
|
+
*
|
|
241
|
+
* Handles BigInt and other non-JSON-serializable types.
|
|
242
|
+
*
|
|
243
|
+
* @param value - Value to convert
|
|
244
|
+
* @returns JSON-safe representation
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* const safe = toJsonSafe({ amount: 1000000n }); // { amount: "1000000" }
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
declare function toJsonSafe(value: unknown): unknown;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Commitment calculation utilities
|
|
255
|
+
*
|
|
256
|
+
* The commitment hash binds all settlement parameters to the client's signature,
|
|
257
|
+
* preventing parameter tampering attacks.
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Calculate commitment hash for x402x settlement
|
|
262
|
+
*
|
|
263
|
+
* This hash becomes the EIP-3009 nonce, cryptographically binding all settlement
|
|
264
|
+
* parameters to the client's signature. The parameter order must exactly match
|
|
265
|
+
* SettlementRouter.sol.
|
|
266
|
+
*
|
|
267
|
+
* @param params - All settlement parameters
|
|
268
|
+
* @returns bytes32 commitment hash
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```typescript
|
|
272
|
+
* const commitment = calculateCommitment({
|
|
273
|
+
* chainId: 84532,
|
|
274
|
+
* hub: '0x...',
|
|
275
|
+
* asset: '0x...',
|
|
276
|
+
* from: '0x...',
|
|
277
|
+
* value: '100000',
|
|
278
|
+
* validAfter: '0',
|
|
279
|
+
* validBefore: '1234567890',
|
|
280
|
+
* salt: '0x...',
|
|
281
|
+
* payTo: '0x...',
|
|
282
|
+
* facilitatorFee: '10000',
|
|
283
|
+
* hook: '0x...',
|
|
284
|
+
* hookData: '0x',
|
|
285
|
+
* });
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
declare function calculateCommitment(params: CommitmentParams): string;
|
|
289
|
+
/**
|
|
290
|
+
* Generate a random salt for settlement uniqueness
|
|
291
|
+
*
|
|
292
|
+
* Works in both Node.js and browser environments.
|
|
293
|
+
* Uses crypto.getRandomValues (Web Crypto API) which is available in:
|
|
294
|
+
* - Modern browsers
|
|
295
|
+
* - Node.js 15+ (via global crypto)
|
|
296
|
+
* - Older Node.js (via crypto.webcrypto)
|
|
297
|
+
*
|
|
298
|
+
* @returns bytes32 hex string (0x + 64 hex characters)
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```typescript
|
|
302
|
+
* const salt = generateSalt();
|
|
303
|
+
* // => '0x1234567890abcdef...'
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
declare function generateSalt(): string;
|
|
307
|
+
/**
|
|
308
|
+
* Validate commitment parameters
|
|
309
|
+
*
|
|
310
|
+
* @param params - Commitment parameters to validate
|
|
311
|
+
* @throws Error if validation fails
|
|
312
|
+
*/
|
|
313
|
+
declare function validateCommitmentParams(params: CommitmentParams): void;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Network configuration for x402x
|
|
317
|
+
*
|
|
318
|
+
* Contains deployed contract addresses and configuration for each supported network.
|
|
319
|
+
* Uses official x402 v2 CAIP-2 network identifiers.
|
|
320
|
+
*/
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Network configurations for all supported networks
|
|
324
|
+
*
|
|
325
|
+
* Uses getNetworkId() and getDefaultAsset() to ensure consistency
|
|
326
|
+
* with CAIP-2 network identifiers.
|
|
327
|
+
*/
|
|
328
|
+
declare const networks: Record<string, NetworkConfig>;
|
|
329
|
+
/**
|
|
330
|
+
* Get network configuration by network name
|
|
331
|
+
*
|
|
332
|
+
* @param network - Network name (e.g., 'base-sepolia', 'skale-base-sepolia')
|
|
333
|
+
* @returns Network configuration
|
|
334
|
+
* @throws Error if network is not supported
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```typescript
|
|
338
|
+
* const config = getNetworkConfig('base-sepolia');
|
|
339
|
+
* console.log(config.settlementRouter);
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
declare function getNetworkConfig(network: string): NetworkConfig;
|
|
343
|
+
/**
|
|
344
|
+
* Check if a network is supported
|
|
345
|
+
*
|
|
346
|
+
* @param network - Network name to check
|
|
347
|
+
* @returns True if network is supported
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```typescript
|
|
351
|
+
* if (isNetworkSupported('base-sepolia')) {
|
|
352
|
+
* // proceed...
|
|
353
|
+
* }
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
declare function isNetworkSupported(network: string): boolean;
|
|
357
|
+
/**
|
|
358
|
+
* Get list of all supported network names (human-readable identifiers)
|
|
359
|
+
*
|
|
360
|
+
* Returns user-friendly network names like "base-sepolia", "base", etc.
|
|
361
|
+
* Use this for UI display, configuration, and user-facing operations.
|
|
362
|
+
*
|
|
363
|
+
* @returns Array of supported network names
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```typescript
|
|
367
|
+
* const networks = getSupportedNetworkNames();
|
|
368
|
+
* // => ['base-sepolia', 'base', 'x-layer-testnet', ...]
|
|
369
|
+
*
|
|
370
|
+
* // For UI dropdown
|
|
371
|
+
* <select>
|
|
372
|
+
* {networks.map(name => <option key={name}>{name}</option>)}
|
|
373
|
+
* </select>
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
declare function getSupportedNetworkNames(): string[];
|
|
377
|
+
/**
|
|
378
|
+
* @deprecated Use getSupportedNetworkNames() instead for clarity
|
|
379
|
+
* Get list of all supported networks
|
|
380
|
+
*/
|
|
381
|
+
declare function getSupportedNetworks(): string[];
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Chain definitions for x402x supported networks
|
|
385
|
+
*
|
|
386
|
+
* This module provides viem chain configurations for all supported networks,
|
|
387
|
+
* including custom definitions for chains not in viem's standard list.
|
|
388
|
+
*/
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Get viem chain configuration for a network name
|
|
392
|
+
*
|
|
393
|
+
* Checks custom chains first, then falls back to viem's standard chains.
|
|
394
|
+
*
|
|
395
|
+
* @param network - Network name (e.g., "base-sepolia", "x-layer-testnet")
|
|
396
|
+
* @returns Viem chain configuration
|
|
397
|
+
* @throws Error if network is not supported
|
|
398
|
+
*
|
|
399
|
+
* @example
|
|
400
|
+
* ```typescript
|
|
401
|
+
* const chain = getChain("x-layer-testnet");
|
|
402
|
+
* // => { id: 1952, name: "X Layer Testnet", ... }
|
|
403
|
+
*
|
|
404
|
+
* const baseChain = getChain("base-sepolia");
|
|
405
|
+
* // => { id: 84532, name: "Base Sepolia", ... }
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
declare function getChain(network: string): Chain;
|
|
409
|
+
/**
|
|
410
|
+
* Get viem chain configuration by chain ID
|
|
411
|
+
*
|
|
412
|
+
* @param chainId - Chain ID
|
|
413
|
+
* @returns Viem chain configuration
|
|
414
|
+
* @throws Error if chain ID is not supported
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* const chain = getChainById(1952);
|
|
419
|
+
* // => { id: 1952, name: "X Layer Testnet", ... }
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
declare function getChainById(chainId: number): Chain;
|
|
423
|
+
/**
|
|
424
|
+
* Get all custom chain definitions
|
|
425
|
+
*
|
|
426
|
+
* @returns Record of chain ID to chain configuration
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```typescript
|
|
430
|
+
* const customs = getCustomChains();
|
|
431
|
+
* // => { 1952: { id: 1952, name: "X Layer Testnet", ... }, ... }
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
declare function getCustomChains(): Record<number, Chain>;
|
|
435
|
+
/**
|
|
436
|
+
* Check if a chain ID has a custom definition
|
|
437
|
+
*
|
|
438
|
+
* @param chainId - Chain ID to check
|
|
439
|
+
* @returns True if chain has custom definition
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```typescript
|
|
443
|
+
* isCustomChain(1952); // true (X Layer Testnet)
|
|
444
|
+
* isCustomChain(84532); // false (Base Sepolia - in viem)
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
declare function isCustomChain(chainId: number): boolean;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* TransferHook utilities
|
|
451
|
+
*
|
|
452
|
+
* TransferHook is a builtin hook that supports two modes:
|
|
453
|
+
* 1. Simple Transfer: Direct transfer to a single recipient (data = '0x')
|
|
454
|
+
* 2. Distributed Transfer: Split transfer to multiple recipients by percentage
|
|
455
|
+
*/
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Split configuration for distributed transfer
|
|
459
|
+
*/
|
|
460
|
+
interface Split {
|
|
461
|
+
/** Recipient address */
|
|
462
|
+
recipient: Address$1;
|
|
463
|
+
/** Basis points (1-10000, where 10000 = 100%, 1 = 0.01%) */
|
|
464
|
+
bips: number;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* TransferHook utilities namespace
|
|
468
|
+
*/
|
|
469
|
+
declare namespace TransferHook {
|
|
470
|
+
/**
|
|
471
|
+
* Encode hookData for TransferHook
|
|
472
|
+
*
|
|
473
|
+
* Supports two modes:
|
|
474
|
+
*
|
|
475
|
+
* **Mode 1 - Simple Transfer** (no parameters):
|
|
476
|
+
* - Transfers entire amount to the `recipient` address in ExecuteParams
|
|
477
|
+
* - Most gas efficient
|
|
478
|
+
* - Returns '0x'
|
|
479
|
+
*
|
|
480
|
+
* **Mode 2 - Distributed Transfer** (with splits):
|
|
481
|
+
* - Distributes amount to multiple recipients based on percentage (bips)
|
|
482
|
+
* - Each split specifies recipient address and basis points (1-10000)
|
|
483
|
+
* - If total bips < 10000, remaining goes to the `recipient` in ExecuteParams
|
|
484
|
+
* - If total bips = 10000, `recipient` receives nothing
|
|
485
|
+
*
|
|
486
|
+
* @param splits - Optional array of split configurations
|
|
487
|
+
* @returns Encoded hookData as hex string
|
|
488
|
+
* @throws Error if validation fails (invalid addresses, bips > 10000, etc.)
|
|
489
|
+
*
|
|
490
|
+
* @example Simple transfer
|
|
491
|
+
* ```typescript
|
|
492
|
+
* // All amount goes to recipient
|
|
493
|
+
* const hookData = TransferHook.encode();
|
|
494
|
+
* // => '0x'
|
|
495
|
+
*
|
|
496
|
+
* await client.execute({
|
|
497
|
+
* hook: TransferHook.getAddress('base-sepolia'),
|
|
498
|
+
* hookData,
|
|
499
|
+
* amount: '100',
|
|
500
|
+
* recipient: '0xAlice...' // Alice receives 100%
|
|
501
|
+
* });
|
|
502
|
+
* ```
|
|
503
|
+
*
|
|
504
|
+
* @example Distributed transfer - full split
|
|
505
|
+
* ```typescript
|
|
506
|
+
* // Split between Alice (60%) and Bob (40%)
|
|
507
|
+
* const hookData = TransferHook.encode([
|
|
508
|
+
* { recipient: '0xAlice...', bips: 6000 }, // 60%
|
|
509
|
+
* { recipient: '0xBob...', bips: 4000 } // 40%
|
|
510
|
+
* ]);
|
|
511
|
+
*
|
|
512
|
+
* await client.execute({
|
|
513
|
+
* hook: TransferHook.getAddress('base-sepolia'),
|
|
514
|
+
* hookData,
|
|
515
|
+
* amount: '100',
|
|
516
|
+
* recipient: '0xCharity...' // Charity receives 0% (total = 100%)
|
|
517
|
+
* });
|
|
518
|
+
* ```
|
|
519
|
+
*
|
|
520
|
+
* @example Distributed transfer - partial split
|
|
521
|
+
* ```typescript
|
|
522
|
+
* // Platform takes 30%, creator gets the rest
|
|
523
|
+
* const hookData = TransferHook.encode([
|
|
524
|
+
* { recipient: '0xPlatform...', bips: 3000 } // 30%
|
|
525
|
+
* ]);
|
|
526
|
+
*
|
|
527
|
+
* await client.execute({
|
|
528
|
+
* hook: TransferHook.getAddress('base-sepolia'),
|
|
529
|
+
* hookData,
|
|
530
|
+
* amount: '100',
|
|
531
|
+
* recipient: '0xCreator...' // Creator receives 70%
|
|
532
|
+
* });
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
function encode(splits?: Split[]): string;
|
|
536
|
+
/**
|
|
537
|
+
* Get TransferHook address for a specific network
|
|
538
|
+
*
|
|
539
|
+
* @param network - Network name (e.g., 'base-sepolia')
|
|
540
|
+
* @returns TransferHook contract address
|
|
541
|
+
* @throws Error if network is not supported
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* ```typescript
|
|
545
|
+
* const address = TransferHook.getAddress('base-sepolia');
|
|
546
|
+
* // => '0x4DE234059C6CcC94B8fE1eb1BD24804794083569'
|
|
547
|
+
* ```
|
|
548
|
+
*/
|
|
549
|
+
function getAddress(network: string): string;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Demo hooks utilities for showcase examples
|
|
554
|
+
*
|
|
555
|
+
* Provides encoding/decoding and address lookup for demo hooks used in showcase examples.
|
|
556
|
+
* These hooks are optional and may not be deployed on all networks.
|
|
557
|
+
*/
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* NFT Mint Configuration
|
|
561
|
+
*/
|
|
562
|
+
interface MintConfig {
|
|
563
|
+
/** Address of the NFT contract to mint from */
|
|
564
|
+
nftContract: Address$1;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Reward Hook Configuration
|
|
568
|
+
*/
|
|
569
|
+
interface RewardConfig {
|
|
570
|
+
/** Address of the ERC20 reward token contract */
|
|
571
|
+
rewardToken: Address$1;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* NFTMintHook utilities for showcase examples
|
|
575
|
+
*/
|
|
576
|
+
declare namespace NFTMintHook {
|
|
577
|
+
/**
|
|
578
|
+
* Get NFTMintHook contract address for a specific network
|
|
579
|
+
*
|
|
580
|
+
* @param network - Network identifier (e.g., 'base-sepolia', 'skale-base-sepolia')
|
|
581
|
+
* @returns The contract address for the specified network
|
|
582
|
+
* @throws Error if demo hooks are not configured for the network
|
|
583
|
+
*/
|
|
584
|
+
function getAddress(network: string): `0x${string}`;
|
|
585
|
+
/**
|
|
586
|
+
* Get the NFT contract address for a specific network
|
|
587
|
+
*
|
|
588
|
+
* This is the address of the ERC721 contract that will be minted from.
|
|
589
|
+
*
|
|
590
|
+
* @param network - Network identifier (e.g., 'base-sepolia', 'skale-base-sepolia')
|
|
591
|
+
* @returns The NFT contract address for the specified network
|
|
592
|
+
* @throws Error if demo hooks are not configured for the network
|
|
593
|
+
*/
|
|
594
|
+
function getNFTContractAddress(network: string): `0x${string}`;
|
|
595
|
+
/**
|
|
596
|
+
* Encode MintConfig into hookData for NFTMintHook
|
|
597
|
+
*
|
|
598
|
+
* The NFTMintHook contract expects a specific ABI-encoded struct format.
|
|
599
|
+
* This method handles the encoding for you.
|
|
600
|
+
*
|
|
601
|
+
* @param config - The mint configuration
|
|
602
|
+
* @returns ABI-encoded hookData ready to use with x402x execute
|
|
603
|
+
*/
|
|
604
|
+
function encode(config: MintConfig): `0x${string}`;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* RewardHook utilities for showcase examples
|
|
608
|
+
*/
|
|
609
|
+
declare namespace RewardHook {
|
|
610
|
+
/**
|
|
611
|
+
* Get RewardHook contract address for a specific network
|
|
612
|
+
*
|
|
613
|
+
* @param network - Network identifier (e.g., 'base-sepolia', 'skale-base-sepolia')
|
|
614
|
+
* @returns The contract address for the specified network
|
|
615
|
+
* @throws Error if demo hooks are not configured for the network
|
|
616
|
+
*/
|
|
617
|
+
function getAddress(network: string): `0x${string}`;
|
|
618
|
+
/**
|
|
619
|
+
* Get the reward token (ERC20) address for a specific network
|
|
620
|
+
*
|
|
621
|
+
* This is the address of the ERC20 contract that will be distributed as rewards.
|
|
622
|
+
*
|
|
623
|
+
* @param network - Network identifier (e.g., 'base-sepolia', 'skale-base-sepolia')
|
|
624
|
+
* @returns The reward token contract address for the specified network
|
|
625
|
+
* @throws Error if demo hooks are not configured for the network
|
|
626
|
+
*/
|
|
627
|
+
function getTokenAddress(network: string): `0x${string}`;
|
|
628
|
+
/**
|
|
629
|
+
* Encode RewardConfig into hookData for RewardHook
|
|
630
|
+
*
|
|
631
|
+
* The RewardHook contract expects a specific ABI-encoded struct format.
|
|
632
|
+
* This method handles the encoding for you.
|
|
633
|
+
*
|
|
634
|
+
* @param config - The reward configuration
|
|
635
|
+
* @returns ABI-encoded hookData ready to use with x402x execute
|
|
636
|
+
*/
|
|
637
|
+
function encode(config: RewardConfig): `0x${string}`;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Utility functions for x402x
|
|
642
|
+
*/
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Add settlement extension to PaymentRequirements
|
|
646
|
+
*
|
|
647
|
+
* This function enriches standard x402 PaymentRequirements with settlement-specific
|
|
648
|
+
* parameters in the `extra` field.
|
|
649
|
+
*
|
|
650
|
+
* @param requirements - Base PaymentRequirements (standard x402)
|
|
651
|
+
* @param params - Settlement parameters
|
|
652
|
+
* @returns Enhanced PaymentRequirements with settlement extra
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* ```typescript
|
|
656
|
+
* import { addSettlementExtra, TransferHook, getNetworkConfig } from '@x402x/core';
|
|
657
|
+
*
|
|
658
|
+
* const baseRequirements = {
|
|
659
|
+
* scheme: 'exact',
|
|
660
|
+
* network: 'base-sepolia',
|
|
661
|
+
* maxAmountRequired: '100000',
|
|
662
|
+
* asset: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',
|
|
663
|
+
* payTo: '0x...',
|
|
664
|
+
* resource: '/api/payment',
|
|
665
|
+
* };
|
|
666
|
+
*
|
|
667
|
+
* const requirements = addSettlementExtra(baseRequirements, {
|
|
668
|
+
* hook: TransferHook.getAddress('base-sepolia'),
|
|
669
|
+
* hookData: TransferHook.encode(),
|
|
670
|
+
* facilitatorFee: '10000',
|
|
671
|
+
* payTo: merchantAddress,
|
|
672
|
+
* });
|
|
673
|
+
* ```
|
|
674
|
+
*/
|
|
675
|
+
declare function addSettlementExtra(requirements: PaymentRequirements, params: {
|
|
676
|
+
hook: string;
|
|
677
|
+
hookData: string;
|
|
678
|
+
facilitatorFee?: string;
|
|
679
|
+
payTo?: string;
|
|
680
|
+
salt?: string;
|
|
681
|
+
}): PaymentRequirements;
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Extension helpers for x402x
|
|
685
|
+
* Implements x402x-router-settlement extension for PaymentRequired.extensions
|
|
686
|
+
*/
|
|
687
|
+
/**
|
|
688
|
+
* Router settlement extension info
|
|
689
|
+
* Contains all settlement-specific parameters that were previously in extra
|
|
690
|
+
*/
|
|
691
|
+
interface RouterSettlementExtensionInfo {
|
|
692
|
+
/** Schema version for the extension */
|
|
693
|
+
schemaVersion: number;
|
|
694
|
+
/** Optional description of the extension */
|
|
695
|
+
description?: string;
|
|
696
|
+
/** Unique salt for idempotency (32 bytes hex, dynamically generated) */
|
|
697
|
+
salt?: string;
|
|
698
|
+
/** Settlement router contract address */
|
|
699
|
+
settlementRouter?: string;
|
|
700
|
+
/** Hook contract address */
|
|
701
|
+
hook?: string;
|
|
702
|
+
/** Encoded hook parameters (hex string) */
|
|
703
|
+
hookData?: string;
|
|
704
|
+
/** Final recipient address (renamed from payTo to avoid confusion with accepts[].payTo) */
|
|
705
|
+
finalPayTo?: string;
|
|
706
|
+
/** Facilitator fee amount in token's smallest unit */
|
|
707
|
+
facilitatorFee?: string;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Router settlement extension structure
|
|
711
|
+
* Location: PaymentRequired.extensions["x402x-router-settlement"]
|
|
712
|
+
*/
|
|
713
|
+
interface RouterSettlementExtension {
|
|
714
|
+
/** Extension information */
|
|
715
|
+
info: RouterSettlementExtensionInfo;
|
|
716
|
+
/** Optional JSON schema for validation */
|
|
717
|
+
schema?: Record<string, unknown>;
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Create x402x-router-settlement extension declaration
|
|
721
|
+
*
|
|
722
|
+
* This extension informs clients that the server supports router settlement functionality.
|
|
723
|
+
* Clients MUST echo extensions in their payment payload.
|
|
724
|
+
*
|
|
725
|
+
* @param params - Extension parameters
|
|
726
|
+
* @param params.description - Optional description of the extension
|
|
727
|
+
* @param params.schema - Optional JSON schema for validation
|
|
728
|
+
* @param params.settlementRouter - Settlement router contract address
|
|
729
|
+
* @param params.hook - Hook contract address
|
|
730
|
+
* @param params.hookData - Encoded hook parameters
|
|
731
|
+
* @param params.finalPayTo - Final recipient address
|
|
732
|
+
* @param params.facilitatorFee - Facilitator fee amount
|
|
733
|
+
* @returns Extension object for PaymentRequired.extensions["x402x-router-settlement"]
|
|
734
|
+
*
|
|
735
|
+
* @example
|
|
736
|
+
* ```typescript
|
|
737
|
+
* const extension = createRouterSettlementExtension({
|
|
738
|
+
* description: "Settlement router with atomic fee distribution",
|
|
739
|
+
* settlementRouter: "0x...",
|
|
740
|
+
* hook: "0x...",
|
|
741
|
+
* hookData: "0x",
|
|
742
|
+
* finalPayTo: "0x...",
|
|
743
|
+
* facilitatorFee: "0"
|
|
744
|
+
* });
|
|
745
|
+
*
|
|
746
|
+
* const paymentRequired = {
|
|
747
|
+
* x402Version: 2,
|
|
748
|
+
* resource: { url: "/api/payment", ... },
|
|
749
|
+
* accepts: [...],
|
|
750
|
+
* extensions: {
|
|
751
|
+
* "x402x-router-settlement": extension
|
|
752
|
+
* }
|
|
753
|
+
* };
|
|
754
|
+
* ```
|
|
755
|
+
*/
|
|
756
|
+
declare function createRouterSettlementExtension(params?: {
|
|
757
|
+
description?: string;
|
|
758
|
+
schema?: Record<string, unknown>;
|
|
759
|
+
settlementRouter?: string;
|
|
760
|
+
hook?: string;
|
|
761
|
+
hookData?: string;
|
|
762
|
+
finalPayTo?: string;
|
|
763
|
+
facilitatorFee?: string;
|
|
764
|
+
}): RouterSettlementExtension;
|
|
765
|
+
/**
|
|
766
|
+
* Get the extension key for router settlement
|
|
767
|
+
*
|
|
768
|
+
* @returns The extension key "x402x-router-settlement"
|
|
769
|
+
*/
|
|
770
|
+
declare function getRouterSettlementExtensionKey(): string;
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* x402x Router Settlement Server Extension
|
|
774
|
+
*
|
|
775
|
+
* Implements ResourceServerExtension interface to integrate router settlement
|
|
776
|
+
* functionality into x402 v2 resource servers.
|
|
777
|
+
*/
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* Extension key constant
|
|
781
|
+
*/
|
|
782
|
+
declare const ROUTER_SETTLEMENT_KEY = "x402x-router-settlement";
|
|
783
|
+
/**
|
|
784
|
+
* x402x Router Settlement ResourceServerExtension
|
|
785
|
+
*
|
|
786
|
+
* This extension enriches PaymentRequired responses with router settlement
|
|
787
|
+
* information, enabling clients to use the SettlementRouter for atomic payments.
|
|
788
|
+
*
|
|
789
|
+
* The extension dynamically generates per-request values like salt to ensure
|
|
790
|
+
* each payment authorization is unique and cannot be replayed.
|
|
791
|
+
*
|
|
792
|
+
* @example
|
|
793
|
+
* ```typescript
|
|
794
|
+
* import { x402ResourceServer } from "@x402/core/server";
|
|
795
|
+
* import { routerSettlementServerExtension } from "@x402x/extensions";
|
|
796
|
+
*
|
|
797
|
+
* const server = new x402ResourceServer(facilitatorClient);
|
|
798
|
+
* server.registerExtension(routerSettlementServerExtension);
|
|
799
|
+
* ```
|
|
800
|
+
*/
|
|
801
|
+
declare const routerSettlementServerExtension: ResourceServerExtension;
|
|
802
|
+
/**
|
|
803
|
+
* Create extension declaration for routes
|
|
804
|
+
*
|
|
805
|
+
* Helper function to create properly formatted extension declarations
|
|
806
|
+
* for use in route configurations. The extension enables dynamic salt
|
|
807
|
+
* generation per request and includes all settlement parameters.
|
|
808
|
+
*
|
|
809
|
+
* @param params - Extension parameters including settlement info
|
|
810
|
+
* @returns Extension declaration object
|
|
811
|
+
*
|
|
812
|
+
* @example
|
|
813
|
+
* ```typescript
|
|
814
|
+
* const routes = {
|
|
815
|
+
* "GET /api/data": {
|
|
816
|
+
* accepts: { scheme: "exact", price: "$0.01", network: "eip155:84532", payTo: "0x..." },
|
|
817
|
+
* extensions: createExtensionDeclaration({
|
|
818
|
+
* description: "Router settlement with dynamic salt",
|
|
819
|
+
* settlementRouter: "0x...",
|
|
820
|
+
* hook: "0x...",
|
|
821
|
+
* hookData: "0x",
|
|
822
|
+
* finalPayTo: "0x...",
|
|
823
|
+
* facilitatorFee: "0"
|
|
824
|
+
* })
|
|
825
|
+
* }
|
|
826
|
+
* };
|
|
827
|
+
* ```
|
|
828
|
+
*/
|
|
829
|
+
declare function createExtensionDeclaration(params?: {
|
|
830
|
+
description?: string;
|
|
831
|
+
schema?: Record<string, unknown>;
|
|
832
|
+
settlementRouter?: string;
|
|
833
|
+
hook?: string;
|
|
834
|
+
hookData?: string;
|
|
835
|
+
finalPayTo?: string;
|
|
836
|
+
facilitatorFee?: string;
|
|
837
|
+
}): Record<string, unknown>;
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Settlement Routes Helper
|
|
841
|
+
*
|
|
842
|
+
* Provides utilities for creating route configurations with router settlement support.
|
|
843
|
+
* This module bridges the gap between x402 v2 official SDK's RoutesConfig and x402x
|
|
844
|
+
* settlement requirements.
|
|
845
|
+
*/
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Route configuration from @x402/core
|
|
849
|
+
* Re-exported for convenience with settlement prefix to avoid naming conflicts
|
|
850
|
+
*/
|
|
851
|
+
interface SettlementRouteConfig {
|
|
852
|
+
accepts: SettlementPaymentOption | SettlementPaymentOption[];
|
|
853
|
+
resource?: string;
|
|
854
|
+
description?: string;
|
|
855
|
+
mimeType?: string;
|
|
856
|
+
extensions?: Record<string, unknown>;
|
|
857
|
+
unpaidResponseBody?: (context: unknown) => Promise<{
|
|
858
|
+
contentType: string;
|
|
859
|
+
body: unknown;
|
|
860
|
+
}> | {
|
|
861
|
+
contentType: string;
|
|
862
|
+
body: unknown;
|
|
863
|
+
};
|
|
864
|
+
customPaywallHtml?: string;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Payment option from @x402/core
|
|
868
|
+
*/
|
|
869
|
+
interface SettlementPaymentOption {
|
|
870
|
+
scheme: string;
|
|
871
|
+
network: string;
|
|
872
|
+
payTo: string | ((context: unknown) => string | Promise<string>);
|
|
873
|
+
price: string | ((context: unknown) => string | Promise<string>);
|
|
874
|
+
maxTimeoutSeconds?: number;
|
|
875
|
+
extra?: Record<string, unknown>;
|
|
876
|
+
}
|
|
877
|
+
/**
|
|
878
|
+
* Settlement options for route configuration
|
|
879
|
+
*/
|
|
880
|
+
interface SettlementOptions {
|
|
881
|
+
/** Hook contract address (optional, defaults to TransferHook for the network) */
|
|
882
|
+
hook?: string;
|
|
883
|
+
/** Encoded hook data (optional, defaults to TransferHook.encode()) */
|
|
884
|
+
hookData?: string;
|
|
885
|
+
/** Facilitator fee amount (optional, will be dynamically calculated if not provided) */
|
|
886
|
+
facilitatorFee?: string;
|
|
887
|
+
/** Final recipient address (the actual merchant/payee) */
|
|
888
|
+
finalPayTo: string;
|
|
889
|
+
/** Optional description for the extension */
|
|
890
|
+
description?: string;
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Configuration for settlement hooks
|
|
894
|
+
*/
|
|
895
|
+
interface SettlementHooksConfig {
|
|
896
|
+
/** Whether to enable automatic salt extraction from extension info */
|
|
897
|
+
enableSaltExtraction?: boolean;
|
|
898
|
+
/** Whether to validate settlement router parameters */
|
|
899
|
+
validateSettlementParams?: boolean;
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* Create a route configuration with router settlement support
|
|
903
|
+
*
|
|
904
|
+
* This helper wraps the standard x402 RouteConfig and adds settlement-specific
|
|
905
|
+
* configuration including hooks, settlement router address, and dynamic extensions.
|
|
906
|
+
*
|
|
907
|
+
* The key insight: We add settlement info to the `extra` field of PaymentRequirements,
|
|
908
|
+
* which gets passed through verify/settle. The extension generates dynamic salt per request.
|
|
909
|
+
*
|
|
910
|
+
* @param baseConfig - Base route configuration
|
|
911
|
+
* @param settlementOptions - Settlement-specific options
|
|
912
|
+
* @returns Enhanced route configuration with settlement support
|
|
913
|
+
*
|
|
914
|
+
* @example
|
|
915
|
+
* ```typescript
|
|
916
|
+
* import { createSettlementRouteConfig, TransferHook } from "@x402x/extensions";
|
|
917
|
+
*
|
|
918
|
+
* const routes = {
|
|
919
|
+
* "POST /api/purchase": createSettlementRouteConfig({
|
|
920
|
+
* accepts: {
|
|
921
|
+
* scheme: "exact",
|
|
922
|
+
* network: "eip155:84532",
|
|
923
|
+
* payTo: "0x...", // Will be overridden with settlementRouter
|
|
924
|
+
* price: "$1.00",
|
|
925
|
+
* },
|
|
926
|
+
* description: "Purchase endpoint",
|
|
927
|
+
* }, {
|
|
928
|
+
* hook: TransferHook.getAddress("base-sepolia"),
|
|
929
|
+
* hookData: TransferHook.encode(),
|
|
930
|
+
* finalPayTo: "0xMerchantAddress",
|
|
931
|
+
* })
|
|
932
|
+
* };
|
|
933
|
+
* ```
|
|
934
|
+
*/
|
|
935
|
+
declare function createSettlementRouteConfig(baseConfig: SettlementRouteConfig, settlementOptions: SettlementOptions): SettlementRouteConfig;
|
|
936
|
+
/**
|
|
937
|
+
* Register settlement-specific hooks with the resource server
|
|
938
|
+
*
|
|
939
|
+
* This function registers lifecycle hooks for handling settlement-specific logic:
|
|
940
|
+
* - Extract salt from extension info before verification
|
|
941
|
+
* - Validate settlement router parameters
|
|
942
|
+
*
|
|
943
|
+
* @param server - x402ResourceServer instance
|
|
944
|
+
* @param config - Hook configuration options
|
|
945
|
+
*
|
|
946
|
+
* @example
|
|
947
|
+
* ```typescript
|
|
948
|
+
* import { registerSettlementHooks } from "@x402x/extensions";
|
|
949
|
+
*
|
|
950
|
+
* registerSettlementHooks(server, {
|
|
951
|
+
* enableSaltExtraction: true,
|
|
952
|
+
* validateSettlementParams: true,
|
|
953
|
+
* });
|
|
954
|
+
* ```
|
|
955
|
+
*/
|
|
956
|
+
declare function registerSettlementHooks(server: x402ResourceServer, config?: SettlementHooksConfig): void;
|
|
957
|
+
|
|
958
|
+
/**
|
|
959
|
+
* Type definitions for facilitator services
|
|
960
|
+
*
|
|
961
|
+
* These types define the interfaces and configurations used by facilitator
|
|
962
|
+
* implementations that handle payment verification and settlement.
|
|
963
|
+
*/
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* Ethereum address type
|
|
967
|
+
*/
|
|
968
|
+
type Address = `0x${string}`;
|
|
969
|
+
/**
|
|
970
|
+
* Response from facilitator verification
|
|
971
|
+
*/
|
|
972
|
+
interface VerifyResponse$1 {
|
|
973
|
+
/** Whether the payment payload is valid */
|
|
974
|
+
isValid: boolean;
|
|
975
|
+
/** Reason for invalidity if isValid is false */
|
|
976
|
+
invalidReason?: string;
|
|
977
|
+
/** Payer address extracted from the payload */
|
|
978
|
+
payer?: string;
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* Response from facilitator settlement
|
|
982
|
+
*/
|
|
983
|
+
interface SettleResponse$1 {
|
|
984
|
+
/** Whether the settlement was successful */
|
|
985
|
+
success: boolean;
|
|
986
|
+
/** Transaction hash of the settlement */
|
|
987
|
+
transaction: string;
|
|
988
|
+
/** Network the settlement was executed on (CAIP-2 format) */
|
|
989
|
+
network: Network;
|
|
990
|
+
/** Payer address */
|
|
991
|
+
payer?: string;
|
|
992
|
+
/** Error reason if settlement failed */
|
|
993
|
+
errorReason?: string;
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Configuration for RouterSettlementFacilitator
|
|
997
|
+
*/
|
|
998
|
+
interface FacilitatorConfig {
|
|
999
|
+
/** Signer address for facilitating settlements (optional, will be derived from privateKey if not provided) */
|
|
1000
|
+
signer?: Address;
|
|
1001
|
+
/** Private key for local signing (enables sending transactions on standard RPC providers) */
|
|
1002
|
+
privateKey?: string;
|
|
1003
|
+
/** Allowed SettlementRouter addresses per network */
|
|
1004
|
+
allowedRouters?: Record<string, string[]>;
|
|
1005
|
+
/** Optional RPC URLs per network */
|
|
1006
|
+
rpcUrls?: Record<string, string>;
|
|
1007
|
+
/** Gas configuration */
|
|
1008
|
+
gasConfig?: {
|
|
1009
|
+
maxGasLimit: bigint;
|
|
1010
|
+
gasMultiplier: number;
|
|
1011
|
+
};
|
|
1012
|
+
/** Fee configuration */
|
|
1013
|
+
feeConfig?: {
|
|
1014
|
+
minFee: string;
|
|
1015
|
+
maxFee: string;
|
|
1016
|
+
};
|
|
1017
|
+
/** Timeouts in milliseconds */
|
|
1018
|
+
timeouts?: {
|
|
1019
|
+
verify: number;
|
|
1020
|
+
settle: number;
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
/**
|
|
1024
|
+
* Parameters for SettlementRouter.settleAndExecute
|
|
1025
|
+
*/
|
|
1026
|
+
interface SettlementRouterParams {
|
|
1027
|
+
token: Address;
|
|
1028
|
+
from: Address;
|
|
1029
|
+
value: string;
|
|
1030
|
+
validAfter: string;
|
|
1031
|
+
validBefore: string;
|
|
1032
|
+
nonce: string;
|
|
1033
|
+
signature: string;
|
|
1034
|
+
salt: string;
|
|
1035
|
+
payTo: Address;
|
|
1036
|
+
facilitatorFee: string;
|
|
1037
|
+
hook: Address;
|
|
1038
|
+
hookData: string;
|
|
1039
|
+
settlementRouter: Address;
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Error types for facilitator operations
|
|
1043
|
+
*/
|
|
1044
|
+
declare class FacilitatorValidationError extends Error {
|
|
1045
|
+
constructor(message: string);
|
|
1046
|
+
}
|
|
1047
|
+
declare class SettlementRouterError extends Error {
|
|
1048
|
+
readonly cause?: unknown | undefined;
|
|
1049
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* Helper functions for x402x router settlement integration
|
|
1054
|
+
*
|
|
1055
|
+
* Provides convenient utilities for working with x402 v2 resource servers
|
|
1056
|
+
* and router settlement extensions.
|
|
1057
|
+
*/
|
|
1058
|
+
|
|
1059
|
+
/**
|
|
1060
|
+
* Register router settlement extension with a resource server
|
|
1061
|
+
*
|
|
1062
|
+
* @param server - x402ResourceServer instance
|
|
1063
|
+
* @returns The server instance for chaining
|
|
1064
|
+
*
|
|
1065
|
+
* @example
|
|
1066
|
+
* ```typescript
|
|
1067
|
+
* import { x402ResourceServer } from "@x402/core/server";
|
|
1068
|
+
* import { registerExactEvmScheme } from "@x402/evm/exact/server/register";
|
|
1069
|
+
* import { registerRouterSettlement } from "@x402x/extensions";
|
|
1070
|
+
*
|
|
1071
|
+
* const server = new x402ResourceServer(facilitatorClient);
|
|
1072
|
+
* registerExactEvmScheme(server, {});
|
|
1073
|
+
* registerRouterSettlement(server);
|
|
1074
|
+
* ```
|
|
1075
|
+
*/
|
|
1076
|
+
declare function registerRouterSettlement(server: x402ResourceServer): x402ResourceServer;
|
|
1077
|
+
/**
|
|
1078
|
+
* Create a router settlement facilitator
|
|
1079
|
+
*
|
|
1080
|
+
* Factory function to create a RouterSettlementFacilitator instance.
|
|
1081
|
+
*
|
|
1082
|
+
* Note: This requires @x402x/facilitator-sdk to be installed separately.
|
|
1083
|
+
*
|
|
1084
|
+
* @param config - Facilitator configuration
|
|
1085
|
+
* @returns RouterSettlementFacilitator instance
|
|
1086
|
+
*
|
|
1087
|
+
* @example
|
|
1088
|
+
* ```typescript
|
|
1089
|
+
* // First install the dependency:
|
|
1090
|
+
* // pnpm install @x402x/facilitator-sdk
|
|
1091
|
+
*
|
|
1092
|
+
* import { createX402xFacilitator } from "@x402x/extensions";
|
|
1093
|
+
* // Or import directly:
|
|
1094
|
+
* // import { createRouterSettlementFacilitator } from "@x402x/facilitator-sdk";
|
|
1095
|
+
*
|
|
1096
|
+
* const facilitator = createX402xFacilitator({
|
|
1097
|
+
* privateKey: process.env.FACILITATOR_PRIVATE_KEY,
|
|
1098
|
+
* rpcUrls: {
|
|
1099
|
+
* "base-sepolia": "https://sepolia.base.org",
|
|
1100
|
+
* },
|
|
1101
|
+
* allowedRouters: {
|
|
1102
|
+
* "base-sepolia": ["0x817e4f0ee2fbdaac426f1178e149f7dc98873ecb"],
|
|
1103
|
+
* },
|
|
1104
|
+
* });
|
|
1105
|
+
* ```
|
|
1106
|
+
*/
|
|
1107
|
+
declare function createX402xFacilitator(config: FacilitatorConfig): Promise<SchemeNetworkFacilitator>;
|
|
1108
|
+
/**
|
|
1109
|
+
* Options for adding router settlement parameters
|
|
1110
|
+
*/
|
|
1111
|
+
interface WithRouterSettlementOptions {
|
|
1112
|
+
/** Hook contract address (required) */
|
|
1113
|
+
hook: string;
|
|
1114
|
+
/** Encoded hook data (required) */
|
|
1115
|
+
hookData: string;
|
|
1116
|
+
/** Facilitator fee amount in atomic units (required) */
|
|
1117
|
+
facilitatorFee: string;
|
|
1118
|
+
/** Final recipient address (required) */
|
|
1119
|
+
payTo: string;
|
|
1120
|
+
/** Unique salt for idempotency (optional, will be auto-generated if not provided) */
|
|
1121
|
+
salt?: string;
|
|
1122
|
+
/** Asset name for EIP-712 (optional, will use network config default if not provided) */
|
|
1123
|
+
name?: string;
|
|
1124
|
+
/** Asset version for EIP-712 (optional, will use network config default if not provided) */
|
|
1125
|
+
version?: string;
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Add router settlement parameters to PaymentRequirements
|
|
1129
|
+
*
|
|
1130
|
+
* Enriches payment requirements with settlement router extra fields needed
|
|
1131
|
+
* for atomic settlement through the SettlementRouter contract.
|
|
1132
|
+
*
|
|
1133
|
+
* @param requirements - Base payment requirements from x402 middleware
|
|
1134
|
+
* @param options - Router settlement options
|
|
1135
|
+
* @returns Enhanced payment requirements with settlement extra
|
|
1136
|
+
*
|
|
1137
|
+
* @example
|
|
1138
|
+
* ```typescript
|
|
1139
|
+
* import { withRouterSettlement, TransferHook } from "@x402x/extensions";
|
|
1140
|
+
*
|
|
1141
|
+
* const baseRequirements = {
|
|
1142
|
+
* scheme: "exact",
|
|
1143
|
+
* network: "eip155:84532",
|
|
1144
|
+
* asset: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
1145
|
+
* amount: "1000000", // 1 USDC
|
|
1146
|
+
* payTo: merchantAddress,
|
|
1147
|
+
* };
|
|
1148
|
+
*
|
|
1149
|
+
* const requirements = withRouterSettlement(baseRequirements, {
|
|
1150
|
+
* hook: TransferHook.getAddress("base-sepolia"),
|
|
1151
|
+
* hookData: TransferHook.encode(),
|
|
1152
|
+
* facilitatorFee: "10000", // 0.01 USDC
|
|
1153
|
+
* payTo: merchantAddress,
|
|
1154
|
+
* });
|
|
1155
|
+
* ```
|
|
1156
|
+
*/
|
|
1157
|
+
declare function withRouterSettlement(requirements: Partial<PaymentRequirements>, options: WithRouterSettlementOptions): PaymentRequirements;
|
|
1158
|
+
/**
|
|
1159
|
+
* Check if payment requirements use router settlement mode
|
|
1160
|
+
*
|
|
1161
|
+
* @param requirements - Payment requirements to check
|
|
1162
|
+
* @returns True if router settlement is enabled
|
|
1163
|
+
*
|
|
1164
|
+
* @example
|
|
1165
|
+
* ```typescript
|
|
1166
|
+
* if (isRouterSettlement(requirements)) {
|
|
1167
|
+
* console.log("Using router settlement mode");
|
|
1168
|
+
* }
|
|
1169
|
+
* ```
|
|
1170
|
+
*/
|
|
1171
|
+
declare function isRouterSettlement(requirements: PaymentRequirements): boolean;
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* Validation helpers for PaymentRequirements.extra (settlement parameters)
|
|
1175
|
+
*/
|
|
1176
|
+
|
|
1177
|
+
/**
|
|
1178
|
+
* Validation result
|
|
1179
|
+
*/
|
|
1180
|
+
interface ValidationResult {
|
|
1181
|
+
/** Whether the validation passed */
|
|
1182
|
+
valid: boolean;
|
|
1183
|
+
/** Error message if validation failed */
|
|
1184
|
+
error?: string;
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* Validate Ethereum address format (0x followed by 40 hex characters)
|
|
1188
|
+
*
|
|
1189
|
+
* @param address - Address to validate
|
|
1190
|
+
* @returns true if valid Ethereum address
|
|
1191
|
+
*/
|
|
1192
|
+
declare function isValidAddress(address: string): boolean;
|
|
1193
|
+
/**
|
|
1194
|
+
* Validate hex string format (0x followed by even number of hex characters)
|
|
1195
|
+
*
|
|
1196
|
+
* @param hex - Hex string to validate
|
|
1197
|
+
* @returns true if valid hex string
|
|
1198
|
+
*/
|
|
1199
|
+
declare function isValidHex(hex: string): boolean;
|
|
1200
|
+
/**
|
|
1201
|
+
* Validate 32-byte hex string (0x followed by 64 hex characters)
|
|
1202
|
+
*
|
|
1203
|
+
* @param hex - Hex string to validate
|
|
1204
|
+
* @returns true if valid 32-byte hex string
|
|
1205
|
+
*/
|
|
1206
|
+
declare function isValid32ByteHex(hex: string): boolean;
|
|
1207
|
+
/**
|
|
1208
|
+
* Validate numeric string (non-negative integer)
|
|
1209
|
+
*
|
|
1210
|
+
* @param value - Value to validate
|
|
1211
|
+
* @returns true if valid numeric string
|
|
1212
|
+
*/
|
|
1213
|
+
declare function isValidNumericString(value: string): boolean;
|
|
1214
|
+
/**
|
|
1215
|
+
* Validate settlement extra parameters
|
|
1216
|
+
*
|
|
1217
|
+
* This validates all required fields for settlement through SettlementRouter.
|
|
1218
|
+
*
|
|
1219
|
+
* @param extra - Settlement extra parameters to validate
|
|
1220
|
+
* @returns Validation result with error message if invalid
|
|
1221
|
+
*
|
|
1222
|
+
* @example
|
|
1223
|
+
* ```typescript
|
|
1224
|
+
* const result = validateSettlementExtra({
|
|
1225
|
+
* settlementRouter: "0x1234...",
|
|
1226
|
+
* payTo: "0x5678...",
|
|
1227
|
+
* facilitatorFee: "10000",
|
|
1228
|
+
* hook: "0xabcd...",
|
|
1229
|
+
* hookData: "0x",
|
|
1230
|
+
* name: "USDC",
|
|
1231
|
+
* version: "2",
|
|
1232
|
+
* salt: "0x1234..."
|
|
1233
|
+
* });
|
|
1234
|
+
*
|
|
1235
|
+
* if (!result.valid) {
|
|
1236
|
+
* throw new Error(result.error);
|
|
1237
|
+
* }
|
|
1238
|
+
* ```
|
|
1239
|
+
*/
|
|
1240
|
+
declare function validateSettlementExtra(extra: Partial<SettlementExtra>): ValidationResult;
|
|
1241
|
+
/**
|
|
1242
|
+
* Assert that settlement extra parameters are valid
|
|
1243
|
+
* Throws SettlementExtraError if validation fails
|
|
1244
|
+
*
|
|
1245
|
+
* @param extra - Settlement extra parameters to validate
|
|
1246
|
+
* @throws {SettlementExtraError} If validation fails
|
|
1247
|
+
*
|
|
1248
|
+
* @example
|
|
1249
|
+
* ```typescript
|
|
1250
|
+
* try {
|
|
1251
|
+
* assertValidSettlementExtra(extra);
|
|
1252
|
+
* // Extra is valid, proceed with settlement
|
|
1253
|
+
* } catch (error) {
|
|
1254
|
+
* console.error("Invalid settlement extra:", error.message);
|
|
1255
|
+
* }
|
|
1256
|
+
* ```
|
|
1257
|
+
*/
|
|
1258
|
+
declare function assertValidSettlementExtra(extra: Partial<SettlementExtra>): asserts extra is SettlementExtra;
|
|
1259
|
+
|
|
1260
|
+
/**
|
|
1261
|
+
* Amount parsing and formatting utilities for x402x default asset (USDC)
|
|
1262
|
+
*/
|
|
1263
|
+
|
|
1264
|
+
/**
|
|
1265
|
+
* Error class for amount-related validation errors
|
|
1266
|
+
*/
|
|
1267
|
+
declare class AmountError extends Error {
|
|
1268
|
+
constructor(message: string);
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Parse amount from various formats to atomic units for the default asset (USDC)
|
|
1272
|
+
*
|
|
1273
|
+
* Supports multiple input formats:
|
|
1274
|
+
* - Dollar format: '$1.2' or '$1.20' → '1200000' (1.2 USDC)
|
|
1275
|
+
* - Decimal string: '1.2' or '1.20' → '1200000'
|
|
1276
|
+
* - Number: 1.2 → '1200000'
|
|
1277
|
+
*
|
|
1278
|
+
* Uses x402's processPriceToAtomicAmount for parsing. All string/number inputs
|
|
1279
|
+
* are treated as USD amounts, not atomic units.
|
|
1280
|
+
*
|
|
1281
|
+
* @param amount - Amount in various formats (USD, not atomic units)
|
|
1282
|
+
* @param network - Network name (required) - used to determine token decimals
|
|
1283
|
+
* @returns Amount in atomic units as string
|
|
1284
|
+
* @throws AmountError if amount format is invalid
|
|
1285
|
+
*
|
|
1286
|
+
* @example
|
|
1287
|
+
* ```typescript
|
|
1288
|
+
* parseDefaultAssetAmount('$1.2', 'base-sepolia') // '1200000'
|
|
1289
|
+
* parseDefaultAssetAmount('1.2', 'base-sepolia') // '1200000'
|
|
1290
|
+
* parseDefaultAssetAmount(1.2, 'base-sepolia') // '1200000'
|
|
1291
|
+
* parseDefaultAssetAmount('100', 'base-sepolia') // '100000000' (100 USDC, not 100 atomic units)
|
|
1292
|
+
* ```
|
|
1293
|
+
*/
|
|
1294
|
+
declare function parseDefaultAssetAmount(amount: string | number, network: Network): string;
|
|
1295
|
+
/**
|
|
1296
|
+
* Format atomic units to human-readable decimal string for the default asset (USDC)
|
|
1297
|
+
*
|
|
1298
|
+
* Automatically determines decimals from the network's default asset configuration.
|
|
1299
|
+
*
|
|
1300
|
+
* @param amount - Amount in atomic units
|
|
1301
|
+
* @param network - Network name (required) - used to determine token decimals
|
|
1302
|
+
* @returns Human-readable decimal string
|
|
1303
|
+
* @throws AmountError if amount is invalid
|
|
1304
|
+
*
|
|
1305
|
+
* @example
|
|
1306
|
+
* ```typescript
|
|
1307
|
+
* formatDefaultAssetAmount('1200000', 'base-sepolia') // '1.2'
|
|
1308
|
+
* formatDefaultAssetAmount('1000000', 'base-sepolia') // '1'
|
|
1309
|
+
* formatDefaultAssetAmount('1', 'base-sepolia') // '0.000001'
|
|
1310
|
+
* ```
|
|
1311
|
+
*/
|
|
1312
|
+
declare function formatDefaultAssetAmount(amount: string, network: Network): string;
|
|
1313
|
+
|
|
1314
|
+
/**
|
|
1315
|
+
* Facilitator API client utilities for x402x
|
|
1316
|
+
*
|
|
1317
|
+
* Provides client-side functions to interact with facilitator HTTP APIs.
|
|
1318
|
+
* This includes fee calculation and caching utilities, as well as
|
|
1319
|
+
* helper functions for settlement mode detection and validation.
|
|
1320
|
+
*/
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* Check if a payment request requires SettlementRouter mode
|
|
1324
|
+
*
|
|
1325
|
+
* This is a client-side utility to determine which settlement flow to use.
|
|
1326
|
+
*
|
|
1327
|
+
* @param paymentRequirements - Payment requirements from 402 response
|
|
1328
|
+
* @returns True if settlement mode is required
|
|
1329
|
+
*
|
|
1330
|
+
* @example
|
|
1331
|
+
* ```typescript
|
|
1332
|
+
* if (isSettlementMode(paymentRequirements)) {
|
|
1333
|
+
* // Use Settlement Router mode
|
|
1334
|
+
* await submitToFacilitator(...);
|
|
1335
|
+
* } else {
|
|
1336
|
+
* // Use standard x402 mode
|
|
1337
|
+
* await settle(...);
|
|
1338
|
+
* }
|
|
1339
|
+
* ```
|
|
1340
|
+
*/
|
|
1341
|
+
declare function isSettlementMode(paymentRequirements: PaymentRequirements): boolean;
|
|
1342
|
+
/**
|
|
1343
|
+
* Parse and validate settlement extra parameters
|
|
1344
|
+
*
|
|
1345
|
+
* This is useful for clients to validate payment requirements before submission.
|
|
1346
|
+
*
|
|
1347
|
+
* @param extra - Extra field from PaymentRequirements
|
|
1348
|
+
* @returns Parsed settlement extra parameters
|
|
1349
|
+
* @throws SettlementExtraError if parameters are invalid
|
|
1350
|
+
*
|
|
1351
|
+
* @example
|
|
1352
|
+
* ```typescript
|
|
1353
|
+
* try {
|
|
1354
|
+
* const extra = parseSettlementExtra(paymentRequirements.extra);
|
|
1355
|
+
* console.log('Hook:', extra.hook);
|
|
1356
|
+
* console.log('Facilitator Fee:', extra.facilitatorFee);
|
|
1357
|
+
* } catch (error) {
|
|
1358
|
+
* console.error('Invalid settlement parameters:', error);
|
|
1359
|
+
* }
|
|
1360
|
+
* ```
|
|
1361
|
+
*/
|
|
1362
|
+
declare function parseSettlementExtra(extra: unknown): SettlementExtraCore;
|
|
1363
|
+
/**
|
|
1364
|
+
* Result of facilitator fee calculation
|
|
1365
|
+
*
|
|
1366
|
+
* This interface represents the response from facilitator's /calculate-fee endpoint.
|
|
1367
|
+
* Only essential information is included - internal cost breakdown is not exposed.
|
|
1368
|
+
*/
|
|
1369
|
+
interface FeeCalculationResult {
|
|
1370
|
+
network: string;
|
|
1371
|
+
hook: string;
|
|
1372
|
+
hookData?: string;
|
|
1373
|
+
hookAllowed: boolean;
|
|
1374
|
+
facilitatorFee: string;
|
|
1375
|
+
facilitatorFeeUSD: string;
|
|
1376
|
+
calculatedAt: string;
|
|
1377
|
+
validitySeconds: number;
|
|
1378
|
+
token: {
|
|
1379
|
+
address: string;
|
|
1380
|
+
symbol: string;
|
|
1381
|
+
decimals: number;
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Calculate recommended facilitator fee by querying the facilitator service
|
|
1386
|
+
*
|
|
1387
|
+
* @param facilitatorUrl - Facilitator service base URL
|
|
1388
|
+
* @param network - Network name
|
|
1389
|
+
* @param hook - Hook contract address
|
|
1390
|
+
* @param hookData - Optional encoded hook parameters
|
|
1391
|
+
* @param useCache - Whether to use caching (default: true)
|
|
1392
|
+
* @returns Fee calculation result with sufficient safety margin
|
|
1393
|
+
*
|
|
1394
|
+
* @example
|
|
1395
|
+
* ```typescript
|
|
1396
|
+
* const feeResult = await calculateFacilitatorFee(
|
|
1397
|
+
* 'https://facilitator.x402x.dev',
|
|
1398
|
+
* 'base-sepolia',
|
|
1399
|
+
* '0x1234...',
|
|
1400
|
+
* '0x'
|
|
1401
|
+
* );
|
|
1402
|
+
* console.log(`Recommended fee: ${feeResult.facilitatorFee} (${feeResult.facilitatorFeeUSD} USD)`);
|
|
1403
|
+
* ```
|
|
1404
|
+
*/
|
|
1405
|
+
declare function calculateFacilitatorFee(facilitatorUrl: string, network: string, hook: string, hookData?: string, useCache?: boolean): Promise<FeeCalculationResult>;
|
|
1406
|
+
/**
|
|
1407
|
+
* Clear the fee calculation cache
|
|
1408
|
+
*
|
|
1409
|
+
* Useful for testing or forcing fresh calculations
|
|
1410
|
+
*/
|
|
1411
|
+
declare function clearFeeCache(): void;
|
|
1412
|
+
/**
|
|
1413
|
+
* Response from facilitator verify endpoint
|
|
1414
|
+
*
|
|
1415
|
+
* Indicates whether a payment payload is valid without executing it.
|
|
1416
|
+
*/
|
|
1417
|
+
interface VerifyResponse {
|
|
1418
|
+
/** Whether the payment payload is valid */
|
|
1419
|
+
isValid: boolean;
|
|
1420
|
+
/** Reason for invalidity if isValid is false */
|
|
1421
|
+
invalidReason?: string;
|
|
1422
|
+
/** Payer address extracted from the payload */
|
|
1423
|
+
payer: string;
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Response from facilitator settle endpoint
|
|
1427
|
+
*
|
|
1428
|
+
* Contains the result of settlement execution on-chain.
|
|
1429
|
+
*/
|
|
1430
|
+
interface SettleResponse {
|
|
1431
|
+
/** Whether the settlement was successful */
|
|
1432
|
+
success: boolean;
|
|
1433
|
+
/** Transaction hash of the settlement */
|
|
1434
|
+
transaction: string;
|
|
1435
|
+
/** Network the settlement was executed on */
|
|
1436
|
+
network: string;
|
|
1437
|
+
/** Payer address */
|
|
1438
|
+
payer: string;
|
|
1439
|
+
/** Error reason if settlement failed */
|
|
1440
|
+
errorReason?: string;
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* Verify a payment payload with the facilitator
|
|
1444
|
+
*
|
|
1445
|
+
* Calls the facilitator's `/verify` endpoint to validate a payment without executing it.
|
|
1446
|
+
* This is useful for pre-validation before actual settlement.
|
|
1447
|
+
*
|
|
1448
|
+
* @param facilitatorUrl - Facilitator service base URL
|
|
1449
|
+
* @param paymentPayload - Payment payload from client (x402 standard)
|
|
1450
|
+
* @param paymentRequirements - Payment requirements (x402 standard)
|
|
1451
|
+
* @returns Verification response indicating validity
|
|
1452
|
+
*
|
|
1453
|
+
* @throws Error if network request fails or response is invalid
|
|
1454
|
+
*
|
|
1455
|
+
* @example
|
|
1456
|
+
* ```typescript
|
|
1457
|
+
* import { verify } from '@x402x/core';
|
|
1458
|
+
*
|
|
1459
|
+
* const result = await verify(
|
|
1460
|
+
* 'https://facilitator.x402x.dev',
|
|
1461
|
+
* paymentPayload,
|
|
1462
|
+
* paymentRequirements
|
|
1463
|
+
* );
|
|
1464
|
+
*
|
|
1465
|
+
* if (result.isValid) {
|
|
1466
|
+
* console.log('Payment is valid, payer:', result.payer);
|
|
1467
|
+
* } else {
|
|
1468
|
+
* console.error('Invalid payment:', result.invalidReason);
|
|
1469
|
+
* }
|
|
1470
|
+
* ```
|
|
1471
|
+
*/
|
|
1472
|
+
declare function verify(facilitatorUrl: string, paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
|
|
1473
|
+
/**
|
|
1474
|
+
* Settle a payment with the facilitator
|
|
1475
|
+
*
|
|
1476
|
+
* Calls the facilitator's `/settle` endpoint to execute the payment on-chain.
|
|
1477
|
+
* This is the core function that submits a signed payment for blockchain execution.
|
|
1478
|
+
*
|
|
1479
|
+
* @param facilitatorUrl - Facilitator service base URL
|
|
1480
|
+
* @param paymentPayload - Payment payload from client (x402 standard)
|
|
1481
|
+
* @param paymentRequirements - Payment requirements (x402 standard)
|
|
1482
|
+
* @param timeout - Optional timeout in milliseconds (default: 30000)
|
|
1483
|
+
* @returns Settlement response with transaction details
|
|
1484
|
+
*
|
|
1485
|
+
* @throws Error if network request fails, response is invalid, or settlement fails
|
|
1486
|
+
*
|
|
1487
|
+
* @example
|
|
1488
|
+
* ```typescript
|
|
1489
|
+
* import { settle } from '@x402x/core';
|
|
1490
|
+
*
|
|
1491
|
+
* const result = await settle(
|
|
1492
|
+
* 'https://facilitator.x402x.dev',
|
|
1493
|
+
* paymentPayload,
|
|
1494
|
+
* paymentRequirements,
|
|
1495
|
+
* 30000 // 30 second timeout
|
|
1496
|
+
* );
|
|
1497
|
+
*
|
|
1498
|
+
* if (result.success) {
|
|
1499
|
+
* console.log('Settlement successful!');
|
|
1500
|
+
* console.log('Transaction:', result.transaction);
|
|
1501
|
+
* console.log('Network:', result.network);
|
|
1502
|
+
* } else {
|
|
1503
|
+
* console.error('Settlement failed:', result.errorReason);
|
|
1504
|
+
* }
|
|
1505
|
+
* ```
|
|
1506
|
+
*/
|
|
1507
|
+
declare function settle(facilitatorUrl: string, paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements, timeout?: number): Promise<SettleResponse>;
|
|
1508
|
+
|
|
1509
|
+
/**
|
|
1510
|
+
* ABI definitions for x402x contracts
|
|
1511
|
+
*/
|
|
1512
|
+
/**
|
|
1513
|
+
* Settlement Router ABI
|
|
1514
|
+
*
|
|
1515
|
+
* Contains functions used by facilitators for settlement and fee management.
|
|
1516
|
+
*/
|
|
1517
|
+
declare const SETTLEMENT_ROUTER_ABI: readonly [{
|
|
1518
|
+
readonly type: "function";
|
|
1519
|
+
readonly name: "settleAndExecute";
|
|
1520
|
+
readonly inputs: readonly [{
|
|
1521
|
+
readonly name: "token";
|
|
1522
|
+
readonly type: "address";
|
|
1523
|
+
}, {
|
|
1524
|
+
readonly name: "from";
|
|
1525
|
+
readonly type: "address";
|
|
1526
|
+
}, {
|
|
1527
|
+
readonly name: "value";
|
|
1528
|
+
readonly type: "uint256";
|
|
1529
|
+
}, {
|
|
1530
|
+
readonly name: "validAfter";
|
|
1531
|
+
readonly type: "uint256";
|
|
1532
|
+
}, {
|
|
1533
|
+
readonly name: "validBefore";
|
|
1534
|
+
readonly type: "uint256";
|
|
1535
|
+
}, {
|
|
1536
|
+
readonly name: "nonce";
|
|
1537
|
+
readonly type: "bytes32";
|
|
1538
|
+
}, {
|
|
1539
|
+
readonly name: "signature";
|
|
1540
|
+
readonly type: "bytes";
|
|
1541
|
+
}, {
|
|
1542
|
+
readonly name: "salt";
|
|
1543
|
+
readonly type: "bytes32";
|
|
1544
|
+
}, {
|
|
1545
|
+
readonly name: "payTo";
|
|
1546
|
+
readonly type: "address";
|
|
1547
|
+
}, {
|
|
1548
|
+
readonly name: "facilitatorFee";
|
|
1549
|
+
readonly type: "uint256";
|
|
1550
|
+
}, {
|
|
1551
|
+
readonly name: "hook";
|
|
1552
|
+
readonly type: "address";
|
|
1553
|
+
}, {
|
|
1554
|
+
readonly name: "hookData";
|
|
1555
|
+
readonly type: "bytes";
|
|
1556
|
+
}];
|
|
1557
|
+
readonly outputs: readonly [];
|
|
1558
|
+
readonly stateMutability: "nonpayable";
|
|
1559
|
+
}, {
|
|
1560
|
+
readonly type: "function";
|
|
1561
|
+
readonly name: "calculateCommitment";
|
|
1562
|
+
readonly inputs: readonly [{
|
|
1563
|
+
readonly name: "token";
|
|
1564
|
+
readonly type: "address";
|
|
1565
|
+
}, {
|
|
1566
|
+
readonly name: "from";
|
|
1567
|
+
readonly type: "address";
|
|
1568
|
+
}, {
|
|
1569
|
+
readonly name: "value";
|
|
1570
|
+
readonly type: "uint256";
|
|
1571
|
+
}, {
|
|
1572
|
+
readonly name: "validAfter";
|
|
1573
|
+
readonly type: "uint256";
|
|
1574
|
+
}, {
|
|
1575
|
+
readonly name: "validBefore";
|
|
1576
|
+
readonly type: "uint256";
|
|
1577
|
+
}, {
|
|
1578
|
+
readonly name: "salt";
|
|
1579
|
+
readonly type: "bytes32";
|
|
1580
|
+
}, {
|
|
1581
|
+
readonly name: "payTo";
|
|
1582
|
+
readonly type: "address";
|
|
1583
|
+
}, {
|
|
1584
|
+
readonly name: "facilitatorFee";
|
|
1585
|
+
readonly type: "uint256";
|
|
1586
|
+
}, {
|
|
1587
|
+
readonly name: "hook";
|
|
1588
|
+
readonly type: "address";
|
|
1589
|
+
}, {
|
|
1590
|
+
readonly name: "hookData";
|
|
1591
|
+
readonly type: "bytes";
|
|
1592
|
+
}];
|
|
1593
|
+
readonly outputs: readonly [{
|
|
1594
|
+
readonly name: "";
|
|
1595
|
+
readonly type: "bytes32";
|
|
1596
|
+
}];
|
|
1597
|
+
readonly stateMutability: "view";
|
|
1598
|
+
}, {
|
|
1599
|
+
readonly type: "function";
|
|
1600
|
+
readonly name: "calculateContextKey";
|
|
1601
|
+
readonly inputs: readonly [{
|
|
1602
|
+
readonly name: "from";
|
|
1603
|
+
readonly type: "address";
|
|
1604
|
+
}, {
|
|
1605
|
+
readonly name: "token";
|
|
1606
|
+
readonly type: "address";
|
|
1607
|
+
}, {
|
|
1608
|
+
readonly name: "nonce";
|
|
1609
|
+
readonly type: "bytes32";
|
|
1610
|
+
}];
|
|
1611
|
+
readonly outputs: readonly [{
|
|
1612
|
+
readonly name: "";
|
|
1613
|
+
readonly type: "bytes32";
|
|
1614
|
+
}];
|
|
1615
|
+
readonly stateMutability: "pure";
|
|
1616
|
+
}, {
|
|
1617
|
+
readonly type: "function";
|
|
1618
|
+
readonly name: "isSettled";
|
|
1619
|
+
readonly inputs: readonly [{
|
|
1620
|
+
readonly name: "contextKey";
|
|
1621
|
+
readonly type: "bytes32";
|
|
1622
|
+
}];
|
|
1623
|
+
readonly outputs: readonly [{
|
|
1624
|
+
readonly name: "";
|
|
1625
|
+
readonly type: "bool";
|
|
1626
|
+
}];
|
|
1627
|
+
readonly stateMutability: "view";
|
|
1628
|
+
}, {
|
|
1629
|
+
readonly type: "function";
|
|
1630
|
+
readonly name: "getPendingFees";
|
|
1631
|
+
readonly inputs: readonly [{
|
|
1632
|
+
readonly name: "facilitator";
|
|
1633
|
+
readonly type: "address";
|
|
1634
|
+
}, {
|
|
1635
|
+
readonly name: "token";
|
|
1636
|
+
readonly type: "address";
|
|
1637
|
+
}];
|
|
1638
|
+
readonly outputs: readonly [{
|
|
1639
|
+
readonly name: "";
|
|
1640
|
+
readonly type: "uint256";
|
|
1641
|
+
}];
|
|
1642
|
+
readonly stateMutability: "view";
|
|
1643
|
+
}, {
|
|
1644
|
+
readonly type: "function";
|
|
1645
|
+
readonly name: "claimFees";
|
|
1646
|
+
readonly inputs: readonly [{
|
|
1647
|
+
readonly name: "tokens";
|
|
1648
|
+
readonly type: "address[]";
|
|
1649
|
+
}];
|
|
1650
|
+
readonly outputs: readonly [];
|
|
1651
|
+
readonly stateMutability: "nonpayable";
|
|
1652
|
+
}];
|
|
1653
|
+
|
|
1654
|
+
/**
|
|
1655
|
+
* Legacy compatibility types and stubs for x402x v2 middleware
|
|
1656
|
+
*
|
|
1657
|
+
* These provide compatibility shims for patterns from x402 v1 that are not
|
|
1658
|
+
* part of the v2 API but are needed by x402x middleware implementations.
|
|
1659
|
+
*/
|
|
1660
|
+
|
|
1661
|
+
/**
|
|
1662
|
+
* Supported EVM networks (legacy v1 pattern)
|
|
1663
|
+
* In v2, networks use CAIP-2 format (e.g., 'eip155:84532')
|
|
1664
|
+
*/
|
|
1665
|
+
declare const SupportedEVMNetworks: Network[];
|
|
1666
|
+
/**
|
|
1667
|
+
* Money schema validator (legacy v1 pattern)
|
|
1668
|
+
* In v2, validation is typically done through zod schemas in @x402/core
|
|
1669
|
+
*/
|
|
1670
|
+
declare const moneySchema: {
|
|
1671
|
+
parse: (value: unknown) => string | number;
|
|
1672
|
+
};
|
|
1673
|
+
/**
|
|
1674
|
+
* Settle response header name (legacy v1 pattern)
|
|
1675
|
+
* In v2, this is typically handled by x402HTTPResourceServer
|
|
1676
|
+
*/
|
|
1677
|
+
declare const settleResponseHeader = "X-Payment-Response";
|
|
1678
|
+
/**
|
|
1679
|
+
* EVM utilities placeholder (legacy v1 pattern)
|
|
1680
|
+
* In v2, EVM functionality is provided by @x402/evm package
|
|
1681
|
+
*/
|
|
1682
|
+
declare const evm: {
|
|
1683
|
+
/**
|
|
1684
|
+
* Check if a value is a valid EVM address
|
|
1685
|
+
*/
|
|
1686
|
+
isAddress: (value: unknown) => boolean;
|
|
1687
|
+
};
|
|
1688
|
+
/**
|
|
1689
|
+
* Payment scheme stub (legacy v1 pattern)
|
|
1690
|
+
* In v2, schemes are implemented as classes extending SchemeNetworkClient/Server
|
|
1691
|
+
*/
|
|
1692
|
+
declare const exact: {
|
|
1693
|
+
name: "exact";
|
|
1694
|
+
};
|
|
1695
|
+
/**
|
|
1696
|
+
* Chain ID to network mapping (legacy v1 pattern)
|
|
1697
|
+
*/
|
|
1698
|
+
declare const ChainIdToNetwork: Record<number, Network>;
|
|
1699
|
+
/**
|
|
1700
|
+
* Check if a signer is a multi-network signer
|
|
1701
|
+
*/
|
|
1702
|
+
declare function isMultiNetworkSigner(signer: unknown): boolean;
|
|
1703
|
+
/**
|
|
1704
|
+
* Check if a signer is an SVM (Solana) signer wallet
|
|
1705
|
+
*/
|
|
1706
|
+
declare function isSvmSignerWallet(signer: unknown): boolean;
|
|
1707
|
+
/**
|
|
1708
|
+
* Multi-network signer interface (legacy v1 pattern)
|
|
1709
|
+
*/
|
|
1710
|
+
interface MultiNetworkSigner {
|
|
1711
|
+
address?: string;
|
|
1712
|
+
signTransaction?: (tx: unknown) => Promise<unknown>;
|
|
1713
|
+
[key: string]: unknown;
|
|
1714
|
+
}
|
|
1715
|
+
/**
|
|
1716
|
+
* X402 configuration interface (legacy v1 pattern)
|
|
1717
|
+
*/
|
|
1718
|
+
interface X402Config {
|
|
1719
|
+
signer?: MultiNetworkSigner;
|
|
1720
|
+
[key: string]: unknown;
|
|
1721
|
+
}
|
|
1722
|
+
/**
|
|
1723
|
+
* Payment requirements selector type (legacy v1 pattern)
|
|
1724
|
+
*/
|
|
1725
|
+
type PaymentRequirementsSelector = (requirements: unknown[]) => unknown;
|
|
1726
|
+
/**
|
|
1727
|
+
* Create payment header (legacy v1 stub)
|
|
1728
|
+
* In v2, this is handled by x402Client.createPaymentPayload()
|
|
1729
|
+
*/
|
|
1730
|
+
declare function createPaymentHeader(_requirements: unknown, _signer: unknown): Promise<string>;
|
|
1731
|
+
/**
|
|
1732
|
+
* Select payment requirements (legacy v1 stub)
|
|
1733
|
+
* In v2, this is handled by x402Client.createPaymentPayload()
|
|
1734
|
+
*/
|
|
1735
|
+
declare function selectPaymentRequirements(_requirements: unknown[], _selector?: PaymentRequirementsSelector): unknown;
|
|
1736
|
+
/**
|
|
1737
|
+
* Decode X-Payment-Response header (legacy v1 stub)
|
|
1738
|
+
* In v2, response handling is done through x402HTTPClient
|
|
1739
|
+
*/
|
|
1740
|
+
declare function decodeXPaymentResponse(_header: string): unknown;
|
|
1741
|
+
/**
|
|
1742
|
+
* Use facilitator for verification (legacy v1 stub)
|
|
1743
|
+
* In v2, this is handled through FacilitatorClient
|
|
1744
|
+
*/
|
|
1745
|
+
declare function useFacilitator(_config: unknown): void;
|
|
1746
|
+
/**
|
|
1747
|
+
* Create a signer instance (legacy v1 stub)
|
|
1748
|
+
*/
|
|
1749
|
+
declare function createSigner(_config: unknown): unknown;
|
|
1750
|
+
|
|
1751
|
+
/**
|
|
1752
|
+
* Network utility functions for x402x core_v2
|
|
1753
|
+
*
|
|
1754
|
+
* These utilities provide helpers for working with CAIP-2 network identifiers
|
|
1755
|
+
* and accessing network-specific asset information.
|
|
1756
|
+
*/
|
|
1757
|
+
|
|
1758
|
+
/**
|
|
1759
|
+
* Asset information including EIP-712 domain parameters
|
|
1760
|
+
*/
|
|
1761
|
+
interface AssetInfo {
|
|
1762
|
+
address: string;
|
|
1763
|
+
decimals: number;
|
|
1764
|
+
eip712: {
|
|
1765
|
+
name: string;
|
|
1766
|
+
version: string;
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
/**
|
|
1770
|
+
* Get CAIP-2 network ID from network name
|
|
1771
|
+
*
|
|
1772
|
+
* @param networkName - Network name (e.g., 'base-sepolia', 'base')
|
|
1773
|
+
* @returns CAIP-2 network identifier (e.g., 'eip155:84532')
|
|
1774
|
+
* @throws Error if network name is not supported
|
|
1775
|
+
*
|
|
1776
|
+
* @example
|
|
1777
|
+
* ```typescript
|
|
1778
|
+
* const networkId = getNetworkId('base-sepolia'); // 'eip155:84532'
|
|
1779
|
+
* ```
|
|
1780
|
+
*/
|
|
1781
|
+
declare function getNetworkId(networkName: string): Network;
|
|
1782
|
+
/**
|
|
1783
|
+
* Get network name from CAIP-2 network ID
|
|
1784
|
+
*
|
|
1785
|
+
* @param network - CAIP-2 network identifier (e.g., 'eip155:84532')
|
|
1786
|
+
* @returns Network name (e.g., 'base-sepolia')
|
|
1787
|
+
* @throws Error if network ID is not supported
|
|
1788
|
+
*
|
|
1789
|
+
* @example
|
|
1790
|
+
* ```typescript
|
|
1791
|
+
* const networkName = getNetworkName('eip155:84532'); // 'base-sepolia'
|
|
1792
|
+
* ```
|
|
1793
|
+
*/
|
|
1794
|
+
declare function getNetworkName(network: Network): string;
|
|
1795
|
+
/**
|
|
1796
|
+
* Get default asset (USDC) information for a network
|
|
1797
|
+
*
|
|
1798
|
+
* @param network - CAIP-2 network identifier (e.g., 'eip155:84532')
|
|
1799
|
+
* @returns Asset information including address, decimals, and EIP-712 domain
|
|
1800
|
+
* @throws Error if network is not supported
|
|
1801
|
+
*
|
|
1802
|
+
* @example
|
|
1803
|
+
* ```typescript
|
|
1804
|
+
* const asset = getDefaultAsset('eip155:84532');
|
|
1805
|
+
* // { address: '0x036Cb...', decimals: 6, eip712: { name: 'USDC', version: '2' } }
|
|
1806
|
+
* ```
|
|
1807
|
+
*/
|
|
1808
|
+
declare function getDefaultAsset(network: Network): AssetInfo;
|
|
1809
|
+
/**
|
|
1810
|
+
* Process price to atomic amount for the default asset on a network
|
|
1811
|
+
*
|
|
1812
|
+
* This function converts various price formats to atomic units (smallest denomination).
|
|
1813
|
+
* For USDC with 6 decimals: 1.5 USD -> '1500000'
|
|
1814
|
+
*
|
|
1815
|
+
* @param price - Price as string or number (in USD, not atomic units)
|
|
1816
|
+
* @param network - CAIP-2 network identifier
|
|
1817
|
+
* @returns Object with amount as string in atomic units, or error
|
|
1818
|
+
*
|
|
1819
|
+
* @example
|
|
1820
|
+
* ```typescript
|
|
1821
|
+
* const result = processPriceToAtomicAmount('1.5', 'eip155:84532');
|
|
1822
|
+
* // { amount: '1500000' }
|
|
1823
|
+
* ```
|
|
1824
|
+
*/
|
|
1825
|
+
declare function processPriceToAtomicAmount(price: string | number, network: Network): {
|
|
1826
|
+
amount: string;
|
|
1827
|
+
} | {
|
|
1828
|
+
error: string;
|
|
1829
|
+
};
|
|
1830
|
+
/**
|
|
1831
|
+
* Alias mapping from v1 network names to v2 CAIP-2 identifiers
|
|
1832
|
+
* This provides backward compatibility for v1 network names
|
|
1833
|
+
*/
|
|
1834
|
+
declare const NETWORK_ALIASES_V1_TO_V2: Record<string, Network>;
|
|
1835
|
+
/**
|
|
1836
|
+
* Get list of all supported network IDs (CAIP-2 identifiers)
|
|
1837
|
+
*
|
|
1838
|
+
* Returns protocol-level CAIP-2 network identifiers like "eip155:84532".
|
|
1839
|
+
* Use this for x402 v2 protocol operations and facilitator configuration.
|
|
1840
|
+
*
|
|
1841
|
+
* @returns Array of CAIP-2 network identifiers
|
|
1842
|
+
*
|
|
1843
|
+
* @example
|
|
1844
|
+
* ```typescript
|
|
1845
|
+
* const networkIds = getSupportedNetworkIds();
|
|
1846
|
+
* // => ['eip155:84532', 'eip155:8453', 'eip155:1952', ...]
|
|
1847
|
+
*
|
|
1848
|
+
* // For x402 v2 protocol
|
|
1849
|
+
* const facilitator = createFacilitator({
|
|
1850
|
+
* networks: getSupportedNetworkIds()
|
|
1851
|
+
* });
|
|
1852
|
+
* ```
|
|
1853
|
+
*/
|
|
1854
|
+
declare function getSupportedNetworkIds(): Network[];
|
|
1855
|
+
/**
|
|
1856
|
+
* @deprecated Use getSupportedNetworkIds() instead for clarity
|
|
1857
|
+
* Get list of all supported networks using v2 CAIP-2 identifiers
|
|
1858
|
+
*/
|
|
1859
|
+
declare function getSupportedNetworksV2(): Network[];
|
|
1860
|
+
/**
|
|
1861
|
+
* Get the alias mapping from v1 network names to v2 CAIP-2 identifiers
|
|
1862
|
+
*
|
|
1863
|
+
* @returns Record mapping v1 names to v2 CAIP-2 keys
|
|
1864
|
+
*
|
|
1865
|
+
* @example
|
|
1866
|
+
* ```typescript
|
|
1867
|
+
* const aliases = getNetworkAliasesV1ToV2();
|
|
1868
|
+
* // => { 'base-sepolia': 'eip155:84532', 'x-layer-testnet': 'eip155:1952', ... }
|
|
1869
|
+
* ```
|
|
1870
|
+
*/
|
|
1871
|
+
declare function getNetworkAliasesV1ToV2(): Record<string, Network>;
|
|
1872
|
+
/**
|
|
1873
|
+
* Convert any network identifier to its canonical v2 CAIP-2 key
|
|
1874
|
+
*
|
|
1875
|
+
* Handles both v1 human-readable names and v2 CAIP-2 identifiers,
|
|
1876
|
+
* returning the canonical v2 CAIP-2 identifier for all inputs.
|
|
1877
|
+
*
|
|
1878
|
+
* @param network - Network identifier (v1 name or v2 CAIP-2)
|
|
1879
|
+
* @returns Canonical v2 CAIP-2 network identifier
|
|
1880
|
+
* @throws Error if network is not supported
|
|
1881
|
+
*
|
|
1882
|
+
* @example
|
|
1883
|
+
* ```typescript
|
|
1884
|
+
* toCanonicalNetworkKey('base-sepolia'); // 'eip155:84532'
|
|
1885
|
+
* toCanonicalNetworkKey('eip155:84532'); // 'eip155:84532'
|
|
1886
|
+
* toCanonicalNetworkKey('x-layer'); // 'eip155:196'
|
|
1887
|
+
* ```
|
|
1888
|
+
*/
|
|
1889
|
+
declare function toCanonicalNetworkKey(network: string): Network;
|
|
1890
|
+
|
|
1891
|
+
export { type Address, AmountError, ChainIdToNetwork, type CommitmentParams, type DemoHooks, type FacilitatorConfig, type SettleResponse$1 as FacilitatorSettleResponse, FacilitatorValidationError, type VerifyResponse$1 as FacilitatorVerifyResponse, type FeeCalculationResult, type RouteConfig as LegacyRouteConfig, type MintConfig, type Money, type MultiNetworkSigner, NETWORK_ALIASES_V1_TO_V2, NFTMintHook, type NetworkConfig, type PaymentRequirementsSelector, ROUTER_SETTLEMENT_KEY, type Resource, type RewardConfig, RewardHook, type RoutePattern, type RouterSettlementExtension, type RouterSettlementExtensionInfo, type RoutesConfig, SETTLEMENT_ROUTER_ABI, type SettleResponse, type SettlementExtra, type SettlementExtraCore, SettlementExtraError, type SettlementHooksConfig, type SettlementOptions, type SettlementPaymentOption, type SettlementRouteConfig, SettlementRouterError, type SettlementRouterParams, type Signer, SupportedEVMNetworks, TransferHook, type ValidationResult, type VerifyResponse, type WithRouterSettlementOptions, type X402Config, addSettlementExtra, assertValidSettlementExtra, calculateCommitment, calculateFacilitatorFee, clearFeeCache, computeRoutePatterns, createExtensionDeclaration, createPaymentHeader, createRouterSettlementExtension, createSettlementRouteConfig, createSigner, createX402xFacilitator, decodeXPaymentResponse, evm, exact, findMatchingPaymentRequirements, findMatchingRoute, formatDefaultAssetAmount, generateSalt, getChain, getChainById, getCustomChains, getDefaultAsset, getNetworkAliasesV1ToV2, getNetworkConfig, getNetworkId, getNetworkName, getRouterSettlementExtensionKey, getSupportedNetworkIds, getSupportedNetworkNames, getSupportedNetworks, getSupportedNetworksV2, isCustomChain, isMultiNetworkSigner, isNetworkSupported, isRouterSettlement, isSettlementMode, isSvmSignerWallet, isValid32ByteHex, isValidAddress, isValidHex, isValidNumericString, moneySchema, networks, parseDefaultAssetAmount, parseSettlementExtra, processPriceToAtomicAmount, registerRouterSettlement, registerSettlementHooks, routerSettlementServerExtension, selectPaymentRequirements, settle, settleResponseHeader, toCanonicalNetworkKey, toJsonSafe, useFacilitator, validateCommitmentParams, validateSettlementExtra, verify, withRouterSettlement };
|