agent0-sdk 1.5.3 → 1.7.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.
Files changed (83) hide show
  1. package/README.md +59 -18
  2. package/dist/core/a2a-client.d.ts +109 -0
  3. package/dist/core/a2a-client.d.ts.map +1 -0
  4. package/dist/core/a2a-client.js +792 -0
  5. package/dist/core/a2a-client.js.map +1 -0
  6. package/dist/core/a2a-summary-client.d.ts +28 -0
  7. package/dist/core/a2a-summary-client.d.ts.map +1 -0
  8. package/dist/core/a2a-summary-client.js +79 -0
  9. package/dist/core/a2a-summary-client.js.map +1 -0
  10. package/dist/core/agent.d.ts +74 -3
  11. package/dist/core/agent.d.ts.map +1 -1
  12. package/dist/core/agent.js +267 -7
  13. package/dist/core/agent.js.map +1 -1
  14. package/dist/core/contracts.d.ts +5 -0
  15. package/dist/core/contracts.d.ts.map +1 -1
  16. package/dist/core/contracts.js +11 -0
  17. package/dist/core/contracts.js.map +1 -1
  18. package/dist/core/endpoint-crawler.d.ts +10 -0
  19. package/dist/core/endpoint-crawler.d.ts.map +1 -1
  20. package/dist/core/endpoint-crawler.js +59 -4
  21. package/dist/core/endpoint-crawler.js.map +1 -1
  22. package/dist/core/feedback-manager.d.ts.map +1 -1
  23. package/dist/core/feedback-manager.js +27 -32
  24. package/dist/core/feedback-manager.js.map +1 -1
  25. package/dist/core/ipfs-client.d.ts +26 -5
  26. package/dist/core/ipfs-client.d.ts.map +1 -1
  27. package/dist/core/ipfs-client.js +133 -108
  28. package/dist/core/ipfs-client.js.map +1 -1
  29. package/dist/core/sdk.d.ts +70 -3
  30. package/dist/core/sdk.d.ts.map +1 -1
  31. package/dist/core/sdk.js +158 -19
  32. package/dist/core/sdk.js.map +1 -1
  33. package/dist/core/subgraph-client.d.ts.map +1 -1
  34. package/dist/core/subgraph-client.js +16 -0
  35. package/dist/core/subgraph-client.js.map +1 -1
  36. package/dist/core/viem-chain-client.d.ts.map +1 -1
  37. package/dist/core/viem-chain-client.js +5 -4
  38. package/dist/core/viem-chain-client.js.map +1 -1
  39. package/dist/core/x402-payment.d.ts +28 -0
  40. package/dist/core/x402-payment.d.ts.map +1 -0
  41. package/dist/core/x402-payment.js +242 -0
  42. package/dist/core/x402-payment.js.map +1 -0
  43. package/dist/core/x402-request.d.ts +33 -0
  44. package/dist/core/x402-request.d.ts.map +1 -0
  45. package/dist/core/x402-request.js +195 -0
  46. package/dist/core/x402-request.js.map +1 -0
  47. package/dist/core/x402-types.d.ts +147 -0
  48. package/dist/core/x402-types.d.ts.map +1 -0
  49. package/dist/core/x402-types.js +190 -0
  50. package/dist/core/x402-types.js.map +1 -0
  51. package/dist/index.d.ts +3 -0
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +2 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/models/a2a.d.ts +176 -0
  56. package/dist/models/a2a.d.ts.map +1 -0
  57. package/dist/models/a2a.js +5 -0
  58. package/dist/models/a2a.js.map +1 -0
  59. package/dist/models/generated/subgraph-types.d.ts +87 -26
  60. package/dist/models/generated/subgraph-types.d.ts.map +1 -1
  61. package/dist/models/index.d.ts +1 -0
  62. package/dist/models/index.d.ts.map +1 -1
  63. package/dist/models/index.js +1 -0
  64. package/dist/models/index.js.map +1 -1
  65. package/dist/models/interfaces.d.ts +16 -10
  66. package/dist/models/interfaces.d.ts.map +1 -1
  67. package/dist/models/interfaces.js.map +1 -1
  68. package/dist/utils/data-uri.d.ts +33 -0
  69. package/dist/utils/data-uri.d.ts.map +1 -0
  70. package/dist/utils/data-uri.js +157 -0
  71. package/dist/utils/data-uri.js.map +1 -0
  72. package/dist/utils/index.d.ts +2 -0
  73. package/dist/utils/index.d.ts.map +1 -1
  74. package/dist/utils/index.js +2 -0
  75. package/dist/utils/index.js.map +1 -1
  76. package/dist/utils/registration-json.d.ts +12 -0
  77. package/dist/utils/registration-json.d.ts.map +1 -0
  78. package/dist/utils/registration-json.js +67 -0
  79. package/dist/utils/registration-json.js.map +1 -0
  80. package/dist/utils/validation.d.ts.map +1 -1
  81. package/dist/utils/validation.js +4 -0
  82. package/dist/utils/validation.js.map +1 -1
  83. package/package.json +15 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402-payment.d.ts","sourceRoot":"","sources":["../../src/core/x402-payment.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAuEzD;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,WAAW,GACvB,OAAO,CAAC,OAAO,CAAC,CAgBlB;AAyDD;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,WAAW,EACxB,SAAS,CAAC,EAAE,eAAe,GAC1B,OAAO,CAAC,MAAM,CAAC,CA8FjB"}
