@lunora/x402 1.0.0-alpha.37 → 1.0.0-alpha.39

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/LICENSE.md CHANGED
@@ -108,4 +108,22 @@ specific language governing permissions and limitations under the License.
108
108
  <!-- /DEPENDENCIES -->
109
109
 
110
110
  <!-- TYPE_DEPENDENCIES -->
111
+
112
+ # Licenses of bundled types
113
+ The published @lunora/x402 artifact additionally contains code with the following licenses:
114
+ Apache-2.0
115
+
116
+ # Bundled types:
117
+ ## @x402/evm
118
+ License: Apache-2.0
119
+ By: x402 Foundation
120
+ Repository: https://github.com/x402-foundation/x402
121
+
122
+ ---------------------------------------
123
+
124
+ ## @x402/svm
125
+ License: Apache-2.0
126
+ By: x402 Foundation
127
+ Repository: https://github.com/x402-foundation/x402
128
+
111
129
  <!-- /TYPE_DEPENDENCIES -->
package/README.md CHANGED
@@ -25,6 +25,24 @@ The root export (`@lunora/x402`) carries only the shared config/types
25
25
  (`.x402({ price })`), and MCP tools behind a USDC price; the **pay** rail signs and
26
26
  retries `402` challenges under a mandatory spend policy.
27
27
 
28
+ ## Install
29
+
30
+ The chain toolchains are **optional peers**, so an EVM-only deployment never
31
+ installs Solana's (heavy) toolchain and vice versa. Install the pair your
32
+ network family needs alongside the package:
33
+
34
+ ```bash
35
+ pnpm add @lunora/x402 # protocol core only
36
+ pnpm add @x402/evm viem # + EVM networks (Base, Arbitrum, …)
37
+ pnpm add @x402/svm @solana/kit # + Solana networks
38
+ pnpm add @coinbase/cdp-sdk # + CDP-managed custody (EVM)
39
+ ```
40
+
41
+ Missing a peer fails with an `ENV_INVALID` error naming exactly what to install.
42
+ Note that TypeScript needs the same peers present to resolve the pay rail's
43
+ signer types (`ClientSvmSigner` resolves through `@solana/kit`); with neither
44
+ family installed, compile the package's declarations under `skipLibCheck`.
45
+
28
46
  ## Networks & custody
29
47
 
