@three-ws/x402-modal 0.2.0 → 0.2.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/CHANGELOG.md +24 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +38 -180
- package/README.md +541 -175
- package/TUTORIAL.md +1 -1
- package/dist/x402-modal.mjs +12 -9
- package/dist/x402-modal.mjs.map +2 -2
- package/dist/x402.global.js +10 -9
- package/dist/x402.global.js.map +2 -2
- package/docs/BACKEND.md +2 -1
- package/docs/CONFIGURATION.md +20 -6
- package/docs/EXAMPLES.md +279 -0
- package/examples/index.html +119 -0
- package/examples/server.mjs +144 -0
- package/package.json +11 -9
- package/src/x402-modal.js +20 -15
- package/types/index.d.ts +7 -3
package/TUTORIAL.md
CHANGED
|
@@ -278,4 +278,4 @@ reservation back so it doesn't count against the budget.
|
|
|
278
278
|
| **`pay()` rejected but nothing went wrong** | The user closed the modal: the rejection's `.code === 'cancelled'`. Treat it as a no-op, not an error. |
|
|
279
279
|
|
|
280
280
|
Still stuck? Open an issue at
|
|
281
|
-
<https://github.com/nirholas/
|
|
281
|
+
<https://github.com/nirholas/x402-modal/issues>.
|
package/dist/x402-modal.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/*! @three-ws/x402-modal v0.2.1 — UNLICENSED — https://github.com/nirholas/x402-modal#readme */
|
|
2
|
+
|
|
1
3
|
// src/util.js
|
|
2
4
|
var EVM_NETWORKS = {
|
|
3
5
|
"eip155:8453": { chainId: 8453, name: "Base", explorer: "https://basescan.org/tx/" },
|
|
@@ -125,12 +127,13 @@ var DEFAULTS = {
|
|
|
125
127
|
// payment path uses these — the EVM/EIP-3009 path is fully client-side and
|
|
126
128
|
// needs no backend. `null` ⇒ resolve from the script's own origin at runtime.
|
|
127
129
|
apiOrigin: null,
|
|
128
|
-
// Footer attribution shown at the bottom of the modal.
|
|
129
|
-
|
|
130
|
+
// Footer attribution shown at the bottom of the modal. `null` ⇒ the footer
|
|
131
|
+
// link is hidden until a host sets `{ label, href? }`.
|
|
132
|
+
brand: null,
|
|
130
133
|
// ERC-8021 builder-code self-attribution echoed back when the 402 challenge
|
|
131
134
|
// declares a builder code. `wallet` = your wallet code, `service` = your
|
|
132
|
-
// integration code.
|
|
133
|
-
builderCode:
|
|
135
|
+
// integration code. `null` ⇒ no self-attribution unless a host opts in.
|
|
136
|
+
builderCode: null,
|
|
134
137
|
// CDN modules dynamic-imported on demand. Override to self-host / satisfy a
|
|
135
138
|
// strict Content-Security-Policy.
|
|
136
139
|
solanaWeb3Url: "https://esm.sh/@solana/web3.js@1.95.3?bundle",
|
|
@@ -138,7 +141,7 @@ var DEFAULTS = {
|
|
|
138
141
|
};
|
|
139
142
|
var config = {
|
|
140
143
|
apiOrigin: DEFAULTS.apiOrigin,
|
|
141
|
-
brand: { ...DEFAULTS.brand },
|
|
144
|
+
brand: DEFAULTS.brand ? { ...DEFAULTS.brand } : null,
|
|
142
145
|
builderCode: DEFAULTS.builderCode ? { ...DEFAULTS.builderCode } : null,
|
|
143
146
|
solanaWeb3Url: DEFAULTS.solanaWeb3Url,
|
|
144
147
|
nobleHashesUrl: DEFAULTS.nobleHashesUrl
|
|
@@ -158,7 +161,8 @@ function resolveScriptOrigin() {
|
|
|
158
161
|
function configure(opts = {}) {
|
|
159
162
|
if (!opts || typeof opts !== "object") return getConfig();
|
|
160
163
|
if (opts.apiOrigin !== void 0) config.apiOrigin = opts.apiOrigin;
|
|
161
|
-
if (opts.brand) config.brand =
|
|
164
|
+
if (opts.brand === null) config.brand = null;
|
|
165
|
+
else if (opts.brand) config.brand = { ...config.brand || {}, ...opts.brand };
|
|
162
166
|
if (opts.builderCode === null) config.builderCode = null;
|
|
163
167
|
else if (opts.builderCode) config.builderCode = { ...config.builderCode || {}, ...opts.builderCode };
|
|
164
168
|
if (opts.solanaWeb3Url) config.solanaWeb3Url = opts.solanaWeb3Url;
|
|
@@ -168,7 +172,7 @@ function configure(opts = {}) {
|
|
|
168
172
|
function getConfig() {
|
|
169
173
|
return {
|
|
170
174
|
apiOrigin: config.apiOrigin,
|
|
171
|
-
brand: { ...config.brand },
|
|
175
|
+
brand: config.brand ? { ...config.brand } : null,
|
|
172
176
|
builderCode: config.builderCode ? { ...config.builderCode } : null,
|
|
173
177
|
solanaWeb3Url: config.solanaWeb3Url,
|
|
174
178
|
nobleHashesUrl: config.nobleHashesUrl
|
|
@@ -827,8 +831,7 @@ var CheckoutModal = class {
|
|
|
827
831
|
this.siwxFallbackNotice = null;
|
|
828
832
|
const solana = challenge.accepts.find((a) => isSolanaNetwork(a.network));
|
|
829
833
|
const evm = challenge.accepts.find(isEip3009Accept);
|
|
830
|
-
|
|
831
|
-
this.accept = phantomDetected && solana || evm || challenge.accepts[0];
|
|
834
|
+
this.accept = solana || evm || challenge.accepts[0];
|
|
832
835
|
this.setPrice(this.accept);
|
|
833
836
|
this.renderConnect();
|
|
834
837
|
} catch (err) {
|
package/dist/x402-modal.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/util.js", "../src/x402-modal.js"],
|
|
4
|
-
"sourcesContent": ["// Pure, browser-API-free helpers shared by the modal. Kept in their own module\n// so they can be unit-tested in Node without a DOM, and so the core stays lean.\n\n// USDC EIP-3009 typed-data sig works against Base USDC. The domain `version`\n// must match the on-chain `EIP712_DOMAIN_SEPARATOR_VERSION` \u2014 Base USDC is \"2\".\nexport const EVM_NETWORKS = {\n\t'eip155:8453': { chainId: 8453, name: 'Base', explorer: 'https://basescan.org/tx/' },\n\t'eip155:84532': { chainId: 84532, name: 'Base Sepolia', explorer: 'https://sepolia.basescan.org/tx/' },\n\t'eip155:42161': { chainId: 42161, name: 'Arbitrum', explorer: 'https://arbiscan.io/tx/' },\n\t'eip155:10': { chainId: 10, name: 'Optimism', explorer: 'https://optimistic.etherscan.io/tx/' },\n};\n\n// Stablecoins whose atomics are already 6-decimal USD-pegged (used by caps).\nexport const STABLE_NAMES = new Set([\n\t'usdc', 'usd coin', 'usdt', 'tether', 'binance-peg usd coin', 'dai',\n]);\n\n// Normalize a single 402 `accept` entry. The x402 spec's canonical atomic-price\n// field is `maxAmountRequired`; some merchants emit `amount`. We read `amount`\n// everywhere downstream, so coerce here once. Without this a spec-compliant\n// merchant yields `accept.amount === undefined` \u2192 \"NaN USDC\".\nexport function normalizeAccept(accept) {\n\tif (!accept || typeof accept !== 'object') return accept;\n\tconst amount = accept.amount ?? accept.maxAmountRequired;\n\treturn amount != null && accept.amount == null ? { ...accept, amount: String(amount) } : accept;\n}\n\nexport function isSolanaNetwork(net) {\n\treturn typeof net === 'string' && (net === 'solana' || net.startsWith('solana:'));\n}\nexport function isEvmNetwork(net) {\n\treturn typeof net === 'string' && net.startsWith('eip155:');\n}\n// The modal only signs EIP-3009 transferWithAuthorization for EVM. When the\n// server publishes both an EIP-3009 entry and a Permit2 sibling (the\n// gas-sponsoring path), pick the EIP-3009 one \u2014 the sibling carries\n// `extra.assetTransferMethod === 'permit2'`.\nexport function isEip3009Accept(accept) {\n\tif (!isEvmNetwork(accept?.network)) return false;\n\tconst method = accept?.extra?.assetTransferMethod;\n\treturn !method || method === 'eip3009';\n}\nexport function networkLabel(net, accept) {\n\tif (isSolanaNetwork(net)) return 'Solana';\n\tconst meta = EVM_NETWORKS[net];\n\treturn meta?.name || accept?.extra?.name || net;\n}\nexport function explorerUrl(net, tx) {\n\tif (!tx) return null;\n\tif (isSolanaNetwork(net)) return `https://solscan.io/tx/${tx}`;\n\tconst meta = EVM_NETWORKS[net];\n\treturn meta ? `${meta.explorer}${tx}` : null;\n}\n\nexport function formatAmount(rawAtomics, decimals = 6) {\n\tconst n = Number(rawAtomics) / 10 ** decimals;\n\tif (n < 0.01) return n.toFixed(6).replace(/0+$/, '').replace(/\\.$/, '');\n\tif (n < 1) return n.toFixed(4).replace(/0+$/, '').replace(/\\.$/, '');\n\treturn n.toFixed(2);\n}\n\nexport function b64encode(obj) {\n\tconst json = JSON.stringify(obj);\n\tif (typeof Buffer !== 'undefined') return Buffer.from(json, 'utf8').toString('base64');\n\treturn btoa(unescape(encodeURIComponent(json)));\n}\nexport function b64decode(str) {\n\tif (!str) return null;\n\ttry {\n\t\tconst bin = typeof Buffer !== 'undefined' ? Buffer.from(str, 'base64').toString('utf8') : decodeURIComponent(escape(atob(str)));\n\t\treturn JSON.parse(bin);\n\t} catch (_) {\n\t\treturn null;\n\t}\n}\n\n// Base58 (Bitcoin alphabet) \u2014 Solana's encoding for addresses and signatures.\nconst BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';\nexport function base58encode(bytes) {\n\tif (!bytes || bytes.length === 0) return '';\n\tlet leadingZeros = 0;\n\twhile (leadingZeros < bytes.length && bytes[leadingZeros] === 0) leadingZeros++;\n\tlet n = 0n;\n\tfor (let i = 0; i < bytes.length; i++) n = (n << 8n) | BigInt(bytes[i]);\n\tlet out = '';\n\twhile (n > 0n) {\n\t\tout = BASE58_ALPHABET[Number(n % 58n)] + out;\n\t\tn /= 58n;\n\t}\n\tfor (let i = 0; i < leadingZeros; i++) out = BASE58_ALPHABET[0] + out;\n\treturn out;\n}\n\n// Convert an asset's atomic amount to micro-USD for cap accounting. Stablecoins\n// pass through (scaled to 6 decimals); non-stable assets pass through atomic and\n// must be capped server-side (the browser modal fetches no prices).\nexport function toMicroUsd(amount, accept) {\n\tconst atomic = BigInt(amount);\n\tconst decimals = Number(accept?.extra?.decimals ?? 6);\n\tconst name = String(accept?.extra?.name || '').toLowerCase();\n\tif (STABLE_NAMES.has(name)) {\n\t\tif (decimals === 6) return atomic;\n\t\tif (decimals > 6) return atomic / 10n ** BigInt(decimals - 6);\n\t\treturn atomic * 10n ** BigInt(6 - decimals);\n\t}\n\treturn atomic;\n}\n\nexport function spendBuckets(timestamp = Date.now()) {\n\tconst hour = Math.floor(timestamp / 3_600_000);\n\tconst day = Math.floor(timestamp / 86_400_000);\n\treturn { hour, day };\n}\n\n// Build the CAIP-122 SIWX message string. The server rebuilds the same string\n// from payload fields when verifying \u2014 any line-by-line drift makes the\n// recovered signer mismatch payload.address and the signature is rejected.\nexport function buildSiwxMessage(info, chain, address) {\n\tconst isEvm = chain.type === 'eip191';\n\tconst accountHeader = isEvm\n\t\t? `${info.domain} wants you to sign in with your Ethereum account:`\n\t\t: `${info.domain} wants you to sign in with your Solana account:`;\n\tconst [, chainTail = ''] = String(chain.chainId).split(':');\n\tconst chainRef = isEvm ? String(parseInt(chainTail, 10)) : chainTail;\n\n\tconst lines = [accountHeader, address, ''];\n\tif (info.statement) {\n\t\tlines.push(info.statement, '');\n\t} else if (isEvm) {\n\t\t// siwe's prepareMessage() reserves the statement block even when absent,\n\t\t// emitting an extra blank line. SIWS does not.\n\t\tlines.push('');\n\t}\n\tlines.push(`URI: ${info.uri}`);\n\tlines.push(`Version: ${info.version || '1'}`);\n\tlines.push(`Chain ID: ${chainRef}`);\n\tlines.push(`Nonce: ${info.nonce}`);\n\tlines.push(`Issued At: ${info.issuedAt}`);\n\tif (info.expirationTime) lines.push(`Expiration Time: ${info.expirationTime}`);\n\tif (info.notBefore) lines.push(`Not Before: ${info.notBefore}`);\n\tif (info.requestId !== undefined && info.requestId !== null) lines.push(`Request ID: ${info.requestId}`);\n\tif (Array.isArray(info.resources) && info.resources.length) {\n\t\tlines.push('Resources:');\n\t\tfor (const r of info.resources) lines.push(`- ${r}`);\n\t}\n\treturn lines.join('\\n');\n}\n", "// @three-ws/x402-modal \u2014 a drop-in payment modal for any x402 paid endpoint.\n//\n// This is the canonical, side-effect-free core. It exports the public API\n// (`pay`, `init`, `configure`, `getConfig`, `version`, `CheckoutModal`, and the\n// declarative helpers `bindElement` / `readOptsFrom`) but does NOT touch\n// `window` or auto-bind anything on import \u2014 that lives in `global.js`, which is\n// what the CDN <script> build ships.\n//\n// Bundler / npm usage:\n//\n// import { pay, configure } from '@three-ws/x402-modal';\n// const out = await pay({ endpoint: '/api/paid/summarize', body: { text: 'hi' } });\n//\n// Drop-in <script> usage (the global build auto-binds `data-x402-endpoint`):\n//\n// <script type=\"module\" src=\"https://unpkg.com/@three-ws/x402-modal/global\"></script>\n// <button data-x402-endpoint=\"/api/paid/summarize\" data-x402-method=\"POST\">Pay & run</button>\n//\n// The modal drives the full 402 \u2192 connect wallet \u2192 sign \u2192 retry \u2192 settle flow,\n// renders price/network/steps/receipt, and resolves with { ok, result, payment,\n// response }. Vanilla JS; the only network deps (Solana web3.js, a keccak for\n// EVM SIWX) are dynamic-imported from a CDN, and only when that path runs.\n\nimport {\n\tEVM_NETWORKS,\n\tnormalizeAccept,\n\tisSolanaNetwork,\n\tisEip3009Accept,\n\tnetworkLabel,\n\texplorerUrl,\n\tformatAmount,\n\tb64encode,\n\tb64decode,\n\tbase58encode,\n\ttoMicroUsd,\n\tspendBuckets,\n\tbuildSiwxMessage,\n} from './util.js';\n\nconst VERSION = '0.2.0';\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 configuration \u2500\u2500\u2500\n// Everything the host wants to brand or repoint lives here. Defaults reproduce\n// three.ws's hosted behaviour exactly, so the drop-in script is unchanged; a\n// standalone deployment overrides them with `configure()` (global) or per-call\n// `pay({ ... })` options (which always win over the global config).\n\nconst DEFAULTS = {\n\t// Origin that serves the Solana `prepare` / `encode` checkout helpers\n\t// (POST {origin}/api/x402-checkout?action=prepare|encode). Only the Solana\n\t// payment path uses these \u2014 the EVM/EIP-3009 path is fully client-side and\n\t// needs no backend. `null` \u21D2 resolve from the script's own origin at runtime.\n\tapiOrigin: null,\n\t// Footer attribution shown at the bottom of the modal.\n\tbrand: { label: 'Powered by three.ws', href: 'https://three.ws' },\n\t// ERC-8021 builder-code self-attribution echoed back when the 402 challenge\n\t// declares a builder code. `wallet` = your wallet code, `service` = your\n\t// integration code. Set to null to disable the echo entirely.\n\tbuilderCode: { wallet: '3d_agent', service: '3d_agent_modal' },\n\t// CDN modules dynamic-imported on demand. Override to self-host / satisfy a\n\t// strict Content-Security-Policy.\n\tsolanaWeb3Url: 'https://esm.sh/@solana/web3.js@1.95.3?bundle',\n\tnobleHashesUrl: 'https://esm.sh/@noble/hashes@1.4.0/sha3?bundle',\n};\n\nconst config = {\n\tapiOrigin: DEFAULTS.apiOrigin,\n\tbrand: { ...DEFAULTS.brand },\n\tbuilderCode: DEFAULTS.builderCode ? { ...DEFAULTS.builderCode } : null,\n\tsolanaWeb3Url: DEFAULTS.solanaWeb3Url,\n\tnobleHashesUrl: DEFAULTS.nobleHashesUrl,\n};\n\n// Resolve the origin that hosts this script \u2014 used as the default API origin for\n// the Solana prepare/encode helpers. Falls back to the page origin.\nfunction resolveScriptOrigin() {\n\ttry {\n\t\tif (typeof document !== 'undefined') {\n\t\t\tconst current = document.currentScript;\n\t\t\tif (current?.src) return new URL(current.src).origin;\n\t\t\tconst found = document.querySelector('script[src*=\"x402\"]');\n\t\t\tif (found?.src) return new URL(found.src).origin;\n\t\t}\n\t} catch (_) {}\n\treturn typeof location !== 'undefined' ? location.origin : '';\n}\n\n// Merge user config in. `apiOrigin: ''` is honoured (same-origin); only\n// `undefined` keeps the default. Returns the resolved snapshot for inspection.\nexport function configure(opts = {}) {\n\tif (!opts || typeof opts !== 'object') return getConfig();\n\tif (opts.apiOrigin !== undefined) config.apiOrigin = opts.apiOrigin;\n\tif (opts.brand) config.brand = { ...config.brand, ...opts.brand };\n\tif (opts.builderCode === null) config.builderCode = null;\n\telse if (opts.builderCode) config.builderCode = { ...(config.builderCode || {}), ...opts.builderCode };\n\tif (opts.solanaWeb3Url) config.solanaWeb3Url = opts.solanaWeb3Url;\n\tif (opts.nobleHashesUrl) config.nobleHashesUrl = opts.nobleHashesUrl;\n\treturn getConfig();\n}\n\nexport function getConfig() {\n\treturn {\n\t\tapiOrigin: config.apiOrigin,\n\t\tbrand: { ...config.brand },\n\t\tbuilderCode: config.builderCode ? { ...config.builderCode } : null,\n\t\tsolanaWeb3Url: config.solanaWeb3Url,\n\t\tnobleHashesUrl: config.nobleHashesUrl,\n\t};\n}\n\n// The effective API origin for a given pay() call: explicit per-call > global\n// config > lazily-resolved script origin (cached back into config).\nfunction apiOriginFor(opts) {\n\tif (opts && opts.apiOrigin !== undefined && opts.apiOrigin !== null) return opts.apiOrigin;\n\tif (config.apiOrigin !== null && config.apiOrigin !== undefined) return config.apiOrigin;\n\tconfig.apiOrigin = resolveScriptOrigin();\n\treturn config.apiOrigin;\n}\n\n// SIWX (\"Sign-In-With-X\" / CAIP-122) lets a wallet that has already paid for\n// an endpoint re-enter it by signing a challenge instead of paying again. The\n// server advertises support by including `extensions['sign-in-with-x']` in the\n// 402 body; clients submit signed proofs via the `SIGN-IN-WITH-X` header.\nconst SIWX_HEADER = 'SIGN-IN-WITH-X';\nconst SIWX_EXTENSION_KEY = 'sign-in-with-x';\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Spending caps \u2500\u2500\u2500\u2500\u2500\n// Persists per-wallet spend in localStorage so reload-survivable caps work in a\n// pure-browser context. Keys are bucketed by UTC hour and UTC day so the\n// sliding windows reset cleanly at midnight UTC for the daily case. Amounts are\n// stored as base-10 BigInt strings of micro-USD; stablecoin payments flow\n// through as-is since their atomics are already 6-decimal USD-pegged.\n\nconst SPEND_LS_PREFIX = 'x402.spend.';\n\nfunction spendKey(address, kind, bucket) {\n\treturn `${SPEND_LS_PREFIX}${kind}.${address.toLowerCase()}.${bucket}`;\n}\n\nfunction readSpend(address, kind, bucket) {\n\ttry {\n\t\tconst raw = localStorage.getItem(spendKey(address, kind, bucket));\n\t\tif (!raw) return 0n;\n\t\treturn BigInt(raw);\n\t} catch {\n\t\treturn 0n;\n\t}\n}\n\nfunction writeSpend(address, kind, bucket, value) {\n\ttry {\n\t\tlocalStorage.setItem(spendKey(address, kind, bucket), value.toString());\n\t} catch {\n\t\t// localStorage full / disabled \u2014 caps degrade to per-call only.\n\t}\n}\n\n// Check the configured caps and, if admitted, reserve the spend in localStorage.\n// Returns { abort, reason?, reservation? }. Reservation carries { address,\n// microUsd, buckets } so a failed payment can roll the reservation back.\nfunction browserEnforceCap({ accept, caps, address }) {\n\tif (!caps || !address) return { abort: false };\n\tconst microUsd = toMicroUsd(accept.amount, accept);\n\tconst maxPerCall = caps.maxPerCall != null ? BigInt(caps.maxPerCall) : null;\n\tconst maxPerHour = caps.maxPerHour != null ? BigInt(caps.maxPerHour) : null;\n\tconst maxPerDay = caps.maxPerDay != null ? BigInt(caps.maxPerDay) : null;\n\tif (maxPerCall != null && microUsd > maxPerCall) {\n\t\treturn { abort: true, reason: `Per-call cap exceeded (${microUsd} > ${maxPerCall} \u00B5USD)` };\n\t}\n\tconst buckets = spendBuckets();\n\tconst hourTotal = readSpend(address, 'hr', buckets.hour) + microUsd;\n\tconst dayTotal = readSpend(address, 'day', buckets.day) + microUsd;\n\tif (maxPerHour != null && hourTotal > maxPerHour) {\n\t\treturn { abort: true, reason: `Hourly cap exceeded (${hourTotal} > ${maxPerHour} \u00B5USD)` };\n\t}\n\tif (maxPerDay != null && dayTotal > maxPerDay) {\n\t\treturn { abort: true, reason: `Daily cap exceeded (${dayTotal} > ${maxPerDay} \u00B5USD)` };\n\t}\n\twriteSpend(address, 'hr', buckets.hour, hourTotal);\n\twriteSpend(address, 'day', buckets.day, dayTotal);\n\treturn { abort: false, reservation: { address, microUsd, buckets } };\n}\n\nfunction browserRollbackReservation(reservation) {\n\tif (!reservation) return;\n\tconst { address, microUsd, buckets } = reservation;\n\tconst hourCurrent = readSpend(address, 'hr', buckets.hour);\n\tconst dayCurrent = readSpend(address, 'day', buckets.day);\n\tconst hourNext = hourCurrent - microUsd;\n\tconst dayNext = dayCurrent - microUsd;\n\twriteSpend(address, 'hr', buckets.hour, hourNext < 0n ? 0n : hourNext);\n\twriteSpend(address, 'day', buckets.day, dayNext < 0n ? 0n : dayNext);\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 ERC-8021 builder-code echo \u2500\u2500\u2500\u2500\n// The server enforces that any client-echoed builder-code `a` matches what the\n// 402 challenge declared (anti-tamper). We self-attribute `w` (wallet) and `s`\n// (service) from config; both are validated against the strict code pattern.\n\nconst BUILDER_CODE_KEY = 'builder-code';\nconst BUILDER_CODE_PATTERN = /^[a-z0-9_]{1,32}$/;\n\nfunction buildBuilderCodeEcho(challenge) {\n\tconst codes = config.builderCode;\n\tif (!codes) return null;\n\tconst ext = challenge?.extensions?.[BUILDER_CODE_KEY];\n\tconst declaredA = ext?.info?.a;\n\tif (!declaredA || !BUILDER_CODE_PATTERN.test(declaredA)) return null;\n\tconst out = { a: declaredA };\n\tif (codes.service && BUILDER_CODE_PATTERN.test(codes.service)) out.s = [codes.service];\n\tif (codes.wallet && BUILDER_CODE_PATTERN.test(codes.wallet)) out.w = codes.wallet;\n\treturn out;\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 SIWX helpers \u2500\u2500\u2500\u2500\n\nfunction extractSiwxExtension(body) {\n\tconst ext = body?.extensions?.[SIWX_EXTENSION_KEY];\n\tif (!ext || !ext.info || !Array.isArray(ext.supportedChains) || !ext.supportedChains.length) return null;\n\treturn ext;\n}\n\n// Returns { chain, kind: 'evm' | 'solana' } or null. `chain` is the matching\n// entry from `ext.supportedChains` whose signature type matches the wallet kind.\nfunction pickSiwxChain(ext, walletKind) {\n\tfor (const chain of ext.supportedChains) {\n\t\tif (walletKind === 'evm' && chain.type === 'eip191') return { chain, kind: 'evm' };\n\t\tif (walletKind === 'solana' && chain.type === 'ed25519') return { chain, kind: 'solana' };\n\t}\n\treturn null;\n}\n\n// Base64-encoded JSON per x402 v2 spec. CAIP-122 fields are all ASCII/Latin-1,\n// so the unescape+encodeURIComponent dance matches what btoa expects.\nfunction encodeSiwxHeaderValue(payload) {\n\tconst json = JSON.stringify(payload);\n\tif (typeof Buffer !== 'undefined') return Buffer.from(json, 'utf8').toString('base64');\n\treturn btoa(unescape(encodeURIComponent(json)));\n}\n\n// EIP-55 checksum the address before signing. MetaMask returns lowercase\n// addresses, but the server rebuilds the SIWE message with a checksummed\n// address. If we sign a lowercase-address message and send the lowercase\n// address in the payload, the recovered signer differs and verification fails.\n// Keccak-256 is dynamic-imported from a CDN only when SIWX EVM sign-in runs.\nlet _evmChecksum = null;\nasync function loadEvmChecksum() {\n\tif (_evmChecksum) return _evmChecksum;\n\tconst sha3 = await import(/* @vite-ignore */ config.nobleHashesUrl);\n\tconst keccak = sha3.keccak_256;\n\t_evmChecksum = (addr) => {\n\t\tconst a = String(addr).toLowerCase().replace(/^0x/, '');\n\t\tif (!/^[0-9a-f]{40}$/.test(a)) throw new Error(`invalid EVM address: ${addr}`);\n\t\tconst hashBytes = keccak(new TextEncoder().encode(a));\n\t\tlet hex = '';\n\t\tfor (let i = 0; i < hashBytes.length; i++) hex += hashBytes[i].toString(16).padStart(2, '0');\n\t\tlet out = '0x';\n\t\tfor (let i = 0; i < 40; i++) {\n\t\t\tout += parseInt(hex[i], 16) >= 8 ? a[i].toUpperCase() : a[i];\n\t\t}\n\t\treturn out;\n\t};\n\treturn _evmChecksum;\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 styles \u2500\u2500\u2500\u2500\n\nconst STYLE_ID = 'x402-styles';\nconst STYLES = `\n:root {\n\t--x402-z: 2147483600;\n}\n.x402-overlay {\n\tposition: fixed; inset: 0;\n\tbackground: rgba(8, 10, 18, 0.55);\n\tbackdrop-filter: blur(10px);\n\t-webkit-backdrop-filter: blur(10px);\n\tdisplay: flex; align-items: center; justify-content: center;\n\tz-index: var(--x402-z);\n\topacity: 0; transition: opacity 0.16s ease-out;\n\tfont-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n\t-webkit-font-smoothing: antialiased;\n\tcolor: #0f0f0f;\n}\n.x402-overlay.x402-open { opacity: 1; }\n.x402-overlay * { box-sizing: border-box; }\n.x402-modal {\n\twidth: calc(100% - 32px); max-width: 420px;\n\tbackground: #ffffff;\n\tborder-radius: 18px;\n\tbox-shadow: 0 24px 80px rgba(8, 10, 18, 0.28), 0 4px 16px rgba(8, 10, 18, 0.12);\n\toverflow: hidden;\n\ttransform: translateY(8px) scale(0.985);\n\ttransition: transform 0.18s ease-out;\n\tdisplay: flex; flex-direction: column;\n\tmax-height: calc(100dvh - 32px);\n}\n.x402-overlay.x402-open .x402-modal { transform: translateY(0) scale(1); }\n.x402-head {\n\tpadding: 18px 20px 14px;\n\tborder-bottom: 1px solid #eef0f4;\n\tdisplay: flex; align-items: center; gap: 12px;\n}\n.x402-head .x402-merchant {\n\tflex: 1; min-width: 0;\n}\n.x402-merchant .x402-name {\n\tfont-size: 12px; color: #5a6378; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase;\n\tmargin-bottom: 2px;\n}\n.x402-merchant .x402-action {\n\tfont-size: 17px; font-weight: 700; color: #0f0f0f;\n\twhite-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n\tletter-spacing: -0.01em;\n}\n.x402-close {\n\twidth: 32px; height: 32px;\n\tborder-radius: 8px; border: none; background: #f3f4f7;\n\tfont-size: 16px; color: #5a6378; cursor: pointer;\n\tdisplay: flex; align-items: center; justify-content: center;\n\ttransition: background 0.12s;\n}\n.x402-close:hover { background: #e7e9ee; color: #0f0f0f; }\n\n.x402-price-row {\n\tpadding: 18px 20px;\n\tdisplay: flex; align-items: baseline; justify-content: space-between;\n\tbackground: linear-gradient(180deg, #fafbfc 0%, #ffffff 100%);\n\tborder-bottom: 1px solid #eef0f4;\n}\n.x402-price {\n\tfont-size: 32px; font-weight: 700; letter-spacing: -0.02em; color: #0f0f0f;\n\tfont-variant-numeric: tabular-nums;\n}\n.x402-price .x402-currency { font-size: 14px; color: #5a6378; font-weight: 600; margin-left: 6px; letter-spacing: 0; }\n.x402-network {\n\tfont-size: 12px; color: #5a6378; font-weight: 500;\n\tbackground: #f3f4f7; padding: 5px 10px; border-radius: 99px;\n\tdisplay: inline-flex; align-items: center; gap: 6px;\n}\n.x402-network::before {\n\tcontent: ''; width: 6px; height: 6px; border-radius: 50%;\n\tbackground: #22c55e;\n}\n\n.x402-body {\n\tpadding: 16px 20px 18px;\n\tflex: 1 1 auto; overflow-y: auto;\n\tdisplay: flex; flex-direction: column; gap: 10px;\n}\n.x402-step {\n\tdisplay: flex; gap: 12px; align-items: flex-start;\n\tpadding: 10px 0;\n}\n.x402-step + .x402-step { border-top: 1px solid #f3f4f7; }\n.x402-step-num {\n\twidth: 22px; height: 22px; flex: 0 0 auto;\n\tborder-radius: 50%; border: 1.5px solid #d0d4dd; background: #fff;\n\tcolor: #5a6378;\n\tfont-size: 11px; font-weight: 700;\n\tdisplay: flex; align-items: center; justify-content: center;\n}\n.x402-step.x402-active .x402-step-num {\n\tborder-color: #0a84ff; background: #0a84ff; color: #fff;\n\tanimation: x402-spin 1.2s linear infinite;\n}\n.x402-step.x402-done .x402-step-num {\n\tborder-color: #22c55e; background: #22c55e; color: #fff;\n}\n.x402-step.x402-error .x402-step-num {\n\tborder-color: #ef4444; background: #ef4444; color: #fff;\n}\n@keyframes x402-spin {\n\tfrom { box-shadow: 0 0 0 0 rgba(10, 132, 255, 0.4); }\n\tto { box-shadow: 0 0 0 8px rgba(10, 132, 255, 0); }\n}\n.x402-step-body { flex: 1; min-width: 0; }\n.x402-step-label { font-size: 14px; font-weight: 600; color: #0f0f0f; line-height: 1.35; }\n.x402-step-meta { font-size: 12px; color: #5a6378; margin-top: 2px; font-feature-settings: 'tnum' 1; }\n.x402-step.x402-error .x402-step-meta { color: #ef4444; }\n\n.x402-wallet-buttons {\n\tdisplay: flex; flex-direction: column; gap: 8px;\n\tmargin-top: 4px;\n}\n.x402-wallet-btn {\n\twidth: 100%; padding: 13px 14px;\n\tbackground: #ffffff; border: 1.5px solid #e2e5ec; border-radius: 11px;\n\tfont-size: 14px; font-weight: 600; color: #0f0f0f;\n\tcursor: pointer; font-family: inherit;\n\tdisplay: flex; align-items: center; gap: 12px;\n\ttransition: border-color 0.12s, background 0.12s, transform 0.05s;\n}\n.x402-wallet-btn:hover:not(:disabled) { border-color: #0a84ff; background: #f7faff; }\n.x402-wallet-btn:active:not(:disabled) { transform: translateY(1px); }\n.x402-wallet-btn:disabled { opacity: 0.45; cursor: not-allowed; }\n.x402-wallet-icon {\n\twidth: 28px; height: 28px; flex: 0 0 auto;\n\tborder-radius: 7px;\n\tdisplay: flex; align-items: center; justify-content: center;\n\tfont-size: 16px;\n\tbackground: #f3f4f7;\n}\n.x402-wallet-icon.x402-phantom { background: linear-gradient(135deg, #ab9ff2, #534bb1); color: #fff; }\n.x402-wallet-icon.x402-metamask { background: linear-gradient(135deg, #f6851b, #e2761b); color: #fff; }\n.x402-wallet-name { flex: 1; text-align: left; }\n.x402-wallet-meta { font-size: 11px; color: #8a90a8; font-weight: 500; }\n\n.x402-pay-btn {\n\twidth: 100%; padding: 14px 16px;\n\tbackground: #0f0f0f; color: #fff; border: none;\n\tborder-radius: 12px;\n\tfont-size: 15px; font-weight: 700; font-family: inherit;\n\tcursor: pointer; letter-spacing: -0.005em;\n\ttransition: background 0.12s, transform 0.05s;\n\tmargin-top: 4px;\n\tdisplay: flex; align-items: center; justify-content: center; gap: 8px;\n}\n.x402-pay-btn:hover:not(:disabled) { background: #1d1d1d; }\n.x402-pay-btn:active:not(:disabled) { transform: translateY(1px); }\n.x402-pay-btn:disabled { background: #c8ccd4; cursor: not-allowed; }\n\n.x402-pay-secondary {\n\twidth: 100%; padding: 12px 14px;\n\tbackground: #ffffff; color: #0f0f0f;\n\tborder: 1.5px solid #e2e5ec; border-radius: 11px;\n\tfont-size: 14px; font-weight: 600; font-family: inherit;\n\tcursor: pointer; letter-spacing: -0.005em;\n\tmargin-top: 6px;\n\ttransition: border-color 0.12s, background 0.12s, transform 0.05s;\n}\n.x402-pay-secondary:hover:not(:disabled) { border-color: #0a84ff; background: #f7faff; }\n.x402-pay-secondary:active:not(:disabled) { transform: translateY(1px); }\n\n.x402-siwx-hint {\n\tfont-size: 11px; color: #5a6378; text-align: center;\n\tmargin-top: 8px; line-height: 1.4;\n}\n.x402-siwx-fallback {\n\tfont-size: 12px; color: #b45309; line-height: 1.45;\n\tpadding: 8px 10px; border-radius: 8px;\n\tbackground: #fffbeb; border: 1px solid #fde68a;\n\tmargin-bottom: 6px;\n}\n\n.x402-error-box {\n\tpadding: 12px 14px; border-radius: 10px;\n\tbackground: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;\n\tfont-size: 13px; line-height: 1.45;\n\tfont-family: ui-monospace, \"JetBrains Mono\", Menlo, monospace;\n\tword-break: break-word;\n}\n.x402-error-box strong { font-weight: 700; }\n\n.x402-receipt {\n\tpadding: 14px 16px; border-radius: 12px;\n\tbackground: linear-gradient(180deg, #f0fdf4 0%, #ffffff 100%);\n\tborder: 1px solid #bbf7d0;\n}\n.x402-receipt-title {\n\tfont-size: 11px; font-weight: 700; color: #15803d;\n\ttext-transform: uppercase; letter-spacing: 0.06em;\n\tmargin-bottom: 8px;\n\tdisplay: flex; align-items: center; gap: 6px;\n}\n.x402-receipt-title::before { content: '\u2713'; font-size: 14px; }\n.x402-receipt-row {\n\tdisplay: flex; justify-content: space-between; gap: 12px;\n\tfont-size: 12px; padding: 2px 0;\n\tfont-family: ui-monospace, \"JetBrains Mono\", Menlo, monospace;\n}\n.x402-receipt-row .x402-k { color: #5a6378; }\n.x402-receipt-row .x402-v { color: #0f0f0f; text-align: right; word-break: break-all; }\n.x402-receipt-row a { color: #0a84ff; text-decoration: none; }\n.x402-receipt-row a:hover { text-decoration: underline; }\n\n.x402-result {\n\tpadding: 12px 14px; border-radius: 10px;\n\tbackground: #fafbfc; border: 1px solid #e2e5ec;\n\tmax-height: 240px; overflow: auto;\n\tfont-family: ui-monospace, \"JetBrains Mono\", Menlo, monospace;\n\tfont-size: 12px; line-height: 1.5; color: #0f0f0f;\n\twhite-space: pre-wrap; word-break: break-word;\n}\n\n.x402-foot {\n\tpadding: 10px 20px 14px;\n\tborder-top: 1px solid #eef0f4;\n\tdisplay: flex; align-items: center; justify-content: space-between;\n\tfont-size: 11px; color: #8a90a8;\n}\n.x402-foot a { color: #5a6378; text-decoration: none; font-weight: 600; }\n.x402-foot a:hover { color: #0f0f0f; }\n.x402-foot .x402-secure { display: flex; align-items: center; gap: 5px; }\n.x402-foot .x402-secure::before { content: '\uD83D\uDD12'; font-size: 10px; }\n\n@media (max-width: 480px) {\n\t.x402-modal { max-width: none; width: calc(100% - 16px); border-radius: 16px; }\n\t.x402-price { font-size: 26px; }\n}\n\n@media (prefers-color-scheme: dark) {\n\t.x402-overlay { color: #e6e8f0; }\n\t.x402-modal { background: #161616; box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6); }\n\t.x402-head, .x402-price-row, .x402-foot { border-color: #272727; }\n\t.x402-step + .x402-step { border-top-color: #272727; }\n\t.x402-merchant .x402-name { color: #8a90a8; }\n\t.x402-merchant .x402-action, .x402-price, .x402-step-label { color: #e6e8f0; }\n\t.x402-step-meta { color: #8a90a8; }\n\t.x402-close { background: #222222; color: #8a90a8; }\n\t.x402-close:hover { background: #2e2e2e; color: #e6e8f0; }\n\t.x402-price-row { background: linear-gradient(180deg, #1d1d1d 0%, #161616 100%); }\n\t.x402-network { background: #222222; color: #b0b6cc; }\n\t.x402-wallet-btn { background: #1d1d1d; border-color: #2e2e2e; color: #e6e8f0; }\n\t.x402-wallet-btn:hover:not(:disabled) { background: #252525; border-color: #0a84ff; }\n\t.x402-wallet-icon { background: #2e2e2e; }\n\t.x402-wallet-meta { color: #6b7088; }\n\t.x402-pay-btn { background: #ffffff; color: #0f0f0f; }\n\t.x402-pay-btn:hover:not(:disabled) { background: #e7e9ee; }\n\t.x402-pay-btn:disabled { background: #2e2e2e; color: #5a6378; }\n\t.x402-pay-secondary { background: #1d1d1d; border-color: #2e2e2e; color: #e6e8f0; }\n\t.x402-pay-secondary:hover:not(:disabled) { background: #252525; border-color: #0a84ff; }\n\t.x402-siwx-hint { color: #8a90a8; }\n\t.x402-siwx-fallback { background: #2a1d10; border-color: #78350f; color: #fcd34d; }\n\t.x402-step-num { background: #161616; border-color: #2e2e2e; color: #8a90a8; }\n\t.x402-result { background: #1d1d1d; border-color: #2e2e2e; color: #e6e8f0; }\n\t.x402-receipt { background: linear-gradient(180deg, #0b1f17 0%, #161616 100%); border-color: #14532d; }\n\t.x402-receipt-title { color: #4ade80; }\n\t.x402-receipt-row .x402-k { color: #8a90a8; }\n\t.x402-receipt-row .x402-v { color: #e6e8f0; }\n\t.x402-receipt-row a { color: #60a5fa; }\n\t.x402-error-box { background: #1f1416; border-color: #7f1d1d; color: #fca5a5; }\n\t.x402-foot a { color: #b0b6cc; }\n\t.x402-foot a:hover { color: #ffffff; }\n}\n`;\n\nfunction injectStyles() {\n\tif (typeof document === 'undefined' || document.getElementById(STYLE_ID)) return;\n\tconst el = document.createElement('style');\n\tel.id = STYLE_ID;\n\tel.textContent = STYLES;\n\tdocument.head.appendChild(el);\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 modal class \u2500\u2500\u2500\n\nexport class CheckoutModal {\n\tconstructor(opts) {\n\t\tthis.opts = opts;\n\t\tthis.steps = [\n\t\t\t{ id: 'discover', label: 'Confirming price' },\n\t\t\t{ id: 'connect', label: 'Connect wallet' },\n\t\t\t{ id: 'authorize', label: 'Authorize payment' },\n\t\t\t{ id: 'verify', label: 'Verify & complete' },\n\t\t];\n\t\tthis.activeNetwork = null;\n\t\tthis.payerAddress = null;\n\t\tthis.accept = null;\n\t\tthis.challenge = null;\n\t\tthis.disposed = false;\n\t\t// One-shot guard for opts.autoConnect: we only auto-open the wallet on the\n\t\t// first connect render, so an error that drops the user back to this step\n\t\t// shows the manual picker instead of re-launching the wallet in a loop.\n\t\tthis.autoConnectTried = false;\n\t}\n\n\t_apiOrigin() {\n\t\treturn apiOriginFor(this.opts);\n\t}\n\n\tmount() {\n\t\tinjectStyles();\n\t\tconst brand = this.opts.brand || config.brand || {};\n\t\tconst overlay = document.createElement('div');\n\t\toverlay.className = 'x402-overlay';\n\t\tconst brandHtml = brand.href\n\t\t\t? `<a href=\"${escapeHtml(brand.href)}\" target=\"_blank\" rel=\"noopener\">${escapeHtml(brand.label || brand.href)}</a>`\n\t\t\t: brand.label\n\t\t\t\t? `<span>${escapeHtml(brand.label)}</span>`\n\t\t\t\t: '';\n\t\toverlay.innerHTML = `\n\t\t\t<div class=\"x402-modal\" role=\"dialog\" aria-modal=\"true\" aria-label=\"x402 payment\">\n\t\t\t\t<div class=\"x402-head\">\n\t\t\t\t\t<div class=\"x402-merchant\">\n\t\t\t\t\t\t<div class=\"x402-name\" data-merchant>${escapeHtml(this.opts.merchant || 'Payment')}</div>\n\t\t\t\t\t\t<div class=\"x402-action\" data-action>${escapeHtml(this.opts.action || 'Pay-per-call')}</div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<button class=\"x402-close\" data-close aria-label=\"Close\">\u2715</button>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"x402-price-row\">\n\t\t\t\t\t<div class=\"x402-price\" data-price>\u2014<span class=\"x402-currency\"> USDC</span></div>\n\t\t\t\t\t<div class=\"x402-network\" data-network>resolving\u2026</div>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"x402-body\" data-body></div>\n\t\t\t\t<div class=\"x402-foot\">\n\t\t\t\t\t<span class=\"x402-secure\">x402 \u00B7 onchain settled</span>\n\t\t\t\t\t${brandHtml}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t`;\n\t\tdocument.body.appendChild(overlay);\n\t\tthis.overlay = overlay;\n\t\tthis.bodyEl = overlay.querySelector('[data-body]');\n\t\tthis.priceEl = overlay.querySelector('[data-price]');\n\t\tthis.networkEl = overlay.querySelector('[data-network]');\n\t\toverlay.querySelector('[data-close]').addEventListener('click', () => this.close('cancelled'));\n\t\toverlay.addEventListener('click', (e) => { if (e.target === overlay) this.close('cancelled'); });\n\t\tthis.onKey = (e) => { if (e.key === 'Escape') this.close('cancelled'); };\n\t\tdocument.addEventListener('keydown', this.onKey);\n\t\trequestAnimationFrame(() => overlay.classList.add('x402-open'));\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.resolve = resolve;\n\t\t\tthis.reject = reject;\n\t\t});\n\t}\n\n\tclose(reason) {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tdocument.removeEventListener('keydown', this.onKey);\n\t\tthis.overlay.classList.remove('x402-open');\n\t\tsetTimeout(() => this.overlay.remove(), 180);\n\t\tif (reason === 'cancelled' && this.reject) {\n\t\t\tconst err = new Error('cancelled');\n\t\t\terr.code = 'cancelled';\n\t\t\tthis.reject(err);\n\t\t}\n\t}\n\n\trenderSteps(activeId, status = {}) {\n\t\tconst html = this.steps\n\t\t\t.map((s) => {\n\t\t\t\tconst state = status[s.id] || (s.id === activeId ? 'active' : 'idle');\n\t\t\t\tconst cls = state === 'active' ? 'x402-active' : state === 'done' ? 'x402-done' : state === 'error' ? 'x402-error' : '';\n\t\t\t\tconst meta = status[`${s.id}_meta`] || '';\n\t\t\t\tconst sym = state === 'done' ? '\u2713' : state === 'error' ? '!' : s.id === activeId && state === 'active' ? ' ' : (this.steps.findIndex((x) => x.id === s.id) + 1);\n\t\t\t\treturn `<div class=\"x402-step ${cls}\">\n\t\t\t\t\t<div class=\"x402-step-num\">${sym}</div>\n\t\t\t\t\t<div class=\"x402-step-body\">\n\t\t\t\t\t\t<div class=\"x402-step-label\">${s.label}</div>\n\t\t\t\t\t\t${meta ? `<div class=\"x402-step-meta\">${escapeHtml(meta)}</div>` : ''}\n\t\t\t\t\t</div>\n\t\t\t\t</div>`;\n\t\t\t})\n\t\t\t.join('');\n\t\treturn html;\n\t}\n\n\tsetPrice(accept) {\n\t\tconst decimals = accept.extra?.decimals ?? 6;\n\t\tconst amount = formatAmount(accept.amount, decimals);\n\t\tconst sym = (accept.extra?.name || 'USDC').replace(/^USD Coin$/, 'USDC');\n\t\tthis.priceEl.innerHTML = `${amount}<span class=\"x402-currency\"> ${sym}</span>`;\n\t\tthis.networkEl.textContent = networkLabel(accept.network, accept);\n\t}\n\n\trenderConnect() {\n\t\tconst phantomDetected = typeof window !== 'undefined' && (window.solana?.isPhantom || window.phantom?.solana);\n\t\tconst evmDetected = typeof window !== 'undefined' && window.ethereum;\n\t\tconst solanaAccept = this.challenge?.accepts.find((a) => isSolanaNetwork(a.network));\n\t\tconst evmAccept = this.challenge?.accepts.find(isEip3009Accept);\n\n\t\t// SIWX-first path: when the 402 advertises sign-in-with-x AND we have a\n\t\t// compatible wallet, lead with \"Sign in with wallet\" (primary) and demote\n\t\t// pay to a secondary action. payFlowOverride is set true when the user\n\t\t// explicitly chooses to pay.\n\t\tif (this.siwx && !this.payFlowOverride) {\n\t\t\tconst siwxSolana = phantomDetected ? pickSiwxChain(this.siwx, 'solana') : null;\n\t\t\tconst siwxEvm = evmDetected ? pickSiwxChain(this.siwx, 'evm') : null;\n\t\t\tif (siwxSolana || siwxEvm) {\n\t\t\t\tthis.renderSiwxChoice({ siwxSolana, siwxEvm });\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// autoConnect (opt-in via opts.autoConnect): when the caller knows the user\n\t\t// is wallet-ready and shouldn't have to pick, skip the picker and go\n\t\t// straight to the signature \u2014 but only when exactly one supported wallet is\n\t\t// actually detected. One-shot via autoConnectTried.\n\t\tif (this.opts.autoConnect && !this.autoConnectTried && !this.siwxFallbackNotice) {\n\t\t\tthis.autoConnectTried = true;\n\t\t\tconst solanaViable = !!(solanaAccept && phantomDetected);\n\t\t\tconst evmViable = !!(evmAccept && evmDetected);\n\t\t\tif (solanaViable && !evmViable) { this.runSolana(solanaAccept); return; }\n\t\t\tif (evmViable && !solanaViable) { this.runEvm(evmAccept); return; }\n\t\t}\n\n\t\tconst buttons = [];\n\t\tif (solanaAccept) {\n\t\t\tbuttons.push(`\n\t\t\t\t<button class=\"x402-wallet-btn\" data-wallet=\"phantom\" ${phantomDetected ? '' : 'disabled'}>\n\t\t\t\t\t<div class=\"x402-wallet-icon x402-phantom\">P</div>\n\t\t\t\t\t<span class=\"x402-wallet-name\">${phantomDetected ? 'Phantom' : 'Phantom (not detected)'}</span>\n\t\t\t\t\t<span class=\"x402-wallet-meta\">${networkLabel(solanaAccept.network, solanaAccept)}</span>\n\t\t\t\t</button>\n\t\t\t`);\n\t\t}\n\t\tif (evmAccept) {\n\t\t\tbuttons.push(`\n\t\t\t\t<button class=\"x402-wallet-btn\" data-wallet=\"evm\" ${evmDetected ? '' : 'disabled'}>\n\t\t\t\t\t<div class=\"x402-wallet-icon x402-metamask\">M</div>\n\t\t\t\t\t<span class=\"x402-wallet-name\">${evmDetected ? 'Browser wallet' : 'No EVM wallet detected'}</span>\n\t\t\t\t\t<span class=\"x402-wallet-meta\">${networkLabel(evmAccept.network, evmAccept)}</span>\n\t\t\t\t</button>\n\t\t\t`);\n\t\t}\n\t\tconst fallbackBox = this.siwxFallbackNotice\n\t\t\t? `<div class=\"x402-siwx-fallback\">${escapeHtml(this.siwxFallbackNotice)}</div>`\n\t\t\t: '';\n\t\tthis.bodyEl.innerHTML = `\n\t\t\t${this.renderSteps('connect', { discover: 'done' })}\n\t\t\t${fallbackBox}\n\t\t\t<div class=\"x402-wallet-buttons\">${buttons.join('')}</div>\n\t\t`;\n\t\tconst onClick = (e) => {\n\t\t\tconst btn = e.target.closest('[data-wallet]');\n\t\t\tif (!btn || btn.disabled) return;\n\t\t\tconst wallet = btn.dataset.wallet;\n\t\t\tif (wallet === 'phantom') this.runSolana(solanaAccept);\n\t\t\telse if (wallet === 'evm') this.runEvm(evmAccept);\n\t\t};\n\t\tthis.bodyEl.querySelectorAll('[data-wallet]').forEach((b) => b.addEventListener('click', onClick));\n\t}\n\n\trenderSiwxChoice({ siwxSolana, siwxEvm }) {\n\t\tconst priceText = formatAmount(this.accept.amount, this.accept.extra?.decimals ?? 6);\n\t\tconst siwxTarget = siwxSolana\n\t\t\t? { kind: 'solana', chain: siwxSolana.chain }\n\t\t\t: { kind: 'evm', chain: siwxEvm.chain };\n\t\tconst siwxLabel = siwxTarget.kind === 'solana' ? 'Sign in with Phantom' : 'Sign in with wallet';\n\t\tthis.bodyEl.innerHTML = `\n\t\t\t${this.renderSteps('connect', { discover: 'done' })}\n\t\t\t<button class=\"x402-pay-btn\" data-action=\"siwx\">${siwxLabel}</button>\n\t\t\t<button class=\"x402-pay-secondary\" data-action=\"pay\">Pay ${priceText} USDC instead</button>\n\t\t\t<div class=\"x402-siwx-hint\">Already paid for this once? Sign in to re-enter without paying again.</div>\n\t\t`;\n\t\tconst siwxBtn = this.bodyEl.querySelector('[data-action=\"siwx\"]');\n\t\tconst payBtn = this.bodyEl.querySelector('[data-action=\"pay\"]');\n\t\tsiwxBtn.addEventListener('click', () => {\n\t\t\tif (siwxTarget.kind === 'solana') this.runSiwxSolana(siwxTarget.chain);\n\t\t\telse this.runSiwxEvm(siwxTarget.chain);\n\t\t});\n\t\tpayBtn.addEventListener('click', () => {\n\t\t\tthis.payFlowOverride = true;\n\t\t\tthis.renderConnect();\n\t\t});\n\t\trequestAnimationFrame(() => siwxBtn.focus());\n\t}\n\n\trenderProgress(activeId, meta = {}) {\n\t\tthis.bodyEl.innerHTML = this.renderSteps(activeId, {\n\t\t\tdiscover: 'done',\n\t\t\tconnect: 'done',\n\t\t\t...(activeId === 'verify' ? { authorize: 'done' } : {}),\n\t\t\t[`${activeId}_meta`]: meta.text || '',\n\t\t\t...meta.statuses,\n\t\t});\n\t}\n\n\trenderError(stepId, message) {\n\t\tthis.bodyEl.innerHTML = `\n\t\t\t${this.renderSteps(stepId, {\n\t\t\t\t...(stepId !== 'discover' ? { discover: 'done' } : {}),\n\t\t\t\t...(stepId === 'authorize' || stepId === 'verify' ? { connect: 'done' } : {}),\n\t\t\t\t...(stepId === 'verify' ? { authorize: 'done' } : {}),\n\t\t\t\t[stepId]: 'error',\n\t\t\t\t[`${stepId}_meta`]: 'failed',\n\t\t\t})}\n\t\t\t<div class=\"x402-error-box\"><strong>${escapeHtml(stepId)}:</strong> ${escapeHtml(message)}</div>\n\t\t\t<button class=\"x402-pay-btn\" data-retry>Try again</button>\n\t\t`;\n\t\tthis.bodyEl.querySelector('[data-retry]').addEventListener('click', () => this.start());\n\t}\n\n\trenderDone({ result, payment, siwx }) {\n\t\tconst resultStr = typeof result === 'string' ? result : JSON.stringify(result, null, 2);\n\t\tlet receiptHtml;\n\t\tif (siwx) {\n\t\t\tconst addrShort = siwx.address ? `${siwx.address.slice(0, 8)}\u2026${siwx.address.slice(-6)}` : '\u2014';\n\t\t\treceiptHtml = `\n\t\t\t\t<div class=\"x402-receipt\">\n\t\t\t\t\t<div class=\"x402-receipt-title\">Welcome back!</div>\n\t\t\t\t\t<div class=\"x402-receipt-row\">\n\t\t\t\t\t\t<span class=\"x402-k\">network</span>\n\t\t\t\t\t\t<span class=\"x402-v\">${escapeHtml(networkLabel(siwx.network) || siwx.network || '\u2014')}</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"x402-receipt-row\">\n\t\t\t\t\t\t<span class=\"x402-k\">wallet</span>\n\t\t\t\t\t\t<span class=\"x402-v\">${escapeHtml(addrShort)}</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"x402-receipt-row\">\n\t\t\t\t\t\t<span class=\"x402-k\">paid</span>\n\t\t\t\t\t\t<span class=\"x402-v\">previously \u00B7 re-entered free</span>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t`;\n\t\t} else {\n\t\t\tconst explorer = explorerUrl(payment?.network, payment?.transaction);\n\t\t\tconst txShort = payment?.transaction ? `${payment.transaction.slice(0, 8)}\u2026${payment.transaction.slice(-6)}` : '\u2014';\n\t\t\treceiptHtml = `\n\t\t\t\t<div class=\"x402-receipt\">\n\t\t\t\t\t<div class=\"x402-receipt-title\">Payment confirmed!</div>\n\t\t\t\t\t<div class=\"x402-receipt-row\">\n\t\t\t\t\t\t<span class=\"x402-k\">network</span>\n\t\t\t\t\t\t<span class=\"x402-v\">${escapeHtml(networkLabel(payment?.network) || '\u2014')}</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"x402-receipt-row\">\n\t\t\t\t\t\t<span class=\"x402-k\">payer</span>\n\t\t\t\t\t\t<span class=\"x402-v\">${escapeHtml(payment?.payer ? `${payment.payer.slice(0, 8)}\u2026${payment.payer.slice(-6)}` : '\u2014')}</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t${\n\t\t\t\t\t\tpayment?.transaction\n\t\t\t\t\t\t\t? `<div class=\"x402-receipt-row\"><span class=\"x402-k\">tx</span><span class=\"x402-v\">${\n\t\t\t\t\t\t\t\t\texplorer ? `<a href=\"${explorer}\" target=\"_blank\" rel=\"noopener\">${txShort} \u2197</a>` : txShort\n\t\t\t\t\t\t\t\t}</span></div>`\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}\n\t\t\t\t</div>\n\t\t\t`;\n\t\t}\n\t\tthis.bodyEl.innerHTML = `\n\t\t\t${receiptHtml}\n\t\t\t<div class=\"x402-result\">${escapeHtml(resultStr).slice(0, 4000)}</div>\n\t\t\t<button class=\"x402-pay-btn\" data-done>Done</button>\n\t\t`;\n\t\tthis.bodyEl.querySelector('[data-done]').addEventListener('click', () => {\n\t\t\tthis.disposed = true;\n\t\t\tdocument.removeEventListener('keydown', this.onKey);\n\t\t\tthis.overlay.classList.remove('x402-open');\n\t\t\tsetTimeout(() => this.overlay.remove(), 180);\n\t\t});\n\t}\n\n\tasync start() {\n\t\tthis.bodyEl.innerHTML = this.renderSteps('discover');\n\t\ttry {\n\t\t\tconst challenge = await discoverChallenge(this.opts);\n\t\t\tthis.challenge = challenge;\n\t\t\tthis.siwx = extractSiwxExtension(challenge);\n\t\t\tthis.payFlowOverride = false;\n\t\t\tthis.siwxFallbackNotice = null;\n\t\t\t// Prefer Solana when Phantom is present, else first EIP-3009 EVM entry\n\t\t\t// (skipping Permit2 siblings the modal can't sign for), else first accept.\n\t\t\tconst solana = challenge.accepts.find((a) => isSolanaNetwork(a.network));\n\t\t\tconst evm = challenge.accepts.find(isEip3009Accept);\n\t\t\tconst phantomDetected = typeof window !== 'undefined' && (window.solana?.isPhantom || window.phantom?.solana);\n\t\t\tthis.accept = (phantomDetected && solana) || evm || challenge.accepts[0];\n\t\t\tthis.setPrice(this.accept);\n\t\t\tthis.renderConnect();\n\t\t} catch (err) {\n\t\t\tthis.renderError('discover', err.message || String(err));\n\t\t}\n\t}\n\n\tasync runSolana(accept) {\n\t\tthis.accept = accept;\n\t\tthis.setPrice(accept);\n\t\tthis.renderProgress('connect', { text: 'Opening Phantom\u2026' });\n\t\ttry {\n\t\t\tconst provider = window.phantom?.solana || window.solana;\n\t\t\tif (!provider) throw new Error('Phantom wallet not detected');\n\t\t\tconst conn = await provider.connect();\n\t\t\tconst payerAddress = (conn?.publicKey || provider.publicKey)?.toString();\n\t\t\tif (!payerAddress) throw new Error('Phantom did not return a public key');\n\t\t\tthis.payerAddress = payerAddress;\n\t\t\tconst capCheck = browserEnforceCap({\n\t\t\t\taccept,\n\t\t\t\tcaps: this.opts.caps,\n\t\t\t\taddress: payerAddress,\n\t\t\t});\n\t\t\tif (capCheck.abort) {\n\t\t\t\tthis.renderError('authorize', capCheck.reason);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.spendReservation = capCheck.reservation || null;\n\t\t\tthis.renderProgress('authorize', { text: `Building Solana payment for ${payerAddress.slice(0, 6)}\u2026${payerAddress.slice(-4)}` });\n\n\t\t\tconst origin = this._apiOrigin();\n\t\t\tconst prep = await postJson(`${origin}/api/x402-checkout?action=prepare`, {\n\t\t\t\taccept,\n\t\t\t\tbuyer: payerAddress,\n\t\t\t});\n\t\t\tthis.renderProgress('authorize', { text: 'Confirm in Phantom\u2026' });\n\t\t\tconst txBytes = base64ToUint8Array(prep.tx_base64);\n\t\t\t// Phantom returns a fully-signed VersionedTransaction with the buyer's\n\t\t\t// signature added. The facilitator's fee-payer signature is added during\n\t\t\t// /settle.\n\t\t\tconst SolanaWeb3 = await loadSolanaWeb3();\n\t\t\tconst tx = SolanaWeb3.VersionedTransaction.deserialize(txBytes);\n\t\t\tconst signed = await provider.signTransaction(tx);\n\t\t\tconst signedB64 = uint8ArrayToBase64(signed.serialize());\n\n\t\t\tconst builderCodeBlock = buildBuilderCodeEcho(this.challenge);\n\t\t\tconst enc = await postJson(`${origin}/api/x402-checkout?action=encode`, {\n\t\t\t\taccept,\n\t\t\t\tsigned_tx_base64: signedB64,\n\t\t\t\tresource_url: new URL(this.opts.endpoint, location.href).href,\n\t\t\t\t...(builderCodeBlock ? { builder_code: builderCodeBlock } : {}),\n\t\t\t});\n\n\t\t\tawait this.executePaid(enc.x_payment);\n\t\t} catch (err) {\n\t\t\tif (this.spendReservation) {\n\t\t\t\tbrowserRollbackReservation(this.spendReservation);\n\t\t\t\tthis.spendReservation = null;\n\t\t\t}\n\t\t\tthis.renderError(this.payerAddress ? 'authorize' : 'connect', friendlyError(err));\n\t\t}\n\t}\n\n\tasync runEvm(accept) {\n\t\tthis.accept = accept;\n\t\tthis.setPrice(accept);\n\t\tthis.renderProgress('connect', { text: 'Opening browser wallet\u2026' });\n\t\ttry {\n\t\t\tconst eth = window.ethereum;\n\t\t\tif (!eth) throw new Error('No EVM wallet detected');\n\t\t\tconst accounts = await eth.request({ method: 'eth_requestAccounts' });\n\t\t\tconst payerAddress = accounts?.[0];\n\t\t\tif (!payerAddress) throw new Error('Wallet did not return an account');\n\t\t\tthis.payerAddress = payerAddress;\n\t\t\tconst capCheck = browserEnforceCap({\n\t\t\t\taccept,\n\t\t\t\tcaps: this.opts.caps,\n\t\t\t\taddress: payerAddress,\n\t\t\t});\n\t\t\tif (capCheck.abort) {\n\t\t\t\tthis.renderError('authorize', capCheck.reason);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.spendReservation = capCheck.reservation || null;\n\n\t\t\tconst meta = EVM_NETWORKS[accept.network];\n\t\t\tif (!meta) throw new Error(`Unknown EVM network ${accept.network}`);\n\t\t\t// Switch chain if needed.\n\t\t\tconst currentChainHex = await eth.request({ method: 'eth_chainId' });\n\t\t\tconst desiredChainHex = '0x' + meta.chainId.toString(16);\n\t\t\tif (currentChainHex !== desiredChainHex) {\n\t\t\t\tthis.renderProgress('connect', { text: `Switch wallet to ${meta.name}\u2026` });\n\t\t\t\ttry {\n\t\t\t\t\tawait eth.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: desiredChainHex }] });\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthrow new Error(`Wallet is on ${currentChainHex}; please switch to ${meta.name} (${desiredChainHex}) and retry`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.renderProgress('authorize', { text: `Authorize ${formatAmount(accept.amount)} USDC\u2026` });\n\n\t\t\t// EIP-3009 transferWithAuthorization typed-data signature.\n\t\t\tconst validAfter = 0;\n\t\t\tconst validBefore = Math.floor(Date.now() / 1000) + (accept.maxTimeoutSeconds || 600);\n\t\t\tconst nonce = '0x' + randomHex(32);\n\t\t\tconst domain = {\n\t\t\t\tname: accept.extra?.name || 'USD Coin',\n\t\t\t\tversion: accept.extra?.version || '2',\n\t\t\t\tchainId: meta.chainId,\n\t\t\t\tverifyingContract: accept.asset,\n\t\t\t};\n\t\t\tconst types = {\n\t\t\t\tEIP712Domain: [\n\t\t\t\t\t{ name: 'name', type: 'string' },\n\t\t\t\t\t{ name: 'version', type: 'string' },\n\t\t\t\t\t{ name: 'chainId', type: 'uint256' },\n\t\t\t\t\t{ name: 'verifyingContract', type: 'address' },\n\t\t\t\t],\n\t\t\t\tTransferWithAuthorization: [\n\t\t\t\t\t{ name: 'from', type: 'address' },\n\t\t\t\t\t{ name: 'to', type: 'address' },\n\t\t\t\t\t{ name: 'value', type: 'uint256' },\n\t\t\t\t\t{ name: 'validAfter', type: 'uint256' },\n\t\t\t\t\t{ name: 'validBefore', type: 'uint256' },\n\t\t\t\t\t{ name: 'nonce', type: 'bytes32' },\n\t\t\t\t],\n\t\t\t};\n\t\t\tconst message = {\n\t\t\t\tfrom: payerAddress,\n\t\t\t\tto: accept.payTo,\n\t\t\t\tvalue: accept.amount,\n\t\t\t\tvalidAfter,\n\t\t\t\tvalidBefore,\n\t\t\t\tnonce,\n\t\t\t};\n\t\t\tconst typedData = {\n\t\t\t\tprimaryType: 'TransferWithAuthorization',\n\t\t\t\ttypes,\n\t\t\t\tdomain,\n\t\t\t\tmessage,\n\t\t\t};\n\t\t\tconst signature = await eth.request({\n\t\t\t\tmethod: 'eth_signTypedData_v4',\n\t\t\t\tparams: [payerAddress, JSON.stringify(typedData)],\n\t\t\t});\n\n\t\t\tconst paymentPayload = {\n\t\t\t\tx402Version: 2,\n\t\t\t\tscheme: 'exact',\n\t\t\t\tnetwork: accept.network,\n\t\t\t\tresource: { url: this.opts.endpoint, mimeType: 'application/json' },\n\t\t\t\taccepted: accept,\n\t\t\t\tpayload: {\n\t\t\t\t\tsignature,\n\t\t\t\t\t// The facilitator /verify requires the EIP-3009 time bounds as\n\t\t\t\t\t// decimal strings, not JSON numbers. The signature is unaffected:\n\t\t\t\t\t// uint256 0 and \"0\" encode identically.\n\t\t\t\t\tauthorization: { from: payerAddress, to: accept.payTo, value: accept.amount, validAfter: String(validAfter), validBefore: String(validBefore), nonce },\n\t\t\t\t},\n\t\t\t};\n\t\t\tconst builderCodeBlock = buildBuilderCodeEcho(this.challenge);\n\t\t\tif (builderCodeBlock) {\n\t\t\t\tpaymentPayload.extensions = { 'builder-code': builderCodeBlock };\n\t\t\t}\n\t\t\tconst xPayment = b64encode(paymentPayload);\n\t\t\tawait this.executePaid(xPayment);\n\t\t} catch (err) {\n\t\t\tif (this.spendReservation) {\n\t\t\t\tbrowserRollbackReservation(this.spendReservation);\n\t\t\t\tthis.spendReservation = null;\n\t\t\t}\n\t\t\tthis.renderError(this.payerAddress ? 'authorize' : 'connect', friendlyError(err));\n\t\t}\n\t}\n\n\tasync executePaid(xPayment, attempt = 0) {\n\t\tthis.renderProgress('verify', {\n\t\t\ttext: attempt ? 'Retrying after upstream throttle\u2026' : 'Calling merchant endpoint\u2026',\n\t\t});\n\t\ttry {\n\t\t\tconst res = await fetch(this.opts.endpoint, {\n\t\t\t\tmethod: this.opts.method || 'GET',\n\t\t\t\theaders: {\n\t\t\t\t\t...(this.opts.headers || {}),\n\t\t\t\t\t...(this.opts.body && !this.opts.headers?.['content-type'] ? { 'content-type': 'application/json' } : {}),\n\t\t\t\t\t'X-PAYMENT': xPayment,\n\t\t\t\t},\n\t\t\t\tbody: this.opts.body ? (typeof this.opts.body === 'string' ? this.opts.body : JSON.stringify(this.opts.body)) : undefined,\n\t\t\t});\n\t\t\tconst ct = res.headers.get('content-type') || '';\n\t\t\tconst text = await res.text();\n\t\t\tlet result;\n\t\t\tif (ct.includes('json')) {\n\t\t\t\ttry {\n\t\t\t\t\tresult = JSON.parse(text);\n\t\t\t\t} catch {\n\t\t\t\t\tresult = text;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tresult = text;\n\t\t\t}\n\t\t\tif (!res.ok) {\n\t\t\t\t// A 429 here is a transient upstream throttle. The payment is signed\n\t\t\t\t// but NOT yet settled \u2014 the merchant runs the work before settling \u2014\n\t\t\t\t// so the same X-PAYMENT can be safely re-sent once the window resets,\n\t\t\t\t// with no risk of a double charge.\n\t\t\t\tif (res.status === 429 && attempt < MAX_THROTTLE_RETRIES) {\n\t\t\t\t\tawait this.waitForThrottle(retryAfterSeconds(res, result));\n\t\t\t\t\treturn this.executePaid(xPayment, attempt + 1);\n\t\t\t\t}\n\t\t\t\tconst msg = (result && typeof result === 'object' && (result.error_description || result.error)) || `HTTP ${res.status}`;\n\t\t\t\tthrow new Error(msg);\n\t\t\t}\n\t\t\tconst settleHeader = res.headers.get('x-payment-response');\n\t\t\tconst payment = b64decode(settleHeader) || {};\n\t\t\tthis.spendReservation = null;\n\t\t\tthis.renderDone({ result, payment });\n\t\t\tthis.resolve?.({ ok: true, result, payment, response: { status: res.status, headers: headersToObject(res.headers) } });\n\t\t} catch (err) {\n\t\t\tif (this.spendReservation) {\n\t\t\t\tbrowserRollbackReservation(this.spendReservation);\n\t\t\t\tthis.spendReservation = null;\n\t\t\t}\n\t\t\tthis.renderError('verify', friendlyError(err));\n\t\t}\n\t}\n\n\t// Hold the verify step on a live countdown while an upstream throttle resets,\n\t// then return so the caller re-sends the same signed payment. The reservation\n\t// is deliberately left intact \u2014 this is the same payment, not a new one.\n\tasync waitForThrottle(seconds) {\n\t\tconst total = Math.max(1, Math.min(30, Math.round(seconds) || 6));\n\t\tfor (let left = total; left > 0; left--) {\n\t\t\tthis.renderProgress('verify', { text: `Service is busy \u2014 retrying in ${left}s\u2026` });\n\t\t\tawait new Promise((r) => setTimeout(r, 1000));\n\t\t}\n\t\tthis.renderProgress('verify', { text: 'Retrying\u2026' });\n\t}\n\n\tasync runSiwxEvm(chain) {\n\t\tthis.renderProgress('connect', { text: 'Opening browser wallet\u2026' });\n\t\ttry {\n\t\t\tconst eth = window.ethereum;\n\t\t\tif (!eth) throw new Error('No EVM wallet detected');\n\t\t\tconst accounts = await eth.request({ method: 'eth_requestAccounts' });\n\t\t\tconst rawAddress = accounts?.[0];\n\t\t\tif (!rawAddress) throw new Error('Wallet did not return an account');\n\t\t\tconst checksum = await loadEvmChecksum();\n\t\t\tconst address = checksum(rawAddress);\n\t\t\tthis.payerAddress = address;\n\t\t\tthis.renderProgress('authorize', { text: `Sign sign-in message as ${address.slice(0, 6)}\u2026${address.slice(-4)}` });\n\n\t\t\tconst message = buildSiwxMessage(this.siwx.info, chain, address);\n\t\t\tconst signature = await eth.request({\n\t\t\t\tmethod: 'personal_sign',\n\t\t\t\tparams: [message, address],\n\t\t\t});\n\n\t\t\tconst info = this.siwx.info;\n\t\t\tconst payload = {\n\t\t\t\tdomain: info.domain,\n\t\t\t\taddress,\n\t\t\t\t...(info.statement ? { statement: info.statement } : {}),\n\t\t\t\turi: info.uri,\n\t\t\t\tversion: info.version || '1',\n\t\t\t\tchainId: chain.chainId,\n\t\t\t\ttype: 'eip191',\n\t\t\t\tnonce: info.nonce,\n\t\t\t\tissuedAt: info.issuedAt,\n\t\t\t\t...(info.expirationTime ? { expirationTime: info.expirationTime } : {}),\n\t\t\t\t...(info.notBefore ? { notBefore: info.notBefore } : {}),\n\t\t\t\t...(info.requestId !== undefined && info.requestId !== null ? { requestId: info.requestId } : {}),\n\t\t\t\t...(Array.isArray(info.resources) ? { resources: info.resources } : {}),\n\t\t\t\tsignatureScheme: 'eip191',\n\t\t\t\tsignature,\n\t\t\t};\n\t\t\tawait this.executeSiwx(payload, chain.chainId);\n\t\t} catch (err) {\n\t\t\tthis.renderError(this.payerAddress ? 'authorize' : 'connect', friendlyError(err));\n\t\t}\n\t}\n\n\tasync runSiwxSolana(chain) {\n\t\tthis.renderProgress('connect', { text: 'Opening Phantom\u2026' });\n\t\ttry {\n\t\t\tconst provider = window.phantom?.solana || window.solana;\n\t\t\tif (!provider) throw new Error('Phantom wallet not detected');\n\t\t\tconst conn = await provider.connect();\n\t\t\tconst pubkey = conn?.publicKey || provider.publicKey;\n\t\t\tconst address = pubkey?.toString();\n\t\t\tif (!address) throw new Error('Phantom did not return a public key');\n\t\t\tthis.payerAddress = address;\n\t\t\tthis.renderProgress('authorize', { text: `Sign sign-in message as ${address.slice(0, 6)}\u2026${address.slice(-4)}` });\n\n\t\t\tconst message = buildSiwxMessage(this.siwx.info, chain, address);\n\t\t\tconst encoded = new TextEncoder().encode(message);\n\t\t\tconst signed = await provider.signMessage(encoded, 'utf8');\n\t\t\tconst sigBytes = signed?.signature instanceof Uint8Array ? signed.signature : new Uint8Array(signed?.signature || signed);\n\t\t\tif (!sigBytes || !sigBytes.length) throw new Error('Phantom did not return a signature');\n\t\t\tconst signature = base58encode(sigBytes);\n\n\t\t\tconst info = this.siwx.info;\n\t\t\tconst payload = {\n\t\t\t\tdomain: info.domain,\n\t\t\t\taddress,\n\t\t\t\t...(info.statement ? { statement: info.statement } : {}),\n\t\t\t\turi: info.uri,\n\t\t\t\tversion: info.version || '1',\n\t\t\t\tchainId: chain.chainId,\n\t\t\t\ttype: 'ed25519',\n\t\t\t\tnonce: info.nonce,\n\t\t\t\tissuedAt: info.issuedAt,\n\t\t\t\t...(info.expirationTime ? { expirationTime: info.expirationTime } : {}),\n\t\t\t\t...(info.notBefore ? { notBefore: info.notBefore } : {}),\n\t\t\t\t...(info.requestId !== undefined && info.requestId !== null ? { requestId: info.requestId } : {}),\n\t\t\t\t...(Array.isArray(info.resources) ? { resources: info.resources } : {}),\n\t\t\t\tsignatureScheme: 'siws',\n\t\t\t\tsignature,\n\t\t\t};\n\t\t\tawait this.executeSiwx(payload, chain.chainId);\n\t\t} catch (err) {\n\t\t\tthis.renderError(this.payerAddress ? 'authorize' : 'connect', friendlyError(err));\n\t\t}\n\t}\n\n\tasync executeSiwx(payload, chainId) {\n\t\tthis.renderProgress('verify', { text: 'Verifying sign-in\u2026' });\n\t\tconst headerValue = encodeSiwxHeaderValue(payload);\n\t\tlet res;\n\t\ttry {\n\t\t\tres = await fetch(this.opts.endpoint, {\n\t\t\t\tmethod: this.opts.method || 'GET',\n\t\t\t\theaders: {\n\t\t\t\t\t...(this.opts.headers || {}),\n\t\t\t\t\t...(this.opts.body && !this.opts.headers?.['content-type'] ? { 'content-type': 'application/json' } : {}),\n\t\t\t\t\t[SIWX_HEADER]: headerValue,\n\t\t\t\t},\n\t\t\t\tbody: this.opts.body ? (typeof this.opts.body === 'string' ? this.opts.body : JSON.stringify(this.opts.body)) : undefined,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tthis.renderError('verify', friendlyError(err));\n\t\t\treturn;\n\t\t}\n\n\t\tif (res.status === 200) {\n\t\t\tconst ct = res.headers.get('content-type') || '';\n\t\t\tconst text = await res.text();\n\t\t\tlet result;\n\t\t\tif (ct.includes('json')) {\n\t\t\t\ttry { result = JSON.parse(text); } catch { result = text; }\n\t\t\t} else {\n\t\t\t\tresult = text;\n\t\t\t}\n\t\t\tconst siwx = { address: payload.address, network: chainId };\n\t\t\tthis.renderDone({ result, siwx });\n\t\t\tthis.resolve?.({\n\t\t\t\tok: true,\n\t\t\t\tresult,\n\t\t\t\tsiwx,\n\t\t\t\tresponse: { status: res.status, headers: headersToObject(res.headers) },\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tif (res.status === 401 || res.status === 402) {\n\t\t\t// Most likely: signature verified but this wallet hasn't actually paid\n\t\t\t// for the resource yet. Drop the SIWX offering and fall back to the\n\t\t\t// normal payment flow with a one-line notice.\n\t\t\tlet parsed = null;\n\t\t\ttry { parsed = await res.clone().json(); } catch (_) {}\n\t\t\tconst code = parsed?.code || parsed?.error;\n\t\t\tthis.siwx = null;\n\t\t\tthis.payerAddress = null;\n\t\t\tthis.payFlowOverride = false;\n\t\t\tthis.siwxFallbackNotice = code === 'siwx_not_paid' || res.status === 402\n\t\t\t\t? \"You haven't paid for this yet \u2014 pay now to unlock re-entry.\"\n\t\t\t\t: 'Sign-in not accepted \u2014 please pay to continue.';\n\t\t\tif (!this.challenge || !Array.isArray(this.challenge.accepts) || !this.challenge.accepts.length) {\n\t\t\t\tthis.start();\n\t\t\t} else {\n\t\t\t\tthis.renderConnect();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst text = await res.text().catch(() => '');\n\t\tthis.renderError('verify', `SIWX retry failed: HTTP ${res.status}${text ? ` \u00B7 ${text.slice(0, 120)}` : ''}`);\n\t}\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfunction escapeHtml(s) {\n\treturn String(s == null ? '' : s).replace(/[&<>\"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '\"': '"', \"'\": ''' }[c]));\n}\n\nfunction headersToObject(headers) {\n\tconst out = {};\n\theaders.forEach((v, k) => (out[k] = v));\n\treturn out;\n}\n\n// How many times executePaid silently re-sends a signed payment after a 429\n// throttle before falling back to the manual \"Try again\". The payment isn't\n// settled until the merchant call succeeds, so re-sending can't double-charge.\nconst MAX_THROTTLE_RETRIES = 2;\n\n// Seconds to wait before re-sending after a 429. Prefers the standard\n// Retry-After header, then the body's `retry_after` hint, then a sane default.\nfunction retryAfterSeconds(res, result, fallback = 6) {\n\tconst header = Number.parseInt(res.headers.get('retry-after') || '', 10);\n\tif (Number.isFinite(header) && header > 0) return header;\n\tconst body = result && typeof result === 'object' ? Number(result.retry_after) : NaN;\n\tif (Number.isFinite(body) && body > 0) return body;\n\treturn fallback;\n}\n\nfunction friendlyError(err) {\n\tconst msg = err?.shortMessage || err?.message || String(err);\n\tif (/user rejected|user denied|reject/i.test(msg)) return 'cancelled in wallet';\n\t// Upstream throttles often arrive as raw provider text that names the\n\t// merchant's internal billing or credit state. Never relay that to the buyer:\n\t// the payment isn't settled until the merchant call succeeds.\n\tif (/throttl|rate.?limit|too many requests|less than \\$|in credit|\\b429\\b/i.test(msg)) {\n\t\treturn 'The service is briefly busy and your payment was not taken \u2014 retry in a few seconds.';\n\t}\n\t// The Solana and EVM-sign-in paths dynamic-import a library from a CDN. A\n\t// strict host Content-Security-Policy (or the CDN being unreachable) blocks\n\t// that import. The Base/EIP-3009 payment path has no such dependency.\n\tif (/dynamically imported module|esm\\.sh|module script failed/i.test(msg)) {\n\t\treturn 'A component this wallet path needs (loaded from a CDN) was blocked \u2014 often by a strict host security policy. Pay with MetaMask on Base instead; it needs no third-party code.';\n\t}\n\treturn msg.slice(0, 240);\n}\n\nfunction base64ToUint8Array(b64) {\n\tif (typeof Buffer !== 'undefined') return new Uint8Array(Buffer.from(b64, 'base64'));\n\tconst bin = atob(b64);\n\tconst arr = new Uint8Array(bin.length);\n\tfor (let i = 0; i < bin.length; i++) arr[i] = bin.charCodeAt(i);\n\treturn arr;\n}\nfunction uint8ArrayToBase64(arr) {\n\tif (typeof Buffer !== 'undefined') return Buffer.from(arr).toString('base64');\n\tlet bin = '';\n\tfor (let i = 0; i < arr.length; i++) bin += String.fromCharCode(arr[i]);\n\treturn btoa(bin);\n}\nfunction randomHex(bytes) {\n\tconst arr = new Uint8Array(bytes);\n\tcrypto.getRandomValues(arr);\n\treturn Array.from(arr).map((b) => b.toString(16).padStart(2, '0')).join('');\n}\n\nlet _solanaWeb3 = null;\nasync function loadSolanaWeb3() {\n\tif (_solanaWeb3) return _solanaWeb3;\n\t// Dynamic import from a CDN keeps the drop-in script tiny \u2014 Solana web3.js is\n\t// only fetched when a Solana payment is actually attempted.\n\t_solanaWeb3 = await import(/* @vite-ignore */ config.solanaWeb3Url);\n\treturn _solanaWeb3;\n}\n\nasync function postJson(url, body) {\n\tconst res = await fetch(url, {\n\t\tmethod: 'POST',\n\t\theaders: { 'content-type': 'application/json' },\n\t\tbody: JSON.stringify(body),\n\t});\n\tconst text = await res.text();\n\tlet data;\n\ttry {\n\t\tdata = JSON.parse(text);\n\t} catch {\n\t\tdata = { error: 'parse_error', error_description: text.slice(0, 200) };\n\t}\n\tif (!res.ok) {\n\t\tconst err = new Error(data.error_description || data.error || `HTTP ${res.status}`);\n\t\terr.status = res.status;\n\t\terr.data = data;\n\t\tthrow err;\n\t}\n\treturn data;\n}\n\n// Probe the merchant endpoint with a benign request to extract the 402\n// challenge. Accepts HTTP 402 (standard x402) or HTTP 401 with a\n// `payment-required` header (MCP 2025-06-18 spec).\nasync function discoverChallenge(opts) {\n\tconst headers = { ...(opts.headers || {}) };\n\tconst init = {\n\t\tmethod: opts.method || 'GET',\n\t\theaders,\n\t\tbody: opts.body ? (typeof opts.body === 'string' ? opts.body : JSON.stringify(opts.body)) : undefined,\n\t};\n\tif (init.body && !headers['content-type']) headers['content-type'] = 'application/json';\n\tconst res = await fetch(opts.endpoint, init);\n\n\t// MCP 2025-06-18 endpoints return 401 with the full x402 challenge in the\n\t// `payment-required` header (base64-JSON). Accept that alongside standard 402.\n\tconst prHeader = res.headers.get('payment-required');\n\tconst is401WithChallenge = res.status === 401 && !!prHeader;\n\n\tif (res.status !== 402 && !is401WithChallenge) {\n\t\t// Endpoint isn't paid (200) or isn't an x402 endpoint at all. Surface a\n\t\t// clear error \u2014 pointing the modal at a free endpoint should not silently\n\t\t// succeed.\n\t\tconst txt = await res.text();\n\t\tthrow new Error(`Endpoint did not return 402 (got ${res.status}). Body: ${txt.slice(0, 120)}`);\n\t}\n\n\tlet body = is401WithChallenge ? b64decode(prHeader) : await res.json().catch(() => null);\n\tif (!body || !Array.isArray(body.accepts) || !body.accepts.length) {\n\t\t// Some servers only emit `{error}` in the body and put the full v2\n\t\t// PaymentRequired envelope in the base64-JSON PAYMENT-REQUIRED header.\n\t\tconst decoded = b64decode(prHeader);\n\t\tif (decoded && Array.isArray(decoded.accepts) && decoded.accepts.length) {\n\t\t\tbody = decoded;\n\t\t}\n\t}\n\tif (!body || !Array.isArray(body.accepts) || !body.accepts.length) {\n\t\tthrow new Error('Endpoint returned 402 but no `accepts` array could be found in body or header');\n\t}\n\t// Coerce spec-canonical `maxAmountRequired` \u2192 `amount` so downstream price /\n\t// caps / signing read one field.\n\tbody.accepts = body.accepts.map(normalizeAccept);\n\treturn body;\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 public api \u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * Open the payment modal for an x402 endpoint and resolve when the call\n * succeeds (after settlement) or reject if the user cancels.\n * @param {import('../types/index.js').PayOptions} opts\n * @returns {Promise<import('../types/index.js').PayResult>}\n */\nexport async function pay(opts) {\n\tif (!opts?.endpoint) throw new Error('X402.pay: endpoint is required');\n\tconst modal = new CheckoutModal(opts);\n\tconst result = modal.mount();\n\t// Kick off discovery on the next tick so the modal animates in first.\n\tqueueMicrotask(() => modal.start());\n\treturn result;\n}\n\nfunction readOptsFrom(el) {\n\tconst ds = el.dataset;\n\tlet body = ds.x402Body;\n\tif (body) {\n\t\ttry { body = JSON.parse(body); } catch { /* keep as string */ }\n\t}\n\tlet headers = ds.x402Headers;\n\tif (headers) {\n\t\ttry { headers = JSON.parse(headers); } catch { headers = undefined; }\n\t}\n\tlet caps = ds.x402Caps;\n\tif (caps) {\n\t\ttry { caps = JSON.parse(caps); } catch { caps = undefined; }\n\t}\n\treturn {\n\t\tendpoint: ds.x402Endpoint,\n\t\tmethod: ds.x402Method || (body ? 'POST' : 'GET'),\n\t\tbody,\n\t\theaders,\n\t\tcaps,\n\t\tapiOrigin: ds.x402ApiOrigin,\n\t\tmerchant: ds.x402Merchant,\n\t\taction: ds.x402Action || el.textContent?.trim().slice(0, 60),\n\t};\n}\n\nfunction bindElement(el) {\n\tif (el.dataset.x402Bound === '1') return;\n\tel.dataset.x402Bound = '1';\n\tel.addEventListener('click', async (e) => {\n\t\te.preventDefault();\n\t\tconst opts = readOptsFrom(el);\n\t\ttry {\n\t\t\tconst out = await pay(opts);\n\t\t\tif (out?.siwx) {\n\t\t\t\tel.dispatchEvent(new CustomEvent('x402:siwx-signed', { detail: out.siwx, bubbles: true }));\n\t\t\t}\n\t\t\tel.dispatchEvent(new CustomEvent('x402:result', { detail: out, bubbles: true }));\n\t\t} catch (err) {\n\t\t\tif (err?.code === 'cancelled') return;\n\t\t\tel.dispatchEvent(new CustomEvent('x402:error', { detail: { error: err?.message || String(err) }, bubbles: true }));\n\t\t}\n\t});\n}\n\n/** Scan the document and bind every `[data-x402-endpoint]` element. Idempotent. */\nexport function init() {\n\tif (typeof document === 'undefined') return;\n\tdocument.querySelectorAll('[data-x402-endpoint]').forEach(bindElement);\n}\n\nexport { VERSION as version, bindElement, readOptsFrom };\n"],
|
|
5
|
-
"mappings": ";AAKO,IAAM,eAAe;AAAA,EAC3B,eAAe,EAAE,SAAS,MAAM,MAAM,QAAQ,UAAU,2BAA2B;AAAA,EACnF,gBAAgB,EAAE,SAAS,OAAO,MAAM,gBAAgB,UAAU,mCAAmC;AAAA,EACrG,gBAAgB,EAAE,SAAS,OAAO,MAAM,YAAY,UAAU,0BAA0B;AAAA,EACxF,aAAa,EAAE,SAAS,IAAI,MAAM,YAAY,UAAU,sCAAsC;AAC/F;AAGO,IAAM,eAAe,oBAAI,IAAI;AAAA,EACnC;AAAA,EAAQ;AAAA,EAAY;AAAA,EAAQ;AAAA,EAAU;AAAA,EAAwB;AAC/D,CAAC;AAMM,SAAS,gBAAgB,QAAQ;AACvC,MAAI,CAAC,UAAU,OAAO,WAAW,SAAU,QAAO;AAClD,QAAM,SAAS,OAAO,UAAU,OAAO;AACvC,SAAO,UAAU,QAAQ,OAAO,UAAU,OAAO,EAAE,GAAG,QAAQ,QAAQ,OAAO,MAAM,EAAE,IAAI;AAC1F;AAEO,SAAS,gBAAgB,KAAK;AACpC,SAAO,OAAO,QAAQ,aAAa,QAAQ,YAAY,IAAI,WAAW,SAAS;AAChF;AACO,SAAS,aAAa,KAAK;AACjC,SAAO,OAAO,QAAQ,YAAY,IAAI,WAAW,SAAS;AAC3D;AAKO,SAAS,gBAAgB,QAAQ;AACvC,MAAI,CAAC,aAAa,QAAQ,OAAO,EAAG,QAAO;AAC3C,QAAM,SAAS,QAAQ,OAAO;AAC9B,SAAO,CAAC,UAAU,WAAW;AAC9B;AACO,SAA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AO,KAAK,MAAM,IAAI;AAAA,IAAG,QAAQ;AAAE,aAAO;AAAA,IAAW;AAAA,EAC5D;AACA,SAAO;AAAA,IACN,UAAU,GAAG;AAAA,IACb,QAAQ,GAAG,eAAe,OAAO,SAAS;AAAA,IAC1C;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW,GAAG;AAAA,IACd,UAAU,GAAG;AAAA,IACb,QAAQ,GAAG,cAAc,GAAG,aAAa,KAAK,EAAE,MAAM,GAAG,EAAE;AAAA,EAC5D;AACD;AAEA,SAAS,YAAY,IAAI;AACxB,MAAI,GAAG,QAAQ,cAAc,IAAK;AAClC,KAAG,QAAQ,YAAY;AACvB,KAAG,iBAAiB,SAAS,OAAO,MAAM;AACzC,MAAE,eAAe;AACjB,UAAM,OAAO,aAAa,EAAE;AAC5B,QAAI;AACH,YAAM,MAAM,MAAM,IAAI,IAAI;AAC1B,UAAI,KAAK,MAAM;AACd,WAAG,cAAc,IAAI,YAAY,oBAAoB,EAAE,QAAQ,IAAI,MAAM,SAAS,KAAK,CAAC,CAAC;AAAA,MAC1F;AACA,SAAG,cAAc,IAAI,YAAY,eAAe,EAAE,QAAQ,KAAK,SAAS,KAAK,CAAC,CAAC;AAAA,IAChF,SAAS,KAAK;AACb,UAAI,KAAK,SAAS,YAAa;AAC/B,SAAG,cAAc,IAAI,YAAY,cAAc,EAAE,QAAQ,EAAE,OAAO,KAAK,WAAW,OAAO,GAAG,EAAE,GAAG,SAAS,KAAK,CAAC,CAAC;AAAA,IAClH;AAAA,EACD,CAAC;AACF;AAGO,SAAS,OAAO;AACtB,MAAI,OAAO,aAAa,YAAa;AACrC,WAAS,iBAAiB,sBAAsB,EAAE,QAAQ,WAAW;AACtE;",
|
|
4
|
+
"sourcesContent": ["// Pure, browser-API-free helpers shared by the modal. Kept in their own module\n// so they can be unit-tested in Node without a DOM, and so the core stays lean.\n\n// USDC EIP-3009 typed-data sig works against Base USDC. The domain `version`\n// must match the on-chain `EIP712_DOMAIN_SEPARATOR_VERSION` \u2014 Base USDC is \"2\".\nexport const EVM_NETWORKS = {\n\t'eip155:8453': { chainId: 8453, name: 'Base', explorer: 'https://basescan.org/tx/' },\n\t'eip155:84532': { chainId: 84532, name: 'Base Sepolia', explorer: 'https://sepolia.basescan.org/tx/' },\n\t'eip155:42161': { chainId: 42161, name: 'Arbitrum', explorer: 'https://arbiscan.io/tx/' },\n\t'eip155:10': { chainId: 10, name: 'Optimism', explorer: 'https://optimistic.etherscan.io/tx/' },\n};\n\n// Stablecoins whose atomics are already 6-decimal USD-pegged (used by caps).\nexport const STABLE_NAMES = new Set([\n\t'usdc', 'usd coin', 'usdt', 'tether', 'binance-peg usd coin', 'dai',\n]);\n\n// Normalize a single 402 `accept` entry. The x402 spec's canonical atomic-price\n// field is `maxAmountRequired`; some merchants emit `amount`. We read `amount`\n// everywhere downstream, so coerce here once. Without this a spec-compliant\n// merchant yields `accept.amount === undefined` \u2192 \"NaN USDC\".\nexport function normalizeAccept(accept) {\n\tif (!accept || typeof accept !== 'object') return accept;\n\tconst amount = accept.amount ?? accept.maxAmountRequired;\n\treturn amount != null && accept.amount == null ? { ...accept, amount: String(amount) } : accept;\n}\n\nexport function isSolanaNetwork(net) {\n\treturn typeof net === 'string' && (net === 'solana' || net.startsWith('solana:'));\n}\nexport function isEvmNetwork(net) {\n\treturn typeof net === 'string' && net.startsWith('eip155:');\n}\n// The modal only signs EIP-3009 transferWithAuthorization for EVM. When the\n// server publishes both an EIP-3009 entry and a Permit2 sibling (the\n// gas-sponsoring path), pick the EIP-3009 one \u2014 the sibling carries\n// `extra.assetTransferMethod === 'permit2'`.\nexport function isEip3009Accept(accept) {\n\tif (!isEvmNetwork(accept?.network)) return false;\n\tconst method = accept?.extra?.assetTransferMethod;\n\treturn !method || method === 'eip3009';\n}\nexport function networkLabel(net, accept) {\n\tif (isSolanaNetwork(net)) return 'Solana';\n\tconst meta = EVM_NETWORKS[net];\n\treturn meta?.name || accept?.extra?.name || net;\n}\nexport function explorerUrl(net, tx) {\n\tif (!tx) return null;\n\tif (isSolanaNetwork(net)) return `https://solscan.io/tx/${tx}`;\n\tconst meta = EVM_NETWORKS[net];\n\treturn meta ? `${meta.explorer}${tx}` : null;\n}\n\nexport function formatAmount(rawAtomics, decimals = 6) {\n\tconst n = Number(rawAtomics) / 10 ** decimals;\n\tif (n < 0.01) return n.toFixed(6).replace(/0+$/, '').replace(/\\.$/, '');\n\tif (n < 1) return n.toFixed(4).replace(/0+$/, '').replace(/\\.$/, '');\n\treturn n.toFixed(2);\n}\n\nexport function b64encode(obj) {\n\tconst json = JSON.stringify(obj);\n\tif (typeof Buffer !== 'undefined') return Buffer.from(json, 'utf8').toString('base64');\n\treturn btoa(unescape(encodeURIComponent(json)));\n}\nexport function b64decode(str) {\n\tif (!str) return null;\n\ttry {\n\t\tconst bin = typeof Buffer !== 'undefined' ? Buffer.from(str, 'base64').toString('utf8') : decodeURIComponent(escape(atob(str)));\n\t\treturn JSON.parse(bin);\n\t} catch (_) {\n\t\treturn null;\n\t}\n}\n\n// Base58 (Bitcoin alphabet) \u2014 Solana's encoding for addresses and signatures.\nconst BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';\nexport function base58encode(bytes) {\n\tif (!bytes || bytes.length === 0) return '';\n\tlet leadingZeros = 0;\n\twhile (leadingZeros < bytes.length && bytes[leadingZeros] === 0) leadingZeros++;\n\tlet n = 0n;\n\tfor (let i = 0; i < bytes.length; i++) n = (n << 8n) | BigInt(bytes[i]);\n\tlet out = '';\n\twhile (n > 0n) {\n\t\tout = BASE58_ALPHABET[Number(n % 58n)] + out;\n\t\tn /= 58n;\n\t}\n\tfor (let i = 0; i < leadingZeros; i++) out = BASE58_ALPHABET[0] + out;\n\treturn out;\n}\n\n// Convert an asset's atomic amount to micro-USD for cap accounting. Stablecoins\n// pass through (scaled to 6 decimals); non-stable assets pass through atomic and\n// must be capped server-side (the browser modal fetches no prices).\nexport function toMicroUsd(amount, accept) {\n\tconst atomic = BigInt(amount);\n\tconst decimals = Number(accept?.extra?.decimals ?? 6);\n\tconst name = String(accept?.extra?.name || '').toLowerCase();\n\tif (STABLE_NAMES.has(name)) {\n\t\tif (decimals === 6) return atomic;\n\t\tif (decimals > 6) return atomic / 10n ** BigInt(decimals - 6);\n\t\treturn atomic * 10n ** BigInt(6 - decimals);\n\t}\n\treturn atomic;\n}\n\nexport function spendBuckets(timestamp = Date.now()) {\n\tconst hour = Math.floor(timestamp / 3_600_000);\n\tconst day = Math.floor(timestamp / 86_400_000);\n\treturn { hour, day };\n}\n\n// Build the CAIP-122 SIWX message string. The server rebuilds the same string\n// from payload fields when verifying \u2014 any line-by-line drift makes the\n// recovered signer mismatch payload.address and the signature is rejected.\nexport function buildSiwxMessage(info, chain, address) {\n\tconst isEvm = chain.type === 'eip191';\n\tconst accountHeader = isEvm\n\t\t? `${info.domain} wants you to sign in with your Ethereum account:`\n\t\t: `${info.domain} wants you to sign in with your Solana account:`;\n\tconst [, chainTail = ''] = String(chain.chainId).split(':');\n\tconst chainRef = isEvm ? String(parseInt(chainTail, 10)) : chainTail;\n\n\tconst lines = [accountHeader, address, ''];\n\tif (info.statement) {\n\t\tlines.push(info.statement, '');\n\t} else if (isEvm) {\n\t\t// siwe's prepareMessage() reserves the statement block even when absent,\n\t\t// emitting an extra blank line. SIWS does not.\n\t\tlines.push('');\n\t}\n\tlines.push(`URI: ${info.uri}`);\n\tlines.push(`Version: ${info.version || '1'}`);\n\tlines.push(`Chain ID: ${chainRef}`);\n\tlines.push(`Nonce: ${info.nonce}`);\n\tlines.push(`Issued At: ${info.issuedAt}`);\n\tif (info.expirationTime) lines.push(`Expiration Time: ${info.expirationTime}`);\n\tif (info.notBefore) lines.push(`Not Before: ${info.notBefore}`);\n\tif (info.requestId !== undefined && info.requestId !== null) lines.push(`Request ID: ${info.requestId}`);\n\tif (Array.isArray(info.resources) && info.resources.length) {\n\t\tlines.push('Resources:');\n\t\tfor (const r of info.resources) lines.push(`- ${r}`);\n\t}\n\treturn lines.join('\\n');\n}\n", "// @three-ws/x402-modal \u2014 a drop-in payment modal for any x402 paid endpoint.\n//\n// This is the canonical, side-effect-free core. It exports the public API\n// (`pay`, `init`, `configure`, `getConfig`, `version`, `CheckoutModal`, and the\n// declarative helpers `bindElement` / `readOptsFrom`) but does NOT touch\n// `window` or auto-bind anything on import \u2014 that lives in `global.js`, which is\n// what the CDN <script> build ships.\n//\n// Bundler / npm usage:\n//\n// import { pay, configure } from '@three-ws/x402-modal';\n// const out = await pay({ endpoint: '/api/paid/summarize', body: { text: 'hi' } });\n//\n// Drop-in <script> usage (the global build auto-binds `data-x402-endpoint`):\n//\n// <script type=\"module\" src=\"https://unpkg.com/@three-ws/x402-modal/global\"></script>\n// <button data-x402-endpoint=\"/api/paid/summarize\" data-x402-method=\"POST\">Pay & run</button>\n//\n// The modal drives the full 402 \u2192 connect wallet \u2192 sign \u2192 retry \u2192 settle flow,\n// renders price/network/steps/receipt, and resolves with { ok, result, payment,\n// response }. Vanilla JS; the only network deps (Solana web3.js, a keccak for\n// EVM SIWX) are dynamic-imported from a CDN, and only when that path runs.\n\nimport {\n\tEVM_NETWORKS,\n\tnormalizeAccept,\n\tisSolanaNetwork,\n\tisEip3009Accept,\n\tnetworkLabel,\n\texplorerUrl,\n\tformatAmount,\n\tb64encode,\n\tb64decode,\n\tbase58encode,\n\ttoMicroUsd,\n\tspendBuckets,\n\tbuildSiwxMessage,\n} from './util.js';\n\nconst VERSION = '0.2.0';\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 configuration \u2500\u2500\u2500\n// Everything the host wants to brand or repoint lives here. The defaults are\n// vendor-neutral: no footer attribution and no builder-code echo until the host\n// opts in. A deployment supplies its own branding with `configure()` (global)\n// or per-call `pay({ ... })` options (which always win over the global config).\n\nconst DEFAULTS = {\n\t// Origin that serves the Solana `prepare` / `encode` checkout helpers\n\t// (POST {origin}/api/x402-checkout?action=prepare|encode). Only the Solana\n\t// payment path uses these \u2014 the EVM/EIP-3009 path is fully client-side and\n\t// needs no backend. `null` \u21D2 resolve from the script's own origin at runtime.\n\tapiOrigin: null,\n\t// Footer attribution shown at the bottom of the modal. `null` \u21D2 the footer\n\t// link is hidden until a host sets `{ label, href? }`.\n\tbrand: null,\n\t// ERC-8021 builder-code self-attribution echoed back when the 402 challenge\n\t// declares a builder code. `wallet` = your wallet code, `service` = your\n\t// integration code. `null` \u21D2 no self-attribution unless a host opts in.\n\tbuilderCode: null,\n\t// CDN modules dynamic-imported on demand. Override to self-host / satisfy a\n\t// strict Content-Security-Policy.\n\tsolanaWeb3Url: 'https://esm.sh/@solana/web3.js@1.95.3?bundle',\n\tnobleHashesUrl: 'https://esm.sh/@noble/hashes@1.4.0/sha3?bundle',\n};\n\nconst config = {\n\tapiOrigin: DEFAULTS.apiOrigin,\n\tbrand: DEFAULTS.brand ? { ...DEFAULTS.brand } : null,\n\tbuilderCode: DEFAULTS.builderCode ? { ...DEFAULTS.builderCode } : null,\n\tsolanaWeb3Url: DEFAULTS.solanaWeb3Url,\n\tnobleHashesUrl: DEFAULTS.nobleHashesUrl,\n};\n\n// Resolve the origin that hosts this script \u2014 used as the default API origin for\n// the Solana prepare/encode helpers. Falls back to the page origin.\nfunction resolveScriptOrigin() {\n\ttry {\n\t\tif (typeof document !== 'undefined') {\n\t\t\tconst current = document.currentScript;\n\t\t\tif (current?.src) return new URL(current.src).origin;\n\t\t\tconst found = document.querySelector('script[src*=\"x402\"]');\n\t\t\tif (found?.src) return new URL(found.src).origin;\n\t\t}\n\t} catch (_) {}\n\treturn typeof location !== 'undefined' ? location.origin : '';\n}\n\n// Merge user config in. `apiOrigin: ''` is honoured (same-origin); only\n// `undefined` keeps the default. Returns the resolved snapshot for inspection.\nexport function configure(opts = {}) {\n\tif (!opts || typeof opts !== 'object') return getConfig();\n\tif (opts.apiOrigin !== undefined) config.apiOrigin = opts.apiOrigin;\n\tif (opts.brand === null) config.brand = null;\n\telse if (opts.brand) config.brand = { ...(config.brand || {}), ...opts.brand };\n\tif (opts.builderCode === null) config.builderCode = null;\n\telse if (opts.builderCode) config.builderCode = { ...(config.builderCode || {}), ...opts.builderCode };\n\tif (opts.solanaWeb3Url) config.solanaWeb3Url = opts.solanaWeb3Url;\n\tif (opts.nobleHashesUrl) config.nobleHashesUrl = opts.nobleHashesUrl;\n\treturn getConfig();\n}\n\nexport function getConfig() {\n\treturn {\n\t\tapiOrigin: config.apiOrigin,\n\t\tbrand: config.brand ? { ...config.brand } : null,\n\t\tbuilderCode: config.builderCode ? { ...config.builderCode } : null,\n\t\tsolanaWeb3Url: config.solanaWeb3Url,\n\t\tnobleHashesUrl: config.nobleHashesUrl,\n\t};\n}\n\n// The effective API origin for a given pay() call: explicit per-call > global\n// config > lazily-resolved script origin (cached back into config).\nfunction apiOriginFor(opts) {\n\tif (opts && opts.apiOrigin !== undefined && opts.apiOrigin !== null) return opts.apiOrigin;\n\tif (config.apiOrigin !== null && config.apiOrigin !== undefined) return config.apiOrigin;\n\tconfig.apiOrigin = resolveScriptOrigin();\n\treturn config.apiOrigin;\n}\n\n// SIWX (\"Sign-In-With-X\" / CAIP-122) lets a wallet that has already paid for\n// an endpoint re-enter it by signing a challenge instead of paying again. The\n// server advertises support by including `extensions['sign-in-with-x']` in the\n// 402 body; clients submit signed proofs via the `SIGN-IN-WITH-X` header.\nconst SIWX_HEADER = 'SIGN-IN-WITH-X';\nconst SIWX_EXTENSION_KEY = 'sign-in-with-x';\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 Spending caps \u2500\u2500\u2500\u2500\u2500\n// Persists per-wallet spend in localStorage so reload-survivable caps work in a\n// pure-browser context. Keys are bucketed by UTC hour and UTC day so the\n// sliding windows reset cleanly at midnight UTC for the daily case. Amounts are\n// stored as base-10 BigInt strings of micro-USD; stablecoin payments flow\n// through as-is since their atomics are already 6-decimal USD-pegged.\n\nconst SPEND_LS_PREFIX = 'x402.spend.';\n\nfunction spendKey(address, kind, bucket) {\n\treturn `${SPEND_LS_PREFIX}${kind}.${address.toLowerCase()}.${bucket}`;\n}\n\nfunction readSpend(address, kind, bucket) {\n\ttry {\n\t\tconst raw = localStorage.getItem(spendKey(address, kind, bucket));\n\t\tif (!raw) return 0n;\n\t\treturn BigInt(raw);\n\t} catch {\n\t\treturn 0n;\n\t}\n}\n\nfunction writeSpend(address, kind, bucket, value) {\n\ttry {\n\t\tlocalStorage.setItem(spendKey(address, kind, bucket), value.toString());\n\t} catch {\n\t\t// localStorage full / disabled \u2014 caps degrade to per-call only.\n\t}\n}\n\n// Check the configured caps and, if admitted, reserve the spend in localStorage.\n// Returns { abort, reason?, reservation? }. Reservation carries { address,\n// microUsd, buckets } so a failed payment can roll the reservation back.\nfunction browserEnforceCap({ accept, caps, address }) {\n\tif (!caps || !address) return { abort: false };\n\tconst microUsd = toMicroUsd(accept.amount, accept);\n\tconst maxPerCall = caps.maxPerCall != null ? BigInt(caps.maxPerCall) : null;\n\tconst maxPerHour = caps.maxPerHour != null ? BigInt(caps.maxPerHour) : null;\n\tconst maxPerDay = caps.maxPerDay != null ? BigInt(caps.maxPerDay) : null;\n\tif (maxPerCall != null && microUsd > maxPerCall) {\n\t\treturn { abort: true, reason: `Per-call cap exceeded (${microUsd} > ${maxPerCall} \u00B5USD)` };\n\t}\n\tconst buckets = spendBuckets();\n\tconst hourTotal = readSpend(address, 'hr', buckets.hour) + microUsd;\n\tconst dayTotal = readSpend(address, 'day', buckets.day) + microUsd;\n\tif (maxPerHour != null && hourTotal > maxPerHour) {\n\t\treturn { abort: true, reason: `Hourly cap exceeded (${hourTotal} > ${maxPerHour} \u00B5USD)` };\n\t}\n\tif (maxPerDay != null && dayTotal > maxPerDay) {\n\t\treturn { abort: true, reason: `Daily cap exceeded (${dayTotal} > ${maxPerDay} \u00B5USD)` };\n\t}\n\twriteSpend(address, 'hr', buckets.hour, hourTotal);\n\twriteSpend(address, 'day', buckets.day, dayTotal);\n\treturn { abort: false, reservation: { address, microUsd, buckets } };\n}\n\nfunction browserRollbackReservation(reservation) {\n\tif (!reservation) return;\n\tconst { address, microUsd, buckets } = reservation;\n\tconst hourCurrent = readSpend(address, 'hr', buckets.hour);\n\tconst dayCurrent = readSpend(address, 'day', buckets.day);\n\tconst hourNext = hourCurrent - microUsd;\n\tconst dayNext = dayCurrent - microUsd;\n\twriteSpend(address, 'hr', buckets.hour, hourNext < 0n ? 0n : hourNext);\n\twriteSpend(address, 'day', buckets.day, dayNext < 0n ? 0n : dayNext);\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 ERC-8021 builder-code echo \u2500\u2500\u2500\u2500\n// The server enforces that any client-echoed builder-code `a` matches what the\n// 402 challenge declared (anti-tamper). We self-attribute `w` (wallet) and `s`\n// (service) from config; both are validated against the strict code pattern.\n\nconst BUILDER_CODE_KEY = 'builder-code';\nconst BUILDER_CODE_PATTERN = /^[a-z0-9_]{1,32}$/;\n\nfunction buildBuilderCodeEcho(challenge) {\n\tconst codes = config.builderCode;\n\tif (!codes) return null;\n\tconst ext = challenge?.extensions?.[BUILDER_CODE_KEY];\n\tconst declaredA = ext?.info?.a;\n\tif (!declaredA || !BUILDER_CODE_PATTERN.test(declaredA)) return null;\n\tconst out = { a: declaredA };\n\tif (codes.service && BUILDER_CODE_PATTERN.test(codes.service)) out.s = [codes.service];\n\tif (codes.wallet && BUILDER_CODE_PATTERN.test(codes.wallet)) out.w = codes.wallet;\n\treturn out;\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 SIWX helpers \u2500\u2500\u2500\u2500\n\nfunction extractSiwxExtension(body) {\n\tconst ext = body?.extensions?.[SIWX_EXTENSION_KEY];\n\tif (!ext || !ext.info || !Array.isArray(ext.supportedChains) || !ext.supportedChains.length) return null;\n\treturn ext;\n}\n\n// Returns { chain, kind: 'evm' | 'solana' } or null. `chain` is the matching\n// entry from `ext.supportedChains` whose signature type matches the wallet kind.\nfunction pickSiwxChain(ext, walletKind) {\n\tfor (const chain of ext.supportedChains) {\n\t\tif (walletKind === 'evm' && chain.type === 'eip191') return { chain, kind: 'evm' };\n\t\tif (walletKind === 'solana' && chain.type === 'ed25519') return { chain, kind: 'solana' };\n\t}\n\treturn null;\n}\n\n// Base64-encoded JSON per x402 v2 spec. CAIP-122 fields are all ASCII/Latin-1,\n// so the unescape+encodeURIComponent dance matches what btoa expects.\nfunction encodeSiwxHeaderValue(payload) {\n\tconst json = JSON.stringify(payload);\n\tif (typeof Buffer !== 'undefined') return Buffer.from(json, 'utf8').toString('base64');\n\treturn btoa(unescape(encodeURIComponent(json)));\n}\n\n// EIP-55 checksum the address before signing. MetaMask returns lowercase\n// addresses, but the server rebuilds the SIWE message with a checksummed\n// address. If we sign a lowercase-address message and send the lowercase\n// address in the payload, the recovered signer differs and verification fails.\n// Keccak-256 is dynamic-imported from a CDN only when SIWX EVM sign-in runs.\nlet _evmChecksum = null;\nasync function loadEvmChecksum() {\n\tif (_evmChecksum) return _evmChecksum;\n\tconst sha3 = await import(/* @vite-ignore */ config.nobleHashesUrl);\n\tconst keccak = sha3.keccak_256;\n\t_evmChecksum = (addr) => {\n\t\tconst a = String(addr).toLowerCase().replace(/^0x/, '');\n\t\tif (!/^[0-9a-f]{40}$/.test(a)) throw new Error(`invalid EVM address: ${addr}`);\n\t\tconst hashBytes = keccak(new TextEncoder().encode(a));\n\t\tlet hex = '';\n\t\tfor (let i = 0; i < hashBytes.length; i++) hex += hashBytes[i].toString(16).padStart(2, '0');\n\t\tlet out = '0x';\n\t\tfor (let i = 0; i < 40; i++) {\n\t\t\tout += parseInt(hex[i], 16) >= 8 ? a[i].toUpperCase() : a[i];\n\t\t}\n\t\treturn out;\n\t};\n\treturn _evmChecksum;\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 styles \u2500\u2500\u2500\u2500\n\nconst STYLE_ID = 'x402-styles';\nconst STYLES = `\n:root {\n\t--x402-z: 2147483600;\n}\n.x402-overlay {\n\tposition: fixed; inset: 0;\n\tbackground: rgba(8, 10, 18, 0.55);\n\tbackdrop-filter: blur(10px);\n\t-webkit-backdrop-filter: blur(10px);\n\tdisplay: flex; align-items: center; justify-content: center;\n\tz-index: var(--x402-z);\n\topacity: 0; transition: opacity 0.16s ease-out;\n\tfont-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n\t-webkit-font-smoothing: antialiased;\n\tcolor: #0f0f0f;\n}\n.x402-overlay.x402-open { opacity: 1; }\n.x402-overlay * { box-sizing: border-box; }\n.x402-modal {\n\twidth: calc(100% - 32px); max-width: 420px;\n\tbackground: #ffffff;\n\tborder-radius: 18px;\n\tbox-shadow: 0 24px 80px rgba(8, 10, 18, 0.28), 0 4px 16px rgba(8, 10, 18, 0.12);\n\toverflow: hidden;\n\ttransform: translateY(8px) scale(0.985);\n\ttransition: transform 0.18s ease-out;\n\tdisplay: flex; flex-direction: column;\n\tmax-height: calc(100dvh - 32px);\n}\n.x402-overlay.x402-open .x402-modal { transform: translateY(0) scale(1); }\n.x402-head {\n\tpadding: 18px 20px 14px;\n\tborder-bottom: 1px solid #eef0f4;\n\tdisplay: flex; align-items: center; gap: 12px;\n}\n.x402-head .x402-merchant {\n\tflex: 1; min-width: 0;\n}\n.x402-merchant .x402-name {\n\tfont-size: 12px; color: #5a6378; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase;\n\tmargin-bottom: 2px;\n}\n.x402-merchant .x402-action {\n\tfont-size: 17px; font-weight: 700; color: #0f0f0f;\n\twhite-space: nowrap; overflow: hidden; text-overflow: ellipsis;\n\tletter-spacing: -0.01em;\n}\n.x402-close {\n\twidth: 32px; height: 32px;\n\tborder-radius: 8px; border: none; background: #f3f4f7;\n\tfont-size: 16px; color: #5a6378; cursor: pointer;\n\tdisplay: flex; align-items: center; justify-content: center;\n\ttransition: background 0.12s;\n}\n.x402-close:hover { background: #e7e9ee; color: #0f0f0f; }\n\n.x402-price-row {\n\tpadding: 18px 20px;\n\tdisplay: flex; align-items: baseline; justify-content: space-between;\n\tbackground: linear-gradient(180deg, #fafbfc 0%, #ffffff 100%);\n\tborder-bottom: 1px solid #eef0f4;\n}\n.x402-price {\n\tfont-size: 32px; font-weight: 700; letter-spacing: -0.02em; color: #0f0f0f;\n\tfont-variant-numeric: tabular-nums;\n}\n.x402-price .x402-currency { font-size: 14px; color: #5a6378; font-weight: 600; margin-left: 6px; letter-spacing: 0; }\n.x402-network {\n\tfont-size: 12px; color: #5a6378; font-weight: 500;\n\tbackground: #f3f4f7; padding: 5px 10px; border-radius: 99px;\n\tdisplay: inline-flex; align-items: center; gap: 6px;\n}\n.x402-network::before {\n\tcontent: ''; width: 6px; height: 6px; border-radius: 50%;\n\tbackground: #22c55e;\n}\n\n.x402-body {\n\tpadding: 16px 20px 18px;\n\tflex: 1 1 auto; overflow-y: auto;\n\tdisplay: flex; flex-direction: column; gap: 10px;\n}\n.x402-step {\n\tdisplay: flex; gap: 12px; align-items: flex-start;\n\tpadding: 10px 0;\n}\n.x402-step + .x402-step { border-top: 1px solid #f3f4f7; }\n.x402-step-num {\n\twidth: 22px; height: 22px; flex: 0 0 auto;\n\tborder-radius: 50%; border: 1.5px solid #d0d4dd; background: #fff;\n\tcolor: #5a6378;\n\tfont-size: 11px; font-weight: 700;\n\tdisplay: flex; align-items: center; justify-content: center;\n}\n.x402-step.x402-active .x402-step-num {\n\tborder-color: #0a84ff; background: #0a84ff; color: #fff;\n\tanimation: x402-spin 1.2s linear infinite;\n}\n.x402-step.x402-done .x402-step-num {\n\tborder-color: #22c55e; background: #22c55e; color: #fff;\n}\n.x402-step.x402-error .x402-step-num {\n\tborder-color: #ef4444; background: #ef4444; color: #fff;\n}\n@keyframes x402-spin {\n\tfrom { box-shadow: 0 0 0 0 rgba(10, 132, 255, 0.4); }\n\tto { box-shadow: 0 0 0 8px rgba(10, 132, 255, 0); }\n}\n.x402-step-body { flex: 1; min-width: 0; }\n.x402-step-label { font-size: 14px; font-weight: 600; color: #0f0f0f; line-height: 1.35; }\n.x402-step-meta { font-size: 12px; color: #5a6378; margin-top: 2px; font-feature-settings: 'tnum' 1; }\n.x402-step.x402-error .x402-step-meta { color: #ef4444; }\n\n.x402-wallet-buttons {\n\tdisplay: flex; flex-direction: column; gap: 8px;\n\tmargin-top: 4px;\n}\n.x402-wallet-btn {\n\twidth: 100%; padding: 13px 14px;\n\tbackground: #ffffff; border: 1.5px solid #e2e5ec; border-radius: 11px;\n\tfont-size: 14px; font-weight: 600; color: #0f0f0f;\n\tcursor: pointer; font-family: inherit;\n\tdisplay: flex; align-items: center; gap: 12px;\n\ttransition: border-color 0.12s, background 0.12s, transform 0.05s;\n}\n.x402-wallet-btn:hover:not(:disabled) { border-color: #0a84ff; background: #f7faff; }\n.x402-wallet-btn:active:not(:disabled) { transform: translateY(1px); }\n.x402-wallet-btn:disabled { opacity: 0.45; cursor: not-allowed; }\n.x402-wallet-icon {\n\twidth: 28px; height: 28px; flex: 0 0 auto;\n\tborder-radius: 7px;\n\tdisplay: flex; align-items: center; justify-content: center;\n\tfont-size: 16px;\n\tbackground: #f3f4f7;\n}\n.x402-wallet-icon.x402-phantom { background: linear-gradient(135deg, #ab9ff2, #534bb1); color: #fff; }\n.x402-wallet-icon.x402-metamask { background: linear-gradient(135deg, #f6851b, #e2761b); color: #fff; }\n.x402-wallet-name { flex: 1; text-align: left; }\n.x402-wallet-meta { font-size: 11px; color: #8a90a8; font-weight: 500; }\n\n.x402-pay-btn {\n\twidth: 100%; padding: 14px 16px;\n\tbackground: #0f0f0f; color: #fff; border: none;\n\tborder-radius: 12px;\n\tfont-size: 15px; font-weight: 700; font-family: inherit;\n\tcursor: pointer; letter-spacing: -0.005em;\n\ttransition: background 0.12s, transform 0.05s;\n\tmargin-top: 4px;\n\tdisplay: flex; align-items: center; justify-content: center; gap: 8px;\n}\n.x402-pay-btn:hover:not(:disabled) { background: #1d1d1d; }\n.x402-pay-btn:active:not(:disabled) { transform: translateY(1px); }\n.x402-pay-btn:disabled { background: #c8ccd4; cursor: not-allowed; }\n\n.x402-pay-secondary {\n\twidth: 100%; padding: 12px 14px;\n\tbackground: #ffffff; color: #0f0f0f;\n\tborder: 1.5px solid #e2e5ec; border-radius: 11px;\n\tfont-size: 14px; font-weight: 600; font-family: inherit;\n\tcursor: pointer; letter-spacing: -0.005em;\n\tmargin-top: 6px;\n\ttransition: border-color 0.12s, background 0.12s, transform 0.05s;\n}\n.x402-pay-secondary:hover:not(:disabled) { border-color: #0a84ff; background: #f7faff; }\n.x402-pay-secondary:active:not(:disabled) { transform: translateY(1px); }\n\n.x402-siwx-hint {\n\tfont-size: 11px; color: #5a6378; text-align: center;\n\tmargin-top: 8px; line-height: 1.4;\n}\n.x402-siwx-fallback {\n\tfont-size: 12px; color: #b45309; line-height: 1.45;\n\tpadding: 8px 10px; border-radius: 8px;\n\tbackground: #fffbeb; border: 1px solid #fde68a;\n\tmargin-bottom: 6px;\n}\n\n.x402-error-box {\n\tpadding: 12px 14px; border-radius: 10px;\n\tbackground: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;\n\tfont-size: 13px; line-height: 1.45;\n\tfont-family: ui-monospace, \"JetBrains Mono\", Menlo, monospace;\n\tword-break: break-word;\n}\n.x402-error-box strong { font-weight: 700; }\n\n.x402-receipt {\n\tpadding: 14px 16px; border-radius: 12px;\n\tbackground: linear-gradient(180deg, #f0fdf4 0%, #ffffff 100%);\n\tborder: 1px solid #bbf7d0;\n}\n.x402-receipt-title {\n\tfont-size: 11px; font-weight: 700; color: #15803d;\n\ttext-transform: uppercase; letter-spacing: 0.06em;\n\tmargin-bottom: 8px;\n\tdisplay: flex; align-items: center; gap: 6px;\n}\n.x402-receipt-title::before { content: '\u2713'; font-size: 14px; }\n.x402-receipt-row {\n\tdisplay: flex; justify-content: space-between; gap: 12px;\n\tfont-size: 12px; padding: 2px 0;\n\tfont-family: ui-monospace, \"JetBrains Mono\", Menlo, monospace;\n}\n.x402-receipt-row .x402-k { color: #5a6378; }\n.x402-receipt-row .x402-v { color: #0f0f0f; text-align: right; word-break: break-all; }\n.x402-receipt-row a { color: #0a84ff; text-decoration: none; }\n.x402-receipt-row a:hover { text-decoration: underline; }\n\n.x402-result {\n\tpadding: 12px 14px; border-radius: 10px;\n\tbackground: #fafbfc; border: 1px solid #e2e5ec;\n\tmax-height: 240px; overflow: auto;\n\tfont-family: ui-monospace, \"JetBrains Mono\", Menlo, monospace;\n\tfont-size: 12px; line-height: 1.5; color: #0f0f0f;\n\twhite-space: pre-wrap; word-break: break-word;\n}\n\n.x402-foot {\n\tpadding: 10px 20px 14px;\n\tborder-top: 1px solid #eef0f4;\n\tdisplay: flex; align-items: center; justify-content: space-between;\n\tfont-size: 11px; color: #8a90a8;\n}\n.x402-foot a { color: #5a6378; text-decoration: none; font-weight: 600; }\n.x402-foot a:hover { color: #0f0f0f; }\n.x402-foot .x402-secure { display: flex; align-items: center; gap: 5px; }\n.x402-foot .x402-secure::before { content: '\uD83D\uDD12'; font-size: 10px; }\n\n@media (max-width: 480px) {\n\t.x402-modal { max-width: none; width: calc(100% - 16px); border-radius: 16px; }\n\t.x402-price { font-size: 26px; }\n}\n\n@media (prefers-color-scheme: dark) {\n\t.x402-overlay { color: #e6e8f0; }\n\t.x402-modal { background: #161616; box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6); }\n\t.x402-head, .x402-price-row, .x402-foot { border-color: #272727; }\n\t.x402-step + .x402-step { border-top-color: #272727; }\n\t.x402-merchant .x402-name { color: #8a90a8; }\n\t.x402-merchant .x402-action, .x402-price, .x402-step-label { color: #e6e8f0; }\n\t.x402-step-meta { color: #8a90a8; }\n\t.x402-close { background: #222222; color: #8a90a8; }\n\t.x402-close:hover { background: #2e2e2e; color: #e6e8f0; }\n\t.x402-price-row { background: linear-gradient(180deg, #1d1d1d 0%, #161616 100%); }\n\t.x402-network { background: #222222; color: #b0b6cc; }\n\t.x402-wallet-btn { background: #1d1d1d; border-color: #2e2e2e; color: #e6e8f0; }\n\t.x402-wallet-btn:hover:not(:disabled) { background: #252525; border-color: #0a84ff; }\n\t.x402-wallet-icon { background: #2e2e2e; }\n\t.x402-wallet-meta { color: #6b7088; }\n\t.x402-pay-btn { background: #ffffff; color: #0f0f0f; }\n\t.x402-pay-btn:hover:not(:disabled) { background: #e7e9ee; }\n\t.x402-pay-btn:disabled { background: #2e2e2e; color: #5a6378; }\n\t.x402-pay-secondary { background: #1d1d1d; border-color: #2e2e2e; color: #e6e8f0; }\n\t.x402-pay-secondary:hover:not(:disabled) { background: #252525; border-color: #0a84ff; }\n\t.x402-siwx-hint { color: #8a90a8; }\n\t.x402-siwx-fallback { background: #2a1d10; border-color: #78350f; color: #fcd34d; }\n\t.x402-step-num { background: #161616; border-color: #2e2e2e; color: #8a90a8; }\n\t.x402-result { background: #1d1d1d; border-color: #2e2e2e; color: #e6e8f0; }\n\t.x402-receipt { background: linear-gradient(180deg, #0b1f17 0%, #161616 100%); border-color: #14532d; }\n\t.x402-receipt-title { color: #4ade80; }\n\t.x402-receipt-row .x402-k { color: #8a90a8; }\n\t.x402-receipt-row .x402-v { color: #e6e8f0; }\n\t.x402-receipt-row a { color: #60a5fa; }\n\t.x402-error-box { background: #1f1416; border-color: #7f1d1d; color: #fca5a5; }\n\t.x402-foot a { color: #b0b6cc; }\n\t.x402-foot a:hover { color: #ffffff; }\n}\n`;\n\nfunction injectStyles() {\n\tif (typeof document === 'undefined' || document.getElementById(STYLE_ID)) return;\n\tconst el = document.createElement('style');\n\tel.id = STYLE_ID;\n\tel.textContent = STYLES;\n\tdocument.head.appendChild(el);\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 modal class \u2500\u2500\u2500\n\nexport class CheckoutModal {\n\tconstructor(opts) {\n\t\tthis.opts = opts;\n\t\tthis.steps = [\n\t\t\t{ id: 'discover', label: 'Confirming price' },\n\t\t\t{ id: 'connect', label: 'Connect wallet' },\n\t\t\t{ id: 'authorize', label: 'Authorize payment' },\n\t\t\t{ id: 'verify', label: 'Verify & complete' },\n\t\t];\n\t\tthis.activeNetwork = null;\n\t\tthis.payerAddress = null;\n\t\tthis.accept = null;\n\t\tthis.challenge = null;\n\t\tthis.disposed = false;\n\t\t// One-shot guard for opts.autoConnect: we only auto-open the wallet on the\n\t\t// first connect render, so an error that drops the user back to this step\n\t\t// shows the manual picker instead of re-launching the wallet in a loop.\n\t\tthis.autoConnectTried = false;\n\t}\n\n\t_apiOrigin() {\n\t\treturn apiOriginFor(this.opts);\n\t}\n\n\tmount() {\n\t\tinjectStyles();\n\t\tconst brand = this.opts.brand || config.brand || {};\n\t\tconst overlay = document.createElement('div');\n\t\toverlay.className = 'x402-overlay';\n\t\tconst brandHtml = brand.href\n\t\t\t? `<a href=\"${escapeHtml(brand.href)}\" target=\"_blank\" rel=\"noopener\">${escapeHtml(brand.label || brand.href)}</a>`\n\t\t\t: brand.label\n\t\t\t\t? `<span>${escapeHtml(brand.label)}</span>`\n\t\t\t\t: '';\n\t\toverlay.innerHTML = `\n\t\t\t<div class=\"x402-modal\" role=\"dialog\" aria-modal=\"true\" aria-label=\"x402 payment\">\n\t\t\t\t<div class=\"x402-head\">\n\t\t\t\t\t<div class=\"x402-merchant\">\n\t\t\t\t\t\t<div class=\"x402-name\" data-merchant>${escapeHtml(this.opts.merchant || 'Payment')}</div>\n\t\t\t\t\t\t<div class=\"x402-action\" data-action>${escapeHtml(this.opts.action || 'Pay-per-call')}</div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<button class=\"x402-close\" data-close aria-label=\"Close\">\u2715</button>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"x402-price-row\">\n\t\t\t\t\t<div class=\"x402-price\" data-price>\u2014<span class=\"x402-currency\"> USDC</span></div>\n\t\t\t\t\t<div class=\"x402-network\" data-network>resolving\u2026</div>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"x402-body\" data-body></div>\n\t\t\t\t<div class=\"x402-foot\">\n\t\t\t\t\t<span class=\"x402-secure\">x402 \u00B7 onchain settled</span>\n\t\t\t\t\t${brandHtml}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t`;\n\t\tdocument.body.appendChild(overlay);\n\t\tthis.overlay = overlay;\n\t\tthis.bodyEl = overlay.querySelector('[data-body]');\n\t\tthis.priceEl = overlay.querySelector('[data-price]');\n\t\tthis.networkEl = overlay.querySelector('[data-network]');\n\t\toverlay.querySelector('[data-close]').addEventListener('click', () => this.close('cancelled'));\n\t\toverlay.addEventListener('click', (e) => { if (e.target === overlay) this.close('cancelled'); });\n\t\tthis.onKey = (e) => { if (e.key === 'Escape') this.close('cancelled'); };\n\t\tdocument.addEventListener('keydown', this.onKey);\n\t\trequestAnimationFrame(() => overlay.classList.add('x402-open'));\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.resolve = resolve;\n\t\t\tthis.reject = reject;\n\t\t});\n\t}\n\n\tclose(reason) {\n\t\tif (this.disposed) return;\n\t\tthis.disposed = true;\n\t\tdocument.removeEventListener('keydown', this.onKey);\n\t\tthis.overlay.classList.remove('x402-open');\n\t\tsetTimeout(() => this.overlay.remove(), 180);\n\t\tif (reason === 'cancelled' && this.reject) {\n\t\t\tconst err = new Error('cancelled');\n\t\t\terr.code = 'cancelled';\n\t\t\tthis.reject(err);\n\t\t}\n\t}\n\n\trenderSteps(activeId, status = {}) {\n\t\tconst html = this.steps\n\t\t\t.map((s) => {\n\t\t\t\tconst state = status[s.id] || (s.id === activeId ? 'active' : 'idle');\n\t\t\t\tconst cls = state === 'active' ? 'x402-active' : state === 'done' ? 'x402-done' : state === 'error' ? 'x402-error' : '';\n\t\t\t\tconst meta = status[`${s.id}_meta`] || '';\n\t\t\t\tconst sym = state === 'done' ? '\u2713' : state === 'error' ? '!' : s.id === activeId && state === 'active' ? ' ' : (this.steps.findIndex((x) => x.id === s.id) + 1);\n\t\t\t\treturn `<div class=\"x402-step ${cls}\">\n\t\t\t\t\t<div class=\"x402-step-num\">${sym}</div>\n\t\t\t\t\t<div class=\"x402-step-body\">\n\t\t\t\t\t\t<div class=\"x402-step-label\">${s.label}</div>\n\t\t\t\t\t\t${meta ? `<div class=\"x402-step-meta\">${escapeHtml(meta)}</div>` : ''}\n\t\t\t\t\t</div>\n\t\t\t\t</div>`;\n\t\t\t})\n\t\t\t.join('');\n\t\treturn html;\n\t}\n\n\tsetPrice(accept) {\n\t\tconst decimals = accept.extra?.decimals ?? 6;\n\t\tconst amount = formatAmount(accept.amount, decimals);\n\t\tconst sym = (accept.extra?.name || 'USDC').replace(/^USD Coin$/, 'USDC');\n\t\tthis.priceEl.innerHTML = `${amount}<span class=\"x402-currency\"> ${sym}</span>`;\n\t\tthis.networkEl.textContent = networkLabel(accept.network, accept);\n\t}\n\n\trenderConnect() {\n\t\tconst phantomDetected = typeof window !== 'undefined' && (window.solana?.isPhantom || window.phantom?.solana);\n\t\tconst evmDetected = typeof window !== 'undefined' && window.ethereum;\n\t\tconst solanaAccept = this.challenge?.accepts.find((a) => isSolanaNetwork(a.network));\n\t\tconst evmAccept = this.challenge?.accepts.find(isEip3009Accept);\n\n\t\t// SIWX-first path: when the 402 advertises sign-in-with-x AND we have a\n\t\t// compatible wallet, lead with \"Sign in with wallet\" (primary) and demote\n\t\t// pay to a secondary action. payFlowOverride is set true when the user\n\t\t// explicitly chooses to pay.\n\t\tif (this.siwx && !this.payFlowOverride) {\n\t\t\tconst siwxSolana = phantomDetected ? pickSiwxChain(this.siwx, 'solana') : null;\n\t\t\tconst siwxEvm = evmDetected ? pickSiwxChain(this.siwx, 'evm') : null;\n\t\t\tif (siwxSolana || siwxEvm) {\n\t\t\t\tthis.renderSiwxChoice({ siwxSolana, siwxEvm });\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// autoConnect (opt-in via opts.autoConnect): when the caller knows the user\n\t\t// is wallet-ready and shouldn't have to pick, skip the picker and go\n\t\t// straight to the signature \u2014 but only when exactly one supported wallet is\n\t\t// actually detected. One-shot via autoConnectTried.\n\t\tif (this.opts.autoConnect && !this.autoConnectTried && !this.siwxFallbackNotice) {\n\t\t\tthis.autoConnectTried = true;\n\t\t\tconst solanaViable = !!(solanaAccept && phantomDetected);\n\t\t\tconst evmViable = !!(evmAccept && evmDetected);\n\t\t\tif (solanaViable && !evmViable) { this.runSolana(solanaAccept); return; }\n\t\t\tif (evmViable && !solanaViable) { this.runEvm(evmAccept); return; }\n\t\t}\n\n\t\tconst buttons = [];\n\t\tif (solanaAccept) {\n\t\t\tbuttons.push(`\n\t\t\t\t<button class=\"x402-wallet-btn\" data-wallet=\"phantom\" ${phantomDetected ? '' : 'disabled'}>\n\t\t\t\t\t<div class=\"x402-wallet-icon x402-phantom\">P</div>\n\t\t\t\t\t<span class=\"x402-wallet-name\">${phantomDetected ? 'Phantom' : 'Phantom (not detected)'}</span>\n\t\t\t\t\t<span class=\"x402-wallet-meta\">${networkLabel(solanaAccept.network, solanaAccept)}</span>\n\t\t\t\t</button>\n\t\t\t`);\n\t\t}\n\t\tif (evmAccept) {\n\t\t\tbuttons.push(`\n\t\t\t\t<button class=\"x402-wallet-btn\" data-wallet=\"evm\" ${evmDetected ? '' : 'disabled'}>\n\t\t\t\t\t<div class=\"x402-wallet-icon x402-metamask\">M</div>\n\t\t\t\t\t<span class=\"x402-wallet-name\">${evmDetected ? 'Browser wallet' : 'No EVM wallet detected'}</span>\n\t\t\t\t\t<span class=\"x402-wallet-meta\">${networkLabel(evmAccept.network, evmAccept)}</span>\n\t\t\t\t</button>\n\t\t\t`);\n\t\t}\n\t\tconst fallbackBox = this.siwxFallbackNotice\n\t\t\t? `<div class=\"x402-siwx-fallback\">${escapeHtml(this.siwxFallbackNotice)}</div>`\n\t\t\t: '';\n\t\tthis.bodyEl.innerHTML = `\n\t\t\t${this.renderSteps('connect', { discover: 'done' })}\n\t\t\t${fallbackBox}\n\t\t\t<div class=\"x402-wallet-buttons\">${buttons.join('')}</div>\n\t\t`;\n\t\tconst onClick = (e) => {\n\t\t\tconst btn = e.target.closest('[data-wallet]');\n\t\t\tif (!btn || btn.disabled) return;\n\t\t\tconst wallet = btn.dataset.wallet;\n\t\t\tif (wallet === 'phantom') this.runSolana(solanaAccept);\n\t\t\telse if (wallet === 'evm') this.runEvm(evmAccept);\n\t\t};\n\t\tthis.bodyEl.querySelectorAll('[data-wallet]').forEach((b) => b.addEventListener('click', onClick));\n\t}\n\n\trenderSiwxChoice({ siwxSolana, siwxEvm }) {\n\t\tconst priceText = formatAmount(this.accept.amount, this.accept.extra?.decimals ?? 6);\n\t\tconst siwxTarget = siwxSolana\n\t\t\t? { kind: 'solana', chain: siwxSolana.chain }\n\t\t\t: { kind: 'evm', chain: siwxEvm.chain };\n\t\tconst siwxLabel = siwxTarget.kind === 'solana' ? 'Sign in with Phantom' : 'Sign in with wallet';\n\t\tthis.bodyEl.innerHTML = `\n\t\t\t${this.renderSteps('connect', { discover: 'done' })}\n\t\t\t<button class=\"x402-pay-btn\" data-action=\"siwx\">${siwxLabel}</button>\n\t\t\t<button class=\"x402-pay-secondary\" data-action=\"pay\">Pay ${priceText} USDC instead</button>\n\t\t\t<div class=\"x402-siwx-hint\">Already paid for this once? Sign in to re-enter without paying again.</div>\n\t\t`;\n\t\tconst siwxBtn = this.bodyEl.querySelector('[data-action=\"siwx\"]');\n\t\tconst payBtn = this.bodyEl.querySelector('[data-action=\"pay\"]');\n\t\tsiwxBtn.addEventListener('click', () => {\n\t\t\tif (siwxTarget.kind === 'solana') this.runSiwxSolana(siwxTarget.chain);\n\t\t\telse this.runSiwxEvm(siwxTarget.chain);\n\t\t});\n\t\tpayBtn.addEventListener('click', () => {\n\t\t\tthis.payFlowOverride = true;\n\t\t\tthis.renderConnect();\n\t\t});\n\t\trequestAnimationFrame(() => siwxBtn.focus());\n\t}\n\n\trenderProgress(activeId, meta = {}) {\n\t\tthis.bodyEl.innerHTML = this.renderSteps(activeId, {\n\t\t\tdiscover: 'done',\n\t\t\tconnect: 'done',\n\t\t\t...(activeId === 'verify' ? { authorize: 'done' } : {}),\n\t\t\t[`${activeId}_meta`]: meta.text || '',\n\t\t\t...meta.statuses,\n\t\t});\n\t}\n\n\trenderError(stepId, message) {\n\t\tthis.bodyEl.innerHTML = `\n\t\t\t${this.renderSteps(stepId, {\n\t\t\t\t...(stepId !== 'discover' ? { discover: 'done' } : {}),\n\t\t\t\t...(stepId === 'authorize' || stepId === 'verify' ? { connect: 'done' } : {}),\n\t\t\t\t...(stepId === 'verify' ? { authorize: 'done' } : {}),\n\t\t\t\t[stepId]: 'error',\n\t\t\t\t[`${stepId}_meta`]: 'failed',\n\t\t\t})}\n\t\t\t<div class=\"x402-error-box\"><strong>${escapeHtml(stepId)}:</strong> ${escapeHtml(message)}</div>\n\t\t\t<button class=\"x402-pay-btn\" data-retry>Try again</button>\n\t\t`;\n\t\tthis.bodyEl.querySelector('[data-retry]').addEventListener('click', () => this.start());\n\t}\n\n\trenderDone({ result, payment, siwx }) {\n\t\tconst resultStr = typeof result === 'string' ? result : JSON.stringify(result, null, 2);\n\t\tlet receiptHtml;\n\t\tif (siwx) {\n\t\t\tconst addrShort = siwx.address ? `${siwx.address.slice(0, 8)}\u2026${siwx.address.slice(-6)}` : '\u2014';\n\t\t\treceiptHtml = `\n\t\t\t\t<div class=\"x402-receipt\">\n\t\t\t\t\t<div class=\"x402-receipt-title\">Welcome back!</div>\n\t\t\t\t\t<div class=\"x402-receipt-row\">\n\t\t\t\t\t\t<span class=\"x402-k\">network</span>\n\t\t\t\t\t\t<span class=\"x402-v\">${escapeHtml(networkLabel(siwx.network) || siwx.network || '\u2014')}</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"x402-receipt-row\">\n\t\t\t\t\t\t<span class=\"x402-k\">wallet</span>\n\t\t\t\t\t\t<span class=\"x402-v\">${escapeHtml(addrShort)}</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"x402-receipt-row\">\n\t\t\t\t\t\t<span class=\"x402-k\">paid</span>\n\t\t\t\t\t\t<span class=\"x402-v\">previously \u00B7 re-entered free</span>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t`;\n\t\t} else {\n\t\t\tconst explorer = explorerUrl(payment?.network, payment?.transaction);\n\t\t\tconst txShort = payment?.transaction ? `${payment.transaction.slice(0, 8)}\u2026${payment.transaction.slice(-6)}` : '\u2014';\n\t\t\treceiptHtml = `\n\t\t\t\t<div class=\"x402-receipt\">\n\t\t\t\t\t<div class=\"x402-receipt-title\">Payment confirmed!</div>\n\t\t\t\t\t<div class=\"x402-receipt-row\">\n\t\t\t\t\t\t<span class=\"x402-k\">network</span>\n\t\t\t\t\t\t<span class=\"x402-v\">${escapeHtml(networkLabel(payment?.network) || '\u2014')}</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"x402-receipt-row\">\n\t\t\t\t\t\t<span class=\"x402-k\">payer</span>\n\t\t\t\t\t\t<span class=\"x402-v\">${escapeHtml(payment?.payer ? `${payment.payer.slice(0, 8)}\u2026${payment.payer.slice(-6)}` : '\u2014')}</span>\n\t\t\t\t\t</div>\n\t\t\t\t\t${\n\t\t\t\t\t\tpayment?.transaction\n\t\t\t\t\t\t\t? `<div class=\"x402-receipt-row\"><span class=\"x402-k\">tx</span><span class=\"x402-v\">${\n\t\t\t\t\t\t\t\t\texplorer ? `<a href=\"${explorer}\" target=\"_blank\" rel=\"noopener\">${txShort} \u2197</a>` : txShort\n\t\t\t\t\t\t\t\t}</span></div>`\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\t}\n\t\t\t\t</div>\n\t\t\t`;\n\t\t}\n\t\tthis.bodyEl.innerHTML = `\n\t\t\t${receiptHtml}\n\t\t\t<div class=\"x402-result\">${escapeHtml(resultStr).slice(0, 4000)}</div>\n\t\t\t<button class=\"x402-pay-btn\" data-done>Done</button>\n\t\t`;\n\t\tthis.bodyEl.querySelector('[data-done]').addEventListener('click', () => {\n\t\t\tthis.disposed = true;\n\t\t\tdocument.removeEventListener('keydown', this.onKey);\n\t\t\tthis.overlay.classList.remove('x402-open');\n\t\t\tsetTimeout(() => this.overlay.remove(), 180);\n\t\t});\n\t}\n\n\tasync start() {\n\t\tthis.bodyEl.innerHTML = this.renderSteps('discover');\n\t\ttry {\n\t\t\tconst challenge = await discoverChallenge(this.opts);\n\t\t\tthis.challenge = challenge;\n\t\t\tthis.siwx = extractSiwxExtension(challenge);\n\t\t\tthis.payFlowOverride = false;\n\t\t\tthis.siwxFallbackNotice = null;\n\t\t\t// Solana-first platform default: select the Solana accept by default\n\t\t\t// whenever one is offered, regardless of which wallet is detected \u2014\n\t\t\t// renderConnect() still shows both wallet buttons (Solana listed\n\t\t\t// first), so EVM users simply click the EVM option. Falls back to the\n\t\t\t// first EIP-3009 EVM entry (skipping Permit2 siblings the modal can't\n\t\t\t// sign for), then the first accept.\n\t\t\tconst solana = challenge.accepts.find((a) => isSolanaNetwork(a.network));\n\t\t\tconst evm = challenge.accepts.find(isEip3009Accept);\n\t\t\tthis.accept = solana || evm || challenge.accepts[0];\n\t\t\tthis.setPrice(this.accept);\n\t\t\tthis.renderConnect();\n\t\t} catch (err) {\n\t\t\tthis.renderError('discover', err.message || String(err));\n\t\t}\n\t}\n\n\tasync runSolana(accept) {\n\t\tthis.accept = accept;\n\t\tthis.setPrice(accept);\n\t\tthis.renderProgress('connect', { text: 'Opening Phantom\u2026' });\n\t\ttry {\n\t\t\tconst provider = window.phantom?.solana || window.solana;\n\t\t\tif (!provider) throw new Error('Phantom wallet not detected');\n\t\t\tconst conn = await provider.connect();\n\t\t\tconst payerAddress = (conn?.publicKey || provider.publicKey)?.toString();\n\t\t\tif (!payerAddress) throw new Error('Phantom did not return a public key');\n\t\t\tthis.payerAddress = payerAddress;\n\t\t\tconst capCheck = browserEnforceCap({\n\t\t\t\taccept,\n\t\t\t\tcaps: this.opts.caps,\n\t\t\t\taddress: payerAddress,\n\t\t\t});\n\t\t\tif (capCheck.abort) {\n\t\t\t\tthis.renderError('authorize', capCheck.reason);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.spendReservation = capCheck.reservation || null;\n\t\t\tthis.renderProgress('authorize', { text: `Building Solana payment for ${payerAddress.slice(0, 6)}\u2026${payerAddress.slice(-4)}` });\n\n\t\t\tconst origin = this._apiOrigin();\n\t\t\tconst prep = await postJson(`${origin}/api/x402-checkout?action=prepare`, {\n\t\t\t\taccept,\n\t\t\t\tbuyer: payerAddress,\n\t\t\t});\n\t\t\tthis.renderProgress('authorize', { text: 'Confirm in Phantom\u2026' });\n\t\t\tconst txBytes = base64ToUint8Array(prep.tx_base64);\n\t\t\t// Phantom returns a fully-signed VersionedTransaction with the buyer's\n\t\t\t// signature added. The facilitator's fee-payer signature is added during\n\t\t\t// /settle.\n\t\t\tconst SolanaWeb3 = await loadSolanaWeb3();\n\t\t\tconst tx = SolanaWeb3.VersionedTransaction.deserialize(txBytes);\n\t\t\tconst signed = await provider.signTransaction(tx);\n\t\t\tconst signedB64 = uint8ArrayToBase64(signed.serialize());\n\n\t\t\tconst builderCodeBlock = buildBuilderCodeEcho(this.challenge);\n\t\t\tconst enc = await postJson(`${origin}/api/x402-checkout?action=encode`, {\n\t\t\t\taccept,\n\t\t\t\tsigned_tx_base64: signedB64,\n\t\t\t\tresource_url: new URL(this.opts.endpoint, location.href).href,\n\t\t\t\t...(builderCodeBlock ? { builder_code: builderCodeBlock } : {}),\n\t\t\t});\n\n\t\t\tawait this.executePaid(enc.x_payment);\n\t\t} catch (err) {\n\t\t\tif (this.spendReservation) {\n\t\t\t\tbrowserRollbackReservation(this.spendReservation);\n\t\t\t\tthis.spendReservation = null;\n\t\t\t}\n\t\t\tthis.renderError(this.payerAddress ? 'authorize' : 'connect', friendlyError(err));\n\t\t}\n\t}\n\n\tasync runEvm(accept) {\n\t\tthis.accept = accept;\n\t\tthis.setPrice(accept);\n\t\tthis.renderProgress('connect', { text: 'Opening browser wallet\u2026' });\n\t\ttry {\n\t\t\tconst eth = window.ethereum;\n\t\t\tif (!eth) throw new Error('No EVM wallet detected');\n\t\t\tconst accounts = await eth.request({ method: 'eth_requestAccounts' });\n\t\t\tconst payerAddress = accounts?.[0];\n\t\t\tif (!payerAddress) throw new Error('Wallet did not return an account');\n\t\t\tthis.payerAddress = payerAddress;\n\t\t\tconst capCheck = browserEnforceCap({\n\t\t\t\taccept,\n\t\t\t\tcaps: this.opts.caps,\n\t\t\t\taddress: payerAddress,\n\t\t\t});\n\t\t\tif (capCheck.abort) {\n\t\t\t\tthis.renderError('authorize', capCheck.reason);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.spendReservation = capCheck.reservation || null;\n\n\t\t\tconst meta = EVM_NETWORKS[accept.network];\n\t\t\tif (!meta) throw new Error(`Unknown EVM network ${accept.network}`);\n\t\t\t// Switch chain if needed.\n\t\t\tconst currentChainHex = await eth.request({ method: 'eth_chainId' });\n\t\t\tconst desiredChainHex = '0x' + meta.chainId.toString(16);\n\t\t\tif (currentChainHex !== desiredChainHex) {\n\t\t\t\tthis.renderProgress('connect', { text: `Switch wallet to ${meta.name}\u2026` });\n\t\t\t\ttry {\n\t\t\t\t\tawait eth.request({ method: 'wallet_switchEthereumChain', params: [{ chainId: desiredChainHex }] });\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthrow new Error(`Wallet is on ${currentChainHex}; please switch to ${meta.name} (${desiredChainHex}) and retry`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.renderProgress('authorize', { text: `Authorize ${formatAmount(accept.amount)} USDC\u2026` });\n\n\t\t\t// EIP-3009 transferWithAuthorization typed-data signature.\n\t\t\tconst validAfter = 0;\n\t\t\tconst validBefore = Math.floor(Date.now() / 1000) + (accept.maxTimeoutSeconds || 600);\n\t\t\tconst nonce = '0x' + randomHex(32);\n\t\t\tconst domain = {\n\t\t\t\tname: accept.extra?.name || 'USD Coin',\n\t\t\t\tversion: accept.extra?.version || '2',\n\t\t\t\tchainId: meta.chainId,\n\t\t\t\tverifyingContract: accept.asset,\n\t\t\t};\n\t\t\tconst types = {\n\t\t\t\tEIP712Domain: [\n\t\t\t\t\t{ name: 'name', type: 'string' },\n\t\t\t\t\t{ name: 'version', type: 'string' },\n\t\t\t\t\t{ name: 'chainId', type: 'uint256' },\n\t\t\t\t\t{ name: 'verifyingContract', type: 'address' },\n\t\t\t\t],\n\t\t\t\tTransferWithAuthorization: [\n\t\t\t\t\t{ name: 'from', type: 'address' },\n\t\t\t\t\t{ name: 'to', type: 'address' },\n\t\t\t\t\t{ name: 'value', type: 'uint256' },\n\t\t\t\t\t{ name: 'validAfter', type: 'uint256' },\n\t\t\t\t\t{ name: 'validBefore', type: 'uint256' },\n\t\t\t\t\t{ name: 'nonce', type: 'bytes32' },\n\t\t\t\t],\n\t\t\t};\n\t\t\tconst message = {\n\t\t\t\tfrom: payerAddress,\n\t\t\t\tto: accept.payTo,\n\t\t\t\tvalue: accept.amount,\n\t\t\t\tvalidAfter,\n\t\t\t\tvalidBefore,\n\t\t\t\tnonce,\n\t\t\t};\n\t\t\tconst typedData = {\n\t\t\t\tprimaryType: 'TransferWithAuthorization',\n\t\t\t\ttypes,\n\t\t\t\tdomain,\n\t\t\t\tmessage,\n\t\t\t};\n\t\t\tconst signature = await eth.request({\n\t\t\t\tmethod: 'eth_signTypedData_v4',\n\t\t\t\tparams: [payerAddress, JSON.stringify(typedData)],\n\t\t\t});\n\n\t\t\tconst paymentPayload = {\n\t\t\t\tx402Version: 2,\n\t\t\t\tscheme: 'exact',\n\t\t\t\tnetwork: accept.network,\n\t\t\t\tresource: { url: this.opts.endpoint, mimeType: 'application/json' },\n\t\t\t\taccepted: accept,\n\t\t\t\tpayload: {\n\t\t\t\t\tsignature,\n\t\t\t\t\t// The facilitator /verify requires the EIP-3009 time bounds as\n\t\t\t\t\t// decimal strings, not JSON numbers. The signature is unaffected:\n\t\t\t\t\t// uint256 0 and \"0\" encode identically.\n\t\t\t\t\tauthorization: { from: payerAddress, to: accept.payTo, value: accept.amount, validAfter: String(validAfter), validBefore: String(validBefore), nonce },\n\t\t\t\t},\n\t\t\t};\n\t\t\tconst builderCodeBlock = buildBuilderCodeEcho(this.challenge);\n\t\t\tif (builderCodeBlock) {\n\t\t\t\tpaymentPayload.extensions = { 'builder-code': builderCodeBlock };\n\t\t\t}\n\t\t\tconst xPayment = b64encode(paymentPayload);\n\t\t\tawait this.executePaid(xPayment);\n\t\t} catch (err) {\n\t\t\tif (this.spendReservation) {\n\t\t\t\tbrowserRollbackReservation(this.spendReservation);\n\t\t\t\tthis.spendReservation = null;\n\t\t\t}\n\t\t\tthis.renderError(this.payerAddress ? 'authorize' : 'connect', friendlyError(err));\n\t\t}\n\t}\n\n\tasync executePaid(xPayment, attempt = 0) {\n\t\tthis.renderProgress('verify', {\n\t\t\ttext: attempt ? 'Retrying after upstream throttle\u2026' : 'Calling merchant endpoint\u2026',\n\t\t});\n\t\ttry {\n\t\t\tconst res = await fetch(this.opts.endpoint, {\n\t\t\t\tmethod: this.opts.method || 'GET',\n\t\t\t\theaders: {\n\t\t\t\t\t...(this.opts.headers || {}),\n\t\t\t\t\t...(this.opts.body && !this.opts.headers?.['content-type'] ? { 'content-type': 'application/json' } : {}),\n\t\t\t\t\t'X-PAYMENT': xPayment,\n\t\t\t\t},\n\t\t\t\tbody: this.opts.body ? (typeof this.opts.body === 'string' ? this.opts.body : JSON.stringify(this.opts.body)) : undefined,\n\t\t\t});\n\t\t\tconst ct = res.headers.get('content-type') || '';\n\t\t\tconst text = await res.text();\n\t\t\tlet result;\n\t\t\tif (ct.includes('json')) {\n\t\t\t\ttry {\n\t\t\t\t\tresult = JSON.parse(text);\n\t\t\t\t} catch {\n\t\t\t\t\tresult = text;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tresult = text;\n\t\t\t}\n\t\t\tif (!res.ok) {\n\t\t\t\t// A 429 here is a transient upstream throttle. The payment is signed\n\t\t\t\t// but NOT yet settled \u2014 the merchant runs the work before settling \u2014\n\t\t\t\t// so the same X-PAYMENT can be safely re-sent once the window resets,\n\t\t\t\t// with no risk of a double charge.\n\t\t\t\tif (res.status === 429 && attempt < MAX_THROTTLE_RETRIES) {\n\t\t\t\t\tawait this.waitForThrottle(retryAfterSeconds(res, result));\n\t\t\t\t\treturn this.executePaid(xPayment, attempt + 1);\n\t\t\t\t}\n\t\t\t\tconst msg = (result && typeof result === 'object' && (result.error_description || result.error)) || `HTTP ${res.status}`;\n\t\t\t\tthrow new Error(msg);\n\t\t\t}\n\t\t\tconst settleHeader = res.headers.get('x-payment-response');\n\t\t\tconst payment = b64decode(settleHeader) || {};\n\t\t\tthis.spendReservation = null;\n\t\t\tthis.renderDone({ result, payment });\n\t\t\tthis.resolve?.({ ok: true, result, payment, response: { status: res.status, headers: headersToObject(res.headers) } });\n\t\t} catch (err) {\n\t\t\tif (this.spendReservation) {\n\t\t\t\tbrowserRollbackReservation(this.spendReservation);\n\t\t\t\tthis.spendReservation = null;\n\t\t\t}\n\t\t\tthis.renderError('verify', friendlyError(err));\n\t\t}\n\t}\n\n\t// Hold the verify step on a live countdown while an upstream throttle resets,\n\t// then return so the caller re-sends the same signed payment. The reservation\n\t// is deliberately left intact \u2014 this is the same payment, not a new one.\n\tasync waitForThrottle(seconds) {\n\t\tconst total = Math.max(1, Math.min(30, Math.round(seconds) || 6));\n\t\tfor (let left = total; left > 0; left--) {\n\t\t\tthis.renderProgress('verify', { text: `Service is busy \u2014 retrying in ${left}s\u2026` });\n\t\t\tawait new Promise((r) => setTimeout(r, 1000));\n\t\t}\n\t\tthis.renderProgress('verify', { text: 'Retrying\u2026' });\n\t}\n\n\tasync runSiwxEvm(chain) {\n\t\tthis.renderProgress('connect', { text: 'Opening browser wallet\u2026' });\n\t\ttry {\n\t\t\tconst eth = window.ethereum;\n\t\t\tif (!eth) throw new Error('No EVM wallet detected');\n\t\t\tconst accounts = await eth.request({ method: 'eth_requestAccounts' });\n\t\t\tconst rawAddress = accounts?.[0];\n\t\t\tif (!rawAddress) throw new Error('Wallet did not return an account');\n\t\t\tconst checksum = await loadEvmChecksum();\n\t\t\tconst address = checksum(rawAddress);\n\t\t\tthis.payerAddress = address;\n\t\t\tthis.renderProgress('authorize', { text: `Sign sign-in message as ${address.slice(0, 6)}\u2026${address.slice(-4)}` });\n\n\t\t\tconst message = buildSiwxMessage(this.siwx.info, chain, address);\n\t\t\tconst signature = await eth.request({\n\t\t\t\tmethod: 'personal_sign',\n\t\t\t\tparams: [message, address],\n\t\t\t});\n\n\t\t\tconst info = this.siwx.info;\n\t\t\tconst payload = {\n\t\t\t\tdomain: info.domain,\n\t\t\t\taddress,\n\t\t\t\t...(info.statement ? { statement: info.statement } : {}),\n\t\t\t\turi: info.uri,\n\t\t\t\tversion: info.version || '1',\n\t\t\t\tchainId: chain.chainId,\n\t\t\t\ttype: 'eip191',\n\t\t\t\tnonce: info.nonce,\n\t\t\t\tissuedAt: info.issuedAt,\n\t\t\t\t...(info.expirationTime ? { expirationTime: info.expirationTime } : {}),\n\t\t\t\t...(info.notBefore ? { notBefore: info.notBefore } : {}),\n\t\t\t\t...(info.requestId !== undefined && info.requestId !== null ? { requestId: info.requestId } : {}),\n\t\t\t\t...(Array.isArray(info.resources) ? { resources: info.resources } : {}),\n\t\t\t\tsignatureScheme: 'eip191',\n\t\t\t\tsignature,\n\t\t\t};\n\t\t\tawait this.executeSiwx(payload, chain.chainId);\n\t\t} catch (err) {\n\t\t\tthis.renderError(this.payerAddress ? 'authorize' : 'connect', friendlyError(err));\n\t\t}\n\t}\n\n\tasync runSiwxSolana(chain) {\n\t\tthis.renderProgress('connect', { text: 'Opening Phantom\u2026' });\n\t\ttry {\n\t\t\tconst provider = window.phantom?.solana || window.solana;\n\t\t\tif (!provider) throw new Error('Phantom wallet not detected');\n\t\t\tconst conn = await provider.connect();\n\t\t\tconst pubkey = conn?.publicKey || provider.publicKey;\n\t\t\tconst address = pubkey?.toString();\n\t\t\tif (!address) throw new Error('Phantom did not return a public key');\n\t\t\tthis.payerAddress = address;\n\t\t\tthis.renderProgress('authorize', { text: `Sign sign-in message as ${address.slice(0, 6)}\u2026${address.slice(-4)}` });\n\n\t\t\tconst message = buildSiwxMessage(this.siwx.info, chain, address);\n\t\t\tconst encoded = new TextEncoder().encode(message);\n\t\t\tconst signed = await provider.signMessage(encoded, 'utf8');\n\t\t\tconst sigBytes = signed?.signature instanceof Uint8Array ? signed.signature : new Uint8Array(signed?.signature || signed);\n\t\t\tif (!sigBytes || !sigBytes.length) throw new Error('Phantom did not return a signature');\n\t\t\tconst signature = base58encode(sigBytes);\n\n\t\t\tconst info = this.siwx.info;\n\t\t\tconst payload = {\n\t\t\t\tdomain: info.domain,\n\t\t\t\taddress,\n\t\t\t\t...(info.statement ? { statement: info.statement } : {}),\n\t\t\t\turi: info.uri,\n\t\t\t\tversion: info.version || '1',\n\t\t\t\tchainId: chain.chainId,\n\t\t\t\ttype: 'ed25519',\n\t\t\t\tnonce: info.nonce,\n\t\t\t\tissuedAt: info.issuedAt,\n\t\t\t\t...(info.expirationTime ? { expirationTime: info.expirationTime } : {}),\n\t\t\t\t...(info.notBefore ? { notBefore: info.notBefore } : {}),\n\t\t\t\t...(info.requestId !== undefined && info.requestId !== null ? { requestId: info.requestId } : {}),\n\t\t\t\t...(Array.isArray(info.resources) ? { resources: info.resources } : {}),\n\t\t\t\tsignatureScheme: 'siws',\n\t\t\t\tsignature,\n\t\t\t};\n\t\t\tawait this.executeSiwx(payload, chain.chainId);\n\t\t} catch (err) {\n\t\t\tthis.renderError(this.payerAddress ? 'authorize' : 'connect', friendlyError(err));\n\t\t}\n\t}\n\n\tasync executeSiwx(payload, chainId) {\n\t\tthis.renderProgress('verify', { text: 'Verifying sign-in\u2026' });\n\t\tconst headerValue = encodeSiwxHeaderValue(payload);\n\t\tlet res;\n\t\ttry {\n\t\t\tres = await fetch(this.opts.endpoint, {\n\t\t\t\tmethod: this.opts.method || 'GET',\n\t\t\t\theaders: {\n\t\t\t\t\t...(this.opts.headers || {}),\n\t\t\t\t\t...(this.opts.body && !this.opts.headers?.['content-type'] ? { 'content-type': 'application/json' } : {}),\n\t\t\t\t\t[SIWX_HEADER]: headerValue,\n\t\t\t\t},\n\t\t\t\tbody: this.opts.body ? (typeof this.opts.body === 'string' ? this.opts.body : JSON.stringify(this.opts.body)) : undefined,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tthis.renderError('verify', friendlyError(err));\n\t\t\treturn;\n\t\t}\n\n\t\tif (res.status === 200) {\n\t\t\tconst ct = res.headers.get('content-type') || '';\n\t\t\tconst text = await res.text();\n\t\t\tlet result;\n\t\t\tif (ct.includes('json')) {\n\t\t\t\ttry { result = JSON.parse(text); } catch { result = text; }\n\t\t\t} else {\n\t\t\t\tresult = text;\n\t\t\t}\n\t\t\tconst siwx = { address: payload.address, network: chainId };\n\t\t\tthis.renderDone({ result, siwx });\n\t\t\tthis.resolve?.({\n\t\t\t\tok: true,\n\t\t\t\tresult,\n\t\t\t\tsiwx,\n\t\t\t\tresponse: { status: res.status, headers: headersToObject(res.headers) },\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tif (res.status === 401 || res.status === 402) {\n\t\t\t// Most likely: signature verified but this wallet hasn't actually paid\n\t\t\t// for the resource yet. Drop the SIWX offering and fall back to the\n\t\t\t// normal payment flow with a one-line notice.\n\t\t\tlet parsed = null;\n\t\t\ttry { parsed = await res.clone().json(); } catch (_) {}\n\t\t\tconst code = parsed?.code || parsed?.error;\n\t\t\tthis.siwx = null;\n\t\t\tthis.payerAddress = null;\n\t\t\tthis.payFlowOverride = false;\n\t\t\tthis.siwxFallbackNotice = code === 'siwx_not_paid' || res.status === 402\n\t\t\t\t? \"You haven't paid for this yet \u2014 pay now to unlock re-entry.\"\n\t\t\t\t: 'Sign-in not accepted \u2014 please pay to continue.';\n\t\t\tif (!this.challenge || !Array.isArray(this.challenge.accepts) || !this.challenge.accepts.length) {\n\t\t\t\tthis.start();\n\t\t\t} else {\n\t\t\t\tthis.renderConnect();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst text = await res.text().catch(() => '');\n\t\tthis.renderError('verify', `SIWX retry failed: HTTP ${res.status}${text ? ` \u00B7 ${text.slice(0, 120)}` : ''}`);\n\t}\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 helpers \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\nfunction escapeHtml(s) {\n\treturn String(s == null ? '' : s).replace(/[&<>\"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '\"': '"', \"'\": ''' }[c]));\n}\n\nfunction headersToObject(headers) {\n\tconst out = {};\n\theaders.forEach((v, k) => (out[k] = v));\n\treturn out;\n}\n\n// How many times executePaid silently re-sends a signed payment after a 429\n// throttle before falling back to the manual \"Try again\". The payment isn't\n// settled until the merchant call succeeds, so re-sending can't double-charge.\nconst MAX_THROTTLE_RETRIES = 2;\n\n// Seconds to wait before re-sending after a 429. Prefers the standard\n// Retry-After header, then the body's `retry_after` hint, then a sane default.\nfunction retryAfterSeconds(res, result, fallback = 6) {\n\tconst header = Number.parseInt(res.headers.get('retry-after') || '', 10);\n\tif (Number.isFinite(header) && header > 0) return header;\n\tconst body = result && typeof result === 'object' ? Number(result.retry_after) : NaN;\n\tif (Number.isFinite(body) && body > 0) return body;\n\treturn fallback;\n}\n\nfunction friendlyError(err) {\n\tconst msg = err?.shortMessage || err?.message || String(err);\n\tif (/user rejected|user denied|reject/i.test(msg)) return 'cancelled in wallet';\n\t// Upstream throttles often arrive as raw provider text that names the\n\t// merchant's internal billing or credit state. Never relay that to the buyer:\n\t// the payment isn't settled until the merchant call succeeds.\n\tif (/throttl|rate.?limit|too many requests|less than \\$|in credit|\\b429\\b/i.test(msg)) {\n\t\treturn 'The service is briefly busy and your payment was not taken \u2014 retry in a few seconds.';\n\t}\n\t// The Solana and EVM-sign-in paths dynamic-import a library from a CDN. A\n\t// strict host Content-Security-Policy (or the CDN being unreachable) blocks\n\t// that import. The Base/EIP-3009 payment path has no such dependency.\n\tif (/dynamically imported module|esm\\.sh|module script failed/i.test(msg)) {\n\t\treturn 'A component this wallet path needs (loaded from a CDN) was blocked \u2014 often by a strict host security policy. Pay with MetaMask on Base instead; it needs no third-party code.';\n\t}\n\treturn msg.slice(0, 240);\n}\n\nfunction base64ToUint8Array(b64) {\n\tif (typeof Buffer !== 'undefined') return new Uint8Array(Buffer.from(b64, 'base64'));\n\tconst bin = atob(b64);\n\tconst arr = new Uint8Array(bin.length);\n\tfor (let i = 0; i < bin.length; i++) arr[i] = bin.charCodeAt(i);\n\treturn arr;\n}\nfunction uint8ArrayToBase64(arr) {\n\tif (typeof Buffer !== 'undefined') return Buffer.from(arr).toString('base64');\n\tlet bin = '';\n\tfor (let i = 0; i < arr.length; i++) bin += String.fromCharCode(arr[i]);\n\treturn btoa(bin);\n}\nfunction randomHex(bytes) {\n\tconst arr = new Uint8Array(bytes);\n\tcrypto.getRandomValues(arr);\n\treturn Array.from(arr).map((b) => b.toString(16).padStart(2, '0')).join('');\n}\n\nlet _solanaWeb3 = null;\nasync function loadSolanaWeb3() {\n\tif (_solanaWeb3) return _solanaWeb3;\n\t// Dynamic import from a CDN keeps the drop-in script tiny \u2014 Solana web3.js is\n\t// only fetched when a Solana payment is actually attempted.\n\t_solanaWeb3 = await import(/* @vite-ignore */ config.solanaWeb3Url);\n\treturn _solanaWeb3;\n}\n\nasync function postJson(url, body) {\n\tconst res = await fetch(url, {\n\t\tmethod: 'POST',\n\t\theaders: { 'content-type': 'application/json' },\n\t\tbody: JSON.stringify(body),\n\t});\n\tconst text = await res.text();\n\tlet data;\n\ttry {\n\t\tdata = JSON.parse(text);\n\t} catch {\n\t\tdata = { error: 'parse_error', error_description: text.slice(0, 200) };\n\t}\n\tif (!res.ok) {\n\t\tconst err = new Error(data.error_description || data.error || `HTTP ${res.status}`);\n\t\terr.status = res.status;\n\t\terr.data = data;\n\t\tthrow err;\n\t}\n\treturn data;\n}\n\n// Probe the merchant endpoint with a benign request to extract the 402\n// challenge. Accepts HTTP 402 (standard x402) or HTTP 401 with a\n// `payment-required` header (MCP 2025-06-18 spec).\nasync function discoverChallenge(opts) {\n\tconst headers = { ...(opts.headers || {}) };\n\tconst init = {\n\t\tmethod: opts.method || 'GET',\n\t\theaders,\n\t\tbody: opts.body ? (typeof opts.body === 'string' ? opts.body : JSON.stringify(opts.body)) : undefined,\n\t};\n\tif (init.body && !headers['content-type']) headers['content-type'] = 'application/json';\n\tconst res = await fetch(opts.endpoint, init);\n\n\t// MCP 2025-06-18 endpoints return 401 with the full x402 challenge in the\n\t// `payment-required` header (base64-JSON). Accept that alongside standard 402.\n\tconst prHeader = res.headers.get('payment-required');\n\tconst is401WithChallenge = res.status === 401 && !!prHeader;\n\n\tif (res.status !== 402 && !is401WithChallenge) {\n\t\t// Endpoint isn't paid (200) or isn't an x402 endpoint at all. Surface a\n\t\t// clear error \u2014 pointing the modal at a free endpoint should not silently\n\t\t// succeed.\n\t\tconst txt = await res.text();\n\t\tthrow new Error(`Endpoint did not return 402 (got ${res.status}). Body: ${txt.slice(0, 120)}`);\n\t}\n\n\tlet body = is401WithChallenge ? b64decode(prHeader) : await res.json().catch(() => null);\n\tif (!body || !Array.isArray(body.accepts) || !body.accepts.length) {\n\t\t// Some servers only emit `{error}` in the body and put the full v2\n\t\t// PaymentRequired envelope in the base64-JSON PAYMENT-REQUIRED header.\n\t\tconst decoded = b64decode(prHeader);\n\t\tif (decoded && Array.isArray(decoded.accepts) && decoded.accepts.length) {\n\t\t\tbody = decoded;\n\t\t}\n\t}\n\tif (!body || !Array.isArray(body.accepts) || !body.accepts.length) {\n\t\tthrow new Error('Endpoint returned 402 but no `accepts` array could be found in body or header');\n\t}\n\t// Coerce spec-canonical `maxAmountRequired` \u2192 `amount` so downstream price /\n\t// caps / signing read one field.\n\tbody.accepts = body.accepts.map(normalizeAccept);\n\treturn body;\n}\n\n// \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 public api \u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n/**\n * Open the payment modal for an x402 endpoint and resolve when the call\n * succeeds (after settlement) or reject if the user cancels.\n * @param {import('../types/index.js').PayOptions} opts\n * @returns {Promise<import('../types/index.js').PayResult>}\n */\nexport async function pay(opts) {\n\tif (!opts?.endpoint) throw new Error('X402.pay: endpoint is required');\n\tconst modal = new CheckoutModal(opts);\n\tconst result = modal.mount();\n\t// Kick off discovery on the next tick so the modal animates in first.\n\tqueueMicrotask(() => modal.start());\n\treturn result;\n}\n\nfunction readOptsFrom(el) {\n\tconst ds = el.dataset;\n\tlet body = ds.x402Body;\n\tif (body) {\n\t\ttry { body = JSON.parse(body); } catch { /* keep as string */ }\n\t}\n\tlet headers = ds.x402Headers;\n\tif (headers) {\n\t\ttry { headers = JSON.parse(headers); } catch { headers = undefined; }\n\t}\n\tlet caps = ds.x402Caps;\n\tif (caps) {\n\t\ttry { caps = JSON.parse(caps); } catch { caps = undefined; }\n\t}\n\treturn {\n\t\tendpoint: ds.x402Endpoint,\n\t\tmethod: ds.x402Method || (body ? 'POST' : 'GET'),\n\t\tbody,\n\t\theaders,\n\t\tcaps,\n\t\tapiOrigin: ds.x402ApiOrigin,\n\t\tmerchant: ds.x402Merchant,\n\t\taction: ds.x402Action || el.textContent?.trim().slice(0, 60),\n\t};\n}\n\nfunction bindElement(el) {\n\tif (el.dataset.x402Bound === '1') return;\n\tel.dataset.x402Bound = '1';\n\tel.addEventListener('click', async (e) => {\n\t\te.preventDefault();\n\t\tconst opts = readOptsFrom(el);\n\t\ttry {\n\t\t\tconst out = await pay(opts);\n\t\t\tif (out?.siwx) {\n\t\t\t\tel.dispatchEvent(new CustomEvent('x402:siwx-signed', { detail: out.siwx, bubbles: true }));\n\t\t\t}\n\t\t\tel.dispatchEvent(new CustomEvent('x402:result', { detail: out, bubbles: true }));\n\t\t} catch (err) {\n\t\t\tif (err?.code === 'cancelled') return;\n\t\t\tel.dispatchEvent(new CustomEvent('x402:error', { detail: { error: err?.message || String(err) }, bubbles: true }));\n\t\t}\n\t});\n}\n\n/** Scan the document and bind every `[data-x402-endpoint]` element. Idempotent. */\nexport function init() {\n\tif (typeof document === 'undefined') return;\n\tdocument.querySelectorAll('[data-x402-endpoint]').forEach(bindElement);\n}\n\nexport { VERSION as version, bindElement, readOptsFrom };\n"],
|
|
5
|
+
"mappings": ";;;AAKO,IAAM,eAAe;AAAA,EAC3B,eAAe,EAAE,SAAS,MAAM,MAAM,QAAQ,UAAU,2BAA2B;AAAA,EACnF,gBAAgB,EAAE,SAAS,OAAO,MAAM,gBAAgB,UAAU,mCAAmC;AAAA,EACrG,gBAAgB,EAAE,SAAS,OAAO,MAAM,YAAY,UAAU,0BAA0B;AAAA,EACxF,aAAa,EAAE,SAAS,IAAI,MAAM,YAAY,UAAU,sCAAsC;AAC/F;AAGO,IAAM,eAAe,oBAAI,IAAI;AAAA,EACnC;AAAA,EAAQ;AAAA,EAAY;AAAA,EAAQ;AAAA,EAAU;AAAA,EAAwB;AAC/D,CAAC;AAMM,SAAS,gBAAgB,QAAQ;AACvC,MAAI,CAAC,UAAU,OAAO,WAAW,SAAU,QAAO;AAClD,QAAM,SAAS,OAAO,U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