@parallel-protocol/x402 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -209,7 +209,7 @@ For the four natively supported networks, `acceptedTokens` defaults to `[USDp, U
209
209
 
210
210
  | Network | USDp | USDC | sUSDp |
211
211
  |---------|------|------|-------|
212
- | `ethereum` | `0x9B3a8f7CEC208e247d97dEE13313690977e24459` | `0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48` | `0x0d45b129dc868963025Db79A9074EA9c9e32Cae4` |
212
+ | `ethereum` | `0x9B3a8f7CEC208e247d97dEE13313690977e24459` | `0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48` | `0xd3a452B305C8285c0Dd7b8537665c734d3D279eF` |
213
213
  | `base` | `0x76A9A0062ec6712b99B4f63bD2b4270185759dd5` | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` | `0x472eD57b376fE400259FB28e5C46eB53f0E3e7E7` |
214
214
  | `avalanche` | `0x9eE1963f05553eF838604Dd39403be21ceF26AA4` | `0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E` | `0x9d92c21205383651610f90722131655a5b8ed3e0` |
215
215
  | `hyperevm` | `0xBE65F0F410A72BeC163dC65d46c83699e957D588` | `0xb88339cb7199b77e23db6e890353e22632ba630f` | `0x9B3a8f7CEC208e247d97dEE13313690977e24459` |