30
48
  - **EVM** (Base, Arbitrum, Ethereum, Polygon, …) is signed via [`@x402/evm`](https://npmjs.com/package/@x402/evm) + [viem](https://viem.sh); pass a raw CAIP-2 id for chains without a friendly alias.
@@ -1,5 +1,5 @@
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,
1
+ import { F as FacilitatorConfig, q as X402ChargeConfig, h as X402Price } from "../packem_shared/index.d-CzQaqaP6.mjs";
2
+ export { type b as Caip2, c as DEFAULT_FACILITATOR_URL,
3
3
  /**
4
4
  * `@lunora/x402/charge` — the charge rail (server side).
5
5
  *
@@ -11,7 +11,7 @@ export { type C as Caip2, a as DEFAULT_FACILITATOR_URL,
11
11
  * `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
12
12
  * framework-agnostic core for other surfaces (procedures, MCP tools).
13
13
  */
14
- type E as EvmAddress, type P as PaymentEventRow, type e as X402Network, type p as X402Receipt, type q as X402ReceiptSink,
14
+ type E as EvmAddress, type P as PaymentEventRow, type g as X402Network, type s as X402Receipt, type v as X402ReceiptSink,
15
15
  /**
16
16
  * `@lunora/x402/charge` — the charge rail (server side).
17
17
  *
@@ -23,13 +23,12 @@ type E as EvmAddress, type P as PaymentEventRow, type e as X402Network, type p a
23
23
  * `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
24
24
  * framework-agnostic core for other surfaces (procedures, MCP tools).
25
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";
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.mjs";
27
27
  import { HTTPFacilitatorClient } from '@x402/core/server';
28
28
  import { RouteConfig } from '@x402/core/http';
29
- import '@x402/evm';
30
- import '@x402/svm';
31
29
  import '@x402/core/client';
32
30
  import '@x402/core/types';
31
+ import '@solana/accounts';
33
32
  /**
34
33
  * Build an `@x402/core` facilitator client from Lunora's {@link FacilitatorConfig}.
35
34
  *
@@ -1,5 +1,5 @@
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,
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
3
  /**
4
4
  * `@lunora/x402/charge` — the charge rail (server side).
5
5
  *
@@ -11,7 +11,7 @@ export { type C as Caip2, a as DEFAULT_FACILITATOR_URL,
11
11
  * `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
12
12
  * framework-agnostic core for other surfaces (procedures, MCP tools).
13
13
  */
14
- type E as EvmAddress, type P as PaymentEventRow, type e as X402Network, type p as X402Receipt, type q as X402ReceiptSink,
14
+ type E as EvmAddress, type P as PaymentEventRow, type g as X402Network, type s as X402Receipt, type v as X402ReceiptSink,
15
15
  /**
16
16
  * `@lunora/x402/charge` — the charge rail (server side).
17
17
  *
@@ -23,13 +23,12 @@ type E as EvmAddress, type P as PaymentEventRow, type e as X402Network, type p a
23
23
  * `withX402` gates a Lunora HTTP action; `createChargeMiddleware` is the
24
24
  * framework-agnostic core for other surfaces (procedures, MCP tools).
25
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";
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";
27
27
  import { HTTPFacilitatorClient } from '@x402/core/server';
28
28
  import { RouteConfig } from '@x402/core/http';
29
- import '@x402/evm';
30
- import '@x402/svm';
31
29
  import '@x402/core/client';
32
30
  import '@x402/core/types';
31
+ import '@solana/accounts';
33
32
  /**
34
33
  * Build an `@x402/core` facilitator client from Lunora's {@link FacilitatorConfig}.
35
34
  *
@@ -1 +1 @@
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};
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-Bcvz7RqY.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, 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";
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";
2
2
  import '@x402/core/http';
3
- import '@x402/evm';
4
- import '@x402/svm';
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, 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";
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";
2
2
  import '@x402/core/http';
3
- import '@x402/evm';
4
- import '@x402/svm';
5
3
  import '@x402/core/client';
6
4
  import '@x402/core/types';
5
+ import '@solana/accounts';
@@ -1 +1 @@
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};
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
+ 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};
@@ -1 +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};
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};
@@ -1 +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
+ import{createChargeMiddleware as d}from"./createChargeMiddleware-CURPSr23.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,8 +1,69 @@
1
1
  import { ProcessSettleSuccessResponse } from '@x402/core/http';
2
- import { ClientEvmSigner } from '@x402/evm';
3
- import { ClientSvmSigner } from '@x402/svm';
4
2
  import { BeforePaymentCreationHook, PaymentPolicy, OnPaymentCreationFailureHook } from '@x402/core/client';
5
3
  import { PaymentRequirements } from '@x402/core/types';
4
+ import { TransactionSigner } from '@solana/accounts';
5
+ /**
6
+ * ClientEvmSigner - Used by x402 clients to sign payment authorizations.
7
+ *
8
+ * Typically a viem LocalAccount:
9
+ * ```typescript
10
+ * const account = privateKeyToAccount('0x...');
11
+ * ```
12
+ *
13
+ * Or composed via `toClientEvmSigner(account, publicClient)`.
14
+ */
15
+ type ClientEvmSigner = {
16
+ readonly address: `0x${string}`;
17
+ signTypedData(message: {
18
+ domain: Record<string, unknown>;
19
+ types: Record<string, unknown>;
20
+ primaryType: string;
21
+ message: Record<string, unknown>;
22
+ }): Promise<`0x${string}`>;
23
+ /**
24
+ * Optional on-chain reads.
25
+ * Required only for extension enrichment (EIP-2612 / ERC-20 approval).
26
+ */
27
+ readContract?(args: {
28
+ address: `0x${string}`;
29
+ abi: readonly unknown[];
30
+ functionName: string;
31
+ args?: readonly unknown[];
32
+ }): Promise<unknown>;
33
+ /**
34
+ * Optional: Signs a raw EIP-1559 transaction without broadcasting.
35
+ * Required for ERC-20 approval gas sponsoring when the token lacks EIP-2612.
36
+ */
37
+ signTransaction?(args: {
38
+ to: `0x${string}`;
39
+ data: `0x${string}`;
40
+ nonce: number;
41
+ gas: bigint;
42
+ maxFeePerGas: bigint;
43
+ maxPriorityFeePerGas: bigint;
44
+ chainId: number;
45
+ }): Promise<`0x${string}`>;
46
+ /**
47
+ * Optional: Gets the current transaction count (nonce) for an address.
48
+ * Required for ERC-20 approval gas sponsoring.
49
+ */
50
+ getTransactionCount?(args: {
51
+ address: `0x${string}`;
52
+ }): Promise<number>;
53
+ /**
54
+ * Optional: Estimates current gas fees per gas.
55
+ * Required for ERC-20 approval gas sponsoring.
56
+ */
57
+ estimateFeesPerGas?(): Promise<{
58
+ maxFeePerGas: bigint;
59
+ maxPriorityFeePerGas: bigint;
60
+ }>;
61
+ };
62
+ /**
63
+ * Client-side signer for creating and signing Solana transactions
64
+ * This is a wrapper around TransactionSigner from @solana/kit
65
+ */
66
+ type ClientSvmSigner = TransactionSigner;
6
67
  /**
7
68
  * A normalised record of one settled x402 payment. The settled `amount` is kept
8
69
  * as its exact on-chain atomic-unit string (USDC has 6 decimals) — never coerced
@@ -469,4 +530,4 @@ type X402SignerConfig = X402CdpSignerConfig | {
469
530
  * @experimental
470
531
  */
471
532
  declare const resolveFacilitatorUrl: (facilitator?: FacilitatorConfig) => string;
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 };
533
+ export { AllowedAsset as A, FriendlyNetwork as B, type ClientEvmSigner as C, DEFAULT_ALLOWED_ASSETS as D, EvmAddress as E, type FacilitatorConfig as F, SVM_NETWORKS as G, NETWORK_TO_CAIP2 as N, PaymentEventRow as P, type SpendPolicy as S, X402PayConfig as X, ClientSvmSigner as a, Caip2 as b, type DEFAULT_FACILITATOR_URL as c, type DEFAULT_STABLECOIN_DECIMALS as d, SpendState as e, X402CdpSignerConfig as f, X402Network as g, X402Price as h, X402SignerConfig as i, assertBoundedPolicy as j, buildPaymentGuard as k, buildSpendPolicy as l, createSpendState as m, isEvmNetwork as n, isSvmNetwork as o, resolveFacilitatorUrl as p, X402ChargeConfig as q, releaseSpendOnFailure as r, X402Receipt as s, toCaip2 as t, usdToAtomic as u, X402ReceiptSink as v, X402Recipient as w, toPaymentEventRow as x, toReceipt as y, EVM_NETWORKS as z };
@@ -1,8 +1,69 @@
1
1
  import { ProcessSettleSuccessResponse } from '@x402/core/http';
2
- import { ClientEvmSigner } from '@x402/evm';
3
- import { ClientSvmSigner } from '@x402/svm';
4
2
  import { BeforePaymentCreationHook, PaymentPolicy, OnPaymentCreationFailureHook } from '@x402/core/client';
5
3
  import { PaymentRequirements } from '@x402/core/types';
4
+ import { TransactionSigner } from '@solana/accounts';
5
+ /**
6
+ * ClientEvmSigner - Used by x402 clients to sign payment authorizations.
7
+ *
8
+ * Typically a viem LocalAccount:
9
+ * ```typescript
10
+ * const account = privateKeyToAccount('0x...');
11
+ * ```
12
+ *
13
+ * Or composed via `toClientEvmSigner(account, publicClient)`.
14
+ */
15
+ type ClientEvmSigner = {
16
+ readonly address: `0x${string}`;
17
+ signTypedData(message: {
18
+ domain: Record<string, unknown>;
19
+ types: Record<string, unknown>;
20
+ primaryType: string;
21
+ message: Record<string, unknown>;
22
+ }): Promise<`0x${string}`>;
23
+ /**
24
+ * Optional on-chain reads.
25
+ * Required only for extension enrichment (EIP-2612 / ERC-20 approval).
26
+ */
27
+ readContract?(args: {
28
+ address: `0x${string}`;
29
+ abi: readonly unknown[];
30
+ functionName: string;
31
+ args?: readonly unknown[];
32
+ }): Promise<unknown>;
33
+ /**
34
+ * Optional: Signs a raw EIP-1559 transaction without broadcasting.
35
+ * Required for ERC-20 approval gas sponsoring when the token lacks EIP-2612.
36
+ */
37
+ signTransaction?(args: {
38
+ to: `0x${string}`;
39
+ data: `0x${string}`;
40
+ nonce: number;
41
+ gas: bigint;
42
+ maxFeePerGas: bigint;
43
+ maxPriorityFeePerGas: bigint;
44
+ chainId: number;
45
+ }): Promise<`0x${string}`>;
46
+ /**
47
+ * Optional: Gets the current transaction count (nonce) for an address.
48
+ * Required for ERC-20 approval gas sponsoring.
49
+ */
50
+ getTransactionCount?(args: {
51
+ address: `0x${string}`;
52
+ }): Promise<number>;
53
+ /**
54
+ * Optional: Estimates current gas fees per gas.
55
+ * Required for ERC-20 approval gas sponsoring.
56
+ */
57
+ estimateFeesPerGas?(): Promise<{
58
+ maxFeePerGas: bigint;
59
+ maxPriorityFeePerGas: bigint;
60
+ }>;
61
+ };
62
+ /**
63
+ * Client-side signer for creating and signing Solana transactions
64
+ * This is a wrapper around TransactionSigner from @solana/kit
65
+ */
66
+ type ClientSvmSigner = TransactionSigner;
6
67
  /**
7
68
  * A normalised record of one settled x402 payment. The settled `amount` is kept
8
69
  * as its exact on-chain atomic-unit string (USDC has 6 decimals) — never coerced
@@ -469,4 +530,4 @@ type X402SignerConfig = X402CdpSignerConfig | {
469
530
  * @experimental
470
531
  */
471
532
  declare const resolveFacilitatorUrl: (facilitator?: FacilitatorConfig) => string;
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 };
533
+ export { AllowedAsset as A, FriendlyNetwork as B, type ClientEvmSigner as C, DEFAULT_ALLOWED_ASSETS as D, EvmAddress as E, type FacilitatorConfig as F, SVM_NETWORKS as G, NETWORK_TO_CAIP2 as N, PaymentEventRow as P, type SpendPolicy as S, X402PayConfig as X, ClientSvmSigner as a, Caip2 as b, type DEFAULT_FACILITATOR_URL as c, type DEFAULT_STABLECOIN_DECIMALS as d, SpendState as e, X402CdpSignerConfig as f, X402Network as g, X402Price as h, X402SignerConfig as i, assertBoundedPolicy as j, buildPaymentGuard as k, buildSpendPolicy as l, createSpendState as m, isEvmNetwork as n, isSvmNetwork as o, resolveFacilitatorUrl as p, X402ChargeConfig as q, releaseSpendOnFailure as r, X402Receipt as s, toCaip2 as t, usdToAtomic as u, X402ReceiptSink as v, X402Recipient as w, toPaymentEventRow as x, toReceipt as y, EVM_NETWORKS as z };
@@ -0,0 +1 @@
1
+ import{LunoraError as u}from"@lunora/errors";const a=new Set(["ERR_MODULE_NOT_FOUND","MODULE_NOT_FOUND"]),i=/cannot find (?:module|package)|module not found|failed to resolve (?:module|import)/i,s=(t,o=3)=>{if(typeof t!="object"||t===null||o<0)return!1;const{cause:e,code:r,message:n}=t;return typeof r=="string"&&a.has(r)||typeof n=="string"&&i.test(n)?!0:s(e,o-1)},f=async(t,o)=>{try{return await t()}catch(e){throw s(e)?new u("ENV_INVALID",o,{cause:e}):e}};export{f as i};
@@ -0,0 +1 @@
1
+ import{LunoraError as n}from"@lunora/errors";import{toCaip2 as p,isEvmNetwork as w}from"./EVM_NETWORKS-C5yyzK27.mjs";import{i as l}from"./optional-peer-BBhVxozi.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},m=(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)=>{const{CdpClient:a}=await l(()=>import("@coinbase/cdp-sdk"),'x402 pay: CDP-managed custody needs the optional @coinbase/cdp-sdk peer — install it, or use "raw-key"/"signer" custody instead.'),[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({apiKeyId:c,apiKeySecret:s,walletSecret:r}).evm.getOrCreateAccount({name:t.account})},u=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 l(()=>import("viem/accounts"),'x402 pay: raw-key EVM custody needs the optional viem peer — install it, or use "cdp"/"signer" custody instead.');return a(e)},E=async t=>{const e=t.trim(),{createKeyPairSignerFromBytes:a,createKeyPairSignerFromPrivateKeyBytes:c,getBase58Encoder:s}=await l(()=>import("@solana/kit"),'x402 pay: raw-key Solana custody needs the optional @solana/kit peer — install it, or pass a pre-built signer via "signer" custody instead.');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.`)},x=async(t,e,a)=>{const c=p(e.network),{signer:s}=e,r=w(e.network);let o;if(s.type==="signer")m(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 u(i):await E(i)}if(r){const{registerExactEvmScheme:i}=await l(()=>import("@x402/evm/exact/client"),"x402 pay: EVM networks need the optional @x402/evm + viem peers — install them, or configure an SVM network.");i(t,{networks:[c],signer:o})}else{const{registerExactSvmScheme:i}=await l(()=>import("@x402/svm/exact/client"),"x402 pay: SVM networks need the optional @x402/svm + @solana/kit peers — install them, or configure an EVM network.");i(t,{networks:[c],signer:o})}};export{x as registerWallet,u as resolveEvmAccount,E as resolveSvmSigner};
@@ -1 +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};
1
+ import{createChargeMiddleware as n}from"./createChargeMiddleware-CURPSr23.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};
@@ -1,11 +1,9 @@
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";
1
+ import { X as X402PayConfig, C as ClientEvmSigner, a as ClientSvmSigner } from "../packem_shared/index.d-CzQaqaP6.mjs";
2
+ export { type A as AllowedAsset, type b as Caip2, D as DEFAULT_ALLOWED_ASSETS, c as DEFAULT_FACILITATOR_URL, d as DEFAULT_STABLECOIN_DECIMALS, type S as SpendPolicy, type e as SpendState, type f as X402CdpSignerConfig, type g as X402Network, type h as X402Price, type i as X402SignerConfig, j as assertBoundedPolicy, k as buildPaymentGuard, l as buildSpendPolicy, m as createSpendState, n as isEvmNetwork, o as isSvmNetwork, r as releaseSpendOnFailure, p as resolveFacilitatorUrl, t as toCaip2, u as usdToAtomic } from "../packem_shared/index.d-CzQaqaP6.mjs";
3
3
  import { x402Client } from '@x402/core/client';
