@agirails/sdk 3.2.0 → 3.4.1
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/LICENSE +1 -1
- package/README.md +12 -14
- package/dist/ACTPClient.d.ts +8 -11
- package/dist/ACTPClient.d.ts.map +1 -1
- package/dist/ACTPClient.js +79 -20
- package/dist/ACTPClient.js.map +1 -1
- package/dist/__tests__/helpers/mockX402Server.d.ts +67 -0
- package/dist/__tests__/helpers/mockX402Server.d.ts.map +1 -0
- package/dist/__tests__/helpers/mockX402Server.js +121 -0
- package/dist/__tests__/helpers/mockX402Server.js.map +1 -0
- package/dist/adapters/BaseAdapter.d.ts +7 -1
- package/dist/adapters/BaseAdapter.d.ts.map +1 -1
- package/dist/adapters/BaseAdapter.js +11 -6
- package/dist/adapters/BaseAdapter.js.map +1 -1
- package/dist/adapters/BasicAdapter.d.ts.map +1 -1
- package/dist/adapters/BasicAdapter.js +12 -2
- package/dist/adapters/BasicAdapter.js.map +1 -1
- package/dist/adapters/StandardAdapter.d.ts.map +1 -1
- package/dist/adapters/StandardAdapter.js +12 -2
- package/dist/adapters/StandardAdapter.js.map +1 -1
- package/dist/adapters/X402Adapter.d.ts +161 -199
- package/dist/adapters/X402Adapter.d.ts.map +1 -1
- package/dist/adapters/X402Adapter.js +603 -414
- package/dist/adapters/X402Adapter.js.map +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/api/agirailsApp.d.ts +21 -1
- package/dist/api/agirailsApp.d.ts.map +1 -1
- package/dist/api/agirailsApp.js.map +1 -1
- package/dist/builders/CounterAcceptBuilder.d.ts +96 -0
- package/dist/builders/CounterAcceptBuilder.d.ts.map +1 -0
- package/dist/builders/CounterAcceptBuilder.js +226 -0
- package/dist/builders/CounterAcceptBuilder.js.map +1 -0
- package/dist/builders/CounterOfferBuilder.d.ts +143 -0
- package/dist/builders/CounterOfferBuilder.d.ts.map +1 -0
- package/dist/builders/CounterOfferBuilder.js +329 -0
- package/dist/builders/CounterOfferBuilder.js.map +1 -0
- package/dist/builders/DeliveryProofBuilder.d.ts.map +1 -1
- package/dist/builders/DeliveryProofBuilder.js +3 -2
- package/dist/builders/DeliveryProofBuilder.js.map +1 -1
- package/dist/builders/QuoteBuilder.d.ts.map +1 -1
- package/dist/builders/QuoteBuilder.js +8 -3
- package/dist/builders/QuoteBuilder.js.map +1 -1
- package/dist/builders/index.d.ts +2 -0
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +7 -1
- package/dist/builders/index.js.map +1 -1
- package/dist/cli/agirails.js +34 -6
- package/dist/cli/agirails.js.map +1 -1
- package/dist/cli/commands/autopublish.js +9 -1
- package/dist/cli/commands/autopublish.js.map +1 -1
- package/dist/cli/commands/config.js +1 -12
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/deploy-env.js +1 -1
- package/dist/cli/commands/deploy-env.js.map +1 -1
- package/dist/cli/commands/diff.js +38 -4
- package/dist/cli/commands/diff.js.map +1 -1
- package/dist/cli/commands/health.js +24 -6
- package/dist/cli/commands/health.js.map +1 -1
- package/dist/cli/commands/init.d.ts +2 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +100 -7
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/pay.d.ts.map +1 -1
- package/dist/cli/commands/pay.js +23 -0
- package/dist/cli/commands/pay.js.map +1 -1
- package/dist/cli/commands/publish.d.ts +34 -0
- package/dist/cli/commands/publish.d.ts.map +1 -1
- package/dist/cli/commands/publish.js +266 -83
- package/dist/cli/commands/publish.js.map +1 -1
- package/dist/cli/commands/pull.js +3 -1
- package/dist/cli/commands/pull.js.map +1 -1
- package/dist/cli/commands/receipt.d.ts +17 -3
- package/dist/cli/commands/receipt.d.ts.map +1 -1
- package/dist/cli/commands/receipt.js +95 -33
- package/dist/cli/commands/receipt.js.map +1 -1
- package/dist/cli/commands/repair.d.ts +23 -0
- package/dist/cli/commands/repair.d.ts.map +1 -0
- package/dist/cli/commands/repair.js +210 -0
- package/dist/cli/commands/repair.js.map +1 -0
- package/dist/cli/commands/serve.d.ts +38 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/serve.js +308 -0
- package/dist/cli/commands/serve.js.map +1 -0
- package/dist/cli/commands/test.d.ts.map +1 -1
- package/dist/cli/commands/test.js +222 -60
- package/dist/cli/commands/test.js.map +1 -1
- package/dist/cli/commands/tx.js +13 -0
- package/dist/cli/commands/tx.js.map +1 -1
- package/dist/cli/index.js +9 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/receiptUpload.d.ts +52 -0
- package/dist/cli/receiptUpload.d.ts.map +1 -0
- package/dist/cli/receiptUpload.js +134 -0
- package/dist/cli/receiptUpload.js.map +1 -0
- package/dist/cli/utils/banner.d.ts +31 -0
- package/dist/cli/utils/banner.d.ts.map +1 -0
- package/dist/cli/utils/banner.js +92 -0
- package/dist/cli/utils/banner.js.map +1 -0
- package/dist/cli/utils/config.d.ts +0 -2
- package/dist/cli/utils/config.d.ts.map +1 -1
- package/dist/cli/utils/config.js +40 -25
- package/dist/cli/utils/config.js.map +1 -1
- package/dist/cli/utils/output.d.ts +2 -0
- package/dist/cli/utils/output.d.ts.map +1 -1
- package/dist/cli/utils/output.js +7 -1
- package/dist/cli/utils/output.js.map +1 -1
- package/dist/cli/utils/share.d.ts +51 -0
- package/dist/cli/utils/share.d.ts.map +1 -0
- package/dist/cli/utils/share.js +133 -0
- package/dist/cli/utils/share.js.map +1 -0
- package/dist/config/agirailsmd.d.ts.map +1 -1
- package/dist/config/agirailsmd.js +2 -1
- package/dist/config/agirailsmd.js.map +1 -1
- package/dist/config/agirailsmdV4.d.ts +46 -1
- package/dist/config/agirailsmdV4.d.ts.map +1 -1
- package/dist/config/agirailsmdV4.js +65 -8
- package/dist/config/agirailsmdV4.js.map +1 -1
- package/dist/config/defaults.d.ts +12 -2
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +19 -3
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/networks.d.ts +7 -0
- package/dist/config/networks.d.ts.map +1 -1
- package/dist/config/networks.js +20 -11
- package/dist/config/networks.js.map +1 -1
- package/dist/config/pendingPublish.d.ts.map +1 -1
- package/dist/config/pendingPublish.js +10 -3
- package/dist/config/pendingPublish.js.map +1 -1
- package/dist/config/publishPipeline.d.ts +23 -1
- package/dist/config/publishPipeline.d.ts.map +1 -1
- package/dist/config/publishPipeline.js +70 -15
- package/dist/config/publishPipeline.js.map +1 -1
- package/dist/config/syncOperations.d.ts.map +1 -1
- package/dist/config/syncOperations.js +4 -2
- package/dist/config/syncOperations.js.map +1 -1
- package/dist/erc8004/ERC8004Bridge.d.ts.map +1 -1
- package/dist/erc8004/ERC8004Bridge.js +0 -1
- package/dist/erc8004/ERC8004Bridge.js.map +1 -1
- package/dist/errors/ACTPError.d.ts +24 -0
- package/dist/errors/ACTPError.d.ts.map +1 -0
- package/dist/errors/ACTPError.js +35 -0
- package/dist/errors/ACTPError.js.map +1 -0
- package/dist/errors/X402Errors.d.ts +106 -0
- package/dist/errors/X402Errors.d.ts.map +1 -0
- package/dist/errors/X402Errors.js +160 -0
- package/dist/errors/X402Errors.js.map +1 -0
- package/dist/errors/index.d.ts +3 -9
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +38 -33
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -3
- package/dist/index.js.map +1 -1
- package/dist/level0/Provider.d.ts +5 -0
- package/dist/level0/Provider.d.ts.map +1 -1
- package/dist/level0/ServiceDirectory.d.ts.map +1 -1
- package/dist/level0/ServiceDirectory.js +3 -2
- package/dist/level0/ServiceDirectory.js.map +1 -1
- package/dist/level0/provide.d.ts.map +1 -1
- package/dist/level0/provide.js +11 -8
- package/dist/level0/provide.js.map +1 -1
- package/dist/level0/request.d.ts.map +1 -1
- package/dist/level0/request.js +14 -6
- package/dist/level0/request.js.map +1 -1
- package/dist/level1/Agent.d.ts +28 -1
- package/dist/level1/Agent.d.ts.map +1 -1
- package/dist/level1/Agent.js +89 -12
- package/dist/level1/Agent.js.map +1 -1
- package/dist/level1/pricing/PriceCalculator.d.ts.map +1 -1
- package/dist/level1/pricing/PriceCalculator.js +4 -12
- package/dist/level1/pricing/PriceCalculator.js.map +1 -1
- package/dist/negotiation/BuyerOrchestrator.d.ts +103 -1
- package/dist/negotiation/BuyerOrchestrator.d.ts.map +1 -1
- package/dist/negotiation/BuyerOrchestrator.js +499 -4
- package/dist/negotiation/BuyerOrchestrator.js.map +1 -1
- package/dist/negotiation/DecisionEngine.d.ts +69 -1
- package/dist/negotiation/DecisionEngine.d.ts.map +1 -1
- package/dist/negotiation/DecisionEngine.js +140 -1
- package/dist/negotiation/DecisionEngine.js.map +1 -1
- package/dist/negotiation/PolicyEngine.d.ts +32 -0
- package/dist/negotiation/PolicyEngine.d.ts.map +1 -1
- package/dist/negotiation/PolicyEngine.js.map +1 -1
- package/dist/negotiation/ProviderOrchestrator.d.ts +108 -0
- package/dist/negotiation/ProviderOrchestrator.d.ts.map +1 -0
- package/dist/negotiation/ProviderOrchestrator.js +136 -0
- package/dist/negotiation/ProviderOrchestrator.js.map +1 -0
- package/dist/negotiation/ProviderPolicy.d.ts +143 -0
- package/dist/negotiation/ProviderPolicy.d.ts.map +1 -0
- package/dist/negotiation/ProviderPolicy.js +207 -0
- package/dist/negotiation/ProviderPolicy.js.map +1 -0
- package/dist/negotiation/index.d.ts +8 -1
- package/dist/negotiation/index.d.ts.map +1 -1
- package/dist/negotiation/index.js +8 -1
- package/dist/negotiation/index.js.map +1 -1
- package/dist/negotiation/verifyQuoteOnChain.d.ts +58 -0
- package/dist/negotiation/verifyQuoteOnChain.d.ts.map +1 -0
- package/dist/negotiation/verifyQuoteOnChain.js +83 -0
- package/dist/negotiation/verifyQuoteOnChain.js.map +1 -0
- package/dist/protocol/ACTPKernel.d.ts +4 -1
- package/dist/protocol/ACTPKernel.d.ts.map +1 -1
- package/dist/protocol/ACTPKernel.js +2 -1
- package/dist/protocol/ACTPKernel.js.map +1 -1
- package/dist/protocol/EventMonitor.d.ts +27 -1
- package/dist/protocol/EventMonitor.d.ts.map +1 -1
- package/dist/protocol/EventMonitor.js +11 -9
- package/dist/protocol/EventMonitor.js.map +1 -1
- package/dist/protocol/ProofGenerator.d.ts.map +1 -1
- package/dist/protocol/ProofGenerator.js +3 -2
- package/dist/protocol/ProofGenerator.js.map +1 -1
- package/dist/runtime/BlockchainRuntime.d.ts +15 -0
- package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
- package/dist/runtime/BlockchainRuntime.js +42 -6
- package/dist/runtime/BlockchainRuntime.js.map +1 -1
- package/dist/runtime/IACTPRuntime.d.ts +35 -0
- package/dist/runtime/IACTPRuntime.d.ts.map +1 -1
- package/dist/runtime/MockRuntime.d.ts +14 -2
- package/dist/runtime/MockRuntime.d.ts.map +1 -1
- package/dist/runtime/MockRuntime.js +55 -22
- package/dist/runtime/MockRuntime.js.map +1 -1
- package/dist/runtime/types/MockState.d.ts +14 -0
- package/dist/runtime/types/MockState.d.ts.map +1 -1
- package/dist/runtime/types/MockState.js.map +1 -1
- package/dist/server/buildX402Server.d.ts +131 -0
- package/dist/server/buildX402Server.d.ts.map +1 -0
- package/dist/server/buildX402Server.js +151 -0
- package/dist/server/buildX402Server.js.map +1 -0
- package/dist/server/index.d.ts +33 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +36 -0
- package/dist/server/index.js.map +1 -0
- package/dist/transport/QuoteChannel.d.ts +201 -0
- package/dist/transport/QuoteChannel.d.ts.map +1 -0
- package/dist/transport/QuoteChannel.js +358 -0
- package/dist/transport/QuoteChannel.js.map +1 -0
- package/dist/types/adapter.d.ts +64 -34
- package/dist/types/adapter.d.ts.map +1 -1
- package/dist/types/adapter.js +6 -1
- package/dist/types/adapter.js.map +1 -1
- package/dist/types/eip712.d.ts +20 -0
- package/dist/types/eip712.d.ts.map +1 -1
- package/dist/types/x402.d.ts +8 -8
- package/dist/utils/security.d.ts.map +1 -1
- package/dist/utils/security.js +4 -6
- package/dist/utils/security.js.map +1 -1
- package/dist/wallet/AutoWalletProvider.d.ts +45 -1
- package/dist/wallet/AutoWalletProvider.d.ts.map +1 -1
- package/dist/wallet/AutoWalletProvider.js +154 -1
- package/dist/wallet/AutoWalletProvider.js.map +1 -1
- package/dist/wallet/EOAWalletProvider.d.ts +13 -1
- package/dist/wallet/EOAWalletProvider.d.ts.map +1 -1
- package/dist/wallet/EOAWalletProvider.js +24 -0
- package/dist/wallet/EOAWalletProvider.js.map +1 -1
- package/dist/wallet/IWalletProvider.d.ts +34 -0
- package/dist/wallet/IWalletProvider.d.ts.map +1 -1
- package/dist/wallet/SmartWalletRouter.d.ts.map +1 -1
- package/dist/wallet/SmartWalletRouter.js +3 -1
- package/dist/wallet/SmartWalletRouter.js.map +1 -1
- package/dist/wallet/aa/BundlerClient.js +8 -4
- package/dist/wallet/aa/BundlerClient.js.map +1 -1
- package/dist/wallet/aa/DualNonceManager.d.ts +4 -1
- package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -1
- package/dist/wallet/aa/DualNonceManager.js +3 -0
- package/dist/wallet/aa/DualNonceManager.js.map +1 -1
- package/dist/wallet/keystore.d.ts.map +1 -1
- package/dist/wallet/keystore.js +6 -4
- package/dist/wallet/keystore.js.map +1 -1
- package/package.json +31 -3
- package/dist/adapters/BeginnerAdapter.d.ts +0 -152
- package/dist/adapters/BeginnerAdapter.d.ts.map +0 -1
- package/dist/adapters/BeginnerAdapter.js +0 -168
- package/dist/adapters/BeginnerAdapter.js.map +0 -1
- package/dist/adapters/IntermediateAdapter.d.ts +0 -211
- package/dist/adapters/IntermediateAdapter.d.ts.map +0 -1
- package/dist/adapters/IntermediateAdapter.js +0 -260
- package/dist/adapters/IntermediateAdapter.js.map +0 -1
|
@@ -1,249 +1,211 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* X402Adapter
|
|
2
|
+
* X402Adapter — real x402 v2 protocol support.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Thin wrapper around official @x402/fetch + @x402/evm + @x402/core packages.
|
|
5
|
+
* Replaces the legacy custom `x-payment-*` HTTP flow (which was never real x402)
|
|
6
|
+
* with proper EIP-3009 / Permit2 wire format for full interoperability with
|
|
7
|
+
* any x402 v2 seller (Coinbase demo, third-party servers, AGIRAILS sellers).
|
|
6
8
|
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
9
|
+
* Architecture:
|
|
10
|
+
* - Buyer signs EIP-3009 authorization or Permit2 witness OFF-CHAIN
|
|
11
|
+
* - Facilitator (server-configured) submits on-chain tx and pays gas
|
|
12
|
+
* - Buyer is always gassless for x402 by protocol design
|
|
13
|
+
* - Smart Wallet buyers use Permit2 path (ERC-1271 + ERC-6492 via viem)
|
|
14
|
+
* - EOA buyers use either path
|
|
10
15
|
*
|
|
11
|
-
*
|
|
12
|
-
* -
|
|
13
|
-
* - Instant delivery (response IS the delivery)
|
|
14
|
-
* - Low-value, high-frequency transactions
|
|
16
|
+
* Zero fee layer: payTo goes directly to seller. X402Relay is never used.
|
|
17
|
+
* Zero reputation hooks: ERC-8004 registry never touched on x402 payments.
|
|
15
18
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* - High-value transactions needing dispute protection
|
|
19
|
-
* - Multi-step deliveries
|
|
19
|
+
* Architecture rationale and Smart Wallet signing flow are documented in
|
|
20
|
+
* the project's internal x402 v2 implementation notes.
|
|
20
21
|
*
|
|
21
22
|
* @module adapters/X402Adapter
|
|
22
23
|
*/
|
|
23
|
-
import { BaseAdapter } from './BaseAdapter';
|
|
24
24
|
import { IAdapter, TransactionStatus } from './IAdapter';
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
/** Type for fetch function (cross-platform compatible) */
|
|
28
|
-
export type FetchFunction = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
25
|
+
import { UnifiedPayParams, UnifiedPayResult, AdapterMetadata } from '../types/adapter';
|
|
26
|
+
import { IWalletProvider } from '../wallet/IWalletProvider';
|
|
29
27
|
/**
|
|
30
|
-
*
|
|
28
|
+
* Configuration for X402Adapter.
|
|
31
29
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
export interface TransferReceiptLike {
|
|
36
|
-
hash: string;
|
|
37
|
-
success?: boolean;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Transfer function for atomic USDC payments.
|
|
41
|
-
*
|
|
42
|
-
* @param to - Recipient address
|
|
43
|
-
* @param amount - Amount in USDC wei (string)
|
|
44
|
-
* @returns Transaction hash string OR receipt-like object with hash/success
|
|
45
|
-
*/
|
|
46
|
-
export type TransferFunction = (to: string, amount: string) => Promise<string | TransferReceiptLike>;
|
|
47
|
-
/**
|
|
48
|
-
* Approve function for USDC allowance (used with X402Relay).
|
|
49
|
-
*
|
|
50
|
-
* @param spender - Spender address (relay contract)
|
|
51
|
-
* @param amount - Amount in USDC wei (string)
|
|
52
|
-
* @returns Transaction hash
|
|
53
|
-
*/
|
|
54
|
-
export type ApproveFunction = (spender: string, amount: string) => Promise<string>;
|
|
55
|
-
/**
|
|
56
|
-
* Relay pay function — calls X402Relay.payWithFee().
|
|
57
|
-
*
|
|
58
|
-
* @param provider - Provider address
|
|
59
|
-
* @param grossAmount - Gross USDC amount (string)
|
|
60
|
-
* @param serviceId - Service identifier (bytes32 hex)
|
|
61
|
-
* @returns Transaction hash
|
|
62
|
-
*/
|
|
63
|
-
export type RelayPayFunction = (provider: string, grossAmount: string, serviceId: string) => Promise<string>;
|
|
64
|
-
/** Supported HTTP methods for x402 requests */
|
|
65
|
-
export type X402HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
66
|
-
/**
|
|
67
|
-
* Extended payment parameters for x402 with full HTTP support.
|
|
68
|
-
*/
|
|
69
|
-
export interface X402PayParams extends UnifiedPayParams {
|
|
70
|
-
/** HTTP method (default: GET) */
|
|
71
|
-
method?: X402HttpMethod;
|
|
72
|
-
/** Custom request headers */
|
|
73
|
-
headers?: Record<string, string>;
|
|
74
|
-
/** Request body (string or object, will be JSON.stringify'd if object) */
|
|
75
|
-
body?: string | Record<string, unknown>;
|
|
76
|
-
/** Content-Type header (default: application/json for POST/PUT/PATCH with body) */
|
|
77
|
-
contentType?: string;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Configuration options for X402Adapter.
|
|
81
|
-
*
|
|
82
|
-
* Fee collection is required (since v2.6.0). Two modes:
|
|
83
|
-
* - Relay (preferred): relayAddress + approveFn + relayPayFn — atomic on-chain split
|
|
84
|
-
* - feeCollector (fallback): feeCollector address — client-side two-transfer split
|
|
30
|
+
* Auto-registered by ACTPClient when walletProvider implements signTypedData.
|
|
31
|
+
* Manual instantiation is supported but rarely needed — in most cases use
|
|
32
|
+
* ACTPClient auto-registration defaults or register a custom adapter instance.
|
|
85
33
|
*/
|
|
86
34
|
export interface X402AdapterConfig {
|
|
87
|
-
/** Expected network for validation (must match server's X-Payment-Network) */
|
|
88
|
-
expectedNetwork: X402Network;
|
|
89
|
-
/** Transfer function for USDC payments (used in feeCollector path for provider + fee transfers) */
|
|
90
|
-
transferFn: TransferFunction;
|
|
91
|
-
/** Request timeout in milliseconds (default: 30000) */
|
|
92
|
-
requestTimeout?: number;
|
|
93
|
-
/** Custom fetch function for testing (default: global fetch) */
|
|
94
|
-
fetchFn?: FetchFunction;
|
|
95
|
-
/** Default headers to include in all requests */
|
|
96
|
-
defaultHeaders?: Record<string, string>;
|
|
97
|
-
/** X402Relay contract address for on-chain fee splitting (preferred) */
|
|
98
|
-
relayAddress?: string;
|
|
99
|
-
/** USDC approve function — required when relayAddress is set */
|
|
100
|
-
approveFn?: ApproveFunction;
|
|
101
|
-
/** Relay payWithFee function — required when relayAddress is set */
|
|
102
|
-
relayPayFn?: RelayPayFunction;
|
|
103
|
-
/** Fee collector address for client-side fee splitting (fallback when relay not available) */
|
|
104
|
-
feeCollector?: string;
|
|
105
|
-
/** Platform fee in basis points (default: 100 = 1%). Read-only display hint. */
|
|
106
|
-
platformFeeBps?: number;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* X402Adapter - Atomic HTTP payment protocol.
|
|
110
|
-
*
|
|
111
|
-
* Key characteristics:
|
|
112
|
-
* - usesEscrow: false (direct payment)
|
|
113
|
-
* - supportsDisputes: false (atomic = final)
|
|
114
|
-
* - settlementMode: 'atomic' (instant)
|
|
115
|
-
* - releaseRequired: false (no escrow to release)
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```typescript
|
|
119
|
-
* const adapter = new X402Adapter(requesterAddress, {
|
|
120
|
-
* expectedNetwork: 'base-sepolia',
|
|
121
|
-
* transferFn: async (to, amount) => {
|
|
122
|
-
* const tx = await usdcContract.transfer(to, amount);
|
|
123
|
-
* return tx.hash;
|
|
124
|
-
* },
|
|
125
|
-
* feeCollector: '0x...treasury', // Required: AGIRAILS fee recipient
|
|
126
|
-
* });
|
|
127
|
-
*
|
|
128
|
-
* const result = await adapter.pay({
|
|
129
|
-
* to: 'https://api.provider.com/service',
|
|
130
|
-
* amount: '10', // Hint only, actual amount from 402
|
|
131
|
-
* });
|
|
132
|
-
*
|
|
133
|
-
* // That's it! No release() needed.
|
|
134
|
-
* console.log(result.response?.status); // 200
|
|
135
|
-
* console.log(result.releaseRequired); // false
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
export declare class X402Adapter extends BaseAdapter implements IAdapter {
|
|
139
|
-
private config;
|
|
140
35
|
/**
|
|
141
|
-
*
|
|
36
|
+
* Wallet provider for signing payment authorizations.
|
|
37
|
+
* Both `EOAWalletProvider` (Tier 2) and `AutoWalletProvider` (Tier 1 Smart Wallet)
|
|
38
|
+
* are supported as long as the provider implements the optional
|
|
39
|
+
* `signTypedData` method.
|
|
142
40
|
*/
|
|
143
|
-
|
|
144
|
-
private readonly timeout;
|
|
145
|
-
private readonly fetchFn;
|
|
146
|
-
private readonly defaultHeaders;
|
|
147
|
-
private readonly transferFn;
|
|
148
|
-
/** Local cache of payments for status lookups */
|
|
149
|
-
private readonly payments;
|
|
41
|
+
walletProvider: IWalletProvider;
|
|
150
42
|
/**
|
|
151
|
-
*
|
|
43
|
+
* Optional CAIP-2 network allowlist (e.g. `["eip155:8453", "eip155:84532"]`).
|
|
152
44
|
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
45
|
+
* Leave undefined (default) to allow ANY EVM network @x402/evm supports —
|
|
46
|
+
* this is the "works with anyone" interop default. Set an explicit list
|
|
47
|
+
* only if you want to restrict your agent to specific chains.
|
|
155
48
|
*/
|
|
156
|
-
|
|
49
|
+
allowedNetworks?: ReadonlyArray<string>;
|
|
157
50
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
51
|
+
* Per-transaction safety cap in human-readable USD (e.g. "1" for $1 USDC).
|
|
52
|
+
* Protects against accidentally paying unexpectedly high prices.
|
|
53
|
+
* Default: "1"
|
|
161
54
|
*/
|
|
162
|
-
|
|
55
|
+
maxAmountPerTx?: string;
|
|
163
56
|
/**
|
|
164
|
-
*
|
|
57
|
+
* Automatically run one-time Permit2 USDC approve on first Smart Wallet
|
|
58
|
+
* x402 payment. The approve is sponsored by the existing paymaster and
|
|
59
|
+
* costs nothing to the user in gas. Default: true.
|
|
165
60
|
*/
|
|
166
|
-
|
|
61
|
+
autoApprovePermit2?: boolean;
|
|
167
62
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* 2. Parse payment headers
|
|
172
|
-
* 3. Execute atomic USDC transfer
|
|
173
|
-
* 4. Retry with tx hash as proof (same method/headers/body)
|
|
174
|
-
* 5. Return response (settlement complete!)
|
|
175
|
-
*
|
|
176
|
-
* @param params - Payment parameters with optional HTTP method, headers, body
|
|
63
|
+
* MEV hard cap on signed authorization validity window in seconds.
|
|
64
|
+
* Facilitator/server may propose longer `maxTimeoutSeconds`, but we clamp
|
|
65
|
+
* to this value before signing. Default: 300 (5 minutes).
|
|
177
66
|
*/
|
|
178
|
-
|
|
67
|
+
maxAuthorizationValidSec?: number;
|
|
179
68
|
/**
|
|
180
|
-
*
|
|
69
|
+
* Allowlist of asset token contract addresses the adapter will pay.
|
|
70
|
+
*
|
|
71
|
+
* Undefined (default) = all canonical USDC addresses on the configured
|
|
72
|
+
* `allowedNetworks` (see `DEFAULT_USDC_BY_NETWORK`). Set to a specific
|
|
73
|
+
* list to restrict further, or pass an empty array to allow any asset
|
|
74
|
+
* (NOT recommended — removes the safety check entirely).
|
|
75
|
+
*
|
|
76
|
+
* P1-1: prevents a server from advertising a different token (e.g., USDT
|
|
77
|
+
* on the same network, or a scam token) and having the adapter sign a
|
|
78
|
+
* payment for it. The cap check in `parseUsdcAmount` / `formatUsdcAmount`
|
|
79
|
+
* assumes 6 decimals, which is only accurate for USDC-family stables.
|
|
80
|
+
* Honoring a non-USDC asset with different decimals would also break the
|
|
81
|
+
* `maxAmountPerTx` cap.
|
|
82
|
+
*
|
|
83
|
+
* Addresses are compared case-insensitively.
|
|
181
84
|
*/
|
|
182
|
-
|
|
85
|
+
allowedAssets?: ReadonlyArray<string>;
|
|
183
86
|
/**
|
|
184
|
-
*
|
|
87
|
+
* Allowlist of HTTPS hosts the adapter will pay without requiring explicit
|
|
88
|
+
* opt-in via `metadata.paymentMethod === 'x402'`.
|
|
89
|
+
*
|
|
90
|
+
* Undefined or empty (default) = no host allowlist; callers must always
|
|
91
|
+
* opt in explicitly unless they trust every HTTPS URL their code hits.
|
|
92
|
+
* Set to specific hostnames (e.g. `['x402.org', 'api.mycoinbase.com']`) to
|
|
93
|
+
* whitelist trusted servers for auto-pay.
|
|
185
94
|
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
95
|
+
* P1-3: prevents accidental `client.pay({ to: 'https://unrelated.com' })`
|
|
96
|
+
* from triggering a silent x402 charge. See `routeHttpsWithOptIn` flow in
|
|
97
|
+
* selectRequirements gate.
|
|
188
98
|
*/
|
|
189
|
-
|
|
99
|
+
allowedHosts?: ReadonlyArray<string>;
|
|
190
100
|
/**
|
|
191
|
-
*
|
|
192
|
-
* @throws {Error} Always - x402 has no lifecycle
|
|
101
|
+
* Optional fetch override for tests. Defaults to global fetch.
|
|
193
102
|
*/
|
|
194
|
-
|
|
103
|
+
fetchImpl?: typeof fetch;
|
|
104
|
+
}
|
|
105
|
+
export declare class X402Adapter implements IAdapter {
|
|
106
|
+
private readonly config;
|
|
107
|
+
readonly metadata: AdapterMetadata;
|
|
108
|
+
private readonly x402;
|
|
109
|
+
private readonly fetchWithPayment;
|
|
110
|
+
private readonly maxAmountPerTx;
|
|
111
|
+
private readonly maxAuthorizationValidSec;
|
|
195
112
|
/**
|
|
196
|
-
*
|
|
197
|
-
*
|
|
113
|
+
* Cached resolved allowed-network list. Computed once at construction; used
|
|
114
|
+
* on every selectRequirements call without re-running resolveAllowedNetworks.
|
|
198
115
|
*/
|
|
199
|
-
|
|
116
|
+
private readonly allowedNetworks;
|
|
200
117
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
118
|
+
* Cached lowercase set of allowed asset (token contract) addresses.
|
|
119
|
+
* Undefined means user explicitly passed an empty array, which is our
|
|
120
|
+
* sentinel for "any asset" (NOT recommended — skips the safety check).
|
|
203
121
|
*/
|
|
204
|
-
|
|
122
|
+
private readonly allowedAssetsLc;
|
|
205
123
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* @param url - Request URL
|
|
209
|
-
* @param method - HTTP method
|
|
210
|
-
* @param customHeaders - Custom headers from request params
|
|
211
|
-
* @param body - Request body (optional)
|
|
212
|
-
* @param contentType - Content-Type header (optional)
|
|
213
|
-
* @param proofHeaders - Payment proof headers for retry (optional)
|
|
124
|
+
* Cached lowercase set of allowed host names. Empty means no host allowlist
|
|
125
|
+
* (user must always opt in via metadata.paymentMethod for every URL).
|
|
214
126
|
*/
|
|
215
|
-
private
|
|
127
|
+
private readonly allowedHostsLc;
|
|
128
|
+
/** network:tokenAddress → cached approved state */
|
|
129
|
+
private readonly permit2ApprovedCache;
|
|
130
|
+
/** network:tokenAddress → in-flight approve promise (coalesces concurrent callers) */
|
|
131
|
+
private readonly permit2InflightApprovals;
|
|
132
|
+
/** Completed payment records for getStatus() lookups. Capped to prevent unbounded growth. */
|
|
133
|
+
private readonly payments;
|
|
134
|
+
private static readonly MAX_PAYMENT_RECORDS;
|
|
135
|
+
constructor(config: X402AdapterConfig);
|
|
216
136
|
/**
|
|
217
|
-
*
|
|
137
|
+
* STRICT HTTPS ONLY. `http://` is rejected at the canHandle level to prevent
|
|
138
|
+
* MITM interception of signed payment payloads. Integration tests that need
|
|
139
|
+
* localhost use a dedicated test flag (not exposed to end users).
|
|
140
|
+
*
|
|
141
|
+
* P1-3: canHandle returns true for any HTTPS URL so the router can select
|
|
142
|
+
* this adapter, but `validate()` enforces explicit opt-in before payment
|
|
143
|
+
* actually executes. This keeps the declarative "any HTTPS is x402-capable"
|
|
144
|
+
* shape while protecting against accidental auto-pay.
|
|
218
145
|
*/
|
|
219
|
-
|
|
146
|
+
canHandle(params: UnifiedPayParams): boolean;
|
|
147
|
+
validate(params: UnifiedPayParams): void;
|
|
148
|
+
pay(params: UnifiedPayParams): Promise<UnifiedPayResult>;
|
|
149
|
+
getStatus(txId: string): Promise<TransactionStatus>;
|
|
150
|
+
startWork(_txId: string): Promise<void>;
|
|
151
|
+
deliver(_txId: string, _proof?: string): Promise<void>;
|
|
152
|
+
release(_escrowId: string, _attestationUID?: string): Promise<void>;
|
|
220
153
|
/**
|
|
221
|
-
*
|
|
154
|
+
* Registered as `onBeforePaymentCreation` hook on the x402Client in the
|
|
155
|
+
* constructor. Runs AFTER selectRequirements has chosen a target and BEFORE
|
|
156
|
+
* the scheme client signs the payload.
|
|
157
|
+
*
|
|
158
|
+
* For Smart Wallet + Permit2 flow, this is where we ensure the one-time
|
|
159
|
+
* Permit2 approve has been submitted and confirmed. The hook is awaited by
|
|
160
|
+
* @x402/core's createPaymentPayload, so we can block signing until the
|
|
161
|
+
* approve lands — no double roundtrip, no race.
|
|
162
|
+
*
|
|
163
|
+
* Return `{ abort: true, reason }` to cancel the payment cleanly.
|
|
222
164
|
*/
|
|
223
|
-
private
|
|
165
|
+
private beforePaymentCreationHook;
|
|
224
166
|
/**
|
|
225
|
-
*
|
|
167
|
+
* Registered as `paymentRequirementsSelector` on the x402Client.
|
|
168
|
+
* Called after server's payment-required is parsed, before signing.
|
|
169
|
+
*
|
|
170
|
+
* Picks the best requirement from `accepts[]` based on:
|
|
171
|
+
* 1. scheme === "exact" AND network in our allowlist
|
|
172
|
+
* 2. Wallet tier: Smart Wallet prefers Permit2, EOA prefers EIP-3009
|
|
173
|
+
* 3. Amount within maxAmountPerTx safety cap
|
|
174
|
+
* 4. Clamps maxTimeoutSeconds to maxAuthorizationValidSec (MEV cap)
|
|
175
|
+
*/
|
|
176
|
+
private selectRequirements;
|
|
177
|
+
private ensurePermit2Approved;
|
|
178
|
+
/**
|
|
179
|
+
* P1-2: Read `USDC.allowance(smartWallet, PERMIT2_ADDRESS)` via the wallet
|
|
180
|
+
* provider's read provider and return true if already >= a sensible threshold
|
|
181
|
+
* (half of max uint256 — Permit2 approves are typically MAX_UINT256).
|
|
226
182
|
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
183
|
+
* Returns false if the wallet provider doesn't expose a read provider
|
|
184
|
+
* (older wallet implementations) — callers then fall back to submitting
|
|
185
|
+
* the approve unconditionally, which is the safe (but slightly wasteful)
|
|
186
|
+
* default.
|
|
187
|
+
*
|
|
188
|
+
* Uses eth_call with the standard ERC-20 allowance ABI selector to avoid
|
|
189
|
+
* pulling in additional contract ABIs.
|
|
230
190
|
*/
|
|
231
|
-
private
|
|
191
|
+
private readPermit2AllowanceIsSet;
|
|
232
192
|
/**
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
* @param endpoint - Request URL
|
|
237
|
-
* @param txHash - Payment transaction hash as proof
|
|
238
|
-
* @param method - Original HTTP method
|
|
239
|
-
* @param customHeaders - Original custom headers
|
|
240
|
-
* @param body - Original request body
|
|
241
|
-
* @param contentType - Original content-type
|
|
193
|
+
* Check if the Smart Wallet is deployed on-chain (has code).
|
|
194
|
+
* Returns true for EOA wallets (they're always "deployed" in a loose sense)
|
|
195
|
+
* and for deployed Smart Wallets. Returns false for counterfactual wallets.
|
|
242
196
|
*/
|
|
243
|
-
private
|
|
197
|
+
private isWalletDeployed;
|
|
198
|
+
private mapToPayResult;
|
|
244
199
|
/**
|
|
245
|
-
*
|
|
200
|
+
* Bridge our IWalletProvider.signTypedData to @x402/evm's ClientEvmSigner
|
|
201
|
+
* structural type. Only `address` + `signTypedData` are required for the
|
|
202
|
+
* `exact` scheme flow we use.
|
|
203
|
+
*
|
|
204
|
+
* B3: no outer try/catch here — each IWalletProvider implementation is the
|
|
205
|
+
* error-converting boundary and already throws X402SignatureFailedError on
|
|
206
|
+
* failure. Wrapping here would produce double-nested error messages like
|
|
207
|
+
* "walletProvider.signTypedData failed: EOA signTypedData failed: ...".
|
|
246
208
|
*/
|
|
247
|
-
private
|
|
209
|
+
private walletProviderToClientEvmSigner;
|
|
248
210
|
}
|
|
249
211
|
//# sourceMappingURL=X402Adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"X402Adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/X402Adapter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"X402Adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/X402Adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAgBH,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAA2B,MAAM,YAAY,CAAC;AAClF,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAmB,MAAM,2BAA2B,CAAC;AAkB7E;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;OAKG;IACH,cAAc,EAAE,eAAe,CAAC;IAEhC;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAExC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAElC;;;;;;;;;;;;;;;;OAgBG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAEtC;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAErC;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAqDD,qBAAa,WAAY,YAAW,QAAQ;IA4C9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IA3CnC,SAAgB,QAAQ,EAAE,eAAe,CAQvC;IAEF,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAkC;IACvD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAe;IAChD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAS;IAClD;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAwB;IAExD;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkC;IAElE;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAsB;IAErD,mDAAmD;IACnD,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAqB;IAE1D,sFAAsF;IACtF,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAoC;IAE7E,6FAA6F;IAC7F,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwC;IACjE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAU;gBAExB,MAAM,EAAE,iBAAiB;IAgEtD;;;;;;;;;OASG;IACH,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO;IAI5C,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI;IAsClC,GAAG,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA0CxD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA6BnD,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOvC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtD,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWzE;;;;;;;;;;;OAWG;YACW,yBAAyB;IA2CvC;;;;;;;;;OASG;IACH,OAAO,CAAC,kBAAkB;YAyEZ,qBAAqB;IAyEnC;;;;;;;;;;;;OAYG;YACW,yBAAyB;IAkCvC;;;;OAIG;YACW,gBAAgB;YAqBhB,cAAc;IAsG5B;;;;;;;;;OASG;IACH,OAAO,CAAC,+BAA+B;CAkBxC"}
|