@lunora/x402 1.0.0-alpha.7 → 1.0.0-alpha.9
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/packem_shared/DEFAULT_STABLECOIN_DECIMALS-gY9zXmGa.mjs +1 -0
- package/dist/packem_shared/{createPayFetch-C4UrAY7P.mjs → createPayFetch-CDZJaS13.mjs} +1 -1
- package/dist/pay/index.mjs +1 -1
- package/package.json +1 -1
- package/dist/packem_shared/DEFAULT_STABLECOIN_DECIMALS-dzQLLL1Z.mjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
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 +1 @@
|
|
|
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-
|
|
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};
|
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-CDZJaS13.mjs";import{DEFAULT_FACILITATOR_URL as p,resolveFacilitatorUrl as d}from"../packem_shared/DEFAULT_FACILITATOR_URL-lUtljfJI.mjs";import{isEvmNetwork as S,isSvmNetwork as f,toCaip2 as u}from"../packem_shared/EVM_NETWORKS-XOms9Rtk.mjs";import{DEFAULT_STABLECOIN_DECIMALS as v,assertBoundedPolicy as E,buildPaymentGuard as F,buildSpendPolicy as L,createSpendState as P,releaseSpendOnFailure as T,usdToAtomic as x}from"../packem_shared/DEFAULT_STABLECOIN_DECIMALS-gY9zXmGa.mjs";import{registerWallet as w,resolveEvmAccount as C,resolveSvmSigner as I}from"../packem_shared/registerWallet-Cu4qF5tj.mjs";const i=async(e,r)=>({fetch:await c(e,r)}),s=(e,r)=>{let t;return{fetch:async(o,a)=>(t??=i(e,r),(await t).fetch(o,a))}};export{p as DEFAULT_FACILITATOR_URL,v as DEFAULT_STABLECOIN_DECIMALS,E as assertBoundedPolicy,F as buildPaymentGuard,L as buildSpendPolicy,c as createPayFetch,P as createSpendState,i as createX402Pay,S as isEvmNetwork,f as isSvmNetwork,s as lazyX402Pay,w as registerWallet,T as releaseSpendOnFailure,C as resolveEvmAccount,d as resolveFacilitatorUrl,I as resolveSvmSigner,u as toCaip2,x as usdToAtomic};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as l}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,d=6,R=()=>{let e=0n;return{add:t=>{e+=t},release:t=>{e=e>t?e-t:0n},get spentAtomic(){return e}}},m=(e,t=d)=>{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(),o=n.startsWith("$")?n.slice(1):n;if(!y.test(o))throw new l("BAD_REQUEST",`x402 policy: "${String(e)}" is not a valid USD amount (use a plain decimal like "0.01").`);const[a="0",r=""]=o.split("."),i=r.slice(0,t).padEnd(t,"0");return BigInt(a)*10n**BigInt(t)+BigInt(i===""?"0":i)},v=e=>{const t=e.decimals??d,n=e.maxPerCall===void 0?void 0:m(e.maxPerCall,t),o=e.allowedNetworks?.map(r=>w(r)),{allowedRecipients:a}=e;return(r,i)=>i.filter(s=>{if(n!==void 0&&BigInt(s.amount)>n||o!==void 0&&!o.includes(s.network))return!1;if(a!==void 0){const c=u(s.payTo,s.network);return a.some(p=>u(p,s.network)===c)}return!0})},x=(e,t)=>{const n=e.decimals??d,o=e.maxPerRun===void 0?void 0:m(e.maxPerRun,n);return async a=>{const r=a.selectedRequirements,i=BigInt(r.amount);if(o!==void 0&&t.spentAtomic+i>o)return{abort:!0,reason:`x402 policy: this payment (${r.amount}) would exceed the per-run cap (already spent ${t.spentAtomic.toString()}, cap ${o.toString()}, in atomic base units).`};if(t.add(i),e.onPaymentRequired!==void 0&&!await e.onPaymentRequired(r))return t.release(i),{abort:!0,reason:"x402 policy: payment was declined by onPaymentRequired."}}},S=e=>t=>(e.release(BigInt(t.selectedRequirements.amount)),Promise.resolve()),f=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 narrow but do not bound spend).")};export{d as DEFAULT_STABLECOIN_DECIMALS,f as assertBoundedPolicy,x as buildPaymentGuard,v as buildSpendPolicy,R as createSpendState,S as releaseSpendOnFailure,m as usdToAtomic};
|