4
- import { ClientSvmSigner } from '@x402/svm';
5
- import { PrivateKeyAccount } from 'viem/accounts';
6
4
  import '@x402/core/http';
7
- import '@x402/evm';
8
5
  import '@x402/core/types';
6
+ import '@solana/accounts';
9
7
  /** Reads a secret by name; resolves `undefined` when unset. */
10
8
  type GetSecret = (name: string) => Promise<string | undefined> | string | undefined;
11
9
  /**
@@ -17,12 +15,14 @@ interface WalletDeps {
17
15
  readonly getSecret: GetSecret;
18
16
  }
19
17
  /**
20
- * Resolve a viem `LocalAccount` from a raw private key. The key may be given with
21
- * or without the `0x` prefix. The account is a structural `ClientEvmSigner`
22
- * (`address` + `signTypedData`), so `@x402/evm` accepts it directly.
18
+ * Resolve a signer from a raw private key (a viem `LocalAccount` under the hood).
19
+ * The key may be given with or without the `0x` prefix. Typed as the structural
20
+ * `ClientEvmSigner` (`address` + `signTypedData`) rather than viem's own
21
+ * `PrivateKeyAccount` so the published declarations don't require the optional
22
+ * viem peer to type-check.
23
23
  * @experimental
24
24
  */
