@dexterai/x402 3.8.0 → 3.8.1
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/server/index.cjs +4 -4
- package/dist/server/index.js +4 -4
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var At=Object.create;var te=Object.defineProperty;var Et=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var vt=Object.getPrototypeOf,Mt=Object.prototype.hasOwnProperty;var Ct=(e,t)=>{for(var n in t)te(e,n,{get:t[n],enumerable:!0})},Ce=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of kt(t))!Mt.call(e,o)&&o!==n&&te(e,o,{get:()=>t[o],enumerable:!(r=Et(t,o))||r.enumerable});return e};var Se=(e,t,n)=>(n=e!=null?At(vt(e)):{},Ce(t||!e||!e.__esModule?te(n,"default",{value:e,enumerable:!0}):n,e)),_t=e=>Ce(te({},"__esModule",{value:!0}),e);var ir={};Ct(ir,{BASE_MAINNET_NETWORK:()=>W,DEXTER_FACILITATOR_URL:()=>U,FacilitatorClient:()=>V,MODEL_PRICING:()=>B,MODEL_PRICING_MAP:()=>xe,MODEL_REGISTRY:()=>I,SOLANA_MAINNET_NETWORK:()=>L,SPONSORED_ACCESS_EXTENSION_KEY:()=>wt.SPONSORED_ACCESS_EXTENSION_KEY,USDC_BASE:()=>le,USDC_MINT:()=>G,bazaarExtension:()=>et,countTokens:()=>Pe,createDynamicPricing:()=>st,createTokenPricing:()=>Pt,createX402Server:()=>X,declareDiscoveryExtension:()=>tt,escapeHtml:()=>D,estimateCost:()=>gt,findModel:()=>ct,formatModelPricing:()=>ht,formatPricing:()=>it,formatTokenPricing:()=>Rt,getActiveModels:()=>mt,getAvailableModelIds:()=>ut,getAvailableModels:()=>Tt,getCheapestModel:()=>yt,getModel:()=>he,getModelsByFamily:()=>dt,getModelsByTier:()=>lt,getTextModels:()=>ft,isValidModel:()=>St,isValidModelId:()=>pt,resolveDefaultAsset:()=>we,stripePayTo:()=>Le,x402AccessPass:()=>ot,x402BrowserSupport:()=>rt,x402Middleware:()=>Qe});module.exports=_t(ir);var L="solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",_e="solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",Oe="solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";var W="eip155:8453",re="eip155:84532",ne="eip155:42161",oe="eip155:137",se="eip155:10",ie="eip155:43114",ae="eip155:56",ce="eip155:1187947933",pe="eip155:324705682",ue="eip155:1";var G="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";var le="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",Ot="0x55d398326f99059fF775485246999027B3197955",Ne="0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",De={[ae]:Ne,[W]:le,[re]:"0x036CbD53842c5426634e7929541eC2318f3dCF7e",[ne]:"0xaf88d065e77c8cC2239327C5EDb3A432268e5831",[oe]:"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",[se]:"0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",[ie]:"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",[ce]:"0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",[pe]:"0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",[ue]:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},Ie={[Ot]:{symbol:"USDT",decimals:18},[Ne]:{symbol:"USDC",decimals:18}},de=6;var cr={[ae]:56,[W]:8453,[re]:84532,[ne]:42161,[oe]:137,[se]:10,[ie]:43114,[ce]:1187947933,[pe]:324705682,[ue]:1},pr={[L]:"https://api.dexter.cash/api/solana/rpc",[_e]:"https://api.devnet.solana.com",[Oe]:"https://api.testnet.solana.com"},ur={[ae]:"https://bsc-dataseed1.binance.org",[W]:"https://api.dexter.cash/api/base/rpc",[re]:"https://sepolia.base.org",[ne]:"https://arb1.arbitrum.io/rpc",[oe]:"https://polygon-rpc.com",[se]:"https://mainnet.optimism.io",[ie]:"https://api.avax.network/ext/bc/C/rpc",[ce]:"https://skale-base.skalenodes.com/v1/base",[pe]:"https://base-sepolia-testnet.skalenodes.com/v1/jubilant-horrible-ancha",[ue]:"https://eth.llamarpc.com"},U="https://x402.dexter.cash",me=L;function J(e,t){if(!Number.isFinite(e))throw new Error(`toAtomicUnits: amount must be finite, got ${e}`);if(e<0)throw new Error(`toAtomicUnits: amount must be non-negative, got ${e}`);if(!Number.isInteger(t)||t<0)throw new Error(`toAtomicUnits: decimals must be a non-negative integer, got ${t}`);let n=Nt(Math.abs(e)),[r,o=""]=n.split("."),s=o.slice(0,t).padEnd(t,"0");return BigInt(r+s).toString()}function Nt(e){let t=e.toString();if(!/[eE]/.test(t))return t;let[n,r]=t.split(/[eE]/),o=parseInt(r,10),s=n.startsWith("-"),p=s?n.slice(1):n,[y,g=""]=p.split("."),m=y+g,b=y.length+o,c;return b<=0?c="0."+"0".repeat(-b)+m:b>=m.length?c=m+"0".repeat(b-m.length):c=m.slice(0,b)+"."+m.slice(b),(s?"-":"")+c}function Re(e){return e.startsWith("solana:")||e==="solana"}function Dt(e){if(typeof Buffer<"u")return Buffer.from(e,"utf-8").toString("base64");let t=new TextEncoder().encode(e),n="";for(let r=0;r<t.length;r++)n+=String.fromCharCode(t[r]);return btoa(n)}function It(e){if(typeof Buffer<"u")return Buffer.from(e,"base64").toString("utf-8");let t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return new TextDecoder().decode(n)}function K(e){return Dt(JSON.stringify(e))}function Q(e){return JSON.parse(It(e))}function Bt(e){if(e instanceof TypeError)return!0;if(e&&typeof e=="object"&&"status"in e){let t=e.status;return t>=500&&t<600}return!1}var Y=class extends Error{status;body;constructor(t,n){super(`HTTP ${t}`),this.status=t,this.body=n}},V=class{facilitatorUrl;cachedSupported=null;cacheTime=0;CACHE_TTL_MS=6e4;timeoutMs;maxRetries;retryBaseMs;constructor(t=U,n){this.facilitatorUrl=t.replace(/\/$/,""),this.timeoutMs=n?.timeoutMs??1e4,this.maxRetries=n?.maxRetries??3,this.retryBaseMs=n?.retryBaseMs??500}async fetchWithTimeout(t,n){let r=new AbortController,o=setTimeout(()=>r.abort(),this.timeoutMs);try{return await fetch(t,{...n,signal:r.signal})}finally{clearTimeout(o)}}async fetchWithRetry(t,n){let r;for(let o=0;o<this.maxRetries;o++)try{let s=await this.fetchWithTimeout(t,n);if(!s.ok&&s.status>=500)throw new Y(s.status,await s.text());return s}catch(s){if(r=s,o<this.maxRetries-1&&Bt(s)){let p=this.retryBaseMs*Math.pow(2,o);await new Promise(y=>setTimeout(y,p));continue}throw s}throw r}async getSupported(){let t=Date.now();if(this.cachedSupported&&t-this.cacheTime<this.CACHE_TTL_MS)return this.cachedSupported;let n=await this.fetchWithTimeout(`${this.facilitatorUrl}/supported`);if(!n.ok)throw new Error(`Facilitator /supported returned ${n.status}`);return this.cachedSupported=await n.json(),this.cacheTime=t,this.cachedSupported}async getFeePayer(t){let r=(await this.getSupported()).kinds.find(o=>o.x402Version===2&&(o.scheme==="exact"||o.scheme==="exact-approval")&&o.network===t);if(!r)throw new Error(`Facilitator does not support network "${t}" with a recognized scheme`);return r.extra?.feePayer}async getNetworkExtra(t){return(await this.getSupported()).kinds.find(o=>o.x402Version===2&&(o.scheme==="exact"||o.scheme==="exact-approval"||o.scheme==="batch-settlement")&&o.network===t)?.extra}async verifyPayment(t,n){try{let r=Q(t),o=await this.fetchWithRetry(`${this.facilitatorUrl}/verify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({x402Version:2,paymentPayload:r,paymentRequirements:n})});return o.ok?await o.json():{isValid:!1,invalidReason:`facilitator_error_${o.status}`}}catch(r){return{isValid:!1,invalidReason:r instanceof Y?`facilitator_error_${r.status}`:r instanceof Error&&r.name==="AbortError"?"facilitator_timeout":r instanceof Error?r.message:"unexpected_verify_error"}}}async settlePayment(t,n){try{let r=Q(t),o=await this.fetchWithRetry(`${this.facilitatorUrl}/settle`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({x402Version:2,paymentPayload:r,paymentRequirements:n})});return o.ok?{...await o.json(),network:n.network}:{success:!1,network:n.network,errorReason:`facilitator_error_${o.status}`}}catch(r){let o=r instanceof Y?`facilitator_error_${r.status}`:r instanceof Error&&r.name==="AbortError"?"facilitator_timeout":r instanceof Error?r.message:"unexpected_settle_error";return{success:!1,network:n.network,errorReason:o}}}};function we(e){if(Re(e))return{address:G,decimals:6};let t=De[e];if(t){let n=Ie[t]?.decimals??6;return{address:t,decimals:n}}return{address:G,decimals:6}}function Be(e){try{let t=Q(e);return t?.accepted?.amount??t?.accepted?.maxAmountRequired}catch{return}}function X(e){let{payTo:t,facilitatorUrl:n=U,network:r=L,defaultTimeoutSeconds:o=60}=e,s=e.asset??we(r),p=e.scheme??"exact",y=new V(n),g=null,m=new Map,b=3e4,c=Date.now();function i(u){let d=(u.maxTimeoutSeconds||o)*1e3;if(m.set(u.payTo,{accept:u,expiresAt:Date.now()+d}),Date.now()-c>b){let T=Date.now();for(let[E,_]of m)_.expiresAt<T&&m.delete(E);c=T}}function h(u){let d=m.get(u);if(d){if(d.expiresAt<Date.now()){m.delete(u);return}return d.accept}}async function l(u){return typeof t=="string"?t:t(u||{})}async function x(){if(g||(g=await y.getNetworkExtra(r)),Re(r)&&!g?.feePayer)throw new Error(`Facilitator does not provide feePayer for network "${r}"`);return{...g?.feePayer?{feePayer:g.feePayer}:{},decimals:g?.decimals??s.decimals,name:g?.name,version:g?.version,...p==="batch-settlement"&&g?.receiverAuthorizer?{receiverAuthorizer:g.receiverAuthorizer}:{}}}async function P(u,d){let{amountAtomic:T,timeoutSeconds:E=o}=d,_=await x(),O={scheme:p,network:r,amount:T,maxAmountRequired:T,asset:s.address,payTo:u,maxTimeoutSeconds:E,extra:_};return i(O),O}async function k(u){let d=await l({amountAtomic:u.amountAtomic,resourceUrl:u.resourceUrl});return P(d,u)}async function A(u){let{resourceUrl:d,description:T,mimeType:E="application/json"}=u,_={url:d,description:T,mimeType:E},O=await k(u);return{x402Version:2,resource:_,accepts:[O],error:"Payment required"}}function S(u){return K(u)}function a(u){return{status:402,headers:{"PAYMENT-REQUIRED":S(u)},body:{}}}async function f(u,d){if(!d){let T=await l({paymentHeader:u});d=h(T),d||(d=await P(T,{amountAtomic:Be(u)??"0",resourceUrl:""}))}return y.verifyPayment(u,d)}async function w(u,d){if(!d){let T=await l({paymentHeader:u});d=h(T),d||(d=await P(T,{amountAtomic:Be(u)??"0",resourceUrl:""}))}return y.settlePayment(u,d)}return{buildRequirements:A,encodeRequirements:S,create402Response:a,verifyPayment:f,settlePayment:w,getPaymentAccept:k,network:r,assetDecimals:s.decimals,facilitator:y}}var Ue=new WeakMap;function $e(e){return Ue.get(e)}var Ut={base:"base","base-sepolia":"base_sepolia"},$t={base:"eip155:8453","base-sepolia":"eip155:84532"};function Le(e){let t=typeof e=="string"?{secretKey:e}:e,n=t.network??"base",r=Ut[n]??"base",o=$t[n]??"eip155:8453",s=t.apiVersion??"2026-01-28.clover",p=null;async function y(){if(p)return p;try{let{default:m}=await import("stripe");return p=new m(t.secretKey,{apiVersion:s,appInfo:{name:"@dexterai/x402",url:"https://dexter.cash/sdk"}}),p}catch{throw new Error('The "stripe" package is required for stripePayTo(). Install it with: npm install stripe')}}let g=async m=>{if(m.paymentHeader){try{let k=JSON.parse(Buffer.from(m.paymentHeader,"base64").toString()),A=k.payload?.authorization?.to;if(A&&typeof A=="string")return A;let S=k.accepted?.payTo;if(S&&typeof S=="string")return S}catch{}throw new Error("Could not extract deposit address from payment header. Ensure the client is sending a valid x402 PAYMENT-SIGNATURE.")}let b=await y(),c=m.amountAtomic?parseInt(m.amountAtomic,10):1e4,i=Math.max(1,Math.round(c/Math.pow(10,de-2))),l=(await b.paymentIntents.create({amount:i,currency:"usd",payment_method_types:["crypto"],payment_method_data:{type:"crypto"},payment_method_options:{crypto:{mode:"custom"}},confirm:!0})).next_action;if(!l?.crypto_collect_deposit_details)throw new Error("Stripe PaymentIntent did not return crypto deposit details. Ensure your Stripe account has crypto payins enabled: https://support.stripe.com/questions/get-started-with-pay-with-crypto");let x=l.crypto_collect_deposit_details,P=x.deposit_addresses?.[r]?.address;if(!P)throw new Error(`No deposit address found for network "${r}". Available networks: ${Object.keys(x.deposit_addresses||{}).join(", ")}`);return P};return g._x402Defaults={network:o,facilitatorUrl:U},Ue.set(g,o),g}var Ge=require("os"),Ve=require("path"),Xe=require("@x402/evm/batch-settlement/server");var fe=require("@x402/core/server"),qe=require("@x402/core/http"),Fe=require("@x402/evm/batch-settlement/server");function He(e){let t=e.verbose?console.log.bind(console,"[batch-settlement:seller]"):()=>{},n=new fe.HTTPFacilitatorClient({url:e.facilitatorUrl}),r=new Fe.BatchSettlementEvmScheme(e.payTo,{storage:e.channelStore}),o=new fe.x402ResourceServer(n).register(e.network,r),s=new qe.x402HTTPResourceServer(o,{[e.route]:{accepts:{scheme:"batch-settlement",payTo:e.payTo,price:e.price,network:e.network},description:"batch-settlement protected route",mimeType:"application/json"}}),p=null;function y(){if(p)return p;let c=s.initialize();return c.catch(i=>{p===c&&(p=null),e.verbose?t("resource server initialize() failed:",i):console.error("[batch-settlement:seller] resource server initialize() failed:",i)}),p=c,c}let g=y();function m(c,i){if(c.headersSent)return;for(let[l,x]of Object.entries(i.headers))c.setHeader(l,x);c.status(i.status);let{body:h}=i;h==null?c.end():typeof h=="string"?c.send(h):c.json(h)}return{scheme:r,facilitator:n,handler:async(c,i,h)=>{try{await y();let l=c.get("host")??"",x=`${c.baseUrl??""}${c.path}`||"/",P={getHeader:w=>c.headers[w.toLowerCase()],getMethod:()=>c.method,getPath:()=>x,getUrl:()=>`${c.protocol}://${l}${c.originalUrl}`,getAcceptHeader:()=>c.headers.accept??"",getUserAgent:()=>c.headers["user-agent"]??"",getBody:()=>c.body??{},getQueryParams:()=>c.query,getQueryParam:w=>{let u=c.query[w];if(typeof u=="string"||Array.isArray(u))return u}},k=c.headers["payment-signature"]??c.headers["x-payment"],A={adapter:P,path:x,method:c.method,paymentHeader:k},S=await s.processHTTPRequest(A);if(t("processHTTPRequest ->",S.type),S.type==="no-payment-required"){h();return}if(S.type==="payment-error"){m(i,S.response);return}let a={request:A,responseBody:Buffer.alloc(0)},f=await s.processSettlement(S.paymentPayload,S.paymentRequirements,S.declaredExtensions,a);if(t("processSettlement ->",f.success?"success":`failure:${f.errorReason}`),!f.success){m(i,f.response);return}for(let[w,u]of Object.entries(f.headers))i.headersSent||i.setHeader(w,u);h()}catch(l){t("handler error:",l),i.headersSent||i.status(500).json({error:"Payment processing error"})}},ready:g}}var Ae=require("viem"),We=6;async function Ee(e){let{manager:t,store:n,channelId:r}=e,o=await n.get(r),s=BigInt(o?.chargedCumulativeAmount??"0"),p=BigInt(o?.balance??"0"),y=p>s?p-s:0n,{claims:g,settle:m}=await t.claimAndSettle(),b=await t.refund([r]),c=b.find(i=>i.channel===r)??b[0];return{claimTx:g[0]?.transaction??"",settleTx:m?.transaction??"",refundTx:c?.transaction??"",settledAmount:(0,Ae.formatUnits)(s,We),refundedAmount:(0,Ae.formatUnits)(y,We)}}async function Ke(e){let t=await e.store.list(),n=[];for(let r of t)try{let o=await Ee({manager:e.manager,store:e.store,channelId:r.channelId});n.push({channelId:r.channelId,...o})}catch(o){n.push({channelId:r.channelId,error:o instanceof Error?o.message:String(o)})}return n}function je(e){let t=!1,n=async()=>{try{await e.claimAndSettle()}catch(o){e.onError?.(o)}},r=setInterval(()=>{t||n()},e.claimIntervalMs);return typeof r.unref=="function"&&r.unref(),{async stop(){t||(t=!0,clearInterval(r),await n())}}}var Lt="https://x402.dexter.cash",qt="GET /",ze=new Set(["eip155:8453","eip155:42161","eip155:137"]);function Ft(e){return e===!1?null:e===void 0||e===!0?3e5:(e.claimIntervalSecs??300)*1e3}function ke(e){if(!ze.has(e.network))throw new Error(`batch-settlement is not supported on network "${e.network}" \u2014 supported: ${[...ze].join(", ")}`);let t=e.facilitatorUrl??Lt,n=e.channelStore??new Xe.FileChannelStorage({directory:(0,Ve.join)((0,Ge.homedir)(),".dexter-x402","seller-channels")}),r=He({payTo:e.payTo,network:e.network,price:e.price,route:e.route??qt,facilitatorUrl:t,channelStore:n,verbose:e.verbose}),o=r.scheme.createChannelManager(r.facilitator,e.network),s=async()=>{await o.claimAndSettle()},p=Ft(e.autoSettle),y=null;p!==null&&(y=je({claimAndSettle:s,claimIntervalMs:p,onError:c=>console.error("[batch-settlement:seller] auto-loop claim pass failed",c)}));let g=n,m=(c,i,h)=>{r.handler(c,i,h)},b=m;return b.middleware=()=>m,b.closeChannel=c=>Ee({manager:o,store:g,channelId:c}),b.closeAll=()=>Ke({manager:o,store:g}),b.stop=async()=>{y&&await y.stop()},b}async function Je(e,t,n){let r={};for(let o of e)if(o.enrichPaymentRequiredResponse&&o.key in t)try{let s=await o.enrichPaymentRequiredResponse(t[o.key],n);s!==void 0&&(r[o.key]=s)}catch(s){console.warn(`[x402:extensions] extension "${o.key}" failed:`,s)}return Object.keys(r).length>0?r:void 0}function Ht(e,t){if(typeof e=="string"||typeof e=="function")return e;if(t in e)return e[t];let r=`${t.split(":")[0]}:*`;if(r in e)return e[r];if("*"in e)return e["*"];throw new Error(`No payTo configured for network "${t}"`)}function Qe(e){if(e.scheme==="batch-settlement"){let a=Array.isArray(e.network)?e.network[0]:e.network;if(!a)throw new Error('x402Middleware: scheme "batch-settlement" requires a network');let f=typeof e.payTo=="string"?e.payTo:void 0;if(!f)throw new Error('x402Middleware: scheme "batch-settlement" requires a string payTo address');return ke({payTo:f,network:a,price:e.amount,facilitatorUrl:e.facilitatorUrl,route:e.batchSettlement?.route,channelStore:e.batchSettlement?.channelStore,autoSettle:e.batchSettlement?.autoSettle,verbose:e.verbose})}let{payTo:t,amount:n,asset:r,description:o,resourceUrl:s,mimeType:p,timeoutSeconds:y,verbose:g=!1,getResourceUrl:m,getAmount:b,getDescription:c,extensions:i,declarations:h}=e,l=g?console.log.bind(console,"[x402:middleware]"):()=>{},x=typeof t=="function"?t._x402Defaults:void 0,P=e.facilitatorUrl??x?.facilitatorUrl,k=e.network?Array.isArray(e.network)?e.network:[e.network]:x?.network?[x.network]:[me],A=new Map;for(let a of k){let f=Ht(t,a);if(typeof f=="function"){let w=$e(f);if(w&&a!==w)throw new Error(`stripePayTo is configured for "${w}" but middleware includes network "${a}". Stripe only supports Base deposit addresses. Use a static payTo for other chains.`)}A.set(a,X({payTo:f,network:a,asset:r,facilitatorUrl:P,defaultTimeoutSeconds:y,scheme:e.scheme}))}let S=A.get(k[0]);return async(a,f,w)=>{try{let u=a.headers["payment-signature"];if(!u){l("No payment signature, returning 402");let F=m?.(a)??s??`${a.protocol}://${a.get("host")}${a.originalUrl}`,R=b?.(a)??n,C=c?.(a)??o,N=parseFloat(R),M=[],v=null;for(let[,H]of A)try{let Te={amountAtomic:J(N,H.assetDecimals),resourceUrl:F,description:C,mimeType:p,timeoutSeconds:y},Me=await H.buildRequirements(Te);M.push(...Me.accepts),v||(v=Me)}catch(Te){l("Failed to build requirements for a network:",Te)}if(!v||M.length===0){f.status(500).json({error:"Failed to build payment requirements"});return}if(v={...v,accepts:M},i&&i.length>0){let H=await Je(i,h??{},{response:v,request:{method:a.method,path:a.route?.path??a.path,params:a.params}});H&&(v={...v,extensions:H})}let ee=S.encodeRequirements(v);f.setHeader("PAYMENT-REQUIRED",ee),f.status(402).json({error:"Payment required",accepts:v.accepts,resource:v.resource,...v.extensions?{extensions:v.extensions}:{}});return}l("Payment signature received, verifying...");let d=S;try{let R=JSON.parse(Buffer.from(u,"base64").toString())?.accepted?.network;R&&A.has(R)&&(d=A.get(R))}catch{}let T=await d.verifyPayment(u);if(!T.isValid){if(l("Payment verification failed:",T.invalidReason),e.onVerifyFailed)try{await e.onVerifyFailed({reason:T.invalidReason,resourceUrl:`${a.protocol}://${a.get("host")}${a.originalUrl}`})}catch{}f.status(402).json({error:"Payment verification failed",reason:T.invalidReason});return}l("Payment verified, settling...");let E=await d.settlePayment(u);if(!E.success){l("Payment settlement failed:",E.errorReason),f.status(402).json({error:"Payment settlement failed",reason:E.errorReason});return}l("Payment settled:",E.transaction);let _=E.network||k[0];if(e.onSettlement)try{await e.onSettlement({transaction:E.transaction,network:_,payer:T.payer??"",resourceUrl:`${a.protocol}://${a.get("host")}${a.originalUrl}`})}catch{}a.x402={transaction:E.transaction,payer:T.payer??"",network:_};let O={success:!0,transaction:E.transaction,network:_,payer:T.payer??""};if(E.extensions&&(O.extensions=E.extensions),f.setHeader("PAYMENT-RESPONSE",K(O)),e.sponsoredAccess&&E.extensions?.["sponsored-access"]){let F=E.extensions["sponsored-access"],R=F?.info?.recommendations??F?.recommendations;if(R&&R.length>0){if(l("Injecting sponsored-access recommendations into response"),typeof e.sponsoredAccess=="object"&&e.sponsoredAccess.onMatch)try{e.sponsoredAccess.onMatch(R,{transaction:E.transaction,network:_,payer:T.payer??""})}catch{}let C=f.json.bind(f);f.json=function(M){return typeof e.sponsoredAccess=="object"&&e.sponsoredAccess.inject?C(e.sponsoredAccess.inject(M,R)):M&&typeof M=="object"&&!Array.isArray(M)?C({_x402_sponsored:R,...M}):C(M)}}}w()}catch(u){l("Middleware error:",u),f.status(500).json({error:"Payment processing error"})}}}var Wt=/^\/[a-zA-Z0-9_/:.\-~%]+$/;function Ye(e){if(!e||!Wt.test(e))return!1;let t;try{t=decodeURIComponent(e)}catch{return!1}return!(t.includes("..")||t.includes("://"))}function Z(e){return e.method==="POST"||e.method==="PUT"||e.method==="PATCH"}var Kt=["GET","HEAD","DELETE"],jt=["POST","PUT","PATCH"];function Ze(e,t){let n=t.pathParams!==void 0&&Object.keys(t.pathParams).length>0,r={type:"http",method:e.method};Z(e)?(r.bodyType=e.bodyType,r.body=e.input??{}):e.input!==void 0&&(r.queryParams=e.input),n&&(r.pathParams=t.pathParams);let o=e.output?.example!==void 0?{type:"json",example:e.output.example}:void 0,s=Z(e)?jt:Kt,p={type:{type:"string",const:"http"},method:{type:"string",enum:s}};Z(e)?(p.bodyType={type:"string",enum:["json","form-data","text"]},p.body={type:"object",...e.inputSchema??{}}):e.inputSchema&&(p.queryParams={type:"object",...e.inputSchema}),e.pathParamsSchema&&(p.pathParams={type:"object",...e.pathParamsSchema});let y={input:{type:"object",properties:p,required:Z(e)?["type","method","bodyType","body"]:["type","method"],additionalProperties:!1}};o&&(y.output={type:"object",properties:{type:{type:"string"},example:{type:"object",...e.output?.schema??{}}},required:["type"]});let g={$schema:"https://json-schema.org/draft/2020-12/schema",type:"object",properties:y,required:["input"]},m={info:{input:r,...o?{output:o}:{}},schema:g};return Ye(t.routeTemplate)&&(m.routeTemplate=t.routeTemplate),m}var zt=["GET","HEAD","DELETE","POST","PUT","PATCH"];function et(){return{key:"bazaar",enrichPaymentRequiredResponse:(e,t)=>{if(e==null)return;let n=e,r=(n.method??t.request.method).toUpperCase();if(!zt.includes(r))return;let o={...n,method:r};return Ze(o,{pathParams:t.request.params,routeTemplate:t.request.path})}}}function tt(e){return{bazaar:e}}function D(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}var Gt='<svg width="18" height="18" viewBox="0 0 2000 2000" xmlns="http://www.w3.org/2000/svg"><path d="M1000 2000c554.17 0 1000-445.83 1000-1000S1554.17 0 1000 0 0 445.83 0 1000s445.83 1000 1000 1000z" fill="#2775ca"/><path d="M1275 1158.33c0-145.83-87.5-195.83-262.5-216.66-125-16.67-150-50-150-108.34s41.67-95.83 125-95.83c75 0 116.67 25 137.5 87.5 4.17 12.5 16.67 20.83 29.17 20.83h66.66c16.67 0 29.17-12.5 29.17-29.16v-4.17c-16.67-91.67-91.67-162.5-187.5-170.83v-100c0-16.67-12.5-29.17-33.33-33.34h-62.5c-16.67 0-29.17 12.5-33.34 33.34v95.83c-125 16.67-204.16 100-204.16 204.17 0 137.5 83.33 191.66 258.33 212.5 116.67 20.83 154.17 45.83 154.17 112.5s-58.34 112.5-137.5 112.5c-108.34 0-145.84-45.84-158.34-108.34-4.16-16.66-16.66-25-29.16-25h-70.84c-16.66 0-29.16 12.5-29.16 29.17v4.17c16.66 104.16 83.33 179.16 220.83 200v100c0 16.66 12.5 29.16 33.33 33.33h62.5c16.67 0 29.17-12.5 33.34-33.33v-100c125-20.84 208.33-108.34 208.33-220.84z" fill="#fff"/><path d="M787.5 1595.83c-325-116.66-491.67-479.16-370.83-800 62.5-175 200-308.33 370.83-370.83 16.67-8.33 25-20.83 25-41.67V325c0-16.67-8.33-29.17-25-33.33-4.17 0-12.5 0-16.67 4.16-395.83 125-612.5 545.84-487.5 941.67 75 233.33 254.17 412.5 487.5 487.5 16.67 8.33 33.34 0 37.5-16.67 4.17-4.16 4.17-8.33 4.17-16.66v-58.34c0-12.5-12.5-29.16-25-37.5zM1229.17 295.83c-16.67-8.33-33.34 0-37.5 16.67-4.17 4.17-4.17 8.33-4.17 16.67v58.33c0 16.67 12.5 33.33 25 41.67 325 116.66 491.67 479.16 370.83 800-62.5 175-200 308.33-370.83 370.83-16.67 8.33-25 20.83-25 41.67V1700c0 16.67 8.33 29.17 25 33.33 4.17 0 12.5 0 16.67-4.16 395.83-125 612.5-545.84 487.5-941.67-75-237.5-258.34-416.67-487.5-491.67z" fill="#fff"/></svg>',Vt='<svg width="36" height="36" viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg"><g><path fill="#F2681A" d="m324.93,313.11c-115.5,0-231,0-350,0l350,0z"/><path fill="#FDFAF5" d="m230.43,50.62c1.1.85 2.19 1.7 3.32 2.57 6.02 4.8 11.77 9.88 17.46 15.07.92.84.92.84 1.86 1.69 1.82 1.69 3.59 3.42 5.35 5.16.61.56 1.22 1.13 1.84 1.71 5.66 5.76 6.18 10.43 6.13 18.3.02 1.16.04 2.32.06 3.52.06 3.83.06 7.65.07 11.48.02 2.68.05 5.35.08 8.03.05 5.6.09 11.21.1 16.81.02 7.15.09 14.31.17 21.46.06 5.53.1 11.05.13 16.58.02 2.64.04 5.27.07 7.91.18 17.58.12 32.82-11.24 47.32-7.35 7.27-16.54 12.06-25.42 17.22-1.97 1.16-3.94 2.33-5.91 3.49-7.16 4.24-14.34 8.44-21.53 12.62-4.8 2.79-9.59 5.6-14.38 8.42-1.25.73-2.5 1.47-3.79 2.23-2.32 1.36-4.64 2.73-6.96 4.1-27.47 16.09-27.47 16.09-42.16 12.93-8.06-2.28-14.94-5.82-22.16-10.02-1.17-.67-2.34-1.34-3.54-2.04-24.55-14.25-43.58-27.03-51.9-55.58-1.07-4.58-1.54-8.92-1.52-13.61.28-9.5.28-9.5-3.3-17.97-1.81-1.49-3.68-2.92-5.59-4.28-9.19-7.06-12.7-20.03-14.18-31.06-.54-5.77-.55-11.56-.6-17.35-.03-1.32-.07-2.63-.1-3.99-.01-1.26-.02-2.53-.03-3.83-.02-1.15-.03-2.29-.05-3.47.72-4.02 1.94-5.36 5.21-7.74 2.89-.53 2.89-.53 6.07-.46 1.71.02 1.71.02 3.46.05 1.19.04 2.37.08 3.59.12 1.2.02 2.41.04 3.65.06 2.97.05 5.93.13 8.9.23.14-1.35.29-2.7.43-4.08.63-5 1.78-9.74 3.14-14.58.22-.79.43-1.59.66-2.4.53-1.92 1.06-3.84 1.6-5.76-1.55-.45-1.55-.45-3.13-.9-9.52-3.52-17.1-10.95-21.37-20.1-3.81-9.26-3.87-20.34-.29-29.68 6.49-13.99 16.36-23.23 30.66-29.01 49.81-17.69 115.79 8.35 155.13 38.85z"/><path fill="#F2671A" d="m142.93,22.62c.86.19 1.73.39 2.62.59 36.12 8.21 68.79 24.98 95.38 50.75 1.02.98 2.03 1.97 3.08 2.98 10.84 10.66 10.84 10.66 11.05 14.62-2.06 3.55-5.44 4.18-9.17 5.3-.79.25-1.59.49-2.41.75-28.13 8.43-60.95 6.37-87.13-7.16-.86-.49-1.71-.97-2.6-1.48-7.37-4.05-12.59-3.36-20.59-1.54-22.76 4-48.47 1.53-68.69-9.74-4.88-3.88-8.23-8.29-10.21-14.22-.93-10.38-.67-18.44 5.83-26.83 19.57-23.38 55.99-20.36 82.83-14z"/><path fill="#F16619" d="m44.93,129.12c27.36-.03 54.72-.05 82.08-.06 12.7-.01 25.41-.01 38.11-.03 11.07-.01 22.14-.02 33.2-.02 5.86 0 11.73-.01 17.59-.01 5.51-.01 11.03-.01 16.54-.01 2.03 0 4.06 0 6.09-.01 2.76-.01 5.52 0 8.28 0 .81 0 1.63-.01 2.47-.01 5.51.02 5.51.02 6.81 1.32.22 3.43.22 3.43 0 7-2.75 2.75-3.42 2.66-7.15 2.82-1.41.07-1.41.07-2.85.14-1.47.05-1.47.05-2.98.11-1.49.07-1.49.07-3 .14-2.45.11-4.9.21-7.35.3-.2 1.3-.4 2.59-.6 3.93-2.57 16.08-5.93 29.89-18.89 40.86-10.35 7.28-21.87 8.49-34.17 7.71-13.11-2.33-22.52-9.19-30.33-19.83-4.49-7.64-4.8-17.05-5.83-25.67-4.24.39-8.47.77-12.83 1.17-.28 1.84-.28 1.84-.56 3.71-2.32 14.39-5.63 23.35-16.95 33.11-2.32 1.67-2.32 1.67-4.65 1.67 4 4.67 9.06 6.59 14.87 8.24 3.79 1.09 3.79 1.09 6.12 3.43-.65 5.31-.65 5.31-2.33 7-8.42-.27-15.13-2.29-22.17-7-1.09-1.21-2.17-2.43-3.25-3.65-2.72-2.81-4.45-3.84-8.36-4.16-1.67-.02-3.34-.02-5.01.01-1.77-.04-3.54-.09-5.3-.15-1.27-.04-1.27-.04-2.56-.08-9.26-.54-17.6-4.56-24.51-10.64-9.58-11.11-11.03-22.56-10.72-36.82.02-1.4.03-2.8.05-4.24.04-3.42.1-6.85.17-10.27z"/><path fill="#F26117" d="m172.68,203.08c7.27.09 13.23 1.97 18.87 6.65 2.88 3.07 3.86 5.12 4.25 9.32-.12 1.01-.24 2.02-.36 3.06-2.55.95-2.55.95-5.83 1.17-3.28-2.84-3.28-2.84-5.83-5.83-.36.58-.71 1.16-1.08 1.75-7.6 11.29-20.06 17.74-33.05 21.09-20.36 3.1-36.81-1.66-53.37-13.73-2.33-2.11-2.33-2.11-4.67-5.61.42-3.45.99-4.49 3.5-7 4.07.37 5.95 2.13 8.75 4.96 9.81 8.93 22.53 11.87 35.51 11.69 11.74-1.05 22.38-5.85 31.57-13.15 2.06-2.45 2.06-2.45 3.5-4.67-1.66.07-1.66.07-3.35.15-3.65-.15-3.65-.15-5.98-2.48.75-6.18 1.46-7.19 7.58-7.36z"/></g></svg>',Xt=`
|
|
1
|
+
"use strict";var At=Object.create;var te=Object.defineProperty;var Et=Object.getOwnPropertyDescriptor;var kt=Object.getOwnPropertyNames;var vt=Object.getPrototypeOf,Mt=Object.prototype.hasOwnProperty;var Ct=(e,t)=>{for(var n in t)te(e,n,{get:t[n],enumerable:!0})},Ce=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of kt(t))!Mt.call(e,o)&&o!==n&&te(e,o,{get:()=>t[o],enumerable:!(r=Et(t,o))||r.enumerable});return e};var Se=(e,t,n)=>(n=e!=null?At(vt(e)):{},Ce(t||!e||!e.__esModule?te(n,"default",{value:e,enumerable:!0}):n,e)),_t=e=>Ce(te({},"__esModule",{value:!0}),e);var ir={};Ct(ir,{BASE_MAINNET_NETWORK:()=>W,DEXTER_FACILITATOR_URL:()=>B,FacilitatorClient:()=>V,MODEL_PRICING:()=>U,MODEL_PRICING_MAP:()=>xe,MODEL_REGISTRY:()=>I,SOLANA_MAINNET_NETWORK:()=>L,SPONSORED_ACCESS_EXTENSION_KEY:()=>wt.SPONSORED_ACCESS_EXTENSION_KEY,USDC_BASE:()=>le,USDC_MINT:()=>G,bazaarExtension:()=>et,countTokens:()=>Pe,createDynamicPricing:()=>st,createTokenPricing:()=>Pt,createX402Server:()=>X,declareDiscoveryExtension:()=>tt,escapeHtml:()=>D,estimateCost:()=>gt,findModel:()=>ct,formatModelPricing:()=>ht,formatPricing:()=>it,formatTokenPricing:()=>Rt,getActiveModels:()=>mt,getAvailableModelIds:()=>ut,getAvailableModels:()=>Tt,getCheapestModel:()=>yt,getModel:()=>he,getModelsByFamily:()=>dt,getModelsByTier:()=>lt,getTextModels:()=>ft,isValidModel:()=>St,isValidModelId:()=>pt,resolveDefaultAsset:()=>we,stripePayTo:()=>Le,x402AccessPass:()=>ot,x402BrowserSupport:()=>rt,x402Middleware:()=>Qe});module.exports=_t(ir);var L="solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",_e="solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",Oe="solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";var W="eip155:8453",re="eip155:84532",ne="eip155:42161",oe="eip155:137",se="eip155:10",ie="eip155:43114",ae="eip155:56",ce="eip155:1187947933",pe="eip155:324705682",ue="eip155:1";var G="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";var le="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",Ot="0x55d398326f99059fF775485246999027B3197955",Ne="0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",De={[ae]:Ne,[W]:le,[re]:"0x036CbD53842c5426634e7929541eC2318f3dCF7e",[ne]:"0xaf88d065e77c8cC2239327C5EDb3A432268e5831",[oe]:"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",[se]:"0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",[ie]:"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",[ce]:"0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",[pe]:"0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",[ue]:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},Ie={[Ot]:{symbol:"USDT",decimals:18},[Ne]:{symbol:"USDC",decimals:18}},de=6;var cr={[ae]:56,[W]:8453,[re]:84532,[ne]:42161,[oe]:137,[se]:10,[ie]:43114,[ce]:1187947933,[pe]:324705682,[ue]:1},pr={[L]:"https://api.dexter.cash/api/solana/rpc",[_e]:"https://api.devnet.solana.com",[Oe]:"https://api.testnet.solana.com"},ur={[ae]:"https://bsc-dataseed1.binance.org",[W]:"https://api.dexter.cash/api/base/rpc",[re]:"https://sepolia.base.org",[ne]:"https://arb1.arbitrum.io/rpc",[oe]:"https://polygon-rpc.com",[se]:"https://mainnet.optimism.io",[ie]:"https://api.avax.network/ext/bc/C/rpc",[ce]:"https://skale-base.skalenodes.com/v1/base",[pe]:"https://base-sepolia-testnet.skalenodes.com/v1/jubilant-horrible-ancha",[ue]:"https://eth.llamarpc.com"},B="https://x402.dexter.cash",me=L;function J(e,t){if(!Number.isFinite(e))throw new Error(`toAtomicUnits: amount must be finite, got ${e}`);if(e<0)throw new Error(`toAtomicUnits: amount must be non-negative, got ${e}`);if(!Number.isInteger(t)||t<0)throw new Error(`toAtomicUnits: decimals must be a non-negative integer, got ${t}`);let n=Nt(Math.abs(e)),[r,o=""]=n.split("."),s=o.slice(0,t).padEnd(t,"0");return BigInt(r+s).toString()}function Nt(e){let t=e.toString();if(!/[eE]/.test(t))return t;let[n,r]=t.split(/[eE]/),o=parseInt(r,10),s=n.startsWith("-"),p=s?n.slice(1):n,[y,g=""]=p.split("."),m=y+g,b=y.length+o,c;return b<=0?c="0."+"0".repeat(-b)+m:b>=m.length?c=m+"0".repeat(b-m.length):c=m.slice(0,b)+"."+m.slice(b),(s?"-":"")+c}function Re(e){return e.startsWith("solana:")||e==="solana"}function Dt(e){if(typeof Buffer<"u")return Buffer.from(e,"utf-8").toString("base64");let t=new TextEncoder().encode(e),n="";for(let r=0;r<t.length;r++)n+=String.fromCharCode(t[r]);return btoa(n)}function It(e){if(typeof Buffer<"u")return Buffer.from(e,"base64").toString("utf-8");let t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return new TextDecoder().decode(n)}function K(e){return Dt(JSON.stringify(e))}function Q(e){return JSON.parse(It(e))}function Ut(e){if(e instanceof TypeError)return!0;if(e&&typeof e=="object"&&"status"in e){let t=e.status;return t>=500&&t<600}return!1}var Y=class extends Error{status;body;constructor(t,n){super(`HTTP ${t}`),this.status=t,this.body=n}},V=class{facilitatorUrl;cachedSupported=null;cacheTime=0;CACHE_TTL_MS=6e4;timeoutMs;maxRetries;retryBaseMs;constructor(t=B,n){this.facilitatorUrl=t.replace(/\/$/,""),this.timeoutMs=n?.timeoutMs??1e4,this.maxRetries=n?.maxRetries??3,this.retryBaseMs=n?.retryBaseMs??500}async fetchWithTimeout(t,n){let r=new AbortController,o=setTimeout(()=>r.abort(),this.timeoutMs);try{return await fetch(t,{...n,signal:r.signal})}finally{clearTimeout(o)}}async fetchWithRetry(t,n){let r;for(let o=0;o<this.maxRetries;o++)try{let s=await this.fetchWithTimeout(t,n);if(!s.ok&&s.status>=500)throw new Y(s.status,await s.text());return s}catch(s){if(r=s,o<this.maxRetries-1&&Ut(s)){let p=this.retryBaseMs*Math.pow(2,o);await new Promise(y=>setTimeout(y,p));continue}throw s}throw r}async getSupported(){let t=Date.now();if(this.cachedSupported&&t-this.cacheTime<this.CACHE_TTL_MS)return this.cachedSupported;let n=await this.fetchWithTimeout(`${this.facilitatorUrl}/supported`);if(!n.ok)throw new Error(`Facilitator /supported returned ${n.status}`);return this.cachedSupported=await n.json(),this.cacheTime=t,this.cachedSupported}async getFeePayer(t){let r=(await this.getSupported()).kinds.find(o=>o.x402Version===2&&(o.scheme==="exact"||o.scheme==="exact-approval")&&o.network===t);if(!r)throw new Error(`Facilitator does not support network "${t}" with a recognized scheme`);return r.extra?.feePayer}async getNetworkExtra(t){return(await this.getSupported()).kinds.find(o=>o.x402Version===2&&(o.scheme==="exact"||o.scheme==="exact-approval"||o.scheme==="batch-settlement")&&o.network===t)?.extra}async verifyPayment(t,n){try{let r=Q(t),o=await this.fetchWithRetry(`${this.facilitatorUrl}/verify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({x402Version:2,paymentPayload:r,paymentRequirements:n})});return o.ok?await o.json():{isValid:!1,invalidReason:`facilitator_error_${o.status}`}}catch(r){return{isValid:!1,invalidReason:r instanceof Y?`facilitator_error_${r.status}`:r instanceof Error&&r.name==="AbortError"?"facilitator_timeout":r instanceof Error?r.message:"unexpected_verify_error"}}}async settlePayment(t,n){try{let r=Q(t),o=await this.fetchWithRetry(`${this.facilitatorUrl}/settle`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({x402Version:2,paymentPayload:r,paymentRequirements:n})});return o.ok?{...await o.json(),network:n.network}:{success:!1,network:n.network,errorReason:`facilitator_error_${o.status}`}}catch(r){let o=r instanceof Y?`facilitator_error_${r.status}`:r instanceof Error&&r.name==="AbortError"?"facilitator_timeout":r instanceof Error?r.message:"unexpected_settle_error";return{success:!1,network:n.network,errorReason:o}}}};function we(e){if(Re(e))return{address:G,decimals:6};let t=De[e];if(t){let n=Ie[t]?.decimals??6;return{address:t,decimals:n}}return{address:G,decimals:6}}function Ue(e){try{let t=Q(e);return t?.accepted?.amount??t?.accepted?.maxAmountRequired}catch{return}}function X(e){let{payTo:t,facilitatorUrl:n=B,network:r=L,defaultTimeoutSeconds:o=60}=e,s=e.asset??we(r),p=e.scheme??"exact",y=new V(n),g=null,m=new Map,b=3e4,c=Date.now();function a(u){let d=(u.maxTimeoutSeconds||o)*1e3;if(m.set(u.payTo,{accept:u,expiresAt:Date.now()+d}),Date.now()-c>b){let T=Date.now();for(let[E,_]of m)_.expiresAt<T&&m.delete(E);c=T}}function h(u){let d=m.get(u);if(d){if(d.expiresAt<Date.now()){m.delete(u);return}return d.accept}}async function l(u){return typeof t=="string"?t:t(u||{})}async function x(){if(g||(g=await y.getNetworkExtra(r)),Re(r)&&!g?.feePayer)throw new Error(`Facilitator does not provide feePayer for network "${r}"`);return{...g?.feePayer?{feePayer:g.feePayer}:{},decimals:g?.decimals??s.decimals,name:g?.name,version:g?.version,...p==="batch-settlement"&&g?.receiverAuthorizer?{receiverAuthorizer:g.receiverAuthorizer}:{}}}async function P(u,d){let{amountAtomic:T,timeoutSeconds:E=o}=d,_=await x(),O={scheme:p,network:r,amount:T,maxAmountRequired:T,asset:s.address,payTo:u,maxTimeoutSeconds:E,extra:_};return a(O),O}async function k(u){let d=await l({amountAtomic:u.amountAtomic,resourceUrl:u.resourceUrl});return P(d,u)}async function A(u){let{resourceUrl:d,description:T,mimeType:E="application/json"}=u,_={url:d,description:T,mimeType:E},O=await k(u);return{x402Version:2,resource:_,accepts:[O],error:"Payment required"}}function S(u){return K(u)}function i(u){return{status:402,headers:{"PAYMENT-REQUIRED":S(u)},body:{}}}async function f(u,d){if(!d){let T=await l({paymentHeader:u});d=h(T),d||(d=await P(T,{amountAtomic:Ue(u)??"0",resourceUrl:""}))}return y.verifyPayment(u,d)}async function w(u,d){if(!d){let T=await l({paymentHeader:u});d=h(T),d||(d=await P(T,{amountAtomic:Ue(u)??"0",resourceUrl:""}))}return y.settlePayment(u,d)}return{buildRequirements:A,encodeRequirements:S,create402Response:i,verifyPayment:f,settlePayment:w,getPaymentAccept:k,network:r,assetDecimals:s.decimals,facilitator:y}}var Be=new WeakMap;function $e(e){return Be.get(e)}var Bt={base:"base","base-sepolia":"base_sepolia"},$t={base:"eip155:8453","base-sepolia":"eip155:84532"};function Le(e){let t=typeof e=="string"?{secretKey:e}:e,n=t.network??"base",r=Bt[n]??"base",o=$t[n]??"eip155:8453",s=t.apiVersion??"2026-01-28.clover",p=null;async function y(){if(p)return p;try{let{default:m}=await import("stripe");return p=new m(t.secretKey,{apiVersion:s,appInfo:{name:"@dexterai/x402",url:"https://dexter.cash/sdk"}}),p}catch{throw new Error('The "stripe" package is required for stripePayTo(). Install it with: npm install stripe')}}let g=async m=>{if(m.paymentHeader){try{let k=JSON.parse(Buffer.from(m.paymentHeader,"base64").toString()),A=k.payload?.authorization?.to;if(A&&typeof A=="string")return A;let S=k.accepted?.payTo;if(S&&typeof S=="string")return S}catch{}throw new Error("Could not extract deposit address from payment header. Ensure the client is sending a valid x402 PAYMENT-SIGNATURE.")}let b=await y(),c=m.amountAtomic?parseInt(m.amountAtomic,10):1e4,a=Math.max(1,Math.round(c/Math.pow(10,de-2))),l=(await b.paymentIntents.create({amount:a,currency:"usd",payment_method_types:["crypto"],payment_method_data:{type:"crypto"},payment_method_options:{crypto:{mode:"custom"}},confirm:!0})).next_action;if(!l?.crypto_collect_deposit_details)throw new Error("Stripe PaymentIntent did not return crypto deposit details. Ensure your Stripe account has crypto payins enabled: https://support.stripe.com/questions/get-started-with-pay-with-crypto");let x=l.crypto_collect_deposit_details,P=x.deposit_addresses?.[r]?.address;if(!P)throw new Error(`No deposit address found for network "${r}". Available networks: ${Object.keys(x.deposit_addresses||{}).join(", ")}`);return P};return g._x402Defaults={network:o,facilitatorUrl:B},Be.set(g,o),g}var Ge=require("os"),Ve=require("path"),Xe=require("@x402/evm/batch-settlement/server");var fe=require("@x402/core/server"),qe=require("@x402/core/http"),Fe=require("@x402/evm/batch-settlement/server");function He(e){let t=e.verbose?console.log.bind(console,"[batch-settlement:seller]"):()=>{},n=new fe.HTTPFacilitatorClient({url:e.facilitatorUrl}),r=new Fe.BatchSettlementEvmScheme(e.payTo,{storage:e.channelStore}),o=new fe.x402ResourceServer(n).register(e.network,r),s=new qe.x402HTTPResourceServer(o,{[e.route]:{accepts:{scheme:"batch-settlement",payTo:e.payTo,price:e.price,network:e.network},description:"batch-settlement protected route",mimeType:"application/json"}}),p=null;function y(){if(p)return p;let c=s.initialize();return c.catch(a=>{p===c&&(p=null),e.verbose?t("resource server initialize() failed:",a):console.error("[batch-settlement:seller] resource server initialize() failed:",a)}),p=c,c}let g=y();function m(c,a){if(c.headersSent)return;for(let[l,x]of Object.entries(a.headers))c.setHeader(l,x);c.status(a.status);let{body:h}=a;h==null?c.end():typeof h=="string"?c.send(h):c.json(h)}return{scheme:r,facilitator:n,handler:async(c,a,h)=>{try{await y();let l=c.get("host")??"",x=`${c.baseUrl??""}${c.path}`||"/",P={getHeader:w=>c.headers[w.toLowerCase()],getMethod:()=>c.method,getPath:()=>x,getUrl:()=>`${c.protocol}://${l}${c.originalUrl}`,getAcceptHeader:()=>c.headers.accept??"",getUserAgent:()=>c.headers["user-agent"]??"",getBody:()=>c.body??{},getQueryParams:()=>c.query,getQueryParam:w=>{let u=c.query[w];if(typeof u=="string"||Array.isArray(u))return u}},k=c.headers["payment-signature"]??c.headers["x-payment"],A={adapter:P,path:x,method:c.method,paymentHeader:k},S=await s.processHTTPRequest(A);if(t("processHTTPRequest ->",S.type),S.type==="no-payment-required"){h();return}if(S.type==="payment-error"){m(a,S.response);return}let i={request:A,responseBody:Buffer.alloc(0)},f=await s.processSettlement(S.paymentPayload,S.paymentRequirements,S.declaredExtensions,i);if(t("processSettlement ->",f.success?"success":`failure:${f.errorReason}`),!f.success){m(a,f.response);return}for(let[w,u]of Object.entries(f.headers))a.headersSent||a.setHeader(w,u);h()}catch(l){t("handler error:",l),a.headersSent||a.status(500).json({error:"Payment processing error"})}},ready:g}}var Ae=require("viem"),We=6;async function Ee(e){let{manager:t,store:n,channelId:r}=e,o=await n.get(r),s=BigInt(o?.chargedCumulativeAmount??"0"),p=BigInt(o?.balance??"0"),y=p>s?p-s:0n,{claims:g,settle:m}=await t.claimAndSettle(),b=await t.refund([r]),c=b.find(a=>a.channel===r)??b[0];return{claimTx:g[0]?.transaction??"",settleTx:m?.transaction??"",refundTx:c?.transaction??"",settledAmount:(0,Ae.formatUnits)(s,We),refundedAmount:(0,Ae.formatUnits)(y,We)}}async function Ke(e){let t=await e.store.list(),n=[];for(let r of t)try{let o=await Ee({manager:e.manager,store:e.store,channelId:r.channelId});n.push({channelId:r.channelId,...o})}catch(o){n.push({channelId:r.channelId,error:o instanceof Error?o.message:String(o)})}return n}function je(e){let t=!1,n=async()=>{try{await e.claimAndSettle()}catch(o){e.onError?.(o)}},r=setInterval(()=>{t||n()},e.claimIntervalMs);return typeof r.unref=="function"&&r.unref(),{async stop(){t||(t=!0,clearInterval(r),await n())}}}var Lt="https://x402.dexter.cash",qt="GET /",ze=new Set(["eip155:8453","eip155:42161","eip155:137"]);function Ft(e){return e===!1?null:e===void 0||e===!0?3e5:(e.claimIntervalSecs??300)*1e3}function ke(e){if(!ze.has(e.network))throw new Error(`batch-settlement is not supported on network "${e.network}" \u2014 supported: ${[...ze].join(", ")}`);let t=e.facilitatorUrl??Lt,n=e.channelStore??new Xe.FileChannelStorage({directory:(0,Ve.join)((0,Ge.homedir)(),".dexter-x402","seller-channels")}),r=He({payTo:e.payTo,network:e.network,price:e.price,route:e.route??qt,facilitatorUrl:t,channelStore:n,verbose:e.verbose}),o=r.scheme.createChannelManager(r.facilitator,e.network),s=async()=>{await o.claimAndSettle()},p=Ft(e.autoSettle),y=null;p!==null&&(y=je({claimAndSettle:s,claimIntervalMs:p,onError:c=>console.error("[batch-settlement:seller] auto-loop claim pass failed",c)}));let g=n,m=(c,a,h)=>{r.handler(c,a,h)},b=m;return b.middleware=()=>m,b.closeChannel=c=>Ee({manager:o,store:g,channelId:c}),b.closeAll=()=>Ke({manager:o,store:g}),b.stop=async()=>{y&&await y.stop()},b}async function Je(e,t,n){let r={};for(let o of e)if(o.enrichPaymentRequiredResponse&&o.key in t)try{let s=await o.enrichPaymentRequiredResponse(t[o.key],n);s!==void 0&&(r[o.key]=s)}catch(s){console.warn(`[x402:extensions] extension "${o.key}" failed:`,s)}return Object.keys(r).length>0?r:void 0}function Ht(e,t){if(typeof e=="string"||typeof e=="function")return e;if(t in e)return e[t];let r=`${t.split(":")[0]}:*`;if(r in e)return e[r];if("*"in e)return e["*"];throw new Error(`No payTo configured for network "${t}"`)}function Qe(e){if(e.scheme==="batch-settlement"){let i=Array.isArray(e.network)?e.network[0]:e.network;if(!i)throw new Error('x402Middleware: scheme "batch-settlement" requires a network');let f=typeof e.payTo=="string"?e.payTo:void 0;if(!f)throw new Error('x402Middleware: scheme "batch-settlement" requires a string payTo address');return ke({payTo:f,network:i,price:e.amount,facilitatorUrl:e.facilitatorUrl,route:e.batchSettlement?.route,channelStore:e.batchSettlement?.channelStore,autoSettle:e.batchSettlement?.autoSettle,verbose:e.verbose})}let{payTo:t,amount:n,asset:r,description:o,resourceUrl:s,mimeType:p,timeoutSeconds:y,verbose:g=!1,getResourceUrl:m,getAmount:b,getDescription:c,extensions:a,declarations:h}=e,l=g?console.log.bind(console,"[x402:middleware]"):()=>{},x=typeof t=="function"?t._x402Defaults:void 0,P=e.facilitatorUrl??x?.facilitatorUrl,k=e.network?Array.isArray(e.network)?e.network:[e.network]:x?.network?[x.network]:[me],A=new Map;for(let i of k){let f=Ht(t,i);if(typeof f=="function"){let w=$e(f);if(w&&i!==w)throw new Error(`stripePayTo is configured for "${w}" but middleware includes network "${i}". Stripe only supports Base deposit addresses. Use a static payTo for other chains.`)}A.set(i,X({payTo:f,network:i,asset:r,facilitatorUrl:P,defaultTimeoutSeconds:y,scheme:e.scheme}))}let S=A.get(k[0]);return async(i,f,w)=>{try{let u=i.headers["payment-signature"];if(!u){l("No payment signature, returning 402");let F=m?.(i)??s??`${i.protocol}://${i.get("host")}${i.originalUrl}`,R=b?.(i)??n,C=c?.(i)??o,N=parseFloat(R),M=[],v=null;for(let[,H]of A)try{let Te={amountAtomic:J(N,H.assetDecimals),resourceUrl:F,description:C,mimeType:p,timeoutSeconds:y},Me=await H.buildRequirements(Te);M.push(...Me.accepts),v||(v=Me)}catch(Te){l("Failed to build requirements for a network:",Te)}if(!v||M.length===0){f.status(500).json({error:"Failed to build payment requirements"});return}if(v={...v,accepts:M},a&&a.length>0){let H=await Je(a,h??{},{response:v,request:{method:i.method,path:(i.baseUrl??"")+(i.route?.path??i.path),params:i.params}});H&&(v={...v,extensions:H})}let ee=S.encodeRequirements(v);f.setHeader("PAYMENT-REQUIRED",ee),f.status(402).json({error:"Payment required",accepts:v.accepts,resource:v.resource,...v.extensions?{extensions:v.extensions}:{}});return}l("Payment signature received, verifying...");let d=S;try{let R=JSON.parse(Buffer.from(u,"base64").toString())?.accepted?.network;R&&A.has(R)&&(d=A.get(R))}catch{}let T=await d.verifyPayment(u);if(!T.isValid){if(l("Payment verification failed:",T.invalidReason),e.onVerifyFailed)try{await e.onVerifyFailed({reason:T.invalidReason,resourceUrl:`${i.protocol}://${i.get("host")}${i.originalUrl}`})}catch{}f.status(402).json({error:"Payment verification failed",reason:T.invalidReason});return}l("Payment verified, settling...");let E=await d.settlePayment(u);if(!E.success){l("Payment settlement failed:",E.errorReason),f.status(402).json({error:"Payment settlement failed",reason:E.errorReason});return}l("Payment settled:",E.transaction);let _=E.network||k[0];if(e.onSettlement)try{await e.onSettlement({transaction:E.transaction,network:_,payer:T.payer??"",resourceUrl:`${i.protocol}://${i.get("host")}${i.originalUrl}`})}catch{}i.x402={transaction:E.transaction,payer:T.payer??"",network:_};let O={success:!0,transaction:E.transaction,network:_,payer:T.payer??""};if(E.extensions&&(O.extensions=E.extensions),f.setHeader("PAYMENT-RESPONSE",K(O)),e.sponsoredAccess&&E.extensions?.["sponsored-access"]){let F=E.extensions["sponsored-access"],R=F?.info?.recommendations??F?.recommendations;if(R&&R.length>0){if(l("Injecting sponsored-access recommendations into response"),typeof e.sponsoredAccess=="object"&&e.sponsoredAccess.onMatch)try{e.sponsoredAccess.onMatch(R,{transaction:E.transaction,network:_,payer:T.payer??""})}catch{}let C=f.json.bind(f);f.json=function(M){return typeof e.sponsoredAccess=="object"&&e.sponsoredAccess.inject?C(e.sponsoredAccess.inject(M,R)):M&&typeof M=="object"&&!Array.isArray(M)?C({_x402_sponsored:R,...M}):C(M)}}}w()}catch(u){l("Middleware error:",u),f.status(500).json({error:"Payment processing error"})}}}var Wt=/^\/[a-zA-Z0-9_/:.\-~%]+$/;function Ye(e){if(!e||!Wt.test(e))return!1;let t;try{t=decodeURIComponent(e)}catch{return!1}return!(t.includes("..")||t.includes("://"))}function Z(e){return e.method==="POST"||e.method==="PUT"||e.method==="PATCH"}var Kt=["GET","HEAD","DELETE"],jt=["POST","PUT","PATCH"];function Ze(e,t){let n=t.pathParams!==void 0&&Object.keys(t.pathParams).length>0,r={type:"http",method:e.method};Z(e)?(r.bodyType=e.bodyType,r.body=e.input??{}):e.input!==void 0&&(r.queryParams=e.input),n&&(r.pathParams=t.pathParams);let o=e.output?.example!==void 0?{type:"json",example:e.output.example}:void 0,s=Z(e)?jt:Kt,p={type:{type:"string",const:"http"},method:{type:"string",enum:s}};Z(e)?(p.bodyType={type:"string",enum:["json","form-data","text"]},p.body={type:"object",...e.inputSchema??{}}):e.inputSchema&&(p.queryParams={type:"object",...e.inputSchema}),e.pathParamsSchema&&(p.pathParams={type:"object",...e.pathParamsSchema});let y={input:{type:"object",properties:p,required:Z(e)?["type","method","bodyType","body"]:["type","method"],additionalProperties:!1}};o&&(y.output={type:"object",properties:{type:{type:"string"},example:{type:"object",...e.output?.schema??{}}},required:["type"]});let g={$schema:"https://json-schema.org/draft/2020-12/schema",type:"object",properties:y,required:["input"]},m={info:{input:r,...o?{output:o}:{}},schema:g};return Ye(t.routeTemplate)&&(m.routeTemplate=t.routeTemplate),m}var zt=["GET","HEAD","DELETE","POST","PUT","PATCH"];function et(){return{key:"bazaar",enrichPaymentRequiredResponse:(e,t)=>{if(e==null)return;let n=e,r=(n.method??t.request.method).toUpperCase();if(!zt.includes(r))return;let o={...n,method:r};return Ze(o,{pathParams:t.request.params,routeTemplate:t.request.path})}}}function tt(e){return{bazaar:e}}function D(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}var Gt='<svg width="18" height="18" viewBox="0 0 2000 2000" xmlns="http://www.w3.org/2000/svg"><path d="M1000 2000c554.17 0 1000-445.83 1000-1000S1554.17 0 1000 0 0 445.83 0 1000s445.83 1000 1000 1000z" fill="#2775ca"/><path d="M1275 1158.33c0-145.83-87.5-195.83-262.5-216.66-125-16.67-150-50-150-108.34s41.67-95.83 125-95.83c75 0 116.67 25 137.5 87.5 4.17 12.5 16.67 20.83 29.17 20.83h66.66c16.67 0 29.17-12.5 29.17-29.16v-4.17c-16.67-91.67-91.67-162.5-187.5-170.83v-100c0-16.67-12.5-29.17-33.33-33.34h-62.5c-16.67 0-29.17 12.5-33.34 33.34v95.83c-125 16.67-204.16 100-204.16 204.17 0 137.5 83.33 191.66 258.33 212.5 116.67 20.83 154.17 45.83 154.17 112.5s-58.34 112.5-137.5 112.5c-108.34 0-145.84-45.84-158.34-108.34-4.16-16.66-16.66-25-29.16-25h-70.84c-16.66 0-29.16 12.5-29.16 29.17v4.17c16.66 104.16 83.33 179.16 220.83 200v100c0 16.66 12.5 29.16 33.33 33.33h62.5c16.67 0 29.17-12.5 33.34-33.33v-100c125-20.84 208.33-108.34 208.33-220.84z" fill="#fff"/><path d="M787.5 1595.83c-325-116.66-491.67-479.16-370.83-800 62.5-175 200-308.33 370.83-370.83 16.67-8.33 25-20.83 25-41.67V325c0-16.67-8.33-29.17-25-33.33-4.17 0-12.5 0-16.67 4.16-395.83 125-612.5 545.84-487.5 941.67 75 233.33 254.17 412.5 487.5 487.5 16.67 8.33 33.34 0 37.5-16.67 4.17-4.16 4.17-8.33 4.17-16.66v-58.34c0-12.5-12.5-29.16-25-37.5zM1229.17 295.83c-16.67-8.33-33.34 0-37.5 16.67-4.17 4.17-4.17 8.33-4.17 16.67v58.33c0 16.67 12.5 33.33 25 41.67 325 116.66 491.67 479.16 370.83 800-62.5 175-200 308.33-370.83 370.83-16.67 8.33-25 20.83-25 41.67V1700c0 16.67 8.33 29.17 25 33.33 4.17 0 12.5 0 16.67-4.16 395.83-125 612.5-545.84 487.5-941.67-75-237.5-258.34-416.67-487.5-491.67z" fill="#fff"/></svg>',Vt='<svg width="36" height="36" viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg"><g><path fill="#F2681A" d="m324.93,313.11c-115.5,0-231,0-350,0l350,0z"/><path fill="#FDFAF5" d="m230.43,50.62c1.1.85 2.19 1.7 3.32 2.57 6.02 4.8 11.77 9.88 17.46 15.07.92.84.92.84 1.86 1.69 1.82 1.69 3.59 3.42 5.35 5.16.61.56 1.22 1.13 1.84 1.71 5.66 5.76 6.18 10.43 6.13 18.3.02 1.16.04 2.32.06 3.52.06 3.83.06 7.65.07 11.48.02 2.68.05 5.35.08 8.03.05 5.6.09 11.21.1 16.81.02 7.15.09 14.31.17 21.46.06 5.53.1 11.05.13 16.58.02 2.64.04 5.27.07 7.91.18 17.58.12 32.82-11.24 47.32-7.35 7.27-16.54 12.06-25.42 17.22-1.97 1.16-3.94 2.33-5.91 3.49-7.16 4.24-14.34 8.44-21.53 12.62-4.8 2.79-9.59 5.6-14.38 8.42-1.25.73-2.5 1.47-3.79 2.23-2.32 1.36-4.64 2.73-6.96 4.1-27.47 16.09-27.47 16.09-42.16 12.93-8.06-2.28-14.94-5.82-22.16-10.02-1.17-.67-2.34-1.34-3.54-2.04-24.55-14.25-43.58-27.03-51.9-55.58-1.07-4.58-1.54-8.92-1.52-13.61.28-9.5.28-9.5-3.3-17.97-1.81-1.49-3.68-2.92-5.59-4.28-9.19-7.06-12.7-20.03-14.18-31.06-.54-5.77-.55-11.56-.6-17.35-.03-1.32-.07-2.63-.1-3.99-.01-1.26-.02-2.53-.03-3.83-.02-1.15-.03-2.29-.05-3.47.72-4.02 1.94-5.36 5.21-7.74 2.89-.53 2.89-.53 6.07-.46 1.71.02 1.71.02 3.46.05 1.19.04 2.37.08 3.59.12 1.2.02 2.41.04 3.65.06 2.97.05 5.93.13 8.9.23.14-1.35.29-2.7.43-4.08.63-5 1.78-9.74 3.14-14.58.22-.79.43-1.59.66-2.4.53-1.92 1.06-3.84 1.6-5.76-1.55-.45-1.55-.45-3.13-.9-9.52-3.52-17.1-10.95-21.37-20.1-3.81-9.26-3.87-20.34-.29-29.68 6.49-13.99 16.36-23.23 30.66-29.01 49.81-17.69 115.79 8.35 155.13 38.85z"/><path fill="#F2671A" d="m142.93,22.62c.86.19 1.73.39 2.62.59 36.12 8.21 68.79 24.98 95.38 50.75 1.02.98 2.03 1.97 3.08 2.98 10.84 10.66 10.84 10.66 11.05 14.62-2.06 3.55-5.44 4.18-9.17 5.3-.79.25-1.59.49-2.41.75-28.13 8.43-60.95 6.37-87.13-7.16-.86-.49-1.71-.97-2.6-1.48-7.37-4.05-12.59-3.36-20.59-1.54-22.76 4-48.47 1.53-68.69-9.74-4.88-3.88-8.23-8.29-10.21-14.22-.93-10.38-.67-18.44 5.83-26.83 19.57-23.38 55.99-20.36 82.83-14z"/><path fill="#F16619" d="m44.93,129.12c27.36-.03 54.72-.05 82.08-.06 12.7-.01 25.41-.01 38.11-.03 11.07-.01 22.14-.02 33.2-.02 5.86 0 11.73-.01 17.59-.01 5.51-.01 11.03-.01 16.54-.01 2.03 0 4.06 0 6.09-.01 2.76-.01 5.52 0 8.28 0 .81 0 1.63-.01 2.47-.01 5.51.02 5.51.02 6.81 1.32.22 3.43.22 3.43 0 7-2.75 2.75-3.42 2.66-7.15 2.82-1.41.07-1.41.07-2.85.14-1.47.05-1.47.05-2.98.11-1.49.07-1.49.07-3 .14-2.45.11-4.9.21-7.35.3-.2 1.3-.4 2.59-.6 3.93-2.57 16.08-5.93 29.89-18.89 40.86-10.35 7.28-21.87 8.49-34.17 7.71-13.11-2.33-22.52-9.19-30.33-19.83-4.49-7.64-4.8-17.05-5.83-25.67-4.24.39-8.47.77-12.83 1.17-.28 1.84-.28 1.84-.56 3.71-2.32 14.39-5.63 23.35-16.95 33.11-2.32 1.67-2.32 1.67-4.65 1.67 4 4.67 9.06 6.59 14.87 8.24 3.79 1.09 3.79 1.09 6.12 3.43-.65 5.31-.65 5.31-2.33 7-8.42-.27-15.13-2.29-22.17-7-1.09-1.21-2.17-2.43-3.25-3.65-2.72-2.81-4.45-3.84-8.36-4.16-1.67-.02-3.34-.02-5.01.01-1.77-.04-3.54-.09-5.3-.15-1.27-.04-1.27-.04-2.56-.08-9.26-.54-17.6-4.56-24.51-10.64-9.58-11.11-11.03-22.56-10.72-36.82.02-1.4.03-2.8.05-4.24.04-3.42.1-6.85.17-10.27z"/><path fill="#F26117" d="m172.68,203.08c7.27.09 13.23 1.97 18.87 6.65 2.88 3.07 3.86 5.12 4.25 9.32-.12 1.01-.24 2.02-.36 3.06-2.55.95-2.55.95-5.83 1.17-3.28-2.84-3.28-2.84-5.83-5.83-.36.58-.71 1.16-1.08 1.75-7.6 11.29-20.06 17.74-33.05 21.09-20.36 3.1-36.81-1.66-53.37-13.73-2.33-2.11-2.33-2.11-4.67-5.61.42-3.45.99-4.49 3.5-7 4.07.37 5.95 2.13 8.75 4.96 9.81 8.93 22.53 11.87 35.51 11.69 11.74-1.05 22.38-5.85 31.57-13.15 2.06-2.45 2.06-2.45 3.5-4.67-1.66.07-1.66.07-3.35.15-3.65-.15-3.65-.15-5.98-2.48.75-6.18 1.46-7.19 7.58-7.36z"/></g></svg>',Xt=`
|
|
2
2
|
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Orbitron:wght@500;700&display=swap');
|
|
3
3
|
*{margin:0;padding:0;box-sizing:border-box}
|
|
4
4
|
body{font-family:'Inter',system-ui,-apple-system,sans-serif;background:#0a0a0a;color:#e2e8f0;min-height:100vh;display:flex;align-items:center;justify-content:center;padding:1rem}
|
|
@@ -233,7 +233,7 @@ if (btn) {
|
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
235
|
</script>
|
|
236
|
-
`;function Yt(e,t,n,r,o,s){let p="?",y="This resource requires payment",g="";try{let c=JSON.parse(Buffer.from(e,"base64").toString()),
|
|
236
|
+
`;function Yt(e,t,n,r,o,s){let p="?",y="This resource requires payment",g="";try{let c=JSON.parse(Buffer.from(e,"base64").toString()),a=c.accepts?.[0];if(a){let h=a.amount??a.maxAmountRequired??"0",l=a.extra?.decimals||6;p=(Number(h)/Math.pow(10,l)).toFixed(l>4?4:2),g=a.network||""}c.resource?.description&&(y=c.resource.description)}catch{}let m=g.includes("solana")?"Solana":g.includes("eip155")?"Base":"",b=r.showEndpoint?`<div class="endpoint"><code>${D(n)} ${D(t)}</code></div>`:"";return`<!DOCTYPE html>
|
|
237
237
|
<html lang="en">
|
|
238
238
|
<head>
|
|
239
239
|
<meta charset="utf-8">
|
|
@@ -281,6 +281,6 @@ if (btn) {
|
|
|
281
281
|
></div>
|
|
282
282
|
${Qt}
|
|
283
283
|
</body>
|
|
284
|
-
</html>`}function rt(e={}){let t={title:e.title??"Payment Required",branding:e.branding??'Powered by <a href="https://docs.dexter.cash/docs/sdk/">Dexter x402</a>',sdkUrl:e.sdkUrl??"https://docs.dexter.cash/docs/sdk/",showEndpoint:e.showEndpoint??!0},n=e.rpcUrl??"https://api.dexter.cash/api/solana/rpc";return(r,o,s)=>{let p=o.json.bind(o);o.json=function(y){if(o.statusCode===402&&r.accepts("html")&&!r.headers["payment-signature"]){let g=o.getHeader("PAYMENT-REQUIRED")||o.getHeader("payment-required");if(g&&typeof g=="string"){let m;if(r.body&&typeof r.body=="object"&&Object.keys(r.body).length>0)try{m=JSON.stringify(r.body)}catch{}let b=Yt(g,r.originalUrl,r.method,t,n,m);return o.setHeader("Content-Security-Policy","default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; connect-src *; img-src data:; frame-ancestors 'none'"),o.setHeader("X-Content-Type-Options","nosniff"),o.status(402).type("html").send(b),o}}return p(y)},s()}}var ye=Se(require("crypto"),1),Zt=/^(\d+)(m|h|d|w)$/;function er(e){let t=e.match(Zt);if(!t)return null;let n=parseInt(t[1],10);switch(t[2]){case"m":return n*60;case"h":return n*3600;case"d":return n*86400;case"w":return n*604800;default:return null}}function nt(e){return e>=604800&&e%604800===0?`${e/604800} week${e/604800>1?"s":""}`:e>=86400&&e%86400===0?`${e/86400} day${e/86400>1?"s":""}`:e>=3600&&e%3600===0?`${e/3600} hour${e/3600>1?"s":""}`:e>=60&&e%60===0?`${e/60} minute${e/60>1?"s":""}`:`${e} second${e>1?"s":""}`}function tr(e,t){let n=Buffer.from(JSON.stringify({alg:"HS256",typ:"JWT"})).toString("base64url"),r=Buffer.from(JSON.stringify(e)).toString("base64url"),o=ye.default.createHmac("sha256",t).update(`${n}.${r}`).digest("base64url");return`${n}.${r}.${o}`}function rr(e,t){try{let n=e.split(".");if(n.length!==3)return null;let[r,o,s]=n,p=ye.default.createHmac("sha256",t).update(`${r}.${o}`).digest("base64url");if(s!==p)return null;let y=JSON.parse(Buffer.from(o,"base64url").toString());return y.exp&&Date.now()/1e3>y.exp||y.sub!=="x402-access-pass"?null:y}catch{return null}}function ot(e){let{payTo:t,network:n=me,asset:r,facilitatorUrl:o,tiers:s,ratePerHour:p,secret:y,issuer:g="x402-access-pass",verbose:m=!1,description:b}=e,c=y??ye.default.randomBytes(32);if(y||console.warn("[x402:access-pass] No secret provided \u2014 access passes will be invalidated on server restart. Set `secret` for production use."),!s&&!p)throw new Error("x402AccessPass: at least one of `tiers` or `ratePerHour` is required");let i=m?console.log.bind(console,"[x402:access-pass]"):()=>{},h=r?.decimals??de,l=[];if(s){for(let[a,f]of Object.entries(s)){let w=er(a);if(!w){console.warn(`x402AccessPass: skipping tier "${a}" \u2014 unrecognized duration format (use 5m, 1h, 24h, 7d)`);continue}l.push({id:a,label:nt(w),seconds:w,price:f,priceAtomic:J(parseFloat(f),h)})}l.sort((a,f)=>a.seconds-f.seconds)}let x=X({payTo:t,network:n,asset:r,facilitatorUrl:o}),P={tiers:l.length>0?l:void 0,ratePerHour:p||void 0,issuer:g},k=K(P);function A(a){if(!p)throw new Error("Custom durations not supported \u2014 no ratePerHour configured");let f=a/3600,w=(parseFloat(p)*f).toFixed(h>4?4:2);return{price:w,priceAtomic:J(parseFloat(w),h)}}function S(a){let f=a.query.tier,w=a.query.duration;if(f){let d=l.find(T=>T.id===f);if(d)return{tier:d.id,seconds:d.seconds,price:d.price,priceAtomic:d.priceAtomic,label:d.label}}if(w){let d=parseInt(w,10);if(d>0&&p){let T=A(d);return{tier:"custom",seconds:d,...T,label:nt(d)}}}if(l.length>0){let d=l[0];return{tier:d.id,seconds:d.seconds,price:d.price,priceAtomic:d.priceAtomic,label:d.label}}return{tier:"custom",seconds:3600,...A(3600),label:"1 hour"}}return async(a,f,w)=>{try{let u=a.headers.authorization;if(u?.startsWith("Bearer ")){let R=rr(u.slice(7),c);if(R)return i("Valid access pass:",R.tier,"| expires:",new Date(R.exp*1e3).toISOString()),a.accessPass={tier:R.tier,duration:R.duration,expiresAt:new Date(R.exp*1e3).toISOString(),payer:R.payer,network:R.network},w();i("Invalid or expired access pass token")}let d=a.headers["payment-signature"];if(d){i("Payment signature received, verifying for pass purchase...");let R=await x.verifyPayment(d);if(!R.isValid){i("Payment verification failed:",R.invalidReason),f.status(402).json({error:"Payment verification failed",reason:R.invalidReason});return}let C=await x.settlePayment(d);if(!C.success){i("Payment settlement failed:",C.errorReason),f.status(402).json({error:"Payment settlement failed",reason:C.errorReason});return}i("Payment settled:",C.transaction);let N=S(a),M=Math.floor(Date.now()/1e3),v={sub:"x402-access-pass",tier:N.tier,duration:N.seconds,iat:M,exp:M+N.seconds,payer:R.payer??"",network:n,iss:g},ee=tr(v,c);a.x402={transaction:C.transaction,payer:R.payer??"",network:n};let H={success:!0,transaction:C.transaction,network:n,payer:R.payer??""};f.setHeader("PAYMENT-RESPONSE",K(H)),f.setHeader("ACCESS-PASS",ee),f.json({accessPass:{token:ee,tier:N.tier,duration:N.label,durationSeconds:N.seconds,expiresAt:new Date((M+N.seconds)*1e3).toISOString(),usage:"Include on subsequent requests as: Authorization: Bearer <token>"},transaction:C.transaction,payer:R.payer});return}i("No access pass or payment, returning 402");let T=S(a),E=T.priceAtomic,_=`${a.protocol}://${a.get("host")}${a.originalUrl}`,O=await x.buildRequirements({amountAtomic:E,resourceUrl:_,description:b||`Access pass: ${T.label}`,mimeType:"application/json"}),F=x.encodeRequirements(O);f.setHeader("PAYMENT-REQUIRED",F),f.setHeader("X-ACCESS-PASS-TIERS",k),f.status(402).json({error:"Access pass required",message:"Purchase an access pass to unlock unlimited API access for a time window.",accepts:O.accepts,resource:O.resource,accessPass:{tiers:l.length>0?l:void 0,ratePerHour:p||void 0,usage:"Add ?tier=<id> or ?duration=<seconds> to your payment request to choose a pass duration."}})}catch(u){i("Access pass middleware error:",u),f.status(500).json({error:"Payment processing error",message:u instanceof Error?u.message:"Unknown error"})}}}var ge=require("crypto"),nr=300;function st(e){let t={unitSize:e.unitSize,ratePerUnit:e.ratePerUnit,minUsd:e.minUsd??.01,maxUsd:e.maxUsd??1/0,roundingMode:e.roundingMode??"ceil",decimals:e.decimals??6},{unitSize:n,ratePerUnit:r,minUsd:o,maxUsd:s,roundingMode:p,decimals:y}=t;if(n<=0)throw new Error("unitSize must be positive");if(r<=0)throw new Error("ratePerUnit must be positive");if(o<0)throw new Error("minUsd cannot be negative");if(s<o)throw new Error("maxUsd must be >= minUsd");let g=(0,ge.randomBytes)(32);function m(i,h){let l=JSON.stringify({unitSize:n,ratePerUnit:r,minUsd:o,maxUsd:s===1/0?"none":s,roundingMode:p}),x=`${i}|${l}|${h}`;return(0,ge.createHmac)("sha256",g).update(x).digest("hex").slice(0,16)}function b(i){let h=i.length,l=h/n,x;switch(p){case"ceil":x=Math.ceil(l);break;case"floor":x=Math.floor(l);break;case"round":x=Math.round(l);break}h>0&&x===0&&(x=1);let P=x*r;P=Math.max(o,P),P=Math.min(s,P);let k=Math.pow(10,y),A=Math.floor(P*k).toString(),S=Math.floor(Date.now()/1e3),a=m(i,S),f=`${S}.${a}`;return{amountAtomic:A,usdAmount:P,quoteHash:f,units:x,inputLength:h}}function c(i,h){if(!h)return!1;let l=h.indexOf(".");if(l===-1)return!1;let x=parseInt(h.slice(0,l),10),P=h.slice(l+1);if(isNaN(x)||!P)return!1;let k=Math.floor(Date.now()/1e3)-x;if(k<0||k>nr)return!1;let A=m(i,x);if(P.length!==A.length)return!1;let S=0;for(let a=0;a<P.length;a++)S|=P.charCodeAt(a)^A.charCodeAt(a);return S===0}return{calculate:b,validateQuote:c,config:t}}function it(e){let t=e.ratePerUnit.toFixed(2),n=e.unitSize.toLocaleString();return`from $${t} per ${n} chars`}var bt=require("crypto");var $={usesMaxCompletionTokens:!1,supportsTemperature:!0,supportsTopP:!0,supportsFrequencyPenalty:!0,supportsPresencePenalty:!0,supportsReasoningEffort:!1,supportsStreaming:!0,supportsSystemMessage:!0,supportsTools:!0,supportsStructuredOutput:!0},j={usesMaxCompletionTokens:!0,supportsTemperature:!1,supportsTopP:!1,supportsFrequencyPenalty:!1,supportsPresencePenalty:!1,supportsReasoningEffort:!1,supportsStreaming:!0,supportsSystemMessage:!0,supportsTools:!0,supportsStructuredOutput:!0},q={usesMaxCompletionTokens:!0,supportsTemperature:!1,supportsTopP:!1,supportsFrequencyPenalty:!1,supportsPresencePenalty:!1,supportsReasoningEffort:!0,supportsStreaming:!0,supportsSystemMessage:!0,supportsTools:!0,supportsStructuredOutput:!0},at={...q,supportsStreaming:!1},I=[{id:"gpt-4o-mini",displayName:"GPT-4o Mini",family:"gpt-4o",tier:"fast",capabilityRank:3,modalities:["text","vision"],apiType:"chat",pricing:{input:.15,output:.6,cached:.075},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:$,deprecated:!1,description:"Fast, affordable small model with vision support"},{id:"gpt-4.1-nano",displayName:"GPT-4.1 Nano",family:"gpt-4.1",tier:"fast",capabilityRank:2,modalities:["text"],apiType:"chat",pricing:{input:.1,output:.4,cached:.025},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:32768,parameters:$,deprecated:!1,description:"Smallest 4.1 model, very fast and cheap"},{id:"gpt-4.1-mini",displayName:"GPT-4.1 Mini",family:"gpt-4.1",tier:"fast",capabilityRank:4,modalities:["text"],apiType:"chat",pricing:{input:.4,output:1.6,cached:.1},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:32768,parameters:$,deprecated:!1,description:"Balanced 4.1 model, good price/performance"},{id:"gpt-5-nano",displayName:"GPT-5 Nano",family:"gpt-5",tier:"fast",capabilityRank:1,modalities:["text"],apiType:"chat",pricing:{input:.05,output:.4,cached:.005},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:j,deprecated:!1,description:"Cheapest GPT-5 variant, extremely fast"},{id:"gpt-5-mini",displayName:"GPT-5 Mini",family:"gpt-5",tier:"fast",capabilityRank:5,modalities:["text"],apiType:"chat",pricing:{input:.25,output:2,cached:.025},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:j,deprecated:!1,description:"Small but capable GPT-5, great value"},{id:"gpt-4o",displayName:"GPT-4o",family:"gpt-4o",tier:"standard",capabilityRank:5,modalities:["text","vision"],apiType:"chat",pricing:{input:2.5,output:10,cached:1.25},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:$,deprecated:!1,description:"Flagship multimodal model with vision"},{id:"gpt-4.1",displayName:"GPT-4.1",family:"gpt-4.1",tier:"standard",capabilityRank:6,modalities:["text"],apiType:"chat",pricing:{input:2,output:8,cached:.5},contextWindow:1e6,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:$,deprecated:!1,description:"Long context specialist, 1M token window"},{id:"gpt-5",displayName:"GPT-5",family:"gpt-5",tier:"standard",capabilityRank:7,modalities:["text"],apiType:"chat",pricing:{input:1.25,output:10,cached:.125},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:j,deprecated:!1,description:"Base GPT-5, excellent all-around"},{id:"gpt-5.1",displayName:"GPT-5.1",family:"gpt-5",tier:"standard",capabilityRank:8,modalities:["text"],apiType:"chat",pricing:{input:1.25,output:10,cached:.125},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:j,deprecated:!1,description:"Improved GPT-5 with better instruction following"},{id:"gpt-5.2",displayName:"GPT-5.2",family:"gpt-5",tier:"standard",capabilityRank:9,modalities:["text"],apiType:"chat",pricing:{input:1.75,output:14,cached:.175},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:j,deprecated:!1,description:"Latest GPT-5, most capable standard model"},{id:"o1-mini",displayName:"o1 Mini",family:"o1",tier:"reasoning",capabilityRank:3,modalities:["text"],apiType:"chat",pricing:{input:1.1,output:4.4,cached:.55},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:q,deprecated:!1,description:"Fast reasoning model, good for math/code"},{id:"o3-mini",displayName:"o3 Mini",family:"o3",tier:"reasoning",capabilityRank:4,modalities:["text"],apiType:"chat",pricing:{input:1.1,output:4.4,cached:.55},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:q,deprecated:!1,description:"Improved mini reasoner with better efficiency"},{id:"o4-mini",displayName:"o4 Mini",family:"o4",tier:"reasoning",capabilityRank:5,modalities:["text"],apiType:"chat",pricing:{input:1.1,output:4.4,cached:.275},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:q,deprecated:!1,description:"Latest mini reasoner, best reasoning per dollar"},{id:"o3",displayName:"o3",family:"o3",tier:"reasoning",capabilityRank:7,modalities:["text"],apiType:"chat",pricing:{input:2,output:8,cached:.5},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:q,deprecated:!1,description:"Full o3 reasoning model, excellent for complex problems"},{id:"o1",displayName:"o1",family:"o1",tier:"reasoning",capabilityRank:8,modalities:["text"],apiType:"chat",pricing:{input:15,output:60,cached:7.5},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:q,deprecated:!1,description:"Original full reasoning model, very capable"},{id:"gpt-5-pro",displayName:"GPT-5 Pro",family:"gpt-5",tier:"premium",capabilityRank:7,modalities:["text"],apiType:"chat",pricing:{input:15,output:120},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:32768,parameters:j,deprecated:!1,description:"Enhanced GPT-5 for demanding tasks"},{id:"gpt-5.2-pro",displayName:"GPT-5.2 Pro",family:"gpt-5",tier:"premium",capabilityRank:8,modalities:["text"],apiType:"chat",pricing:{input:21,output:168},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:32768,parameters:j,deprecated:!1,description:"Most capable standard model available"},{id:"o3-pro",displayName:"o3 Pro",family:"o3",tier:"premium",capabilityRank:9,modalities:["text"],apiType:"chat",pricing:{input:20,output:80},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:at,deprecated:!1,description:"Premium o3 with extended thinking time"},{id:"o1-pro",displayName:"o1 Pro",family:"o1",tier:"premium",capabilityRank:10,modalities:["text"],apiType:"chat",pricing:{input:150,output:600},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:at,deprecated:!1,description:"Most capable reasoning model, extended compute"},{id:"o3-deep-research",displayName:"o3 Deep Research",family:"o3",tier:"specialized",capabilityRank:8,modalities:["text"],apiType:"responses",pricing:{input:10,output:40,cached:2.5},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:{...q,supportsStreaming:!1},deprecated:!1,description:"Extended research sessions with web access"},{id:"o4-mini-deep-research",displayName:"o4 Mini Deep Research",family:"o4",tier:"specialized",capabilityRank:6,modalities:["text"],apiType:"responses",pricing:{input:2,output:8,cached:.5},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:{...q,supportsStreaming:!1},deprecated:!1,description:"Affordable deep research with o4 mini"},{id:"computer-use-preview",displayName:"Computer Use Preview",family:"computer-use",tier:"specialized",capabilityRank:5,modalities:["text","vision"],apiType:"responses",pricing:{input:3,output:12},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:{...$,supportsReasoningEffort:!1},deprecated:!1,description:"Can control computer interfaces via screenshots"},{id:"gpt-realtime",displayName:"GPT Realtime",family:"gpt-realtime",tier:"specialized",capabilityRank:7,modalities:["text","audio","realtime"],apiType:"chat",pricing:{input:4,output:16,cached:.4},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:4096,parameters:{...$,supportsReasoningEffort:!1},deprecated:!1,description:"Real-time audio conversation model"},{id:"gpt-realtime-mini",displayName:"GPT Realtime Mini",family:"gpt-realtime",tier:"specialized",capabilityRank:4,modalities:["text","audio","realtime"],apiType:"chat",pricing:{input:.6,output:2.4,cached:.06},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:4096,parameters:{...$,supportsReasoningEffort:!1},deprecated:!1,description:"Affordable real-time audio model"},{id:"gpt-4o-2024-05-13",displayName:"GPT-4o (May 2024)",family:"gpt-4o",tier:"standard",capabilityRank:4,modalities:["text","vision"],apiType:"chat",pricing:{input:5,output:15},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:4096,parameters:$,deprecated:!0,description:"Original GPT-4o snapshot, use gpt-4o instead"}],ve=new Map(I.map(e=>[e.id,e]));function he(e){let t=ve.get(e);if(!t)throw new Error(`Unknown model: ${e}. Use getAvailableModelIds() to see valid options.`);return t}function ct(e){return ve.get(e)}function pt(e){return ve.has(e)}function ut(){return I.map(e=>e.id)}function lt(e){return I.filter(t=>t.tier===e&&!t.deprecated).sort((t,n)=>t.capabilityRank-n.capabilityRank)}function dt(e){return I.filter(t=>t.family===e).sort((t,n)=>t.capabilityRank-n.capabilityRank)}function mt(){let e={fast:1,standard:2,reasoning:3,premium:4,specialized:5};return I.filter(t=>!t.deprecated).sort((t,n)=>{let r=e[t.tier]-e[n.tier];return r!==0?r:t.capabilityRank-n.capabilityRank})}function ft(){return I.filter(e=>!e.deprecated&&e.modalities.includes("text")&&!e.modalities.includes("realtime")&&e.apiType!=="responses").sort((e,t)=>{let n={fast:1,standard:2,reasoning:3,premium:4,specialized:5},r=n[e.tier]-n[t.tier];return r!==0?r:e.capabilityRank-t.capabilityRank})}function yt(e="fast"){let t={fast:1,standard:2,reasoning:3,premium:4,specialized:5},n=t[e];return I.filter(o=>!o.deprecated&&t[o.tier]>=n).sort((o,s)=>o.pricing.input-s.pricing.input)[0]}function gt(e,t,n,r=!1){let o=he(e),s=r&&o.pricing.cached?t/1e6*o.pricing.cached:t/1e6*o.pricing.input,p=n/1e6*o.pricing.output;return s+p}function ht(e){let t=he(e);return`$${t.pricing.input.toFixed(2)} in / $${t.pricing.output.toFixed(2)} out per 1M tokens`}var xe=Object.fromEntries(I.map(e=>[e.id,{input:e.pricing.input,output:e.pricing.output,cached:e.pricing.cached,maxTokens:e.defaultMaxOutput,tier:e.tier}]));var be=null;async function or(){if(be)return be;try{return be=await import("tiktoken"),be}catch{throw new Error('Token pricing requires the "tiktoken" package. Install with: npm install tiktoken')}}var B=xe,z="gpt-4o-mini";async function sr(e){let t=await or();try{return t.encoding_for_model(e)}catch{return t.get_encoding("cl100k_base")}}async function Pe(e,t=z){let n=await sr(t);try{return n.encode(e).length}finally{n.free()}}function xt(e,t,n,r){let o=JSON.stringify({model:t,rate:n,tokens:r});return(0,bt.createHash)("sha256").update(e+o).digest("hex").slice(0,16)}function Pt(e={}){let t=e.model??z,n=B[t],r={input:e.inputRate??n?.input??B[z].input,output:e.outputRate??n?.output??B[z].output,maxTokens:e.maxTokens??n?.maxTokens??4096,tier:e.tier??n?.tier??"custom"},o=e.tokenizer,s={model:t,inputRate:r.input,outputRate:r.output,maxTokens:r.maxTokens,tier:r.tier,tokenizer:o??(i=>Pe(i,t)),minUsd:e.minUsd??.001,maxUsd:e.maxUsd??50,decimals:e.decimals??6},{minUsd:p,maxUsd:y,decimals:g}=s;async function m(i){return o?o(i):Pe(i,t)}async function b(i,h){let l=h?`${h}
|
|
284
|
+
</html>`}function rt(e={}){let t={title:e.title??"Payment Required",branding:e.branding??'Powered by <a href="https://docs.dexter.cash/docs/sdk/">Dexter x402</a>',sdkUrl:e.sdkUrl??"https://docs.dexter.cash/docs/sdk/",showEndpoint:e.showEndpoint??!0},n=e.rpcUrl??"https://api.dexter.cash/api/solana/rpc";return(r,o,s)=>{let p=o.json.bind(o);o.json=function(y){if(o.statusCode===402&&r.accepts("html")&&!r.headers["payment-signature"]){let g=o.getHeader("PAYMENT-REQUIRED")||o.getHeader("payment-required");if(g&&typeof g=="string"){let m;if(r.body&&typeof r.body=="object"&&Object.keys(r.body).length>0)try{m=JSON.stringify(r.body)}catch{}let b=Yt(g,r.originalUrl,r.method,t,n,m);return o.setHeader("Content-Security-Policy","default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; connect-src *; img-src data:; frame-ancestors 'none'"),o.setHeader("X-Content-Type-Options","nosniff"),o.status(402).type("html").send(b),o}}return p(y)},s()}}var ye=Se(require("crypto"),1),Zt=/^(\d+)(m|h|d|w)$/;function er(e){let t=e.match(Zt);if(!t)return null;let n=parseInt(t[1],10);switch(t[2]){case"m":return n*60;case"h":return n*3600;case"d":return n*86400;case"w":return n*604800;default:return null}}function nt(e){return e>=604800&&e%604800===0?`${e/604800} week${e/604800>1?"s":""}`:e>=86400&&e%86400===0?`${e/86400} day${e/86400>1?"s":""}`:e>=3600&&e%3600===0?`${e/3600} hour${e/3600>1?"s":""}`:e>=60&&e%60===0?`${e/60} minute${e/60>1?"s":""}`:`${e} second${e>1?"s":""}`}function tr(e,t){let n=Buffer.from(JSON.stringify({alg:"HS256",typ:"JWT"})).toString("base64url"),r=Buffer.from(JSON.stringify(e)).toString("base64url"),o=ye.default.createHmac("sha256",t).update(`${n}.${r}`).digest("base64url");return`${n}.${r}.${o}`}function rr(e,t){try{let n=e.split(".");if(n.length!==3)return null;let[r,o,s]=n,p=ye.default.createHmac("sha256",t).update(`${r}.${o}`).digest("base64url");if(s!==p)return null;let y=JSON.parse(Buffer.from(o,"base64url").toString());return y.exp&&Date.now()/1e3>y.exp||y.sub!=="x402-access-pass"?null:y}catch{return null}}function ot(e){let{payTo:t,network:n=me,asset:r,facilitatorUrl:o,tiers:s,ratePerHour:p,secret:y,issuer:g="x402-access-pass",verbose:m=!1,description:b}=e,c=y??ye.default.randomBytes(32);if(y||console.warn("[x402:access-pass] No secret provided \u2014 access passes will be invalidated on server restart. Set `secret` for production use."),!s&&!p)throw new Error("x402AccessPass: at least one of `tiers` or `ratePerHour` is required");let a=m?console.log.bind(console,"[x402:access-pass]"):()=>{},h=r?.decimals??de,l=[];if(s){for(let[i,f]of Object.entries(s)){let w=er(i);if(!w){console.warn(`x402AccessPass: skipping tier "${i}" \u2014 unrecognized duration format (use 5m, 1h, 24h, 7d)`);continue}l.push({id:i,label:nt(w),seconds:w,price:f,priceAtomic:J(parseFloat(f),h)})}l.sort((i,f)=>i.seconds-f.seconds)}let x=X({payTo:t,network:n,asset:r,facilitatorUrl:o}),P={tiers:l.length>0?l:void 0,ratePerHour:p||void 0,issuer:g},k=K(P);function A(i){if(!p)throw new Error("Custom durations not supported \u2014 no ratePerHour configured");let f=i/3600,w=(parseFloat(p)*f).toFixed(h>4?4:2);return{price:w,priceAtomic:J(parseFloat(w),h)}}function S(i){let f=i.query.tier,w=i.query.duration;if(f){let d=l.find(T=>T.id===f);if(d)return{tier:d.id,seconds:d.seconds,price:d.price,priceAtomic:d.priceAtomic,label:d.label}}if(w){let d=parseInt(w,10);if(d>0&&p){let T=A(d);return{tier:"custom",seconds:d,...T,label:nt(d)}}}if(l.length>0){let d=l[0];return{tier:d.id,seconds:d.seconds,price:d.price,priceAtomic:d.priceAtomic,label:d.label}}return{tier:"custom",seconds:3600,...A(3600),label:"1 hour"}}return async(i,f,w)=>{try{let u=i.headers.authorization;if(u?.startsWith("Bearer ")){let R=rr(u.slice(7),c);if(R)return a("Valid access pass:",R.tier,"| expires:",new Date(R.exp*1e3).toISOString()),i.accessPass={tier:R.tier,duration:R.duration,expiresAt:new Date(R.exp*1e3).toISOString(),payer:R.payer,network:R.network},w();a("Invalid or expired access pass token")}let d=i.headers["payment-signature"];if(d){a("Payment signature received, verifying for pass purchase...");let R=await x.verifyPayment(d);if(!R.isValid){a("Payment verification failed:",R.invalidReason),f.status(402).json({error:"Payment verification failed",reason:R.invalidReason});return}let C=await x.settlePayment(d);if(!C.success){a("Payment settlement failed:",C.errorReason),f.status(402).json({error:"Payment settlement failed",reason:C.errorReason});return}a("Payment settled:",C.transaction);let N=S(i),M=Math.floor(Date.now()/1e3),v={sub:"x402-access-pass",tier:N.tier,duration:N.seconds,iat:M,exp:M+N.seconds,payer:R.payer??"",network:n,iss:g},ee=tr(v,c);i.x402={transaction:C.transaction,payer:R.payer??"",network:n};let H={success:!0,transaction:C.transaction,network:n,payer:R.payer??""};f.setHeader("PAYMENT-RESPONSE",K(H)),f.setHeader("ACCESS-PASS",ee),f.json({accessPass:{token:ee,tier:N.tier,duration:N.label,durationSeconds:N.seconds,expiresAt:new Date((M+N.seconds)*1e3).toISOString(),usage:"Include on subsequent requests as: Authorization: Bearer <token>"},transaction:C.transaction,payer:R.payer});return}a("No access pass or payment, returning 402");let T=S(i),E=T.priceAtomic,_=`${i.protocol}://${i.get("host")}${i.originalUrl}`,O=await x.buildRequirements({amountAtomic:E,resourceUrl:_,description:b||`Access pass: ${T.label}`,mimeType:"application/json"}),F=x.encodeRequirements(O);f.setHeader("PAYMENT-REQUIRED",F),f.setHeader("X-ACCESS-PASS-TIERS",k),f.status(402).json({error:"Access pass required",message:"Purchase an access pass to unlock unlimited API access for a time window.",accepts:O.accepts,resource:O.resource,accessPass:{tiers:l.length>0?l:void 0,ratePerHour:p||void 0,usage:"Add ?tier=<id> or ?duration=<seconds> to your payment request to choose a pass duration."}})}catch(u){a("Access pass middleware error:",u),f.status(500).json({error:"Payment processing error",message:u instanceof Error?u.message:"Unknown error"})}}}var ge=require("crypto"),nr=300;function st(e){let t={unitSize:e.unitSize,ratePerUnit:e.ratePerUnit,minUsd:e.minUsd??.01,maxUsd:e.maxUsd??1/0,roundingMode:e.roundingMode??"ceil",decimals:e.decimals??6},{unitSize:n,ratePerUnit:r,minUsd:o,maxUsd:s,roundingMode:p,decimals:y}=t;if(n<=0)throw new Error("unitSize must be positive");if(r<=0)throw new Error("ratePerUnit must be positive");if(o<0)throw new Error("minUsd cannot be negative");if(s<o)throw new Error("maxUsd must be >= minUsd");let g=(0,ge.randomBytes)(32);function m(a,h){let l=JSON.stringify({unitSize:n,ratePerUnit:r,minUsd:o,maxUsd:s===1/0?"none":s,roundingMode:p}),x=`${a}|${l}|${h}`;return(0,ge.createHmac)("sha256",g).update(x).digest("hex").slice(0,16)}function b(a){let h=a.length,l=h/n,x;switch(p){case"ceil":x=Math.ceil(l);break;case"floor":x=Math.floor(l);break;case"round":x=Math.round(l);break}h>0&&x===0&&(x=1);let P=x*r;P=Math.max(o,P),P=Math.min(s,P);let k=Math.pow(10,y),A=Math.floor(P*k).toString(),S=Math.floor(Date.now()/1e3),i=m(a,S),f=`${S}.${i}`;return{amountAtomic:A,usdAmount:P,quoteHash:f,units:x,inputLength:h}}function c(a,h){if(!h)return!1;let l=h.indexOf(".");if(l===-1)return!1;let x=parseInt(h.slice(0,l),10),P=h.slice(l+1);if(isNaN(x)||!P)return!1;let k=Math.floor(Date.now()/1e3)-x;if(k<0||k>nr)return!1;let A=m(a,x);if(P.length!==A.length)return!1;let S=0;for(let i=0;i<P.length;i++)S|=P.charCodeAt(i)^A.charCodeAt(i);return S===0}return{calculate:b,validateQuote:c,config:t}}function it(e){let t=e.ratePerUnit.toFixed(2),n=e.unitSize.toLocaleString();return`from $${t} per ${n} chars`}var bt=require("crypto");var $={usesMaxCompletionTokens:!1,supportsTemperature:!0,supportsTopP:!0,supportsFrequencyPenalty:!0,supportsPresencePenalty:!0,supportsReasoningEffort:!1,supportsStreaming:!0,supportsSystemMessage:!0,supportsTools:!0,supportsStructuredOutput:!0},j={usesMaxCompletionTokens:!0,supportsTemperature:!1,supportsTopP:!1,supportsFrequencyPenalty:!1,supportsPresencePenalty:!1,supportsReasoningEffort:!1,supportsStreaming:!0,supportsSystemMessage:!0,supportsTools:!0,supportsStructuredOutput:!0},q={usesMaxCompletionTokens:!0,supportsTemperature:!1,supportsTopP:!1,supportsFrequencyPenalty:!1,supportsPresencePenalty:!1,supportsReasoningEffort:!0,supportsStreaming:!0,supportsSystemMessage:!0,supportsTools:!0,supportsStructuredOutput:!0},at={...q,supportsStreaming:!1},I=[{id:"gpt-4o-mini",displayName:"GPT-4o Mini",family:"gpt-4o",tier:"fast",capabilityRank:3,modalities:["text","vision"],apiType:"chat",pricing:{input:.15,output:.6,cached:.075},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:$,deprecated:!1,description:"Fast, affordable small model with vision support"},{id:"gpt-4.1-nano",displayName:"GPT-4.1 Nano",family:"gpt-4.1",tier:"fast",capabilityRank:2,modalities:["text"],apiType:"chat",pricing:{input:.1,output:.4,cached:.025},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:32768,parameters:$,deprecated:!1,description:"Smallest 4.1 model, very fast and cheap"},{id:"gpt-4.1-mini",displayName:"GPT-4.1 Mini",family:"gpt-4.1",tier:"fast",capabilityRank:4,modalities:["text"],apiType:"chat",pricing:{input:.4,output:1.6,cached:.1},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:32768,parameters:$,deprecated:!1,description:"Balanced 4.1 model, good price/performance"},{id:"gpt-5-nano",displayName:"GPT-5 Nano",family:"gpt-5",tier:"fast",capabilityRank:1,modalities:["text"],apiType:"chat",pricing:{input:.05,output:.4,cached:.005},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:j,deprecated:!1,description:"Cheapest GPT-5 variant, extremely fast"},{id:"gpt-5-mini",displayName:"GPT-5 Mini",family:"gpt-5",tier:"fast",capabilityRank:5,modalities:["text"],apiType:"chat",pricing:{input:.25,output:2,cached:.025},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:j,deprecated:!1,description:"Small but capable GPT-5, great value"},{id:"gpt-4o",displayName:"GPT-4o",family:"gpt-4o",tier:"standard",capabilityRank:5,modalities:["text","vision"],apiType:"chat",pricing:{input:2.5,output:10,cached:1.25},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:$,deprecated:!1,description:"Flagship multimodal model with vision"},{id:"gpt-4.1",displayName:"GPT-4.1",family:"gpt-4.1",tier:"standard",capabilityRank:6,modalities:["text"],apiType:"chat",pricing:{input:2,output:8,cached:.5},contextWindow:1e6,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:$,deprecated:!1,description:"Long context specialist, 1M token window"},{id:"gpt-5",displayName:"GPT-5",family:"gpt-5",tier:"standard",capabilityRank:7,modalities:["text"],apiType:"chat",pricing:{input:1.25,output:10,cached:.125},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:j,deprecated:!1,description:"Base GPT-5, excellent all-around"},{id:"gpt-5.1",displayName:"GPT-5.1",family:"gpt-5",tier:"standard",capabilityRank:8,modalities:["text"],apiType:"chat",pricing:{input:1.25,output:10,cached:.125},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:j,deprecated:!1,description:"Improved GPT-5 with better instruction following"},{id:"gpt-5.2",displayName:"GPT-5.2",family:"gpt-5",tier:"standard",capabilityRank:9,modalities:["text"],apiType:"chat",pricing:{input:1.75,output:14,cached:.175},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:j,deprecated:!1,description:"Latest GPT-5, most capable standard model"},{id:"o1-mini",displayName:"o1 Mini",family:"o1",tier:"reasoning",capabilityRank:3,modalities:["text"],apiType:"chat",pricing:{input:1.1,output:4.4,cached:.55},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:q,deprecated:!1,description:"Fast reasoning model, good for math/code"},{id:"o3-mini",displayName:"o3 Mini",family:"o3",tier:"reasoning",capabilityRank:4,modalities:["text"],apiType:"chat",pricing:{input:1.1,output:4.4,cached:.55},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:q,deprecated:!1,description:"Improved mini reasoner with better efficiency"},{id:"o4-mini",displayName:"o4 Mini",family:"o4",tier:"reasoning",capabilityRank:5,modalities:["text"],apiType:"chat",pricing:{input:1.1,output:4.4,cached:.275},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:q,deprecated:!1,description:"Latest mini reasoner, best reasoning per dollar"},{id:"o3",displayName:"o3",family:"o3",tier:"reasoning",capabilityRank:7,modalities:["text"],apiType:"chat",pricing:{input:2,output:8,cached:.5},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:q,deprecated:!1,description:"Full o3 reasoning model, excellent for complex problems"},{id:"o1",displayName:"o1",family:"o1",tier:"reasoning",capabilityRank:8,modalities:["text"],apiType:"chat",pricing:{input:15,output:60,cached:7.5},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:q,deprecated:!1,description:"Original full reasoning model, very capable"},{id:"gpt-5-pro",displayName:"GPT-5 Pro",family:"gpt-5",tier:"premium",capabilityRank:7,modalities:["text"],apiType:"chat",pricing:{input:15,output:120},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:32768,parameters:j,deprecated:!1,description:"Enhanced GPT-5 for demanding tasks"},{id:"gpt-5.2-pro",displayName:"GPT-5.2 Pro",family:"gpt-5",tier:"premium",capabilityRank:8,modalities:["text"],apiType:"chat",pricing:{input:21,output:168},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:32768,parameters:j,deprecated:!1,description:"Most capable standard model available"},{id:"o3-pro",displayName:"o3 Pro",family:"o3",tier:"premium",capabilityRank:9,modalities:["text"],apiType:"chat",pricing:{input:20,output:80},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:at,deprecated:!1,description:"Premium o3 with extended thinking time"},{id:"o1-pro",displayName:"o1 Pro",family:"o1",tier:"premium",capabilityRank:10,modalities:["text"],apiType:"chat",pricing:{input:150,output:600},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:at,deprecated:!1,description:"Most capable reasoning model, extended compute"},{id:"o3-deep-research",displayName:"o3 Deep Research",family:"o3",tier:"specialized",capabilityRank:8,modalities:["text"],apiType:"responses",pricing:{input:10,output:40,cached:2.5},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:{...q,supportsStreaming:!1},deprecated:!1,description:"Extended research sessions with web access"},{id:"o4-mini-deep-research",displayName:"o4 Mini Deep Research",family:"o4",tier:"specialized",capabilityRank:6,modalities:["text"],apiType:"responses",pricing:{input:2,output:8,cached:.5},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:{...q,supportsStreaming:!1},deprecated:!1,description:"Affordable deep research with o4 mini"},{id:"computer-use-preview",displayName:"Computer Use Preview",family:"computer-use",tier:"specialized",capabilityRank:5,modalities:["text","vision"],apiType:"responses",pricing:{input:3,output:12},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:{...$,supportsReasoningEffort:!1},deprecated:!1,description:"Can control computer interfaces via screenshots"},{id:"gpt-realtime",displayName:"GPT Realtime",family:"gpt-realtime",tier:"specialized",capabilityRank:7,modalities:["text","audio","realtime"],apiType:"chat",pricing:{input:4,output:16,cached:.4},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:4096,parameters:{...$,supportsReasoningEffort:!1},deprecated:!1,description:"Real-time audio conversation model"},{id:"gpt-realtime-mini",displayName:"GPT Realtime Mini",family:"gpt-realtime",tier:"specialized",capabilityRank:4,modalities:["text","audio","realtime"],apiType:"chat",pricing:{input:.6,output:2.4,cached:.06},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:4096,parameters:{...$,supportsReasoningEffort:!1},deprecated:!1,description:"Affordable real-time audio model"},{id:"gpt-4o-2024-05-13",displayName:"GPT-4o (May 2024)",family:"gpt-4o",tier:"standard",capabilityRank:4,modalities:["text","vision"],apiType:"chat",pricing:{input:5,output:15},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:4096,parameters:$,deprecated:!0,description:"Original GPT-4o snapshot, use gpt-4o instead"}],ve=new Map(I.map(e=>[e.id,e]));function he(e){let t=ve.get(e);if(!t)throw new Error(`Unknown model: ${e}. Use getAvailableModelIds() to see valid options.`);return t}function ct(e){return ve.get(e)}function pt(e){return ve.has(e)}function ut(){return I.map(e=>e.id)}function lt(e){return I.filter(t=>t.tier===e&&!t.deprecated).sort((t,n)=>t.capabilityRank-n.capabilityRank)}function dt(e){return I.filter(t=>t.family===e).sort((t,n)=>t.capabilityRank-n.capabilityRank)}function mt(){let e={fast:1,standard:2,reasoning:3,premium:4,specialized:5};return I.filter(t=>!t.deprecated).sort((t,n)=>{let r=e[t.tier]-e[n.tier];return r!==0?r:t.capabilityRank-n.capabilityRank})}function ft(){return I.filter(e=>!e.deprecated&&e.modalities.includes("text")&&!e.modalities.includes("realtime")&&e.apiType!=="responses").sort((e,t)=>{let n={fast:1,standard:2,reasoning:3,premium:4,specialized:5},r=n[e.tier]-n[t.tier];return r!==0?r:e.capabilityRank-t.capabilityRank})}function yt(e="fast"){let t={fast:1,standard:2,reasoning:3,premium:4,specialized:5},n=t[e];return I.filter(o=>!o.deprecated&&t[o.tier]>=n).sort((o,s)=>o.pricing.input-s.pricing.input)[0]}function gt(e,t,n,r=!1){let o=he(e),s=r&&o.pricing.cached?t/1e6*o.pricing.cached:t/1e6*o.pricing.input,p=n/1e6*o.pricing.output;return s+p}function ht(e){let t=he(e);return`$${t.pricing.input.toFixed(2)} in / $${t.pricing.output.toFixed(2)} out per 1M tokens`}var xe=Object.fromEntries(I.map(e=>[e.id,{input:e.pricing.input,output:e.pricing.output,cached:e.pricing.cached,maxTokens:e.defaultMaxOutput,tier:e.tier}]));var be=null;async function or(){if(be)return be;try{return be=await import("tiktoken"),be}catch{throw new Error('Token pricing requires the "tiktoken" package. Install with: npm install tiktoken')}}var U=xe,z="gpt-4o-mini";async function sr(e){let t=await or();try{return t.encoding_for_model(e)}catch{return t.get_encoding("cl100k_base")}}async function Pe(e,t=z){let n=await sr(t);try{return n.encode(e).length}finally{n.free()}}function xt(e,t,n,r){let o=JSON.stringify({model:t,rate:n,tokens:r});return(0,bt.createHash)("sha256").update(e+o).digest("hex").slice(0,16)}function Pt(e={}){let t=e.model??z,n=U[t],r={input:e.inputRate??n?.input??U[z].input,output:e.outputRate??n?.output??U[z].output,maxTokens:e.maxTokens??n?.maxTokens??4096,tier:e.tier??n?.tier??"custom"},o=e.tokenizer,s={model:t,inputRate:r.input,outputRate:r.output,maxTokens:r.maxTokens,tier:r.tier,tokenizer:o??(a=>Pe(a,t)),minUsd:e.minUsd??.001,maxUsd:e.maxUsd??50,decimals:e.decimals??6},{minUsd:p,maxUsd:y,decimals:g}=s;async function m(a){return o?o(a):Pe(a,t)}async function b(a,h){let l=h?`${h}
|
|
285
285
|
|
|
286
|
-
${
|
|
286
|
+
${a}`:a,x=await m(l),P=x/1e6*r.input;P=Math.max(P,p),P=Math.min(P,y);let k=Math.pow(10,g),A=Math.floor(P*k).toString(),S=xt(a,t,r.input,x);return{amountAtomic:A,usdAmount:P,inputTokens:x,model:t,tier:r.tier,inputRatePerMillion:r.input,outputRatePerMillion:r.output,maxOutputTokens:r.maxTokens,quoteHash:S}}async function c(a,h){if(!h)return!1;let l=await m(a);return xt(a,t,r.input,l)===h}return{calculate:b,validateQuote:c,countTokens:m,config:s,modelInfo:r}}function Tt(){return Object.entries(U).map(([e,t])=>({model:e,inputRate:t.input,outputRate:t.output,maxTokens:t.maxTokens,tier:t.tier})).sort((e,t)=>{let n={fast:0,standard:1,reasoning:2,premium:3},r=n[e.tier]-n[t.tier];return r!==0?r:e.inputRate-t.inputRate})}function St(e){return e in U}function Rt(e=z){let t=U[e]??U[z],n=U[e]?e:z;return`$${t.input.toFixed(2)} per 1M tokens (${n})`}var wt=require("@dexterai/x402-ads-types");0&&(module.exports={BASE_MAINNET_NETWORK,DEXTER_FACILITATOR_URL,FacilitatorClient,MODEL_PRICING,MODEL_PRICING_MAP,MODEL_REGISTRY,SOLANA_MAINNET_NETWORK,SPONSORED_ACCESS_EXTENSION_KEY,USDC_BASE,USDC_MINT,bazaarExtension,countTokens,createDynamicPricing,createTokenPricing,createX402Server,declareDiscoveryExtension,escapeHtml,estimateCost,findModel,formatModelPricing,formatPricing,formatTokenPricing,getActiveModels,getAvailableModelIds,getAvailableModels,getCheapestModel,getModel,getModelsByFamily,getModelsByTier,getTextModels,isValidModel,isValidModelId,resolveDefaultAsset,stripePayTo,x402AccessPass,x402BrowserSupport,x402Middleware});
|
package/dist/server/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var H="solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",we="solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",Ae="solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";var z="eip155:8453",te="eip155:84532",re="eip155:42161",ne="eip155:137",oe="eip155:10",se="eip155:43114",ie="eip155:56",ae="eip155:1187947933",ce="eip155:324705682",pe="eip155:1";var G="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";var fe="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",je="0x55d398326f99059fF775485246999027B3197955",Ee="0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",ke={[ie]:Ee,[z]:fe,[te]:"0x036CbD53842c5426634e7929541eC2318f3dCF7e",[re]:"0xaf88d065e77c8cC2239327C5EDb3A432268e5831",[ne]:"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",[oe]:"0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",[se]:"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",[ae]:"0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",[ce]:"0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",[pe]:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},ve={[je]:{symbol:"USDT",decimals:18},[Ee]:{symbol:"USDC",decimals:18}},ue=6;var Qt={[ie]:56,[z]:8453,[te]:84532,[re]:42161,[ne]:137,[oe]:10,[se]:43114,[ae]:1187947933,[ce]:324705682,[pe]:1},Yt={[H]:"https://api.dexter.cash/api/solana/rpc",[we]:"https://api.devnet.solana.com",[Ae]:"https://api.testnet.solana.com"},Zt={[ie]:"https://bsc-dataseed1.binance.org",[z]:"https://api.dexter.cash/api/base/rpc",[te]:"https://sepolia.base.org",[re]:"https://arb1.arbitrum.io/rpc",[ne]:"https://polygon-rpc.com",[oe]:"https://mainnet.optimism.io",[se]:"https://api.avax.network/ext/bc/C/rpc",[ae]:"https://skale-base.skalenodes.com/v1/base",[ce]:"https://base-sepolia-testnet.skalenodes.com/v1/jubilant-horrible-ancha",[pe]:"https://eth.llamarpc.com"},$="https://x402.dexter.cash",le=H;function V(e,t){if(!Number.isFinite(e))throw new Error(`toAtomicUnits: amount must be finite, got ${e}`);if(e<0)throw new Error(`toAtomicUnits: amount must be non-negative, got ${e}`);if(!Number.isInteger(t)||t<0)throw new Error(`toAtomicUnits: decimals must be a non-negative integer, got ${t}`);let n=ze(Math.abs(e)),[r,o=""]=n.split("."),s=o.slice(0,t).padEnd(t,"0");return BigInt(r+s).toString()}function ze(e){let t=e.toString();if(!/[eE]/.test(t))return t;let[n,r]=t.split(/[eE]/),o=parseInt(r,10),s=n.startsWith("-"),p=s?n.slice(1):n,[y,g=""]=p.split("."),m=y+g,b=y.length+o,c;return b<=0?c="0."+"0".repeat(-b)+m:b>=m.length?c=m+"0".repeat(b-m.length):c=m.slice(0,b)+"."+m.slice(b),(s?"-":"")+c}function ye(e){return e.startsWith("solana:")||e==="solana"}function Ge(e){if(typeof Buffer<"u")return Buffer.from(e,"utf-8").toString("base64");let t=new TextEncoder().encode(e),n="";for(let r=0;r<t.length;r++)n+=String.fromCharCode(t[r]);return btoa(n)}function Ve(e){if(typeof Buffer<"u")return Buffer.from(e,"base64").toString("utf-8");let t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return new TextDecoder().decode(n)}function W(e){return Ge(JSON.stringify(e))}function X(e){return JSON.parse(Ve(e))}function Xe(e){if(e instanceof TypeError)return!0;if(e&&typeof e=="object"&&"status"in e){let t=e.status;return t>=500&&t<600}return!1}var J=class extends Error{status;body;constructor(t,n){super(`HTTP ${t}`),this.status=t,this.body=n}},Q=class{facilitatorUrl;cachedSupported=null;cacheTime=0;CACHE_TTL_MS=6e4;timeoutMs;maxRetries;retryBaseMs;constructor(t=$,n){this.facilitatorUrl=t.replace(/\/$/,""),this.timeoutMs=n?.timeoutMs??1e4,this.maxRetries=n?.maxRetries??3,this.retryBaseMs=n?.retryBaseMs??500}async fetchWithTimeout(t,n){let r=new AbortController,o=setTimeout(()=>r.abort(),this.timeoutMs);try{return await fetch(t,{...n,signal:r.signal})}finally{clearTimeout(o)}}async fetchWithRetry(t,n){let r;for(let o=0;o<this.maxRetries;o++)try{let s=await this.fetchWithTimeout(t,n);if(!s.ok&&s.status>=500)throw new J(s.status,await s.text());return s}catch(s){if(r=s,o<this.maxRetries-1&&Xe(s)){let p=this.retryBaseMs*Math.pow(2,o);await new Promise(y=>setTimeout(y,p));continue}throw s}throw r}async getSupported(){let t=Date.now();if(this.cachedSupported&&t-this.cacheTime<this.CACHE_TTL_MS)return this.cachedSupported;let n=await this.fetchWithTimeout(`${this.facilitatorUrl}/supported`);if(!n.ok)throw new Error(`Facilitator /supported returned ${n.status}`);return this.cachedSupported=await n.json(),this.cacheTime=t,this.cachedSupported}async getFeePayer(t){let r=(await this.getSupported()).kinds.find(o=>o.x402Version===2&&(o.scheme==="exact"||o.scheme==="exact-approval")&&o.network===t);if(!r)throw new Error(`Facilitator does not support network "${t}" with a recognized scheme`);return r.extra?.feePayer}async getNetworkExtra(t){return(await this.getSupported()).kinds.find(o=>o.x402Version===2&&(o.scheme==="exact"||o.scheme==="exact-approval"||o.scheme==="batch-settlement")&&o.network===t)?.extra}async verifyPayment(t,n){try{let r=X(t),o=await this.fetchWithRetry(`${this.facilitatorUrl}/verify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({x402Version:2,paymentPayload:r,paymentRequirements:n})});return o.ok?await o.json():{isValid:!1,invalidReason:`facilitator_error_${o.status}`}}catch(r){return{isValid:!1,invalidReason:r instanceof J?`facilitator_error_${r.status}`:r instanceof Error&&r.name==="AbortError"?"facilitator_timeout":r instanceof Error?r.message:"unexpected_verify_error"}}}async settlePayment(t,n){try{let r=X(t),o=await this.fetchWithRetry(`${this.facilitatorUrl}/settle`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({x402Version:2,paymentPayload:r,paymentRequirements:n})});return o.ok?{...await o.json(),network:n.network}:{success:!1,network:n.network,errorReason:`facilitator_error_${o.status}`}}catch(r){let o=r instanceof J?`facilitator_error_${r.status}`:r instanceof Error&&r.name==="AbortError"?"facilitator_timeout":r instanceof Error?r.message:"unexpected_settle_error";return{success:!1,network:n.network,errorReason:o}}}};function Ce(e){if(ye(e))return{address:G,decimals:6};let t=ke[e];if(t){let n=ve[t]?.decimals??6;return{address:t,decimals:n}}return{address:G,decimals:6}}function Me(e){try{let t=X(e);return t?.accepted?.amount??t?.accepted?.maxAmountRequired}catch{return}}function Y(e){let{payTo:t,facilitatorUrl:n=$,network:r=H,defaultTimeoutSeconds:o=60}=e,s=e.asset??Ce(r),p=e.scheme??"exact",y=new Q(n),g=null,m=new Map,b=3e4,c=Date.now();function i(u){let d=(u.maxTimeoutSeconds||o)*1e3;if(m.set(u.payTo,{accept:u,expiresAt:Date.now()+d}),Date.now()-c>b){let T=Date.now();for(let[E,_]of m)_.expiresAt<T&&m.delete(E);c=T}}function h(u){let d=m.get(u);if(d){if(d.expiresAt<Date.now()){m.delete(u);return}return d.accept}}async function l(u){return typeof t=="string"?t:t(u||{})}async function x(){if(g||(g=await y.getNetworkExtra(r)),ye(r)&&!g?.feePayer)throw new Error(`Facilitator does not provide feePayer for network "${r}"`);return{...g?.feePayer?{feePayer:g.feePayer}:{},decimals:g?.decimals??s.decimals,name:g?.name,version:g?.version,...p==="batch-settlement"&&g?.receiverAuthorizer?{receiverAuthorizer:g.receiverAuthorizer}:{}}}async function P(u,d){let{amountAtomic:T,timeoutSeconds:E=o}=d,_=await x(),O={scheme:p,network:r,amount:T,maxAmountRequired:T,asset:s.address,payTo:u,maxTimeoutSeconds:E,extra:_};return i(O),O}async function k(u){let d=await l({amountAtomic:u.amountAtomic,resourceUrl:u.resourceUrl});return P(d,u)}async function A(u){let{resourceUrl:d,description:T,mimeType:E="application/json"}=u,_={url:d,description:T,mimeType:E},O=await k(u);return{x402Version:2,resource:_,accepts:[O],error:"Payment required"}}function S(u){return W(u)}function a(u){return{status:402,headers:{"PAYMENT-REQUIRED":S(u)},body:{}}}async function f(u,d){if(!d){let T=await l({paymentHeader:u});d=h(T),d||(d=await P(T,{amountAtomic:Me(u)??"0",resourceUrl:""}))}return y.verifyPayment(u,d)}async function w(u,d){if(!d){let T=await l({paymentHeader:u});d=h(T),d||(d=await P(T,{amountAtomic:Me(u)??"0",resourceUrl:""}))}return y.settlePayment(u,d)}return{buildRequirements:A,encodeRequirements:S,create402Response:a,verifyPayment:f,settlePayment:w,getPaymentAccept:k,network:r,assetDecimals:s.decimals,facilitator:y}}var _e=new WeakMap;function Oe(e){return _e.get(e)}var Je={base:"base","base-sepolia":"base_sepolia"},Qe={base:"eip155:8453","base-sepolia":"eip155:84532"};function Ye(e){let t=typeof e=="string"?{secretKey:e}:e,n=t.network??"base",r=Je[n]??"base",o=Qe[n]??"eip155:8453",s=t.apiVersion??"2026-01-28.clover",p=null;async function y(){if(p)return p;try{let{default:m}=await import("stripe");return p=new m(t.secretKey,{apiVersion:s,appInfo:{name:"@dexterai/x402",url:"https://dexter.cash/sdk"}}),p}catch{throw new Error('The "stripe" package is required for stripePayTo(). Install it with: npm install stripe')}}let g=async m=>{if(m.paymentHeader){try{let k=JSON.parse(Buffer.from(m.paymentHeader,"base64").toString()),A=k.payload?.authorization?.to;if(A&&typeof A=="string")return A;let S=k.accepted?.payTo;if(S&&typeof S=="string")return S}catch{}throw new Error("Could not extract deposit address from payment header. Ensure the client is sending a valid x402 PAYMENT-SIGNATURE.")}let b=await y(),c=m.amountAtomic?parseInt(m.amountAtomic,10):1e4,i=Math.max(1,Math.round(c/Math.pow(10,ue-2))),l=(await b.paymentIntents.create({amount:i,currency:"usd",payment_method_types:["crypto"],payment_method_data:{type:"crypto"},payment_method_options:{crypto:{mode:"custom"}},confirm:!0})).next_action;if(!l?.crypto_collect_deposit_details)throw new Error("Stripe PaymentIntent did not return crypto deposit details. Ensure your Stripe account has crypto payins enabled: https://support.stripe.com/questions/get-started-with-pay-with-crypto");let x=l.crypto_collect_deposit_details,P=x.deposit_addresses?.[r]?.address;if(!P)throw new Error(`No deposit address found for network "${r}". Available networks: ${Object.keys(x.deposit_addresses||{}).join(", ")}`);return P};return g._x402Defaults={network:o,facilitatorUrl:$},_e.set(g,o),g}import{homedir as nt}from"os";import{join as ot}from"path";import{FileChannelStorage as st}from"@x402/evm/batch-settlement/server";import{HTTPFacilitatorClient as Ze,x402ResourceServer as et}from"@x402/core/server";import{x402HTTPResourceServer as tt}from"@x402/core/http";import{BatchSettlementEvmScheme as rt}from"@x402/evm/batch-settlement/server";function Ne(e){let t=e.verbose?console.log.bind(console,"[batch-settlement:seller]"):()=>{},n=new Ze({url:e.facilitatorUrl}),r=new rt(e.payTo,{storage:e.channelStore}),o=new et(n).register(e.network,r),s=new tt(o,{[e.route]:{accepts:{scheme:"batch-settlement",payTo:e.payTo,price:e.price,network:e.network},description:"batch-settlement protected route",mimeType:"application/json"}}),p=null;function y(){if(p)return p;let c=s.initialize();return c.catch(i=>{p===c&&(p=null),e.verbose?t("resource server initialize() failed:",i):console.error("[batch-settlement:seller] resource server initialize() failed:",i)}),p=c,c}let g=y();function m(c,i){if(c.headersSent)return;for(let[l,x]of Object.entries(i.headers))c.setHeader(l,x);c.status(i.status);let{body:h}=i;h==null?c.end():typeof h=="string"?c.send(h):c.json(h)}return{scheme:r,facilitator:n,handler:async(c,i,h)=>{try{await y();let l=c.get("host")??"",x=`${c.baseUrl??""}${c.path}`||"/",P={getHeader:w=>c.headers[w.toLowerCase()],getMethod:()=>c.method,getPath:()=>x,getUrl:()=>`${c.protocol}://${l}${c.originalUrl}`,getAcceptHeader:()=>c.headers.accept??"",getUserAgent:()=>c.headers["user-agent"]??"",getBody:()=>c.body??{},getQueryParams:()=>c.query,getQueryParam:w=>{let u=c.query[w];if(typeof u=="string"||Array.isArray(u))return u}},k=c.headers["payment-signature"]??c.headers["x-payment"],A={adapter:P,path:x,method:c.method,paymentHeader:k},S=await s.processHTTPRequest(A);if(t("processHTTPRequest ->",S.type),S.type==="no-payment-required"){h();return}if(S.type==="payment-error"){m(i,S.response);return}let a={request:A,responseBody:Buffer.alloc(0)},f=await s.processSettlement(S.paymentPayload,S.paymentRequirements,S.declaredExtensions,a);if(t("processSettlement ->",f.success?"success":`failure:${f.errorReason}`),!f.success){m(i,f.response);return}for(let[w,u]of Object.entries(f.headers))i.headersSent||i.setHeader(w,u);h()}catch(l){t("handler error:",l),i.headersSent||i.status(500).json({error:"Payment processing error"})}},ready:g}}import{formatUnits as De}from"viem";var Ie=6;async function ge(e){let{manager:t,store:n,channelId:r}=e,o=await n.get(r),s=BigInt(o?.chargedCumulativeAmount??"0"),p=BigInt(o?.balance??"0"),y=p>s?p-s:0n,{claims:g,settle:m}=await t.claimAndSettle(),b=await t.refund([r]),c=b.find(i=>i.channel===r)??b[0];return{claimTx:g[0]?.transaction??"",settleTx:m?.transaction??"",refundTx:c?.transaction??"",settledAmount:De(s,Ie),refundedAmount:De(y,Ie)}}async function Be(e){let t=await e.store.list(),n=[];for(let r of t)try{let o=await ge({manager:e.manager,store:e.store,channelId:r.channelId});n.push({channelId:r.channelId,...o})}catch(o){n.push({channelId:r.channelId,error:o instanceof Error?o.message:String(o)})}return n}function Ue(e){let t=!1,n=async()=>{try{await e.claimAndSettle()}catch(o){e.onError?.(o)}},r=setInterval(()=>{t||n()},e.claimIntervalMs);return typeof r.unref=="function"&&r.unref(),{async stop(){t||(t=!0,clearInterval(r),await n())}}}var it="https://x402.dexter.cash",at="GET /",$e=new Set(["eip155:8453","eip155:42161","eip155:137"]);function ct(e){return e===!1?null:e===void 0||e===!0?3e5:(e.claimIntervalSecs??300)*1e3}function he(e){if(!$e.has(e.network))throw new Error(`batch-settlement is not supported on network "${e.network}" \u2014 supported: ${[...$e].join(", ")}`);let t=e.facilitatorUrl??it,n=e.channelStore??new st({directory:ot(nt(),".dexter-x402","seller-channels")}),r=Ne({payTo:e.payTo,network:e.network,price:e.price,route:e.route??at,facilitatorUrl:t,channelStore:n,verbose:e.verbose}),o=r.scheme.createChannelManager(r.facilitator,e.network),s=async()=>{await o.claimAndSettle()},p=ct(e.autoSettle),y=null;p!==null&&(y=Ue({claimAndSettle:s,claimIntervalMs:p,onError:c=>console.error("[batch-settlement:seller] auto-loop claim pass failed",c)}));let g=n,m=(c,i,h)=>{r.handler(c,i,h)},b=m;return b.middleware=()=>m,b.closeChannel=c=>ge({manager:o,store:g,channelId:c}),b.closeAll=()=>Be({manager:o,store:g}),b.stop=async()=>{y&&await y.stop()},b}async function Le(e,t,n){let r={};for(let o of e)if(o.enrichPaymentRequiredResponse&&o.key in t)try{let s=await o.enrichPaymentRequiredResponse(t[o.key],n);s!==void 0&&(r[o.key]=s)}catch(s){console.warn(`[x402:extensions] extension "${o.key}" failed:`,s)}return Object.keys(r).length>0?r:void 0}function pt(e,t){if(typeof e=="string"||typeof e=="function")return e;if(t in e)return e[t];let r=`${t.split(":")[0]}:*`;if(r in e)return e[r];if("*"in e)return e["*"];throw new Error(`No payTo configured for network "${t}"`)}function ut(e){if(e.scheme==="batch-settlement"){let a=Array.isArray(e.network)?e.network[0]:e.network;if(!a)throw new Error('x402Middleware: scheme "batch-settlement" requires a network');let f=typeof e.payTo=="string"?e.payTo:void 0;if(!f)throw new Error('x402Middleware: scheme "batch-settlement" requires a string payTo address');return he({payTo:f,network:a,price:e.amount,facilitatorUrl:e.facilitatorUrl,route:e.batchSettlement?.route,channelStore:e.batchSettlement?.channelStore,autoSettle:e.batchSettlement?.autoSettle,verbose:e.verbose})}let{payTo:t,amount:n,asset:r,description:o,resourceUrl:s,mimeType:p,timeoutSeconds:y,verbose:g=!1,getResourceUrl:m,getAmount:b,getDescription:c,extensions:i,declarations:h}=e,l=g?console.log.bind(console,"[x402:middleware]"):()=>{},x=typeof t=="function"?t._x402Defaults:void 0,P=e.facilitatorUrl??x?.facilitatorUrl,k=e.network?Array.isArray(e.network)?e.network:[e.network]:x?.network?[x.network]:[le],A=new Map;for(let a of k){let f=pt(t,a);if(typeof f=="function"){let w=Oe(f);if(w&&a!==w)throw new Error(`stripePayTo is configured for "${w}" but middleware includes network "${a}". Stripe only supports Base deposit addresses. Use a static payTo for other chains.`)}A.set(a,Y({payTo:f,network:a,asset:r,facilitatorUrl:P,defaultTimeoutSeconds:y,scheme:e.scheme}))}let S=A.get(k[0]);return async(a,f,w)=>{try{let u=a.headers["payment-signature"];if(!u){l("No payment signature, returning 402");let q=m?.(a)??s??`${a.protocol}://${a.get("host")}${a.originalUrl}`,R=b?.(a)??n,C=c?.(a)??o,N=parseFloat(R),M=[],v=null;for(let[,F]of A)try{let me={amountAtomic:V(N,F.assetDecimals),resourceUrl:q,description:C,mimeType:p,timeoutSeconds:y},Re=await F.buildRequirements(me);M.push(...Re.accepts),v||(v=Re)}catch(me){l("Failed to build requirements for a network:",me)}if(!v||M.length===0){f.status(500).json({error:"Failed to build payment requirements"});return}if(v={...v,accepts:M},i&&i.length>0){let F=await Le(i,h??{},{response:v,request:{method:a.method,path:a.route?.path??a.path,params:a.params}});F&&(v={...v,extensions:F})}let ee=S.encodeRequirements(v);f.setHeader("PAYMENT-REQUIRED",ee),f.status(402).json({error:"Payment required",accepts:v.accepts,resource:v.resource,...v.extensions?{extensions:v.extensions}:{}});return}l("Payment signature received, verifying...");let d=S;try{let R=JSON.parse(Buffer.from(u,"base64").toString())?.accepted?.network;R&&A.has(R)&&(d=A.get(R))}catch{}let T=await d.verifyPayment(u);if(!T.isValid){if(l("Payment verification failed:",T.invalidReason),e.onVerifyFailed)try{await e.onVerifyFailed({reason:T.invalidReason,resourceUrl:`${a.protocol}://${a.get("host")}${a.originalUrl}`})}catch{}f.status(402).json({error:"Payment verification failed",reason:T.invalidReason});return}l("Payment verified, settling...");let E=await d.settlePayment(u);if(!E.success){l("Payment settlement failed:",E.errorReason),f.status(402).json({error:"Payment settlement failed",reason:E.errorReason});return}l("Payment settled:",E.transaction);let _=E.network||k[0];if(e.onSettlement)try{await e.onSettlement({transaction:E.transaction,network:_,payer:T.payer??"",resourceUrl:`${a.protocol}://${a.get("host")}${a.originalUrl}`})}catch{}a.x402={transaction:E.transaction,payer:T.payer??"",network:_};let O={success:!0,transaction:E.transaction,network:_,payer:T.payer??""};if(E.extensions&&(O.extensions=E.extensions),f.setHeader("PAYMENT-RESPONSE",W(O)),e.sponsoredAccess&&E.extensions?.["sponsored-access"]){let q=E.extensions["sponsored-access"],R=q?.info?.recommendations??q?.recommendations;if(R&&R.length>0){if(l("Injecting sponsored-access recommendations into response"),typeof e.sponsoredAccess=="object"&&e.sponsoredAccess.onMatch)try{e.sponsoredAccess.onMatch(R,{transaction:E.transaction,network:_,payer:T.payer??""})}catch{}let C=f.json.bind(f);f.json=function(M){return typeof e.sponsoredAccess=="object"&&e.sponsoredAccess.inject?C(e.sponsoredAccess.inject(M,R)):M&&typeof M=="object"&&!Array.isArray(M)?C({_x402_sponsored:R,...M}):C(M)}}}w()}catch(u){l("Middleware error:",u),f.status(500).json({error:"Payment processing error"})}}}var lt=/^\/[a-zA-Z0-9_/:.\-~%]+$/;function qe(e){if(!e||!lt.test(e))return!1;let t;try{t=decodeURIComponent(e)}catch{return!1}return!(t.includes("..")||t.includes("://"))}function Z(e){return e.method==="POST"||e.method==="PUT"||e.method==="PATCH"}var dt=["GET","HEAD","DELETE"],mt=["POST","PUT","PATCH"];function Fe(e,t){let n=t.pathParams!==void 0&&Object.keys(t.pathParams).length>0,r={type:"http",method:e.method};Z(e)?(r.bodyType=e.bodyType,r.body=e.input??{}):e.input!==void 0&&(r.queryParams=e.input),n&&(r.pathParams=t.pathParams);let o=e.output?.example!==void 0?{type:"json",example:e.output.example}:void 0,s=Z(e)?mt:dt,p={type:{type:"string",const:"http"},method:{type:"string",enum:s}};Z(e)?(p.bodyType={type:"string",enum:["json","form-data","text"]},p.body={type:"object",...e.inputSchema??{}}):e.inputSchema&&(p.queryParams={type:"object",...e.inputSchema}),e.pathParamsSchema&&(p.pathParams={type:"object",...e.pathParamsSchema});let y={input:{type:"object",properties:p,required:Z(e)?["type","method","bodyType","body"]:["type","method"],additionalProperties:!1}};o&&(y.output={type:"object",properties:{type:{type:"string"},example:{type:"object",...e.output?.schema??{}}},required:["type"]});let g={$schema:"https://json-schema.org/draft/2020-12/schema",type:"object",properties:y,required:["input"]},m={info:{input:r,...o?{output:o}:{}},schema:g};return qe(t.routeTemplate)&&(m.routeTemplate=t.routeTemplate),m}var ft=["GET","HEAD","DELETE","POST","PUT","PATCH"];function yt(){return{key:"bazaar",enrichPaymentRequiredResponse:(e,t)=>{if(e==null)return;let n=e,r=(n.method??t.request.method).toUpperCase();if(!ft.includes(r))return;let o={...n,method:r};return Fe(o,{pathParams:t.request.params,routeTemplate:t.request.path})}}}function gt(e){return{bazaar:e}}function D(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}var ht='<svg width="18" height="18" viewBox="0 0 2000 2000" xmlns="http://www.w3.org/2000/svg"><path d="M1000 2000c554.17 0 1000-445.83 1000-1000S1554.17 0 1000 0 0 445.83 0 1000s445.83 1000 1000 1000z" fill="#2775ca"/><path d="M1275 1158.33c0-145.83-87.5-195.83-262.5-216.66-125-16.67-150-50-150-108.34s41.67-95.83 125-95.83c75 0 116.67 25 137.5 87.5 4.17 12.5 16.67 20.83 29.17 20.83h66.66c16.67 0 29.17-12.5 29.17-29.16v-4.17c-16.67-91.67-91.67-162.5-187.5-170.83v-100c0-16.67-12.5-29.17-33.33-33.34h-62.5c-16.67 0-29.17 12.5-33.34 33.34v95.83c-125 16.67-204.16 100-204.16 204.17 0 137.5 83.33 191.66 258.33 212.5 116.67 20.83 154.17 45.83 154.17 112.5s-58.34 112.5-137.5 112.5c-108.34 0-145.84-45.84-158.34-108.34-4.16-16.66-16.66-25-29.16-25h-70.84c-16.66 0-29.16 12.5-29.16 29.17v4.17c16.66 104.16 83.33 179.16 220.83 200v100c0 16.66 12.5 29.16 33.33 33.33h62.5c16.67 0 29.17-12.5 33.34-33.33v-100c125-20.84 208.33-108.34 208.33-220.84z" fill="#fff"/><path d="M787.5 1595.83c-325-116.66-491.67-479.16-370.83-800 62.5-175 200-308.33 370.83-370.83 16.67-8.33 25-20.83 25-41.67V325c0-16.67-8.33-29.17-25-33.33-4.17 0-12.5 0-16.67 4.16-395.83 125-612.5 545.84-487.5 941.67 75 233.33 254.17 412.5 487.5 487.5 16.67 8.33 33.34 0 37.5-16.67 4.17-4.16 4.17-8.33 4.17-16.66v-58.34c0-12.5-12.5-29.16-25-37.5zM1229.17 295.83c-16.67-8.33-33.34 0-37.5 16.67-4.17 4.17-4.17 8.33-4.17 16.67v58.33c0 16.67 12.5 33.33 25 41.67 325 116.66 491.67 479.16 370.83 800-62.5 175-200 308.33-370.83 370.83-16.67 8.33-25 20.83-25 41.67V1700c0 16.67 8.33 29.17 25 33.33 4.17 0 12.5 0 16.67-4.16 395.83-125 612.5-545.84 487.5-941.67-75-237.5-258.34-416.67-487.5-491.67z" fill="#fff"/></svg>',xt='<svg width="36" height="36" viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg"><g><path fill="#F2681A" d="m324.93,313.11c-115.5,0-231,0-350,0l350,0z"/><path fill="#FDFAF5" d="m230.43,50.62c1.1.85 2.19 1.7 3.32 2.57 6.02 4.8 11.77 9.88 17.46 15.07.92.84.92.84 1.86 1.69 1.82 1.69 3.59 3.42 5.35 5.16.61.56 1.22 1.13 1.84 1.71 5.66 5.76 6.18 10.43 6.13 18.3.02 1.16.04 2.32.06 3.52.06 3.83.06 7.65.07 11.48.02 2.68.05 5.35.08 8.03.05 5.6.09 11.21.1 16.81.02 7.15.09 14.31.17 21.46.06 5.53.1 11.05.13 16.58.02 2.64.04 5.27.07 7.91.18 17.58.12 32.82-11.24 47.32-7.35 7.27-16.54 12.06-25.42 17.22-1.97 1.16-3.94 2.33-5.91 3.49-7.16 4.24-14.34 8.44-21.53 12.62-4.8 2.79-9.59 5.6-14.38 8.42-1.25.73-2.5 1.47-3.79 2.23-2.32 1.36-4.64 2.73-6.96 4.1-27.47 16.09-27.47 16.09-42.16 12.93-8.06-2.28-14.94-5.82-22.16-10.02-1.17-.67-2.34-1.34-3.54-2.04-24.55-14.25-43.58-27.03-51.9-55.58-1.07-4.58-1.54-8.92-1.52-13.61.28-9.5.28-9.5-3.3-17.97-1.81-1.49-3.68-2.92-5.59-4.28-9.19-7.06-12.7-20.03-14.18-31.06-.54-5.77-.55-11.56-.6-17.35-.03-1.32-.07-2.63-.1-3.99-.01-1.26-.02-2.53-.03-3.83-.02-1.15-.03-2.29-.05-3.47.72-4.02 1.94-5.36 5.21-7.74 2.89-.53 2.89-.53 6.07-.46 1.71.02 1.71.02 3.46.05 1.19.04 2.37.08 3.59.12 1.2.02 2.41.04 3.65.06 2.97.05 5.93.13 8.9.23.14-1.35.29-2.7.43-4.08.63-5 1.78-9.74 3.14-14.58.22-.79.43-1.59.66-2.4.53-1.92 1.06-3.84 1.6-5.76-1.55-.45-1.55-.45-3.13-.9-9.52-3.52-17.1-10.95-21.37-20.1-3.81-9.26-3.87-20.34-.29-29.68 6.49-13.99 16.36-23.23 30.66-29.01 49.81-17.69 115.79 8.35 155.13 38.85z"/><path fill="#F2671A" d="m142.93,22.62c.86.19 1.73.39 2.62.59 36.12 8.21 68.79 24.98 95.38 50.75 1.02.98 2.03 1.97 3.08 2.98 10.84 10.66 10.84 10.66 11.05 14.62-2.06 3.55-5.44 4.18-9.17 5.3-.79.25-1.59.49-2.41.75-28.13 8.43-60.95 6.37-87.13-7.16-.86-.49-1.71-.97-2.6-1.48-7.37-4.05-12.59-3.36-20.59-1.54-22.76 4-48.47 1.53-68.69-9.74-4.88-3.88-8.23-8.29-10.21-14.22-.93-10.38-.67-18.44 5.83-26.83 19.57-23.38 55.99-20.36 82.83-14z"/><path fill="#F16619" d="m44.93,129.12c27.36-.03 54.72-.05 82.08-.06 12.7-.01 25.41-.01 38.11-.03 11.07-.01 22.14-.02 33.2-.02 5.86 0 11.73-.01 17.59-.01 5.51-.01 11.03-.01 16.54-.01 2.03 0 4.06 0 6.09-.01 2.76-.01 5.52 0 8.28 0 .81 0 1.63-.01 2.47-.01 5.51.02 5.51.02 6.81 1.32.22 3.43.22 3.43 0 7-2.75 2.75-3.42 2.66-7.15 2.82-1.41.07-1.41.07-2.85.14-1.47.05-1.47.05-2.98.11-1.49.07-1.49.07-3 .14-2.45.11-4.9.21-7.35.3-.2 1.3-.4 2.59-.6 3.93-2.57 16.08-5.93 29.89-18.89 40.86-10.35 7.28-21.87 8.49-34.17 7.71-13.11-2.33-22.52-9.19-30.33-19.83-4.49-7.64-4.8-17.05-5.83-25.67-4.24.39-8.47.77-12.83 1.17-.28 1.84-.28 1.84-.56 3.71-2.32 14.39-5.63 23.35-16.95 33.11-2.32 1.67-2.32 1.67-4.65 1.67 4 4.67 9.06 6.59 14.87 8.24 3.79 1.09 3.79 1.09 6.12 3.43-.65 5.31-.65 5.31-2.33 7-8.42-.27-15.13-2.29-22.17-7-1.09-1.21-2.17-2.43-3.25-3.65-2.72-2.81-4.45-3.84-8.36-4.16-1.67-.02-3.34-.02-5.01.01-1.77-.04-3.54-.09-5.3-.15-1.27-.04-1.27-.04-2.56-.08-9.26-.54-17.6-4.56-24.51-10.64-9.58-11.11-11.03-22.56-10.72-36.82.02-1.4.03-2.8.05-4.24.04-3.42.1-6.85.17-10.27z"/><path fill="#F26117" d="m172.68,203.08c7.27.09 13.23 1.97 18.87 6.65 2.88 3.07 3.86 5.12 4.25 9.32-.12 1.01-.24 2.02-.36 3.06-2.55.95-2.55.95-5.83 1.17-3.28-2.84-3.28-2.84-5.83-5.83-.36.58-.71 1.16-1.08 1.75-7.6 11.29-20.06 17.74-33.05 21.09-20.36 3.1-36.81-1.66-53.37-13.73-2.33-2.11-2.33-2.11-4.67-5.61.42-3.45.99-4.49 3.5-7 4.07.37 5.95 2.13 8.75 4.96 9.81 8.93 22.53 11.87 35.51 11.69 11.74-1.05 22.38-5.85 31.57-13.15 2.06-2.45 2.06-2.45 3.5-4.67-1.66.07-1.66.07-3.35.15-3.65-.15-3.65-.15-5.98-2.48.75-6.18 1.46-7.19 7.58-7.36z"/></g></svg>',bt=`
|
|
1
|
+
var H="solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",we="solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",Ae="solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";var z="eip155:8453",te="eip155:84532",re="eip155:42161",ne="eip155:137",oe="eip155:10",se="eip155:43114",ie="eip155:56",ae="eip155:1187947933",ce="eip155:324705682",pe="eip155:1";var G="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";var fe="0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",je="0x55d398326f99059fF775485246999027B3197955",Ee="0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",ke={[ie]:Ee,[z]:fe,[te]:"0x036CbD53842c5426634e7929541eC2318f3dCF7e",[re]:"0xaf88d065e77c8cC2239327C5EDb3A432268e5831",[ne]:"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",[oe]:"0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",[se]:"0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",[ae]:"0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",[ce]:"0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",[pe]:"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"},ve={[je]:{symbol:"USDT",decimals:18},[Ee]:{symbol:"USDC",decimals:18}},ue=6;var Qt={[ie]:56,[z]:8453,[te]:84532,[re]:42161,[ne]:137,[oe]:10,[se]:43114,[ae]:1187947933,[ce]:324705682,[pe]:1},Yt={[H]:"https://api.dexter.cash/api/solana/rpc",[we]:"https://api.devnet.solana.com",[Ae]:"https://api.testnet.solana.com"},Zt={[ie]:"https://bsc-dataseed1.binance.org",[z]:"https://api.dexter.cash/api/base/rpc",[te]:"https://sepolia.base.org",[re]:"https://arb1.arbitrum.io/rpc",[ne]:"https://polygon-rpc.com",[oe]:"https://mainnet.optimism.io",[se]:"https://api.avax.network/ext/bc/C/rpc",[ae]:"https://skale-base.skalenodes.com/v1/base",[ce]:"https://base-sepolia-testnet.skalenodes.com/v1/jubilant-horrible-ancha",[pe]:"https://eth.llamarpc.com"},$="https://x402.dexter.cash",le=H;function V(e,t){if(!Number.isFinite(e))throw new Error(`toAtomicUnits: amount must be finite, got ${e}`);if(e<0)throw new Error(`toAtomicUnits: amount must be non-negative, got ${e}`);if(!Number.isInteger(t)||t<0)throw new Error(`toAtomicUnits: decimals must be a non-negative integer, got ${t}`);let n=ze(Math.abs(e)),[r,o=""]=n.split("."),s=o.slice(0,t).padEnd(t,"0");return BigInt(r+s).toString()}function ze(e){let t=e.toString();if(!/[eE]/.test(t))return t;let[n,r]=t.split(/[eE]/),o=parseInt(r,10),s=n.startsWith("-"),p=s?n.slice(1):n,[y,g=""]=p.split("."),m=y+g,b=y.length+o,c;return b<=0?c="0."+"0".repeat(-b)+m:b>=m.length?c=m+"0".repeat(b-m.length):c=m.slice(0,b)+"."+m.slice(b),(s?"-":"")+c}function ye(e){return e.startsWith("solana:")||e==="solana"}function Ge(e){if(typeof Buffer<"u")return Buffer.from(e,"utf-8").toString("base64");let t=new TextEncoder().encode(e),n="";for(let r=0;r<t.length;r++)n+=String.fromCharCode(t[r]);return btoa(n)}function Ve(e){if(typeof Buffer<"u")return Buffer.from(e,"base64").toString("utf-8");let t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t.charCodeAt(r);return new TextDecoder().decode(n)}function W(e){return Ge(JSON.stringify(e))}function X(e){return JSON.parse(Ve(e))}function Xe(e){if(e instanceof TypeError)return!0;if(e&&typeof e=="object"&&"status"in e){let t=e.status;return t>=500&&t<600}return!1}var J=class extends Error{status;body;constructor(t,n){super(`HTTP ${t}`),this.status=t,this.body=n}},Q=class{facilitatorUrl;cachedSupported=null;cacheTime=0;CACHE_TTL_MS=6e4;timeoutMs;maxRetries;retryBaseMs;constructor(t=$,n){this.facilitatorUrl=t.replace(/\/$/,""),this.timeoutMs=n?.timeoutMs??1e4,this.maxRetries=n?.maxRetries??3,this.retryBaseMs=n?.retryBaseMs??500}async fetchWithTimeout(t,n){let r=new AbortController,o=setTimeout(()=>r.abort(),this.timeoutMs);try{return await fetch(t,{...n,signal:r.signal})}finally{clearTimeout(o)}}async fetchWithRetry(t,n){let r;for(let o=0;o<this.maxRetries;o++)try{let s=await this.fetchWithTimeout(t,n);if(!s.ok&&s.status>=500)throw new J(s.status,await s.text());return s}catch(s){if(r=s,o<this.maxRetries-1&&Xe(s)){let p=this.retryBaseMs*Math.pow(2,o);await new Promise(y=>setTimeout(y,p));continue}throw s}throw r}async getSupported(){let t=Date.now();if(this.cachedSupported&&t-this.cacheTime<this.CACHE_TTL_MS)return this.cachedSupported;let n=await this.fetchWithTimeout(`${this.facilitatorUrl}/supported`);if(!n.ok)throw new Error(`Facilitator /supported returned ${n.status}`);return this.cachedSupported=await n.json(),this.cacheTime=t,this.cachedSupported}async getFeePayer(t){let r=(await this.getSupported()).kinds.find(o=>o.x402Version===2&&(o.scheme==="exact"||o.scheme==="exact-approval")&&o.network===t);if(!r)throw new Error(`Facilitator does not support network "${t}" with a recognized scheme`);return r.extra?.feePayer}async getNetworkExtra(t){return(await this.getSupported()).kinds.find(o=>o.x402Version===2&&(o.scheme==="exact"||o.scheme==="exact-approval"||o.scheme==="batch-settlement")&&o.network===t)?.extra}async verifyPayment(t,n){try{let r=X(t),o=await this.fetchWithRetry(`${this.facilitatorUrl}/verify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({x402Version:2,paymentPayload:r,paymentRequirements:n})});return o.ok?await o.json():{isValid:!1,invalidReason:`facilitator_error_${o.status}`}}catch(r){return{isValid:!1,invalidReason:r instanceof J?`facilitator_error_${r.status}`:r instanceof Error&&r.name==="AbortError"?"facilitator_timeout":r instanceof Error?r.message:"unexpected_verify_error"}}}async settlePayment(t,n){try{let r=X(t),o=await this.fetchWithRetry(`${this.facilitatorUrl}/settle`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({x402Version:2,paymentPayload:r,paymentRequirements:n})});return o.ok?{...await o.json(),network:n.network}:{success:!1,network:n.network,errorReason:`facilitator_error_${o.status}`}}catch(r){let o=r instanceof J?`facilitator_error_${r.status}`:r instanceof Error&&r.name==="AbortError"?"facilitator_timeout":r instanceof Error?r.message:"unexpected_settle_error";return{success:!1,network:n.network,errorReason:o}}}};function Ce(e){if(ye(e))return{address:G,decimals:6};let t=ke[e];if(t){let n=ve[t]?.decimals??6;return{address:t,decimals:n}}return{address:G,decimals:6}}function Me(e){try{let t=X(e);return t?.accepted?.amount??t?.accepted?.maxAmountRequired}catch{return}}function Y(e){let{payTo:t,facilitatorUrl:n=$,network:r=H,defaultTimeoutSeconds:o=60}=e,s=e.asset??Ce(r),p=e.scheme??"exact",y=new Q(n),g=null,m=new Map,b=3e4,c=Date.now();function a(u){let d=(u.maxTimeoutSeconds||o)*1e3;if(m.set(u.payTo,{accept:u,expiresAt:Date.now()+d}),Date.now()-c>b){let T=Date.now();for(let[E,_]of m)_.expiresAt<T&&m.delete(E);c=T}}function h(u){let d=m.get(u);if(d){if(d.expiresAt<Date.now()){m.delete(u);return}return d.accept}}async function l(u){return typeof t=="string"?t:t(u||{})}async function x(){if(g||(g=await y.getNetworkExtra(r)),ye(r)&&!g?.feePayer)throw new Error(`Facilitator does not provide feePayer for network "${r}"`);return{...g?.feePayer?{feePayer:g.feePayer}:{},decimals:g?.decimals??s.decimals,name:g?.name,version:g?.version,...p==="batch-settlement"&&g?.receiverAuthorizer?{receiverAuthorizer:g.receiverAuthorizer}:{}}}async function P(u,d){let{amountAtomic:T,timeoutSeconds:E=o}=d,_=await x(),O={scheme:p,network:r,amount:T,maxAmountRequired:T,asset:s.address,payTo:u,maxTimeoutSeconds:E,extra:_};return a(O),O}async function k(u){let d=await l({amountAtomic:u.amountAtomic,resourceUrl:u.resourceUrl});return P(d,u)}async function A(u){let{resourceUrl:d,description:T,mimeType:E="application/json"}=u,_={url:d,description:T,mimeType:E},O=await k(u);return{x402Version:2,resource:_,accepts:[O],error:"Payment required"}}function S(u){return W(u)}function i(u){return{status:402,headers:{"PAYMENT-REQUIRED":S(u)},body:{}}}async function f(u,d){if(!d){let T=await l({paymentHeader:u});d=h(T),d||(d=await P(T,{amountAtomic:Me(u)??"0",resourceUrl:""}))}return y.verifyPayment(u,d)}async function w(u,d){if(!d){let T=await l({paymentHeader:u});d=h(T),d||(d=await P(T,{amountAtomic:Me(u)??"0",resourceUrl:""}))}return y.settlePayment(u,d)}return{buildRequirements:A,encodeRequirements:S,create402Response:i,verifyPayment:f,settlePayment:w,getPaymentAccept:k,network:r,assetDecimals:s.decimals,facilitator:y}}var _e=new WeakMap;function Oe(e){return _e.get(e)}var Je={base:"base","base-sepolia":"base_sepolia"},Qe={base:"eip155:8453","base-sepolia":"eip155:84532"};function Ye(e){let t=typeof e=="string"?{secretKey:e}:e,n=t.network??"base",r=Je[n]??"base",o=Qe[n]??"eip155:8453",s=t.apiVersion??"2026-01-28.clover",p=null;async function y(){if(p)return p;try{let{default:m}=await import("stripe");return p=new m(t.secretKey,{apiVersion:s,appInfo:{name:"@dexterai/x402",url:"https://dexter.cash/sdk"}}),p}catch{throw new Error('The "stripe" package is required for stripePayTo(). Install it with: npm install stripe')}}let g=async m=>{if(m.paymentHeader){try{let k=JSON.parse(Buffer.from(m.paymentHeader,"base64").toString()),A=k.payload?.authorization?.to;if(A&&typeof A=="string")return A;let S=k.accepted?.payTo;if(S&&typeof S=="string")return S}catch{}throw new Error("Could not extract deposit address from payment header. Ensure the client is sending a valid x402 PAYMENT-SIGNATURE.")}let b=await y(),c=m.amountAtomic?parseInt(m.amountAtomic,10):1e4,a=Math.max(1,Math.round(c/Math.pow(10,ue-2))),l=(await b.paymentIntents.create({amount:a,currency:"usd",payment_method_types:["crypto"],payment_method_data:{type:"crypto"},payment_method_options:{crypto:{mode:"custom"}},confirm:!0})).next_action;if(!l?.crypto_collect_deposit_details)throw new Error("Stripe PaymentIntent did not return crypto deposit details. Ensure your Stripe account has crypto payins enabled: https://support.stripe.com/questions/get-started-with-pay-with-crypto");let x=l.crypto_collect_deposit_details,P=x.deposit_addresses?.[r]?.address;if(!P)throw new Error(`No deposit address found for network "${r}". Available networks: ${Object.keys(x.deposit_addresses||{}).join(", ")}`);return P};return g._x402Defaults={network:o,facilitatorUrl:$},_e.set(g,o),g}import{homedir as nt}from"os";import{join as ot}from"path";import{FileChannelStorage as st}from"@x402/evm/batch-settlement/server";import{HTTPFacilitatorClient as Ze,x402ResourceServer as et}from"@x402/core/server";import{x402HTTPResourceServer as tt}from"@x402/core/http";import{BatchSettlementEvmScheme as rt}from"@x402/evm/batch-settlement/server";function Ne(e){let t=e.verbose?console.log.bind(console,"[batch-settlement:seller]"):()=>{},n=new Ze({url:e.facilitatorUrl}),r=new rt(e.payTo,{storage:e.channelStore}),o=new et(n).register(e.network,r),s=new tt(o,{[e.route]:{accepts:{scheme:"batch-settlement",payTo:e.payTo,price:e.price,network:e.network},description:"batch-settlement protected route",mimeType:"application/json"}}),p=null;function y(){if(p)return p;let c=s.initialize();return c.catch(a=>{p===c&&(p=null),e.verbose?t("resource server initialize() failed:",a):console.error("[batch-settlement:seller] resource server initialize() failed:",a)}),p=c,c}let g=y();function m(c,a){if(c.headersSent)return;for(let[l,x]of Object.entries(a.headers))c.setHeader(l,x);c.status(a.status);let{body:h}=a;h==null?c.end():typeof h=="string"?c.send(h):c.json(h)}return{scheme:r,facilitator:n,handler:async(c,a,h)=>{try{await y();let l=c.get("host")??"",x=`${c.baseUrl??""}${c.path}`||"/",P={getHeader:w=>c.headers[w.toLowerCase()],getMethod:()=>c.method,getPath:()=>x,getUrl:()=>`${c.protocol}://${l}${c.originalUrl}`,getAcceptHeader:()=>c.headers.accept??"",getUserAgent:()=>c.headers["user-agent"]??"",getBody:()=>c.body??{},getQueryParams:()=>c.query,getQueryParam:w=>{let u=c.query[w];if(typeof u=="string"||Array.isArray(u))return u}},k=c.headers["payment-signature"]??c.headers["x-payment"],A={adapter:P,path:x,method:c.method,paymentHeader:k},S=await s.processHTTPRequest(A);if(t("processHTTPRequest ->",S.type),S.type==="no-payment-required"){h();return}if(S.type==="payment-error"){m(a,S.response);return}let i={request:A,responseBody:Buffer.alloc(0)},f=await s.processSettlement(S.paymentPayload,S.paymentRequirements,S.declaredExtensions,i);if(t("processSettlement ->",f.success?"success":`failure:${f.errorReason}`),!f.success){m(a,f.response);return}for(let[w,u]of Object.entries(f.headers))a.headersSent||a.setHeader(w,u);h()}catch(l){t("handler error:",l),a.headersSent||a.status(500).json({error:"Payment processing error"})}},ready:g}}import{formatUnits as De}from"viem";var Ie=6;async function ge(e){let{manager:t,store:n,channelId:r}=e,o=await n.get(r),s=BigInt(o?.chargedCumulativeAmount??"0"),p=BigInt(o?.balance??"0"),y=p>s?p-s:0n,{claims:g,settle:m}=await t.claimAndSettle(),b=await t.refund([r]),c=b.find(a=>a.channel===r)??b[0];return{claimTx:g[0]?.transaction??"",settleTx:m?.transaction??"",refundTx:c?.transaction??"",settledAmount:De(s,Ie),refundedAmount:De(y,Ie)}}async function Ue(e){let t=await e.store.list(),n=[];for(let r of t)try{let o=await ge({manager:e.manager,store:e.store,channelId:r.channelId});n.push({channelId:r.channelId,...o})}catch(o){n.push({channelId:r.channelId,error:o instanceof Error?o.message:String(o)})}return n}function Be(e){let t=!1,n=async()=>{try{await e.claimAndSettle()}catch(o){e.onError?.(o)}},r=setInterval(()=>{t||n()},e.claimIntervalMs);return typeof r.unref=="function"&&r.unref(),{async stop(){t||(t=!0,clearInterval(r),await n())}}}var it="https://x402.dexter.cash",at="GET /",$e=new Set(["eip155:8453","eip155:42161","eip155:137"]);function ct(e){return e===!1?null:e===void 0||e===!0?3e5:(e.claimIntervalSecs??300)*1e3}function he(e){if(!$e.has(e.network))throw new Error(`batch-settlement is not supported on network "${e.network}" \u2014 supported: ${[...$e].join(", ")}`);let t=e.facilitatorUrl??it,n=e.channelStore??new st({directory:ot(nt(),".dexter-x402","seller-channels")}),r=Ne({payTo:e.payTo,network:e.network,price:e.price,route:e.route??at,facilitatorUrl:t,channelStore:n,verbose:e.verbose}),o=r.scheme.createChannelManager(r.facilitator,e.network),s=async()=>{await o.claimAndSettle()},p=ct(e.autoSettle),y=null;p!==null&&(y=Be({claimAndSettle:s,claimIntervalMs:p,onError:c=>console.error("[batch-settlement:seller] auto-loop claim pass failed",c)}));let g=n,m=(c,a,h)=>{r.handler(c,a,h)},b=m;return b.middleware=()=>m,b.closeChannel=c=>ge({manager:o,store:g,channelId:c}),b.closeAll=()=>Ue({manager:o,store:g}),b.stop=async()=>{y&&await y.stop()},b}async function Le(e,t,n){let r={};for(let o of e)if(o.enrichPaymentRequiredResponse&&o.key in t)try{let s=await o.enrichPaymentRequiredResponse(t[o.key],n);s!==void 0&&(r[o.key]=s)}catch(s){console.warn(`[x402:extensions] extension "${o.key}" failed:`,s)}return Object.keys(r).length>0?r:void 0}function pt(e,t){if(typeof e=="string"||typeof e=="function")return e;if(t in e)return e[t];let r=`${t.split(":")[0]}:*`;if(r in e)return e[r];if("*"in e)return e["*"];throw new Error(`No payTo configured for network "${t}"`)}function ut(e){if(e.scheme==="batch-settlement"){let i=Array.isArray(e.network)?e.network[0]:e.network;if(!i)throw new Error('x402Middleware: scheme "batch-settlement" requires a network');let f=typeof e.payTo=="string"?e.payTo:void 0;if(!f)throw new Error('x402Middleware: scheme "batch-settlement" requires a string payTo address');return he({payTo:f,network:i,price:e.amount,facilitatorUrl:e.facilitatorUrl,route:e.batchSettlement?.route,channelStore:e.batchSettlement?.channelStore,autoSettle:e.batchSettlement?.autoSettle,verbose:e.verbose})}let{payTo:t,amount:n,asset:r,description:o,resourceUrl:s,mimeType:p,timeoutSeconds:y,verbose:g=!1,getResourceUrl:m,getAmount:b,getDescription:c,extensions:a,declarations:h}=e,l=g?console.log.bind(console,"[x402:middleware]"):()=>{},x=typeof t=="function"?t._x402Defaults:void 0,P=e.facilitatorUrl??x?.facilitatorUrl,k=e.network?Array.isArray(e.network)?e.network:[e.network]:x?.network?[x.network]:[le],A=new Map;for(let i of k){let f=pt(t,i);if(typeof f=="function"){let w=Oe(f);if(w&&i!==w)throw new Error(`stripePayTo is configured for "${w}" but middleware includes network "${i}". Stripe only supports Base deposit addresses. Use a static payTo for other chains.`)}A.set(i,Y({payTo:f,network:i,asset:r,facilitatorUrl:P,defaultTimeoutSeconds:y,scheme:e.scheme}))}let S=A.get(k[0]);return async(i,f,w)=>{try{let u=i.headers["payment-signature"];if(!u){l("No payment signature, returning 402");let q=m?.(i)??s??`${i.protocol}://${i.get("host")}${i.originalUrl}`,R=b?.(i)??n,C=c?.(i)??o,N=parseFloat(R),M=[],v=null;for(let[,F]of A)try{let me={amountAtomic:V(N,F.assetDecimals),resourceUrl:q,description:C,mimeType:p,timeoutSeconds:y},Re=await F.buildRequirements(me);M.push(...Re.accepts),v||(v=Re)}catch(me){l("Failed to build requirements for a network:",me)}if(!v||M.length===0){f.status(500).json({error:"Failed to build payment requirements"});return}if(v={...v,accepts:M},a&&a.length>0){let F=await Le(a,h??{},{response:v,request:{method:i.method,path:(i.baseUrl??"")+(i.route?.path??i.path),params:i.params}});F&&(v={...v,extensions:F})}let ee=S.encodeRequirements(v);f.setHeader("PAYMENT-REQUIRED",ee),f.status(402).json({error:"Payment required",accepts:v.accepts,resource:v.resource,...v.extensions?{extensions:v.extensions}:{}});return}l("Payment signature received, verifying...");let d=S;try{let R=JSON.parse(Buffer.from(u,"base64").toString())?.accepted?.network;R&&A.has(R)&&(d=A.get(R))}catch{}let T=await d.verifyPayment(u);if(!T.isValid){if(l("Payment verification failed:",T.invalidReason),e.onVerifyFailed)try{await e.onVerifyFailed({reason:T.invalidReason,resourceUrl:`${i.protocol}://${i.get("host")}${i.originalUrl}`})}catch{}f.status(402).json({error:"Payment verification failed",reason:T.invalidReason});return}l("Payment verified, settling...");let E=await d.settlePayment(u);if(!E.success){l("Payment settlement failed:",E.errorReason),f.status(402).json({error:"Payment settlement failed",reason:E.errorReason});return}l("Payment settled:",E.transaction);let _=E.network||k[0];if(e.onSettlement)try{await e.onSettlement({transaction:E.transaction,network:_,payer:T.payer??"",resourceUrl:`${i.protocol}://${i.get("host")}${i.originalUrl}`})}catch{}i.x402={transaction:E.transaction,payer:T.payer??"",network:_};let O={success:!0,transaction:E.transaction,network:_,payer:T.payer??""};if(E.extensions&&(O.extensions=E.extensions),f.setHeader("PAYMENT-RESPONSE",W(O)),e.sponsoredAccess&&E.extensions?.["sponsored-access"]){let q=E.extensions["sponsored-access"],R=q?.info?.recommendations??q?.recommendations;if(R&&R.length>0){if(l("Injecting sponsored-access recommendations into response"),typeof e.sponsoredAccess=="object"&&e.sponsoredAccess.onMatch)try{e.sponsoredAccess.onMatch(R,{transaction:E.transaction,network:_,payer:T.payer??""})}catch{}let C=f.json.bind(f);f.json=function(M){return typeof e.sponsoredAccess=="object"&&e.sponsoredAccess.inject?C(e.sponsoredAccess.inject(M,R)):M&&typeof M=="object"&&!Array.isArray(M)?C({_x402_sponsored:R,...M}):C(M)}}}w()}catch(u){l("Middleware error:",u),f.status(500).json({error:"Payment processing error"})}}}var lt=/^\/[a-zA-Z0-9_/:.\-~%]+$/;function qe(e){if(!e||!lt.test(e))return!1;let t;try{t=decodeURIComponent(e)}catch{return!1}return!(t.includes("..")||t.includes("://"))}function Z(e){return e.method==="POST"||e.method==="PUT"||e.method==="PATCH"}var dt=["GET","HEAD","DELETE"],mt=["POST","PUT","PATCH"];function Fe(e,t){let n=t.pathParams!==void 0&&Object.keys(t.pathParams).length>0,r={type:"http",method:e.method};Z(e)?(r.bodyType=e.bodyType,r.body=e.input??{}):e.input!==void 0&&(r.queryParams=e.input),n&&(r.pathParams=t.pathParams);let o=e.output?.example!==void 0?{type:"json",example:e.output.example}:void 0,s=Z(e)?mt:dt,p={type:{type:"string",const:"http"},method:{type:"string",enum:s}};Z(e)?(p.bodyType={type:"string",enum:["json","form-data","text"]},p.body={type:"object",...e.inputSchema??{}}):e.inputSchema&&(p.queryParams={type:"object",...e.inputSchema}),e.pathParamsSchema&&(p.pathParams={type:"object",...e.pathParamsSchema});let y={input:{type:"object",properties:p,required:Z(e)?["type","method","bodyType","body"]:["type","method"],additionalProperties:!1}};o&&(y.output={type:"object",properties:{type:{type:"string"},example:{type:"object",...e.output?.schema??{}}},required:["type"]});let g={$schema:"https://json-schema.org/draft/2020-12/schema",type:"object",properties:y,required:["input"]},m={info:{input:r,...o?{output:o}:{}},schema:g};return qe(t.routeTemplate)&&(m.routeTemplate=t.routeTemplate),m}var ft=["GET","HEAD","DELETE","POST","PUT","PATCH"];function yt(){return{key:"bazaar",enrichPaymentRequiredResponse:(e,t)=>{if(e==null)return;let n=e,r=(n.method??t.request.method).toUpperCase();if(!ft.includes(r))return;let o={...n,method:r};return Fe(o,{pathParams:t.request.params,routeTemplate:t.request.path})}}}function gt(e){return{bazaar:e}}function D(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}var ht='<svg width="18" height="18" viewBox="0 0 2000 2000" xmlns="http://www.w3.org/2000/svg"><path d="M1000 2000c554.17 0 1000-445.83 1000-1000S1554.17 0 1000 0 0 445.83 0 1000s445.83 1000 1000 1000z" fill="#2775ca"/><path d="M1275 1158.33c0-145.83-87.5-195.83-262.5-216.66-125-16.67-150-50-150-108.34s41.67-95.83 125-95.83c75 0 116.67 25 137.5 87.5 4.17 12.5 16.67 20.83 29.17 20.83h66.66c16.67 0 29.17-12.5 29.17-29.16v-4.17c-16.67-91.67-91.67-162.5-187.5-170.83v-100c0-16.67-12.5-29.17-33.33-33.34h-62.5c-16.67 0-29.17 12.5-33.34 33.34v95.83c-125 16.67-204.16 100-204.16 204.17 0 137.5 83.33 191.66 258.33 212.5 116.67 20.83 154.17 45.83 154.17 112.5s-58.34 112.5-137.5 112.5c-108.34 0-145.84-45.84-158.34-108.34-4.16-16.66-16.66-25-29.16-25h-70.84c-16.66 0-29.16 12.5-29.16 29.17v4.17c16.66 104.16 83.33 179.16 220.83 200v100c0 16.66 12.5 29.16 33.33 33.33h62.5c16.67 0 29.17-12.5 33.34-33.33v-100c125-20.84 208.33-108.34 208.33-220.84z" fill="#fff"/><path d="M787.5 1595.83c-325-116.66-491.67-479.16-370.83-800 62.5-175 200-308.33 370.83-370.83 16.67-8.33 25-20.83 25-41.67V325c0-16.67-8.33-29.17-25-33.33-4.17 0-12.5 0-16.67 4.16-395.83 125-612.5 545.84-487.5 941.67 75 233.33 254.17 412.5 487.5 487.5 16.67 8.33 33.34 0 37.5-16.67 4.17-4.16 4.17-8.33 4.17-16.66v-58.34c0-12.5-12.5-29.16-25-37.5zM1229.17 295.83c-16.67-8.33-33.34 0-37.5 16.67-4.17 4.17-4.17 8.33-4.17 16.67v58.33c0 16.67 12.5 33.33 25 41.67 325 116.66 491.67 479.16 370.83 800-62.5 175-200 308.33-370.83 370.83-16.67 8.33-25 20.83-25 41.67V1700c0 16.67 8.33 29.17 25 33.33 4.17 0 12.5 0 16.67-4.16 395.83-125 612.5-545.84 487.5-941.67-75-237.5-258.34-416.67-487.5-491.67z" fill="#fff"/></svg>',xt='<svg width="36" height="36" viewBox="0 0 300 300" xmlns="http://www.w3.org/2000/svg"><g><path fill="#F2681A" d="m324.93,313.11c-115.5,0-231,0-350,0l350,0z"/><path fill="#FDFAF5" d="m230.43,50.62c1.1.85 2.19 1.7 3.32 2.57 6.02 4.8 11.77 9.88 17.46 15.07.92.84.92.84 1.86 1.69 1.82 1.69 3.59 3.42 5.35 5.16.61.56 1.22 1.13 1.84 1.71 5.66 5.76 6.18 10.43 6.13 18.3.02 1.16.04 2.32.06 3.52.06 3.83.06 7.65.07 11.48.02 2.68.05 5.35.08 8.03.05 5.6.09 11.21.1 16.81.02 7.15.09 14.31.17 21.46.06 5.53.1 11.05.13 16.58.02 2.64.04 5.27.07 7.91.18 17.58.12 32.82-11.24 47.32-7.35 7.27-16.54 12.06-25.42 17.22-1.97 1.16-3.94 2.33-5.91 3.49-7.16 4.24-14.34 8.44-21.53 12.62-4.8 2.79-9.59 5.6-14.38 8.42-1.25.73-2.5 1.47-3.79 2.23-2.32 1.36-4.64 2.73-6.96 4.1-27.47 16.09-27.47 16.09-42.16 12.93-8.06-2.28-14.94-5.82-22.16-10.02-1.17-.67-2.34-1.34-3.54-2.04-24.55-14.25-43.58-27.03-51.9-55.58-1.07-4.58-1.54-8.92-1.52-13.61.28-9.5.28-9.5-3.3-17.97-1.81-1.49-3.68-2.92-5.59-4.28-9.19-7.06-12.7-20.03-14.18-31.06-.54-5.77-.55-11.56-.6-17.35-.03-1.32-.07-2.63-.1-3.99-.01-1.26-.02-2.53-.03-3.83-.02-1.15-.03-2.29-.05-3.47.72-4.02 1.94-5.36 5.21-7.74 2.89-.53 2.89-.53 6.07-.46 1.71.02 1.71.02 3.46.05 1.19.04 2.37.08 3.59.12 1.2.02 2.41.04 3.65.06 2.97.05 5.93.13 8.9.23.14-1.35.29-2.7.43-4.08.63-5 1.78-9.74 3.14-14.58.22-.79.43-1.59.66-2.4.53-1.92 1.06-3.84 1.6-5.76-1.55-.45-1.55-.45-3.13-.9-9.52-3.52-17.1-10.95-21.37-20.1-3.81-9.26-3.87-20.34-.29-29.68 6.49-13.99 16.36-23.23 30.66-29.01 49.81-17.69 115.79 8.35 155.13 38.85z"/><path fill="#F2671A" d="m142.93,22.62c.86.19 1.73.39 2.62.59 36.12 8.21 68.79 24.98 95.38 50.75 1.02.98 2.03 1.97 3.08 2.98 10.84 10.66 10.84 10.66 11.05 14.62-2.06 3.55-5.44 4.18-9.17 5.3-.79.25-1.59.49-2.41.75-28.13 8.43-60.95 6.37-87.13-7.16-.86-.49-1.71-.97-2.6-1.48-7.37-4.05-12.59-3.36-20.59-1.54-22.76 4-48.47 1.53-68.69-9.74-4.88-3.88-8.23-8.29-10.21-14.22-.93-10.38-.67-18.44 5.83-26.83 19.57-23.38 55.99-20.36 82.83-14z"/><path fill="#F16619" d="m44.93,129.12c27.36-.03 54.72-.05 82.08-.06 12.7-.01 25.41-.01 38.11-.03 11.07-.01 22.14-.02 33.2-.02 5.86 0 11.73-.01 17.59-.01 5.51-.01 11.03-.01 16.54-.01 2.03 0 4.06 0 6.09-.01 2.76-.01 5.52 0 8.28 0 .81 0 1.63-.01 2.47-.01 5.51.02 5.51.02 6.81 1.32.22 3.43.22 3.43 0 7-2.75 2.75-3.42 2.66-7.15 2.82-1.41.07-1.41.07-2.85.14-1.47.05-1.47.05-2.98.11-1.49.07-1.49.07-3 .14-2.45.11-4.9.21-7.35.3-.2 1.3-.4 2.59-.6 3.93-2.57 16.08-5.93 29.89-18.89 40.86-10.35 7.28-21.87 8.49-34.17 7.71-13.11-2.33-22.52-9.19-30.33-19.83-4.49-7.64-4.8-17.05-5.83-25.67-4.24.39-8.47.77-12.83 1.17-.28 1.84-.28 1.84-.56 3.71-2.32 14.39-5.63 23.35-16.95 33.11-2.32 1.67-2.32 1.67-4.65 1.67 4 4.67 9.06 6.59 14.87 8.24 3.79 1.09 3.79 1.09 6.12 3.43-.65 5.31-.65 5.31-2.33 7-8.42-.27-15.13-2.29-22.17-7-1.09-1.21-2.17-2.43-3.25-3.65-2.72-2.81-4.45-3.84-8.36-4.16-1.67-.02-3.34-.02-5.01.01-1.77-.04-3.54-.09-5.3-.15-1.27-.04-1.27-.04-2.56-.08-9.26-.54-17.6-4.56-24.51-10.64-9.58-11.11-11.03-22.56-10.72-36.82.02-1.4.03-2.8.05-4.24.04-3.42.1-6.85.17-10.27z"/><path fill="#F26117" d="m172.68,203.08c7.27.09 13.23 1.97 18.87 6.65 2.88 3.07 3.86 5.12 4.25 9.32-.12 1.01-.24 2.02-.36 3.06-2.55.95-2.55.95-5.83 1.17-3.28-2.84-3.28-2.84-5.83-5.83-.36.58-.71 1.16-1.08 1.75-7.6 11.29-20.06 17.74-33.05 21.09-20.36 3.1-36.81-1.66-53.37-13.73-2.33-2.11-2.33-2.11-4.67-5.61.42-3.45.99-4.49 3.5-7 4.07.37 5.95 2.13 8.75 4.96 9.81 8.93 22.53 11.87 35.51 11.69 11.74-1.05 22.38-5.85 31.57-13.15 2.06-2.45 2.06-2.45 3.5-4.67-1.66.07-1.66.07-3.35.15-3.65-.15-3.65-.15-5.98-2.48.75-6.18 1.46-7.19 7.58-7.36z"/></g></svg>',bt=`
|
|
2
2
|
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Orbitron:wght@500;700&display=swap');
|
|
3
3
|
*{margin:0;padding:0;box-sizing:border-box}
|
|
4
4
|
body{font-family:'Inter',system-ui,-apple-system,sans-serif;background:#0a0a0a;color:#e2e8f0;min-height:100vh;display:flex;align-items:center;justify-content:center;padding:1rem}
|
|
@@ -233,7 +233,7 @@ if (btn) {
|
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
235
|
</script>
|
|
236
|
-
`;function St(e,t,n,r,o,s){let p="?",y="This resource requires payment",g="";try{let c=JSON.parse(Buffer.from(e,"base64").toString()),
|
|
236
|
+
`;function St(e,t,n,r,o,s){let p="?",y="This resource requires payment",g="";try{let c=JSON.parse(Buffer.from(e,"base64").toString()),a=c.accepts?.[0];if(a){let h=a.amount??a.maxAmountRequired??"0",l=a.extra?.decimals||6;p=(Number(h)/Math.pow(10,l)).toFixed(l>4?4:2),g=a.network||""}c.resource?.description&&(y=c.resource.description)}catch{}let m=g.includes("solana")?"Solana":g.includes("eip155")?"Base":"",b=r.showEndpoint?`<div class="endpoint"><code>${D(n)} ${D(t)}</code></div>`:"";return`<!DOCTYPE html>
|
|
237
237
|
<html lang="en">
|
|
238
238
|
<head>
|
|
239
239
|
<meta charset="utf-8">
|
|
@@ -281,6 +281,6 @@ if (btn) {
|
|
|
281
281
|
></div>
|
|
282
282
|
${Tt}
|
|
283
283
|
</body>
|
|
284
|
-
</html>`}function Rt(e={}){let t={title:e.title??"Payment Required",branding:e.branding??'Powered by <a href="https://docs.dexter.cash/docs/sdk/">Dexter x402</a>',sdkUrl:e.sdkUrl??"https://docs.dexter.cash/docs/sdk/",showEndpoint:e.showEndpoint??!0},n=e.rpcUrl??"https://api.dexter.cash/api/solana/rpc";return(r,o,s)=>{let p=o.json.bind(o);o.json=function(y){if(o.statusCode===402&&r.accepts("html")&&!r.headers["payment-signature"]){let g=o.getHeader("PAYMENT-REQUIRED")||o.getHeader("payment-required");if(g&&typeof g=="string"){let m;if(r.body&&typeof r.body=="object"&&Object.keys(r.body).length>0)try{m=JSON.stringify(r.body)}catch{}let b=St(g,r.originalUrl,r.method,t,n,m);return o.setHeader("Content-Security-Policy","default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; connect-src *; img-src data:; frame-ancestors 'none'"),o.setHeader("X-Content-Type-Options","nosniff"),o.status(402).type("html").send(b),o}}return p(y)},s()}}import xe from"crypto";var wt=/^(\d+)(m|h|d|w)$/;function At(e){let t=e.match(wt);if(!t)return null;let n=parseInt(t[1],10);switch(t[2]){case"m":return n*60;case"h":return n*3600;case"d":return n*86400;case"w":return n*604800;default:return null}}function He(e){return e>=604800&&e%604800===0?`${e/604800} week${e/604800>1?"s":""}`:e>=86400&&e%86400===0?`${e/86400} day${e/86400>1?"s":""}`:e>=3600&&e%3600===0?`${e/3600} hour${e/3600>1?"s":""}`:e>=60&&e%60===0?`${e/60} minute${e/60>1?"s":""}`:`${e} second${e>1?"s":""}`}function Et(e,t){let n=Buffer.from(JSON.stringify({alg:"HS256",typ:"JWT"})).toString("base64url"),r=Buffer.from(JSON.stringify(e)).toString("base64url"),o=xe.createHmac("sha256",t).update(`${n}.${r}`).digest("base64url");return`${n}.${r}.${o}`}function kt(e,t){try{let n=e.split(".");if(n.length!==3)return null;let[r,o,s]=n,p=xe.createHmac("sha256",t).update(`${r}.${o}`).digest("base64url");if(s!==p)return null;let y=JSON.parse(Buffer.from(o,"base64url").toString());return y.exp&&Date.now()/1e3>y.exp||y.sub!=="x402-access-pass"?null:y}catch{return null}}function vt(e){let{payTo:t,network:n=le,asset:r,facilitatorUrl:o,tiers:s,ratePerHour:p,secret:y,issuer:g="x402-access-pass",verbose:m=!1,description:b}=e,c=y??xe.randomBytes(32);if(y||console.warn("[x402:access-pass] No secret provided \u2014 access passes will be invalidated on server restart. Set `secret` for production use."),!s&&!p)throw new Error("x402AccessPass: at least one of `tiers` or `ratePerHour` is required");let i=m?console.log.bind(console,"[x402:access-pass]"):()=>{},h=r?.decimals??ue,l=[];if(s){for(let[a,f]of Object.entries(s)){let w=At(a);if(!w){console.warn(`x402AccessPass: skipping tier "${a}" \u2014 unrecognized duration format (use 5m, 1h, 24h, 7d)`);continue}l.push({id:a,label:He(w),seconds:w,price:f,priceAtomic:V(parseFloat(f),h)})}l.sort((a,f)=>a.seconds-f.seconds)}let x=Y({payTo:t,network:n,asset:r,facilitatorUrl:o}),P={tiers:l.length>0?l:void 0,ratePerHour:p||void 0,issuer:g},k=W(P);function A(a){if(!p)throw new Error("Custom durations not supported \u2014 no ratePerHour configured");let f=a/3600,w=(parseFloat(p)*f).toFixed(h>4?4:2);return{price:w,priceAtomic:V(parseFloat(w),h)}}function S(a){let f=a.query.tier,w=a.query.duration;if(f){let d=l.find(T=>T.id===f);if(d)return{tier:d.id,seconds:d.seconds,price:d.price,priceAtomic:d.priceAtomic,label:d.label}}if(w){let d=parseInt(w,10);if(d>0&&p){let T=A(d);return{tier:"custom",seconds:d,...T,label:He(d)}}}if(l.length>0){let d=l[0];return{tier:d.id,seconds:d.seconds,price:d.price,priceAtomic:d.priceAtomic,label:d.label}}return{tier:"custom",seconds:3600,...A(3600),label:"1 hour"}}return async(a,f,w)=>{try{let u=a.headers.authorization;if(u?.startsWith("Bearer ")){let R=kt(u.slice(7),c);if(R)return i("Valid access pass:",R.tier,"| expires:",new Date(R.exp*1e3).toISOString()),a.accessPass={tier:R.tier,duration:R.duration,expiresAt:new Date(R.exp*1e3).toISOString(),payer:R.payer,network:R.network},w();i("Invalid or expired access pass token")}let d=a.headers["payment-signature"];if(d){i("Payment signature received, verifying for pass purchase...");let R=await x.verifyPayment(d);if(!R.isValid){i("Payment verification failed:",R.invalidReason),f.status(402).json({error:"Payment verification failed",reason:R.invalidReason});return}let C=await x.settlePayment(d);if(!C.success){i("Payment settlement failed:",C.errorReason),f.status(402).json({error:"Payment settlement failed",reason:C.errorReason});return}i("Payment settled:",C.transaction);let N=S(a),M=Math.floor(Date.now()/1e3),v={sub:"x402-access-pass",tier:N.tier,duration:N.seconds,iat:M,exp:M+N.seconds,payer:R.payer??"",network:n,iss:g},ee=Et(v,c);a.x402={transaction:C.transaction,payer:R.payer??"",network:n};let F={success:!0,transaction:C.transaction,network:n,payer:R.payer??""};f.setHeader("PAYMENT-RESPONSE",W(F)),f.setHeader("ACCESS-PASS",ee),f.json({accessPass:{token:ee,tier:N.tier,duration:N.label,durationSeconds:N.seconds,expiresAt:new Date((M+N.seconds)*1e3).toISOString(),usage:"Include on subsequent requests as: Authorization: Bearer <token>"},transaction:C.transaction,payer:R.payer});return}i("No access pass or payment, returning 402");let T=S(a),E=T.priceAtomic,_=`${a.protocol}://${a.get("host")}${a.originalUrl}`,O=await x.buildRequirements({amountAtomic:E,resourceUrl:_,description:b||`Access pass: ${T.label}`,mimeType:"application/json"}),q=x.encodeRequirements(O);f.setHeader("PAYMENT-REQUIRED",q),f.setHeader("X-ACCESS-PASS-TIERS",k),f.status(402).json({error:"Access pass required",message:"Purchase an access pass to unlock unlimited API access for a time window.",accepts:O.accepts,resource:O.resource,accessPass:{tiers:l.length>0?l:void 0,ratePerHour:p||void 0,usage:"Add ?tier=<id> or ?duration=<seconds> to your payment request to choose a pass duration."}})}catch(u){i("Access pass middleware error:",u),f.status(500).json({error:"Payment processing error",message:u instanceof Error?u.message:"Unknown error"})}}}import{createHmac as Mt,randomBytes as Ct}from"crypto";var _t=300;function Ot(e){let t={unitSize:e.unitSize,ratePerUnit:e.ratePerUnit,minUsd:e.minUsd??.01,maxUsd:e.maxUsd??1/0,roundingMode:e.roundingMode??"ceil",decimals:e.decimals??6},{unitSize:n,ratePerUnit:r,minUsd:o,maxUsd:s,roundingMode:p,decimals:y}=t;if(n<=0)throw new Error("unitSize must be positive");if(r<=0)throw new Error("ratePerUnit must be positive");if(o<0)throw new Error("minUsd cannot be negative");if(s<o)throw new Error("maxUsd must be >= minUsd");let g=Ct(32);function m(i,h){let l=JSON.stringify({unitSize:n,ratePerUnit:r,minUsd:o,maxUsd:s===1/0?"none":s,roundingMode:p}),x=`${i}|${l}|${h}`;return Mt("sha256",g).update(x).digest("hex").slice(0,16)}function b(i){let h=i.length,l=h/n,x;switch(p){case"ceil":x=Math.ceil(l);break;case"floor":x=Math.floor(l);break;case"round":x=Math.round(l);break}h>0&&x===0&&(x=1);let P=x*r;P=Math.max(o,P),P=Math.min(s,P);let k=Math.pow(10,y),A=Math.floor(P*k).toString(),S=Math.floor(Date.now()/1e3),a=m(i,S),f=`${S}.${a}`;return{amountAtomic:A,usdAmount:P,quoteHash:f,units:x,inputLength:h}}function c(i,h){if(!h)return!1;let l=h.indexOf(".");if(l===-1)return!1;let x=parseInt(h.slice(0,l),10),P=h.slice(l+1);if(isNaN(x)||!P)return!1;let k=Math.floor(Date.now()/1e3)-x;if(k<0||k>_t)return!1;let A=m(i,x);if(P.length!==A.length)return!1;let S=0;for(let a=0;a<P.length;a++)S|=P.charCodeAt(a)^A.charCodeAt(a);return S===0}return{calculate:b,validateQuote:c,config:t}}function Nt(e){let t=e.ratePerUnit.toFixed(2),n=e.unitSize.toLocaleString();return`from $${t} per ${n} chars`}import{createHash as Kt}from"crypto";var I={usesMaxCompletionTokens:!1,supportsTemperature:!0,supportsTopP:!0,supportsFrequencyPenalty:!0,supportsPresencePenalty:!0,supportsReasoningEffort:!1,supportsStreaming:!0,supportsSystemMessage:!0,supportsTools:!0,supportsStructuredOutput:!0},K={usesMaxCompletionTokens:!0,supportsTemperature:!1,supportsTopP:!1,supportsFrequencyPenalty:!1,supportsPresencePenalty:!1,supportsReasoningEffort:!1,supportsStreaming:!0,supportsSystemMessage:!0,supportsTools:!0,supportsStructuredOutput:!0},L={usesMaxCompletionTokens:!0,supportsTemperature:!1,supportsTopP:!1,supportsFrequencyPenalty:!1,supportsPresencePenalty:!1,supportsReasoningEffort:!0,supportsStreaming:!0,supportsSystemMessage:!0,supportsTools:!0,supportsStructuredOutput:!0},We={...L,supportsStreaming:!1},B=[{id:"gpt-4o-mini",displayName:"GPT-4o Mini",family:"gpt-4o",tier:"fast",capabilityRank:3,modalities:["text","vision"],apiType:"chat",pricing:{input:.15,output:.6,cached:.075},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:I,deprecated:!1,description:"Fast, affordable small model with vision support"},{id:"gpt-4.1-nano",displayName:"GPT-4.1 Nano",family:"gpt-4.1",tier:"fast",capabilityRank:2,modalities:["text"],apiType:"chat",pricing:{input:.1,output:.4,cached:.025},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:32768,parameters:I,deprecated:!1,description:"Smallest 4.1 model, very fast and cheap"},{id:"gpt-4.1-mini",displayName:"GPT-4.1 Mini",family:"gpt-4.1",tier:"fast",capabilityRank:4,modalities:["text"],apiType:"chat",pricing:{input:.4,output:1.6,cached:.1},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:32768,parameters:I,deprecated:!1,description:"Balanced 4.1 model, good price/performance"},{id:"gpt-5-nano",displayName:"GPT-5 Nano",family:"gpt-5",tier:"fast",capabilityRank:1,modalities:["text"],apiType:"chat",pricing:{input:.05,output:.4,cached:.005},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:K,deprecated:!1,description:"Cheapest GPT-5 variant, extremely fast"},{id:"gpt-5-mini",displayName:"GPT-5 Mini",family:"gpt-5",tier:"fast",capabilityRank:5,modalities:["text"],apiType:"chat",pricing:{input:.25,output:2,cached:.025},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:K,deprecated:!1,description:"Small but capable GPT-5, great value"},{id:"gpt-4o",displayName:"GPT-4o",family:"gpt-4o",tier:"standard",capabilityRank:5,modalities:["text","vision"],apiType:"chat",pricing:{input:2.5,output:10,cached:1.25},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:I,deprecated:!1,description:"Flagship multimodal model with vision"},{id:"gpt-4.1",displayName:"GPT-4.1",family:"gpt-4.1",tier:"standard",capabilityRank:6,modalities:["text"],apiType:"chat",pricing:{input:2,output:8,cached:.5},contextWindow:1e6,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:I,deprecated:!1,description:"Long context specialist, 1M token window"},{id:"gpt-5",displayName:"GPT-5",family:"gpt-5",tier:"standard",capabilityRank:7,modalities:["text"],apiType:"chat",pricing:{input:1.25,output:10,cached:.125},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:K,deprecated:!1,description:"Base GPT-5, excellent all-around"},{id:"gpt-5.1",displayName:"GPT-5.1",family:"gpt-5",tier:"standard",capabilityRank:8,modalities:["text"],apiType:"chat",pricing:{input:1.25,output:10,cached:.125},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:K,deprecated:!1,description:"Improved GPT-5 with better instruction following"},{id:"gpt-5.2",displayName:"GPT-5.2",family:"gpt-5",tier:"standard",capabilityRank:9,modalities:["text"],apiType:"chat",pricing:{input:1.75,output:14,cached:.175},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:K,deprecated:!1,description:"Latest GPT-5, most capable standard model"},{id:"o1-mini",displayName:"o1 Mini",family:"o1",tier:"reasoning",capabilityRank:3,modalities:["text"],apiType:"chat",pricing:{input:1.1,output:4.4,cached:.55},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:L,deprecated:!1,description:"Fast reasoning model, good for math/code"},{id:"o3-mini",displayName:"o3 Mini",family:"o3",tier:"reasoning",capabilityRank:4,modalities:["text"],apiType:"chat",pricing:{input:1.1,output:4.4,cached:.55},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:L,deprecated:!1,description:"Improved mini reasoner with better efficiency"},{id:"o4-mini",displayName:"o4 Mini",family:"o4",tier:"reasoning",capabilityRank:5,modalities:["text"],apiType:"chat",pricing:{input:1.1,output:4.4,cached:.275},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:L,deprecated:!1,description:"Latest mini reasoner, best reasoning per dollar"},{id:"o3",displayName:"o3",family:"o3",tier:"reasoning",capabilityRank:7,modalities:["text"],apiType:"chat",pricing:{input:2,output:8,cached:.5},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:L,deprecated:!1,description:"Full o3 reasoning model, excellent for complex problems"},{id:"o1",displayName:"o1",family:"o1",tier:"reasoning",capabilityRank:8,modalities:["text"],apiType:"chat",pricing:{input:15,output:60,cached:7.5},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:L,deprecated:!1,description:"Original full reasoning model, very capable"},{id:"gpt-5-pro",displayName:"GPT-5 Pro",family:"gpt-5",tier:"premium",capabilityRank:7,modalities:["text"],apiType:"chat",pricing:{input:15,output:120},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:32768,parameters:K,deprecated:!1,description:"Enhanced GPT-5 for demanding tasks"},{id:"gpt-5.2-pro",displayName:"GPT-5.2 Pro",family:"gpt-5",tier:"premium",capabilityRank:8,modalities:["text"],apiType:"chat",pricing:{input:21,output:168},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:32768,parameters:K,deprecated:!1,description:"Most capable standard model available"},{id:"o3-pro",displayName:"o3 Pro",family:"o3",tier:"premium",capabilityRank:9,modalities:["text"],apiType:"chat",pricing:{input:20,output:80},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:We,deprecated:!1,description:"Premium o3 with extended thinking time"},{id:"o1-pro",displayName:"o1 Pro",family:"o1",tier:"premium",capabilityRank:10,modalities:["text"],apiType:"chat",pricing:{input:150,output:600},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:We,deprecated:!1,description:"Most capable reasoning model, extended compute"},{id:"o3-deep-research",displayName:"o3 Deep Research",family:"o3",tier:"specialized",capabilityRank:8,modalities:["text"],apiType:"responses",pricing:{input:10,output:40,cached:2.5},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:{...L,supportsStreaming:!1},deprecated:!1,description:"Extended research sessions with web access"},{id:"o4-mini-deep-research",displayName:"o4 Mini Deep Research",family:"o4",tier:"specialized",capabilityRank:6,modalities:["text"],apiType:"responses",pricing:{input:2,output:8,cached:.5},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:{...L,supportsStreaming:!1},deprecated:!1,description:"Affordable deep research with o4 mini"},{id:"computer-use-preview",displayName:"Computer Use Preview",family:"computer-use",tier:"specialized",capabilityRank:5,modalities:["text","vision"],apiType:"responses",pricing:{input:3,output:12},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:{...I,supportsReasoningEffort:!1},deprecated:!1,description:"Can control computer interfaces via screenshots"},{id:"gpt-realtime",displayName:"GPT Realtime",family:"gpt-realtime",tier:"specialized",capabilityRank:7,modalities:["text","audio","realtime"],apiType:"chat",pricing:{input:4,output:16,cached:.4},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:4096,parameters:{...I,supportsReasoningEffort:!1},deprecated:!1,description:"Real-time audio conversation model"},{id:"gpt-realtime-mini",displayName:"GPT Realtime Mini",family:"gpt-realtime",tier:"specialized",capabilityRank:4,modalities:["text","audio","realtime"],apiType:"chat",pricing:{input:.6,output:2.4,cached:.06},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:4096,parameters:{...I,supportsReasoningEffort:!1},deprecated:!1,description:"Affordable real-time audio model"},{id:"gpt-4o-2024-05-13",displayName:"GPT-4o (May 2024)",family:"gpt-4o",tier:"standard",capabilityRank:4,modalities:["text","vision"],apiType:"chat",pricing:{input:5,output:15},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:4096,parameters:I,deprecated:!0,description:"Original GPT-4o snapshot, use gpt-4o instead"}],be=new Map(B.map(e=>[e.id,e]));function Pe(e){let t=be.get(e);if(!t)throw new Error(`Unknown model: ${e}. Use getAvailableModelIds() to see valid options.`);return t}function Dt(e){return be.get(e)}function It(e){return be.has(e)}function Bt(){return B.map(e=>e.id)}function Ut(e){return B.filter(t=>t.tier===e&&!t.deprecated).sort((t,n)=>t.capabilityRank-n.capabilityRank)}function $t(e){return B.filter(t=>t.family===e).sort((t,n)=>t.capabilityRank-n.capabilityRank)}function Lt(){let e={fast:1,standard:2,reasoning:3,premium:4,specialized:5};return B.filter(t=>!t.deprecated).sort((t,n)=>{let r=e[t.tier]-e[n.tier];return r!==0?r:t.capabilityRank-n.capabilityRank})}function qt(){return B.filter(e=>!e.deprecated&&e.modalities.includes("text")&&!e.modalities.includes("realtime")&&e.apiType!=="responses").sort((e,t)=>{let n={fast:1,standard:2,reasoning:3,premium:4,specialized:5},r=n[e.tier]-n[t.tier];return r!==0?r:e.capabilityRank-t.capabilityRank})}function Ft(e="fast"){let t={fast:1,standard:2,reasoning:3,premium:4,specialized:5},n=t[e];return B.filter(o=>!o.deprecated&&t[o.tier]>=n).sort((o,s)=>o.pricing.input-s.pricing.input)[0]}function Ht(e,t,n,r=!1){let o=Pe(e),s=r&&o.pricing.cached?t/1e6*o.pricing.cached:t/1e6*o.pricing.input,p=n/1e6*o.pricing.output;return s+p}function Wt(e){let t=Pe(e);return`$${t.pricing.input.toFixed(2)} in / $${t.pricing.output.toFixed(2)} out per 1M tokens`}var Te=Object.fromEntries(B.map(e=>[e.id,{input:e.pricing.input,output:e.pricing.output,cached:e.pricing.cached,maxTokens:e.defaultMaxOutput,tier:e.tier}]));var de=null;async function jt(){if(de)return de;try{return de=await import("tiktoken"),de}catch{throw new Error('Token pricing requires the "tiktoken" package. Install with: npm install tiktoken')}}var U=Te,j="gpt-4o-mini";async function zt(e){let t=await jt();try{return t.encoding_for_model(e)}catch{return t.get_encoding("cl100k_base")}}async function Se(e,t=j){let n=await zt(t);try{return n.encode(e).length}finally{n.free()}}function Ke(e,t,n,r){let o=JSON.stringify({model:t,rate:n,tokens:r});return Kt("sha256").update(e+o).digest("hex").slice(0,16)}function Gt(e={}){let t=e.model??j,n=U[t],r={input:e.inputRate??n?.input??U[j].input,output:e.outputRate??n?.output??U[j].output,maxTokens:e.maxTokens??n?.maxTokens??4096,tier:e.tier??n?.tier??"custom"},o=e.tokenizer,s={model:t,inputRate:r.input,outputRate:r.output,maxTokens:r.maxTokens,tier:r.tier,tokenizer:o??(i=>Se(i,t)),minUsd:e.minUsd??.001,maxUsd:e.maxUsd??50,decimals:e.decimals??6},{minUsd:p,maxUsd:y,decimals:g}=s;async function m(i){return o?o(i):Se(i,t)}async function b(i,h){let l=h?`${h}
|
|
284
|
+
</html>`}function Rt(e={}){let t={title:e.title??"Payment Required",branding:e.branding??'Powered by <a href="https://docs.dexter.cash/docs/sdk/">Dexter x402</a>',sdkUrl:e.sdkUrl??"https://docs.dexter.cash/docs/sdk/",showEndpoint:e.showEndpoint??!0},n=e.rpcUrl??"https://api.dexter.cash/api/solana/rpc";return(r,o,s)=>{let p=o.json.bind(o);o.json=function(y){if(o.statusCode===402&&r.accepts("html")&&!r.headers["payment-signature"]){let g=o.getHeader("PAYMENT-REQUIRED")||o.getHeader("payment-required");if(g&&typeof g=="string"){let m;if(r.body&&typeof r.body=="object"&&Object.keys(r.body).length>0)try{m=JSON.stringify(r.body)}catch{}let b=St(g,r.originalUrl,r.method,t,n,m);return o.setHeader("Content-Security-Policy","default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; connect-src *; img-src data:; frame-ancestors 'none'"),o.setHeader("X-Content-Type-Options","nosniff"),o.status(402).type("html").send(b),o}}return p(y)},s()}}import xe from"crypto";var wt=/^(\d+)(m|h|d|w)$/;function At(e){let t=e.match(wt);if(!t)return null;let n=parseInt(t[1],10);switch(t[2]){case"m":return n*60;case"h":return n*3600;case"d":return n*86400;case"w":return n*604800;default:return null}}function He(e){return e>=604800&&e%604800===0?`${e/604800} week${e/604800>1?"s":""}`:e>=86400&&e%86400===0?`${e/86400} day${e/86400>1?"s":""}`:e>=3600&&e%3600===0?`${e/3600} hour${e/3600>1?"s":""}`:e>=60&&e%60===0?`${e/60} minute${e/60>1?"s":""}`:`${e} second${e>1?"s":""}`}function Et(e,t){let n=Buffer.from(JSON.stringify({alg:"HS256",typ:"JWT"})).toString("base64url"),r=Buffer.from(JSON.stringify(e)).toString("base64url"),o=xe.createHmac("sha256",t).update(`${n}.${r}`).digest("base64url");return`${n}.${r}.${o}`}function kt(e,t){try{let n=e.split(".");if(n.length!==3)return null;let[r,o,s]=n,p=xe.createHmac("sha256",t).update(`${r}.${o}`).digest("base64url");if(s!==p)return null;let y=JSON.parse(Buffer.from(o,"base64url").toString());return y.exp&&Date.now()/1e3>y.exp||y.sub!=="x402-access-pass"?null:y}catch{return null}}function vt(e){let{payTo:t,network:n=le,asset:r,facilitatorUrl:o,tiers:s,ratePerHour:p,secret:y,issuer:g="x402-access-pass",verbose:m=!1,description:b}=e,c=y??xe.randomBytes(32);if(y||console.warn("[x402:access-pass] No secret provided \u2014 access passes will be invalidated on server restart. Set `secret` for production use."),!s&&!p)throw new Error("x402AccessPass: at least one of `tiers` or `ratePerHour` is required");let a=m?console.log.bind(console,"[x402:access-pass]"):()=>{},h=r?.decimals??ue,l=[];if(s){for(let[i,f]of Object.entries(s)){let w=At(i);if(!w){console.warn(`x402AccessPass: skipping tier "${i}" \u2014 unrecognized duration format (use 5m, 1h, 24h, 7d)`);continue}l.push({id:i,label:He(w),seconds:w,price:f,priceAtomic:V(parseFloat(f),h)})}l.sort((i,f)=>i.seconds-f.seconds)}let x=Y({payTo:t,network:n,asset:r,facilitatorUrl:o}),P={tiers:l.length>0?l:void 0,ratePerHour:p||void 0,issuer:g},k=W(P);function A(i){if(!p)throw new Error("Custom durations not supported \u2014 no ratePerHour configured");let f=i/3600,w=(parseFloat(p)*f).toFixed(h>4?4:2);return{price:w,priceAtomic:V(parseFloat(w),h)}}function S(i){let f=i.query.tier,w=i.query.duration;if(f){let d=l.find(T=>T.id===f);if(d)return{tier:d.id,seconds:d.seconds,price:d.price,priceAtomic:d.priceAtomic,label:d.label}}if(w){let d=parseInt(w,10);if(d>0&&p){let T=A(d);return{tier:"custom",seconds:d,...T,label:He(d)}}}if(l.length>0){let d=l[0];return{tier:d.id,seconds:d.seconds,price:d.price,priceAtomic:d.priceAtomic,label:d.label}}return{tier:"custom",seconds:3600,...A(3600),label:"1 hour"}}return async(i,f,w)=>{try{let u=i.headers.authorization;if(u?.startsWith("Bearer ")){let R=kt(u.slice(7),c);if(R)return a("Valid access pass:",R.tier,"| expires:",new Date(R.exp*1e3).toISOString()),i.accessPass={tier:R.tier,duration:R.duration,expiresAt:new Date(R.exp*1e3).toISOString(),payer:R.payer,network:R.network},w();a("Invalid or expired access pass token")}let d=i.headers["payment-signature"];if(d){a("Payment signature received, verifying for pass purchase...");let R=await x.verifyPayment(d);if(!R.isValid){a("Payment verification failed:",R.invalidReason),f.status(402).json({error:"Payment verification failed",reason:R.invalidReason});return}let C=await x.settlePayment(d);if(!C.success){a("Payment settlement failed:",C.errorReason),f.status(402).json({error:"Payment settlement failed",reason:C.errorReason});return}a("Payment settled:",C.transaction);let N=S(i),M=Math.floor(Date.now()/1e3),v={sub:"x402-access-pass",tier:N.tier,duration:N.seconds,iat:M,exp:M+N.seconds,payer:R.payer??"",network:n,iss:g},ee=Et(v,c);i.x402={transaction:C.transaction,payer:R.payer??"",network:n};let F={success:!0,transaction:C.transaction,network:n,payer:R.payer??""};f.setHeader("PAYMENT-RESPONSE",W(F)),f.setHeader("ACCESS-PASS",ee),f.json({accessPass:{token:ee,tier:N.tier,duration:N.label,durationSeconds:N.seconds,expiresAt:new Date((M+N.seconds)*1e3).toISOString(),usage:"Include on subsequent requests as: Authorization: Bearer <token>"},transaction:C.transaction,payer:R.payer});return}a("No access pass or payment, returning 402");let T=S(i),E=T.priceAtomic,_=`${i.protocol}://${i.get("host")}${i.originalUrl}`,O=await x.buildRequirements({amountAtomic:E,resourceUrl:_,description:b||`Access pass: ${T.label}`,mimeType:"application/json"}),q=x.encodeRequirements(O);f.setHeader("PAYMENT-REQUIRED",q),f.setHeader("X-ACCESS-PASS-TIERS",k),f.status(402).json({error:"Access pass required",message:"Purchase an access pass to unlock unlimited API access for a time window.",accepts:O.accepts,resource:O.resource,accessPass:{tiers:l.length>0?l:void 0,ratePerHour:p||void 0,usage:"Add ?tier=<id> or ?duration=<seconds> to your payment request to choose a pass duration."}})}catch(u){a("Access pass middleware error:",u),f.status(500).json({error:"Payment processing error",message:u instanceof Error?u.message:"Unknown error"})}}}import{createHmac as Mt,randomBytes as Ct}from"crypto";var _t=300;function Ot(e){let t={unitSize:e.unitSize,ratePerUnit:e.ratePerUnit,minUsd:e.minUsd??.01,maxUsd:e.maxUsd??1/0,roundingMode:e.roundingMode??"ceil",decimals:e.decimals??6},{unitSize:n,ratePerUnit:r,minUsd:o,maxUsd:s,roundingMode:p,decimals:y}=t;if(n<=0)throw new Error("unitSize must be positive");if(r<=0)throw new Error("ratePerUnit must be positive");if(o<0)throw new Error("minUsd cannot be negative");if(s<o)throw new Error("maxUsd must be >= minUsd");let g=Ct(32);function m(a,h){let l=JSON.stringify({unitSize:n,ratePerUnit:r,minUsd:o,maxUsd:s===1/0?"none":s,roundingMode:p}),x=`${a}|${l}|${h}`;return Mt("sha256",g).update(x).digest("hex").slice(0,16)}function b(a){let h=a.length,l=h/n,x;switch(p){case"ceil":x=Math.ceil(l);break;case"floor":x=Math.floor(l);break;case"round":x=Math.round(l);break}h>0&&x===0&&(x=1);let P=x*r;P=Math.max(o,P),P=Math.min(s,P);let k=Math.pow(10,y),A=Math.floor(P*k).toString(),S=Math.floor(Date.now()/1e3),i=m(a,S),f=`${S}.${i}`;return{amountAtomic:A,usdAmount:P,quoteHash:f,units:x,inputLength:h}}function c(a,h){if(!h)return!1;let l=h.indexOf(".");if(l===-1)return!1;let x=parseInt(h.slice(0,l),10),P=h.slice(l+1);if(isNaN(x)||!P)return!1;let k=Math.floor(Date.now()/1e3)-x;if(k<0||k>_t)return!1;let A=m(a,x);if(P.length!==A.length)return!1;let S=0;for(let i=0;i<P.length;i++)S|=P.charCodeAt(i)^A.charCodeAt(i);return S===0}return{calculate:b,validateQuote:c,config:t}}function Nt(e){let t=e.ratePerUnit.toFixed(2),n=e.unitSize.toLocaleString();return`from $${t} per ${n} chars`}import{createHash as Kt}from"crypto";var I={usesMaxCompletionTokens:!1,supportsTemperature:!0,supportsTopP:!0,supportsFrequencyPenalty:!0,supportsPresencePenalty:!0,supportsReasoningEffort:!1,supportsStreaming:!0,supportsSystemMessage:!0,supportsTools:!0,supportsStructuredOutput:!0},K={usesMaxCompletionTokens:!0,supportsTemperature:!1,supportsTopP:!1,supportsFrequencyPenalty:!1,supportsPresencePenalty:!1,supportsReasoningEffort:!1,supportsStreaming:!0,supportsSystemMessage:!0,supportsTools:!0,supportsStructuredOutput:!0},L={usesMaxCompletionTokens:!0,supportsTemperature:!1,supportsTopP:!1,supportsFrequencyPenalty:!1,supportsPresencePenalty:!1,supportsReasoningEffort:!0,supportsStreaming:!0,supportsSystemMessage:!0,supportsTools:!0,supportsStructuredOutput:!0},We={...L,supportsStreaming:!1},U=[{id:"gpt-4o-mini",displayName:"GPT-4o Mini",family:"gpt-4o",tier:"fast",capabilityRank:3,modalities:["text","vision"],apiType:"chat",pricing:{input:.15,output:.6,cached:.075},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:I,deprecated:!1,description:"Fast, affordable small model with vision support"},{id:"gpt-4.1-nano",displayName:"GPT-4.1 Nano",family:"gpt-4.1",tier:"fast",capabilityRank:2,modalities:["text"],apiType:"chat",pricing:{input:.1,output:.4,cached:.025},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:32768,parameters:I,deprecated:!1,description:"Smallest 4.1 model, very fast and cheap"},{id:"gpt-4.1-mini",displayName:"GPT-4.1 Mini",family:"gpt-4.1",tier:"fast",capabilityRank:4,modalities:["text"],apiType:"chat",pricing:{input:.4,output:1.6,cached:.1},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:32768,parameters:I,deprecated:!1,description:"Balanced 4.1 model, good price/performance"},{id:"gpt-5-nano",displayName:"GPT-5 Nano",family:"gpt-5",tier:"fast",capabilityRank:1,modalities:["text"],apiType:"chat",pricing:{input:.05,output:.4,cached:.005},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:K,deprecated:!1,description:"Cheapest GPT-5 variant, extremely fast"},{id:"gpt-5-mini",displayName:"GPT-5 Mini",family:"gpt-5",tier:"fast",capabilityRank:5,modalities:["text"],apiType:"chat",pricing:{input:.25,output:2,cached:.025},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:K,deprecated:!1,description:"Small but capable GPT-5, great value"},{id:"gpt-4o",displayName:"GPT-4o",family:"gpt-4o",tier:"standard",capabilityRank:5,modalities:["text","vision"],apiType:"chat",pricing:{input:2.5,output:10,cached:1.25},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:I,deprecated:!1,description:"Flagship multimodal model with vision"},{id:"gpt-4.1",displayName:"GPT-4.1",family:"gpt-4.1",tier:"standard",capabilityRank:6,modalities:["text"],apiType:"chat",pricing:{input:2,output:8,cached:.5},contextWindow:1e6,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:I,deprecated:!1,description:"Long context specialist, 1M token window"},{id:"gpt-5",displayName:"GPT-5",family:"gpt-5",tier:"standard",capabilityRank:7,modalities:["text"],apiType:"chat",pricing:{input:1.25,output:10,cached:.125},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:K,deprecated:!1,description:"Base GPT-5, excellent all-around"},{id:"gpt-5.1",displayName:"GPT-5.1",family:"gpt-5",tier:"standard",capabilityRank:8,modalities:["text"],apiType:"chat",pricing:{input:1.25,output:10,cached:.125},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:K,deprecated:!1,description:"Improved GPT-5 with better instruction following"},{id:"gpt-5.2",displayName:"GPT-5.2",family:"gpt-5",tier:"standard",capabilityRank:9,modalities:["text"],apiType:"chat",pricing:{input:1.75,output:14,cached:.175},contextWindow:128e3,defaultMaxOutput:8192,maxOutputTokens:32768,parameters:K,deprecated:!1,description:"Latest GPT-5, most capable standard model"},{id:"o1-mini",displayName:"o1 Mini",family:"o1",tier:"reasoning",capabilityRank:3,modalities:["text"],apiType:"chat",pricing:{input:1.1,output:4.4,cached:.55},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:L,deprecated:!1,description:"Fast reasoning model, good for math/code"},{id:"o3-mini",displayName:"o3 Mini",family:"o3",tier:"reasoning",capabilityRank:4,modalities:["text"],apiType:"chat",pricing:{input:1.1,output:4.4,cached:.55},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:L,deprecated:!1,description:"Improved mini reasoner with better efficiency"},{id:"o4-mini",displayName:"o4 Mini",family:"o4",tier:"reasoning",capabilityRank:5,modalities:["text"],apiType:"chat",pricing:{input:1.1,output:4.4,cached:.275},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:L,deprecated:!1,description:"Latest mini reasoner, best reasoning per dollar"},{id:"o3",displayName:"o3",family:"o3",tier:"reasoning",capabilityRank:7,modalities:["text"],apiType:"chat",pricing:{input:2,output:8,cached:.5},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:L,deprecated:!1,description:"Full o3 reasoning model, excellent for complex problems"},{id:"o1",displayName:"o1",family:"o1",tier:"reasoning",capabilityRank:8,modalities:["text"],apiType:"chat",pricing:{input:15,output:60,cached:7.5},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:L,deprecated:!1,description:"Original full reasoning model, very capable"},{id:"gpt-5-pro",displayName:"GPT-5 Pro",family:"gpt-5",tier:"premium",capabilityRank:7,modalities:["text"],apiType:"chat",pricing:{input:15,output:120},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:32768,parameters:K,deprecated:!1,description:"Enhanced GPT-5 for demanding tasks"},{id:"gpt-5.2-pro",displayName:"GPT-5.2 Pro",family:"gpt-5",tier:"premium",capabilityRank:8,modalities:["text"],apiType:"chat",pricing:{input:21,output:168},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:32768,parameters:K,deprecated:!1,description:"Most capable standard model available"},{id:"o3-pro",displayName:"o3 Pro",family:"o3",tier:"premium",capabilityRank:9,modalities:["text"],apiType:"chat",pricing:{input:20,output:80},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:We,deprecated:!1,description:"Premium o3 with extended thinking time"},{id:"o1-pro",displayName:"o1 Pro",family:"o1",tier:"premium",capabilityRank:10,modalities:["text"],apiType:"chat",pricing:{input:150,output:600},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:We,deprecated:!1,description:"Most capable reasoning model, extended compute"},{id:"o3-deep-research",displayName:"o3 Deep Research",family:"o3",tier:"specialized",capabilityRank:8,modalities:["text"],apiType:"responses",pricing:{input:10,output:40,cached:2.5},contextWindow:2e5,defaultMaxOutput:32768,maxOutputTokens:1e5,parameters:{...L,supportsStreaming:!1},deprecated:!1,description:"Extended research sessions with web access"},{id:"o4-mini-deep-research",displayName:"o4 Mini Deep Research",family:"o4",tier:"specialized",capabilityRank:6,modalities:["text"],apiType:"responses",pricing:{input:2,output:8,cached:.5},contextWindow:128e3,defaultMaxOutput:16384,maxOutputTokens:65536,parameters:{...L,supportsStreaming:!1},deprecated:!1,description:"Affordable deep research with o4 mini"},{id:"computer-use-preview",displayName:"Computer Use Preview",family:"computer-use",tier:"specialized",capabilityRank:5,modalities:["text","vision"],apiType:"responses",pricing:{input:3,output:12},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:16384,parameters:{...I,supportsReasoningEffort:!1},deprecated:!1,description:"Can control computer interfaces via screenshots"},{id:"gpt-realtime",displayName:"GPT Realtime",family:"gpt-realtime",tier:"specialized",capabilityRank:7,modalities:["text","audio","realtime"],apiType:"chat",pricing:{input:4,output:16,cached:.4},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:4096,parameters:{...I,supportsReasoningEffort:!1},deprecated:!1,description:"Real-time audio conversation model"},{id:"gpt-realtime-mini",displayName:"GPT Realtime Mini",family:"gpt-realtime",tier:"specialized",capabilityRank:4,modalities:["text","audio","realtime"],apiType:"chat",pricing:{input:.6,output:2.4,cached:.06},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:4096,parameters:{...I,supportsReasoningEffort:!1},deprecated:!1,description:"Affordable real-time audio model"},{id:"gpt-4o-2024-05-13",displayName:"GPT-4o (May 2024)",family:"gpt-4o",tier:"standard",capabilityRank:4,modalities:["text","vision"],apiType:"chat",pricing:{input:5,output:15},contextWindow:128e3,defaultMaxOutput:4096,maxOutputTokens:4096,parameters:I,deprecated:!0,description:"Original GPT-4o snapshot, use gpt-4o instead"}],be=new Map(U.map(e=>[e.id,e]));function Pe(e){let t=be.get(e);if(!t)throw new Error(`Unknown model: ${e}. Use getAvailableModelIds() to see valid options.`);return t}function Dt(e){return be.get(e)}function It(e){return be.has(e)}function Ut(){return U.map(e=>e.id)}function Bt(e){return U.filter(t=>t.tier===e&&!t.deprecated).sort((t,n)=>t.capabilityRank-n.capabilityRank)}function $t(e){return U.filter(t=>t.family===e).sort((t,n)=>t.capabilityRank-n.capabilityRank)}function Lt(){let e={fast:1,standard:2,reasoning:3,premium:4,specialized:5};return U.filter(t=>!t.deprecated).sort((t,n)=>{let r=e[t.tier]-e[n.tier];return r!==0?r:t.capabilityRank-n.capabilityRank})}function qt(){return U.filter(e=>!e.deprecated&&e.modalities.includes("text")&&!e.modalities.includes("realtime")&&e.apiType!=="responses").sort((e,t)=>{let n={fast:1,standard:2,reasoning:3,premium:4,specialized:5},r=n[e.tier]-n[t.tier];return r!==0?r:e.capabilityRank-t.capabilityRank})}function Ft(e="fast"){let t={fast:1,standard:2,reasoning:3,premium:4,specialized:5},n=t[e];return U.filter(o=>!o.deprecated&&t[o.tier]>=n).sort((o,s)=>o.pricing.input-s.pricing.input)[0]}function Ht(e,t,n,r=!1){let o=Pe(e),s=r&&o.pricing.cached?t/1e6*o.pricing.cached:t/1e6*o.pricing.input,p=n/1e6*o.pricing.output;return s+p}function Wt(e){let t=Pe(e);return`$${t.pricing.input.toFixed(2)} in / $${t.pricing.output.toFixed(2)} out per 1M tokens`}var Te=Object.fromEntries(U.map(e=>[e.id,{input:e.pricing.input,output:e.pricing.output,cached:e.pricing.cached,maxTokens:e.defaultMaxOutput,tier:e.tier}]));var de=null;async function jt(){if(de)return de;try{return de=await import("tiktoken"),de}catch{throw new Error('Token pricing requires the "tiktoken" package. Install with: npm install tiktoken')}}var B=Te,j="gpt-4o-mini";async function zt(e){let t=await jt();try{return t.encoding_for_model(e)}catch{return t.get_encoding("cl100k_base")}}async function Se(e,t=j){let n=await zt(t);try{return n.encode(e).length}finally{n.free()}}function Ke(e,t,n,r){let o=JSON.stringify({model:t,rate:n,tokens:r});return Kt("sha256").update(e+o).digest("hex").slice(0,16)}function Gt(e={}){let t=e.model??j,n=B[t],r={input:e.inputRate??n?.input??B[j].input,output:e.outputRate??n?.output??B[j].output,maxTokens:e.maxTokens??n?.maxTokens??4096,tier:e.tier??n?.tier??"custom"},o=e.tokenizer,s={model:t,inputRate:r.input,outputRate:r.output,maxTokens:r.maxTokens,tier:r.tier,tokenizer:o??(a=>Se(a,t)),minUsd:e.minUsd??.001,maxUsd:e.maxUsd??50,decimals:e.decimals??6},{minUsd:p,maxUsd:y,decimals:g}=s;async function m(a){return o?o(a):Se(a,t)}async function b(a,h){let l=h?`${h}
|
|
285
285
|
|
|
286
|
-
${
|
|
286
|
+
${a}`:a,x=await m(l),P=x/1e6*r.input;P=Math.max(P,p),P=Math.min(P,y);let k=Math.pow(10,g),A=Math.floor(P*k).toString(),S=Ke(a,t,r.input,x);return{amountAtomic:A,usdAmount:P,inputTokens:x,model:t,tier:r.tier,inputRatePerMillion:r.input,outputRatePerMillion:r.output,maxOutputTokens:r.maxTokens,quoteHash:S}}async function c(a,h){if(!h)return!1;let l=await m(a);return Ke(a,t,r.input,l)===h}return{calculate:b,validateQuote:c,countTokens:m,config:s,modelInfo:r}}function Vt(){return Object.entries(B).map(([e,t])=>({model:e,inputRate:t.input,outputRate:t.output,maxTokens:t.maxTokens,tier:t.tier})).sort((e,t)=>{let n={fast:0,standard:1,reasoning:2,premium:3},r=n[e.tier]-n[t.tier];return r!==0?r:e.inputRate-t.inputRate})}function Xt(e){return e in B}function Jt(e=j){let t=B[e]??B[j],n=B[e]?e:j;return`$${t.input.toFixed(2)} per 1M tokens (${n})`}import{SPONSORED_ACCESS_EXTENSION_KEY as Tn}from"@dexterai/x402-ads-types";export{z as BASE_MAINNET_NETWORK,$ as DEXTER_FACILITATOR_URL,Q as FacilitatorClient,B as MODEL_PRICING,Te as MODEL_PRICING_MAP,U as MODEL_REGISTRY,H as SOLANA_MAINNET_NETWORK,Tn as SPONSORED_ACCESS_EXTENSION_KEY,fe as USDC_BASE,G as USDC_MINT,yt as bazaarExtension,Se as countTokens,Ot as createDynamicPricing,Gt as createTokenPricing,Y as createX402Server,gt as declareDiscoveryExtension,D as escapeHtml,Ht as estimateCost,Dt as findModel,Wt as formatModelPricing,Nt as formatPricing,Jt as formatTokenPricing,Lt as getActiveModels,Ut as getAvailableModelIds,Vt as getAvailableModels,Ft as getCheapestModel,Pe as getModel,$t as getModelsByFamily,Bt as getModelsByTier,qt as getTextModels,Xt as isValidModel,It as isValidModelId,Ce as resolveDefaultAsset,Ye as stripePayTo,vt as x402AccessPass,Rt as x402BrowserSupport,ut as x402Middleware};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dexterai/x402",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.1",
|
|
4
4
|
"description": "Full-stack x402 SDK - add paid API monetization to any endpoint. Express middleware, React hooks, Access Pass, dynamic pricing. Solana, Base, Polygon, Arbitrum, Optimism, Avalanche, SKALE.",
|
|
5
5
|
"author": "Dexter",
|
|
6
6
|
"license": "MIT",
|