@agentspend/sdk 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +7 -5
- package/package.json +3 -2
- package/src/index.ts +7 -5
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.createAgentSpend = createAgentSpend;
|
|
|
10
10
|
// x402 imports – server-side only (HTTP calls to facilitator, no crypto deps)
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
const server_1 = require("@x402/core/server");
|
|
13
|
+
const server_2 = require("@x402/evm/exact/server");
|
|
13
14
|
class AgentSpendChargeError extends Error {
|
|
14
15
|
statusCode;
|
|
15
16
|
details;
|
|
@@ -74,6 +75,7 @@ function createAgentSpend(options) {
|
|
|
74
75
|
const facilitatorUrl = options.crypto?.facilitatorUrl ?? "https://x402.org/facilitator";
|
|
75
76
|
facilitator = new server_1.HTTPFacilitatorClient({ url: facilitatorUrl });
|
|
76
77
|
resourceServer = new server_1.x402ResourceServer(facilitator);
|
|
78
|
+
(0, server_2.registerExactEvmScheme)(resourceServer);
|
|
77
79
|
}
|
|
78
80
|
// -------------------------------------------------------------------
|
|
79
81
|
// charge() — card-only, unchanged
|
|
@@ -206,7 +208,7 @@ function createAgentSpend(options) {
|
|
|
206
208
|
// handleCryptoPayment — x402 verify + settle via facilitator
|
|
207
209
|
// -------------------------------------------------------------------
|
|
208
210
|
async function handleCryptoPayment(c, next, paymentHeader, amountCents, currency, _body, _opts) {
|
|
209
|
-
if (!
|
|
211
|
+
if (!resourceServer) {
|
|
210
212
|
return c.json({ error: "Crypto payments not configured" }, 500);
|
|
211
213
|
}
|
|
212
214
|
try {
|
|
@@ -237,13 +239,13 @@ function createAgentSpend(options) {
|
|
|
237
239
|
maxTimeoutSeconds: 300,
|
|
238
240
|
extra: { name: "USD Coin", version: "2" }
|
|
239
241
|
};
|
|
240
|
-
// Verify payment via facilitator
|
|
241
|
-
const verifyResult = await
|
|
242
|
+
// Verify payment via resource server (delegates to facilitator)
|
|
243
|
+
const verifyResult = await resourceServer.verifyPayment(paymentPayload, paymentRequirements);
|
|
242
244
|
if (!verifyResult.isValid) {
|
|
243
245
|
return c.json({ error: "Payment verification failed", details: verifyResult.invalidReason }, 402);
|
|
244
246
|
}
|
|
245
|
-
// Settle payment via facilitator
|
|
246
|
-
const settleResult = await
|
|
247
|
+
// Settle payment via resource server (delegates to facilitator)
|
|
248
|
+
const settleResult = await resourceServer.settlePayment(paymentPayload, paymentRequirements);
|
|
247
249
|
if (!settleResult.success) {
|
|
248
250
|
return c.json({ error: "Payment settlement failed", details: settleResult.errorReason }, 402);
|
|
249
251
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentspend/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@x402/core": "^2.3.1"
|
|
10
|
+
"@x402/core": "^2.3.1",
|
|
11
|
+
"@x402/evm": "^2.3.1"
|
|
11
12
|
},
|
|
12
13
|
"scripts": {
|
|
13
14
|
"build": "tsc",
|
package/src/index.ts
CHANGED
|
@@ -43,6 +43,7 @@ export interface PaywallPaymentContext {
|
|
|
43
43
|
// x402 imports – server-side only (HTTP calls to facilitator, no crypto deps)
|
|
44
44
|
// ---------------------------------------------------------------------------
|
|
45
45
|
import { HTTPFacilitatorClient, x402ResourceServer } from "@x402/core/server";
|
|
46
|
+
import { registerExactEvmScheme } from "@x402/evm/exact/server";
|
|
46
47
|
import type {
|
|
47
48
|
PaymentRequirements,
|
|
48
49
|
PaymentPayload,
|
|
@@ -204,6 +205,7 @@ export function createAgentSpend(options: AgentSpendOptions): AgentSpend {
|
|
|
204
205
|
options.crypto?.facilitatorUrl ?? "https://x402.org/facilitator";
|
|
205
206
|
facilitator = new HTTPFacilitatorClient({ url: facilitatorUrl });
|
|
206
207
|
resourceServer = new x402ResourceServer(facilitator);
|
|
208
|
+
registerExactEvmScheme(resourceServer);
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
// -------------------------------------------------------------------
|
|
@@ -385,7 +387,7 @@ export function createAgentSpend(options: AgentSpendOptions): AgentSpend {
|
|
|
385
387
|
_body: unknown,
|
|
386
388
|
_opts: PaywallOptions
|
|
387
389
|
): Promise<Response | void> {
|
|
388
|
-
if (!
|
|
390
|
+
if (!resourceServer) {
|
|
389
391
|
return c.json({ error: "Crypto payments not configured" }, 500);
|
|
390
392
|
}
|
|
391
393
|
|
|
@@ -421,8 +423,8 @@ export function createAgentSpend(options: AgentSpendOptions): AgentSpend {
|
|
|
421
423
|
extra: { name: "USD Coin", version: "2" }
|
|
422
424
|
};
|
|
423
425
|
|
|
424
|
-
// Verify payment via facilitator
|
|
425
|
-
const verifyResult: VerifyResponse = await
|
|
426
|
+
// Verify payment via resource server (delegates to facilitator)
|
|
427
|
+
const verifyResult: VerifyResponse = await resourceServer!.verifyPayment(
|
|
426
428
|
paymentPayload,
|
|
427
429
|
paymentRequirements
|
|
428
430
|
);
|
|
@@ -434,8 +436,8 @@ export function createAgentSpend(options: AgentSpendOptions): AgentSpend {
|
|
|
434
436
|
);
|
|
435
437
|
}
|
|
436
438
|
|
|
437
|
-
// Settle payment via facilitator
|
|
438
|
-
const settleResult: SettleResponse = await
|
|
439
|
+
// Settle payment via resource server (delegates to facilitator)
|
|
440
|
+
const settleResult: SettleResponse = await resourceServer!.settlePayment(
|
|
439
441
|
paymentPayload,
|
|
440
442
|
paymentRequirements
|
|
441
443
|
);
|