25
- declare const resolveEvmAccount: (privateKey: string) => Promise<PrivateKeyAccount>;
25
+ declare const resolveEvmAccount: (privateKey: string) => Promise<ClientEvmSigner>;
26
26
  /**
27
27
  * Resolve a `@solana/kit` `KeyPairSigner` from a raw Solana secret key. The secret
28
28
  * may be given as a JSON byte array (`[12,34,…]`, the `solana-keygen` keyfile
@@ -1,11 +1,9 @@
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";
1
+ import { X as X402PayConfig, C as ClientEvmSigner, a as ClientSvmSigner } from "../packem_shared/index.d-CzQaqaP6.js";
2
+ export { type A as AllowedAsset, type b as Caip2, D as DEFAULT_ALLOWED_ASSETS, c as DEFAULT_FACILITATOR_URL, d as DEFAULT_STABLECOIN_DECIMALS, type S as SpendPolicy, type e as SpendState, type f as X402CdpSignerConfig, type g as X402Network, type h as X402Price, type i as X402SignerConfig, j as assertBoundedPolicy, k as buildPaymentGuard, l as buildSpendPolicy, m as createSpendState, n as isEvmNetwork, o as isSvmNetwork, r as releaseSpendOnFailure, p as resolveFacilitatorUrl, t as toCaip2, u as usdToAtomic } from "../packem_shared/index.d-CzQaqaP6.js";
3
3
  import { x402Client } from '@x402/core/client';
4
- import { ClientSvmSigner } from '@x402/svm';
5
- import { PrivateKeyAccount } from 'viem/accounts';
6
4
  import '@x402/core/http';
7
- import '@x402/evm';
8
5
  import '@x402/core/types';
6
+ import '@solana/accounts';
9
7
  /** Reads a secret by name; resolves `undefined` when unset. */
