@lunora/x402 1.0.0-alpha.9 → 1.0.0-alpha.90
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 +18 -0
- package/README.md +22 -4
- package/dist/charge/index.d.mts +82 -47
- package/dist/charge/index.d.ts +82 -47
- package/dist/charge/index.mjs +1 -1
- package/dist/index.d.mts +2 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/DEFAULT_ALLOWED_ASSETS-CX67Ktyc.mjs +1 -0
- package/dist/packem_shared/DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs +1 -0
- package/dist/packem_shared/EVM_NETWORKS-CwbBEtp1.mjs +1 -0
- package/dist/packem_shared/createChargeMiddleware-DyOEuTCT.mjs +1 -0
- package/dist/packem_shared/createProcedureChargeGate-BidGWCmf.mjs +1 -0
- package/dist/packem_shared/{config.d-B-NYmHgG.d.ts → index.d-A-g7yKuO.d.mts} +122 -130
- package/dist/packem_shared/{config.d-B-NYmHgG.d.mts → index.d-A-g7yKuO.d.ts} +122 -130
- package/dist/packem_shared/optional-peer-BBhVxozi.mjs +1 -0
- package/dist/packem_shared/toPaymentEventRow-DTXuTDh0.mjs +1 -0
- package/dist/packem_shared/withX402-mUrRb9a2.mjs +1 -0
- package/dist/pay/index.d.mts +9 -58
- package/dist/pay/index.d.ts +9 -58
- package/dist/pay/index.mjs +1 -1
- package/package.json +21 -9
- package/dist/packem_shared/DEFAULT_FACILITATOR_URL-lUtljfJI.mjs +0 -1
- package/dist/packem_shared/DEFAULT_STABLECOIN_DECIMALS-gY9zXmGa.mjs +0 -1
- package/dist/packem_shared/EVM_NETWORKS-XOms9Rtk.mjs +0 -1
- package/dist/packem_shared/createChargeMiddleware-MQhSA6Wt.mjs +0 -1
- package/dist/packem_shared/createFacilitatorClient-Dj4Ll9xQ.mjs +0 -1
- package/dist/packem_shared/createPayFetch-CDZJaS13.mjs +0 -1
- package/dist/packem_shared/createProcedureChargeGate-Cfm5mD2y.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-D10895ct.mjs +0 -1
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.90",
|
|
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.
|
|
56
|
-
"@
|
|
57
|
-
"@x402/
|
|
58
|
-
"@x402/evm": "2.19.0",
|
|
59
|
-
"@x402/fetch": "2.19.0",
|
|
60
|
-
"@x402/svm": "2.19.0",
|
|
61
|
-
"viem": "2.55.8"
|
|
55
|
+
"@lunora/errors": ">=1.0.0-alpha.51 <2.0.0-0",
|
|
56
|
+
"@x402/core": "2.28.0",
|
|
57
|
+
"@x402/fetch": "2.28.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
|
-
const r="https://x402.org/facilitator",o=t=>t?.url??r;export{r as DEFAULT_FACILITATOR_URL,o as resolveFacilitatorUrl};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as s}from"@lunora/errors";import{toCaip2 as w}from"./EVM_NETWORKS-XOms9Rtk.mjs";const y=/^\d+(?:\.\d+)?$/,u=(e,t)=>t.startsWith("eip155:")?e.toLowerCase():e,l=6,v=()=>{let e=0n;return{add:t=>{e+=t},release:t=>{e=e>t?e-t:0n},get spentAtomic(){return e}}},m=(e,t=l)=>{if(!Number.isInteger(t)||t<0)throw new s("BAD_REQUEST",`x402 policy: decimals must be a non-negative integer, got ${String(t)}.`);const n=(typeof e=="number"?e.toString():e).trim(),o=n.startsWith("$")?n.slice(1):n;if(!y.test(o))throw new s("BAD_REQUEST",`x402 policy: "${String(e)}" is not a valid USD amount (use a plain decimal like "0.01").`);const[d="0",i=""]=o.split("."),r=i.slice(0,t).padEnd(t,"0");return BigInt(d)*10n**BigInt(t)+BigInt(r===""?"0":r)},R=e=>{const t=e.decimals??l,n=e.maxPerCall===void 0?void 0:m(e.maxPerCall,t),o=e.allowedNetworks?.map(i=>w(i)),{allowedRecipients:d}=e;return(i,r)=>r.filter(a=>{if(n!==void 0&&BigInt(a.amount)>n||o!==void 0&&!o.includes(a.network))return!1;if(d!==void 0){const c=u(a.payTo,a.network);return d.some(p=>u(p,a.network)===c)}return!0})},x=(e,t)=>{const n=e.decimals??l,o=e.maxPerRun===void 0?void 0:m(e.maxPerRun,n);return async d=>{const i=d.selectedRequirements,r=BigInt(i.amount);if(o!==void 0&&t.spentAtomic+r>o)return{abort:!0,reason:`x402 policy: this payment (${i.amount}) would exceed the per-run cap (already spent ${t.spentAtomic.toString()}, cap ${o.toString()}, in atomic base units).`};t.add(r);try{return e.onPaymentRequired!==void 0&&!await e.onPaymentRequired(i)?(t.release(r),{abort:!0,reason:"x402 policy: payment was declined by onPaymentRequired."}):void 0}catch(a){throw t.release(r),a}}},S=e=>t=>(e.release(BigInt(t.selectedRequirements.amount)),Promise.resolve()),b=e=>{if(!(e.maxPerCall!==void 0||e.maxPerRun!==void 0||e.onPaymentRequired!==void 0))throw new s("FORBIDDEN","x402 pay: refusing to build a wallet with an unbounded spend policy. Set at least one of maxPerCall, maxPerRun, or onPaymentRequired (allowedNetworks/allowedRecipients narrow but do not bound spend).")};export{l as DEFAULT_STABLECOIN_DECIMALS,b as assertBoundedPolicy,x as buildPaymentGuard,R as buildSpendPolicy,v as createSpendState,S as releaseSpendOnFailure,m as usdToAtomic};
|
|
@@ -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??!1;return{handle:async(o,h,w)=>{const y=new URL(o.url),l={adapter:A(o,y),method:o.method,path:y.pathname,paymentHeader:o.headers.get(S)??void 0},n=await a.processHTTPRequest(l);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:l});if(!c.success)return m(c.response);g(e.onReceipt,c,f,w?.waitUntil);const d=await h();return R(d,c.headers)}let u;try{u=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:l,responseHeaders:E(u.headers)});return p.success?(g(e.onReceipt,p,f,w?.waitUntil),R(u,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 i}from"@x402/core/client";import{wrapFetchWithPayment as a}from"@x402/fetch";import{assertBoundedPolicy as n,buildSpendPolicy as c,buildPaymentGuard as l,releaseSpendOnFailure as m,createSpendState as p}from"./DEFAULT_STABLECOIN_DECIMALS-gY9zXmGa.mjs";import{registerWallet as y}from"./registerWallet-Cu4qF5tj.mjs";const u=async(r,t)=>{n(r.policy);const e=new i;await y(e,r,t);const o=p();return e.registerPolicy(c(r.policy)),e.onBeforePaymentCreation(l(r.policy,o)),e.onPaymentCreationFailure(m(o)),a(t.fetch??globalThis.fetch,e)};export{u as createPayFetch};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createChargeMiddleware as h}from"./createChargeMiddleware-MQhSA6Wt.mjs";const d=a=>{const r=new Map;return async(n,e,c,o)=>{let t=r.get(e.functionPath);return t===void 0&&(t=h({...a,price:e.price},{resource:e.functionPath},{settleBeforeHandler:!0}).catch(i=>{throw r.delete(e.functionPath),i}),r.set(e.functionPath,t)),(await t).handle(n,c,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-MQhSA6Wt.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};
|