@lunora/x402 1.0.0-alpha.36 → 1.0.0-alpha.38
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/charge/index.d.mts +63 -3
- package/dist/charge/index.d.ts +63 -3
- package/dist/charge/index.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{DEFAULT_ALLOWED_ASSETS-BIIP_mdG.mjs → DEFAULT_ALLOWED_ASSETS-dGcAqjXx.mjs} +1 -1
- package/dist/packem_shared/DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs +1 -0
- package/dist/packem_shared/EVM_NETWORKS-C5yyzK27.mjs +1 -0
- package/dist/packem_shared/createChargeMiddleware-maSEWe6e.mjs +1 -0
- package/dist/packem_shared/createFacilitatorClient-piLSnKs5.mjs +1 -0
- package/dist/packem_shared/createPayFetch-rMvWpF_k.mjs +1 -0
- package/dist/packem_shared/createProcedureChargeGate-BiAt1YGO.mjs +1 -0
- package/dist/packem_shared/{config.d-Dki_2r9a.d.ts → index.d-BoH6uPM5.d.mts} +2 -2
- package/dist/packem_shared/{config.d-Dki_2r9a.d.mts → index.d-BoH6uPM5.d.ts} +2 -2
- package/dist/packem_shared/registerWallet-BANE2x02.mjs +1 -0
- package/dist/packem_shared/toPaymentEventRow-DTXuTDh0.mjs +1 -0
- package/dist/packem_shared/withX402-BY8hjUUD.mjs +1 -0
- package/dist/pay/index.d.mts +3 -3
- package/dist/pay/index.d.ts +3 -3
- package/dist/pay/index.mjs +1 -1
- package/package.json +7 -7
- package/dist/packem_shared/DEFAULT_FACILITATOR_URL-lUtljfJI.mjs +0 -1
- package/dist/packem_shared/EVM_NETWORKS-XOms9Rtk.mjs +0 -1
- package/dist/packem_shared/createChargeMiddleware-BtNcqDSy.mjs +0 -1
- package/dist/packem_shared/createFacilitatorClient-Dj4Ll9xQ.mjs +0 -1
- package/dist/packem_shared/createPayFetch-B6A51xPI.mjs +0 -1
- package/dist/packem_shared/createProcedureChargeGate-D3N5D-dW.mjs +0 -1
- package/dist/packem_shared/registerWallet-Cu4qF5tj.mjs +0 -1
- package/dist/packem_shared/toPaymentEventRow-D_kRVcb3.mjs +0 -1
- package/dist/packem_shared/withX402-B-JxoON3.mjs +0 -1
package/dist/charge/index.d.mts
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
|
-
import { F as FacilitatorConfig,
|
|
2
|
-
export { type C as Caip2,
|
|
1
|
+
import { F as FacilitatorConfig, o as X402ChargeConfig, f as X402Price } from "../packem_shared/index.d-BoH6uPM5.mjs";
|
|
2
|
+
export { type C as Caip2, a 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 e as X402Network, type p as X402Receipt, type q 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 s as X402Recipient, l as isEvmNetwork, m as isSvmNetwork, n as resolveFacilitatorUrl, t as toCaip2, v as toPaymentEventRow, w as toReceipt } from "../packem_shared/index.d-BoH6uPM5.mjs";
|
|
3
27
|
import { HTTPFacilitatorClient } from '@x402/core/server';
|
|
4
28
|
import { RouteConfig } from '@x402/core/http';
|
|
5
29
|
import '@x402/evm';
|
|
@@ -137,4 +161,40 @@ type X402ProcedureChargeGate = (request: Request, spec: X402ProcedureSpec, dispa
|
|
|
137
161
|
* @experimental
|
|
138
162
|
*/
|
|
139
163
|
declare const createProcedureChargeGate: (config: X402ProcedureChargeConfig) => X402ProcedureChargeGate;
|
|
140
|
-
export { type ChargeHandler, type ChargeHandlerDeps, type ChargeMiddleware, type ChargeMiddlewareOptions, type ChargeRouteOverrides,
|
|
164
|
+
export { type ChargeHandler, type ChargeHandlerDeps, type ChargeMiddleware, type ChargeMiddlewareOptions, type ChargeRouteOverrides,
|
|
165
|
+
/**
|
|
166
|
+
* `@lunora/x402/charge` — the charge rail (server side).
|
|
167
|
+
*
|
|
168
|
+
* A Lunora deployment gates a resource (an HTTP-action route, a procedure, or
|
|
169
|
+
* an MCP tool) behind a USDC price: it returns `402 Payment Required` with a
|
|
170
|
+
* `PAYMENT-REQUIRED` header, verifies the client's `X-PAYMENT` payload (via a
|
|
171
|
+
* facilitator), runs the handler, settles, and attaches `X-PAYMENT-RESPONSE`.
|
|
172
|
+
*
|
|
173
|
+
* `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
|
|
174
|
+
* framework-agnostic core for other surfaces (procedures, MCP tools).
|
|
175
|
+
*/
|
|
176
|
+
type FacilitatorConfig, type HttpActionHandler,
|
|
177
|
+
/**
|
|
178
|
+
* `@lunora/x402/charge` — the charge rail (server side).
|
|
179
|
+
*
|
|
180
|
+
* A Lunora deployment gates a resource (an HTTP-action route, a procedure, or
|
|
181
|
+
* an MCP tool) behind a USDC price: it returns `402 Payment Required` with a
|
|
182
|
+
* `PAYMENT-REQUIRED` header, verifies the client's `X-PAYMENT` payload (via a
|
|
183
|
+
* facilitator), runs the handler, settles, and attaches `X-PAYMENT-RESPONSE`.
|
|
184
|
+
*
|
|
185
|
+
* `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
|
|
186
|
+
* framework-agnostic core for other surfaces (procedures, MCP tools).
|
|
187
|
+
*/
|
|
188
|
+
type X402ChargeConfig,
|
|
189
|
+
/**
|
|
190
|
+
* `@lunora/x402/charge` — the charge rail (server side).
|
|
191
|
+
*
|
|
192
|
+
* A Lunora deployment gates a resource (an HTTP-action route, a procedure, or
|
|
193
|
+
* an MCP tool) behind a USDC price: it returns `402 Payment Required` with a
|
|
194
|
+
* `PAYMENT-REQUIRED` header, verifies the client's `X-PAYMENT` payload (via a
|
|
195
|
+
* facilitator), runs the handler, settles, and attaches `X-PAYMENT-RESPONSE`.
|
|
196
|
+
*
|
|
197
|
+
* `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
|
|
198
|
+
* framework-agnostic core for other surfaces (procedures, MCP tools).
|
|
199
|
+
*/
|
|
200
|
+
type X402Price, type X402ProcedureChargeConfig, type X402ProcedureChargeGate, type X402ProcedureSpec, createChargeMiddleware, createFacilitatorClient, createProcedureChargeGate, withX402 };
|
package/dist/charge/index.d.ts
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
|
-
import { F as FacilitatorConfig,
|
|
2
|
-
export { type C as Caip2,
|
|
1
|
+
import { F as FacilitatorConfig, o as X402ChargeConfig, f as X402Price } from "../packem_shared/index.d-BoH6uPM5.js";
|
|
2
|
+
export { type C as Caip2, a 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 e as X402Network, type p as X402Receipt, type q 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 s as X402Recipient, l as isEvmNetwork, m as isSvmNetwork, n as resolveFacilitatorUrl, t as toCaip2, v as toPaymentEventRow, w as toReceipt } from "../packem_shared/index.d-BoH6uPM5.js";
|
|
3
27
|
import { HTTPFacilitatorClient } from '@x402/core/server';
|
|
4
28
|
import { RouteConfig } from '@x402/core/http';
|
|
5
29
|
import '@x402/evm';
|
|
@@ -137,4 +161,40 @@ type X402ProcedureChargeGate = (request: Request, spec: X402ProcedureSpec, dispa
|
|
|
137
161
|
* @experimental
|
|
138
162
|
*/
|
|
139
163
|
declare const createProcedureChargeGate: (config: X402ProcedureChargeConfig) => X402ProcedureChargeGate;
|
|
140
|
-
export { type ChargeHandler, type ChargeHandlerDeps, type ChargeMiddleware, type ChargeMiddlewareOptions, type ChargeRouteOverrides,
|
|
164
|
+
export { type ChargeHandler, type ChargeHandlerDeps, type ChargeMiddleware, type ChargeMiddlewareOptions, type ChargeRouteOverrides,
|
|
165
|
+
/**
|
|
166
|
+
* `@lunora/x402/charge` — the charge rail (server side).
|
|
167
|
+
*
|
|
168
|
+
* A Lunora deployment gates a resource (an HTTP-action route, a procedure, or
|
|
169
|
+
* an MCP tool) behind a USDC price: it returns `402 Payment Required` with a
|
|
170
|
+
* `PAYMENT-REQUIRED` header, verifies the client's `X-PAYMENT` payload (via a
|
|
171
|
+
* facilitator), runs the handler, settles, and attaches `X-PAYMENT-RESPONSE`.
|
|
172
|
+
*
|
|
173
|
+
* `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
|
|
174
|
+
* framework-agnostic core for other surfaces (procedures, MCP tools).
|
|
175
|
+
*/
|
|
176
|
+
type FacilitatorConfig, type HttpActionHandler,
|
|
177
|
+
/**
|
|
178
|
+
* `@lunora/x402/charge` — the charge rail (server side).
|
|
179
|
+
*
|
|
180
|
+
* A Lunora deployment gates a resource (an HTTP-action route, a procedure, or
|
|
181
|
+
* an MCP tool) behind a USDC price: it returns `402 Payment Required` with a
|
|
182
|
+
* `PAYMENT-REQUIRED` header, verifies the client's `X-PAYMENT` payload (via a
|
|
183
|
+
* facilitator), runs the handler, settles, and attaches `X-PAYMENT-RESPONSE`.
|
|
184
|
+
*
|
|
185
|
+
* `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
|
|
186
|
+
* framework-agnostic core for other surfaces (procedures, MCP tools).
|
|
187
|
+
*/
|
|
188
|
+
type X402ChargeConfig,
|
|
189
|
+
/**
|
|
190
|
+
* `@lunora/x402/charge` — the charge rail (server side).
|
|
191
|
+
*
|
|
192
|
+
* A Lunora deployment gates a resource (an HTTP-action route, a procedure, or
|
|
193
|
+
* an MCP tool) behind a USDC price: it returns `402 Payment Required` with a
|
|
194
|
+
* `PAYMENT-REQUIRED` header, verifies the client's `X-PAYMENT` payload (via a
|
|
195
|
+
* facilitator), runs the handler, settles, and attaches `X-PAYMENT-RESPONSE`.
|
|
196
|
+
*
|
|
197
|
+
* `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
|
|
198
|
+
* framework-agnostic core for other surfaces (procedures, MCP tools).
|
|
199
|
+
*/
|
|
200
|
+
type X402Price, type X402ProcedureChargeConfig, type X402ProcedureChargeGate, type X402ProcedureSpec, createChargeMiddleware, createFacilitatorClient, createProcedureChargeGate, withX402 };
|
package/dist/charge/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DEFAULT_FACILITATOR_URL as t,resolveFacilitatorUrl as o}from"../packem_shared/DEFAULT_FACILITATOR_URL-
|
|
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-BY8hjUUD.mjs";import{createChargeMiddleware as C}from"../packem_shared/createChargeMiddleware-maSEWe6e.mjs";import{createProcedureChargeGate as F}from"../packem_shared/createProcedureChargeGate-BiAt1YGO.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,6 @@
|
|
|
1
|
-
export { type C as Caip2,
|
|
1
|
+
export { type C as Caip2, a as DEFAULT_FACILITATOR_URL, x as EVM_NETWORKS, type E as EvmAddress, type F as FacilitatorConfig, type y as FriendlyNetwork, N as NETWORK_TO_CAIP2, z as SVM_NETWORKS, type d as X402CdpSignerConfig, type o as X402ChargeConfig, type e as X402Network, type X as X402PayConfig, type f as X402Price, type p as X402Receipt, type q as X402ReceiptSink, type s as X402Recipient, type g as X402SignerConfig, l as isEvmNetwork, m as isSvmNetwork, n as resolveFacilitatorUrl, t as toCaip2 } from "./packem_shared/index.d-BoH6uPM5.mjs";
|
|
2
|
+
import '@x402/core/http';
|
|
2
3
|
import '@x402/evm';
|
|
3
4
|
import '@x402/svm';
|
|
4
|
-
import '@x402/core/http';
|
|
5
5
|
import '@x402/core/client';
|
|
6
6
|
import '@x402/core/types';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { type C as Caip2,
|
|
1
|
+
export { type C as Caip2, a as DEFAULT_FACILITATOR_URL, x as EVM_NETWORKS, type E as EvmAddress, type F as FacilitatorConfig, type y as FriendlyNetwork, N as NETWORK_TO_CAIP2, z as SVM_NETWORKS, type d as X402CdpSignerConfig, type o as X402ChargeConfig, type e as X402Network, type X as X402PayConfig, type f as X402Price, type p as X402Receipt, type q as X402ReceiptSink, type s as X402Recipient, type g as X402SignerConfig, l as isEvmNetwork, m as isSvmNetwork, n as resolveFacilitatorUrl, t as toCaip2 } from "./packem_shared/index.d-BoH6uPM5.js";
|
|
2
|
+
import '@x402/core/http';
|
|
2
3
|
import '@x402/evm';
|
|
3
4
|
import '@x402/svm';
|
|
4
|
-
import '@x402/core/http';
|
|
5
5
|
import '@x402/core/client';
|
|
6
6
|
import '@x402/core/types';
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{DEFAULT_FACILITATOR_URL as t,resolveFacilitatorUrl as T}from"./packem_shared/DEFAULT_FACILITATOR_URL-
|
|
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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LunoraError as
|
|
1
|
+
import{LunoraError as l}from"@lunora/errors";import{toCaip2 as w}from"./EVM_NETWORKS-C5yyzK27.mjs";const h=/^\d+(?:\.\d+)?$/,u=(e,t)=>t.startsWith("eip155:")?e.toLowerCase():e,p=(e,t)=>`${t}|${u(e,t)}`,v=/^\d+$/,f=e=>v.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(!h.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)},g=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=w(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},b=(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=g(e),n=b(e.maxPerCall,t),s=e.allowedNetworks?.map(r=>w(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=f(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=g(e),s=b(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=f(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=>(e.release(BigInt(t.selectedRequirements.amount)),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 k}from"@x402/core/http";import{toCaip2 as x,isEvmNetwork as P}from"./EVM_NETWORKS-C5yyzK27.mjs";import{toReceipt as E}from"./toPaymentEventRow-DTXuTDh0.mjs";import{createFacilitatorClient as H}from"./createFacilitatorClient-piLSnKs5.mjs";const S=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 import("@x402/evm/exact/server");a(t,{networks:[s]})}else{const{registerExactSvmScheme:a}=await import("@x402/svm/exact/server");a(t,{networks:[s]})}return t},T="X-PAYMENT",A=e=>{const r=Object.create(null);for(const[t,s]of e)r[t]=s;return r},R=(e,r,t,s)=>{if(e!==void 0)try{const a=Promise.resolve(e(E(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})},g=(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 S(e),a=new k(s,{...U(e),...r});await a.initialize();const i=t?.settleBeforeHandler??!0;return{handle:async(c,p,y)=>{const v=new URL(c.url),d={adapter:j(c,v),method:c.method,path:v.pathname,paymentHeader:c.headers.get(T)??void 0},n=await a.processHTTPRequest(d);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:d});if(!o.success)return u(o.response);R(e.onReceipt,o,f,y?.waitUntil);const m=await p();return g(m,o.headers)}let h;try{h=await p()}catch(o){try{await n.cancellationDispatcher.cancel({error:o,reason:"handler_threw"})}catch(m){console.error("x402 charge: failed to cancel payment after the handler threw",m)}throw o}const l=await a.processSettlement(n.paymentPayload,n.paymentRequirements,n.declaredExtensions,{request:d,responseHeaders:A(h.headers)});return l.success?(R(e.onReceipt,l,f,y?.waitUntil),g(h,l.headers)):u(l.response)}}};export{U as buildRoute,B as createChargeMiddleware,j as createRequestAdapter,R as reportReceipt,b as resolvePayTo,u as toResponse,g 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-dGcAqjXx.mjs";import{registerWallet as P}from"./registerWallet-BANE2x02.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 d}from"./createChargeMiddleware-maSEWe6e.mjs";const l=n=>{const r=new Map;return async(a,e,i,o)=>{let t=r.get(e.functionPath);return t===void 0&&(t=d({...n,price:e.price},{resource:e.functionPath}).catch(c=>{throw r.delete(e.functionPath),c}),r.set(e.functionPath,t)),(await t).handle(a,i,o)}};export{l as createProcedureChargeGate};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ProcessSettleSuccessResponse } from '@x402/core/http';
|
|
1
2
|
import { ClientEvmSigner } from '@x402/evm';
|
|
2
3
|
import { ClientSvmSigner } from '@x402/svm';
|
|
3
|
-
import { ProcessSettleSuccessResponse } from '@x402/core/http';
|
|
4
4
|
import { BeforePaymentCreationHook, PaymentPolicy, OnPaymentCreationFailureHook } from '@x402/core/client';
|
|
5
5
|
import { PaymentRequirements } from '@x402/core/types';
|
|
6
6
|
/**
|
|
@@ -469,4 +469,4 @@ type X402SignerConfig = X402CdpSignerConfig | {
|
|
|
469
469
|
* @experimental
|
|
470
470
|
*/
|
|
471
471
|
declare const resolveFacilitatorUrl: (facilitator?: FacilitatorConfig) => string;
|
|
472
|
-
export { AllowedAsset as A, Caip2 as C,
|
|
472
|
+
export { AllowedAsset as A, Caip2 as C, DEFAULT_ALLOWED_ASSETS as D, EvmAddress as E, FacilitatorConfig as F, NETWORK_TO_CAIP2 as N, PaymentEventRow as P, SpendPolicy as S, X402PayConfig as X, DEFAULT_FACILITATOR_URL as a, DEFAULT_STABLECOIN_DECIMALS as b, SpendState as c, X402CdpSignerConfig as d, X402Network as e, X402Price as f, X402SignerConfig as g, assertBoundedPolicy as h, buildPaymentGuard as i, buildSpendPolicy as j, createSpendState as k, isEvmNetwork as l, isSvmNetwork as m, resolveFacilitatorUrl as n, X402ChargeConfig as o, X402Receipt as p, X402ReceiptSink as q, releaseSpendOnFailure as r, X402Recipient as s, toCaip2 as t, usdToAtomic as u, toPaymentEventRow as v, toReceipt as w, EVM_NETWORKS as x, FriendlyNetwork as y, SVM_NETWORKS as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { ProcessSettleSuccessResponse } from '@x402/core/http';
|
|
1
2
|
import { ClientEvmSigner } from '@x402/evm';
|
|
2
3
|
import { ClientSvmSigner } from '@x402/svm';
|
|
3
|
-
import { ProcessSettleSuccessResponse } from '@x402/core/http';
|
|
4
4
|
import { BeforePaymentCreationHook, PaymentPolicy, OnPaymentCreationFailureHook } from '@x402/core/client';
|
|
5
5
|
import { PaymentRequirements } from '@x402/core/types';
|
|
6
6
|
/**
|
|
@@ -469,4 +469,4 @@ type X402SignerConfig = X402CdpSignerConfig | {
|
|
|
469
469
|
* @experimental
|
|
470
470
|
*/
|
|
471
471
|
declare const resolveFacilitatorUrl: (facilitator?: FacilitatorConfig) => string;
|
|
472
|
-
export { AllowedAsset as A, Caip2 as C,
|
|
472
|
+
export { AllowedAsset as A, Caip2 as C, DEFAULT_ALLOWED_ASSETS as D, EvmAddress as E, FacilitatorConfig as F, NETWORK_TO_CAIP2 as N, PaymentEventRow as P, SpendPolicy as S, X402PayConfig as X, DEFAULT_FACILITATOR_URL as a, DEFAULT_STABLECOIN_DECIMALS as b, SpendState as c, X402CdpSignerConfig as d, X402Network as e, X402Price as f, X402SignerConfig as g, assertBoundedPolicy as h, buildPaymentGuard as i, buildSpendPolicy as j, createSpendState as k, isEvmNetwork as l, isSvmNetwork as m, resolveFacilitatorUrl as n, X402ChargeConfig as o, X402Receipt as p, X402ReceiptSink as q, releaseSpendOnFailure as r, X402Recipient as s, toCaip2 as t, usdToAtomic as u, toPaymentEventRow as v, toReceipt as w, EVM_NETWORKS as x, FriendlyNetwork as y, SVM_NETWORKS as z };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as n}from"@lunora/errors";import{toCaip2 as l,isEvmNetwork as w}from"./EVM_NETWORKS-C5yyzK27.mjs";const d=/^0x[0-9a-fA-F]{64}$/,y=async(t,e)=>{const a=await t(e);if(a===void 0||a.length===0)throw new n("ENV_INVALID",`x402 pay: secret "${e}" is not set — the agent wallet has no key to sign with.`);return a},p=(t,e)=>{const a=t.address.startsWith("0x");if(e&&!a)throw new n("ENV_INVALID",`x402 pay: the supplied signer address "${t.address}" is not an EVM (0x…) address, but the network is EVM.`);if(!e&&a)throw new n("ENV_INVALID",`x402 pay: the supplied signer address "${t.address}" is an EVM (0x…) address, but the network is Solana.`)},h=async(t,e)=>{let a;try{a=await import("@coinbase/cdp-sdk")}catch{throw new n("ENV_INVALID",'x402 pay: CDP-managed custody needs the optional @coinbase/cdp-sdk peer — install it, or use "raw-key"/"signer" custody instead.')}const[c,s,r]=await Promise.all([y(e,t.apiKeyIdSecretName??"CDP_API_KEY_ID"),y(e,t.apiKeySecretName??"CDP_API_KEY_SECRET"),y(e,t.walletSecretName??"CDP_WALLET_SECRET")]);return new a.CdpClient({apiKeyId:c,apiKeySecret:s,walletSecret:r}).evm.getOrCreateAccount({name:t.account})},m=async t=>{const e=t.startsWith("0x")?t:`0x${t}`;if(!d.test(e))throw new n("ENV_INVALID","x402 pay: the EVM wallet key must be a 32-byte hex private key (64 hex chars, optional 0x prefix).");const{privateKeyToAccount:a}=await import("viem/accounts");return a(e)},u=async t=>{const e=t.trim(),{createKeyPairSignerFromBytes:a,createKeyPairSignerFromPrivateKeyBytes:c,getBase58Encoder:s}=await import("@solana/kit");let r;if(e.startsWith("[")){let o;try{o=JSON.parse(e)}catch{throw new n("ENV_INVALID","x402 pay: the Solana wallet key looks like a JSON byte array but is not valid JSON.")}if(!Array.isArray(o)||o.some(i=>typeof i!="number"))throw new n("ENV_INVALID","x402 pay: the Solana wallet key JSON must be an array of byte values.");r=Uint8Array.from(o)}else try{r=Uint8Array.from(s().encode(e))}catch{throw new n("ENV_INVALID","x402 pay: the Solana wallet key must be a base58 secret key or a JSON byte array.")}if(r.length===64)return a(r);if(r.length===32)return c(r);throw new n("ENV_INVALID",`x402 pay: the Solana wallet key must decode to 32 or 64 bytes (got ${String(r.length)}). Provide a base58 secret key or a JSON byte array.`)},S=async(t,e,a)=>{const c=l(e.network),{signer:s}=e,r=w(e.network);let o;if(s.type==="signer")p(s.signer,r),o=s.signer;else if(s.type==="cdp"){if(!r)throw new n("NOT_IMPLEMENTED",`x402 pay: CDP-managed Solana custody (account "${s.account}") is not wired — a CDP Solana account is not a @solana/kit signer. Build a @solana/kit signer around it and pass it via the { type: "signer" } escape hatch, or use "raw-key".`);o=await h(s,a.getSecret)}else{const i=await y(a.getSecret,s.secretName);o=r?await m(i):await u(i)}if(r){const{registerExactEvmScheme:i}=await import("@x402/evm/exact/client");i(t,{networks:[c],signer:o})}else{const{registerExactSvmScheme:i}=await import("@x402/svm/exact/client");i(t,{networks:[c],signer:o})}};export{S as registerWallet,m as resolveEvmAccount,u as resolveSvmSigner};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=(r,o)=>({amount:r.amount??r.requirements.amount,asset:r.requirements.asset,from:r.payer,network:r.network,resource:o.resource,to:r.requirements.payTo,ts:o.ts,tx:r.transaction}),s=r=>({processedAt:r.ts,provider:"x402",providerEventId:r.tx,type:"x402.settled"});export{s as toPaymentEventRow,e as toReceipt};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createChargeMiddleware as n}from"./createChargeMiddleware-maSEWe6e.mjs";const w=(t,a)=>{let e;return async(d,r)=>(e??=n(t).catch(i=>{throw e=void 0,i}),(await e).handle(r,()=>a(d,r)))};export{w as withX402};
|
package/dist/pay/index.d.mts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type A as AllowedAsset, type C as Caip2,
|
|
1
|
+
import { X as X402PayConfig } from "../packem_shared/index.d-BoH6uPM5.mjs";
|
|
2
|
+
export { type A as AllowedAsset, type C as Caip2, D as DEFAULT_ALLOWED_ASSETS, a as DEFAULT_FACILITATOR_URL, b as DEFAULT_STABLECOIN_DECIMALS, type S as SpendPolicy, type c as SpendState, type d as X402CdpSignerConfig, type e as X402Network, type f as X402Price, type g as X402SignerConfig, h as assertBoundedPolicy, i as buildPaymentGuard, j as buildSpendPolicy, k as createSpendState, l as isEvmNetwork, m as isSvmNetwork, r as releaseSpendOnFailure, n as resolveFacilitatorUrl, t as toCaip2, u as usdToAtomic } from "../packem_shared/index.d-BoH6uPM5.mjs";
|
|
3
3
|
import { x402Client } from '@x402/core/client';
|
|
4
4
|
import { ClientSvmSigner } from '@x402/svm';
|
|
5
5
|
import { PrivateKeyAccount } from 'viem/accounts';
|
|
6
|
-
import '@x402/evm';
|
|
7
6
|
import '@x402/core/http';
|
|
7
|
+
import '@x402/evm';
|
|
8
8
|
import '@x402/core/types';
|
|
9
9
|
/** Reads a secret by name; resolves `undefined` when unset. */
|
|
10
10
|
type GetSecret = (name: string) => Promise<string | undefined> | string | undefined;
|
package/dist/pay/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type A as AllowedAsset, type C as Caip2,
|
|
1
|
+
import { X as X402PayConfig } from "../packem_shared/index.d-BoH6uPM5.js";
|
|
2
|
+
export { type A as AllowedAsset, type C as Caip2, D as DEFAULT_ALLOWED_ASSETS, a as DEFAULT_FACILITATOR_URL, b as DEFAULT_STABLECOIN_DECIMALS, type S as SpendPolicy, type c as SpendState, type d as X402CdpSignerConfig, type e as X402Network, type f as X402Price, type g as X402SignerConfig, h as assertBoundedPolicy, i as buildPaymentGuard, j as buildSpendPolicy, k as createSpendState, l as isEvmNetwork, m as isSvmNetwork, r as releaseSpendOnFailure, n as resolveFacilitatorUrl, t as toCaip2, u as usdToAtomic } from "../packem_shared/index.d-BoH6uPM5.js";
|
|
3
3
|
import { x402Client } from '@x402/core/client';
|
|
4
4
|
import { ClientSvmSigner } from '@x402/svm';
|
|
5
5
|
import { PrivateKeyAccount } from 'viem/accounts';
|
|
6
|
-
import '@x402/evm';
|
|
7
6
|
import '@x402/core/http';
|
|
7
|
+
import '@x402/evm';
|
|
8
8
|
import '@x402/core/types';
|
|
9
9
|
/** Reads a secret by name; resolves `undefined` when unset. */
|
|
10
10
|
type GetSecret = (name: string) => Promise<string | undefined> | string | undefined;
|
package/dist/pay/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createPayFetch as c}from"../packem_shared/createPayFetch-
|
|
1
|
+
import{createPayFetch as c}from"../packem_shared/createPayFetch-rMvWpF_k.mjs";import{DEFAULT_FACILITATOR_URL as f,resolveFacilitatorUrl as p}from"../packem_shared/DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs";import{isEvmNetwork as d,isSvmNetwork as y,toCaip2 as E}from"../packem_shared/EVM_NETWORKS-C5yyzK27.mjs";import{DEFAULT_ALLOWED_ASSETS as T,DEFAULT_STABLECOIN_DECIMALS as v,assertBoundedPolicy as F,buildPaymentGuard as P,buildSpendPolicy as h,createSpendState as _,releaseSpendOnFailure as x,usdToAtomic as D}from"../packem_shared/DEFAULT_ALLOWED_ASSETS-dGcAqjXx.mjs";import{registerWallet as w,resolveEvmAccount as C,resolveSvmSigner as I}from"../packem_shared/registerWallet-BANE2x02.mjs";const i=async(e,t)=>({fetch:await c(e,t)}),m=(e,t)=>{let r;return{fetch:async(o,a)=>(r??=i(e,t),(await r).fetch(o,a))}};export{T as DEFAULT_ALLOWED_ASSETS,f as DEFAULT_FACILITATOR_URL,v as DEFAULT_STABLECOIN_DECIMALS,F as assertBoundedPolicy,P as buildPaymentGuard,h as buildSpendPolicy,c as createPayFetch,_ as createSpendState,i as createX402Pay,d as isEvmNetwork,y as isSvmNetwork,m as lazyX402Pay,w as registerWallet,x as releaseSpendOnFailure,C as resolveEvmAccount,p as resolveFacilitatorUrl,I as resolveSvmSigner,E as toCaip2,D as usdToAtomic};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/x402",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.38",
|
|
4
4
|
"description": "Agentic payments (x402) for Lunora: charge agents per request (charge rail) and let your agents pay x402-gated resources (pay rail)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
55
|
+
"@lunora/errors": "1.0.0-alpha.22",
|
|
56
56
|
"@solana/kit": "7.0.0",
|
|
57
|
-
"@x402/core": "2.
|
|
58
|
-
"@x402/evm": "2.
|
|
59
|
-
"@x402/fetch": "2.
|
|
60
|
-
"@x402/svm": "2.
|
|
61
|
-
"viem": "2.55.
|
|
57
|
+
"@x402/core": "2.21.0",
|
|
58
|
+
"@x402/evm": "2.21.0",
|
|
59
|
+
"@x402/fetch": "2.21.0",
|
|
60
|
+
"@x402/svm": "2.21.0",
|
|
61
|
+
"viem": "2.55.13"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"@coinbase/cdp-sdk": ">=1.0.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const r="https://x402.org/facilitator",o=t=>t?.url??r;export{r as DEFAULT_FACILITATOR_URL,o as resolveFacilitatorUrl};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const i={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"},r=["arbitrum","arbitrum-sepolia","base","base-sepolia","ethereum","polygon"],s=["solana","solana-devnet"],o=a=>{const e=i[a];if(e!==void 0)return e;if(a.includes(":"))return a;throw new Error(`Unknown x402 network "${a}". Use a friendly name (${r.join(", ")}, ${s.join(", ")}) or a raw CAIP-2 id.`)},t=a=>o(a).startsWith("eip155:"),n=a=>o(a).startsWith("solana:");export{r as EVM_NETWORKS,i as NETWORK_TO_CAIP2,s as SVM_NETWORKS,t as isEvmNetwork,n as isSvmNetwork,o as toCaip2};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{x402HTTPResourceServer as P}from"@x402/core/http";import{toCaip2 as v,isEvmNetwork as x}from"./EVM_NETWORKS-XOms9Rtk.mjs";import{toReceipt as H}from"./toPaymentEventRow-D_kRVcb3.mjs";import{createFacilitatorClient as k}from"./createFacilitatorClient-Dj4Ll9xQ.mjs";const T=async e=>{const{x402ResourceServer:r}=await import("@x402/core/server"),t=new r(k(e.facilitator)),s=v(e.network);if(x(e.network)){const{registerExactEvmScheme:a}=await import("@x402/evm/exact/server");a(t,{networks:[s]})}else{const{registerExactSvmScheme:a}=await import("@x402/svm/exact/server");a(t,{networks:[s]})}return t},S="X-PAYMENT",E=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(H(r,{resource:t,ts:Date.now()}))).catch(()=>{});s?.(a)}catch{}},b=e=>{const r=x(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},q=e=>({accepts:{network:v(e.network),payTo:b(e),price:e.price,scheme:"exact"}}),A=(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,...o]=a;i!==void 0&&(t[s]=o.length>0?a:i)}return t},getUrl:()=>e.url,getUserAgent:()=>e.headers.get("user-agent")??""}),m=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})},R=(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})},O=async(e,r,t)=>{const s=await T(e),a=new P(s,{...q(e),...r});await a.initialize();const i=t?.settleBeforeHandler??!0;return{handle:async(o,h,w)=>{const y=new URL(o.url),u={adapter:A(o,y),method:o.method,path:y.pathname,paymentHeader:o.headers.get(S)??void 0},n=await a.processHTTPRequest(u);if(n.type==="no-payment-required")return h();if(n.type==="payment-error")return m(n.response);const f=r?.resource??o.url;if(i){const c=await a.processSettlement(n.paymentPayload,n.paymentRequirements,n.declaredExtensions,{request:u});if(!c.success)return m(c.response);g(e.onReceipt,c,f,w?.waitUntil);const d=await h();return R(d,c.headers)}let l;try{l=await h()}catch(c){try{await n.cancellationDispatcher.cancel({error:c,reason:"handler_threw"})}catch(d){console.error("x402 charge: failed to cancel payment after the handler threw",d)}throw c}const p=await a.processSettlement(n.paymentPayload,n.paymentRequirements,n.declaredExtensions,{request:u,responseHeaders:E(l.headers)});return p.success?(g(e.onReceipt,p,f,w?.waitUntil),R(l,p.headers)):m(p.response)}}};export{q as buildRoute,O as createChargeMiddleware,A as createRequestAdapter,g as reportReceipt,b as resolvePayTo,m as toResponse,R as withHeaders};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{HTTPFacilitatorClient as o}from"@x402/core/server";import{resolveFacilitatorUrl as i}from"./DEFAULT_FACILITATOR_URL-lUtljfJI.mjs";const s=r=>{const t=i(r);if(r?.headers===void 0)return new o({url:t});const e={...r.headers};return new o({createAuthHeaders:()=>Promise.resolve({settle:e,supported:e,verify:e}),url:t})};export{s as createFacilitatorClient};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{x402Client as l}from"@x402/core/client";import{wrapFetchWithPayment as c}from"@x402/fetch";import{assertBoundedPolicy as m,buildSpendPolicy as p,buildPaymentGuard as y,releaseSpendOnFailure as s,createSpendState as d}from"./DEFAULT_ALLOWED_ASSETS-BIIP_mdG.mjs";import{registerWallet as P}from"./registerWallet-Cu4qF5tj.mjs";const S=async(r,t)=>{m(r.policy);const i=d(),o=p(r.policy),a=y(r.policy,i),n=s(i),e=new l;return await P(e,r,t),e.registerPolicy(o),e.onBeforePaymentCreation(a),e.onPaymentCreationFailure(n),c(t.fetch??globalThis.fetch,e)};export{S as createPayFetch};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createChargeMiddleware as h}from"./createChargeMiddleware-BtNcqDSy.mjs";const d=a=>{const r=new Map;return async(c,t,n,o)=>{let e=r.get(t.functionPath);return e===void 0&&(e=h({...a,price:t.price},{resource:t.functionPath}).catch(i=>{throw r.delete(t.functionPath),i}),r.set(t.functionPath,e)),(await e).handle(c,n,o)}};export{d as createProcedureChargeGate};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as i}from"@lunora/errors";import{toCaip2 as l,isEvmNetwork as w}from"./EVM_NETWORKS-XOms9Rtk.mjs";const p=/^0x[0-9a-fA-F]{64}$/,y=async(t,e)=>{const a=await t(e);if(a===void 0||a.length===0)throw new i("ENV_INVALID",`x402 pay: secret "${e}" is not set — the agent wallet has no key to sign with.`);return a},d=(t,e)=>{const a=t.address.startsWith("0x");if(e&&!a)throw new i("ENV_INVALID",`x402 pay: the supplied signer address "${t.address}" is not an EVM (0x…) address, but the network is EVM.`);if(!e&&a)throw new i("ENV_INVALID",`x402 pay: the supplied signer address "${t.address}" is an EVM (0x…) address, but the network is Solana.`)},h=async(t,e)=>{let a;try{a=await import("@coinbase/cdp-sdk")}catch{throw new i("ENV_INVALID",'x402 pay: CDP-managed custody needs the optional @coinbase/cdp-sdk peer — install it, or use "raw-key"/"signer" custody instead.')}const[c,s,r]=await Promise.all([y(e,t.apiKeyIdSecretName??"CDP_API_KEY_ID"),y(e,t.apiKeySecretName??"CDP_API_KEY_SECRET"),y(e,t.walletSecretName??"CDP_WALLET_SECRET")]);return new a.CdpClient({apiKeyId:c,apiKeySecret:s,walletSecret:r}).evm.getOrCreateAccount({name:t.account})},m=async t=>{const e=t.startsWith("0x")?t:`0x${t}`;if(!p.test(e))throw new i("ENV_INVALID","x402 pay: the EVM wallet key must be a 32-byte hex private key (64 hex chars, optional 0x prefix).");const{privateKeyToAccount:a}=await import("viem/accounts");return a(e)},g=async t=>{const e=t.trim(),{createKeyPairSignerFromBytes:a,createKeyPairSignerFromPrivateKeyBytes:c,getBase58Encoder:s}=await import("@solana/kit");let r;if(e.startsWith("[")){let n;try{n=JSON.parse(e)}catch{throw new i("ENV_INVALID","x402 pay: the Solana wallet key looks like a JSON byte array but is not valid JSON.")}if(!Array.isArray(n)||n.some(o=>typeof o!="number"))throw new i("ENV_INVALID","x402 pay: the Solana wallet key JSON must be an array of byte values.");r=Uint8Array.from(n)}else try{r=Uint8Array.from(s().encode(e))}catch{throw new i("ENV_INVALID","x402 pay: the Solana wallet key must be a base58 secret key or a JSON byte array.")}if(r.length===64)return a(r);if(r.length===32)return c(r);throw new i("ENV_INVALID",`x402 pay: the Solana wallet key must decode to 32 or 64 bytes (got ${String(r.length)}). Provide a base58 secret key or a JSON byte array.`)},E=async(t,e,a)=>{const c=l(e.network),{signer:s}=e,r=w(e.network);let n;if(s.type==="signer")d(s.signer,r),n=s.signer;else if(s.type==="cdp"){if(!r)throw new i("NOT_IMPLEMENTED",`x402 pay: CDP-managed Solana custody (account "${s.account}") is not wired — a CDP Solana account is not a @solana/kit signer. Build a @solana/kit signer around it and pass it via the { type: "signer" } escape hatch, or use "raw-key".`);n=await h(s,a.getSecret)}else{const o=await y(a.getSecret,s.secretName);n=r?await m(o):await g(o)}if(r){const{registerExactEvmScheme:o}=await import("@x402/evm/exact/client");o(t,{networks:[c],signer:n})}else{const{registerExactSvmScheme:o}=await import("@x402/svm/exact/client");o(t,{networks:[c],signer:n})}};export{E as registerWallet,m as resolveEvmAccount,g as resolveSvmSigner};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const r=(t,e)=>({amount:t.amount??t.requirements.amount,asset:t.requirements.asset,from:t.payer,network:t.network,resource:e.resource,to:t.requirements.payTo,ts:e.ts,tx:t.transaction}),o=t=>({processedAt:t.ts,provider:"x402",providerEventId:t.tx,type:"x402.settled"});export{o as toPaymentEventRow,r as toReceipt};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createChargeMiddleware as h}from"./createChargeMiddleware-BtNcqDSy.mjs";const d=(t,a)=>{let e;return async(o,r)=>(e??=h(t).catch(c=>{throw e=void 0,c}),(await e).handle(r,()=>a(o,r)))};export{d as withX402};
|