@agirails/sdk 2.2.0 → 2.2.2
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/ACTPClient.d.ts +200 -0
- package/dist/ACTPClient.d.ts.map +1 -1
- package/dist/ACTPClient.js +266 -2
- package/dist/ACTPClient.js.map +1 -1
- package/dist/abi/ACTPKernel.json +16 -0
- package/dist/adapters/AdapterRegistry.d.ts +140 -0
- package/dist/adapters/AdapterRegistry.d.ts.map +1 -0
- package/dist/adapters/AdapterRegistry.js +166 -0
- package/dist/adapters/AdapterRegistry.js.map +1 -0
- package/dist/adapters/AdapterRouter.d.ts +165 -0
- package/dist/adapters/AdapterRouter.d.ts.map +1 -0
- package/dist/adapters/AdapterRouter.js +350 -0
- package/dist/adapters/AdapterRouter.js.map +1 -0
- package/dist/adapters/BaseAdapter.d.ts +17 -0
- package/dist/adapters/BaseAdapter.d.ts.map +1 -1
- package/dist/adapters/BaseAdapter.js +21 -0
- package/dist/adapters/BaseAdapter.js.map +1 -1
- package/dist/adapters/BasicAdapter.d.ts +72 -3
- package/dist/adapters/BasicAdapter.d.ts.map +1 -1
- package/dist/adapters/BasicAdapter.js +170 -2
- package/dist/adapters/BasicAdapter.js.map +1 -1
- package/dist/adapters/IAdapter.d.ts +230 -0
- package/dist/adapters/IAdapter.d.ts.map +1 -0
- package/dist/adapters/IAdapter.js +44 -0
- package/dist/adapters/IAdapter.js.map +1 -0
- package/dist/adapters/StandardAdapter.d.ts +70 -1
- package/dist/adapters/StandardAdapter.d.ts.map +1 -1
- package/dist/adapters/StandardAdapter.js +184 -0
- package/dist/adapters/StandardAdapter.js.map +1 -1
- package/dist/adapters/X402Adapter.d.ts +208 -0
- package/dist/adapters/X402Adapter.d.ts.map +1 -0
- package/dist/adapters/X402Adapter.js +423 -0
- package/dist/adapters/X402Adapter.js.map +1 -0
- package/dist/adapters/index.d.ts +8 -0
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +19 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +4 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +184 -4
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/config/networks.js +3 -3
- package/dist/config/networks.js.map +1 -1
- package/dist/erc8004/ERC8004Bridge.d.ts +155 -0
- package/dist/erc8004/ERC8004Bridge.d.ts.map +1 -0
- package/dist/erc8004/ERC8004Bridge.js +325 -0
- package/dist/erc8004/ERC8004Bridge.js.map +1 -0
- package/dist/erc8004/ReputationReporter.d.ts +223 -0
- package/dist/erc8004/ReputationReporter.d.ts.map +1 -0
- package/dist/erc8004/ReputationReporter.js +266 -0
- package/dist/erc8004/ReputationReporter.js.map +1 -0
- package/dist/erc8004/index.d.ts +36 -0
- package/dist/erc8004/index.d.ts.map +1 -0
- package/dist/erc8004/index.js +46 -0
- package/dist/erc8004/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/protocol/ACTPKernel.d.ts +1 -1
- package/dist/protocol/ACTPKernel.d.ts.map +1 -1
- package/dist/protocol/ACTPKernel.js +16 -7
- package/dist/protocol/ACTPKernel.js.map +1 -1
- package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
- package/dist/runtime/BlockchainRuntime.js +2 -0
- package/dist/runtime/BlockchainRuntime.js.map +1 -1
- package/dist/runtime/IACTPRuntime.d.ts +6 -0
- package/dist/runtime/IACTPRuntime.d.ts.map +1 -1
- package/dist/runtime/MockRuntime.d.ts +12 -0
- package/dist/runtime/MockRuntime.d.ts.map +1 -1
- package/dist/runtime/MockRuntime.js +41 -0
- package/dist/runtime/MockRuntime.js.map +1 -1
- package/dist/runtime/types/MockState.d.ts +6 -0
- package/dist/runtime/types/MockState.d.ts.map +1 -1
- package/dist/runtime/types/MockState.js.map +1 -1
- package/dist/types/adapter.d.ts +359 -0
- package/dist/types/adapter.d.ts.map +1 -0
- package/dist/types/adapter.js +115 -0
- package/dist/types/adapter.js.map +1 -0
- package/dist/types/erc8004.d.ts +184 -0
- package/dist/types/erc8004.d.ts.map +1 -0
- package/dist/types/erc8004.js +132 -0
- package/dist/types/erc8004.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/transaction.d.ts +12 -0
- package/dist/types/transaction.d.ts.map +1 -1
- package/dist/types/x402.d.ts +162 -0
- package/dist/types/x402.d.ts.map +1 -0
- package/dist/types/x402.js +162 -0
- package/dist/types/x402.js.map +1 -0
- package/package.json +3 -2
- package/src/ACTPClient.ts +318 -2
- package/src/abi/ACTPKernel.json +16 -0
- package/src/adapters/AdapterRegistry.ts +173 -0
- package/src/adapters/AdapterRouter.ts +417 -0
- package/src/adapters/BaseAdapter.ts +25 -0
- package/src/adapters/BasicAdapter.ts +199 -3
- package/src/adapters/IAdapter.ts +292 -0
- package/src/adapters/StandardAdapter.ts +220 -1
- package/src/adapters/X402Adapter.ts +653 -0
- package/src/adapters/index.ts +27 -0
- package/src/cli/commands/init.ts +208 -3
- package/src/config/networks.ts +3 -3
- package/src/erc8004/ERC8004Bridge.ts +461 -0
- package/src/erc8004/ReputationReporter.ts +472 -0
- package/src/erc8004/index.ts +61 -0
- package/src/index.ts +43 -0
- package/src/protocol/ACTPKernel.ts +26 -7
- package/src/runtime/BlockchainRuntime.ts +2 -0
- package/src/runtime/IACTPRuntime.ts +6 -0
- package/src/runtime/MockRuntime.ts +42 -0
- package/src/runtime/types/MockState.ts +7 -0
- package/src/types/adapter.ts +296 -0
- package/src/types/erc8004.ts +293 -0
- package/src/types/index.ts +3 -0
- package/src/types/transaction.ts +12 -0
- package/src/types/x402.ts +219 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* X402Adapter - HTTP 402 Payment Required Protocol (Atomic Payments)
|
|
4
|
+
*
|
|
5
|
+
* Implements the x402 protocol for atomic, instant API payments.
|
|
6
|
+
* NO escrow, NO state machine, NO disputes - just pay and receive.
|
|
7
|
+
*
|
|
8
|
+
* This is fundamentally different from ACTP:
|
|
9
|
+
* - ACTP: escrow → state machine → disputes → explicit release
|
|
10
|
+
* - x402: atomic payment → instant settlement → done
|
|
11
|
+
*
|
|
12
|
+
* Use x402 for:
|
|
13
|
+
* - Simple API calls (pay-per-request)
|
|
14
|
+
* - Instant delivery (response IS the delivery)
|
|
15
|
+
* - Low-value, high-frequency transactions
|
|
16
|
+
*
|
|
17
|
+
* Use ACTP for:
|
|
18
|
+
* - Complex services requiring verification
|
|
19
|
+
* - High-value transactions needing dispute protection
|
|
20
|
+
* - Multi-step deliveries
|
|
21
|
+
*
|
|
22
|
+
* @module adapters/X402Adapter
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.X402Adapter = void 0;
|
|
26
|
+
const BaseAdapter_1 = require("./BaseAdapter");
|
|
27
|
+
const x402_1 = require("../types/x402");
|
|
28
|
+
// ============================================================================
|
|
29
|
+
// X402Adapter Implementation
|
|
30
|
+
// ============================================================================
|
|
31
|
+
/**
|
|
32
|
+
* X402Adapter - Atomic HTTP payment protocol.
|
|
33
|
+
*
|
|
34
|
+
* Key characteristics:
|
|
35
|
+
* - usesEscrow: false (direct payment)
|
|
36
|
+
* - supportsDisputes: false (atomic = final)
|
|
37
|
+
* - settlementMode: 'atomic' (instant)
|
|
38
|
+
* - releaseRequired: false (no escrow to release)
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const adapter = new X402Adapter(requesterAddress, {
|
|
43
|
+
* expectedNetwork: 'base-sepolia',
|
|
44
|
+
* transferFn: async (to, amount) => {
|
|
45
|
+
* const tx = await usdcContract.transfer(to, amount);
|
|
46
|
+
* return tx.hash;
|
|
47
|
+
* },
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* const result = await adapter.pay({
|
|
51
|
+
* to: 'https://api.provider.com/service',
|
|
52
|
+
* amount: '10', // Hint only, actual amount from 402
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* // That's it! No release() needed.
|
|
56
|
+
* console.log(result.response?.status); // 200
|
|
57
|
+
* console.log(result.releaseRequired); // false
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
class X402Adapter extends BaseAdapter_1.BaseAdapter {
|
|
61
|
+
/**
|
|
62
|
+
* Creates a new X402Adapter instance.
|
|
63
|
+
*
|
|
64
|
+
* @param requesterAddress - The requester's Ethereum address
|
|
65
|
+
* @param config - X402-specific configuration
|
|
66
|
+
*/
|
|
67
|
+
constructor(requesterAddress, config) {
|
|
68
|
+
super(requesterAddress);
|
|
69
|
+
this.config = config;
|
|
70
|
+
/**
|
|
71
|
+
* Adapter metadata - atomic, no escrow.
|
|
72
|
+
*/
|
|
73
|
+
this.metadata = {
|
|
74
|
+
id: 'x402',
|
|
75
|
+
name: 'X402 Atomic Payment Adapter',
|
|
76
|
+
usesEscrow: false,
|
|
77
|
+
supportsDisputes: false,
|
|
78
|
+
requiresIdentity: false,
|
|
79
|
+
settlementMode: 'atomic',
|
|
80
|
+
priority: 70,
|
|
81
|
+
};
|
|
82
|
+
/** Local cache of payments for status lookups */
|
|
83
|
+
this.payments = new Map();
|
|
84
|
+
this.timeout = config.requestTimeout ?? 30000;
|
|
85
|
+
this.fetchFn = config.fetchFn ?? fetch;
|
|
86
|
+
this.defaultHeaders = config.defaultHeaders ?? {};
|
|
87
|
+
this.transferFn = config.transferFn;
|
|
88
|
+
}
|
|
89
|
+
// ==========================================================================
|
|
90
|
+
// IAdapter Implementation
|
|
91
|
+
// ==========================================================================
|
|
92
|
+
/**
|
|
93
|
+
* Check if this adapter can handle the given parameters.
|
|
94
|
+
*
|
|
95
|
+
* X402Adapter handles HTTPS URLs only (security requirement).
|
|
96
|
+
*/
|
|
97
|
+
canHandle(params) {
|
|
98
|
+
if (typeof params.to !== 'string') {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const url = new URL(params.to);
|
|
103
|
+
return url.protocol === 'https:';
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Validate parameters before execution.
|
|
111
|
+
*/
|
|
112
|
+
validate(params) {
|
|
113
|
+
if (!this.canHandle(params)) {
|
|
114
|
+
throw new BaseAdapter_1.ValidationError(`X402 requires HTTPS URL, got: "${params.to}". ` +
|
|
115
|
+
`HTTP endpoints are not supported for security reasons.`);
|
|
116
|
+
}
|
|
117
|
+
const url = new URL(params.to);
|
|
118
|
+
if (url.username || url.password) {
|
|
119
|
+
throw new BaseAdapter_1.ValidationError('URL cannot contain embedded credentials (username:password).');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Execute atomic x402 payment flow with full HTTP support.
|
|
124
|
+
*
|
|
125
|
+
* 1. Request endpoint → get 402
|
|
126
|
+
* 2. Parse payment headers
|
|
127
|
+
* 3. Execute atomic USDC transfer
|
|
128
|
+
* 4. Retry with tx hash as proof (same method/headers/body)
|
|
129
|
+
* 5. Return response (settlement complete!)
|
|
130
|
+
*
|
|
131
|
+
* @param params - Payment parameters with optional HTTP method, headers, body
|
|
132
|
+
*/
|
|
133
|
+
async pay(params) {
|
|
134
|
+
this.validate(params);
|
|
135
|
+
const endpoint = params.to;
|
|
136
|
+
const x402Params = params;
|
|
137
|
+
// Extract HTTP options
|
|
138
|
+
const method = x402Params.method ?? 'GET';
|
|
139
|
+
const requestHeaders = x402Params.headers ?? {};
|
|
140
|
+
const requestBody = this.serializeBody(x402Params.body, x402Params.contentType);
|
|
141
|
+
const contentType = x402Params.contentType ??
|
|
142
|
+
(x402Params.body && method !== 'GET' ? 'application/json' : undefined);
|
|
143
|
+
// Step 1: Initial request
|
|
144
|
+
const initialResponse = await this.makeRequest(endpoint, method, requestHeaders, requestBody, contentType);
|
|
145
|
+
// Step 2: Check response status
|
|
146
|
+
if (initialResponse.status !== 402) {
|
|
147
|
+
if (initialResponse.ok) {
|
|
148
|
+
return this.createFreeServiceResult(params, initialResponse);
|
|
149
|
+
}
|
|
150
|
+
throw new x402_1.X402Error(`Expected 402 Payment Required, got ${initialResponse.status}`, x402_1.X402ErrorCode.NOT_402_RESPONSE, initialResponse);
|
|
151
|
+
}
|
|
152
|
+
// Step 3: Parse payment headers
|
|
153
|
+
const paymentHeaders = this.parsePaymentHeaders(initialResponse);
|
|
154
|
+
// Step 4: Validate network
|
|
155
|
+
if (paymentHeaders.network !== this.config.expectedNetwork) {
|
|
156
|
+
throw new x402_1.X402Error(`Network mismatch: expected ${this.config.expectedNetwork}, got ${paymentHeaders.network}`, x402_1.X402ErrorCode.NETWORK_MISMATCH, initialResponse);
|
|
157
|
+
}
|
|
158
|
+
// Step 5: Validate deadline
|
|
159
|
+
const now = Math.floor(Date.now() / 1000);
|
|
160
|
+
if (paymentHeaders.deadline <= now) {
|
|
161
|
+
throw new x402_1.X402Error(`Payment deadline has passed: ${new Date(paymentHeaders.deadline * 1000).toISOString()}`, x402_1.X402ErrorCode.DEADLINE_PASSED, initialResponse);
|
|
162
|
+
}
|
|
163
|
+
// Step 6: ATOMIC PAYMENT - direct transfer, no escrow
|
|
164
|
+
const txHash = await this.executeAtomicPayment(paymentHeaders);
|
|
165
|
+
// Step 7: Retry with proof (same method/headers/body + payment proof)
|
|
166
|
+
const serviceResponse = await this.retryWithProof(endpoint, txHash, method, requestHeaders, requestBody, contentType);
|
|
167
|
+
// Step 8: Cache payment record for status lookups
|
|
168
|
+
this.payments.set(txHash, {
|
|
169
|
+
txHash,
|
|
170
|
+
provider: paymentHeaders.paymentAddress.toLowerCase(),
|
|
171
|
+
requester: this.requesterAddress.toLowerCase(),
|
|
172
|
+
amount: paymentHeaders.amount,
|
|
173
|
+
timestamp: now,
|
|
174
|
+
endpoint,
|
|
175
|
+
});
|
|
176
|
+
// Step 9: Return result - DONE! No release needed.
|
|
177
|
+
return {
|
|
178
|
+
txId: txHash,
|
|
179
|
+
escrowId: null, // No escrow!
|
|
180
|
+
adapter: this.metadata.id,
|
|
181
|
+
state: 'COMMITTED', // Atomic = immediately settled
|
|
182
|
+
success: true,
|
|
183
|
+
amount: this.formatAmount(paymentHeaders.amount),
|
|
184
|
+
response: serviceResponse,
|
|
185
|
+
releaseRequired: false, // KEY DIFFERENCE from ACTP
|
|
186
|
+
provider: paymentHeaders.paymentAddress.toLowerCase(),
|
|
187
|
+
requester: this.requesterAddress.toLowerCase(),
|
|
188
|
+
deadline: new Date(paymentHeaders.deadline * 1000).toISOString(),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Serialize request body to string.
|
|
193
|
+
*/
|
|
194
|
+
serializeBody(body, _contentType) {
|
|
195
|
+
if (body === undefined)
|
|
196
|
+
return undefined;
|
|
197
|
+
if (typeof body === 'string')
|
|
198
|
+
return body;
|
|
199
|
+
return JSON.stringify(body);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get payment status by transaction hash.
|
|
203
|
+
*
|
|
204
|
+
* For atomic payments, status is simple:
|
|
205
|
+
* - If tx exists → SETTLED (atomic = instant settlement)
|
|
206
|
+
*/
|
|
207
|
+
async getStatus(txId) {
|
|
208
|
+
const record = this.payments.get(txId);
|
|
209
|
+
if (!record) {
|
|
210
|
+
throw new Error(`Payment ${txId} not found. X402 payments are atomic and stateless.`);
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
state: 'SETTLED',
|
|
214
|
+
canStartWork: false,
|
|
215
|
+
canDeliver: false,
|
|
216
|
+
canRelease: false,
|
|
217
|
+
canDispute: false,
|
|
218
|
+
amount: this.formatAmount(record.amount),
|
|
219
|
+
provider: record.provider,
|
|
220
|
+
requester: record.requester,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Not applicable for atomic payments.
|
|
225
|
+
* @throws {Error} Always - x402 has no lifecycle
|
|
226
|
+
*/
|
|
227
|
+
async startWork(_txId) {
|
|
228
|
+
throw new Error('X402 is atomic - no lifecycle methods. ' +
|
|
229
|
+
'Payment and delivery happen atomically. Use ACTP for stateful transactions.');
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Not applicable for atomic payments.
|
|
233
|
+
* @throws {Error} Always - x402 has no lifecycle
|
|
234
|
+
*/
|
|
235
|
+
async deliver(_txId, _proof) {
|
|
236
|
+
throw new Error('X402 is atomic - no lifecycle methods. ' +
|
|
237
|
+
'The HTTP response IS the delivery. Use ACTP for stateful transactions.');
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Not applicable for atomic payments.
|
|
241
|
+
* @throws {Error} Always - x402 has no escrow
|
|
242
|
+
*/
|
|
243
|
+
async release(_escrowId, _attestationUID) {
|
|
244
|
+
throw new Error('X402 is atomic - no escrow to release. ' +
|
|
245
|
+
'Payment settled instantly. Use ACTP for escrow-based transactions.');
|
|
246
|
+
}
|
|
247
|
+
// ==========================================================================
|
|
248
|
+
// Private Helpers
|
|
249
|
+
// ==========================================================================
|
|
250
|
+
/**
|
|
251
|
+
* Make an HTTP request with full options support.
|
|
252
|
+
*
|
|
253
|
+
* @param url - Request URL
|
|
254
|
+
* @param method - HTTP method
|
|
255
|
+
* @param customHeaders - Custom headers from request params
|
|
256
|
+
* @param body - Request body (optional)
|
|
257
|
+
* @param contentType - Content-Type header (optional)
|
|
258
|
+
* @param proofHeaders - Payment proof headers for retry (optional)
|
|
259
|
+
*/
|
|
260
|
+
async makeRequest(url, method, customHeaders = {}, body, contentType, proofHeaders) {
|
|
261
|
+
const controller = new AbortController();
|
|
262
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
263
|
+
try {
|
|
264
|
+
// Build headers: defaults + custom + content-type + proof
|
|
265
|
+
const headers = new Headers(this.defaultHeaders);
|
|
266
|
+
// Add custom headers from request
|
|
267
|
+
for (const [key, value] of Object.entries(customHeaders)) {
|
|
268
|
+
headers.set(key, value);
|
|
269
|
+
}
|
|
270
|
+
// Add content-type if provided
|
|
271
|
+
if (contentType) {
|
|
272
|
+
headers.set('Content-Type', contentType);
|
|
273
|
+
}
|
|
274
|
+
// Add proof headers for retry
|
|
275
|
+
if (proofHeaders) {
|
|
276
|
+
for (const [key, value] of Object.entries(proofHeaders)) {
|
|
277
|
+
headers.set(key, value);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const init = {
|
|
281
|
+
method,
|
|
282
|
+
headers,
|
|
283
|
+
signal: controller.signal,
|
|
284
|
+
};
|
|
285
|
+
// Add body for non-GET requests
|
|
286
|
+
if (body && method !== 'GET') {
|
|
287
|
+
init.body = body;
|
|
288
|
+
}
|
|
289
|
+
return await this.fetchFn(url, init);
|
|
290
|
+
}
|
|
291
|
+
finally {
|
|
292
|
+
clearTimeout(timeoutId);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Parse X-Payment-* headers from 402 response.
|
|
297
|
+
*/
|
|
298
|
+
parsePaymentHeaders(response) {
|
|
299
|
+
const h = response.headers;
|
|
300
|
+
const requiredHeader = h.get(x402_1.X402_HEADERS.REQUIRED);
|
|
301
|
+
if (requiredHeader?.toLowerCase() !== 'true') {
|
|
302
|
+
throw new x402_1.X402Error(`Missing or invalid ${x402_1.X402_HEADERS.REQUIRED} header`, x402_1.X402ErrorCode.MISSING_HEADERS, response);
|
|
303
|
+
}
|
|
304
|
+
const address = h.get(x402_1.X402_HEADERS.ADDRESS);
|
|
305
|
+
const amount = h.get(x402_1.X402_HEADERS.AMOUNT);
|
|
306
|
+
const network = h.get(x402_1.X402_HEADERS.NETWORK);
|
|
307
|
+
const token = h.get(x402_1.X402_HEADERS.TOKEN);
|
|
308
|
+
const deadline = h.get(x402_1.X402_HEADERS.DEADLINE);
|
|
309
|
+
if (!address) {
|
|
310
|
+
throw new x402_1.X402Error(`Missing ${x402_1.X402_HEADERS.ADDRESS}`, x402_1.X402ErrorCode.MISSING_HEADERS, response);
|
|
311
|
+
}
|
|
312
|
+
if (!amount) {
|
|
313
|
+
throw new x402_1.X402Error(`Missing ${x402_1.X402_HEADERS.AMOUNT}`, x402_1.X402ErrorCode.MISSING_HEADERS, response);
|
|
314
|
+
}
|
|
315
|
+
if (!network) {
|
|
316
|
+
throw new x402_1.X402Error(`Missing ${x402_1.X402_HEADERS.NETWORK}`, x402_1.X402ErrorCode.MISSING_HEADERS, response);
|
|
317
|
+
}
|
|
318
|
+
if (!token) {
|
|
319
|
+
throw new x402_1.X402Error(`Missing ${x402_1.X402_HEADERS.TOKEN}`, x402_1.X402ErrorCode.MISSING_HEADERS, response);
|
|
320
|
+
}
|
|
321
|
+
if (!deadline) {
|
|
322
|
+
throw new x402_1.X402Error(`Missing ${x402_1.X402_HEADERS.DEADLINE}`, x402_1.X402ErrorCode.MISSING_HEADERS, response);
|
|
323
|
+
}
|
|
324
|
+
// Validate address
|
|
325
|
+
const validatedAddress = this.validatePaymentAddress(address, response);
|
|
326
|
+
// Validate amount
|
|
327
|
+
if (!/^\d+$/.test(amount)) {
|
|
328
|
+
throw new x402_1.X402Error(`Invalid ${x402_1.X402_HEADERS.AMOUNT}: "${amount}"`, x402_1.X402ErrorCode.INVALID_AMOUNT, response);
|
|
329
|
+
}
|
|
330
|
+
// Validate network
|
|
331
|
+
if (!(0, x402_1.isValidX402Network)(network)) {
|
|
332
|
+
throw new x402_1.X402Error(`Invalid ${x402_1.X402_HEADERS.NETWORK}: "${network}"`, x402_1.X402ErrorCode.INVALID_NETWORK, response);
|
|
333
|
+
}
|
|
334
|
+
// Validate token
|
|
335
|
+
if (token.toUpperCase() !== 'USDC') {
|
|
336
|
+
throw new x402_1.X402Error(`Unsupported token: "${token}". Only USDC supported.`, x402_1.X402ErrorCode.MISSING_HEADERS, response);
|
|
337
|
+
}
|
|
338
|
+
const deadlineNum = parseInt(deadline, 10);
|
|
339
|
+
if (isNaN(deadlineNum) || deadlineNum <= 0) {
|
|
340
|
+
throw new x402_1.X402Error(`Invalid ${x402_1.X402_HEADERS.DEADLINE}: "${deadline}"`, x402_1.X402ErrorCode.MISSING_HEADERS, response);
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
required: true,
|
|
344
|
+
paymentAddress: validatedAddress,
|
|
345
|
+
amount,
|
|
346
|
+
network,
|
|
347
|
+
token: 'USDC',
|
|
348
|
+
deadline: deadlineNum,
|
|
349
|
+
serviceId: h.get(x402_1.X402_HEADERS.SERVICE_ID) ?? undefined,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Validate payment address from header.
|
|
354
|
+
*/
|
|
355
|
+
validatePaymentAddress(address, response) {
|
|
356
|
+
try {
|
|
357
|
+
return this.validateAddress(address, x402_1.X402_HEADERS.ADDRESS);
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
throw new x402_1.X402Error(`Invalid ${x402_1.X402_HEADERS.ADDRESS}: "${address}"`, x402_1.X402ErrorCode.INVALID_ADDRESS, response);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Execute atomic payment - direct transfer to provider.
|
|
365
|
+
*
|
|
366
|
+
* This is the key difference from ACTP:
|
|
367
|
+
* - No escrow
|
|
368
|
+
* - No state machine
|
|
369
|
+
* - Just transfer and done
|
|
370
|
+
*/
|
|
371
|
+
async executeAtomicPayment(headers) {
|
|
372
|
+
try {
|
|
373
|
+
const txHash = await this.transferFn(headers.paymentAddress, headers.amount);
|
|
374
|
+
return txHash;
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
throw new x402_1.X402Error(`Atomic payment failed: ${error instanceof Error ? error.message : 'Unknown error'}`, x402_1.X402ErrorCode.PAYMENT_FAILED);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Retry request with payment proof (tx hash).
|
|
382
|
+
* Uses the same HTTP method, headers, and body as the original request.
|
|
383
|
+
*
|
|
384
|
+
* @param endpoint - Request URL
|
|
385
|
+
* @param txHash - Payment transaction hash as proof
|
|
386
|
+
* @param method - Original HTTP method
|
|
387
|
+
* @param customHeaders - Original custom headers
|
|
388
|
+
* @param body - Original request body
|
|
389
|
+
* @param contentType - Original content-type
|
|
390
|
+
*/
|
|
391
|
+
async retryWithProof(endpoint, txHash, method = 'GET', customHeaders = {}, body, contentType) {
|
|
392
|
+
// Add payment proof headers
|
|
393
|
+
const proofHeaders = {
|
|
394
|
+
[x402_1.X402_PROOF_HEADERS.TX_ID]: txHash,
|
|
395
|
+
// No escrow ID for atomic payments
|
|
396
|
+
};
|
|
397
|
+
const response = await this.makeRequest(endpoint, method, customHeaders, body, contentType, proofHeaders);
|
|
398
|
+
if (!response.ok) {
|
|
399
|
+
throw new x402_1.X402Error(`Retry failed: ${response.status} ${response.statusText}`, x402_1.X402ErrorCode.RETRY_FAILED, response);
|
|
400
|
+
}
|
|
401
|
+
return response;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Create result for free services (200 on initial request).
|
|
405
|
+
*/
|
|
406
|
+
createFreeServiceResult(params, response) {
|
|
407
|
+
return {
|
|
408
|
+
txId: '0x' + '0'.repeat(64),
|
|
409
|
+
escrowId: null,
|
|
410
|
+
adapter: this.metadata.id,
|
|
411
|
+
state: 'COMMITTED',
|
|
412
|
+
success: true,
|
|
413
|
+
amount: '0.00 USDC',
|
|
414
|
+
response,
|
|
415
|
+
releaseRequired: false,
|
|
416
|
+
provider: '0x' + '0'.repeat(40),
|
|
417
|
+
requester: this.requesterAddress.toLowerCase(),
|
|
418
|
+
deadline: new Date(Date.now() + 86400000).toISOString(),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
exports.X402Adapter = X402Adapter;
|
|
423
|
+
//# sourceM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ACJ,WAAW,EACX,YAAY,CACb,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,gBAAS,CACjB,iBAAiB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,EACzD,oBAAa,CAAC,YAAY,EAC1B,QAAQ,CACT,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;OAEG;IACK,uBAAuB,CAC7B,MAAwB,EACxB,QAAkB;QAElB,OAAO;YACL,IAAI,EAAE,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE;YACzB,KAAK,EAAE,WAAW;YAClB,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,WAAW;YACnB,QAAQ;YACR,eAAe,EAAE,KAAK;YACtB,QAAQ,EAAE,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAC/B,SAAS,EAAE,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE;YAC9C,QAAQ,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,CAAC,WAAW,EAAE;SACxD,CAAC;IACJ,CAAC;CACF;AA/fD,kCA+fC"}
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -5,11 +5,19 @@
|
|
|
5
5
|
* - BaseAdapter: Abstract base with shared utilities
|
|
6
6
|
* - BasicAdapter: High-level, opinionated API
|
|
7
7
|
* - StandardAdapter: Balanced control API
|
|
8
|
+
* - AdapterRegistry: Central registry for adapter management
|
|
9
|
+
* - AdapterRouter: Intelligent adapter selection with guard-rails
|
|
10
|
+
* - IAdapter: Common interface for all adapters
|
|
8
11
|
*
|
|
9
12
|
* @module adapters
|
|
10
13
|
*/
|
|
11
14
|
export { BaseAdapter, ValidationError, DEFAULT_DISPUTE_WINDOW_SECONDS, DEFAULT_DEADLINE_SECONDS, MIN_AMOUNT_WEI, MAX_DEADLINE_HOURS, MAX_DEADLINE_DAYS, } from './BaseAdapter';
|
|
12
15
|
export { BasicAdapter, BasicPayParams, BasicPayResult } from './BasicAdapter';
|
|
13
16
|
export { StandardAdapter, StandardTransactionParams } from './StandardAdapter';
|
|
17
|
+
export { X402Adapter, X402AdapterConfig, FetchFunction } from './X402Adapter';
|
|
18
|
+
export { AdapterRegistry } from './AdapterRegistry';
|
|
19
|
+
export { AdapterRouter, AdapterSelectionResult } from './AdapterRouter';
|
|
20
|
+
export { IAdapter, TransactionStatus, AdapterTransactionState, isAdapter, } from './IAdapter';
|
|
14
21
|
export { IACTPRuntime, CreateTransactionParams } from '../runtime/IACTPRuntime';
|
|
22
|
+
export { AdapterMetadata, PaymentMetadata, PaymentIdentity, UnifiedPayParams, UnifiedPayResult, InitialTransactionState, AdapterMetadataSchema, PaymentMetadataSchema, UnifiedPayParamsSchema, validatePayParams, safeValidatePayParams, } from '../types/adapter';
|
|
15
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,WAAW,EACX,eAAe,EACf,8BAA8B,EAC9B,wBAAwB,EACxB,cAAc,EACd,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,uBAAuB,EACvB,SAAS,GACV,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAGhF,OAAO,EACL,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,kBAAkB,CAAC"}
|
package/dist/adapters/index.js
CHANGED
|
@@ -6,11 +6,14 @@
|
|
|
6
6
|
* - BaseAdapter: Abstract base with shared utilities
|
|
7
7
|
* - BasicAdapter: High-level, opinionated API
|
|
8
8
|
* - StandardAdapter: Balanced control API
|
|
9
|
+
* - AdapterRegistry: Central registry for adapter management
|
|
10
|
+
* - AdapterRouter: Intelligent adapter selection with guard-rails
|
|
11
|
+
* - IAdapter: Common interface for all adapters
|
|
9
12
|
*
|
|
10
13
|
* @module adapters
|
|
11
14
|
*/
|
|
12
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.StandardAdapter = exports.BasicAdapter = exports.MAX_DEADLINE_DAYS = exports.MAX_DEADLINE_HOURS = exports.MIN_AMOUNT_WEI = exports.DEFAULT_DEADLINE_SECONDS = exports.DEFAULT_DISPUTE_WINDOW_SECONDS = exports.ValidationError = exports.BaseAdapter = void 0;
|
|
16
|
+
exports.safeValidatePayParams = exports.validatePayParams = exports.UnifiedPayParamsSchema = exports.PaymentMetadataSchema = exports.AdapterMetadataSchema = exports.isAdapter = exports.AdapterRouter = exports.AdapterRegistry = exports.X402Adapter = exports.StandardAdapter = exports.BasicAdapter = exports.MAX_DEADLINE_DAYS = exports.MAX_DEADLINE_HOURS = exports.MIN_AMOUNT_WEI = exports.DEFAULT_DEADLINE_SECONDS = exports.DEFAULT_DISPUTE_WINDOW_SECONDS = exports.ValidationError = exports.BaseAdapter = void 0;
|
|
14
17
|
var BaseAdapter_1 = require("./BaseAdapter");
|
|
15
18
|
Object.defineProperty(exports, "BaseAdapter", { enumerable: true, get: function () { return BaseAdapter_1.BaseAdapter; } });
|
|
16
19
|
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return BaseAdapter_1.ValidationError; } });
|
|
@@ -23,4 +26,19 @@ var BasicAdapter_1 = require("./BasicAdapter");
|
|
|
23
26
|
Object.defineProperty(exports, "BasicAdapter", { enumerable: true, get: function () { return BasicAdapter_1.BasicAdapter; } });
|
|
24
27
|
var StandardAdapter_1 = require("./StandardAdapter");
|
|
25
28
|
Object.defineProperty(exports, "StandardAdapter", { enumerable: true, get: function () { return StandardAdapter_1.StandardAdapter; } });
|
|
29
|
+
var X402Adapter_1 = require("./X402Adapter");
|
|
30
|
+
Object.defineProperty(exports, "X402Adapter", { enumerable: true, get: function () { return X402Adapter_1.X402Adapter; } });
|
|
31
|
+
var AdapterRegistry_1 = require("./AdapterRegistry");
|
|
32
|
+
Object.defineProperty(exports, "AdapterRegistry", { enumerable: true, get: function () { return AdapterRegistry_1.AdapterRegistry; } });
|
|
33
|
+
var AdapterRouter_1 = require("./AdapterRouter");
|
|
34
|
+
Object.defineProperty(exports, "AdapterRouter", { enumerable: true, get: function () { return AdapterRouter_1.AdapterRouter; } });
|
|
35
|
+
var IAdapter_1 = require("./IAdapter");
|
|
36
|
+
Object.defineProperty(exports, "isAdapter", { enumerable: true, get: function () { return IAdapter_1.isAdapter; } });
|
|
37
|
+
// Re-export adapter types for convenience
|
|
38
|
+
var adapter_1 = require("../types/adapter");
|
|
39
|
+
Object.defineProperty(exports, "AdapterMetadataSchema", { enumerable: true, get: function () { return adapter_1.AdapterMetadataSchema; } });
|
|
40
|
+
Object.defineProperty(exports, "PaymentMetadataSchema", { enumerable: true, get: function () { return adapter_1.PaymentMetadataSchema; } });
|
|
41
|
+
Object.defineProperty(exports, "UnifiedPayParamsSchema", { enumerable: true, get: function () { return adapter_1.UnifiedPayParamsSchema; } });
|
|
42
|
+
Object.defineProperty(exports, "validatePayParams", { enumerable: true, get: function () { return adapter_1.validatePayParams; } });
|
|
43
|
+
Object.defineProperty(exports, "safeValidatePayParams", { enumerable: true, get: function () { return adapter_1.safeValidatePayParams; } });
|
|
26
44
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,6CAQuB;AAPrB,0GAAA,WAAW,OAAA;AACX,8GAAA,eAAe,OAAA;AACf,6HAAA,8BAA8B,OAAA;AAC9B,uHAAA,wBAAwB,OAAA;AACxB,6GAAA,cAAc,OAAA;AACd,iHAAA,kBAAkB,OAAA;AAClB,gHAAA,iBAAiB,OAAA;AAEnB,+CAA8E;AAArE,4GAAA,YAAY,OAAA;AACrB,qDAA+E;AAAtE,kHAAA,eAAe,OAAA;AACxB,6CAA8E;AAArE,0GAAA,WAAW,OAAA;AACpB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,iDAAwE;AAA/D,8GAAA,aAAa,OAAA;AACtB,uCAKoB;AADlB,qGAAA,SAAS,OAAA;AAMX,0CAA0C;AAC1C,4CAY0B;AALxB,gHAAA,qBAAqB,OAAA;AACrB,gHAAA,qBAAqB,OAAA;AACrB,iHAAA,sBAAsB,OAAA;AACtB,4GAAA,iBAAiB,OAAA;AACjB,gHAAA,qBAAqB,OAAA"}
|
|
@@ -13,6 +13,10 @@ interface InitOptions {
|
|
|
13
13
|
mode: string;
|
|
14
14
|
address?: string;
|
|
15
15
|
force?: boolean;
|
|
16
|
+
scaffold?: boolean;
|
|
17
|
+
intent?: string;
|
|
18
|
+
service?: string;
|
|
19
|
+
price?: string;
|
|
16
20
|
}
|
|
17
21
|
declare function runInit(options: InitOptions, output: Output): Promise<void>;
|
|
18
22
|
export { runInit };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,OAAO,EAAE,MAAM,EAAY,MAAM,iBAAiB,CAAC;AAOnD,wBAAgB,iBAAiB,IAAI,OAAO,CA6B3C;AAQD,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,iBAAe,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsG1E;AA4LD,OAAO,EAAE,OAAO,EAAE,CAAC"}
|