@lunora/x402 1.0.0-alpha.4 → 1.0.0-alpha.41

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.
Files changed (37) hide show
  1. package/LICENSE.md +18 -0
  2. package/README.md +18 -0
  3. package/dist/charge/index.d.mts +155 -95
  4. package/dist/charge/index.d.ts +155 -95
  5. package/dist/charge/index.mjs +1 -7
  6. package/dist/index.d.mts +2 -3
  7. package/dist/index.d.ts +2 -3
  8. package/dist/index.mjs +1 -2
  9. package/dist/packem_shared/DEFAULT_ALLOWED_ASSETS-hq1xeZL6.mjs +1 -0
  10. package/dist/packem_shared/DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs +1 -0
  11. package/dist/packem_shared/EVM_NETWORKS-C5yyzK27.mjs +1 -0
  12. package/dist/packem_shared/createChargeMiddleware-CURPSr23.mjs +1 -0
  13. package/dist/packem_shared/createFacilitatorClient-piLSnKs5.mjs +1 -0
  14. package/dist/packem_shared/createPayFetch-lyg7i3Js.mjs +1 -0
  15. package/dist/packem_shared/createProcedureChargeGate-Ki_K8dQE.mjs +1 -0
  16. package/dist/packem_shared/index.d-CzQaqaP6.d.mts +533 -0
  17. package/dist/packem_shared/index.d-CzQaqaP6.d.ts +533 -0
  18. package/dist/packem_shared/optional-peer-BBhVxozi.mjs +1 -0
  19. package/dist/packem_shared/registerWallet-DvCt0Q7M.mjs +1 -0
  20. package/dist/packem_shared/toPaymentEventRow-DTXuTDh0.mjs +1 -0
  21. package/dist/packem_shared/withX402-CJcBVHdI.mjs +1 -0
  22. package/dist/pay/index.d.mts +61 -61
  23. package/dist/pay/index.d.ts +61 -61
  24. package/dist/pay/index.mjs +1 -21
  25. package/package.json +21 -9
  26. package/dist/packem_shared/DEFAULT_FACILITATOR_URL-Cbz6kIqa.mjs +0 -4
  27. package/dist/packem_shared/DEFAULT_STABLECOIN_DECIMALS-CpW619nu.mjs +0 -90
  28. package/dist/packem_shared/EVM_NETWORKS-BhnYWUQ4.mjs +0 -26
  29. package/dist/packem_shared/config.d-5Nqi5iox.d.mts +0 -404
  30. package/dist/packem_shared/config.d-5Nqi5iox.d.ts +0 -404
  31. package/dist/packem_shared/createChargeMiddleware-D3yhOpFs.mjs +0 -162
  32. package/dist/packem_shared/createFacilitatorClient-rXHBnCZm.mjs +0 -16
  33. package/dist/packem_shared/createPayFetch-BeT05njL.mjs +0 -17
  34. package/dist/packem_shared/createProcedureChargeGate-eh9yv36U.mjs +0 -21
  35. package/dist/packem_shared/registerWallet-I4pVwq65.mjs +0 -109
  36. package/dist/packem_shared/toPaymentEventRow-DW4O9N7Y.mjs +0 -22
  37. package/dist/packem_shared/withX402-DILL2DvD.mjs +0 -15
@@ -1,112 +1,136 @@
1
- import { F as FacilitatorConfig, c as X402ChargeConfig, f as X402Price } from "../packem_shared/config.d-5Nqi5iox.js";
2
- export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, type a as EvmAddress, type P as PaymentEventRow, type d as X402Network, type g as X402Receipt, type h as X402ReceiptSink, type i as X402Recipient, k as isEvmNetwork, l as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2, x as toPaymentEventRow, y as toReceipt } from "../packem_shared/config.d-5Nqi5iox.js";
1
+ import { F as FacilitatorConfig, q as X402ChargeConfig, h as X402Price } from "../packem_shared/index.d-CzQaqaP6.js";
2
+ export { type b as Caip2, c as DEFAULT_FACILITATOR_URL,
3
+ /**
4
+ * `@lunora/x402/charge` — the charge rail (server side).
5
+ *
6
+ * A Lunora deployment gates a resource (an HTTP-action route, a procedure, or
7
+ * an MCP tool) behind a USDC price: it returns `402 Payment Required` with a
8
+ * `PAYMENT-REQUIRED` header, verifies the client's `X-PAYMENT` payload (via a
9
+ * facilitator), runs the handler, settles, and attaches `X-PAYMENT-RESPONSE`.
10
+ *
11
+ * `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
12
+ * framework-agnostic core for other surfaces (procedures, MCP tools).
13
+ */
14
+ type E as EvmAddress, type P as PaymentEventRow, type g as X402Network, type s as X402Receipt, type v as X402ReceiptSink,
15
+ /**
16
+ * `@lunora/x402/charge` — the charge rail (server side).
17
+ *
18
+ * A Lunora deployment gates a resource (an HTTP-action route, a procedure, or
19
+ * an MCP tool) behind a USDC price: it returns `402 Payment Required` with a
20
+ * `PAYMENT-REQUIRED` header, verifies the client's `X-PAYMENT` payload (via a
21
+ * facilitator), runs the handler, settles, and attaches `X-PAYMENT-RESPONSE`.
22
+ *
23
+ * `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
24
+ * framework-agnostic core for other surfaces (procedures, MCP tools).
25
+ */
26
+ type w as X402Recipient, n as isEvmNetwork, o as isSvmNetwork, p as resolveFacilitatorUrl, t as toCaip2, x as toPaymentEventRow, y as toReceipt } from "../packem_shared/index.d-CzQaqaP6.js";
3
27
  import { HTTPFacilitatorClient } from '@x402/core/server';
