pay-lobster 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +401 -0
- package/README.md.bak +401 -0
- package/dist/agent.d.ts +132 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +224 -0
- package/dist/agent.js.map +1 -0
- package/dist/analytics.d.ts +120 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/analytics.js +345 -0
- package/dist/analytics.js.map +1 -0
- package/dist/approvals.d.ts +168 -0
- package/dist/approvals.d.ts.map +1 -0
- package/dist/approvals.js +406 -0
- package/dist/approvals.js.map +1 -0
- package/dist/circle-client.d.ts +152 -0
- package/dist/circle-client.d.ts.map +1 -0
- package/dist/circle-client.js +266 -0
- package/dist/circle-client.js.map +1 -0
- package/dist/commission.d.ts +191 -0
- package/dist/commission.d.ts.map +1 -0
- package/dist/commission.js +475 -0
- package/dist/commission.js.map +1 -0
- package/dist/condition-builder.d.ts +98 -0
- package/dist/condition-builder.d.ts.map +1 -0
- package/dist/condition-builder.js +193 -0
- package/dist/condition-builder.js.map +1 -0
- package/dist/contacts.d.ts +179 -0
- package/dist/contacts.d.ts.map +1 -0
- package/dist/contacts.js +445 -0
- package/dist/contacts.js.map +1 -0
- package/dist/easy.d.ts +22 -0
- package/dist/easy.d.ts.map +1 -0
- package/dist/easy.js +40 -0
- package/dist/easy.js.map +1 -0
- package/dist/erc8004/constants.d.ts +152 -0
- package/dist/erc8004/constants.d.ts.map +1 -0
- package/dist/erc8004/constants.js +114 -0
- package/dist/erc8004/constants.js.map +1 -0
- package/dist/erc8004/discovery.d.ts +84 -0
- package/dist/erc8004/discovery.d.ts.map +1 -0
- package/dist/erc8004/discovery.js +217 -0
- package/dist/erc8004/discovery.js.map +1 -0
- package/dist/erc8004/identity.d.ts +91 -0
- package/dist/erc8004/identity.d.ts.map +1 -0
- package/dist/erc8004/identity.js +250 -0
- package/dist/erc8004/identity.js.map +1 -0
- package/dist/erc8004/index.d.ts +147 -0
- package/dist/erc8004/index.d.ts.map +1 -0
- package/dist/erc8004/index.js +225 -0
- package/dist/erc8004/index.js.map +1 -0
- package/dist/erc8004/reputation.d.ts +133 -0
- package/dist/erc8004/reputation.d.ts.map +1 -0
- package/dist/erc8004/reputation.js +277 -0
- package/dist/erc8004/reputation.js.map +1 -0
- package/dist/escrow-templates.d.ts +38 -0
- package/dist/escrow-templates.d.ts.map +1 -0
- package/dist/escrow-templates.js +419 -0
- package/dist/escrow-templates.js.map +1 -0
- package/dist/escrow.d.ts +320 -0
- package/dist/escrow.d.ts.map +1 -0
- package/dist/escrow.js +854 -0
- package/dist/escrow.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/invoices.d.ts +212 -0
- package/dist/invoices.d.ts.map +1 -0
- package/dist/invoices.js +393 -0
- package/dist/invoices.js.map +1 -0
- package/dist/notifications.d.ts +141 -0
- package/dist/notifications.d.ts.map +1 -0
- package/dist/notifications.js +350 -0
- package/dist/notifications.js.map +1 -0
- package/dist/tips.d.ts +171 -0
- package/dist/tips.d.ts.map +1 -0
- package/dist/tips.js +390 -0
- package/dist/tips.js.map +1 -0
- package/dist/types.d.ts +100 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/x402-client.d.ts +127 -0
- package/dist/x402-client.d.ts.map +1 -0
- package/dist/x402-client.js +350 -0
- package/dist/x402-client.js.map +1 -0
- package/dist/x402-server.d.ts +133 -0
- package/dist/x402-server.d.ts.map +1 -0
- package/dist/x402-server.js +330 -0
- package/dist/x402-server.js.map +1 -0
- package/lib/agent.ts +273 -0
- package/lib/analytics.ts +474 -0
- package/lib/analytics.ts.bak +474 -0
- package/lib/approvals.ts +585 -0
- package/lib/approvals.ts.bak +585 -0
- package/lib/circle-client.ts +376 -0
- package/lib/circle-client.ts.bak +376 -0
- package/lib/commission.ts +680 -0
- package/lib/commission.ts.bak +680 -0
- package/lib/condition-builder.ts +223 -0
- package/lib/condition-builder.ts.bak +223 -0
- package/lib/contacts.ts +615 -0
- package/lib/contacts.ts.bak +615 -0
- package/lib/easy.ts +46 -0
- package/lib/easy.ts.bak +352 -0
- package/lib/erc8004/constants.ts +175 -0
- package/lib/erc8004/discovery.ts +299 -0
- package/lib/erc8004/identity.ts +327 -0
- package/lib/erc8004/index.ts +285 -0
- package/lib/erc8004/reputation.ts +368 -0
- package/lib/escrow-templates.ts +462 -0
- package/lib/escrow.ts +1216 -0
- package/lib/index.ts +13 -0
- package/lib/invoices.ts +588 -0
- package/lib/notifications.ts +484 -0
- package/lib/tips.ts +570 -0
- package/lib/types.ts +108 -0
- package/lib/x402-client.ts +471 -0
- package/lib/x402-server.ts +462 -0
- package/package.json +58 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* x402 Payment-Enabled HTTP Client
|
|
4
|
+
*
|
|
5
|
+
* Wraps fetch() to automatically handle 402 Payment Required responses.
|
|
6
|
+
* Uses Circle Programmable Wallets to pay and retry with signature.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.X402Client = void 0;
|
|
13
|
+
exports.createX402Fetch = createX402Fetch;
|
|
14
|
+
exports.simpleX402Fetch = simpleX402Fetch;
|
|
15
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
16
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
/**
|
|
19
|
+
* Create a payment-enabled fetch wrapper
|
|
20
|
+
*/
|
|
21
|
+
function createX402Fetch(config) {
|
|
22
|
+
const client = new X402Client(config);
|
|
23
|
+
return async (url, init) => {
|
|
24
|
+
return client.fetch(url, init);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* X402 HTTP Client
|
|
29
|
+
*/
|
|
30
|
+
class X402Client {
|
|
31
|
+
constructor(config) {
|
|
32
|
+
// In-memory receipt cache
|
|
33
|
+
this.receiptCache = new Map();
|
|
34
|
+
this.wallet = config.wallet;
|
|
35
|
+
this.walletId = config.walletId;
|
|
36
|
+
this.maxAutoPayUSDC = config.maxAutoPayUSDC ? parseFloat(config.maxAutoPayUSDC) : undefined;
|
|
37
|
+
this.requireConfirmation = config.requireConfirmation ?? false;
|
|
38
|
+
this.cacheReceipts = config.cacheReceipts ?? true;
|
|
39
|
+
this.cacheDir = config.cacheDir || './data/x402-receipts';
|
|
40
|
+
this.onPayment = config.onPayment;
|
|
41
|
+
this.onChallenge = config.onChallenge;
|
|
42
|
+
this.onVerified = config.onVerified;
|
|
43
|
+
this.onError = config.onError;
|
|
44
|
+
// Load cached receipts on init
|
|
45
|
+
if (this.cacheReceipts) {
|
|
46
|
+
this.loadReceiptCache().catch(() => {
|
|
47
|
+
// Ignore cache load errors
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Main fetch method - handles 402 automatically
|
|
53
|
+
*/
|
|
54
|
+
async fetch(url, init) {
|
|
55
|
+
const urlString = this.getUrlString(url);
|
|
56
|
+
try {
|
|
57
|
+
// Check for cached receipt
|
|
58
|
+
const cachedReceipt = this.getCachedReceipt(urlString);
|
|
59
|
+
if (cachedReceipt) {
|
|
60
|
+
// Use cached payment signature
|
|
61
|
+
return this.fetchWithPayment(url, init, cachedReceipt.signature);
|
|
62
|
+
}
|
|
63
|
+
// First attempt - no payment
|
|
64
|
+
const response = await fetch(url, init);
|
|
65
|
+
// Success or non-402 error - return as-is
|
|
66
|
+
if (response.status !== 402) {
|
|
67
|
+
return response;
|
|
68
|
+
}
|
|
69
|
+
// 402 Payment Required - handle payment
|
|
70
|
+
const paymentResponse = await this.handlePaymentRequired(response, urlString, url, init);
|
|
71
|
+
return paymentResponse;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
const err = error;
|
|
75
|
+
this.onError?.(err, urlString);
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Handle 402 Payment Required response
|
|
81
|
+
*/
|
|
82
|
+
async handlePaymentRequired(response, urlString, originalUrl, originalInit) {
|
|
83
|
+
// Parse payment challenge from response
|
|
84
|
+
const challenge = await this.parsePaymentChallenge(response);
|
|
85
|
+
if (!challenge) {
|
|
86
|
+
throw new Error('Invalid 402 response: missing x-payment-required');
|
|
87
|
+
}
|
|
88
|
+
// Trigger challenge hook
|
|
89
|
+
this.onChallenge?.(challenge);
|
|
90
|
+
// Check if challenge is expired
|
|
91
|
+
if (challenge['x-payment-required'].expires < Math.floor(Date.now() / 1000)) {
|
|
92
|
+
throw new Error('Payment challenge expired');
|
|
93
|
+
}
|
|
94
|
+
// Check max auto-pay limit
|
|
95
|
+
const amount = parseFloat(challenge['x-payment-required'].amount);
|
|
96
|
+
if (this.maxAutoPayUSDC !== undefined && amount > this.maxAutoPayUSDC) {
|
|
97
|
+
throw new Error(`Payment amount ${amount} USDC exceeds max auto-pay limit ${this.maxAutoPayUSDC} USDC`);
|
|
98
|
+
}
|
|
99
|
+
// Confirm payment if required
|
|
100
|
+
if (this.requireConfirmation) {
|
|
101
|
+
const confirmed = await this.confirmPayment(challenge);
|
|
102
|
+
if (!confirmed) {
|
|
103
|
+
throw new Error('Payment cancelled by user');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Execute payment
|
|
107
|
+
const txHash = await this.executePayment(challenge);
|
|
108
|
+
// Trigger payment hook
|
|
109
|
+
this.onPayment?.(challenge['x-payment-required'].amount, urlString, txHash);
|
|
110
|
+
// Generate payment signature
|
|
111
|
+
const signature = this.generatePaymentSignature(challenge, txHash);
|
|
112
|
+
// Cache receipt
|
|
113
|
+
const receipt = {
|
|
114
|
+
url: urlString,
|
|
115
|
+
challenge: challenge['x-payment-required'],
|
|
116
|
+
txHash,
|
|
117
|
+
signature,
|
|
118
|
+
paidAt: new Date().toISOString(),
|
|
119
|
+
expiresAt: challenge['x-payment-required'].expires,
|
|
120
|
+
};
|
|
121
|
+
await this.cacheReceipt(receipt);
|
|
122
|
+
this.onVerified?.(receipt);
|
|
123
|
+
// Retry request with payment signature
|
|
124
|
+
return this.fetchWithPayment(originalUrl, originalInit, signature);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Execute USDC payment via Circle
|
|
128
|
+
*/
|
|
129
|
+
async executePayment(challenge) {
|
|
130
|
+
const { amount, receiver, network } = challenge['x-payment-required'];
|
|
131
|
+
// Determine wallet to use
|
|
132
|
+
let walletId = this.walletId;
|
|
133
|
+
if (!walletId) {
|
|
134
|
+
// Auto-select wallet for the network
|
|
135
|
+
const wallets = await this.wallet.listWallets();
|
|
136
|
+
const wallet = wallets.find(w => w.blockchain === network);
|
|
137
|
+
if (!wallet) {
|
|
138
|
+
throw new Error(`No wallet found for network ${network}`);
|
|
139
|
+
}
|
|
140
|
+
walletId = wallet.id;
|
|
141
|
+
}
|
|
142
|
+
// Send USDC
|
|
143
|
+
const tx = await this.wallet.sendUSDC({
|
|
144
|
+
fromWalletId: walletId,
|
|
145
|
+
toAddress: receiver,
|
|
146
|
+
amount,
|
|
147
|
+
});
|
|
148
|
+
// Wait for transaction to be confirmed
|
|
149
|
+
// In production, you might want to poll for confirmation
|
|
150
|
+
// For now, return transaction ID
|
|
151
|
+
return tx.txHash || tx.id;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Fetch with payment signature header
|
|
155
|
+
*/
|
|
156
|
+
async fetchWithPayment(url, init, signature) {
|
|
157
|
+
const headers = new Headers(init?.headers);
|
|
158
|
+
headers.set('x-payment-signature', signature);
|
|
159
|
+
return fetch(url, {
|
|
160
|
+
...init,
|
|
161
|
+
headers,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Parse payment challenge from 402 response
|
|
166
|
+
*/
|
|
167
|
+
async parsePaymentChallenge(response) {
|
|
168
|
+
try {
|
|
169
|
+
const body = await response.json();
|
|
170
|
+
if (body['x-payment-required']) {
|
|
171
|
+
return body;
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Generate payment signature from challenge and tx hash
|
|
181
|
+
*/
|
|
182
|
+
generatePaymentSignature(challenge, txHash) {
|
|
183
|
+
// In production, this would involve the x402 facilitator
|
|
184
|
+
// For now, create a deterministic signature
|
|
185
|
+
const data = JSON.stringify({
|
|
186
|
+
nonce: challenge['x-payment-required'].nonce,
|
|
187
|
+
amount: challenge['x-payment-required'].amount,
|
|
188
|
+
receiver: challenge['x-payment-required'].receiver,
|
|
189
|
+
txHash,
|
|
190
|
+
});
|
|
191
|
+
// Simple hash-based signature (production would use proper signing)
|
|
192
|
+
return crypto_1.default.createHash('sha256').update(data).digest('hex');
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Confirm payment with user (if required)
|
|
196
|
+
*/
|
|
197
|
+
async confirmPayment(challenge) {
|
|
198
|
+
// In a real implementation, this would prompt the user
|
|
199
|
+
// For CLI/automated contexts, we can skip confirmation
|
|
200
|
+
// For UI contexts, show a dialog
|
|
201
|
+
const { amount, description } = challenge['x-payment-required'];
|
|
202
|
+
console.log(`\n💳 Payment Required`);
|
|
203
|
+
console.log(` Amount: ${amount} USDC`);
|
|
204
|
+
console.log(` Description: ${description}`);
|
|
205
|
+
console.log(` Confirm? (auto-approved)\n`);
|
|
206
|
+
// Auto-approve for now
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Get cached receipt for URL
|
|
211
|
+
*/
|
|
212
|
+
getCachedReceipt(url) {
|
|
213
|
+
if (!this.cacheReceipts)
|
|
214
|
+
return null;
|
|
215
|
+
const receipt = this.receiptCache.get(url);
|
|
216
|
+
// Check if receipt is still valid
|
|
217
|
+
if (receipt && receipt.expiresAt > Math.floor(Date.now() / 1000)) {
|
|
218
|
+
return receipt;
|
|
219
|
+
}
|
|
220
|
+
// Expired - remove from cache
|
|
221
|
+
if (receipt) {
|
|
222
|
+
this.receiptCache.delete(url);
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Cache payment receipt
|
|
228
|
+
*/
|
|
229
|
+
async cacheReceipt(receipt) {
|
|
230
|
+
if (!this.cacheReceipts)
|
|
231
|
+
return;
|
|
232
|
+
// Add to in-memory cache
|
|
233
|
+
this.receiptCache.set(receipt.url, receipt);
|
|
234
|
+
// Persist to disk
|
|
235
|
+
try {
|
|
236
|
+
await promises_1.default.mkdir(this.cacheDir, { recursive: true });
|
|
237
|
+
const filename = crypto_1.default.createHash('md5').update(receipt.url).digest('hex') + '.json';
|
|
238
|
+
const filepath = path_1.default.join(this.cacheDir, filename);
|
|
239
|
+
await promises_1.default.writeFile(filepath, JSON.stringify(receipt, null, 2));
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
// Ignore cache write errors
|
|
243
|
+
console.error('Failed to cache receipt:', error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Load cached receipts from disk
|
|
248
|
+
*/
|
|
249
|
+
async loadReceiptCache() {
|
|
250
|
+
try {
|
|
251
|
+
await promises_1.default.mkdir(this.cacheDir, { recursive: true });
|
|
252
|
+
const files = await promises_1.default.readdir(this.cacheDir);
|
|
253
|
+
for (const file of files) {
|
|
254
|
+
if (!file.endsWith('.json'))
|
|
255
|
+
continue;
|
|
256
|
+
try {
|
|
257
|
+
const filepath = path_1.default.join(this.cacheDir, file);
|
|
258
|
+
const data = await promises_1.default.readFile(filepath, 'utf-8');
|
|
259
|
+
const receipt = JSON.parse(data);
|
|
260
|
+
// Only cache if not expired
|
|
261
|
+
if (receipt.expiresAt > Math.floor(Date.now() / 1000)) {
|
|
262
|
+
this.receiptCache.set(receipt.url, receipt);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
// Delete expired receipt
|
|
266
|
+
await promises_1.default.unlink(filepath);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
// Ignore individual file errors
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
// Ignore cache directory errors
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Get receipt history
|
|
280
|
+
*/
|
|
281
|
+
async getReceiptHistory() {
|
|
282
|
+
const receipts = [];
|
|
283
|
+
try {
|
|
284
|
+
const files = await promises_1.default.readdir(this.cacheDir);
|
|
285
|
+
for (const file of files) {
|
|
286
|
+
if (!file.endsWith('.json'))
|
|
287
|
+
continue;
|
|
288
|
+
try {
|
|
289
|
+
const filepath = path_1.default.join(this.cacheDir, file);
|
|
290
|
+
const data = await promises_1.default.readFile(filepath, 'utf-8');
|
|
291
|
+
const receipt = JSON.parse(data);
|
|
292
|
+
receipts.push(receipt);
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
// Ignore individual file errors
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
// Ignore directory errors
|
|
301
|
+
}
|
|
302
|
+
// Sort by payment date (newest first)
|
|
303
|
+
return receipts.sort((a, b) => new Date(b.paidAt).getTime() - new Date(a.paidAt).getTime());
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Clear receipt cache
|
|
307
|
+
*/
|
|
308
|
+
async clearCache() {
|
|
309
|
+
this.receiptCache.clear();
|
|
310
|
+
try {
|
|
311
|
+
const files = await promises_1.default.readdir(this.cacheDir);
|
|
312
|
+
for (const file of files) {
|
|
313
|
+
const filepath = path_1.default.join(this.cacheDir, file);
|
|
314
|
+
await promises_1.default.unlink(filepath);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch {
|
|
318
|
+
// Ignore errors
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Extract URL string from various input types
|
|
323
|
+
*/
|
|
324
|
+
getUrlString(url) {
|
|
325
|
+
if (typeof url === 'string') {
|
|
326
|
+
return url;
|
|
327
|
+
}
|
|
328
|
+
else if (url instanceof URL) {
|
|
329
|
+
return url.toString();
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
return url.url;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
exports.X402Client = X402Client;
|
|
337
|
+
/**
|
|
338
|
+
* Helper: Create simple x402 client with minimal config
|
|
339
|
+
*/
|
|
340
|
+
function simpleX402Fetch(wallet, maxAutoPayUSDC) {
|
|
341
|
+
return createX402Fetch({
|
|
342
|
+
wallet,
|
|
343
|
+
maxAutoPayUSDC,
|
|
344
|
+
onPayment: (amount, url) => {
|
|
345
|
+
console.log(`💸 Paid ${amount} USDC for ${url}`);
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
exports.default = { createX402Fetch, simpleX402Fetch, X402Client };
|
|
350
|
+
//# sourceMappingURL=x402-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402-client.js","sourceRoot":"","sources":["../lib/x402-client.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AA0DH,0CAMC;AAuYD,0CAQC;AA5cD,oDAA4B;AAC5B,2DAA6B;AAC7B,gDAAwB;AAkDxB;;GAEG;AACH,SAAgB,eAAe,CAAC,MAAwB;IACtD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAEtC,OAAO,KA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,CAAC,KAAK,EAAE,CAAC;QAE1B,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,kBAAE,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAE9C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBAChD,MAAM,kBAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,gBAAgB;QAClB,CAAC;IACH,CAAC;IAED;;OAEG;IACK,YAAY,CAAC,GAA2B;QAC9C,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,GAAG,CAAC;QACb,CAAC;aAAM,IAAI,GAAG,YAAY,GAAG,EAAE,CAAC;YAC9B,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,CAAC,GAAG,CAAC;QACjB,CAAC;IACH,CAAC;CACF;AA7XD,gCA6XC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,MAAoB,EAAE,cAAuB;IAC3E,OAAO,eAAe,CAAC;QACrB,MAAM;QACN,cAAc;QACd,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;YACzB,OAAO,CAAC,GAAG,CAAC,WAAW,MAAM,aAAa,GAAG,EAAE,CAAC,CAAC;QACnD,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,kBAAe,EAAE,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* x402 Payment Server Middleware
|
|
3
|
+
*
|
|
4
|
+
* Express middleware for HTTP 402 Payment Required.
|
|
5
|
+
* Generates payment challenges and verifies payments via Coinbase facilitator.
|
|
6
|
+
*/
|
|
7
|
+
import { Request, Response, NextFunction } from 'express';
|
|
8
|
+
export interface X402ServerConfig {
|
|
9
|
+
facilitatorUrl?: string;
|
|
10
|
+
network: string;
|
|
11
|
+
receiverAddress: string;
|
|
12
|
+
acceptedAssets?: string[];
|
|
13
|
+
challengeExpiry?: number;
|
|
14
|
+
verifyPayment?: (signature: string, amount: string) => Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
export interface PaymentChallenge {
|
|
17
|
+
'x-payment-required': {
|
|
18
|
+
version: '1';
|
|
19
|
+
network: string;
|
|
20
|
+
receiver: string;
|
|
21
|
+
asset: string;
|
|
22
|
+
amount: string;
|
|
23
|
+
description: string;
|
|
24
|
+
expires: number;
|
|
25
|
+
nonce: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Configure x402 server globally
|
|
30
|
+
*/
|
|
31
|
+
export declare function configureX402Server(config: X402ServerConfig): void;
|
|
32
|
+
/**
|
|
33
|
+
* Create payment challenge
|
|
34
|
+
*/
|
|
35
|
+
export declare function createPaymentChallenge(amount: string, description: string, config?: Partial<X402ServerConfig>): PaymentChallenge;
|
|
36
|
+
/**
|
|
37
|
+
* Paywall middleware - require payment to access endpoint
|
|
38
|
+
*/
|
|
39
|
+
export declare function paywall(price: string, description: string, config?: Partial<X402ServerConfig>): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Dynamic paywall - determine price at runtime
|
|
42
|
+
*/
|
|
43
|
+
export declare function dynamicPaywall(priceFn: (req: Request) => string | Promise<string>, descriptionFn: (req: Request) => string | Promise<string>, config?: Partial<X402ServerConfig>): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Mock verification for testing (accepts any signature)
|
|
46
|
+
*/
|
|
47
|
+
export declare function mockVerification(): (signature: string, amount: string) => Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Simple signature verification (hash-based)
|
|
50
|
+
* Use only for testing - NOT secure for production
|
|
51
|
+
*/
|
|
52
|
+
export declare function simpleVerification(secret: string): (signature: string, amount: string) => Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Pricing helper - combine multiple tiers
|
|
55
|
+
*/
|
|
56
|
+
export declare class PricingTier {
|
|
57
|
+
private tiers;
|
|
58
|
+
add(key: string, price: string): this;
|
|
59
|
+
get(key: string): string | undefined;
|
|
60
|
+
middleware(keyFn: (req: Request) => string, descriptionFn: (req: Request) => string, config?: Partial<X402ServerConfig>): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Usage-based pricing
|
|
64
|
+
*/
|
|
65
|
+
export interface UsageConfig {
|
|
66
|
+
basePrice: string;
|
|
67
|
+
perUnit: string;
|
|
68
|
+
unit: string;
|
|
69
|
+
calculate: (req: Request) => number | Promise<number>;
|
|
70
|
+
}
|
|
71
|
+
export declare function usagePaywall(usage: UsageConfig, config?: Partial<X402ServerConfig>): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Subscription paywall (check for valid subscription)
|
|
74
|
+
*/
|
|
75
|
+
export interface SubscriptionConfig {
|
|
76
|
+
getSubscription: (req: Request) => Promise<{
|
|
77
|
+
active: boolean;
|
|
78
|
+
expiresAt: string;
|
|
79
|
+
} | null>;
|
|
80
|
+
price: string;
|
|
81
|
+
period: 'monthly' | 'yearly';
|
|
82
|
+
renewalUrl?: string;
|
|
83
|
+
}
|
|
84
|
+
export declare function subscriptionPaywall(subscription: SubscriptionConfig, config?: Partial<X402ServerConfig>): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Rate-limited paywall (free tier + paid tier)
|
|
87
|
+
*/
|
|
88
|
+
export interface RateLimitConfig {
|
|
89
|
+
free: {
|
|
90
|
+
limit: number;
|
|
91
|
+
windowMs: number;
|
|
92
|
+
};
|
|
93
|
+
paid: {
|
|
94
|
+
price: string;
|
|
95
|
+
description: string;
|
|
96
|
+
};
|
|
97
|
+
getUserId: (req: Request) => string;
|
|
98
|
+
}
|
|
99
|
+
export declare function rateLimitedPaywall(rateLimitConfig: RateLimitConfig, config?: Partial<X402ServerConfig>): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Express router with common x402 endpoints
|
|
102
|
+
*/
|
|
103
|
+
export declare function createX402Router(): null;
|
|
104
|
+
export declare const PRICING: {
|
|
105
|
+
micro: string;
|
|
106
|
+
small: string;
|
|
107
|
+
medium: string;
|
|
108
|
+
large: string;
|
|
109
|
+
premium: string;
|
|
110
|
+
enterprise: string;
|
|
111
|
+
};
|
|
112
|
+
declare const _default: {
|
|
113
|
+
configureX402Server: typeof configureX402Server;
|
|
114
|
+
createPaymentChallenge: typeof createPaymentChallenge;
|
|
115
|
+
paywall: typeof paywall;
|
|
116
|
+
dynamicPaywall: typeof dynamicPaywall;
|
|
117
|
+
usagePaywall: typeof usagePaywall;
|
|
118
|
+
subscriptionPaywall: typeof subscriptionPaywall;
|
|
119
|
+
rateLimitedPaywall: typeof rateLimitedPaywall;
|
|
120
|
+
mockVerification: typeof mockVerification;
|
|
121
|
+
simpleVerification: typeof simpleVerification;
|
|
122
|
+
PricingTier: typeof PricingTier;
|
|
123
|
+
PRICING: {
|
|
124
|
+
micro: string;
|
|
125
|
+
small: string;
|
|
126
|
+
medium: string;
|
|
127
|
+
large: string;
|
|
128
|
+
premium: string;
|
|
129
|
+
enterprise: string;
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
export default _default;
|
|
133
|
+
//# sourceMappingURL=x402-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402-server.d.ts","sourceRoot":"","sources":["../lib/x402-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM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