@sly_ai/sdk 0.1.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 +346 -0
- package/dist/a2a.d.mts +108 -0
- package/dist/a2a.d.ts +108 -0
- package/dist/a2a.js +173 -0
- package/dist/a2a.js.map +1 -0
- package/dist/a2a.mjs +171 -0
- package/dist/a2a.mjs.map +1 -0
- package/dist/acp.d.mts +201 -0
- package/dist/acp.d.ts +201 -0
- package/dist/acp.js +143 -0
- package/dist/acp.js.map +1 -0
- package/dist/acp.mjs +141 -0
- package/dist/acp.mjs.map +1 -0
- package/dist/ap2.d.mts +188 -0
- package/dist/ap2.d.ts +188 -0
- package/dist/ap2.js +135 -0
- package/dist/ap2.js.map +1 -0
- package/dist/ap2.mjs +133 -0
- package/dist/ap2.mjs.map +1 -0
- package/dist/cards.d.mts +750 -0
- package/dist/cards.d.ts +750 -0
- package/dist/cards.js +373 -0
- package/dist/cards.js.map +1 -0
- package/dist/cards.mjs +369 -0
- package/dist/cards.mjs.map +1 -0
- package/dist/client-Cwe2CLU7.d.mts +41 -0
- package/dist/client-CyJe3uWO.d.ts +41 -0
- package/dist/index.d.mts +662 -0
- package/dist/index.d.ts +662 -0
- package/dist/index.js +2709 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2700 -0
- package/dist/index.mjs.map +1 -0
- package/dist/langchain.d.mts +11 -0
- package/dist/langchain.d.ts +11 -0
- package/dist/langchain.js +25 -0
- package/dist/langchain.js.map +1 -0
- package/dist/langchain.mjs +23 -0
- package/dist/langchain.mjs.map +1 -0
- package/dist/types-df1EICn_.d.mts +165 -0
- package/dist/types-df1EICn_.d.ts +165 -0
- package/dist/ucp.d.mts +844 -0
- package/dist/ucp.d.ts +844 -0
- package/dist/ucp.js +616 -0
- package/dist/ucp.js.map +1 -0
- package/dist/ucp.mjs +614 -0
- package/dist/ucp.mjs.map +1 -0
- package/dist/vercel.d.mts +178 -0
- package/dist/vercel.d.ts +178 -0
- package/dist/vercel.js +143 -0
- package/dist/vercel.js.map +1 -0
- package/dist/vercel.mjs +138 -0
- package/dist/vercel.mjs.map +1 -0
- package/dist/x402.d.mts +209 -0
- package/dist/x402.d.ts +209 -0
- package/dist/x402.js +476 -0
- package/dist/x402.js.map +1 -0
- package/dist/x402.mjs +471 -0
- package/dist/x402.mjs.map +1 -0
- package/package.json +118 -0
package/dist/x402.mjs
ADDED
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
var ENVIRONMENT_CONFIGS = {
|
|
3
|
+
sandbox: {
|
|
4
|
+
apiUrl: "https://sandbox.getsly.ai",
|
|
5
|
+
facilitatorUrl: "https://facilitator.x402.org"
|
|
6
|
+
// x402.org Base Sepolia
|
|
7
|
+
},
|
|
8
|
+
testnet: {
|
|
9
|
+
apiUrl: "https://sandbox.getsly.ai",
|
|
10
|
+
facilitatorUrl: "https://facilitator.x402.org"
|
|
11
|
+
// x402.org Base Sepolia
|
|
12
|
+
},
|
|
13
|
+
production: {
|
|
14
|
+
apiUrl: "https://api.getsly.ai",
|
|
15
|
+
facilitatorUrl: "https://facilitator.coinbase.com"
|
|
16
|
+
// Coinbase CDP Base mainnet
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
function getEnvironmentConfig(environment) {
|
|
20
|
+
return ENVIRONMENT_CONFIGS[environment];
|
|
21
|
+
}
|
|
22
|
+
function validateEnvironment(environment, evmPrivateKey) {
|
|
23
|
+
if (environment !== "sandbox" && !evmPrivateKey) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`EVM private key is required for ${environment} environment. Use sandbox mode for local development without blockchain.`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/facilitator/sandbox-facilitator.ts
|
|
31
|
+
var SandboxFacilitator = class {
|
|
32
|
+
constructor(config) {
|
|
33
|
+
this.config = {
|
|
34
|
+
apiUrl: config.apiUrl,
|
|
35
|
+
apiKey: config.apiKey,
|
|
36
|
+
settlementDelayMs: config.settlementDelayMs ?? 0,
|
|
37
|
+
failureRate: config.failureRate ?? 0,
|
|
38
|
+
debug: config.debug ?? false,
|
|
39
|
+
supportedSchemes: config.supportedSchemes ?? [
|
|
40
|
+
{
|
|
41
|
+
scheme: "exact-evm",
|
|
42
|
+
networks: ["eip155:8453", "eip155:84532"]
|
|
43
|
+
// Base mainnet and Sepolia
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
};
|
|
47
|
+
if (this.config.debug) {
|
|
48
|
+
console.log("[SandboxFacilitator] Initialized with config:", {
|
|
49
|
+
apiUrl: this.config.apiUrl,
|
|
50
|
+
settlementDelayMs: this.config.settlementDelayMs,
|
|
51
|
+
failureRate: this.config.failureRate
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Verify a payment payload
|
|
57
|
+
*
|
|
58
|
+
* In sandbox mode, this validates the structure but skips signature verification
|
|
59
|
+
*/
|
|
60
|
+
async verify(request) {
|
|
61
|
+
const { payment } = request;
|
|
62
|
+
if (this.config.debug) {
|
|
63
|
+
console.log("[SandboxFacilitator] Verifying payment:", payment);
|
|
64
|
+
}
|
|
65
|
+
const requiredFields = ["scheme", "network", "amount", "token", "from", "to"];
|
|
66
|
+
for (const field of requiredFields) {
|
|
67
|
+
if (!payment[field]) {
|
|
68
|
+
return {
|
|
69
|
+
valid: false,
|
|
70
|
+
reason: `Missing required field: ${field}`
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const schemeSupported = this.config.supportedSchemes.some(
|
|
75
|
+
(s) => s.scheme === payment.scheme
|
|
76
|
+
);
|
|
77
|
+
if (!schemeSupported) {
|
|
78
|
+
return {
|
|
79
|
+
valid: false,
|
|
80
|
+
reason: `Unsupported scheme: ${payment.scheme}`,
|
|
81
|
+
details: {
|
|
82
|
+
supportedSchemes: this.config.supportedSchemes.map((s) => s.scheme)
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const scheme = this.config.supportedSchemes.find(
|
|
87
|
+
(s) => s.scheme === payment.scheme
|
|
88
|
+
);
|
|
89
|
+
if (scheme && !scheme.networks.includes(payment.network)) {
|
|
90
|
+
return {
|
|
91
|
+
valid: false,
|
|
92
|
+
reason: `Unsupported network: ${payment.network} for scheme: ${payment.scheme}`,
|
|
93
|
+
details: {
|
|
94
|
+
supportedNetworks: scheme.networks
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const amount = parseFloat(payment.amount);
|
|
99
|
+
if (isNaN(amount) || amount <= 0) {
|
|
100
|
+
return {
|
|
101
|
+
valid: false,
|
|
102
|
+
reason: `Invalid amount: ${payment.amount}`
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
valid: true
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Settle a payment
|
|
111
|
+
*
|
|
112
|
+
* In sandbox mode, this generates a mock transaction hash and
|
|
113
|
+
* optionally records the payment in PayOS
|
|
114
|
+
*/
|
|
115
|
+
async settle(request) {
|
|
116
|
+
const { payment } = request;
|
|
117
|
+
if (this.config.debug) {
|
|
118
|
+
console.log("[SandboxFacilitator] Settling payment:", payment);
|
|
119
|
+
}
|
|
120
|
+
const verification = await this.verify({ payment });
|
|
121
|
+
if (!verification.valid) {
|
|
122
|
+
throw new Error(`Payment verification failed: ${verification.reason}`);
|
|
123
|
+
}
|
|
124
|
+
if (this.config.failureRate > 0) {
|
|
125
|
+
const random = Math.random() * 100;
|
|
126
|
+
if (random < this.config.failureRate) {
|
|
127
|
+
throw new Error("Simulated settlement failure");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (this.config.settlementDelayMs > 0) {
|
|
131
|
+
await new Promise(
|
|
132
|
+
(resolve) => setTimeout(resolve, this.config.settlementDelayMs)
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
const txHash = this.generateMockTxHash();
|
|
136
|
+
if (this.config.debug) {
|
|
137
|
+
console.log("[SandboxFacilitator] Settlement complete:", {
|
|
138
|
+
txHash,
|
|
139
|
+
amount: payment.amount,
|
|
140
|
+
from: payment.from,
|
|
141
|
+
to: payment.to
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
transactionHash: txHash,
|
|
146
|
+
settled: true,
|
|
147
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get supported schemes and networks
|
|
152
|
+
*/
|
|
153
|
+
async supported() {
|
|
154
|
+
return {
|
|
155
|
+
schemes: this.config.supportedSchemes
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Generate a realistic-looking mock transaction hash
|
|
160
|
+
*/
|
|
161
|
+
generateMockTxHash() {
|
|
162
|
+
const chars = "0123456789abcdef";
|
|
163
|
+
let hash = "0x";
|
|
164
|
+
for (let i = 0; i < 64; i++) {
|
|
165
|
+
hash += chars[Math.floor(Math.random() * chars.length)];
|
|
166
|
+
}
|
|
167
|
+
return hash;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/protocols/x402/client.ts
|
|
172
|
+
var SlyX402Client = class {
|
|
173
|
+
constructor(config) {
|
|
174
|
+
this.dailySpent = 0;
|
|
175
|
+
validateEnvironment(config.environment, config.evmPrivateKey);
|
|
176
|
+
const envConfig = getEnvironmentConfig(config.environment);
|
|
177
|
+
this.config = {
|
|
178
|
+
apiKey: config.apiKey,
|
|
179
|
+
environment: config.environment,
|
|
180
|
+
evmPrivateKey: config.evmPrivateKey,
|
|
181
|
+
facilitatorUrl: config.facilitatorUrl || envConfig.facilitatorUrl || "",
|
|
182
|
+
maxAutoPayAmount: config.maxAutoPayAmount || "1.00",
|
|
183
|
+
maxDailySpend: config.maxDailySpend || "100.00",
|
|
184
|
+
onPayment: config.onPayment,
|
|
185
|
+
onSettlement: config.onSettlement,
|
|
186
|
+
settleToRail: config.settleToRail
|
|
187
|
+
};
|
|
188
|
+
this.lastResetDate = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
189
|
+
if (this.config.environment === "sandbox") {
|
|
190
|
+
this.sandboxFacilitator = new SandboxFacilitator({
|
|
191
|
+
apiUrl: envConfig.apiUrl,
|
|
192
|
+
apiKey: this.config.apiKey
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Fetch a resource with automatic 402 payment handling
|
|
198
|
+
*/
|
|
199
|
+
async fetch(url, options = {}) {
|
|
200
|
+
const { maxPayment, ...fetchOptions } = options;
|
|
201
|
+
let response = await fetch(url, fetchOptions);
|
|
202
|
+
if (response.status !== 402) {
|
|
203
|
+
return response;
|
|
204
|
+
}
|
|
205
|
+
const paymentRequired = await this.parse402Response(response);
|
|
206
|
+
const acceptedOption = paymentRequired.accepts[0];
|
|
207
|
+
if (!acceptedOption) {
|
|
208
|
+
throw new Error("No acceptable payment options in 402 response");
|
|
209
|
+
}
|
|
210
|
+
const amount = parseFloat(acceptedOption.amount);
|
|
211
|
+
const maxAmount = parseFloat(maxPayment || this.config.maxAutoPayAmount);
|
|
212
|
+
if (amount > maxAmount) {
|
|
213
|
+
throw new Error(
|
|
214
|
+
`Payment amount ${acceptedOption.amount} exceeds max auto-pay amount ${maxPayment || this.config.maxAutoPayAmount}`
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
this.resetDailySpendIfNeeded();
|
|
218
|
+
if (this.dailySpent + amount > parseFloat(this.config.maxDailySpend)) {
|
|
219
|
+
throw new Error(
|
|
220
|
+
`Payment would exceed daily limit. Spent: ${this.dailySpent}, Limit: ${this.config.maxDailySpend}`
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
const payment = await this.createPayment(acceptedOption);
|
|
224
|
+
if (this.config.onPayment) {
|
|
225
|
+
await this.config.onPayment({
|
|
226
|
+
amount: acceptedOption.amount,
|
|
227
|
+
currency: acceptedOption.token,
|
|
228
|
+
from: payment.from,
|
|
229
|
+
to: payment.to,
|
|
230
|
+
scheme: acceptedOption.scheme,
|
|
231
|
+
network: acceptedOption.network,
|
|
232
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
this.dailySpent += amount;
|
|
236
|
+
response = await fetch(url, {
|
|
237
|
+
...fetchOptions,
|
|
238
|
+
headers: {
|
|
239
|
+
...fetchOptions.headers,
|
|
240
|
+
"X-Payment": JSON.stringify(payment)
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
if (this.config.onSettlement && payment.transactionHash) {
|
|
244
|
+
await this.config.onSettlement({
|
|
245
|
+
transactionHash: payment.transactionHash,
|
|
246
|
+
amount: acceptedOption.amount,
|
|
247
|
+
currency: acceptedOption.token,
|
|
248
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return response;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get client status
|
|
255
|
+
*/
|
|
256
|
+
getStatus() {
|
|
257
|
+
this.resetDailySpendIfNeeded();
|
|
258
|
+
return {
|
|
259
|
+
environment: this.config.environment,
|
|
260
|
+
dailySpent: this.dailySpent.toFixed(2),
|
|
261
|
+
dailyLimit: this.config.maxDailySpend,
|
|
262
|
+
walletAddress: this.getWalletAddress()
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Parse 402 response
|
|
267
|
+
*/
|
|
268
|
+
async parse402Response(response) {
|
|
269
|
+
const body = await response.json();
|
|
270
|
+
if (!body.accepts || !Array.isArray(body.accepts)) {
|
|
271
|
+
throw new Error("Invalid 402 response: missing accepts array");
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
statusCode: 402,
|
|
275
|
+
accepts: body.accepts
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Create payment based on environment
|
|
280
|
+
*/
|
|
281
|
+
async createPayment(option) {
|
|
282
|
+
if (this.config.environment === "sandbox") {
|
|
283
|
+
return this.createSandboxPayment(option);
|
|
284
|
+
} else {
|
|
285
|
+
return this.createBlockchainPayment(option);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Create sandbox payment (mock)
|
|
290
|
+
*/
|
|
291
|
+
async createSandboxPayment(option) {
|
|
292
|
+
if (!this.sandboxFacilitator) {
|
|
293
|
+
throw new Error("Sandbox facilitator not initialized");
|
|
294
|
+
}
|
|
295
|
+
const payment = {
|
|
296
|
+
scheme: option.scheme,
|
|
297
|
+
network: option.network,
|
|
298
|
+
amount: option.amount,
|
|
299
|
+
token: option.token,
|
|
300
|
+
from: "0x0000000000000000000000000000000000000001",
|
|
301
|
+
// Mock address
|
|
302
|
+
to: "0x0000000000000000000000000000000000000002"
|
|
303
|
+
// Mock address
|
|
304
|
+
};
|
|
305
|
+
const settlement = await this.sandboxFacilitator.settle({ payment });
|
|
306
|
+
return {
|
|
307
|
+
...payment,
|
|
308
|
+
transactionHash: settlement.transactionHash
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Create blockchain payment (real EVM)
|
|
313
|
+
*/
|
|
314
|
+
async createBlockchainPayment(_option) {
|
|
315
|
+
if (!this.config.evmPrivateKey) {
|
|
316
|
+
throw new Error("EVM private key required for blockchain payments");
|
|
317
|
+
}
|
|
318
|
+
throw new Error("Blockchain payments not yet implemented - use sandbox mode");
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Get wallet address based on environment
|
|
322
|
+
*/
|
|
323
|
+
getWalletAddress() {
|
|
324
|
+
if (this.config.environment === "sandbox") {
|
|
325
|
+
return "0x0000000000000000000000000000000000000001";
|
|
326
|
+
}
|
|
327
|
+
return void 0;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Reset daily spend if date has changed
|
|
331
|
+
*/
|
|
332
|
+
resetDailySpendIfNeeded() {
|
|
333
|
+
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
334
|
+
if (today !== this.lastResetDate) {
|
|
335
|
+
this.dailySpent = 0;
|
|
336
|
+
this.lastResetDate = today;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// src/protocols/x402/provider.ts
|
|
342
|
+
var SlyX402Provider = class {
|
|
343
|
+
constructor(config) {
|
|
344
|
+
const envConfig = getEnvironmentConfig(config.environment);
|
|
345
|
+
this.config = {
|
|
346
|
+
apiKey: config.apiKey,
|
|
347
|
+
environment: config.environment,
|
|
348
|
+
routes: config.routes,
|
|
349
|
+
facilitatorUrl: config.facilitatorUrl || envConfig.facilitatorUrl
|
|
350
|
+
};
|
|
351
|
+
if (this.config.environment === "sandbox") {
|
|
352
|
+
this.sandboxFacilitator = new SandboxFacilitator({
|
|
353
|
+
apiUrl: envConfig.apiUrl,
|
|
354
|
+
apiKey: this.config.apiKey
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Create Express middleware
|
|
360
|
+
*/
|
|
361
|
+
middleware() {
|
|
362
|
+
return async (req, res, next) => {
|
|
363
|
+
try {
|
|
364
|
+
const routeConfig = this.getRouteConfig(req);
|
|
365
|
+
if (!routeConfig) {
|
|
366
|
+
return next();
|
|
367
|
+
}
|
|
368
|
+
const paymentHeader = req.headers["x-payment"];
|
|
369
|
+
if (!paymentHeader) {
|
|
370
|
+
return this.return402(req, res, routeConfig);
|
|
371
|
+
}
|
|
372
|
+
const isValid = await this.verifyPayment(paymentHeader, routeConfig);
|
|
373
|
+
if (!isValid) {
|
|
374
|
+
return this.return402(req, res, routeConfig);
|
|
375
|
+
}
|
|
376
|
+
next();
|
|
377
|
+
} catch (error) {
|
|
378
|
+
res.status(500).json({
|
|
379
|
+
error: "Payment verification failed",
|
|
380
|
+
message: error.message
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Get route configuration for request
|
|
387
|
+
*/
|
|
388
|
+
getRouteConfig(req) {
|
|
389
|
+
const routeKey = `${req.method} ${req.path}`;
|
|
390
|
+
if (this.config.routes[routeKey]) {
|
|
391
|
+
return this.config.routes[routeKey];
|
|
392
|
+
}
|
|
393
|
+
for (const [pattern, config] of Object.entries(this.config.routes)) {
|
|
394
|
+
if (this.matchRoute(pattern, routeKey)) {
|
|
395
|
+
return config;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Simple route pattern matching
|
|
402
|
+
*/
|
|
403
|
+
matchRoute(pattern, route) {
|
|
404
|
+
const regexPattern = pattern.replace(/\*/g, ".*").replace(/\//g, "\\/");
|
|
405
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
406
|
+
return regex.test(route);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Return 402 Payment Required response
|
|
410
|
+
*/
|
|
411
|
+
return402(_req, res, routeConfig) {
|
|
412
|
+
const scheme = "exact-evm";
|
|
413
|
+
const network = this.config.environment === "sandbox" ? "eip155:8453" : "eip155:8453";
|
|
414
|
+
res.status(402).json({
|
|
415
|
+
statusCode: 402,
|
|
416
|
+
message: "Payment Required",
|
|
417
|
+
accepts: [
|
|
418
|
+
{
|
|
419
|
+
scheme,
|
|
420
|
+
network,
|
|
421
|
+
token: routeConfig.token || "USDC",
|
|
422
|
+
amount: routeConfig.price,
|
|
423
|
+
facilitator: this.config.facilitatorUrl,
|
|
424
|
+
description: routeConfig.description
|
|
425
|
+
}
|
|
426
|
+
]
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Verify payment
|
|
431
|
+
*/
|
|
432
|
+
async verifyPayment(paymentHeader, routeConfig) {
|
|
433
|
+
try {
|
|
434
|
+
const payment = JSON.parse(paymentHeader);
|
|
435
|
+
if (payment.amount !== routeConfig.price) {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
const expectedToken = routeConfig.token || "USDC";
|
|
439
|
+
if (payment.token !== expectedToken) {
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
if (this.config.environment === "sandbox") {
|
|
443
|
+
return this.verifySandboxPayment(payment);
|
|
444
|
+
} else {
|
|
445
|
+
return this.verifyBlockchainPayment(payment);
|
|
446
|
+
}
|
|
447
|
+
} catch (error) {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Verify sandbox payment
|
|
453
|
+
*/
|
|
454
|
+
async verifySandboxPayment(payment) {
|
|
455
|
+
if (!this.sandboxFacilitator) {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
const result = await this.sandboxFacilitator.verify({ payment });
|
|
459
|
+
return result.valid;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Verify blockchain payment
|
|
463
|
+
*/
|
|
464
|
+
async verifyBlockchainPayment(_payment) {
|
|
465
|
+
throw new Error("Blockchain payment verification not yet implemented - use sandbox mode");
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
export { SlyX402Client as PayOSX402Client, SlyX402Provider as PayOSX402Provider, SlyX402Client, SlyX402Provider };
|
|
470
|
+
//# sourceMappingURL=x402.mjs.map
|
|
471
|
+
//# sourceMappingURL=x402.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts","../src/facilitator/sandbox-facilitator.ts","../src/protocols/x402/client.ts","../src/protocols/x402/provider.ts"],"names":[],"mappings":";AAKO,IAAM,mBAAA,GAAmE;AAAA,EAC9E,OAAA,EAAS;AAAA,IACP,MAAA,EAAQ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fig } from './types';\n\n/**\n * Environment-specific configuration\n */\nexport const ENVIRONMENT_CONFIGS: Record<PayOSEnvironment, EnvironmentConfig> = {\n sandbox: {\n apiUrl: 'https://sandbox.getsly.ai',\n facilitatorUrl: 'https://facilitator.x402.org', // x402.org Base Sepolia\n },\n testnet: {\n apiUrl: 'https://sandbox.getsly.ai',\n facilitatorUrl: 'https://facilitator.x402.org', // x402.org Base Sepolia\n },\n production: {\n apiUrl: 'https://api.getsly.ai',\n facilitatorUrl: 'https://facilitator.coinbase.com', // Coinbase CDP Base mainnet\n },\n};\n\n/**\n * Infer environment from API key prefix\n * - pk_test_* or pk_sandbox_* → sandbox\n * - pk_live_* → production\n */\nexport function inferEnvironmentFromKey(apiKey: string): PayOSEnvironment | undefined {\n if (apiKey.startsWith('pk_test_') || apiKey.startsWith('pk_sandbox_')) {\n return 'sandbox';\n }\n if (apiKey.startsWith('pk_live_')) {\n return 'production';\n }\n return undefined;\n}\n\n/**\n * Get configuration for an environment\n */\nexport function getEnvironmentConfig(environment: PayOSEnvironment): EnvironmentConfig {\n return ENVIRONMENT_CONFIGS[environment];\n}\n\n/**\n * Validate environment configuration\n */\nexport function validateEnvironment(\n environment: PayOSEnvironment,\n evmPrivateKey?: string\n): void {\n if (environment !== 'sandbox' && !evmPrivateKey) {\n throw new Error(\n `EVM private key is required for ${environment} environment. ` +\n 'Use sandbox mode for local development without blockchain.'\n );\n }\n}\n\n","import type {\n SandboxFacilitatorConfig,\n X402Payment,\n VerifyRequest,\n VerifyResponse,\n SettleRequest,\n SettleResponse,\n SupportedResponse,\n} from './types';\n\n/**\n * Sandbox Facilitator for x402 protocol\n * \n * Provides a mock blockchain facilitator that implements the x402\n * facilitator interface but skips actual blockchain verification.\n * \n * This enables local development and testing without:\n * - Gas fees\n * - Real USDC\n * - Network delays\n * - EVM private keys\n */\nexport class SandboxFacilitator {\n private config: Required<SandboxFacilitatorConfig>;\n\n constructor(config: SandboxFacilitatorConfig) {\n this.config = {\n apiUrl: config.apiUrl,\n apiKey: config.apiKey,\n settlementDelayMs: config.settlementDelayMs ?? 0,\n failureRate: config.failureRate ?? 0,\n debug: config.debug ?? false,\n supportedSchemes: config.supportedSchemes ?? [\n {\n scheme: 'exact-evm',\n networks: ['eip155:8453', 'eip155:84532'], // Base mainnet and Sepolia\n },\n ],\n };\n\n if (this.config.debug) {\n console.log('[SandboxFacilitator] Initialized with config:', {\n apiUrl: this.config.apiUrl,\n settlementDelayMs: this.config.settlementDelayMs,\n failureRate: this.config.failureRate,\n });\n }\n }\n\n /**\n * Verify a payment payload\n * \n * In sandbox mode, this validates the structure but skips signature verification\n */\n async verify(request: VerifyRequest): Promise<VerifyResponse> {\n const { payment } = request;\n\n if (this.config.debug) {\n console.log('[SandboxFacilitator] Verifying payment:', payment);\n }\n\n // Validate required fields\n const requiredFields = ['scheme', 'network', 'amount', 'token', 'from', 'to'];\n for (const field of requiredFields) {\n if (!payment[field]) {\n return {\n valid: false,\n reason: `Missing required field: ${field}`,\n };\n }\n }\n\n // Validate scheme is supported\n const schemeSupported = this.config.supportedSchemes.some(\n (s) => s.scheme === payment.scheme\n );\n if (!schemeSupported) {\n return {\n valid: false,\n reason: `Unsupported scheme: ${payment.scheme}`,\n details: {\n supportedSchemes: this.config.supportedSchemes.map((s) => s.scheme),\n },\n };\n }\n\n // Validate network is supported for scheme\n const scheme = this.config.supportedSchemes.find(\n (s) => s.scheme === payment.scheme\n );\n if (scheme && !scheme.networks.includes(payment.network)) {\n return {\n valid: false,\n reason: `Unsupported network: ${payment.network} for scheme: ${payment.scheme}`,\n details: {\n supportedNetworks: scheme.networks,\n },\n };\n }\n\n // Validate amount is a valid number\n const amount = parseFloat(payment.amount);\n if (isNaN(amount) || amount <= 0) {\n return {\n valid: false,\n reason: `Invalid amount: ${payment.amount}`,\n };\n }\n\n // In sandbox mode, we skip signature verification\n // In production, this would verify the EIP-3009 signature\n\n return {\n valid: true,\n };\n }\n\n /**\n * Settle a payment\n * \n * In sandbox mode, this generates a mock transaction hash and\n * optionally records the payment in PayOS\n */\n async settle(request: SettleRequest): Promise<SettleResponse> {\n const { payment } = request;\n\n if (this.config.debug) {\n console.log('[SandboxFacilitator] Settling payment:', payment);\n }\n\n // First verify the payment\n const verification = await this.verify({ payment });\n if (!verification.valid) {\n throw new Error(`Payment verification failed: ${verification.reason}`);\n }\n\n // Simulate random failures if configured\n if (this.config.failureRate > 0) {\n const random = Math.random() * 100;\n if (random < this.config.failureRate) {\n throw new Error('Simulated settlement failure');\n }\n }\n\n // Simulate settlement delay if configured\n if (this.config.settlementDelayMs > 0) {\n await new Promise((resolve) =>\n setTimeout(resolve, this.config.settlementDelayMs)\n );\n }\n\n // Generate mock transaction hash\n const txHash = this.generateMockTxHash();\n\n // Record payment in PayOS (optional - may not be needed in pure sandbox)\n // This would call the PayOS API to create a transfer record\n // For now, we'll skip this to keep the facilitator independent\n\n if (this.config.debug) {\n console.log('[SandboxFacilitator] Settlement complete:', {\n txHash,\n amount: payment.amount,\n from: payment.from,\n to: payment.to,\n });\n }\n\n return {\n transactionHash: txHash,\n settled: true,\n timestamp: new Date().toISOString(),\n };\n }\n\n /**\n * Get supported schemes and networks\n */\n async supported(): Promise<SupportedResponse> {\n return {\n schemes: this.config.supportedSchemes,\n };\n }\n\n /**\n * Generate a realistic-looking mock transaction hash\n */\n private generateMockTxHash(): string {\n const chars = '0123456789abcdef';\n let hash = '0x';\n for (let i = 0; i < 64; i++) {\n hash += chars[Math.floor(Math.random() * chars.length)];\n }\n return hash;\n }\n}\n\n","import type {\n X402ClientConfig,\n X402ClientStatus,\n X402PaymentInfo,\n X402SettlementInfo,\n X402Response,\n} from './types';\nimport { getEnvironmentConfig, validateEnvironment } from '../../config';\nimport { SandboxFacilitator } from '../../facilitator/sandbox-facilitator';\n\n/**\n * x402 Client for making payments\n *\n * Automatically handles 402 responses by creating payments and retrying.\n * Supports sandbox mode (no blockchain) and production mode (real EVM).\n */\nexport class SlyX402Client {\n private config: Required<Omit<X402ClientConfig, 'evmPrivateKey' | 'onPayment' | 'onSettlement' | 'settleToRail'>> & {\n evmPrivateKey?: string;\n onPayment?: (payment: X402PaymentInfo) => void | Promise<void>;\n onSettlement?: (settlement: X402SettlementInfo) => void | Promise<void>;\n settleToRail?: 'pix' | 'spei' | 'none';\n };\n private dailySpent: number = 0;\n private lastResetDate: string;\n private sandboxFacilitator?: SandboxFacilitator;\n\n constructor(config: X402ClientConfig) {\n validateEnvironment(config.environment, config.evmPrivateKey);\n\n const envConfig = getEnvironmentConfig(config.environment);\n\n this.config = {\n apiKey: config.apiKey,\n environment: config.environment,\n evmPrivateKey: config.evmPrivateKey,\n facilitatorUrl: config.facilitatorUrl || envConfig.facilitatorUrl || '',\n maxAutoPayAmount: config.maxAutoPayAmount || '1.00',\n maxDailySpend: config.maxDailySpend || '100.00',\n onPayment: config.onPayment,\n onSettlement: config.onSettlement,\n settleToRail: config.settleToRail,\n };\n\n this.lastResetDate = new Date().toISOString().split('T')[0];\n\n // Initialize sandbox facilitator if in sandbox mode\n if (this.config.environment === 'sandbox') {\n this.sandboxFacilitator = new SandboxFacilitator({\n apiUrl: envConfig.apiUrl,\n apiKey: this.config.apiKey,\n });\n }\n }\n\n /**\n * Fetch a resource with automatic 402 payment handling\n */\n async fetch(url: string, options: RequestInit & { maxPayment?: string } = {}): Promise<Response> {\n const { maxPayment, ...fetchOptions } = options;\n\n // Make initial request\n let response = await fetch(url, fetchOptions);\n\n // If not 402, return response\n if (response.status !== 402) {\n return response;\n }\n\n // Parse 402 response\n const paymentRequired = await this.parse402Response(response);\n\n // Find acceptable payment option\n const acceptedOption = paymentRequired.accepts[0];\n if (!acceptedOption) {\n throw new Error('No acceptable payment options in 402 response');\n }\n\n // Check payment amount against limits\n const amount = parseFloat(acceptedOption.amount);\n const maxAmount = parseFloat(maxPayment || this.config.maxAutoPayAmount);\n\n if (amount > maxAmount) {\n throw new Error(\n `Payment amount ${acceptedOption.amount} exceeds max auto-pay amount ${maxPayment || this.config.maxAutoPayAmount}`\n );\n }\n\n // Check daily limit\n this.resetDailySpendIfNeeded();\n if (this.dailySpent + amount > parseFloat(this.config.maxDailySpend)) {\n throw new Error(\n `Payment would exceed daily limit. Spent: ${this.dailySpent}, Limit: ${this.config.maxDailySpend}`\n );\n }\n\n // Create payment\n const payment = await this.createPayment(acceptedOption);\n\n // Fire onPayment callback\n if (this.config.onPayment) {\n await this.config.onPayment({\n amount: acceptedOption.amount,\n currency: acceptedOption.token,\n from: payment.from,\n to: payment.to,\n scheme: acceptedOption.scheme,\n network: acceptedOption.network,\n timestamp: new Date().toISOString(),\n });\n }\n\n // Update daily spend\n this.dailySpent += amount;\n\n // Retry request with payment header\n response = await fetch(url, {\n ...fetchOptions,\n headers: {\n ...fetchOptions.headers,\n 'X-Payment': JSON.stringify(payment),\n },\n });\n\n // Fire onSettlement callback\n if (this.config.onSettlement && payment.transactionHash) {\n await this.config.onSettlement({\n transactionHash: payment.transactionHash,\n amount: acceptedOption.amount,\n currency: acceptedOption.token,\n timestamp: new Date().toISOString(),\n });\n }\n\n return response;\n }\n\n /**\n * Get client status\n */\n getStatus(): X402ClientStatus {\n this.resetDailySpendIfNeeded();\n\n return {\n environment: this.config.environment,\n dailySpent: this.dailySpent.toFixed(2),\n dailyLimit: this.config.maxDailySpend,\n walletAddress: this.getWalletAddress(),\n };\n }\n\n /**\n * Parse 402 response\n */\n private async parse402Response(response: Response): Promise<X402Response> {\n const body: any = await response.json();\n \n if (!body.accepts || !Array.isArray(body.accepts)) {\n throw new Error('Invalid 402 response: missing accepts array');\n }\n\n return {\n statusCode: 402,\n accepts: body.accepts,\n };\n }\n\n /**\n * Create payment based on environment\n */\n private async createPayment(option: X402Response['accepts'][0]): Promise<any> {\n if (this.config.environment === 'sandbox') {\n return this.createSandboxPayment(option);\n } else {\n return this.createBlockchainPayment(option);\n }\n }\n\n /**\n * Create sandbox payment (mock)\n */\n private async createSandboxPayment(option: X402Response['accepts'][0]): Promise<any> {\n if (!this.sandboxFacilitator) {\n throw new Error('Sandbox facilitator not initialized');\n }\n\n const payment = {\n scheme: option.scheme,\n network: option.network,\n amount: option.amount,\n token: option.token,\n from: '0x0000000000000000000000000000000000000001', // Mock address\n to: '0x0000000000000000000000000000000000000002', // Mock address\n };\n\n // Settle through sandbox facilitator\n const settlement = await this.sandboxFacilitator.settle({ payment });\n\n return {\n ...payment,\n transactionHash: settlement.transactionHash,\n };\n }\n\n /**\n * Create blockchain payment (real EVM)\n */\n private async createBlockchainPayment(_option: X402Response['accepts'][0]): Promise<any> {\n if (!this.config.evmPrivateKey) {\n throw new Error('EVM private key required for blockchain payments');\n }\n\n // In a real implementation, this would:\n // 1. Use @x402/evm to create an EIP-3009 transfer\n // 2. Sign with the private key\n // 3. Submit to the facilitator\n // 4. Return the payment proof\n\n // For now, throw an error as this requires the full @x402 integration\n throw new Error('Blockchain payments not yet implemented - use sandbox mode');\n }\n\n /**\n * Get wallet address based on environment\n */\n private getWalletAddress(): string | undefined {\n if (this.config.environment === 'sandbox') {\n return '0x0000000000000000000000000000000000000001';\n }\n\n // In production, derive from private key\n return undefined;\n }\n\n /**\n * Reset daily spend if date has changed\n */\n private resetDailySpendIfNeeded(): void {\n const today = new Date().toISOString().split('T')[0];\n if (today !== this.lastResetDate) {\n this.dailySpent = 0;\n this.lastResetDate = today;\n }\n }\n}\n\n// Backward compatibility alias\nexport { SlyX402Client as PayOSX402Client };\n\n","import type { Request, Response, NextFunction, RequestHandler } from 'express';\nimport type { SlyEnvironment } from '../../types';\nimport { getEnvironmentConfig } from '../../config';\nimport { SandboxFacilitator } from '../../facilitator/sandbox-facilitator';\n\n/**\n * x402 Provider configuration\n */\nexport interface X402ProviderConfig {\n /**\n * Sly API key\n */\n apiKey: string;\n\n /**\n * Environment (sandbox, testnet, production)\n */\n environment: SlyEnvironment;\n\n /**\n * Route configuration\n * Maps route patterns to prices\n */\n routes: Record<string, {\n price: string;\n description?: string;\n token?: string;\n }>;\n\n /**\n * Custom facilitator URL (overrides environment default)\n */\n facilitatorUrl?: string;\n}\n\n/**\n * x402 Provider for accepting payments\n *\n * Express middleware that returns 402 responses for protected routes\n * and verifies payments before serving content.\n */\nexport class SlyX402Provider {\n private config: Required<Omit<X402ProviderConfig, 'facilitatorUrl'>> & {\n facilitatorUrl?: string;\n };\n private sandboxFacilitator?: SandboxFacilitator;\n\n constructor(config: X402ProviderConfig) {\n const envConfig = getEnvironmentConfig(config.environment);\n\n this.config = {\n apiKey: config.apiKey,\n environment: config.environment,\n routes: config.routes,\n facilitatorUrl: config.facilitatorUrl || envConfig.facilitatorUrl,\n };\n\n // Initialize sandbox facilitator if in sandbox mode\n if (this.config.environment === 'sandbox') {\n this.sandboxFacilitator = new SandboxFacilitator({\n apiUrl: envConfig.apiUrl,\n apiKey: this.config.apiKey,\n });\n }\n }\n\n /**\n * Create Express middleware\n */\n middleware(): RequestHandler {\n return async (req: Request, res: Response, next: NextFunction) => {\n try {\n // Check if route is protected\n const routeConfig = this.getRouteConfig(req);\n if (!routeConfig) {\n // Route not protected, continue\n return next();\n }\n\n // Check for payment header\n const paymentHeader = req.headers['x-payment'] as string | undefined;\n\n if (!paymentHeader) {\n // No payment, return 402\n return this.return402(req, res, routeConfig);\n }\n\n // Verify payment\n const isValid = await this.verifyPayment(paymentHeader, routeConfig);\n\n if (!isValid) {\n // Invalid payment, return 402\n return this.return402(req, res, routeConfig);\n }\n\n // Payment valid, continue to route handler\n next();\n } catch (error: any) {\n res.status(500).json({\n error: 'Payment verification failed',\n message: error.message,\n });\n }\n };\n }\n\n /**\n * Get route configuration for request\n */\n private getRouteConfig(req: Request): X402ProviderConfig['routes'][string] | null {\n const routeKey = `${req.method} ${req.path}`;\n \n // Exact match\n if (this.config.routes[routeKey]) {\n return this.config.routes[routeKey];\n }\n\n // Pattern match (simple wildcard support)\n for (const [pattern, config] of Object.entries(this.config.routes)) {\n if (this.matchRoute(pattern, routeKey)) {\n return config;\n }\n }\n\n return null;\n }\n\n /**\n * Simple route pattern matching\n */\n private matchRoute(pattern: string, route: string): boolean {\n // Convert pattern to regex\n const regexPattern = pattern\n .replace(/\\*/g, '.*')\n .replace(/\\//g, '\\\\/');\n \n const regex = new RegExp(`^${regexPattern}$`);\n return regex.test(route);\n }\n\n /**\n * Return 402 Payment Required response\n */\n private return402(\n _req: Request,\n res: Response,\n routeConfig: X402ProviderConfig['routes'][string]\n ): void {\n const scheme = 'exact-evm';\n const network = this.config.environment === 'sandbox' \n ? 'eip155:8453' // Base mainnet (mock)\n : 'eip155:8453'; // Base mainnet (real)\n\n res.status(402).json({\n statusCode: 402,\n message: 'Payment Required',\n accepts: [\n {\n scheme,\n network,\n token: routeConfig.token || 'USDC',\n amount: routeConfig.price,\n facilitator: this.config.facilitatorUrl,\n description: routeConfig.description,\n },\n ],\n });\n }\n\n /**\n * Verify payment\n */\n private async verifyPayment(\n paymentHeader: string,\n routeConfig: X402ProviderConfig['routes'][string]\n ): Promise<boolean> {\n try {\n const payment = JSON.parse(paymentHeader);\n\n // Check amount matches\n if (payment.amount !== routeConfig.price) {\n return false;\n }\n\n // Check token matches\n const expectedToken = routeConfig.token || 'USDC';\n if (payment.token !== expectedToken) {\n return false;\n }\n\n // Verify with facilitator\n if (this.config.environment === 'sandbox') {\n return this.verifySandboxPayment(payment);\n } else {\n return this.verifyBlockchainPayment(payment);\n }\n } catch (error) {\n return false;\n }\n }\n\n /**\n * Verify sandbox payment\n */\n private async verifySandboxPayment(payment: any): Promise<boolean> {\n if (!this.sandboxFacilitator) {\n return false;\n }\n\n const result = await this.sandboxFacilitator.verify({ payment });\n return result.valid;\n }\n\n /**\n * Verify blockchain payment\n */\n private async verifyBlockchainPayment(_payment: any): Promise<boolean> {\n // In production, this would:\n // 1. Call the real facilitator to verify the payment\n // 2. Check the signature\n // 3. Verify the transaction on-chain\n\n // For now, throw an error as this requires full @x402 integration\n throw new Error('Blockchain payment verification not yet implemented - use sandbox mode');\n }\n}\n\n// Backward compatibility alias\nexport { SlyX402Provider as PayOSX402Provider };\n\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sly_ai/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Unified PayOS SDK for multi-protocol settlement in LATAM",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./x402": {
|
|
15
|
+
"types": "./dist/x402.d.ts",
|
|
16
|
+
"import": "./dist/x402.mjs",
|
|
17
|
+
"require": "./dist/x402.js"
|
|
18
|
+
},
|
|
19
|
+
"./ap2": {
|
|
20
|
+
"types": "./dist/ap2.d.ts",
|
|
21
|
+
"import": "./dist/ap2.mjs",
|
|
22
|
+
"require": "./dist/ap2.js"
|
|
23
|
+
},
|
|
24
|
+
"./acp": {
|
|
25
|
+
"types": "./dist/acp.d.ts",
|
|
26
|
+
"import": "./dist/acp.mjs",
|
|
27
|
+
"require": "./dist/acp.js"
|
|
28
|
+
},
|
|
29
|
+
"./ucp": {
|
|
30
|
+
"types": "./dist/ucp.d.ts",
|
|
31
|
+
"import": "./dist/ucp.mjs",
|
|
32
|
+
"require": "./dist/ucp.js"
|
|
33
|
+
},
|
|
34
|
+
"./langchain": {
|
|
35
|
+
"types": "./dist/langchain.d.ts",
|
|
36
|
+
"import": "./dist/langchain.mjs",
|
|
37
|
+
"require": "./dist/langchain.js"
|
|
38
|
+
},
|
|
39
|
+
"./vercel": {
|
|
40
|
+
"types": "./dist/vercel.d.ts",
|
|
41
|
+
"import": "./dist/vercel.mjs",
|
|
42
|
+
"require": "./dist/vercel.js"
|
|
43
|
+
},
|
|
44
|
+
"./cards": {
|
|
45
|
+
"types": "./dist/cards.d.ts",
|
|
46
|
+
"import": "./dist/cards.mjs",
|
|
47
|
+
"require": "./dist/cards.js"
|
|
48
|
+
},
|
|
49
|
+
"./a2a": {
|
|
50
|
+
"types": "./dist/a2a.d.ts",
|
|
51
|
+
"import": "./dist/a2a.mjs",
|
|
52
|
+
"require": "./dist/a2a.js"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"files": [
|
|
56
|
+
"dist",
|
|
57
|
+
"README.md"
|
|
58
|
+
],
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsup",
|
|
61
|
+
"dev": "tsup --watch",
|
|
62
|
+
"typecheck": "tsc --noEmit",
|
|
63
|
+
"test": "vitest run",
|
|
64
|
+
"test:watch": "vitest",
|
|
65
|
+
"test:coverage": "vitest run --coverage",
|
|
66
|
+
"clean": "rm -rf dist"
|
|
67
|
+
},
|
|
68
|
+
"keywords": [
|
|
69
|
+
"payos",
|
|
70
|
+
"payments",
|
|
71
|
+
"settlement",
|
|
72
|
+
"x402",
|
|
73
|
+
"ap2",
|
|
74
|
+
"acp",
|
|
75
|
+
"ucp",
|
|
76
|
+
"latam",
|
|
77
|
+
"pix",
|
|
78
|
+
"spei",
|
|
79
|
+
"stablecoin",
|
|
80
|
+
"usdc",
|
|
81
|
+
"agentic-commerce"
|
|
82
|
+
],
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"@sly/types": "workspace:*",
|
|
85
|
+
"@x402/core": "^2.1.0",
|
|
86
|
+
"@x402/evm": "^2.1.0",
|
|
87
|
+
"@x402/express": "^2.1.0",
|
|
88
|
+
"@x402/fetch": "^2.1.0",
|
|
89
|
+
"ai": "^3.0.0",
|
|
90
|
+
"zod": "^3.22.4"
|
|
91
|
+
},
|
|
92
|
+
"devDependencies": {
|
|
93
|
+
"@types/express": "^4.17.21",
|
|
94
|
+
"@types/node": "^20.10.0",
|
|
95
|
+
"@vitest/coverage-v8": "^2.0.0",
|
|
96
|
+
"tsup": "^8.0.0",
|
|
97
|
+
"typescript": "^5.3.3",
|
|
98
|
+
"vitest": "^2.0.0"
|
|
99
|
+
},
|
|
100
|
+
"peerDependencies": {
|
|
101
|
+
"express": "^4.18.0"
|
|
102
|
+
},
|
|
103
|
+
"peerDependenciesMeta": {
|
|
104
|
+
"express": {
|
|
105
|
+
"optional": true
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"engines": {
|
|
109
|
+
"node": ">=18"
|
|
110
|
+
},
|
|
111
|
+
"repository": {
|
|
112
|
+
"type": "git",
|
|
113
|
+
"url": "https://github.com/payos/payos",
|
|
114
|
+
"directory": "packages/sdk"
|
|
115
|
+
},
|
|
116
|
+
"author": "PayOS",
|
|
117
|
+
"license": "MIT"
|
|
118
|
+
}
|