4
28
  import { RouteConfig } from '@x402/core/http';
5
- import '@x402/evm';
6
- import '@x402/svm';
7
29
  import '@x402/core/client';
8
30
  import '@x402/core/types';
31
+ import '@solana/accounts';
9
32
  /**
10
- * Build an `@x402/core` facilitator client from Lunora's {@link FacilitatorConfig}.
11
- *
12
- * `config.headers` (e.g. a CDP bearer token) are applied to every facilitator
13
- * call — `@x402/core` splits auth per endpoint (`verify` / `settle` /
14
- * `supported`), so the same header map is handed to each. With no config the
15
- * client points at the public {@link resolveFacilitatorUrl default} and sends no
16
- * auth headers.
17
- * @experimental
18
- */
33
+ * Build an `@x402/core` facilitator client from Lunora's {@link FacilitatorConfig}.
34
+ *
35
+ * `config.headers` (e.g. a CDP bearer token) are applied to every facilitator
36
+ * call — `@x402/core` splits auth per endpoint (`verify` / `settle` /
37
+ * `supported`), so the same header map is handed to each. With no config the
38
+ * client points at the public {@link resolveFacilitatorUrl default} and sends no
39
+ * auth headers.
40
+ * @experimental
41
+ */
19
42
  declare const createFacilitatorClient: (config?: FacilitatorConfig) => HTTPFacilitatorClient;
20
43
  /**
21
- * A handler shaped like a Lunora HTTP action: `(context, request) => Response`.
22
- * @experimental
23
- */
44
+ * A handler shaped like a Lunora HTTP action: `(context, request) => Response`.
45
+ * @experimental
46
+ */
24
47
  type HttpActionHandler<Context> = (context: Context, request: Request) => Promise<Response> | Response;
25
48
  /**
26
- * Gate `handler` behind an x402 paywall described by `config`. Returns a handler
27
- * of the same shape, ready to pass to `httpAction`.
28
- * @experimental
29
- */
49
+ * Gate `handler` behind an x402 paywall described by `config`. Returns a handler
50
+ * of the same shape, ready to pass to `httpAction`.
51
+ * @experimental
52
+ */
30
53
  declare const withX402: <Context>(config: X402ChargeConfig, handler: HttpActionHandler<Context>) => HttpActionHandler<Context>;
31
54
  /**
32
- * Runs the protected resource handler, producing the Response to gate.
33
- * @experimental
34
- */
55
+ * Runs the protected resource handler, producing the Response to gate.
56
+ * @experimental
57
+ */
35
58
  type ChargeHandler = () => Promise<Response> | Response;