@@ -245,7 +245,7 @@ var FacilitatorClient = class {
245
245
  var PARALLEL_TOKENS = {
246
246
  ethereum: {
247
247
  usdp: "0x9B3a8f7CEC208e247d97dEE13313690977e24459",
248
- susdp: "0x0d45b129dc868963025Db79A9074EA9c9e32Cae4",
248
+ susdp: "0xd3a452B305C8285c0Dd7b8537665c734d3D279eF",
249
249
  usdc: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
250
250
  frxUSD: "0xCAcd6fd266aF91b8AeD52aCCc382b4e165586E29",
251
251
  sfrxUSD: "0xcf62F905562626CfcDD2261162a51fd02Fc9c5b6",
@@ -326,14 +326,40 @@ function buildPaymentRequired(url, config, resolvedTokens) {
326
326
  accepts
327
327
  };
328
328
  }
329
- function buildFacilitatorRequirements(config, resolvedTokens) {
330
- const asset = resolvedTokens[0];
329
+ function decodePaymentPayload(header) {
330
+ try {
331
+ const parsed = JSON.parse(
332
+ Buffer.from(header, "base64").toString("utf8")
333
+ );
334
+ return typeof parsed === "object" && parsed !== null ? parsed : void 0;
335
+ } catch {
336
+ return void 0;
337
+ }
338
+ }
339
+ function deliveredToken(payload, chainTokens) {
340
+ if (payload.method === "depositWithAuthorization" || payload.payload?.depositAuthorization) {
341
+ return chainTokens?.susdp;
342
+ }
343
+ if (payload.method === "redeemWithAuthorization") return chainTokens?.usdp;
344
+ if (payload.swapParams?.tokenOut) return payload.swapParams.tokenOut;
345
+ if (payload.method === "partialRedeemWithAuthorization") {
346
+ return chainTokens?.usdp;
347
+ }
348
+ return payload.tokenIn ?? chainTokens?.usdp;
349
+ }
350
+ function resolveDeliveredAsset(header, config, resolvedTokens) {
351
+ const payload = decodePaymentPayload(header);
352
+ const target = payload ? deliveredToken(
353
+ payload,
354
+ PARALLEL_TOKENS[config.network]
355
+ ) : void 0;
356
+ const lower = target?.toLowerCase();
357
+ return resolvedTokens.find((token) => token.toLowerCase() === lower) ?? resolvedTokens[0];
358
+ }
359
+ function buildFacilitatorRequirements(config, asset) {
331
360
  const decimals = resolveDecimals(config, asset);
332
361
  return {
333
362
  maxAmountRequired: parsePrice(config.price, decimals).toString(),
334
- // Informational only: the facilitator validates the amount + the on-chain
335
- // payload (the paid token lives in the payload / swapParams), and ignores
336
- // `asset`. resolveAcceptedTokens guarantees at least one entry.
337
363
  asset,
338
364
  payTo: config.payTo,
339
365
  network: config.network
@@ -381,7 +407,7 @@ function createPaymentGate(config) {
381
407
  }
382
408
  const requirements = buildFacilitatorRequirements(
383
409
  routeConfig,
384
- resolvedTokens
410
+ resolveDeliveredAsset(paymentHeader, routeConfig, resolvedTokens)
385
411
  );
386
412
  try {
387
413
  await client.verify(paymentHeader, requirements);
@@ -247,7 +247,7 @@ var FacilitatorClient = class {
247
247
  var PARALLEL_TOKENS = {
248
248
  ethereum: {
249
249
  usdp: "0x9B3a8f7CEC208e247d97dEE13313690977e24459",
250
- susdp: "0x0d45b129dc868963025Db79A9074EA9c9e32Cae4",
250
+ susdp: "0xd3a452B305C8285c0Dd7b8537665c734d3D279eF",
251
251
  usdc: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
252
252
  frxUSD: "0xCAcd6fd266aF91b8AeD52aCCc382b4e165586E29",
253
253
  sfrxUSD: "0xcf62F905562626CfcDD2261162a51fd02Fc9c5b6",
@@ -328,14 +328,40 @@ function buildPaymentRequired(url, config, resolvedTokens) {
328
328
  accepts
329
329
  };
330
330
  }
331
- function buildFacilitatorRequirements(config, resolvedTokens) {
332
- const asset = resolvedTokens[0];
331
+ function decodePaymentPayload(header) {
332
+ try {
333
+ const parsed = JSON.parse(
334
+ Buffer.from(header, "base64").toString("utf8")
335
+ );
336
+ return typeof parsed === "object" && parsed !== null ? parsed : void 0;
337
+ } catch {
338
+ return void 0;
339
+ }
340
+ }
341
+ function deliveredToken(payload, chainTokens) {
342
+ if (payload.method === "depositWithAuthorization" || payload.payload?.depositAuthorization) {
343
+ return chainTokens?.susdp;
344
+ }
345
+ if (payload.method === "redeemWithAuthorization") return chainTokens?.usdp;
346
+ if (payload.swapParams?.tokenOut) return payload.swapParams.tokenOut;
347
+ if (payload.method === "partialRedeemWithAuthorization") {
348
+ return chainTokens?.usdp;
349
+ }
350
+ return payload.tokenIn ?? chainTokens?.usdp;
351
+ }
352
+ function resolveDeliveredAsset(header, config, resolvedTokens) {
353
+ const payload = decodePaymentPayload(header);
354
+ const target = payload ? deliveredToken(
355
+ payload,
356
+ PARALLEL_TOKENS[config.network]
357
+ ) : void 0;
358
+ const lower = target?.toLowerCase();
359
+ return resolvedTokens.find((token) => token.toLowerCase() === lower) ?? resolvedTokens[0];
360
+ }
361
+ function buildFacilitatorRequirements(config, asset) {
333
362
  const decimals = resolveDecimals(config, asset);
334
363
  return {
335
364
  maxAmountRequired: parsePrice(config.price, decimals).toString(),
336
- // Informational only: the facilitator validates the amount + the on-chain
337
- // payload (the paid token lives in the payload / swapParams), and ignores
338
- // `asset`. resolveAcceptedTokens guarantees at least one entry.
339
365
  asset,
340
366
  payTo: config.payTo,
341
367
  network: config.network
@@ -383,7 +409,7 @@ function createPaymentGate(config) {
383
409
  }
384
410
  const requirements = buildFacilitatorRequirements(
385
411
  routeConfig,
386
- resolvedTokens
412
+ resolveDeliveredAsset(paymentHeader, routeConfig, resolvedTokens)
387
413
  );
388
414
  try {
389
415
  await client.verify(paymentHeader, requirements);
package/dist/express.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkXUNNMCO5_cjs = require('./chunk-XUNNMCO5.cjs');
4
- var chunkW3SMR5LQ_cjs = require('./chunk-W3SMR5LQ.cjs');
4
+ var chunkKQPIZ6SZ_cjs = require('./chunk-KQPIZ6SZ.cjs');
5
5
 
6
6
  // src/express/adapter.ts
7
7
  var TIMEOUT_BODY = JSON.stringify({
@@ -113,7 +113,7 @@ var ExpressAdapter = class {
113
113
 
114
114
  // src/express/index.ts
115
115
  function paymentMiddleware(config) {
116
- const middleware = chunkW3SMR5LQ_cjs.createPaymentMiddleware(config);
116
+ const middleware = chunkKQPIZ6SZ_cjs.createPaymentMiddleware(config);
117
117
  return async (req, res, next) => {
118
118
  const result = await middleware(new ExpressAdapter(req, res, next));
119
119
  if ("pass" in result) {
package/dist/express.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { raceTimeout, HANDLER_TIMEOUT } from './chunk-2UEAVMCH.js';
2
- import { createPaymentMiddleware } from './chunk-FDQULXKG.js';
2
+ import { createPaymentMiddleware } from './chunk-75GLDK7L.js';
3
3
 
4
4
  // src/express/adapter.ts
5
5
  var TIMEOUT_BODY = JSON.stringify({
package/dist/fastify.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkW3SMR5LQ_cjs = require('./chunk-W3SMR5LQ.cjs');
3
+ var chunkKQPIZ6SZ_cjs = require('./chunk-KQPIZ6SZ.cjs');
4
4
  var fp = require('fastify-plugin');
5
5
 
6
6
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -31,7 +31,7 @@ var FastifyAdapter = class {
31
31
  // src/fastify/index.ts
32
32
  function paymentMiddleware(config) {
33
33
  return fp__default.default(async (fastify) => {
34
- const gate = chunkW3SMR5LQ_cjs.createPaymentGate(config);
34
+ const gate = chunkKQPIZ6SZ_cjs.createPaymentGate(config);
35
35
  const settleMap = /* @__PURE__ */ new WeakMap();
36
36
  fastify.addHook("onRequest", async (req, reply) => {
37
37
  const gateResult = await gate(new FastifyAdapter(req));
@@ -54,7 +54,7 @@ function paymentMiddleware(config) {
54
54
  try {
55
55
  const settleResponse = await settle();
56
56
  if (settleResponse.success) {
57
- reply.header("payment-response", chunkW3SMR5LQ_cjs.encodeBase64(settleResponse));
57
+ reply.header("payment-response", chunkKQPIZ6SZ_cjs.encodeBase64(settleResponse));
58
58
  reply.header("access-control-expose-headers", "payment-response");
59
59
  settled = true;
60
60
  }
package/dist/fastify.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createPaymentGate, encodeBase64 } from './chunk-FDQULXKG.js';
1
+ import { createPaymentGate, encodeBase64 } from './chunk-75GLDK7L.js';
2
2
  import fp from 'fastify-plugin';
3
3
 
4
4
  // src/fastify/adapter.ts
package/dist/hono.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkXUNNMCO5_cjs = require('./chunk-XUNNMCO5.cjs');
4
- var chunkW3SMR5LQ_cjs = require('./chunk-W3SMR5LQ.cjs');
4
+ var chunkKQPIZ6SZ_cjs = require('./chunk-KQPIZ6SZ.cjs');
5
5
 
6
6
  // src/hono/adapter.ts
7
7
  var TIMEOUT_BODY = JSON.stringify({
@@ -58,7 +58,7 @@ var HonoAdapter = class {
58
58
 
59
59
  // src/hono/index.ts
60
60
  function paymentMiddleware(config) {
61
- const middleware = chunkW3SMR5LQ_cjs.createPaymentMiddleware(config);
61
+ const middleware = chunkKQPIZ6SZ_cjs.createPaymentMiddleware(config);
62
62
  return async (c, next) => {
63
63
  const result = await middleware(new HonoAdapter(c, next));
64
64
  if ("pass" in result) {
package/dist/hono.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { raceTimeout, HANDLER_TIMEOUT } from './chunk-2UEAVMCH.js';
2
- import { createPaymentMiddleware } from './chunk-FDQULXKG.js';
2
+ import { createPaymentMiddleware } from './chunk-75GLDK7L.js';
3
3
 
4
4
  // src/hono/adapter.ts
5
5
  var TIMEOUT_BODY = JSON.stringify({
package/dist/index.cjs CHANGED
@@ -1,54 +1,54 @@
1
1
  'use strict';
2
2
 
3
- var chunkW3SMR5LQ_cjs = require('./chunk-W3SMR5LQ.cjs');
3
+ var chunkKQPIZ6SZ_cjs = require('./chunk-KQPIZ6SZ.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "FacilitatorClient", {
8
8
  enumerable: true,
9
- get: function () { return chunkW3SMR5LQ_cjs.FacilitatorClient; }
9
+ get: function () { return chunkKQPIZ6SZ_cjs.FacilitatorClient; }
10
10
  });
11
11
  Object.defineProperty(exports, "PARALLEL_TOKENS", {
12
12
  enumerable: true,
13
- get: function () { return chunkW3SMR5LQ_cjs.PARALLEL_TOKENS; }
13
+ get: function () { return chunkKQPIZ6SZ_cjs.PARALLEL_TOKENS; }
14
14
  });
15
15
  Object.defineProperty(exports, "X402ConfigError", {
16
16
  enumerable: true,
17
- get: function () { return chunkW3SMR5LQ_cjs.X402ConfigError; }
17
+ get: function () { return chunkKQPIZ6SZ_cjs.X402ConfigError; }
18
18
  });
19
19
  Object.defineProperty(exports, "X402RuntimeError", {
20
20
  enumerable: true,
21
- get: function () { return chunkW3SMR5LQ_cjs.X402RuntimeError; }
21
+ get: function () { return chunkKQPIZ6SZ_cjs.X402RuntimeError; }
22
22
  });
23
23
  Object.defineProperty(exports, "X402_ERROR_CODES", {
24
24
  enumerable: true,
25
- get: function () { return chunkW3SMR5LQ_cjs.X402_ERROR_CODES; }
25
+ get: function () { return chunkKQPIZ6SZ_cjs.X402_ERROR_CODES; }
26
26
  });
27
27
  Object.defineProperty(exports, "createPaymentGate", {
28
28
  enumerable: true,
29
- get: function () { return chunkW3SMR5LQ_cjs.createPaymentGate; }
29
+ get: function () { return chunkKQPIZ6SZ_cjs.createPaymentGate; }
30
30
  });
31
31
  Object.defineProperty(exports, "createPaymentMiddleware", {
32
32
  enumerable: true,
33
- get: function () { return chunkW3SMR5LQ_cjs.createPaymentMiddleware; }
33
+ get: function () { return chunkKQPIZ6SZ_cjs.createPaymentMiddleware; }
34
34
  });
35
35
  Object.defineProperty(exports, "encodeBase64", {
36
36
  enumerable: true,
37
- get: function () { return chunkW3SMR5LQ_cjs.encodeBase64; }
37
+ get: function () { return chunkKQPIZ6SZ_cjs.encodeBase64; }
38
38
  });
39
39
  Object.defineProperty(exports, "getDefaultAcceptedTokens", {
40
40
  enumerable: true,
41
- get: function () { return chunkW3SMR5LQ_cjs.getDefaultAcceptedTokens; }
41
+ get: function () { return chunkKQPIZ6SZ_cjs.getDefaultAcceptedTokens; }
42
42
  });
43
43
  Object.defineProperty(exports, "parsePrice", {
44
44
  enumerable: true,
45
- get: function () { return chunkW3SMR5LQ_cjs.parsePrice; }
45
+ get: function () { return chunkKQPIZ6SZ_cjs.parsePrice; }
46
46
  });
47
47
  Object.defineProperty(exports, "toEip155Network", {
48
48
  enumerable: true,
49
- get: function () { return chunkW3SMR5LQ_cjs.toEip155Network; }
49
+ get: function () { return chunkKQPIZ6SZ_cjs.toEip155Network; }
50
50
  });
51
51
  Object.defineProperty(exports, "validateAddress", {
52
52
  enumerable: true,
53
- get: function () { return chunkW3SMR5LQ_cjs.validateAddress; }
53
+ get: function () { return chunkKQPIZ6SZ_cjs.validateAddress; }
54
54
  });
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { FacilitatorClient, PARALLEL_TOKENS, X402ConfigError, X402RuntimeError, X402_ERROR_CODES, createPaymentGate, createPaymentMiddleware, encodeBase64, getDefaultAcceptedTokens, parsePrice, toEip155Network, validateAddress } from './chunk-FDQULXKG.js';
1
+ export { FacilitatorClient, PARALLEL_TOKENS, X402ConfigError, X402RuntimeError, X402_ERROR_CODES, createPaymentGate, createPaymentMiddleware, encodeBase64, getDefaultAcceptedTokens, parsePrice, toEip155Network, validateAddress } from './chunk-75GLDK7L.js';
package/dist/next.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkXUNNMCO5_cjs = require('./chunk-XUNNMCO5.cjs');
4
- var chunkW3SMR5LQ_cjs = require('./chunk-W3SMR5LQ.cjs');
4
+ var chunkKQPIZ6SZ_cjs = require('./chunk-KQPIZ6SZ.cjs');
5
5
  var server = require('next/server');
6
6
 
7
7
  // src/next/adapter.ts
@@ -26,7 +26,7 @@ var NextAdapter = class {
26
26
 
27
27
  // src/next/index.ts
28
28
  function withPayment(config, handler) {
29
- const gate = chunkW3SMR5LQ_cjs.createPaymentGate(config);
29
+ const gate = chunkKQPIZ6SZ_cjs.createPaymentGate(config);
30
30
  return async (req) => {
31
31
  const gateResult = await gate(new NextAdapter(req));
32
32
  if (gateResult.type === "pass") {
@@ -56,7 +56,7 @@ function withPayment(config, handler) {
56
56
  const settleResponse = await gateResult.settle();
57
57
  if (settleResponse.success) {
58
58
  const headers = new Headers(response.headers);
59
- headers.set("payment-response", chunkW3SMR5LQ_cjs.encodeBase64(settleResponse));
59
+ headers.set("payment-response", chunkKQPIZ6SZ_cjs.encodeBase64(settleResponse));
60
60
  headers.set("access-control-expose-headers", "payment-response");
61
61
  return new server.NextResponse(response.body, {
62
62
  status: response.status,
package/dist/next.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { raceTimeout, HANDLER_TIMEOUT } from './chunk-2UEAVMCH.js';
2
- import { createPaymentGate, encodeBase64 } from './chunk-FDQULXKG.js';
2
+ import { createPaymentGate, encodeBase64 } from './chunk-75GLDK7L.js';
3
3
  import { NextResponse } from 'next/server';
4
4
 
5
5
  // src/next/adapter.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parallel-protocol/x402",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Parallel Protocol x402 payment middleware — Express, Next.js, Fastify, Hono",
5
5
  "author": "Parallel Protocol <contact@parallel.best>",
6
6
  "repository": {
@@ -123,7 +123,7 @@
123
123
  "vitest": "^4.0.14"
124
124
  },
125
125
  "dependencies": {
126
- "@parallel-protocol/chains": "^0.2.0",
126
+ "@parallel-protocol/chains": "^0.2.1",
127
127
  "fastify-plugin": "^6.0.0",
128
128
  "zod": "^4.4.3"
129
129
  },