@@ -0,0 +1,242 @@
1
+ /**
2
+ * Build EVM x402 payment payload (EIP-3009 TransferWithAuthorization style).
3
+ * Uses ChainClient only (no viem) to align with SDK conventions.
4
+ *
5
+ * Spec alignment (docs/x402v1.md, docs/x402v2.md):
6
+ * - V1: header X-PAYMENT, payload { x402Version: 1, scheme, network, payload }; network is human-readable (e.g. "base", "base-sepolia").
7
+ * - V2: header PAYMENT-SIGNATURE, payload { x402Version: 2, accepted, payload, extensions }; network is CAIP-2 (eip155:chainId).
8
+ */
9
+ /** Minimal ABI for token name (ERC-20). */
10
+ const NAME_ABI = [
11
+ { inputs: [], name: 'name', outputs: [{ internalType: 'string', name: '', type: 'string' }], stateMutability: 'view', type: 'function' },
12
+ ];
13
+ /** Optional version (EIP-3009 / EIP-712 domain). */
14
+ const VERSION_ABI = [
15
+ { inputs: [], name: 'version', outputs: [{ internalType: 'string', name: '', type: 'string' }], stateMutability: 'view', type: 'function' },
16
+ ];
17
+ /** ERC-20 balanceOf for balance checks (payFirst). */
18
+ const BALANCE_OF_ABI = [
19
+ { inputs: [{ internalType: 'address', name: 'account', type: 'address' }], name: 'balanceOf', outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], stateMutability: 'view', type: 'function' },
20
+ ];
21
+ /** EIP-3009 TransferWithAuthorization type for EIP-712. */
22
+ const TRANSFER_WITH_AUTHORIZATION_TYPES = [
23
+ { name: 'from', type: 'address' },
24
+ { name: 'to', type: 'address' },
25
+ { name: 'value', type: 'uint256' },
26
+ { name: 'validAfter', type: 'uint256' },
27
+ { name: 'validBefore', type: 'uint256' },
28
+ { name: 'nonce', type: 'bytes32' },
29
+ ];
30
+ function randomBytes32Hex() {
31
+ const bytes = new Uint8Array(32);
32
+ if (typeof globalThis.crypto !== 'undefined' && globalThis.crypto.getRandomValues) {
33
+ globalThis.crypto.getRandomValues(bytes);
34
+ }
35
+ else {
36
+ throw new Error('x402: crypto.getRandomValues not available for nonce generation');
37
+ }
38
+ let hex = '0x';
39
+ for (let i = 0; i < bytes.length; i++) {
40
+ hex += bytes[i].toString(16).padStart(2, '0');
41
+ }
42
+ return hex;
43
+ }
44
+ /**
45
+ * Resolve token contract address from accept (token or asset; must be checksum address).
46
+ */
47
+ function tokenAddress(accept, chainClient) {
48
+ const raw = accept.token || accept.asset || '';
49
+ if (!raw || !chainClient.isAddress(raw)) {
50
+ throw new Error('x402: accept has no valid token/asset address');
51
+ }
52
+ return chainClient.toChecksumAddress(raw);
53
+ }
54
+ /**
55
+ * Resolve destination (to) address from accept.
56
+ */
57
+ function destinationAddress(accept, chainClient) {
58
+ const raw = accept.destination || accept.payTo;
59
+ if (!raw || !chainClient.isAddress(raw)) {
60
+ throw new Error('x402: accept has no valid destination/payTo address');
61
+ }
62
+ return chainClient.toChecksumAddress(raw);
63
+ }
64
+ /**
65
+ * Resolve value in smallest units (string for uint256).
66
+ */
67
+ function valueAmount(accept) {
68
+ const v = accept.price ?? accept.maxAmountRequired ?? '0';
69
+ return String(v);
70
+ }
71
+ /**
72
+ * Check whether the signer has sufficient token balance for the given accept on the given chain.
73
+ * Returns true if balance >= accept.price, false otherwise or on any error (e.g. no signer, RPC failure, invalid token).
74
+ * Used by payFirst() to pick the first accept with sufficient balance.
75
+ */
76
+ export async function checkEvmBalance(accept, chainClient) {
77
+ try {
78
+ const token = tokenAddress(accept, chainClient);
79
+ const signer = await chainClient.ensureAddress();
80
+ if (!signer)
81
+ return false;
82
+ const balance = await chainClient.readContract({
83
+ address: token,
84
+ abi: [...BALANCE_OF_ABI],
85
+ functionName: 'balanceOf',
86
+ args: [signer],
87
+ });
88
+ const price = BigInt(valueAmount(accept));
89
+ return balance >= price;
90
+ }
91
+ catch {
92
+ return false;
93
+ }
94
+ }
95
+ /**
96
+ * x402 v1 spec §5.2: PaymentPayload.network must be a human-readable network identifier
97
+ * (e.g. "base-sepolia", "ethereum-mainnet"), not CAIP-2. Map CAIP-2 or chainId to v1 name.
98
+ */
99
+ const V1_NETWORK_NAMES = {
100
+ 'eip155:1': 'ethereum-mainnet',
101
+ 'eip155:11155111': 'ethereum-sepolia',
102
+ 'eip155:8453': 'base',
103
+ 'eip155:84532': 'base-sepolia',
104
+ 'eip155:43114': 'avalanche',
105
+ 'eip155:43113': 'avalanche-fuji',
106
+ 'eip155:4689': 'iotex',
107
+ 'eip155:4690': 'iotex-testnet',
108
+ };
109
+ function toV1NetworkName(networkOrChainId) {
110
+ const s = String(networkOrChainId);
111
+ if (V1_NETWORK_NAMES[s])
112
+ return V1_NETWORK_NAMES[s];
113
+ const caip = s.startsWith('eip155:') ? s : `eip155:${s}`;
114
+ if (V1_NETWORK_NAMES[caip])
115
+ return V1_NETWORK_NAMES[caip];
116
+ return s;
117
+ }
118
+ /**
119
+ * Fetch EIP-712 domain name and version from token contract (for EIP-3009).
120
+ * Falls back to "Token" / "2" if version() is not present.
121
+ */
122
+ async function getTokenDomain(tokenAddress, chainId, chainClient) {
123
+ let name = 'Token';
124
+ let version = '2';
125
+ try {
126
+ name = await chainClient.readContract({
127
+ address: tokenAddress,
128
+ abi: [...NAME_ABI],
129
+ functionName: 'name',
130
+ });
131
+ }
132
+ catch {
133
+ // keep default
134
+ }
135
+ try {
136
+ version = await chainClient.readContract({
137
+ address: tokenAddress,
138
+ abi: [...VERSION_ABI],
139
+ functionName: 'version',
140
+ });
141
+ }
142
+ catch {
143
+ // EIP-3009 often uses "2"
144
+ }
145
+ return { name: name || 'Token', version: version || '2' };
146
+ }
147
+ /**
148
+ * Build the base64-encoded PAYMENT-SIGNATURE payload for EVM (x402 style).
149
+ * Uses EIP-3009 TransferWithAuthorization typed data and ChainClient.signTypedData.
150
+ *
151
+ * @param accept - Payment option from 402 response (token, destination, price, etc.)
152
+ * @param chainClient - SDK chain client (signer required)
153
+ * @param _snapshot - Unused; reserved for future (e.g. request-specific nonce)
154
+ * @returns Base64 string to set as PAYMENT-SIGNATURE header
155
+ */
156
+ export async function buildEvmPayment(accept, chainClient, _snapshot) {
157
+ const token = tokenAddress(accept, chainClient);
158
+ const to = destinationAddress(accept, chainClient);
159
+ const value = valueAmount(accept);
160
+ const chainId = chainClient.chainId;
161
+ const { name: domainName, version: domainVersion } = await getTokenDomain(token, chainId, chainClient);
162
+ const from = await chainClient.ensureAddress();
163
+ const validAfter = '0';
164
+ const validBefore = String(Math.floor(Date.now() / 1000) + 3600); // 1 hour
165
+ const nonce = randomBytes32Hex();
166
+ const domain = {
167
+ name: domainName,
168
+ version: domainVersion,
169
+ chainId,
170
+ verifyingContract: token,
171
+ };
172
+ const types = {
173
+ TransferWithAuthorization: TRANSFER_WITH_AUTHORIZATION_TYPES,
174
+ };
175
+ const message = {
176
+ from,
177
+ to,
178
+ value: BigInt(value),
179
+ validAfter: BigInt(validAfter),
180
+ validBefore: BigInt(validBefore),
181
+ nonce,
182
+ };
183
+ const signature = await chainClient.signTypedData({
184
+ domain,
185
+ types,
186
+ primaryType: 'TransferWithAuthorization',
187
+ message,
188
+ });
189
+ // x402 spec: use server's x402Version from 402 response when available; else infer from CAIP-2 network.
190
+ const networkStr = accept.network ?? String(chainId);
191
+ const serverVersion = _snapshot?.x402Version;
192
+ const isV2 = serverVersion === 2 || (serverVersion == null && /^eip155:\d+$/.test(String(networkStr)));
193
+ const scheme = accept.scheme ?? 'exact';
194
+ const amount = value;
195
+ const payTo = to;
196
+ if (isV2) {
197
+ // V2 spec §5.2: client MUST send "accepted" = the chosen PaymentRequirements so server can match.
198
+ const accepted = {
199
+ scheme,
200
+ network: networkStr,
201
+ amount,
202
+ asset: token,
203
+ payTo,
204
+ maxTimeoutSeconds: typeof accept.maxTimeoutSeconds === 'number'
205
+ ? accept.maxTimeoutSeconds
206
+ : 60,
207
+ ...(accept.extra != null && { extra: accept.extra }),
208
+ };
209
+ const payloadV2 = {
210
+ x402Version: 2,
211
+ scheme,
212
+ network: networkStr,
213
+ ...(_snapshot?.resource != null && { resource: _snapshot.resource }),
214
+ accepted,
215
+ payload: {
216
+ signature,
217
+ authorization: { from, to, value, validAfter, validBefore, nonce },
218
+ },
219
+ extensions: {},
220
+ };
221
+ const json = JSON.stringify(payloadV2);
222
+ const base64 = typeof Buffer !== 'undefined'
223
+ ? Buffer.from(json, 'utf8').toString('base64')
224
+ : btoa(unescape(encodeURIComponent(json)));
225
+ return base64;
226
+ }
227
+ const payload = {
228
+ x402Version: 1,
229
+ scheme,
230
+ network: toV1NetworkName(networkStr),
231
+ payload: {
232
+ signature,
233
+ authorization: { from, to, value, validAfter, validBefore, nonce },
234
+ },
235
+ };
236
+ const json = JSON.stringify(payload);
237
+ const base64 = typeof Buffer !== 'undefined'
238
+ ? Buffer.from(json, 'utf8').toString('base64')
239
+ : btoa(unescape(encodeURIComponent(json)));
240
+ return base64;
241
+ }
242
+ //# sourceMappingURL=x402-payment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402-payment.js","sourceRoot":"","sources":["../../src/core/x402-payment.ts"],"names":[],"mappings":"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CAAC;QACvC,MAAM,MAAM,GAAG,OAAO,MAAM,KAAK,WAAW;YAC1C,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAC9C,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC7C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,OAAO,GAAG;QACd,WAAW,EAAE,CAAC;QACd,MAAM;QACN,OAAO,EAAE,eAAe,CAAC,UAAU,CAAC;QACpC,OAAO,EAAE;YACP,SAAS;YACT,aAAa,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE;SACnE;KACF,CAAC;IACF,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,OAAO,MAAM,KAAK,WAAW;QAC1C,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC9C,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Generic HTTP request with x402 (402 Payment Required) handling.
3
+ * Used by sdk.request() and by A2A methods.
4
+ */
5
+ import type { X402Accept, X402RequestOptions, X402RequestResult } from './x402-types.js';
6
+ import type { ResourceInfo } from './x402-types.js';
7
+ /** Snapshot of the original request so pay() can retry the same request with PAYMENT-SIGNATURE. */
8
+ export interface RequestSnapshot {
9
+ url: string;
10
+ method: string;
11
+ headers: Record<string, string>;
12
+ body?: string | ArrayBuffer | Uint8Array;
13
+ /** x402 version from server's 402 PAYMENT-REQUIRED header (1 or 2). When set, buildPayment uses it for payload shape. */
14
+ x402Version?: number;
15
+ /** V2 ResourceInfo from 402 response when present. Passed to buildPayment for V2 payload. */
16
+ resource?: ResourceInfo;
17
+ /** V1/V2 error message from 402 response when present. */
18
+ error?: string;
19
+ }
20
+ export interface X402RequestDeps {
21
+ fetch: typeof globalThis.fetch;
22
+ buildPayment: (accept: X402Accept, snapshot: RequestSnapshot) => Promise<string>;
23
+ /** Optional: used by payFirst() to pick the first accept with sufficient token balance. */
24
+ checkBalance?: (accept: X402Accept) => Promise<boolean>;
25
+ }
26
+ /**
27
+ * Perform a single HTTP request with built-in 402 handling.
28
+ * - 2xx: return parsed result (default: JSON body; or use parseResponse for custom parsing).
29
+ * - 402: do not throw; return { x402Required: true, x402Payment } with pay(accept?) (uses first-with-balance when checkBalance is set) that retries once.
30
+ * - Other status or network error: throw.
31
+ */
32
+ export declare function requestWithX402<T = unknown>(options: X402RequestOptions<T>, deps: X402RequestDeps): Promise<X402RequestResult<T>>;
33
+ //# sourceMappingURL=x402-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402-request.d.ts","sourceRoot":"","sources":["../../src/core/x402-request.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAe,kBAAkB,EAAwB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC5H,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,mGAAmG;AACnG,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,CAAC;IACzC,yHAAyH;IACzH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6FAA6F;IAC7F,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,0DAA0D;IAC1D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAC/B,YAAY,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACjF,2FAA2F;IAC3F,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACzD;AASD;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,CAAC,GAAG,OAAO,EAC/C,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAC9B,IAAI,EAAE,eAAe,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAiM/B"}
@@ -0,0 +1,195 @@
1
+ /**
2
+ * Generic HTTP request with x402 (402 Payment Required) handling.
3
+ * Used by sdk.request() and by A2A methods.
4
+ */
5
+ import { filterEvmAccepts, parse402FromBody, parse402FromHeader, parse402SettlementFromHeader, parse402FromWWWAuthenticate } from './x402-types.js';
6
+ /**
7
+ * Default parser when parseResponse is omitted: parse response body as JSON (res.json()).
8
+ */
9
+ async function defaultParseResponse(res) {
10
+ return res.json();
11
+ }
12
+ /**
13
+ * Perform a single HTTP request with built-in 402 handling.
14
+ * - 2xx: return parsed result (default: JSON body; or use parseResponse for custom parsing).
15
+ * - 402: do not throw; return { x402Required: true, x402Payment } with pay(accept?) (uses first-with-balance when checkBalance is set) that retries once.
16
+ * - Other status or network error: throw.
17
+ */
18
+ export async function requestWithX402(options, deps) {
19
+ const { url, method, headers = {}, body, payment } = options;
20
+ const parseResponse = options.parseResponse ?? defaultParseResponse;
21
+ const snapshot = {
22
+ url,
23
+ method,
24
+ headers: { ...headers },
25
+ body,
26
+ };
27
+ /** x402 spec: V1 uses X-PAYMENT header; V2 uses PAYMENT-SIGNATURE. Fetch to a given requestUrl (default snapshot.url). */
28
+ const doFetch = async (paymentPayload, paymentHeaderName, requestUrl) => {
29
+ const targetUrl = requestUrl ?? snapshot.url;
30
+ const reqHeaders = { ...snapshot.headers };
31
+ if (paymentPayload !== undefined) {
32
+ const headerName = paymentHeaderName ?? 'PAYMENT-SIGNATURE';
33
+ reqHeaders[headerName] = paymentPayload;
34
+ }
35
+ return deps.fetch(targetUrl, {
36
+ method: snapshot.method,
37
+ headers: reqHeaders,
38
+ body: snapshot.body,
39
+ });
40
+ };
41
+ const firstPayload = payment !== undefined ? payment : undefined;
42
+ let response = await doFetch(firstPayload);
43
+ if (response.status === 402) {
44
+ // x402 spec: payment requirements in header (PAYMENT-REQUIRED base64) or body (JSON). Fallback: WWW-Authenticate.
45
+ const headerPayload = response.headers.get('payment-required') ?? response.headers.get('PAYMENT-REQUIRED');
46
+ let { accepts, x402Version, resource, error } = parse402FromHeader(headerPayload);
47
+ let responseFromWWWAuthenticate = false;
48
+ if (accepts.length === 0) {
49
+ const wwwAuth = response.headers.get('www-authenticate') ?? response.headers.get('WWW-Authenticate');
50
+ const parsed = parse402FromWWWAuthenticate(wwwAuth);
51
+ accepts = parsed.accepts;
52
+ if (accepts.length > 0)
53
+ responseFromWWWAuthenticate = true;
54
+ if (x402Version === undefined && parsed.x402Version !== undefined)
55
+ x402Version = parsed.x402Version;
56
+ }
57
+ if (accepts.length === 0) {
58
+ const bodyText = await response.text();
59
+ const parsed = parse402FromBody(bodyText);
60
+ accepts = parsed.accepts;
61
+ if (x402Version === undefined && parsed.x402Version !== undefined)
62
+ x402Version = parsed.x402Version;
63
+ if (resource === undefined && parsed.resource !== undefined)
64
+ resource = parsed.resource;
65
+ if (error === undefined && parsed.error !== undefined)
66
+ error = parsed.error;
67
+ }
68
+ accepts = filterEvmAccepts(accepts);
69
+ const singleAccept = accepts.length === 1 ? accepts[0] : undefined;
70
+ const payFn = async (accept) => {
71
+ let chosen;
72
+ if (accept === undefined) {
73
+ if (deps.checkBalance) {
74
+ for (let i = 0; i < accepts.length; i++) {
75
+ const acc = accepts[i];
76
+ if (acc && (await deps.checkBalance(acc))) {
77
+ chosen = acc;
78
+ break;
79
+ }
80
+ }
81
+ if (chosen === undefined) {
82
+ throw new Error('x402: no accept with sufficient balance');
83
+ }
84
+ }
85
+ if (chosen === undefined) {
86
+ chosen = singleAccept ?? accepts[0];
87
+ }
88
+ }
89
+ else if (typeof accept === 'number') {
90
+ chosen = accepts[accept];
91
+ }
92
+ else {
93
+ chosen = accept;
94
+ }
95
+ if (!chosen) {
96
+ throw new Error('x402: no payment option selected (empty accepts or invalid index)');
97
+ }
98
+ const payload = await deps.buildPayment(chosen, { ...snapshot, x402Version, resource, error });
99
+ // When server challenged with WWW-Authenticate: try Authorization: x402 <payload> first (RFC 7235); if 402 again, retry with PAYMENT-SIGNATURE (some servers expect spec header).
100
+ const paymentHeaderName = responseFromWWWAuthenticate
101
+ ? 'Authorization'
102
+ : (x402Version === 1 ? 'X-PAYMENT' : 'PAYMENT-SIGNATURE');
103
+ const paymentHeaderValue = responseFromWWWAuthenticate ? `x402 ${payload}` : payload;
104
+ const retryHeaders = { ...snapshot.headers, [paymentHeaderName]: paymentHeaderValue };
105
+ const tryUrl = async (requestUrl, useAuthHeader = true) => {
106
+ if (responseFromWWWAuthenticate && !useAuthHeader) {
107
+ return doFetch(payload, 'PAYMENT-SIGNATURE', requestUrl);
108
+ }
109
+ return doFetch(paymentHeaderValue, paymentHeaderName, requestUrl);
110
+ };
111
+ let retryResponse = await tryUrl(snapshot.url);
112
+ // If we used WWW-Authenticate and server returned 402 again, retry with PAYMENT-SIGNATURE (same payload).
113
+ if (responseFromWWWAuthenticate && !retryResponse.ok && retryResponse.status === 402) {
114
+ retryResponse = await tryUrl(snapshot.url, false);
115
+ }
116
+ if (!retryResponse.ok) {
117
+ let body = '';
118
+ try {
119
+ body = await retryResponse.text();
120
+ }
121
+ catch {
122
+ body = '(failed to read body)';
123
+ }
124
+ const paymentRequired = retryResponse.headers.get('payment-required') ?? retryResponse.headers.get('PAYMENT-REQUIRED');
125
+ const paymentResponse = retryResponse.headers.get('payment-response') ?? retryResponse.headers.get('PAYMENT-RESPONSE');
126
+ const responseHeaders = {};
127
+ retryResponse.headers.forEach((v, k) => {
128
+ responseHeaders[k] = v;
129
+ });
130
+ const msg = retryResponse.status === 402
131
+ ? 'x402: payment rejected or insufficient (server returned 402 again)'
132
+ : `x402: retry failed with HTTP ${retryResponse.status}`;
133
+ let requestBody = '';
134
+ if (snapshot.body !== undefined) {
135
+ if (typeof snapshot.body === 'string')
136
+ requestBody = snapshot.body;
137
+ else if (snapshot.body instanceof ArrayBuffer)
138
+ requestBody = new TextDecoder().decode(snapshot.body);
139
+ else if (snapshot.body instanceof Uint8Array)
140
+ requestBody = new TextDecoder().decode(snapshot.body);
141
+ }
142
+ const err = new Error(msg);
143
+ err.status = retryResponse.status;
144
+ err.body = body;
145
+ err.url = snapshot.url;
146
+ err.method = snapshot.method;
147
+ err.requestHeaders = retryHeaders;
148
+ err.requestBody = requestBody;
149
+ err.responseHeaders = responseHeaders;
150
+ err.headers = {
151
+ ...(paymentRequired && { 'payment-required': paymentRequired }),
152
+ ...(paymentResponse && { 'payment-response': paymentResponse }),
153
+ };
154
+ if (Object.keys(err.headers).length === 0)
155
+ delete err.headers;
156
+ throw err;
157
+ }
158
+ const result = await parseResponse(retryResponse);
159
+ const paymentResponseHeader = retryResponse.headers.get('payment-response') ?? retryResponse.headers.get('PAYMENT-RESPONSE');
160
+ const settlement = paymentResponseHeader ? parse402SettlementFromHeader(paymentResponseHeader) : undefined;
161
+ if (settlement !== undefined &&
162
+ typeof result === 'object' &&
163
+ result !== null &&
164
+ !Array.isArray(result)) {
165
+ result.x402Settlement = settlement;
166
+ }
167
+ return result;
168
+ };
169
+ const x402Payment = {
170
+ accepts,
171
+ ...(x402Version !== undefined && { x402Version }),
172
+ ...(error !== undefined && { error }),
173
+ ...(resource !== undefined && { resource }),
174
+ ...(singleAccept && {
175
+ price: singleAccept.price,
176
+ token: singleAccept.token,
177
+ network: singleAccept.network,
178
+ }),
179
+ pay: payFn,
180
+ ...(deps.checkBalance && {
181
+ payFirst: () => payFn(), // pay() with no arg now uses first-with-balance
182
+ }),
183
+ };
184
+ const result = {
185
+ x402Required: true,
186
+ x402Payment,
187
+ };
188
+ return result;
189
+ }
190
+ if (response.ok) {
191
+ return parseResponse(response);
192
+ }
193
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
194
+ }
195
+ //# sourceMappingURL=x402-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402-request.js","sourceRoot":"","sources":["../../src/core/x402-request.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAuBpJ;;GAEG;AACH,KAAK,UAAU,oBAAoB,CAAC,GAAa;IAC/C,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAA8B,EAC9B,IAAqB;IAErB,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC7D,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAK,oBAAsD,CAAC;IAEvG,MAAM,QAAQ,GAAoB;QAChC,GAAG;QACH,MAAM;QACN,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE;QACvB,IAAI;KACL,CAAC;IAEF,0HAA0H;IAC1H,MAAM,OAAO,GAAG,KAAK,EACnB,cAAuB,EACvB,iBAA0B,EAC1B,UAAmB,EACA,EAAE;QACrB,MAAM,SAAS,GAAG,UAAU,IAAI,QAAQ,CAAC,GAAG,CAAC;QAC7C,MAAM,UAAU,GAA2B,EAAE,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC;QACnE,IAAI,cAAc,KAAK,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;YAClB,WAAW;SACZ,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;QAChB,OAAO,aAAa,CAAC,QAAQ,CAAkC,CAAC;IAClE,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;AACrE,CAAC"}
@@ -0,0 +1,147 @@
1
+ /**
2
+ * x402 payment-required types and 402 response parsing.
3
+ */
4
+ /**
5
+ * A single payment option from a 402 response (PAYMENT-REQUIRED header).
6
+ * Each entry has at least price and token; optional fields for network, scheme, etc.
7
+ */
8
+ export interface X402Accept {
9
+ /** Amount in smallest units (e.g. USDC 6 decimals). May be string for large values. */
10
+ price: string;
11
+ /** Token contract address or symbol. */
12
+ token: string;
13
+ /** Chain id (number or string e.g. "base-sepolia", "eip155:84532"). */
14
+ network?: string;
15
+ scheme?: string;
16
+ description?: string;
17
+ /** Max amount required when variable. */
18
+ maxAmountRequired?: string;
19
+ /** Destination / pay-to address (recipient or verifying contract). */
20
+ destination?: string;
21
+ /** Asset address (alias for token in some 402 body shapes). */
22
+ asset?: string;
23
+ /** Additional fields from server (e.g. payTo, paymentRequirements). */
24
+ [key: string]: unknown;
25
+ }
26
+ /**
27
+ * Payment-required payload returned when the server responds with HTTP 402.
28
+ * Always includes accepts[]; when there is a single accept, convenience fields may be set.
29
+ */
30
+ export interface X402Payment<T = unknown> {
31
+ /** Array of accepted payment options. Always present. */
32
+ accepts: X402Accept[];
33
+ /** x402 version from server's PAYMENT-REQUIRED header (e.g. 1 or 2). */
34
+ x402Version?: number;
35
+ /** V1/V2 human-readable error message from 402 response when present. */
36
+ error?: string;
37
+ /** V2 ResourceInfo from 402 response when present. */
38
+ resource?: ResourceInfo;
39
+ /** When single accept: convenience price (same as accepts[0].price). */
40
+ price?: string;
41
+ /** When single accept: convenience token (same as accepts[0].token). */
42
+ token?: string;
43
+ /** When single accept: convenience network (same as accepts[0].network). */
44
+ network?: string;
45
+ /**
46
+ * Performs payment and retries the request.
47
+ * No arg = use single accept; number = accepts[index]; X402Accept = chosen option.
48
+ * Resolves to the same shape as a successful request (no x402Required).
49
+ */
50
+ pay(accept?: X402Accept | number): Promise<T>;
51
+ /**
52
+ * When present (deps provided checkBalance): pays using the first accept for which
53
+ * the signer has sufficient token balance on that chain. Throws if none have sufficient balance.
54
+ */
55
+ payFirst?(): Promise<T>;
56
+ }
57
+ /**
58
+ * Options for the generic x402 HTTP request.
59
+ */
60
+ export interface X402RequestOptions<T = unknown> {
61
+ url: string;
62
+ method: string;
63
+ headers?: Record<string, string>;
64
+ body?: string | ArrayBuffer | Uint8Array;
65
+ /**
66
+ * Optional parser for 2xx response body. If omitted, the body is parsed as JSON (res.json()).
67
+ */
68
+ parseResponse?: (response: Response) => Promise<T>;
69
+ /**
70
+ * Optional payment to send with the first request (e.g. base64 PAYMENT-SIGNATURE payload).
71
+ * If provided and server returns 2xx, one round trip; if 402, normal x402 flow.
72
+ */
73
+ payment?: string;
74
+ }
75
+ /**
76
+ * Response when server returns HTTP 402. Caller checks x402Required and may call x402Payment.pay().
77
+ */
78
+ export interface X402RequiredResponse<T> {
79
+ x402Required: true;
80
+ x402Payment: X402Payment<T>;
81
+ }
82
+ /**
83
+ * Result of sdk.request(): either the parsed success value or the 402 response object.
84
+ * Success branch is typed with x402Required?: false so you can always read result.x402Required
85
+ * (undefined/false on success, true on 402) and use if (result.x402Required) to narrow.
86
+ */
87
+ export type X402RequestResult<T> = (T & {
88
+ x402Required?: false;
89
+ }) | X402RequiredResponse<T>;
90
+ /**
91
+ * Type guard: result is 402 response. Returns false for null/undefined.
92
+ */
93
+ export declare function isX402Required<T>(result: X402RequestResult<T> | null | undefined): result is X402RequiredResponse<T>;
94
+ /** Filter accepts to EVM-only (Solana and other non-EVM options removed). Applied when building 402 response. */
95
+ export declare function filterEvmAccepts(accepts: X402Accept[]): X402Accept[];
96
+ /**
97
+ * Result of parsing PAYMENT-REQUIRED header (accepts + optional version, resource, error).
98
+ */
99
+ export interface Parse402FromHeaderResult {
100
+ accepts: X402Accept[];
101
+ x402Version?: number;
102
+ /** V2 PaymentRequired top-level resource (ResourceInfo). Present when server sends it. */
103
+ resource?: ResourceInfo;
104
+ /** V1 PaymentRequirementsResponse human-readable error message. Present when server sends it. */
105
+ error?: string;
106
+ }
107
+ /** V2 ResourceInfo: url, optional description and mimeType (x402 spec §5.1). */
108
+ export interface ResourceInfo {
109
+ url?: string;
110
+ description?: string;
111
+ mimeType?: string;
112
+ }
113
+ /** Settlement response (SettlementResponse / SettleResponse) from PAYMENT-RESPONSE header or body after successful pay. */
114
+ export interface X402SettlementResponse {
115
+ success: boolean;
116
+ errorReason?: string;
117
+ transaction?: string;
118
+ network?: string;
119
+ payer?: string;
120
+ }
121
+ /**
122
+ * Parse PAYMENT-REQUIRED header (x402 spec: base64-encoded JSON with accepts array).
123
+ * Returns accepts, x402Version, and when present resource (v2) and error (v1).
124
+ */
125
+ export declare function parse402FromHeader(headerValue: string | null): Parse402FromHeaderResult;
126
+ /**
127
+ * Parse WWW-Authenticate header with x402 challenge (e.g. 402payment-test.com).
128
+ * Format: x402 address="0x...", amount="0.01", chainId="8453", token="0x..."
129
+ * Returns a single accept; amount is converted to atomic units if it looks like a decimal (USDC 6 decimals).
130
+ */
131
+ export declare function parse402FromWWWAuthenticate(headerValue: string | null): Parse402FromHeaderResult;
132
+ /**
133
+ * Parse 402 response body (JSON with accepts array). Used when server sends payment options in body (e.g. httpay.xyz).
134
+ * Returns accepts, x402Version, and when present resource (v2) and error (v1).
135
+ */
136
+ export declare function parse402FromBody(bodyText: string | null): Parse402FromHeaderResult;
137
+ /**
138
+ * Parse PAYMENT-REQUIRED header (x402 spec: base64-encoded JSON with accepts array).
139
+ * Server sends payment options in header; body may be empty. Returns [] if header missing/invalid.
140
+ */
141
+ export declare function parse402AcceptsFromHeader(headerValue: string | null): X402Accept[];
142
+ /**
143
+ * Parse PAYMENT-RESPONSE header (base64-encoded JSON) after successful pay.
144
+ * Returns settlement info (success, transaction, network, payer) when present and valid.
145
+ */
146
+ export declare function parse402SettlementFromHeader(headerValue: string | null): X402SettlementResponse | undefined;
147
+ //# sourceMappingURL=x402-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402-types.d.ts","sourceRoot":"","sources":["../../src/core/x402-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,uFAAuF;IACvF,KAAK,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACtC,yDAAyD;IACzD,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,GAAG,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,MAAM,G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