36
59
  /**
37
- * Per-request platform seams `handle` can use, beyond the request/handler pair.
38
- * @experimental
39
- */
60
+ * Per-request platform seams `handle` can use, beyond the request/handler pair.
61
+ * @experimental
62
+ */
40
63
  interface ChargeHandlerDeps {
41
64
  /**
42
- * Keep background work (the receipt sink) alive past the response — the
43
- * request's `ctx.waitUntil`. Absent on paths with no platform execution
44
- * context reaching the middleware (e.g. today's HTTP-action rail).
45
- */
65
+ * Keep background work (the receipt sink) alive past the response — the
66
+ * request's `ctx.waitUntil`. Absent on paths with no platform execution
67
+ * context reaching the middleware (e.g. today's HTTP-action rail).
68
+ */
46
69
  readonly waitUntil?: (promise: Promise<unknown>) => void;
47
70
  }
48
71
  /**
49
- * A prepared, initialised paywall. Build once (it fetches facilitator support), reuse per request.
50
- * @experimental
51
- */
72
+ * A prepared, initialised paywall. Build once (it fetches facilitator support), reuse per request.
73
+ * @experimental
74
+ */
52
75
  interface ChargeMiddleware {
53
76
  /** Gate `request`: challenge / verify / settle around `runHandler`. */
54
77
  handle: (request: Request, runHandler: ChargeHandler, deps?: ChargeHandlerDeps) => Promise<Response>;
55
78
  }
56
79
  /**
57
- * Route metadata a caller can layer onto the generated catch-all route. The
58
- * procedure gate sets `resource` to the `functionPath` so the x402 challenge
59
- * names the paid function (x402 core falls back to the request URL otherwise —
60
- * every RPC POSTs to the same `/_lunora/rpc`, so the URL can't tell two paid
61
- * procedures apart).
62
- * @experimental
63
- */
80
+ * Route metadata a caller can layer onto the generated catch-all route. The
81
+ * procedure gate sets `resource` to the `functionPath` so the x402 challenge
82
+ * names the paid function (x402 core falls back to the request URL otherwise —
83
+ * every RPC POSTs to the same `/_lunora/rpc`, so the URL can't tell two paid
84
+ * procedures apart).
85
+ * @experimental
86
+ */
64
87
  type ChargeRouteOverrides = Pick<RouteConfig, "description" | "resource">;
65
88
  /**
66
- * Behaviour knobs for {@link createChargeMiddleware} beyond route metadata.
67
- * @experimental
68
- */
89
+ * Behaviour knobs for {@link createChargeMiddleware} beyond route metadata.
90
+ * @experimental
91
+ */
69
92
  interface ChargeMiddlewareOptions {
70
93
  /**
71
- * Settle the verified payment **before** dispatching `runHandler`, instead
72
- * of after. Use this for a mutation/procedure gate: a settlement failure
73
- * then means the handler never runs at all, so a paid mutation's writes can
74
- * never be committed without payment (the free-execution gap X402-04
75
- * closes). Once settlement succeeds the payment is final (on-chain) — a
76
- * handler failure after that point is a normal application error, not a
77
- * payment to unwind: there is nothing left to cancel, so it is not caught
78
- * here and simply propagates.
79
- *
80
- * Default `false` (settle-after, the historical behaviour): the handler's
81
- * response is passed to settlement as transport context (`responseHeaders`
82
- * — read by some schemes for settlement overrides), and a handler throw
83
- * still releases the verified-but-unsettled payment via
84
- * `cancellationDispatcher.cancel`. Because settlement can still fail after
85
- * the handler already ran on this path, `.x402()` handlers gated this way
86
- * MUST be idempotent or compensatable — see the `@lunora/x402` charge docs.
87
- */
94
+ * Settle the verified payment **before** dispatching `runHandler`, instead
95
+ * of after. **Default `true`** — a settlement failure then means the handler
96
+ * never runs at all, so its side effects (writes, LLM calls, mail, push) can
97
+ * never happen unpaid. This matters because `verifyPayment` only checks the
98
+ * signed intent, NOT solvency: an underfunded or facilitator-refused payment
99
+ * passes verify and fails at `/settle`. Once settlement succeeds the payment
100
+ * is final (on-chain) — a handler failure after that point is a normal
101
+ * application error, not a payment to unwind: there is nothing left to
102
+ * cancel, so it is not caught here and simply propagates.
103
+ *
104
+ * Set `false` for settle-after: the handler's response is passed to
105
+ * settlement as transport context (`responseHeaders` — read by some schemes
106
+ * for settlement overrides), and a handler throw releases the
107
+ * verified-but-unsettled payment via `cancellationDispatcher.cancel`.
108
+ * Settlement can still FAIL after the handler already ran on this path, so a
109
+ * handler gated this way MUST be idempotent or compensatable — opt in only
110
+ * when you need the response as settlement context and can accept that.
111
+ */
88
112
  readonly settleBeforeHandler?: boolean;
89
113
  }
90
114
  /**
91
- * Build and initialise a {@link ChargeMiddleware} for `config`. Fetches
92
- * facilitator support once (via `initialize()`), so call this once per config
93
- * and reuse the result across requests. `routeOverrides` layers extra route
94
- * metadata (e.g. `resource`) onto the generated catch-all route; `options`
95
- * controls settlement ordering (see {@link ChargeMiddlewareOptions}).
96
- * @experimental
97
- */
115
+ * Build and initialise a {@link ChargeMiddleware} for `config`. Fetches
116
+ * facilitator support once (via `initialize()`), so call this once per config
117
+ * and reuse the result across requests. `routeOverrides` layers extra route
118
+ * metadata (e.g. `resource`) onto the generated catch-all route; `options`
119
+ * controls settlement ordering (see {@link ChargeMiddlewareOptions}).
120
+ * @experimental
121
+ */
98
122
  declare const createChargeMiddleware: (config: X402ChargeConfig, routeOverrides?: ChargeRouteOverrides, options?: ChargeMiddlewareOptions) => Promise<ChargeMiddleware>;
99
123
  /**
100
- * Charge config for the procedure gate: the worker-level settlement vocabulary
101
- * (network, recipient, facilitator) minus `price` — price is per-procedure and
102
- * arrives with each {@link X402ProcedureSpec}.
103
- * @experimental
104
- */
124
+ * Charge config for the procedure gate: the worker-level settlement vocabulary
125
+ * (network, recipient, facilitator) minus `price` — price is per-procedure and
126
+ * arrives with each {@link X402ProcedureSpec}.
127
+ * @experimental
128
+ */
105
129
  type X402ProcedureChargeConfig = Omit<X402ChargeConfig, "price">;
106
130
  /**
107
- * The per-RPC charge spec the runtime passes the gate for each paid dispatch.
108
- * @experimental
109
- */
131
+ * The per-RPC charge spec the runtime passes the gate for each paid dispatch.
132
+ * @experimental
133
+ */
110
134
  interface X402ProcedureSpec {
111
135
  /** The `file:function` id of the paid procedure; becomes the x402 challenge `resource`. */
112
136
  readonly functionPath: string;
@@ -114,26 +138,62 @@ interface X402ProcedureSpec {
114
138
  readonly price: X402Price;
115
139
  }
116
140
  /**
117
- * Gate one paid RPC. Returns a real `402` + `PAYMENT-REQUIRED` challenge when the
118
- * request is unpaid, or the dispatched response (with `X-PAYMENT-RESPONSE`
119
- * attached) once the client's `X-PAYMENT` is verified and settled. `dispatch`
120
- * runs the actual shard forward — settlement happens **before** `dispatch` is
121
- * invoked (settle-first), so a settlement failure means the shard forward
122
- * (the mutation's commit) never runs at all — no committed-but-unpaid write is
123
- * possible. `deps.waitUntil`, when supplied (the request's `ctx.waitUntil`),
124
- * keeps the opt-in receipt sink alive past the response.
125
- * @experimental
126
- */
141
+ * Gate one paid RPC. Returns a real `402` + `PAYMENT-REQUIRED` challenge when the
142
+ * request is unpaid, or the dispatched response (with `X-PAYMENT-RESPONSE`
143
+ * attached) once the client's `X-PAYMENT` is verified and settled. `dispatch`
144
+ * runs the actual shard forward — settlement happens **before** `dispatch` is
145
+ * invoked (settle-first), so a settlement failure means the shard forward
146
+ * (the mutation's commit) never runs at all — no committed-but-unpaid write is
147
+ * possible. `deps.waitUntil`, when supplied (the request's `ctx.waitUntil`),
148
+ * keeps the opt-in receipt sink alive past the response.
149
+ * @experimental
150
+ */
127
151
  type X402ProcedureChargeGate = (request: Request, spec: X402ProcedureSpec, dispatch: () => Promise<Response>, deps?: ChargeHandlerDeps) => Promise<Response>;
128
152
  /**
129
- * Build the injectable procedure charge gate for `config`. One initialised
130
- * {@link ChargeMiddleware} is memoised per `functionPath` (each bakes that
131
- * function's price + `resource`), since `createChargeMiddleware` fetches
132
- * facilitator support on first use. A failed init is not cached, so a transient
133
- * facilitator outage retries on the next request. Settlement runs before
134
- * `dispatch` (`settleBeforeHandler: true`) since `dispatch` commits the
135
- * procedure's real mutation — see `createChargeMiddleware`'s `ChargeMiddlewareOptions`.
136
- * @experimental
137
- */
153
+ * Build the injectable procedure charge gate for `config`. One initialised
154
+ * {@link ChargeMiddleware} is memoised per `functionPath` (each bakes that
155
+ * function's price + `resource`), since `createChargeMiddleware` fetches
156
+ * facilitator support on first use. A failed init is not cached, so a transient
157
+ * facilitator outage retries on the next request. Settlement runs before
158
+ * `dispatch` (the `settleBeforeHandler` default) since `dispatch` commits the
159
+ * procedure's real mutation — see `createChargeMiddleware`'s `ChargeMiddlewareOptions`.
160
+ * @experimental
161
+ */
138
162
  declare const createProcedureChargeGate: (config: X402ProcedureChargeConfig) => X402ProcedureChargeGate;
139
- export { type ChargeHandler, type ChargeHandlerDeps, type ChargeMiddleware, type ChargeMiddlewareOptions, type ChargeRouteOverrides, type FacilitatorConfig, type HttpActionHandler, type X402ChargeConfig, type X402Price, type X402ProcedureChargeConfig, type X402ProcedureChargeGate, type X402ProcedureSpec, createChargeMiddleware, createFacilitatorClient, createProcedureChargeGate, withX402 };
163
+ export { type ChargeHandler, type ChargeHandlerDeps, type ChargeMiddleware, type ChargeMiddlewareOptions, type ChargeRouteOverrides,
164
+ /**
165
+ * `@lunora/x402/charge` — the charge rail (server side).
166
+ *
167
+ * A Lunora deployment gates a resource (an HTTP-action route, a procedure, or
168
+ * an MCP tool) behind a USDC price: it returns `402 Payment Required` with a
169
+ * `PAYMENT-REQUIRED` header, verifies the client's `X-PAYMENT` payload (via a
170
+ * facilitator), runs the handler, settles, and attaches `X-PAYMENT-RESPONSE`.
171
+ *
172
+ * `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
173
+ * framework-agnostic core for other surfaces (procedures, MCP tools).
174
+ */
175
+ type FacilitatorConfig, type HttpActionHandler,
176
+ /**
177
+ * `@lunora/x402/charge` — the charge rail (server side).
178
+ *
179
+ * A Lunora deployment gates a resource (an HTTP-action route, a procedure, or
180
+ * an MCP tool) behind a USDC price: it returns `402 Payment Required` with a
181
+ * `PAYMENT-REQUIRED` header, verifies the client's `X-PAYMENT` payload (via a
182
+ * facilitator), runs the handler, settles, and attaches `X-PAYMENT-RESPONSE`.
183
+ *
184
+ * `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
185
+ * framework-agnostic core for other surfaces (procedures, MCP tools).
186
+ */
187
+ type X402ChargeConfig,
188
+ /**
189
+ * `@lunora/x402/charge` — the charge rail (server side).
190
+ *
191
+ * A Lunora deployment gates a resource (an HTTP-action route, a procedure, or
192
+ * an MCP tool) behind a USDC price: it returns `402 Payment Required` with a
193
+ * `PAYMENT-REQUIRED` header, verifies the client's `X-PAYMENT` payload (via a
194
+ * facilitator), runs the handler, settles, and attaches `X-PAYMENT-RESPONSE`.
195
+ *
196
+ * `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
197
+ * framework-agnostic core for other surfaces (procedures, MCP tools).
198
+ */
199
+ type X402Price, type X402ProcedureChargeConfig, type X402ProcedureChargeGate, type X402ProcedureSpec, createChargeMiddleware, createFacilitatorClient, createProcedureChargeGate, withX402 };
@@ -1,7 +1 @@
1
- export { DEFAULT_FACILITATOR_URL, resolveFacilitatorUrl } from '../packem_shared/DEFAULT_FACILITATOR_URL-Cbz6kIqa.mjs';
2
- export { createFacilitatorClient } from '../packem_shared/createFacilitatorClient-rXHBnCZm.mjs';
3
- export { isEvmNetwork, isSvmNetwork, toCaip2 } from '../packem_shared/EVM_NETWORKS-BhnYWUQ4.mjs';
4
- export { withX402 } from '../packem_shared/withX402-DILL2DvD.mjs';
5
- export { createChargeMiddleware } from '../packem_shared/createChargeMiddleware-D3yhOpFs.mjs';
6
- export { createProcedureChargeGate } from '../packem_shared/createProcedureChargeGate-eh9yv36U.mjs';
7
- export { toPaymentEventRow, toReceipt } from '../packem_shared/toPaymentEventRow-DW4O9N7Y.mjs';
1
+ import{DEFAULT_FACILITATOR_URL as t,resolveFacilitatorUrl as o}from"../packem_shared/DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs";import{createFacilitatorClient as i}from"../packem_shared/createFacilitatorClient-piLSnKs5.mjs";import{isEvmNetwork as p,isSvmNetwork as c,toCaip2 as f}from"../packem_shared/EVM_NETWORKS-C5yyzK27.mjs";import{withX402 as l}from"../packem_shared/withX402-CJcBVHdI.mjs";import{createChargeMiddleware as C}from"../packem_shared/createChargeMiddleware-CURPSr23.mjs";import{createProcedureChargeGate as F}from"../packem_shared/createProcedureChargeGate-Ki_K8dQE.mjs";import{toPaymentEventRow as d,toReceipt as h}from"../packem_shared/toPaymentEventRow-DTXuTDh0.mjs";export{t as DEFAULT_FACILITATOR_URL,C as createChargeMiddleware,i as createFacilitatorClient,F as createProcedureChargeGate,p as isEvmNetwork,c as isSvmNetwork,o as resolveFacilitatorUrl,f as toCaip2,d as toPaymentEventRow,h as toReceipt,l as withX402};
package/dist/index.d.mts CHANGED
@@ -1,6 +1,5 @@
1
- export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, E as EVM_NETWORKS, type a as EvmAddress, type F as FacilitatorConfig, type b as FriendlyNetwork, N as NETWORK_TO_CAIP2, S as SVM_NETWORKS, type X as X402CdpSignerConfig, type c as X402ChargeConfig, type d as X402Network, type e as X402PayConfig, type f as X402Price, type g as X402Receipt, type h as X402ReceiptSink, type i as X402Recipient, type j as X402SignerConfig, k as isEvmNetwork, l as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2 } from "./packem_shared/config.d-5Nqi5iox.mjs";
2
- import '@x402/evm';
3
- import '@x402/svm';
1
+ export { type b as Caip2, c as DEFAULT_FACILITATOR_URL, z as EVM_NETWORKS, type E as EvmAddress, type F as FacilitatorConfig, type B as FriendlyNetwork, N as NETWORK_TO_CAIP2, G as SVM_NETWORKS, type f as X402CdpSignerConfig, type q as X402ChargeConfig, type g as X402Network, type X as X402PayConfig, type h as X402Price, type s as X402Receipt, type v as X402ReceiptSink, type w as X402Recipient, type i as X402SignerConfig, n as isEvmNetwork, o as isSvmNetwork, p as resolveFacilitatorUrl, t as toCaip2 } from "./packem_shared/index.d-CzQaqaP6.mjs";
4
2
  import '@x402/core/http';
5
3
  import '@x402/core/client';
6
4
  import '@x402/core/types';
5
+ import '@solana/accounts';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, E as EVM_NETWORKS, type a as EvmAddress, type F as FacilitatorConfig, type b as FriendlyNetwork, N as NETWORK_TO_CAIP2, S as SVM_NETWORKS, type X as X402CdpSignerConfig, type c as X402ChargeConfig, type d as X402Network, type e as X402PayConfig, type f as X402Price, type g as X402Receipt, type h as X402ReceiptSink, type i as X402Recipient, type j as X402SignerConfig, k as isEvmNetwork, l as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2 } from "./packem_shared/config.d-5Nqi5iox.js";
2
- import '@x402/evm';
3
- import '@x402/svm';
1
+ export { type b as Caip2, c as DEFAULT_FACILITATOR_URL, z as EVM_NETWORKS, type E as EvmAddress, type F as FacilitatorConfig, type B as FriendlyNetwork, N as NETWORK_TO_CAIP2, G as SVM_NETWORKS, type f as X402CdpSignerConfig, type q as X402ChargeConfig, type g as X402Network, type X as X402PayConfig, type h as X402Price, type s as X402Receipt, type v as X402ReceiptSink, type w as X402Recipient, type i as X402SignerConfig, n as isEvmNetwork, o as isSvmNetwork, p as resolveFacilitatorUrl, t as toCaip2 } from "./packem_shared/index.d-CzQaqaP6.js";
4
2
  import '@x402/core/http';
5
3
  import '@x402/core/client';
6
4
  import '@x402/core/types';
5
+ import '@solana/accounts';
package/dist/index.mjs CHANGED
@@ -1,2 +1 @@
1
- export { DEFAULT_FACILITATOR_URL, resolveFacilitatorUrl } from './packem_shared/DEFAULT_FACILITATOR_URL-Cbz6kIqa.mjs';
2
- export { EVM_NETWORKS, NETWORK_TO_CAIP2, SVM_NETWORKS, isEvmNetwork, isSvmNetwork, toCaip2 } from './packem_shared/EVM_NETWORKS-BhnYWUQ4.mjs';
1
+ import{DEFAULT_FACILITATOR_URL as t,resolveFacilitatorUrl as T}from"./packem_shared/DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs";import{EVM_NETWORKS as E,NETWORK_TO_CAIP2 as _,SVM_NETWORKS as i,isEvmNetwork as N,isSvmNetwork as O,toCaip2 as R}from"./packem_shared/EVM_NETWORKS-C5yyzK27.mjs";export{t as DEFAULT_FACILITATOR_URL,E as EVM_NETWORKS,_ as NETWORK_TO_CAIP2,i as SVM_NETWORKS,N as isEvmNetwork,O as isSvmNetwork,T as resolveFacilitatorUrl,R as toCaip2};
@@ -0,0 +1 @@
1
+ import{LunoraError as l}from"@lunora/errors";import{toCaip2 as f}from"./EVM_NETWORKS-C5yyzK27.mjs";const v=/^\d+(?:\.\d+)?$/,u=(e,t)=>t.startsWith("eip155:")?e.toLowerCase():e,p=(e,t)=>`${t}|${u(e,t)}`,h=/^\d+$/,w=e=>h.test(e)?BigInt(e):void 0,S=6,x=[{asset:"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",decimals:6,network:"base"},{asset:"0x036CbD53842c5426634e7929541eC2318f3dCF7e",decimals:6,network:"base-sepolia"},{asset:"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",decimals:6,network:"polygon"},{asset:"0xaf88d065e77c8cC2239327C5EDb3A432268e5831",decimals:6,network:"arbitrum"},{asset:"0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",decimals:6,network:"arbitrum-sepolia"},{asset:"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",decimals:6,network:"solana"},{asset:"4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU",decimals:6,network:"solana-devnet"}],C=()=>{let e=0n;return{add:t=>{e+=t},release:t=>{e=e>t?e-t:0n},get spentAtomic(){return e}}},E=(e,t=S)=>{if(!Number.isInteger(t)||t<0)throw new l("BAD_REQUEST",`x402 policy: decimals must be a non-negative integer, got ${String(t)}.`);const n=(typeof e=="number"?e.toString():e).trim(),s=n.startsWith("$")?n.slice(1):n;if(!v.test(s))throw new l("BAD_REQUEST",`x402 policy: "${String(e)}" is not a valid USD amount (use a plain decimal like "0.01").`);const[o="0",r=""]=s.split("."),a=r.slice(0,t).padEnd(t,"0");return BigInt(o)*10n**BigInt(t)+BigInt(a===""?"0":a)},b=e=>{if(e.decimals!==void 0)throw new l("BAD_REQUEST","x402 policy: `decimals` is no longer supported — a single policy-wide decimal count can't describe the assets a server may name. List the asset in `allowedAssets` with its own `decimals` instead.");const t=e.allowedAssets??x;if(t.length===0)throw new l("BAD_REQUEST","x402 policy: `allowedAssets` is empty, so no payment could ever be made. Omit it to accept the default USDC assets, or list at least one asset.");const n=new Map;for(const s of t){if(!Number.isInteger(s.decimals)||s.decimals<0)throw new l("BAD_REQUEST",`x402 policy: allowedAssets[${s.asset}].decimals must be a non-negative integer, got ${String(s.decimals)}.`);const o=f(s.network),r=p(s.asset,o),a=n.get(r);if(a!==void 0&&a.decimals!==s.decimals)throw new l("BAD_REQUEST",`x402 policy: allowedAssets lists ${s.asset} on ${o} twice with different decimals (${String(a.decimals)} and ${String(s.decimals)}). One asset cannot have two precisions.`);n.set(r,{...s,network:o})}return n},g=(e,t)=>{const n=new Map;if(e===void 0)return n;for(const{decimals:s}of t.values())n.has(s)||n.set(s,E(e,s));return n},R=e=>{const t=b(e),n=g(e.maxPerCall,t),s=e.allowedNetworks?.map(r=>f(r)),{allowedRecipients:o}=e;return(r,a)=>a.filter(i=>{const c=t.get(p(i.asset,i.network));if(c===void 0)return!1;const d=w(i.amount);if(d===void 0)return!1;const m=n.get(c.decimals);if(m!==void 0&&d>m||s!==void 0&&!s.includes(i.network))return!1;if(o!==void 0){const A=u(i.payTo,i.network);return o.some(y=>u(y,i.network)===A)}return!0})},P=(e,t)=>{const n=b(e),s=g(e.maxPerRun,n);let o;return async r=>{const a=r.selectedRequirements,i=n.get(p(a.asset,a.network));if(i===void 0)return{abort:!0,reason:`x402 policy: asset ${a.asset} on ${a.network} is not in this wallet's allowed assets, so its amount cannot be priced against the caps.`};if(o===void 0)o=i.decimals;else if(o!==i.decimals)return{abort:!0,reason:`x402 policy: this payment is in a ${String(i.decimals)}-decimal asset but the run's spend is tracked in ${String(o)}-decimal units. One wallet cannot mix asset precisions under a single per-run cap.`};const c=w(a.amount);if(c===void 0)return{abort:!0,reason:`x402 policy: this payment's amount (${a.amount}) is not a canonical atomic quantity, so it cannot be checked against the caps.`};const d=s.get(i.decimals);if(d!==void 0&&t.spentAtomic+c>d)return{abort:!0,reason:`x402 policy: this payment (${a.amount}) would exceed the per-run cap (already spent ${t.spentAtomic.toString()}, cap ${d.toString()}, in atomic base units).`};t.add(c);try{return e.onPaymentRequired!==void 0&&!await e.onPaymentRequired(a)?(t.release(c),{abort:!0,reason:"x402 policy: payment was declined by onPaymentRequired."}):void 0}catch(m){throw t.release(c),m}}},$=e=>t=>{const n=w(t.selectedRequirements.amount);return n!==void 0&&e.release(n),Promise.resolve()},T=e=>{if(!(e.maxPerCall!==void 0||e.maxPerRun!==void 0||e.onPaymentRequired!==void 0))throw new l("FORBIDDEN","x402 pay: refusing to build a wallet with an unbounded spend policy. Set at least one of maxPerCall, maxPerRun, or onPaymentRequired (allowedNetworks/allowedRecipients/allowedAssets narrow but do not bound spend).")};export{x as DEFAULT_ALLOWED_ASSETS,S as DEFAULT_STABLECOIN_DECIMALS,T as assertBoundedPolicy,P as buildPaymentGuard,R as buildSpendPolicy,C as createSpendState,$ as releaseSpendOnFailure,E as usdToAtomic};
@@ -0,0 +1 @@
1
+ const o="https://x402.org/facilitator",r=t=>t?.url??o;export{o as DEFAULT_FACILITATOR_URL,r as resolveFacilitatorUrl};
@@ -0,0 +1 @@
1
+ const s={arbitrum:"eip155:42161","arbitrum-sepolia":"eip155:421614",base:"eip155:8453","base-sepolia":"eip155:84532",ethereum:"eip155:1",polygon:"eip155:137",solana:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp","solana-devnet":"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"},i=["arbitrum","arbitrum-sepolia","base","base-sepolia","ethereum","polygon"],t=["solana","solana-devnet"],o=a=>{const e=s[a];if(e!==void 0)return e;if(a.includes(":"))return a;throw new Error(`Unknown x402 network "${a}". Use a friendly name (${i.join(", ")}, ${t.join(", ")}) or a raw CAIP-2 id.`)},n=a=>o(a).startsWith("eip155:"),r=a=>o(a).startsWith("solana:");export{i as EVM_NETWORKS,s as NETWORK_TO_CAIP2,t as SVM_NETWORKS,n as isEvmNetwork,r as isSvmNetwork,o as toCaip2};
@@ -0,0 +1 @@
1
+ import{x402HTTPResourceServer as E}from"@x402/core/http";import{toCaip2 as x,isEvmNetwork as P}from"./EVM_NETWORKS-C5yyzK27.mjs";import{toReceipt as S}from"./toPaymentEventRow-DTXuTDh0.mjs";import{createFacilitatorClient as H}from"./createFacilitatorClient-piLSnKs5.mjs";import{i as R}from"./optional-peer-BBhVxozi.mjs";const T=async e=>{const{x402ResourceServer:r}=await import("@x402/core/server"),t=new r(H(e.facilitator)),s=x(e.network);if(P(e.network)){const{registerExactEvmScheme:a}=await R(()=>import("@x402/evm/exact/server"),"x402 charge: EVM networks need the optional @x402/evm + viem peers — install them, or configure an SVM network.");a(t,{networks:[s]})}else{const{registerExactSvmScheme:a}=await R(()=>import("@x402/svm/exact/server"),"x402 charge: SVM networks need the optional @x402/svm + @solana/kit peers — install them, or configure an EVM network.");a(t,{networks:[s]})}return t},A="X-PAYMENT",M=e=>{const r=Object.create(null);for(const[t,s]of e)r[t]=s;return r},g=(e,r,t,s)=>{if(e!==void 0)try{const a=Promise.resolve(e(S(r,{resource:t,ts:Date.now()}))).catch(()=>{});s?.(a)}catch{}},b=e=>{const r=P(e.network),t=r?e.recipient.evm:e.recipient.svm;if(t===void 0||t.length===0)throw new Error(`x402 charge on "${e.network}" needs recipient.${r?"evm":"svm"} set.`);return t},U=e=>({accepts:{network:x(e.network),payTo:b(e),price:e.price,scheme:"exact"}}),j=(e,r)=>({getAcceptHeader:()=>e.headers.get("accept")??"",getHeader:t=>e.headers.get(t)??void 0,getMethod:()=>e.method,getPath:()=>r.pathname,getQueryParam:t=>{const s=r.searchParams.getAll(t);if(s.length!==0)return s.length===1?s[0]:s},getQueryParams:()=>{const t=Object.create(null);for(const s of new Set(r.searchParams.keys())){const a=r.searchParams.getAll(s),[i,...w]=a;i!==void 0&&(t[s]=w.length>0?a:i)}return t},getUrl:()=>e.url,getUserAgent:()=>e.headers.get("user-agent")??""}),u=e=>{const r=new Headers(e.headers),{body:t}=e;return t==null?new Response(void 0,{headers:r,status:e.status}):typeof t=="string"?(e.isHtml&&!r.has("content-type")&&r.set("content-type","text/html; charset=utf-8"),new Response(t,{headers:r,status:e.status})):Response.json(t,{headers:r,status:e.status})},k=(e,r)=>{const t=new Headers(e.headers);for(const[s,a]of Object.entries(r))t.set(s,a);return new Response(e.body,{headers:t,status:e.status,statusText:e.statusText})},B=async(e,r,t)=>{const s=await T(e),a=new E(s,{...U(e),...r});await a.initialize();const i=t?.settleBeforeHandler??!0;return{handle:async(c,p,y)=>{const v=new URL(c.url),h={adapter:j(c,v),method:c.method,path:v.pathname,paymentHeader:c.headers.get(A)??void 0},n=await a.processHTTPRequest(h);if(n.type==="no-payment-required")return p();if(n.type==="payment-error")return u(n.response);const f=r?.resource??c.url;if(i){const o=await a.processSettlement(n.paymentPayload,n.paymentRequirements,n.declaredExtensions,{request:h});if(!o.success)return u(o.response);g(e.onReceipt,o,f,y?.waitUntil);const d=await p();return k(d,o.headers)}let m;try{m=await p()}catch(o){try{await n.cancellationDispatcher.cancel({error:o,reason:"handler_threw"})}catch(d){console.error("x402 charge: failed to cancel payment after the handler threw",d)}throw o}const l=await a.processSettlement(n.paymentPayload,n.paymentRequirements,n.declaredExtensions,{request:h,responseHeaders:M(m.headers)});return l.success?(g(e.onReceipt,l,f,y?.waitUntil),k(m,l.headers)):u(l.response)}}};export{U as buildRoute,B as createChargeMiddleware,j as createRequestAdapter,g as reportReceipt,b as resolvePayTo,u as toResponse,k as withHeaders};
@@ -0,0 +1 @@
1
+ import{HTTPFacilitatorClient as o}from"@x402/core/server";import{resolveFacilitatorUrl as a}from"./DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs";const l=e=>{const t=a(e);if(e?.headers===void 0)return new o({url:t});const r={...e.headers};return new o({createAuthHeaders:()=>Promise.resolve({settle:r,supported:r,verify:r}),url:t})};export{l as createFacilitatorClient};
@@ -0,0 +1 @@
1
+ import{x402Client as l}from"@x402/core/client";import{wrapFetchWithPayment as c}from"@x402/fetch";import{assertBoundedPolicy as s,buildSpendPolicy as p,buildPaymentGuard as y,releaseSpendOnFailure as m,createSpendState as d}from"./DEFAULT_ALLOWED_ASSETS-hq1xeZL6.mjs";import{registerWallet as P}from"./registerWallet-DvCt0Q7M.mjs";const S=async(t,r)=>{s(t.policy);const o=d(),a=p(t.policy),n=y(t.policy,o),i=m(o),e=new l;return await P(e,t,r),e.registerPolicy(a),e.onBeforePaymentCreation(n),e.onPaymentCreationFailure(i),c(r.fetch??globalThis.fetch,e)};export{S as createPayFetch};
@@ -0,0 +1 @@
1
+ import{createChargeMiddleware as a}from"./createChargeMiddleware-CURPSr23.mjs";const d=(e,r,i,n)=>{const c=e.get(r);if(c!==void 0)return c;const t=i().catch(o=>{throw e.get(r)===t&&e.delete(r),o});return e.set(r,t),t},u=e=>{const r=new Map;return async(i,n,c,t)=>(await d(r,n.functionPath,async()=>a({...e,price:n.price},{resource:n.functionPath}))).handle(i,c,t)};export{u as createProcedureChargeGate};