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,330 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* x402 Payment Server Middleware
|
|
4
|
+
*
|
|
5
|
+
* Express middleware for HTTP 402 Payment Required.
|
|
6
|
+
* Generates payment challenges and verifies payments via Coinbase facilitator.
|
|
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.PRICING = exports.PricingTier = void 0;
|
|
13
|
+
exports.configureX402Server = configureX402Server;
|
|
14
|
+
exports.createPaymentChallenge = createPaymentChallenge;
|
|
15
|
+
exports.paywall = paywall;
|
|
16
|
+
exports.dynamicPaywall = dynamicPaywall;
|
|
17
|
+
exports.mockVerification = mockVerification;
|
|
18
|
+
exports.simpleVerification = simpleVerification;
|
|
19
|
+
exports.usagePaywall = usagePaywall;
|
|
20
|
+
exports.subscriptionPaywall = subscriptionPaywall;
|
|
21
|
+
exports.rateLimitedPaywall = rateLimitedPaywall;
|
|
22
|
+
exports.createX402Router = createX402Router;
|
|
23
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
24
|
+
// Global config (can be set once for all middleware)
|
|
25
|
+
let globalConfig = null;
|
|
26
|
+
/**
|
|
27
|
+
* Configure x402 server globally
|
|
28
|
+
*/
|
|
29
|
+
function configureX402Server(config) {
|
|
30
|
+
globalConfig = {
|
|
31
|
+
facilitatorUrl: config.facilitatorUrl || 'https://x402.coinbase.com',
|
|
32
|
+
acceptedAssets: config.acceptedAssets || ['USDC'],
|
|
33
|
+
challengeExpiry: config.challengeExpiry || 300,
|
|
34
|
+
...config,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get effective config (merge global + local)
|
|
39
|
+
*/
|
|
40
|
+
function getConfig(localConfig) {
|
|
41
|
+
if (!globalConfig && !localConfig) {
|
|
42
|
+
throw new Error('x402 server not configured. Call configureX402Server() first.');
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
facilitatorUrl: localConfig?.facilitatorUrl || globalConfig?.facilitatorUrl || 'https://x402.coinbase.com',
|
|
46
|
+
network: localConfig?.network || globalConfig?.network || 'ETH-SEPOLIA',
|
|
47
|
+
receiverAddress: localConfig?.receiverAddress || globalConfig?.receiverAddress || '',
|
|
48
|
+
acceptedAssets: localConfig?.acceptedAssets || globalConfig?.acceptedAssets || ['USDC'],
|
|
49
|
+
challengeExpiry: localConfig?.challengeExpiry || globalConfig?.challengeExpiry || 300,
|
|
50
|
+
verifyPayment: localConfig?.verifyPayment || globalConfig?.verifyPayment,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create payment challenge
|
|
55
|
+
*/
|
|
56
|
+
function createPaymentChallenge(amount, description, config) {
|
|
57
|
+
const effectiveConfig = getConfig(config);
|
|
58
|
+
return {
|
|
59
|
+
'x-payment-required': {
|
|
60
|
+
version: '1',
|
|
61
|
+
network: effectiveConfig.network,
|
|
62
|
+
receiver: effectiveConfig.receiverAddress,
|
|
63
|
+
asset: 'USDC',
|
|
64
|
+
amount,
|
|
65
|
+
description,
|
|
66
|
+
expires: Math.floor(Date.now() / 1000) + (effectiveConfig.challengeExpiry || 300),
|
|
67
|
+
nonce: crypto_1.default.randomUUID(),
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Paywall middleware - require payment to access endpoint
|
|
73
|
+
*/
|
|
74
|
+
function paywall(price, description, config) {
|
|
75
|
+
return async (req, res, next) => {
|
|
76
|
+
const paymentSignature = req.headers['x-payment-signature'];
|
|
77
|
+
if (!paymentSignature) {
|
|
78
|
+
// No payment provided - return 402 with challenge
|
|
79
|
+
const challenge = createPaymentChallenge(price, description, config);
|
|
80
|
+
res.status(402).json({
|
|
81
|
+
error: 'Payment Required',
|
|
82
|
+
message: `This endpoint requires ${price} USDC`,
|
|
83
|
+
...challenge,
|
|
84
|
+
});
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// Verify payment
|
|
88
|
+
try {
|
|
89
|
+
const effectiveConfig = getConfig(config);
|
|
90
|
+
const verified = await verifyPayment(paymentSignature, price, effectiveConfig);
|
|
91
|
+
if (verified) {
|
|
92
|
+
// Payment verified - proceed
|
|
93
|
+
req.paymentVerified = true;
|
|
94
|
+
req.paymentAmount = price;
|
|
95
|
+
req.paymentSignature = paymentSignature;
|
|
96
|
+
next();
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
res.status(402).json({
|
|
100
|
+
error: 'Payment Invalid',
|
|
101
|
+
message: 'Payment signature could not be verified',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error('Payment verification error:', error);
|
|
107
|
+
res.status(500).json({
|
|
108
|
+
error: 'Payment Verification Failed',
|
|
109
|
+
message: error.message,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Dynamic paywall - determine price at runtime
|
|
116
|
+
*/
|
|
117
|
+
function dynamicPaywall(priceFn, descriptionFn, config) {
|
|
118
|
+
return async (req, res, next) => {
|
|
119
|
+
try {
|
|
120
|
+
// Determine price and description
|
|
121
|
+
const price = await Promise.resolve(priceFn(req));
|
|
122
|
+
const description = await Promise.resolve(descriptionFn(req));
|
|
123
|
+
// Use standard paywall
|
|
124
|
+
const middleware = paywall(price, description, config);
|
|
125
|
+
await middleware(req, res, next);
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
res.status(500).json({
|
|
129
|
+
error: 'Paywall Configuration Error',
|
|
130
|
+
message: error.message,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Verify payment with Coinbase x402 facilitator
|
|
137
|
+
*/
|
|
138
|
+
async function verifyPayment(signature, expectedAmount, config) {
|
|
139
|
+
// Use custom verification if provided
|
|
140
|
+
if (config.verifyPayment) {
|
|
141
|
+
return config.verifyPayment(signature, expectedAmount);
|
|
142
|
+
}
|
|
143
|
+
// Default: verify with Coinbase facilitator
|
|
144
|
+
try {
|
|
145
|
+
const response = await fetch(`${config.facilitatorUrl}/verify`, {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
headers: {
|
|
148
|
+
'Content-Type': 'application/json',
|
|
149
|
+
},
|
|
150
|
+
body: JSON.stringify({
|
|
151
|
+
signature,
|
|
152
|
+
expectedAmount,
|
|
153
|
+
network: config.network,
|
|
154
|
+
receiver: config.receiverAddress,
|
|
155
|
+
}),
|
|
156
|
+
});
|
|
157
|
+
if (!response.ok) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
const result = await response.json();
|
|
161
|
+
return result.valid === true;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error('Facilitator verification error:', error);
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Mock verification for testing (accepts any signature)
|
|
170
|
+
*/
|
|
171
|
+
function mockVerification() {
|
|
172
|
+
return async (signature, amount) => {
|
|
173
|
+
// In testing, accept any non-empty signature
|
|
174
|
+
return signature.length > 0;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Simple signature verification (hash-based)
|
|
179
|
+
* Use only for testing - NOT secure for production
|
|
180
|
+
*/
|
|
181
|
+
function simpleVerification(secret) {
|
|
182
|
+
return async (signature, amount) => {
|
|
183
|
+
// Verify signature matches hash of secret + amount
|
|
184
|
+
const expectedSig = crypto_1.default.createHash('sha256')
|
|
185
|
+
.update(secret + amount)
|
|
186
|
+
.digest('hex');
|
|
187
|
+
return signature === expectedSig;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Pricing helper - combine multiple tiers
|
|
192
|
+
*/
|
|
193
|
+
class PricingTier {
|
|
194
|
+
constructor() {
|
|
195
|
+
this.tiers = new Map();
|
|
196
|
+
}
|
|
197
|
+
add(key, price) {
|
|
198
|
+
this.tiers.set(key, price);
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
get(key) {
|
|
202
|
+
return this.tiers.get(key);
|
|
203
|
+
}
|
|
204
|
+
middleware(keyFn, descriptionFn, config) {
|
|
205
|
+
return dynamicPaywall((req) => {
|
|
206
|
+
const key = keyFn(req);
|
|
207
|
+
const price = this.tiers.get(key);
|
|
208
|
+
if (!price) {
|
|
209
|
+
throw new Error(`No price configured for tier: ${key}`);
|
|
210
|
+
}
|
|
211
|
+
return price;
|
|
212
|
+
}, descriptionFn, config);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.PricingTier = PricingTier;
|
|
216
|
+
function usagePaywall(usage, config) {
|
|
217
|
+
return dynamicPaywall(async (req) => {
|
|
218
|
+
const units = await Promise.resolve(usage.calculate(req));
|
|
219
|
+
const base = parseFloat(usage.basePrice);
|
|
220
|
+
const perUnit = parseFloat(usage.perUnit);
|
|
221
|
+
const total = base + (units * perUnit);
|
|
222
|
+
return total.toFixed(2);
|
|
223
|
+
}, (req) => `Usage-based pricing: base + ${usage.perUnit} per ${usage.unit}`, config);
|
|
224
|
+
}
|
|
225
|
+
function subscriptionPaywall(subscription, config) {
|
|
226
|
+
return async (req, res, next) => {
|
|
227
|
+
// Check for active subscription
|
|
228
|
+
const sub = await subscription.getSubscription(req);
|
|
229
|
+
if (sub && sub.active && new Date(sub.expiresAt) > new Date()) {
|
|
230
|
+
// Active subscription - allow access
|
|
231
|
+
req.subscription = sub;
|
|
232
|
+
next();
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
// No active subscription - require payment
|
|
236
|
+
const description = `${subscription.period} subscription - ${subscription.price} USDC`;
|
|
237
|
+
const challenge = createPaymentChallenge(subscription.price, description, config);
|
|
238
|
+
res.status(402).json({
|
|
239
|
+
error: 'Subscription Required',
|
|
240
|
+
message: `This endpoint requires an active ${subscription.period} subscription`,
|
|
241
|
+
subscription: {
|
|
242
|
+
price: subscription.price,
|
|
243
|
+
period: subscription.period,
|
|
244
|
+
renewalUrl: subscription.renewalUrl,
|
|
245
|
+
},
|
|
246
|
+
...challenge,
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
// Simple in-memory rate limiter
|
|
251
|
+
const rateLimitStore = new Map();
|
|
252
|
+
function rateLimitedPaywall(rateLimitConfig, config) {
|
|
253
|
+
return async (req, res, next) => {
|
|
254
|
+
const userId = rateLimitConfig.getUserId(req);
|
|
255
|
+
const now = Date.now();
|
|
256
|
+
// Get or create usage record
|
|
257
|
+
let usage = rateLimitStore.get(userId);
|
|
258
|
+
if (!usage || usage.resetAt < now) {
|
|
259
|
+
// New window
|
|
260
|
+
usage = {
|
|
261
|
+
count: 0,
|
|
262
|
+
resetAt: now + rateLimitConfig.free.windowMs,
|
|
263
|
+
};
|
|
264
|
+
rateLimitStore.set(userId, usage);
|
|
265
|
+
}
|
|
266
|
+
// Check if within free tier
|
|
267
|
+
if (usage.count < rateLimitConfig.free.limit) {
|
|
268
|
+
usage.count++;
|
|
269
|
+
next();
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
// Exceeded free tier - require payment
|
|
273
|
+
const paymentSignature = req.headers['x-payment-signature'];
|
|
274
|
+
if (!paymentSignature) {
|
|
275
|
+
const challenge = createPaymentChallenge(rateLimitConfig.paid.price, rateLimitConfig.paid.description, config);
|
|
276
|
+
res.status(402).json({
|
|
277
|
+
error: 'Rate Limit Exceeded',
|
|
278
|
+
message: `Free tier limit reached (${rateLimitConfig.free.limit} requests per window)`,
|
|
279
|
+
rateTier: 'paid',
|
|
280
|
+
...challenge,
|
|
281
|
+
});
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
// Verify payment for additional request
|
|
285
|
+
const effectiveConfig = getConfig(config);
|
|
286
|
+
const verified = await verifyPayment(paymentSignature, rateLimitConfig.paid.price, effectiveConfig);
|
|
287
|
+
if (verified) {
|
|
288
|
+
req.paymentVerified = true;
|
|
289
|
+
req.paidRequest = true;
|
|
290
|
+
next();
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
res.status(402).json({
|
|
294
|
+
error: 'Payment Invalid',
|
|
295
|
+
message: 'Payment signature could not be verified',
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Express router with common x402 endpoints
|
|
302
|
+
*/
|
|
303
|
+
function createX402Router() {
|
|
304
|
+
// This would return an Express router with health/pricing endpoints
|
|
305
|
+
// Implemented in the specific application
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
// Export pricing helpers
|
|
309
|
+
exports.PRICING = {
|
|
310
|
+
micro: '0.01',
|
|
311
|
+
small: '0.05',
|
|
312
|
+
medium: '0.10',
|
|
313
|
+
large: '0.25',
|
|
314
|
+
premium: '0.50',
|
|
315
|
+
enterprise: '1.00',
|
|
316
|
+
};
|
|
317
|
+
exports.default = {
|
|
318
|
+
configureX402Server,
|
|
319
|
+
createPaymentChallenge,
|
|
320
|
+
paywall,
|
|
321
|
+
dynamicPaywall,
|
|
322
|
+
usagePaywall,
|
|
323
|
+
subscriptionPaywall,
|
|
324
|
+
rateLimitedPaywall,
|
|
325
|
+
mockVerification,
|
|
326
|
+
simpleVerification,
|
|
327
|
+
PricingTier,
|
|
328
|
+
PRICING: exports.PRICING,
|
|
329
|
+
};
|
|
330
|
+
//# sourceMappingURL=x402-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402-server.js","sourceRoot":"","sources":["../lib/x402-server.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAqCH,kDAOC;AAuBD,wDAmBC;AAKD,0BAiDC;AAKD,wCAqBC;AA6CD,4CAKC;AAMD,gDASC;AA+CD,oCAeC;AAeD,kDA8BC;AAoBD,gDAiEC;AAKD,4CAIC;AA7aD,oDAA4B;AA4B5B,qDAAqD;AACrD,IAAI,YAAY,GAA4B,IAAI,CAAC;AAEjD;;GAEG;AACH,SAAgB,mBAAmB,CAAC,MAAwB;IAC1D,YAAY,GAAG;QACb,cAAc,EAAE,MAAM,CAAC,cAAc,IAAI,2BAA2B;QACpE,cAAc,EAAE,MAAM,CAAC,cAAc,IAAI,CAAC,MAAM,CAAC;QACjD,eAAe,EAAE,MAAM,CAAC,eAAe,IAAI,GAAG;QAC9C,GAAG,MAAM;KACV,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,SAAS,CAAC,WAAuC;IACxD,IAAI,CAAC,YAAY,IAAI,CAAC,WAAW,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;IACnF,CAAC;IAED,OAAO;QACL,cAAc,EAAE,WAAW,EAAE,cAAc,IAAI,YAAY,EAAE,cAAc,IAAI,2BAA2B;QAC1G,OAAO,EAAE,WAAW,EAAE,OAAO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AA0C;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC;AAED,yBAAyB;AACZ,QAAA,OAAO,GAAG;IACrB,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,MAAM;IACd,KAAK,EAAE,MAAM;IACb,OAAO,EAAE,MAAM;IACf,UAAU,EAAE,MAAM;CACnB,CAAC;AAEF,kBAAe;IACb,mBAAmB;IACnB,sBAAsB;IACtB,OAAO;IACP,cAAc;IACd,YAAY;IACZ,mBAAmB;IACnB,kBAAkB;IAClB,gBAAgB;IAChB,kBAAkB;IAClB,WAAW;IACX,OAAO,EAAP,eAAO;CACR,CAAC"}
|
package/lib/agent.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LobsterAgent - Main class for Pay Lobster SDK
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
LobsterConfig,
|
|
7
|
+
Wallet,
|
|
8
|
+
Transfer,
|
|
9
|
+
Escrow,
|
|
10
|
+
TrustScore,
|
|
11
|
+
Agent,
|
|
12
|
+
TransferOptions,
|
|
13
|
+
EscrowOptions,
|
|
14
|
+
DiscoverOptions,
|
|
15
|
+
AutonomousConfig
|
|
16
|
+
} from './types';
|
|
17
|
+
|
|
18
|
+
const BASE_RPC = 'https://mainnet.base.org';
|
|
19
|
+
const USDC_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
|
|
20
|
+
|
|
21
|
+
export class LobsterAgent {
|
|
22
|
+
private config: LobsterConfig;
|
|
23
|
+
private wallet?: Wallet;
|
|
24
|
+
private autonomousConfig?: AutonomousConfig;
|
|
25
|
+
|
|
26
|
+
constructor(config: LobsterConfig = {}) {
|
|
27
|
+
this.config = {
|
|
28
|
+
network: 'base',
|
|
29
|
+
enableTrust: true,
|
|
30
|
+
...config
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Initialize the agent and connect to wallet
|
|
36
|
+
*/
|
|
37
|
+
async initialize(): Promise<void> {
|
|
38
|
+
if (this.config.walletId) {
|
|
39
|
+
this.wallet = await this.getWallet();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create a new Circle-managed wallet
|
|
45
|
+
*/
|
|
46
|
+
async createWallet(): Promise<Wallet> {
|
|
47
|
+
// Implementation would use Circle API
|
|
48
|
+
throw new Error('Circle wallet creation requires entity secret. Use external wallet or Circle Console.');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get wallet details and balance
|
|
53
|
+
*/
|
|
54
|
+
async getWallet(): Promise<Wallet> {
|
|
55
|
+
if (!this.wallet?.address && !this.config.walletId) {
|
|
56
|
+
throw new Error('No wallet configured');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const address = this.wallet?.address || this.config.walletId!;
|
|
60
|
+
const balance = await this.getBalance();
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
id: this.config.walletId || 'external',
|
|
64
|
+
address,
|
|
65
|
+
network: this.config.network || 'base',
|
|
66
|
+
balance
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get current USDC balance
|
|
72
|
+
*/
|
|
73
|
+
async getBalance(): Promise<string> {
|
|
74
|
+
const address = this.wallet?.address || this.config.walletId;
|
|
75
|
+
if (!address) throw new Error('No wallet address');
|
|
76
|
+
|
|
77
|
+
const rpc = this.config.rpcUrl || BASE_RPC;
|
|
78
|
+
const data = '0x70a08231' + address.slice(2).padStart(64, '0');
|
|
79
|
+
|
|
80
|
+
const response = await fetch(rpc, {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
headers: { 'Content-Type': 'application/json' },
|
|
83
|
+
body: JSON.stringify({
|
|
84
|
+
jsonrpc: '2.0',
|
|
85
|
+
id: 1,
|
|
86
|
+
method: 'eth_call',
|
|
87
|
+
params: [{ to: USDC_BASE, data }, 'latest']
|
|
88
|
+
})
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const result: any = await response.json();
|
|
92
|
+
const balance = parseInt(result.result || '0', 16) / 1e6;
|
|
93
|
+
return balance.toFixed(2);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Get deposit address
|
|
98
|
+
*/
|
|
99
|
+
async getDepositAddress(): Promise<string> {
|
|
100
|
+
return this.wallet?.address || this.config.walletId || '';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Transfer USDC to another address
|
|
105
|
+
*/
|
|
106
|
+
async transfer(options: TransferOptions): Promise<Transfer> {
|
|
107
|
+
// Implementation requires private key or Circle wallet
|
|
108
|
+
console.log(`Transfer: ${options.amount} USDC to ${options.to}`);
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
id: `tx_${Date.now()}`,
|
|
112
|
+
status: 'pending',
|
|
113
|
+
amount: options.amount,
|
|
114
|
+
to: options.to,
|
|
115
|
+
from: this.wallet?.address || '',
|
|
116
|
+
memo: options.memo,
|
|
117
|
+
createdAt: new Date().toISOString()
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Alias for transfer
|
|
123
|
+
*/
|
|
124
|
+
async send(to: string, amount: number | string): Promise<Transfer> {
|
|
125
|
+
return this.transfer({ to, amount: amount.toString() });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Create an escrow
|
|
130
|
+
*/
|
|
131
|
+
async createEscrow(options: EscrowOptions): Promise<Escrow> {
|
|
132
|
+
return {
|
|
133
|
+
id: `esc_${Date.now()}`,
|
|
134
|
+
amount: options.amount,
|
|
135
|
+
buyer: this.wallet?.address || '',
|
|
136
|
+
seller: options.recipient,
|
|
137
|
+
status: 'funded',
|
|
138
|
+
conditions: options.conditions,
|
|
139
|
+
createdAt: new Date().toISOString()
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Release escrow funds
|
|
145
|
+
*/
|
|
146
|
+
async releaseEscrow(escrowId: string, options?: { amount?: string }): Promise<void> {
|
|
147
|
+
console.log(`Releasing escrow ${escrowId}`, options);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Refund escrow
|
|
152
|
+
*/
|
|
153
|
+
async refundEscrow(escrowId: string): Promise<void> {
|
|
154
|
+
console.log(`Refunding escrow ${escrowId}`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Dispute escrow
|
|
159
|
+
*/
|
|
160
|
+
async disputeEscrow(escrowId: string, options: { reason: string }): Promise<void> {
|
|
161
|
+
console.log(`Disputing escrow ${escrowId}: ${options.reason}`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Get trust score for an address
|
|
166
|
+
*/
|
|
167
|
+
async getTrustScore(address: string): Promise<TrustScore> {
|
|
168
|
+
// Would query ERC-8004 registry
|
|
169
|
+
return {
|
|
170
|
+
score: 100,
|
|
171
|
+
level: 'new',
|
|
172
|
+
totalTransactions: 0,
|
|
173
|
+
successRate: 100
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Rate an agent
|
|
179
|
+
*/
|
|
180
|
+
async rateAgent(options: { agent: string; rating: number; comment?: string; transactionId?: string }): Promise<void> {
|
|
181
|
+
console.log(`Rating agent ${options.agent}: ${options.rating}/5`);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get agent ratings
|
|
186
|
+
*/
|
|
187
|
+
async getAgentRatings(address: string): Promise<any[]> {
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Register agent in on-chain registry
|
|
193
|
+
*/
|
|
194
|
+
async registerAgent(options: {
|
|
195
|
+
name: string;
|
|
196
|
+
capabilities: string[];
|
|
197
|
+
pricing?: Record<string, string>;
|
|
198
|
+
metadata?: Record<string, any>;
|
|
199
|
+
}): Promise<void> {
|
|
200
|
+
console.log(`Registering agent: ${options.name}`);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Discover agents by capability
|
|
205
|
+
*/
|
|
206
|
+
async discoverAgents(options: DiscoverOptions): Promise<Agent[]> {
|
|
207
|
+
// Would query on-chain registry
|
|
208
|
+
return [{
|
|
209
|
+
address: '0xf775f0224A680E2915a066e53A389d0335318b7B',
|
|
210
|
+
name: 'paylobster',
|
|
211
|
+
capabilities: ['payments', 'escrow'],
|
|
212
|
+
trustScore: { score: 100, level: 'verified', totalTransactions: 0, successRate: 100 }
|
|
213
|
+
}];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Get agent details
|
|
218
|
+
*/
|
|
219
|
+
async getAgent(address: string): Promise<Agent | null> {
|
|
220
|
+
const agents = await this.discoverAgents({});
|
|
221
|
+
return agents.find(a => a.address.toLowerCase() === address.toLowerCase()) || null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Configure autonomous mode
|
|
226
|
+
*/
|
|
227
|
+
setAutonomousMode(config: AutonomousConfig): void {
|
|
228
|
+
this.autonomousConfig = config;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Hire an agent autonomously
|
|
233
|
+
*/
|
|
234
|
+
async hireAgent(options: { agent: string; task: string; maxPrice: string }): Promise<any> {
|
|
235
|
+
console.log(`Hiring agent ${options.agent} for: ${options.task}`);
|
|
236
|
+
return { taskId: `task_${Date.now()}`, agent: options.agent, price: options.maxPrice };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Set webhook for notifications
|
|
241
|
+
*/
|
|
242
|
+
setWebhook(options: { url: string; secret: string; events: string[] }): void {
|
|
243
|
+
console.log(`Webhook configured: ${options.url}`);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Fetch with x402 auto-payment
|
|
248
|
+
*/
|
|
249
|
+
async fetch(url: string, options?: { x402?: boolean; maxPayment?: string }): Promise<Response> {
|
|
250
|
+
const response = await fetch(url);
|
|
251
|
+
|
|
252
|
+
if (response.status === 402 && options?.x402) {
|
|
253
|
+
// Would handle payment automatically
|
|
254
|
+
console.log('402 Payment Required - auto-paying...');
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return response;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Get transfer by ID
|
|
262
|
+
*/
|
|
263
|
+
async getTransfer(id: string): Promise<Transfer | null> {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* List transfer history
|
|
269
|
+
*/
|
|
270
|
+
async listTransfers(options?: { limit?: number; direction?: string; since?: string }): Promise<Transfer[]> {
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
}
|