@parallel-protocol/x402 0.8.2 → 0.8.3
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 +21 -12
- package/dist/{chunk-KTBFF5HI.js → chunk-G7HSURPM.js} +8 -1
- package/dist/{chunk-MXGS3HMS.cjs → chunk-TH77IB3T.cjs} +7 -0
- package/dist/express.cjs +5 -5
- package/dist/express.js +1 -1
- package/dist/fastify.cjs +11 -11
- package/dist/fastify.js +1 -1
- package/dist/hono.cjs +6 -6
- package/dist/hono.js +1 -1
- package/dist/index.cjs +15 -15
- package/dist/index.js +1 -1
- package/dist/next.cjs +13 -13
- package/dist/next.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -222,7 +222,7 @@ For the four natively supported networks, `acceptedTokens` defaults to `[USDp, U
|
|
|
222
222
|
| `avalanche` | `0x9eE1963f05553eF838604Dd39403be21ceF26AA4` | `0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E` | `0x9d92c21205383651610f90722131655a5b8ed3e0` |
|
|
223
223
|
| `hyperevm` | `0xBE65F0F410A72BeC163dC65d46c83699e957D588` | `0xb88339cb7199b77e23db6e890353e22632ba630f` | `0x9B3a8f7CEC208e247d97dEE13313690977e24459` |
|
|
224
224
|
|
|
225
|
-
|
|
225
|
+
A route on any other chain of the Parallel catalog, such as Sonic, raises `X402ConfigError` at construction.
|
|
226
226
|
|
|
227
227
|
You can also import the token list directly:
|
|
228
228
|
|
|
@@ -255,7 +255,7 @@ routes: {
|
|
|
255
255
|
}
|
|
256
256
|
```
|
|
257
257
|
|
|
258
|
-
**Accepting Parallelizer collateral payments:** Each supported network exposes additional collateral tokens whitelisted in the Parallelizer contract. They are available in `PARALLEL_TOKENS` but excluded from the defaults. Add them to `acceptedTokens` to
|
|
258
|
+
**Accepting Parallelizer collateral payments:** Each supported network exposes additional collateral tokens whitelisted in the Parallelizer contract. They are available in `PARALLEL_TOKENS` but excluded from the defaults. Add them to `acceptedTokens` to receive them: the agent pays in USDp or sUSDp, and the Parallelizer swaps to the collateral in the same settlement (routes D, K and L):
|
|
259
259
|
|
|
260
260
|
| Network | Token | Key | Yield-bearing |
|
|
261
261
|
|---------|-------|-----|---------------|
|
|
@@ -347,6 +347,10 @@ const header = Buffer.from(JSON.stringify(signedPayload)).toString("base64");
|
|
|
347
347
|
|
|
348
348
|
See [`@parallel-protocol/payment-core`](../payment-core) for EIP-3009 signing helpers.
|
|
349
349
|
|
|
350
|
+
### Request header: `x402-client`
|
|
351
|
+
|
|
352
|
+
A payer on `@parallel-protocol/x402-fetch` 0.5.0 or later also sends an `x402-client` header with the x402-fetch and CLI versions it runs, for example `x402-client: x402-fetch/0.5.0 cli/0.5.1`, and nothing else about the agent. Earlier releases and other clients send none. The middleware does not read it. Your handler can read it to spot a payer on outdated versions and tell it to update.
|
|
353
|
+
|
|
350
354
|
### 200 response: `payment-response`
|
|
351
355
|
|
|
352
356
|
On success, the middleware sets a `payment-response` header with a base64-encoded settlement confirmation:
|
|
@@ -545,9 +549,9 @@ The facilitator supports 13 settlement routes. The route is selected automatical
|
|
|
545
549
|
| **B** | `swapExactOutputWithAuthorization` | USDp | USDC (exact) | ~120K | Parallelizer swaps agent's USDp → exact USDC for merchant |
|
|
546
550
|
| **C** | `depositWithAuthorization` | USDp | sUSDp | ~110K | Agent's USDp deposited into the savings vault, the merchant receives sUSDp shares |
|
|
547
551
|
| **D** | `swapExactOutputWithAuthorization` | USDp | non-USDC backing collateral (exact) | ~120K | Same as B but for other Parallelizer collaterals |
|
|
548
|
-
| **E** | `swapExactInputWithAuthorization` | USDC
|
|
549
|
-
| **F** | `transferWithAuthorization` | USDC
|
|
550
|
-
| **G** | `swapExactInputWithAuthorization` | USDC
|
|
552
|
+
| **E** | `swapExactInputWithAuthorization` | USDC (exact), on Base and Avalanche | USDp (min) | ~120K | Agent pays an exact amount, the Parallelizer delivers at least the minimum USDp to the merchant |
|
|
553
|
+
| **F** | `transferWithAuthorization` | USDC | USDC | ~65K | Direct USDC transfer |
|
|
554
|
+
| **G** | `swapExactInputWithAuthorization` | USDC (exact), on Base and Avalanche | sUSDp | ~200K | The USDC is swapped to USDp, then the USDp is deposited as sUSDp for the merchant (atomic multicall3) |
|
|
551
555
|
| **H** | `redeemWithAuthorization` | sUSDp shares | USDp | ~130K | Agent burns sUSDp shares; merchant receives USDp assets |
|
|
552
556
|
| **I** | `redeemWithAuthorization` + `swapExactOutputWithAuthorization` | sUSDp | USDC (exact) | ~180K | Agent redeems sUSDp → USDp, then swaps USDp → exact USDC for merchant (atomic multicall3) |
|
|
553
557
|
| **J** | `transferWithAuthorization` | sUSDp | sUSDp | ~65K | Direct sUSDp share transfer |
|
|
@@ -557,9 +561,10 @@ The facilitator supports 13 settlement routes. The route is selected automatical
|
|
|
557
561
|
|
|
558
562
|
**Chain requirements:**
|
|
559
563
|
- Routes B, D, E, G, I, K, L require the **Parallelizer** to be deployed on the target chain (Ethereum, Base, Avalanche, HyperEVM).
|
|
560
|
-
- Routes B and I swap to USDC, so they need USDC among the chain's collaterals, which is the case on Base and Avalanche.
|
|
564
|
+
- Routes B and I swap to USDC, and routes E and G swap from it, so they need USDC among the chain's collaterals, which is the case on Base and Avalanche.
|
|
561
565
|
- Routes C, G, H, I, J, K, L require **sUSDp** (savings module) to be deployed on the target chain.
|
|
562
|
-
-
|
|
566
|
+
- Agents pay with USDp, sUSDp or the chain's USDC. Route F takes the chain's USDC, routes E and G the chain's USDC where it is a collateral (Base and Avalanche). On these three routes any other `tokenIn` is refused at verify and at settle with `PAYMENT_METHOD_NOT_SUPPORTED`, before the signature is checked.
|
|
567
|
+
- The facilitator settles on Ethereum, Base, Avalanche and HyperEVM. A payment on another chain is refused at verify and at settle with `NETWORK_MISMATCH`.
|
|
563
568
|
- Route U needs the escrow contract, deployed on Base only. A metered payment on another chain is refused at verify with `PAYMENT_METHOD_NOT_SUPPORTED`.
|
|
564
569
|
- Gas sponsorship is decided by the facilitator per payment and reported as `gasSponsored` in the settlement receipt.
|
|
565
570
|
- The facilitator's `GET /capabilities?chain=<slug>` lists the routes available on a chain right now, with the gas estimates above and the burn fees.
|
|
@@ -779,7 +784,7 @@ What the middleware answers on a paid route instead of the handler's response:
|
|
|
779
784
|
|
|
780
785
|
| Error class | When |
|
|
781
786
|
|-------------|------|
|
|
782
|
-
| `X402ConfigError` | Invalid config at construction, the message naming the first field at fault: a bad `payTo`, a facilitator URL that is neither https nor plain http on `localhost`, `127.0.0.1` or `[::1]`, empty `routes`, a malformed or non-positive `price`, a `meter` on a route that is not `upto`, or an `upto` route with `maxTimeoutSeconds` above 3600 or a token other than USDp. Then, on a request to a route: an unknown network with no `acceptedTokens`, an accepted token whose decimals are neither in the catalog nor set via `decimals`, a price finer than the token's precision, or a price function that throws or returns something that is not a price |
|
|
787
|
+
| `X402ConfigError` | Invalid config at construction, the message naming the first field at fault: a bad `payTo`, a facilitator URL that is neither https nor plain http on `localhost`, `127.0.0.1` or `[::1]`, empty `routes`, a `network` of the catalog other than `ethereum`, `base`, `avalanche` or `hyperevm`, a malformed or non-positive `price`, a `meter` on a route that is not `upto`, or an `upto` route with `maxTimeoutSeconds` above 3600 or a token other than USDp. Then, on a request to a route: an unknown network with no `acceptedTokens`, an accepted token whose decimals are neither in the catalog nor set via `decimals`, a price finer than the token's precision, or a price function that throws or returns something that is not a price |
|
|
783
788
|
| `X402RuntimeError` | Runtime failure; `.code` is one of the SDK codes below, or a facilitator error code propagated verbatim (see next table) |
|
|
784
789
|
| `X402PriceRejectedError` | Thrown by a price function to refuse a request before anything is invoiced; the client gets `.status` (400 by default) with `{ error: .code, message }`. `isPriceRejection(err)` recognises one by shape. |
|
|
785
790
|
|
|
@@ -833,6 +838,8 @@ When the facilitator refuses a payment at verify, its code is forwarded as the `
|
|
|
833
838
|
| `PAYMENT_METHOD_NOT_SUPPORTED` | 400 | No route for this method or token on this chain, including a metered payment on a chain without the escrow | Pay with another method or token |
|
|
834
839
|
| `COLLATERAL_NOT_SUPPORTED` | 400 | The swap delivers a token that is not a collateral of the chain | Pay for another of the `accepts` assets: the merchant lists one the facilitator does not deliver |
|
|
835
840
|
| `RATE_LIMIT_EXCEEDED` | 429 | The payer passed 1,000 verifies in the current UTC hour | Pay again after `Retry-After`, which points to the next hour |
|
|
841
|
+
| `PARALLELIZER_PAUSED` | 503 | The Parallelizer has closed the swap the payment needs, or its state could not be read. Nothing was taken | Pay with another token, or pay again later |
|
|
842
|
+
| `SAVINGS_PAUSED` | 503 | The sUSDp savings vault the payment deposits into or redeems from is paused, or its state could not be read. Nothing was taken | Pay with another token, or pay again later |
|
|
836
843
|
| `SERVICE_UNAVAILABLE` | 503 | The facilitator could not read the chain or its own store | Pay again after a short wait |
|
|
837
844
|
|
|
838
845
|
An `error` that is not a code (capitals, digits and underscores) is not forwarded: the 402 carries `error: "FACILITATOR_INVALID_RESPONSE"` with the facilitator's message instead. The facilitator answers this way with `Bad Request` to a payment payload that does not match its request schema, and with `Too Many Requests` from its per-IP limit (see [Rate limits](#rate-limits)).
|
|
@@ -844,18 +851,20 @@ When the facilitator refuses at settle, the 402 body is `{ error: "PAYMENT_SETTL
|
|
|
844
851
|
| `INSUFFICIENT_BALANCE` | 402 | The payer no longer holds the signed amount | Fund the wallet, sign a new payment |
|
|
845
852
|
| `AUTHORIZATION_USED` | 409 | The authorization is already consumed or cancelled on-chain. It may have paid the merchant | Do not sign another payment before checking with the merchant |
|
|
846
853
|
| `PAYMENT_EXPIRED` | 402 | The authorization expired before settlement | Sign a new payment |
|
|
847
|
-
| `PAYMENT_NOT_VERIFIED` | 402 | No verified payment for this authorization, or an earlier settle of it failed. The merchant may have been paid, or may still be | Do not sign another payment before checking with the merchant |
|
|
854
|
+
| `PAYMENT_NOT_VERIFIED` | 402 | No verified payment for this authorization, or an earlier settle of it failed. After `AUTHORIZATION_USED`, `RECEIPT_UNAVAILABLE` or `SUBMISSION_FAILED`, a repeated settle gets that code again instead. The merchant may have been paid, or may still be | Do not sign another payment before checking with the merchant |
|
|
848
855
|
| `SETTLE_IN_PROGRESS` | 409 | Another settle of the same payment is still running | Do not sign another payment before checking with the merchant |
|
|
849
856
|
| `SETTLE_TOKEN_INVALID`, `SETTLE_TOKEN_REQUIRED` | 403 | The merchant did not present the settle token verify issued: a merchant client issue, not the payer's, and nothing was settled | Do not sign another payment before checking with the merchant |
|
|
850
857
|
| `RELAYER_UNAVAILABLE` | 503 | The facilitator is temporarily unable to settle. The payment was not taken, and the facilitator will not settle it | Retry later with a new payment, after `Retry-After` when given |
|
|
851
|
-
| `PARALLELIZER_PAUSED`, `SERVICE_UNAVAILABLE` | 503 | The facilitator or the chain is temporarily unable to settle. This settle sent nothing, but the payment may still settle until its authorization expires, and an earlier attempt may already have settled it | Do not sign another payment before checking with the merchant |
|
|
858
|
+
| `PARALLELIZER_PAUSED`, `SAVINGS_PAUSED`, `SERVICE_UNAVAILABLE` | 503 | The swap or the savings vault the payment needs is paused, or its state could not be read, or the facilitator or the chain is temporarily unable to settle. This settle sent nothing, but the payment may still settle until its authorization expires, and an earlier attempt may already have settled it | Do not sign another payment before checking with the merchant |
|
|
852
859
|
| `TX_REVERTED` | 500 | The transaction reverted for a reason the facilitator could not attribute | Sign a new payment |
|
|
853
|
-
| `
|
|
860
|
+
| `SWAP_PRICE_MOVED` | 402 | The Parallelizer refused the swap: its price or fee moved, between signing and settlement, beyond the margin signed with the payment. The payment was not taken, and the facilitator will not settle it | Sign a new payment |
|
|
861
|
+
| `SWAP_UNAVAILABLE` | 503 | The Parallelizer refused the swap because it cannot make it now: the swap closed since the facilitator checked it, a cap or a maximum fee is reached, the amount exceeds what it can release, or a price feed is stale. The payment was not taken, and the facilitator will not settle it | Pay with another token, or later with a new payment |
|
|
862
|
+
| `SUBMISSION_FAILED` | 500 | The settle failed. When the message says the outcome is unknown, a transaction may have been sent, or the facilitator could not read whether the authorization was used, and the payment may have settled or may still settle | Do not sign another payment before checking with the merchant. x402-fetch says so for this reason whatever the message. A client that reads the 402 itself may sign a new payment when the message says no transaction was submitted |
|
|
854
863
|
| `RECEIPT_UNAVAILABLE` | 500 | The transaction was sent but its confirmation could not be read | Do not sign another payment before checking with the merchant |
|
|
855
864
|
| `INVALID_PAYLOAD`, `NETWORK_MISMATCH`, `PAYMENT_METHOD_NOT_SUPPORTED` | 400 | The settle request does not match the payment that was verified, or a metered amount is missing, malformed or above the signed cap. Nothing was settled | Sign a new payment |
|
|
856
865
|
| `INSUFFICIENT_AMOUNT` | 402 | A metered amount of zero, or an authorization for zero. Nothing was settled | Sign a new payment |
|
|
857
866
|
|
|
858
|
-
Reasons from this SDK: `SETTLE_TIMEOUT`, `FACILITATOR_UNAVAILABLE` and `FACILITATOR_INVALID_RESPONSE` (the settle may still have gone through, do not pay again before checking with the merchant), `AMOUNT_MISMATCH` (the facilitator settled another amount than the one asked, money moved, the response was not served, do not pay again before checking), `UNKNOWN` (anything that is not a code, such as the `Too Many Requests` of the facilitator's per-IP limit: the payment may have settled, do not pay again before checking). For `SETTLE_IN_PROGRESS`, `RECEIPT_UNAVAILABLE`, `SETTLE_TOKEN_INVALID` and `SETTLE_TOKEN_REQUIRED` the message is this SDK's as well, since the facilitator's text addresses the merchant. The message is this SDK's too for `AUTHORIZATION_USED`, `PAYMENT_NOT_VERIFIED`, `PARALLELIZER_PAUSED` and `SERVICE_UNAVAILABLE`: the payment may have settled or may still settle, so the message tells the agent to check with the merchant before paying again.
|
|
867
|
+
Reasons from this SDK: `SETTLE_TIMEOUT`, `FACILITATOR_UNAVAILABLE` and `FACILITATOR_INVALID_RESPONSE` (the settle may still have gone through, do not pay again before checking with the merchant), `AMOUNT_MISMATCH` (the facilitator settled another amount than the one asked, money moved, the response was not served, do not pay again before checking), `UNKNOWN` (anything that is not a code, such as the `Too Many Requests` of the facilitator's per-IP limit: the payment may have settled, do not pay again before checking). For `SETTLE_IN_PROGRESS`, `RECEIPT_UNAVAILABLE`, `SETTLE_TOKEN_INVALID` and `SETTLE_TOKEN_REQUIRED` the message is this SDK's as well, since the facilitator's text addresses the merchant. The message is this SDK's too for `AUTHORIZATION_USED`, `PAYMENT_NOT_VERIFIED`, `PARALLELIZER_PAUSED`, `SAVINGS_PAUSED` and `SERVICE_UNAVAILABLE`: the payment may have settled or may still settle, so the message tells the agent to check with the merchant before paying again.
|
|
859
868
|
|
|
860
869
|
`AMOUNT_MISMATCH` is also the one reason that points at the facilitator rather than at the request: it confirmed a settlement of another amount than the one the route asked for, so money moved. Alert on it, for example on 402 responses whose `reason` is `AMOUNT_MISMATCH`, rather than treating it as a routine refusal.
|
|
861
870
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { X402_ERROR_CODES, X402ConfigError, X402RuntimeError, isPriceRejection } from './chunk-QAECRSWF.js';
|
|
2
|
-
import { getTokenDecimals as getTokenDecimals$1 } from '@parallel-protocol/chains';
|
|
2
|
+
import { isKnownChain, isActiveParallelizerChain, ACTIVE_PARALLELIZER_CHAINS, getTokenDecimals as getTokenDecimals$1 } from '@parallel-protocol/chains';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
var PARALLEL_TOKENS = {
|
|
@@ -155,6 +155,12 @@ var routeConfigSchema = z.object({
|
|
|
155
155
|
"meter must be a function of the response"
|
|
156
156
|
).optional()
|
|
157
157
|
}).refine(
|
|
158
|
+
(route) => !isKnownChain(route.network) || isActiveParallelizerChain(route.network),
|
|
159
|
+
{
|
|
160
|
+
message: `network must be one of the chains the facilitator settles on: ${ACTIVE_PARALLELIZER_CHAINS.join(", ")}`,
|
|
161
|
+
path: ["network"]
|
|
162
|
+
}
|
|
163
|
+
).refine(
|
|
158
164
|
(route) => route.meter === void 0 || route.scheme === "upto",
|
|
159
165
|
"meter only applies to upto routes"
|
|
160
166
|
).refine(
|
|
@@ -788,6 +794,7 @@ var AGENT_MESSAGES = {
|
|
|
788
794
|
AUTHORIZATION_USED: "The payment's authorization was already consumed or cancelled on-chain. It may have paid the merchant: do not sign another payment for this request before checking with the merchant.",
|
|
789
795
|
PAYMENT_NOT_VERIFIED: "The facilitator holds no payment it can settle for this request. An earlier attempt may have paid the merchant, or may still settle: do not sign another payment for this request before checking with the merchant.",
|
|
790
796
|
PARALLELIZER_PAUSED: UNAVAILABLE_SETTLEMENT_MESSAGE,
|
|
797
|
+
SAVINGS_PAUSED: UNAVAILABLE_SETTLEMENT_MESSAGE,
|
|
791
798
|
SERVICE_UNAVAILABLE: UNAVAILABLE_SETTLEMENT_MESSAGE,
|
|
792
799
|
AMOUNT_MISMATCH: "The facilitator settled a different amount than this request asked for. The response was not served: do not sign another payment for this request before checking with the merchant.",
|
|
793
800
|
UNKNOWN: "The facilitator gave no reason for this failure, and the payment may have settled: do not sign another payment for this request before checking with the merchant."
|
|
@@ -157,6 +157,12 @@ var routeConfigSchema = zod.z.object({
|
|
|
157
157
|
"meter must be a function of the response"
|
|
158
158
|
).optional()
|
|
159
159
|
}).refine(
|
|
160
|
+
(route) => !chains.isKnownChain(route.network) || chains.isActiveParallelizerChain(route.network),
|
|
161
|
+
{
|
|
162
|
+
message: `network must be one of the chains the facilitator settles on: ${chains.ACTIVE_PARALLELIZER_CHAINS.join(", ")}`,
|
|
163
|
+
path: ["network"]
|
|
164
|
+
}
|
|
165
|
+
).refine(
|
|
160
166
|
(route) => route.meter === void 0 || route.scheme === "upto",
|
|
161
167
|
"meter only applies to upto routes"
|
|
162
168
|
).refine(
|
|
@@ -790,6 +796,7 @@ var AGENT_MESSAGES = {
|
|
|
790
796
|
AUTHORIZATION_USED: "The payment's authorization was already consumed or cancelled on-chain. It may have paid the merchant: do not sign another payment for this request before checking with the merchant.",
|
|
791
797
|
PAYMENT_NOT_VERIFIED: "The facilitator holds no payment it can settle for this request. An earlier attempt may have paid the merchant, or may still settle: do not sign another payment for this request before checking with the merchant.",
|
|
792
798
|
PARALLELIZER_PAUSED: UNAVAILABLE_SETTLEMENT_MESSAGE,
|
|
799
|
+
SAVINGS_PAUSED: UNAVAILABLE_SETTLEMENT_MESSAGE,
|
|
793
800
|
SERVICE_UNAVAILABLE: UNAVAILABLE_SETTLEMENT_MESSAGE,
|
|
794
801
|
AMOUNT_MISMATCH: "The facilitator settled a different amount than this request asked for. The response was not served: do not sign another payment for this request before checking with the merchant.",
|
|
795
802
|
UNKNOWN: "The facilitator gave no reason for this failure, and the payment may have settled: do not sign another payment for this request before checking with the merchant."
|
package/dist/express.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkTH77IB3T_cjs = require('./chunk-TH77IB3T.cjs');
|
|
4
4
|
require('./chunk-KZZY5LS6.cjs');
|
|
5
5
|
|
|
6
6
|
// src/express/adapter.ts
|
|
@@ -108,8 +108,8 @@ var ExpressAdapter = class {
|
|
|
108
108
|
return originalEnd(...args);
|
|
109
109
|
});
|
|
110
110
|
next();
|
|
111
|
-
const outcome = await
|
|
112
|
-
if (outcome ===
|
|
111
|
+
const outcome = await chunkTH77IB3T_cjs.raceTimeout(endPromise, options?.timeoutMs);
|
|
112
|
+
if (outcome === chunkTH77IB3T_cjs.HANDLER_TIMEOUT) {
|
|
113
113
|
discarded = true;
|
|
114
114
|
return {
|
|
115
115
|
status: 504,
|
|
@@ -146,7 +146,7 @@ var ExpressAdapter = class {
|
|
|
146
146
|
const chunk = chunkBytes(args);
|
|
147
147
|
if (chunk) bytes.push(chunk);
|
|
148
148
|
}
|
|
149
|
-
return
|
|
149
|
+
return chunkTH77IB3T_cjs.parseJsonBody(
|
|
150
150
|
contentType,
|
|
151
151
|
Buffer.concat(bytes).toString("utf8")
|
|
152
152
|
);
|
|
@@ -170,7 +170,7 @@ var ExpressAdapter = class {
|
|
|
170
170
|
|
|
171
171
|
// src/express/index.ts
|
|
172
172
|
function paymentMiddleware(config) {
|
|
173
|
-
const middleware =
|
|
173
|
+
const middleware = chunkTH77IB3T_cjs.createPaymentMiddleware(config);
|
|
174
174
|
return async (req, res, next) => {
|
|
175
175
|
const result = await middleware(new ExpressAdapter(req, res, next));
|
|
176
176
|
if ("pass" in result) {
|
package/dist/express.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { raceTimeout, HANDLER_TIMEOUT, parseJsonBody, createPaymentMiddleware } from './chunk-
|
|
1
|
+
import { raceTimeout, HANDLER_TIMEOUT, parseJsonBody, createPaymentMiddleware } from './chunk-G7HSURPM.js';
|
|
2
2
|
import './chunk-QAECRSWF.js';
|
|
3
3
|
|
|
4
4
|
// src/express/adapter.ts
|
package/dist/fastify.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkTH77IB3T_cjs = require('./chunk-TH77IB3T.cjs');
|
|
4
4
|
require('./chunk-KZZY5LS6.cjs');
|
|
5
5
|
var fp = require('fastify-plugin');
|
|
6
6
|
|
|
@@ -37,7 +37,7 @@ var FastifyAdapter = class {
|
|
|
37
37
|
// src/fastify/index.ts
|
|
38
38
|
function payloadJson(contentType, payload) {
|
|
39
39
|
const text = typeof payload === "string" ? payload : payload instanceof Uint8Array ? Buffer.from(payload).toString("utf8") : void 0;
|
|
40
|
-
return
|
|
40
|
+
return chunkTH77IB3T_cjs.parseJsonBody(contentType, text);
|
|
41
41
|
}
|
|
42
42
|
function refuse(reply, result) {
|
|
43
43
|
const json = JSON.stringify(result.body);
|
|
@@ -54,11 +54,11 @@ function headerValue(value) {
|
|
|
54
54
|
}
|
|
55
55
|
function paymentMiddleware(config) {
|
|
56
56
|
return fp__default.default(async (fastify) => {
|
|
57
|
-
const gate =
|
|
57
|
+
const gate = chunkTH77IB3T_cjs.createPaymentGate(config);
|
|
58
58
|
const verifiedMap = /* @__PURE__ */ new WeakMap();
|
|
59
59
|
const rawWriters = /* @__PURE__ */ new WeakMap();
|
|
60
60
|
const needsBody = (req) => {
|
|
61
|
-
const route =
|
|
61
|
+
const route = chunkTH77IB3T_cjs.matchRoute(
|
|
62
62
|
new FastifyAdapter(req).getPath(),
|
|
63
63
|
config.routes
|
|
64
64
|
);
|
|
@@ -111,29 +111,29 @@ function paymentMiddleware(config) {
|
|
|
111
111
|
if (!verified) return payload;
|
|
112
112
|
let raw;
|
|
113
113
|
if (verified.scheme === "upto") {
|
|
114
|
-
raw = headerValue(reply.getHeader(
|
|
115
|
-
reply.removeHeader(
|
|
114
|
+
raw = headerValue(reply.getHeader(chunkTH77IB3T_cjs.SETTLE_AMOUNT_HEADER));
|
|
115
|
+
reply.removeHeader(chunkTH77IB3T_cjs.SETTLE_AMOUNT_HEADER);
|
|
116
116
|
}
|
|
117
117
|
if (reply.statusCode < 200 || reply.statusCode >= 300) {
|
|
118
118
|
return payload;
|
|
119
119
|
}
|
|
120
120
|
let settleOptions;
|
|
121
121
|
if (verified.scheme === "upto") {
|
|
122
|
-
const resolved = await
|
|
122
|
+
const resolved = await chunkTH77IB3T_cjs.resolveCharge(verified, raw, {
|
|
123
123
|
status: reply.statusCode,
|
|
124
124
|
header: (name) => headerValue(reply.getHeader(name)),
|
|
125
125
|
body: async () => payloadJson(headerValue(reply.getHeader("content-type")), payload)
|
|
126
126
|
});
|
|
127
127
|
if (resolved.kind === "invalid") {
|
|
128
|
-
return refuse(reply,
|
|
128
|
+
return refuse(reply, chunkTH77IB3T_cjs.invalidSettleAmountResponse(resolved.reason));
|
|
129
129
|
}
|
|
130
130
|
if (resolved.kind === "skip") return payload;
|
|
131
131
|
settleOptions = { amount: resolved.amount };
|
|
132
132
|
}
|
|
133
|
-
const outcome = await
|
|
133
|
+
const outcome = await chunkTH77IB3T_cjs.settleVerified(verified, settleOptions);
|
|
134
134
|
if (!outcome.settled)
|
|
135
|
-
return refuse(reply,
|
|
136
|
-
reply.header("payment-response",
|
|
135
|
+
return refuse(reply, chunkTH77IB3T_cjs.settlementFailureResponse(outcome));
|
|
136
|
+
reply.header("payment-response", chunkTH77IB3T_cjs.encodeBase64(outcome.confirmation));
|
|
137
137
|
reply.header("access-control-expose-headers", "payment-response");
|
|
138
138
|
return payload;
|
|
139
139
|
});
|
package/dist/fastify.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createPaymentGate, SETTLE_AMOUNT_HEADER, resolveCharge, invalidSettleAmountResponse, settleVerified, settlementFailureResponse, encodeBase64, matchRoute, parseJsonBody } from './chunk-
|
|
1
|
+
import { createPaymentGate, SETTLE_AMOUNT_HEADER, resolveCharge, invalidSettleAmountResponse, settleVerified, settlementFailureResponse, encodeBase64, matchRoute, parseJsonBody } from './chunk-G7HSURPM.js';
|
|
2
2
|
import './chunk-QAECRSWF.js';
|
|
3
3
|
import fp from 'fastify-plugin';
|
|
4
4
|
|
package/dist/hono.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkTH77IB3T_cjs = require('./chunk-TH77IB3T.cjs');
|
|
4
4
|
require('./chunk-KZZY5LS6.cjs');
|
|
5
5
|
|
|
6
6
|
// src/hono/adapter.ts
|
|
@@ -30,7 +30,7 @@ var HonoAdapter = class {
|
|
|
30
30
|
// Hono caches the parsed body on the request, so the handler can still read
|
|
31
31
|
// it after the price function did.
|
|
32
32
|
async getBody() {
|
|
33
|
-
if (!
|
|
33
|
+
if (!chunkTH77IB3T_cjs.isJsonContentType(this.c.req.header("content-type"))) return void 0;
|
|
34
34
|
try {
|
|
35
35
|
return await this.c.req.json();
|
|
36
36
|
} catch {
|
|
@@ -38,8 +38,8 @@ var HonoAdapter = class {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
async runHandler(options) {
|
|
41
|
-
const outcome = await
|
|
42
|
-
if (outcome ===
|
|
41
|
+
const outcome = await chunkTH77IB3T_cjs.raceTimeout(this.next(), options?.timeoutMs);
|
|
42
|
+
if (outcome === chunkTH77IB3T_cjs.HANDLER_TIMEOUT) {
|
|
43
43
|
return {
|
|
44
44
|
status: 504,
|
|
45
45
|
setResponseHeader: () => {
|
|
@@ -64,7 +64,7 @@ var HonoAdapter = class {
|
|
|
64
64
|
getResponseHeader: (name) => res.headers.get(name) ?? void 0,
|
|
65
65
|
removeResponseHeader: (name) => res.headers.delete(name),
|
|
66
66
|
// Read from a clone: the response body streams once, to the client.
|
|
67
|
-
getResponseBody: () =>
|
|
67
|
+
getResponseBody: () => chunkTH77IB3T_cjs.jsonFromResponse(res),
|
|
68
68
|
sendResponse: () => {
|
|
69
69
|
},
|
|
70
70
|
// The response is replaced: release its body (and whatever upstream
|
|
@@ -79,7 +79,7 @@ var HonoAdapter = class {
|
|
|
79
79
|
|
|
80
80
|
// src/hono/index.ts
|
|
81
81
|
function paymentMiddleware(config) {
|
|
82
|
-
const middleware =
|
|
82
|
+
const middleware = chunkTH77IB3T_cjs.createPaymentMiddleware(config);
|
|
83
83
|
return async (c, next) => {
|
|
84
84
|
const result = await middleware(new HonoAdapter(c, next));
|
|
85
85
|
if ("pass" in result) {
|
package/dist/hono.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isJsonContentType, raceTimeout, HANDLER_TIMEOUT, jsonFromResponse, createPaymentMiddleware } from './chunk-
|
|
1
|
+
import { isJsonContentType, raceTimeout, HANDLER_TIMEOUT, jsonFromResponse, createPaymentMiddleware } from './chunk-G7HSURPM.js';
|
|
2
2
|
import './chunk-QAECRSWF.js';
|
|
3
3
|
|
|
4
4
|
// src/hono/adapter.ts
|
package/dist/index.cjs
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkTH77IB3T_cjs = require('./chunk-TH77IB3T.cjs');
|
|
4
4
|
var chunkKZZY5LS6_cjs = require('./chunk-KZZY5LS6.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "FacilitatorClient", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkTH77IB3T_cjs.FacilitatorClient; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "PARALLEL_TOKENS", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkTH77IB3T_cjs.PARALLEL_TOKENS; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "SETTLE_AMOUNT_HEADER", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunkTH77IB3T_cjs.SETTLE_AMOUNT_HEADER; }
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "createPaymentGate", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
22
|
+
get: function () { return chunkTH77IB3T_cjs.createPaymentGate; }
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "createPaymentMiddleware", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
26
|
+
get: function () { return chunkTH77IB3T_cjs.createPaymentMiddleware; }
|
|
27
27
|
});
|
|
28
28
|
Object.defineProperty(exports, "encodeBase64", {
|
|
29
29
|
enumerable: true,
|
|
30
|
-
get: function () { return
|
|
30
|
+
get: function () { return chunkTH77IB3T_cjs.encodeBase64; }
|
|
31
31
|
});
|
|
32
32
|
Object.defineProperty(exports, "getDefaultAcceptedTokens", {
|
|
33
33
|
enumerable: true,
|
|
34
|
-
get: function () { return
|
|
34
|
+
get: function () { return chunkTH77IB3T_cjs.getDefaultAcceptedTokens; }
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "parsePrice", {
|
|
37
37
|
enumerable: true,
|
|
38
|
-
get: function () { return
|
|
38
|
+
get: function () { return chunkTH77IB3T_cjs.parsePrice; }
|
|
39
39
|
});
|
|
40
40
|
Object.defineProperty(exports, "resolveCharge", {
|
|
41
41
|
enumerable: true,
|
|
42
|
-
get: function () { return
|
|
42
|
+
get: function () { return chunkTH77IB3T_cjs.resolveCharge; }
|
|
43
43
|
});
|
|
44
44
|
Object.defineProperty(exports, "resolveSettleAmount", {
|
|
45
45
|
enumerable: true,
|
|
46
|
-
get: function () { return
|
|
46
|
+
get: function () { return chunkTH77IB3T_cjs.resolveSettleAmount; }
|
|
47
47
|
});
|
|
48
48
|
Object.defineProperty(exports, "settleVerified", {
|
|
49
49
|
enumerable: true,
|
|
50
|
-
get: function () { return
|
|
50
|
+
get: function () { return chunkTH77IB3T_cjs.settleVerified; }
|
|
51
51
|
});
|
|
52
52
|
Object.defineProperty(exports, "settlementFailureResponse", {
|
|
53
53
|
enumerable: true,
|
|
54
|
-
get: function () { return
|
|
54
|
+
get: function () { return chunkTH77IB3T_cjs.settlementFailureResponse; }
|
|
55
55
|
});
|
|
56
56
|
Object.defineProperty(exports, "toEip155Network", {
|
|
57
57
|
enumerable: true,
|
|
58
|
-
get: function () { return
|
|
58
|
+
get: function () { return chunkTH77IB3T_cjs.toEip155Network; }
|
|
59
59
|
});
|
|
60
60
|
Object.defineProperty(exports, "validateAddress", {
|
|
61
61
|
enumerable: true,
|
|
62
|
-
get: function () { return
|
|
62
|
+
get: function () { return chunkTH77IB3T_cjs.validateAddress; }
|
|
63
63
|
});
|
|
64
64
|
Object.defineProperty(exports, "X402ConfigError", {
|
|
65
65
|
enumerable: true,
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { FacilitatorClient, PARALLEL_TOKENS, SETTLE_AMOUNT_HEADER, createPaymentGate, createPaymentMiddleware, encodeBase64, getDefaultAcceptedTokens, parsePrice, resolveCharge, resolveSettleAmount, settleVerified, settlementFailureResponse, toEip155Network, validateAddress } from './chunk-
|
|
1
|
+
export { FacilitatorClient, PARALLEL_TOKENS, SETTLE_AMOUNT_HEADER, createPaymentGate, createPaymentMiddleware, encodeBase64, getDefaultAcceptedTokens, parsePrice, resolveCharge, resolveSettleAmount, settleVerified, settlementFailureResponse, toEip155Network, validateAddress } from './chunk-G7HSURPM.js';
|
|
2
2
|
export { X402ConfigError, X402PriceRejectedError, X402RuntimeError, X402_ERROR_CODES, isPriceRejection } from './chunk-QAECRSWF.js';
|
package/dist/next.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkTH77IB3T_cjs = require('./chunk-TH77IB3T.cjs');
|
|
4
4
|
require('./chunk-KZZY5LS6.cjs');
|
|
5
5
|
var server = require('next/server');
|
|
6
6
|
|
|
@@ -25,7 +25,7 @@ var NextAdapter = class {
|
|
|
25
25
|
// Read from a clone: a request body is a stream that can be consumed once,
|
|
26
26
|
// and the handler still needs the original.
|
|
27
27
|
async getBody() {
|
|
28
|
-
if (!
|
|
28
|
+
if (!chunkTH77IB3T_cjs.isJsonContentType(this.req.headers.get("content-type") ?? void 0))
|
|
29
29
|
return void 0;
|
|
30
30
|
try {
|
|
31
31
|
return await this.req.clone().json();
|
|
@@ -43,7 +43,7 @@ function fromResult(result) {
|
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
function withPayment(config, handler) {
|
|
46
|
-
const gate =
|
|
46
|
+
const gate = chunkTH77IB3T_cjs.createPaymentGate(config);
|
|
47
47
|
return async (req) => {
|
|
48
48
|
const gateResult = await gate(new NextAdapter(req));
|
|
49
49
|
if (gateResult.type === "pass") {
|
|
@@ -52,11 +52,11 @@ function withPayment(config, handler) {
|
|
|
52
52
|
if (gateResult.type === "error") return fromResult(gateResult.result);
|
|
53
53
|
let response;
|
|
54
54
|
try {
|
|
55
|
-
const outcome = await
|
|
55
|
+
const outcome = await chunkTH77IB3T_cjs.raceTimeout(
|
|
56
56
|
handler(req),
|
|
57
57
|
gateResult.handlerTimeoutMs
|
|
58
58
|
);
|
|
59
|
-
if (outcome ===
|
|
59
|
+
if (outcome === chunkTH77IB3T_cjs.HANDLER_TIMEOUT) {
|
|
60
60
|
return new server.NextResponse(null, { status: 504 });
|
|
61
61
|
}
|
|
62
62
|
response = outcome;
|
|
@@ -65,10 +65,10 @@ function withPayment(config, handler) {
|
|
|
65
65
|
}
|
|
66
66
|
let raw;
|
|
67
67
|
if (gateResult.scheme === "upto") {
|
|
68
|
-
raw = response.headers.get(
|
|
68
|
+
raw = response.headers.get(chunkTH77IB3T_cjs.SETTLE_AMOUNT_HEADER) ?? void 0;
|
|
69
69
|
if (raw !== void 0) {
|
|
70
70
|
const headers = new Headers(response.headers);
|
|
71
|
-
headers.delete(
|
|
71
|
+
headers.delete(chunkTH77IB3T_cjs.SETTLE_AMOUNT_HEADER);
|
|
72
72
|
response = new server.NextResponse(response.body, {
|
|
73
73
|
status: response.status,
|
|
74
74
|
headers
|
|
@@ -79,24 +79,24 @@ function withPayment(config, handler) {
|
|
|
79
79
|
let settleOptions;
|
|
80
80
|
if (gateResult.scheme === "upto") {
|
|
81
81
|
const handled = response;
|
|
82
|
-
const resolved = await
|
|
82
|
+
const resolved = await chunkTH77IB3T_cjs.resolveCharge(gateResult, raw, {
|
|
83
83
|
status: handled.status,
|
|
84
84
|
header: (name) => handled.headers.get(name) ?? void 0,
|
|
85
85
|
// Read from a clone: the body streams once, to the client.
|
|
86
|
-
body: () =>
|
|
86
|
+
body: () => chunkTH77IB3T_cjs.jsonFromResponse(handled)
|
|
87
87
|
});
|
|
88
88
|
if (resolved.kind === "invalid") {
|
|
89
89
|
handled.body?.cancel().catch(() => {
|
|
90
90
|
});
|
|
91
|
-
return fromResult(
|
|
91
|
+
return fromResult(chunkTH77IB3T_cjs.invalidSettleAmountResponse(resolved.reason));
|
|
92
92
|
}
|
|
93
93
|
if (resolved.kind === "skip") return response;
|
|
94
94
|
settleOptions = { amount: resolved.amount };
|
|
95
95
|
}
|
|
96
|
-
const outcome = await
|
|
96
|
+
const outcome = await chunkTH77IB3T_cjs.settleVerified(gateResult, settleOptions);
|
|
97
97
|
if (outcome.settled) {
|
|
98
98
|
const headers = new Headers(response.headers);
|
|
99
|
-
headers.set("payment-response",
|
|
99
|
+
headers.set("payment-response", chunkTH77IB3T_cjs.encodeBase64(outcome.confirmation));
|
|
100
100
|
headers.set("access-control-expose-headers", "payment-response");
|
|
101
101
|
return new server.NextResponse(response.body, {
|
|
102
102
|
status: response.status,
|
|
@@ -105,7 +105,7 @@ function withPayment(config, handler) {
|
|
|
105
105
|
}
|
|
106
106
|
response.body?.cancel().catch(() => {
|
|
107
107
|
});
|
|
108
|
-
return fromResult(
|
|
108
|
+
return fromResult(chunkTH77IB3T_cjs.settlementFailureResponse(outcome));
|
|
109
109
|
}
|
|
110
110
|
return response;
|
|
111
111
|
};
|
package/dist/next.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isJsonContentType, createPaymentGate, raceTimeout, HANDLER_TIMEOUT, SETTLE_AMOUNT_HEADER, resolveCharge, jsonFromResponse, invalidSettleAmountResponse, settleVerified, encodeBase64, settlementFailureResponse } from './chunk-
|
|
1
|
+
import { isJsonContentType, createPaymentGate, raceTimeout, HANDLER_TIMEOUT, SETTLE_AMOUNT_HEADER, resolveCharge, jsonFromResponse, invalidSettleAmountResponse, settleVerified, encodeBase64, settlementFailureResponse } from './chunk-G7HSURPM.js';
|
|
2
2
|
import './chunk-QAECRSWF.js';
|
|
3
3
|
import { NextResponse } from 'next/server';
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parallel-protocol/x402",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "Parallel Protocol x402 payment middleware — Express, Next.js, Fastify, Hono",
|
|
5
5
|
"author": "Parallel Protocol <contact@parallel.best>",
|
|
6
6
|
"repository": {
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
"vitest": "^4.0.14"
|
|
134
134
|
},
|
|
135
135
|
"dependencies": {
|
|
136
|
-
"@parallel-protocol/chains": "^0.5.
|
|
136
|
+
"@parallel-protocol/chains": "^0.5.1",
|
|
137
137
|
"fastify-plugin": "^6.0.0",
|
|
138
138
|
"zod": "^4.4.3"
|
|
139
139
|
},
|