10
8
  type GetSecret = (name: string) => Promise<string | undefined> | string | undefined;
11
9
  /**
@@ -17,12 +15,14 @@ interface WalletDeps {
17
15
  readonly getSecret: GetSecret;
18
16
  }
19
17
  /**
20
- * Resolve a viem `LocalAccount` from a raw private key. The key may be given with
21
- * or without the `0x` prefix. The account is a structural `ClientEvmSigner`
22
- * (`address` + `signTypedData`), so `@x402/evm` accepts it directly.
18
+ * Resolve a signer from a raw private key (a viem `LocalAccount` under the hood).
19
+ * The key may be given with or without the `0x` prefix. Typed as the structural
20
+ * `ClientEvmSigner` (`address` + `signTypedData`) rather than viem's own
21
+ * `PrivateKeyAccount` so the published declarations don't require the optional
22
+ * viem peer to type-check.
23
23
  * @experimental
24
24
  */
25
- declare const resolveEvmAccount: (privateKey: string) => Promise<PrivateKeyAccount>;
25
+ declare const resolveEvmAccount: (privateKey: string) => Promise<ClientEvmSigner>;
26
26
  /**
27
27
  * Resolve a `@solana/kit` `KeyPairSigner` from a raw Solana secret key. The secret
28
28
  * may be given as a JSON byte array (`[12,34,…]`, the `solana-keygen` keyfile
@@ -1 +1 @@
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};
1
+ import{createPayFetch as c}from"../packem_shared/createPayFetch-lyg7i3Js.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-hq1xeZL6.mjs";import{registerWallet as w,resolveEvmAccount as C,resolveSvmSigner as I}from"../packem_shared/registerWallet-DvCt0Q7M.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.37",
3
+ "version": "1.0.0-alpha.39",
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,17 +52,17 @@
52
52
  "access": "public"
53
53
  },
54
54
  "dependencies": {
55
- "@lunora/errors": "1.0.0-alpha.21",
56
- "@solana/kit": "7.0.0",
55
+ "@lunora/errors": "1.0.0-alpha.22",
57
56
  "@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"
57
+ "@x402/fetch": "2.21.0"
62
58
  },
63
59
  "peerDependencies": {
64
60
  "@coinbase/cdp-sdk": ">=1.0.0",
65
- "@coinbase/x402": ">=2.0.0"
61
+ "@coinbase/x402": ">=2.0.0",
62
+ "@solana/kit": ">=7.0.0",
63
+ "@x402/evm": ">=2.0.0",
64
+ "@x402/svm": ">=2.0.0",
65
+ "viem": ">=2.0.0"
66
66
  },
67
67
  "peerDependenciesMeta": {
68
68
  "@coinbase/cdp-sdk": {
@@ -70,6 +70,18 @@
70
70
  },
71
71
  "@coinbase/x402": {
72
72
  "optional": true
73
+ },
74
+ "@solana/kit": {
75
+ "optional": true
76
+ },
77
+ "@x402/evm": {
78
+ "optional": true
79
+ },
80
+ "@x402/svm": {
81
+ "optional": true
82
+ },
83
+ "viem": {
84
+ "optional": true
73
85
  }
74
86
  },
75
87
  "engines": {
@@ -1 +0,0 @@
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};
@@ -1 +0,0 @@
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};