@devlab.group/agent-commerce 1.4.0 → 1.5.0
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/README.md +115 -126
- package/dist/ap2.d.ts +5 -5
- package/dist/ap2.js +19 -11
- package/dist/ap2.js.map +1 -1
- package/dist/{authorization-CPDcpJVa.d.ts → authorization-DA7mjy_O.d.ts} +4 -4
- package/dist/{chunk-ZDVJ7EVL.js → chunk-5GEWKNIH.js} +5 -4
- package/dist/chunk-5GEWKNIH.js.map +1 -0
- package/dist/chunk-6D2EZ5ME.js +27 -0
- package/dist/chunk-6D2EZ5ME.js.map +1 -0
- package/dist/chunk-NKNXVDHN.js +701 -0
- package/dist/chunk-NKNXVDHN.js.map +1 -0
- package/dist/{chunk-IUR3Q7DE.js → chunk-PBYN7EK2.js} +33 -31
- package/dist/chunk-PBYN7EK2.js.map +1 -0
- package/dist/{chunk-7NKWFGBY.js → chunk-US622BKF.js} +3 -3
- package/dist/{chunk-7NKWFGBY.js.map → chunk-US622BKF.js.map} +1 -1
- package/dist/cli/index.js +339 -107
- package/dist/cli/index.js.map +1 -1
- package/dist/constants-6mypC60h.d.ts +50 -0
- package/dist/index.d.ts +44 -13
- package/dist/index.js +358 -113
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +3 -3
- package/dist/mcp.js +4 -1
- package/dist/mcp.js.map +1 -1
- package/dist/mpp.d.ts +50 -0
- package/dist/mpp.js +351 -0
- package/dist/mpp.js.map +1 -0
- package/dist/{protocol-adapter-CaMZj6Wm.d.ts → protocol-adapter-APRjs1E2.d.ts} +25 -11
- package/dist/{runtime-CKq3d_3K.d.ts → runtime-DC5XQ9Cc.d.ts} +24 -13
- package/dist/x402.d.ts +1 -1
- package/dist/x402.js +7 -678
- package/dist/x402.js.map +1 -1
- package/package.json +22 -4
- package/dist/chunk-IUR3Q7DE.js.map +0 -1
- package/dist/chunk-ZDVJ7EVL.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/payments/x402/amount.ts","../src/payments/x402/chain.ts","../src/payments/x402/facilitator.ts","../src/payments/x402/payload.ts","../src/payments/x402/replay-key.ts","../src/payments/x402/provider.ts"],"names":[],"mappings":";;;;;;;;;;;AAiBA,IAAM,sBAAA,GAAyB,iBAAA;AAUxB,SAAS,oBAAA,CAAqB,QAAgB,QAAA,EAA0B;AAC7E,EAAA,IAAI,CAAC,MAAA,CAAO,SAAA,CAAU,QAAQ,CAAA,IAAK,WAAW,CAAA,EAAG;AAC/C,IAAA,MAAM,IAAI,aAAA,CAAc,gBAAA,EAAkB,CAAA,wBAAA,EAA2B,QAAQ,CAAA,CAAE,CAAA;AAAA,EACjF;AACA,EAAA,IAAI,CAAC,sBAAA,CAAuB,IAAA,CAAK,MAAM,CAAA,EAAG;AACxC,IAAA,MAAM,IAAI,aAAA;AAAA,MACR,iBAAA;AAAA,MACA,WAAW,MAAM,CAAA,4CAAA,CAAA;AAAA,MACjB;AAAA,QACE,OAAA,EAAS,EAAE,MAAA;AAAO;AACpB,KACF;AAAA,EACF;AAEA,EAAA,MAAM,CAAC,cAAc,GAAA,EAAK,YAAA,GAAe,EAAE,CAAA,GAAI,MAAA,CAAO,MAAM,GAAG,CAAA;AAE/D,EAAA,IAAI,YAAA,CAAa,SAAS,QAAA,EAAU;AAClC,IAAA,MAAM,IAAI,aAAA;AAAA,MACR,iBAAA;AAAA,MACA,CAAA,QAAA,EAAW,MAAM,CAAA,8CAAA,EAAiD,QAAQ,CAAA,UAAA,CAAA;AAAA,MAC1E,EAAE,OAAA,EAAS,EAAE,MAAA,EAAQ,aAAA,EAAe,UAAS;AAAE,KACjD;AAAA,EACF;AAEA,EAAA,MAAM,cAAA,GAAiB,YAAA,CAAa,MAAA,CAAO,QAAA,EAAU,GAAG,CAAA;AACxD,EAAA,MAAM,QAAA,GAAW,CAAA,EAAG,WAAW,CAAA,EAAG,cAAc,CAAA,CAAA;AAGhD,EAAA,OAAO,O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,EAAQ,IAAI,CAAA;AACtD,IAAA,OAAO,IAAA;AAAA,EACT,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF","file":"chunk-NKNXVDHN.js","sourcesContent":["/**\n * Deterministic decimal <-> base-unit conversion.\n *\n * `DecimalAmount` (see src/core) is a decimal string in\n * *display* units (\"0.01\" USDC). x402 / EIP-3009 need base units (integer\n * string, e.g. \"10000\" for 0.01 USDC at 6 decimals). This conversion must\n * never go through a JS `number` — floating point cannot represent most\n * decimal fractions exactly, and a silently-rounded payment amount is a\n * security bug in a payment provider.\n *\n * viem's own `parseUnits` rounds silently when given more fractional digits\n * than `decimals` supports; we need a hard error instead (a merchant asking\n * for \"0.0000001\" against a 6-decimal asset is a configuration bug, not a\n * roundable amount), so this module implements its own strict parser.\n */\nimport { CommerceError } from '../../core/index.js';\n\nconst DECIMAL_STRING_PATTERN = /^\\d+(?:\\.\\d+)?$/;\n\n/**\n * Parses a canonical decimal display amount (e.g. \"0.01\") into base units\n * for an asset with the given number of decimals, without floating point.\n *\n * Throws `CommerceError('PAYMENT_INVALID')` if the string is not a plain\n * non-negative decimal, or if it carries more fractional digits than the\n * asset supports.\n */\nexport function parseCanonicalAmount(amount: string, decimals: number): bigint {\n if (!Number.isInteger(decimals) || decimals < 0) {\n throw new CommerceError('INTERNAL_ERROR', `Invalid asset decimals: ${decimals}`);\n }\n if (!DECIMAL_STRING_PATTERN.test(amount)) {\n throw new CommerceError(\n 'PAYMENT_INVALID',\n `Amount \"${amount}\" is not a valid non-negative decimal string`,\n {\n details: { amount },\n },\n );\n }\n\n const [integerPart = '0', fractionPart = ''] = amount.split('.');\n\n if (fractionPart.length > decimals) {\n throw new CommerceError(\n 'PAYMENT_INVALID',\n `Amount \"${amount}\" has more precision than the asset supports (${decimals} decimals)`,\n { details: { amount, assetDecimals: decimals } },\n );\n }\n\n const paddedFraction = fractionPart.padEnd(decimals, '0');\n const combined = `${integerPart}${paddedFraction}`;\n // Strip leading zeros so BigInt doesn't choke on e.g. \"007\" — BigInt() is\n // fine with leading zeros in decimal strings, but normalise defensively.\n return BigInt(combined);\n}\n\n/**\n * Formats base units back into a canonical decimal display string.\n *\n * Exact (no rounding is possible going from integer base units to a wider\n * decimal representation), so this is safe to implement directly.\n */\nexport function formatCanonicalAmount(baseUnits: bigint, decimals: number): string {\n if (!Number.isInteger(decimals) || decimals < 0) {\n throw new CommerceError('INTERNAL_ERROR', `Invalid asset decimals: ${decimals}`);\n }\n const negative = baseUnits < 0n;\n const abs = negative ? -baseUnits : baseUnits;\n const digits = abs.toString().padStart(decimals + 1, '0');\n const integerPart = digits.slice(0, digits.length - decimals) || '0';\n const fractionPart = digits.slice(digits.length - decimals).replace(/0+$/, '');\n const sign = negative ? '-' : '';\n return fractionPart.length > 0\n ? `${sign}${integerPart}.${fractionPart}`\n : `${sign}${integerPart}`;\n}\n","/**\n * Local deterministic chain wiring.\n *\n * The x402 SDK resolves RPC endpoints for public networks from its own\n * tables — exactly what we must never touch: the tests must stay\n * deterministic. Instead we build plain viem clients pointed at\n * `options.rpcUrl`, using a custom `Chain` object whose id is 84532, the\n * chain id carried by the CAIP-2 network identifier the gateway advertises\n * (`eip155:84532`).\n *\n * The `Local` prefix on everything here describes the *chain* these clients\n * are built for, not a test-only status: `provider.ts` calls\n * `createLocalPublicClient` and `createLocalFacilitatorClient` on the real\n * settlement path, and this is not demo scaffolding a production build could\n * drop.\n *\n * Public networks are supported, and `buildLocalChain` now takes the chain id\n * as a parameter — exactly what this comment used to say would be required.\n * What stays local is the *facilitator* client: signing in-process is refused\n * on any mainnet, so that client can only ever exist on the dev chain. The\n * read-only health client is built for whatever network is configured.\n *\n * `dev-key-guard.ts` is the boundary that keeps that arrangement safe: it\n * refuses at provider construction if a dev key or dev `payTo` is pointed at\n * anything other than a loopback/private RPC.\n */\nimport {\n type Account,\n type Chain,\n type Client,\n createPublicClient,\n createWalletClient,\n http,\n type PublicActions,\n type PublicClient,\n publicActions,\n type Transport,\n type WalletActions,\n} from 'viem';\nimport { privateKeyToAccount } from 'viem/accounts';\n\n/** A wallet client that can also read chain state — matches x402's `SignerWallet`. */\nexport type LocalFacilitatorClient = Client<\n Transport,\n Chain,\n Account,\n undefined,\n PublicActions<Transport, Chain, Account> & WalletActions<Chain, Account>\n>;\n\n/**\n * Chain id of the local deterministic dev chain. Shared with the public Base\n * Sepolia testnet, which is why nothing may infer \"this is a public network\"\n * from the id alone — `provider.ts` probes for a real Anvil node instead.\n */\nexport const LOCAL_CHAIN_ID = 84532;\n\n/** CAIP-2 identifier the local dev chain is advertised under. */\nexport const LOCAL_NETWORK = `eip155:${LOCAL_CHAIN_ID}`;\n\n/**\n * Chain id carried by a CAIP-2 `eip155` network identifier.\n *\n * x402 v2 identifies networks as CAIP-2 strings rather than the v1 name table,\n * so the chain id a signature is bound to is read straight off the wire value\n * instead of looked up. Returns `undefined` for anything that is not an\n * `eip155` identifier — a caller must never fall back to a default chain id,\n * because the chain id is part of the EIP-712 domain a buyer signed.\n */\nexport function chainIdFromCaip2(network: string): number | undefined {\n const match = /^eip155:(\\d+)$/.exec(network);\n if (!match?.[1]) return undefined;\n const chainId = Number(match[1]);\n return Number.isSafeInteger(chainId) && chainId > 0 ? chainId : undefined;\n}\n\n/**\n * `chainId` defaults to the local dev chain because the *facilitator* client\n * can only ever exist there — a local facilitator is refused on any mainnet.\n * The read-only health client is different: it is built for whatever network\n * is configured, including Base, and inherited 84532 on every one of them.\n * Inert while it only issues raw `getChainId`/`getCode`/`anvil_nodeInfo`, and\n * wrong the moment anything through it consults `chain.id`.\n */\nexport function buildLocalChain(rpcUrl: string, chainId: number = LOCAL_CHAIN_ID): Chain {\n return {\n id: chainId,\n name: 'agent-commerce-local',\n nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },\n rpcUrls: {\n default: { http: [rpcUrl] },\n },\n } satisfies Chain;\n}\n\n/**\n * A viem `PublicClient` for the local chain — read-only, no signing capability.\n *\n * `timeoutMs`, when given, is passed straight to viem's `http()` transport,\n * which ties it to a real `AbortController` around the underlying `fetch`\n * (see viem's `utils/promise/withTimeout.js` — `signal: true`). That is a\n * genuine cancellation, unlike a bare `Promise.race` against a timer, which\n * only stops *waiting* for the request while the request itself keeps\n * running server-side. Omit it to keep viem's own default (10s).\n */\nexport function createLocalPublicClient(\n rpcUrl: string,\n timeoutMs?: number,\n chainId?: number,\n): PublicClient {\n return createPublicClient({\n chain: buildLocalChain(rpcUrl, chainId),\n transport: http(rpcUrl, timeoutMs !== undefined ? { timeout: timeoutMs } : undefined),\n });\n}\n\n/**\n * A viem `WalletClient` extended with public actions, for the local\n * facilitator signer only. x402's `settle()` calls `writeContract`,\n * `waitForTransactionReceipt` and `getCode` on this client — i.e. it needs\n * both `WalletActions` and `PublicActions`, matching x402's `SignerWallet`\n * type.\n *\n * LOCAL DEVELOPMENT ONLY — the private key behind this client must always be\n * an Anvil well-known development key, never a merchant or buyer key, and\n * never a production key of any kind.\n */\nexport function createLocalFacilitatorClient(\n rpcUrl: string,\n signerPrivateKey: `0x${string}`,\n): LocalFacilitatorClient {\n const chain = buildLocalChain(rpcUrl);\n const account = privateKeyToAccount(signerPrivateKey);\n return createWalletClient({\n account,\n chain,\n transport: http(rpcUrl),\n }).extend(publicActions);\n}\n","/**\n * The facilitator seam.\n *\n * A facilitator is whatever verifies an authorisation and broadcasts the\n * transfer. This gateway supports two, behind one interface:\n *\n * local the SDK's in-process `x402Facilitator` signing against a dev node\n * remote an HTTP facilitator, with or without a credential\n *\n * Both are the SDK's own `FacilitatorClient` contract underneath, so neither\n * is a bespoke reimplementation of the protocol — the local one is the same\n * code a hosted facilitator runs, pointed at the local chain.\n *\n * A *session* is opened per verify/settle call rather than reused, because\n * `transportFailed()` has to be scoped to one request: two concurrent\n * payments must not see each other's transport failures. The cost is an\n * object literal against an RPC or HTTP round-trip.\n */\nimport { x402Facilitator } from '@x402/core/facilitator';\nimport { HTTPFacilitatorClient } from '@x402/core/http';\nimport type {\n Network,\n PaymentPayload,\n PaymentRequirements,\n SettleResponse,\n VerifyResponse,\n} from '@x402/core/types';\nimport { toFacilitatorEvmSigner } from '@x402/evm';\nimport { registerExactEvmScheme } from '@x402/evm/exact/facilitator';\nimport { CommerceError } from '../../core/index.js';\nimport type { LocalFacilitatorClient } from './chain.js';\nimport type { FacilitatorAuth } from './guardrails.js';\n\n/** One verify or one settle, with its own transport-failure flag. */\nexport interface FacilitatorSession {\n verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;\n settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;\n /**\n * True when the call failed to reach the facilitator (or the chain behind\n * it) rather than producing a verdict.\n *\n * The SDK's `exact`/EVM scheme catches its own RPC errors and reports them\n * as an ordinary verification failure — an unreachable node comes back as\n * `invalid_exact_evm_signature`. Fail-closed still holds, but the buyer is\n * told their signature is bad and the attempt is recorded as their fault,\n * when nothing about their payment was ever checked. This flag is how the\n * provider tells \"we looked and it was wrong\" apart from \"we could not\n * look\".\n */\n transportFailed(): boolean;\n}\n\nexport interface SupportedKind {\n readonly x402Version: number;\n readonly scheme: string;\n readonly network: string;\n}\n\nexport interface FacilitatorBinding {\n readonly kind: 'local' | 'remote';\n /** Human-readable, never a credential. */\n readonly describe: string;\n open(): FacilitatorSession;\n /** What the facilitator says it can settle. Used by health(), not by the payment path. */\n supported(): Promise<readonly SupportedKind[]>;\n}\n\n/** Bounds every receipt wait the in-process facilitator performs. */\nexport const SETTLEMENT_CONFIRMATION_TIMEOUT_MS = 60_000;\n\n/**\n * An in-process `x402Facilitator` with the `exact`/EVM scheme registered\n * against exactly one network.\n *\n * One network, not the `eip155:*` wildcard the SDK would otherwise derive: a\n * payload naming some other chain must find no facilitator at all rather than\n * reaching a scheme that would then have to reject it.\n */\nexport function createLocalFacilitatorBinding(\n client: LocalFacilitatorClient,\n network: string,\n isTransportError: (err: unknown) => boolean,\n): FacilitatorBinding {\n const build = (): { facilitator: x402Facilitator; failed: () => boolean } => {\n let failed = false;\n const watch = <T>(promise: Promise<T>): Promise<T> =>\n promise.catch((err: unknown) => {\n if (isTransportError(err)) failed = true;\n throw err;\n });\n\n // Exactly the `FacilitatorEvmSigner` surface, so the wrapper covers every\n // call the SDK can make. `toFacilitatorEvmSigner` wants a flat `address`,\n // which viem carries on `client.account` instead.\n const signer = {\n address: client.account.address,\n readContract: (args: Parameters<LocalFacilitatorClient['readContract']>[0]) =>\n watch(client.readContract(args)),\n verifyTypedData: (args: Parameters<LocalFacilitatorClient['verifyTypedData']>[0]) =>\n watch(client.verifyTypedData(args)),\n writeContract: (args: Parameters<LocalFacilitatorClient['writeContract']>[0]) =>\n watch(client.writeContract(args)),\n sendTransaction: (args: Parameters<LocalFacilitatorClient['sendTransaction']>[0]) =>\n watch(client.sendTransaction(args)),\n waitForTransactionReceipt: (\n args: Parameters<LocalFacilitatorClient['waitForTransactionReceipt']>[0],\n ) => watch(client.waitForTransactionReceipt(args)),\n getCode: (args: Parameters<LocalFacilitatorClient['getCode']>[0]) =>\n watch(client.getCode(args)),\n } as unknown as Parameters<typeof toFacilitatorEvmSigner>[0];\n\n // `confirmationTimeoutMs` is what turns a lost receipt wait into\n // `settlement_pending` + the broadcast hash instead of a discarded broadcast.\n const facilitator = registerExactEvmScheme(new x402Facilitator(), {\n signer: toFacilitatorEvmSigner(signer, {\n confirmationTimeoutMs: SETTLEMENT_CONFIRMATION_TIMEOUT_MS,\n }),\n networks: network as Network,\n });\n\n return { facilitator, failed: () => failed };\n };\n\n return {\n kind: 'local',\n describe: 'local (in-process)',\n open(): FacilitatorSession {\n const { facilitator, failed } = build();\n return {\n verify: (payload, requirements) => facilitator.verify(payload, requirements),\n settle: (payload, requirements) => facilitator.settle(payload, requirements),\n transportFailed: failed,\n };\n },\n async supported(): Promise<readonly SupportedKind[]> {\n return build().facilitator.getSupported().kinds;\n },\n };\n}\n\nexport interface RemoteFacilitatorOptions {\n readonly url: string;\n readonly auth: FacilitatorAuth;\n readonly timeoutMs?: number;\n}\n\n/** The SDK's path-keyed auth-header shape. A flat object throws inside it. */\ntype AuthHeaderFactory = () => Promise<Record<string, Record<string, string>>>;\n\n/**\n * CDP signs a fresh JWT per request over method + host + path, so a static\n * header cannot express it. `@coinbase/x402` does that signing, and is\n * imported dynamically: a static import would drag the whole CDP SDK — and its\n * Solana, axios and JOSE dependencies — into the `/x402` subpath for everyone,\n * including the majority who use a facilitator that needs no credential at all.\n *\n * The import is started at construction rather than on the first payment. A\n * missing peer must surface as an unhealthy provider before a buyer signs\n * anything, not as a failure inside verify() with their authorisation already\n * spent.\n */\nfunction cdpAuthHeaders(apiKeyId: string, apiKeySecret: string): AuthHeaderFactory {\n const loading = import('@coinbase/x402').then(\n (mod) => mod.createCdpAuthHeaders(apiKeyId, apiKeySecret),\n (cause: unknown) => {\n throw new CommerceError(\n 'CONFIG_INVALID',\n 'x402 provider: facilitator.auth.type is \"cdp\", which needs the optional peer ' +\n '\"@coinbase/x402\". Install it (npm install @coinbase/x402), or use a facilitator ' +\n 'that accepts a static token with auth.type \"bearer\".',\n { cause },\n );\n },\n );\n // Nothing awaits this until the first call; without a handler the rejection\n // above would be an unhandled promise rejection at startup.\n loading.catch(() => {});\n\n return async () => {\n const create = await loading;\n if (!create) {\n throw new CommerceError(\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n 'x402 provider: @coinbase/x402 returned no auth-header factory',\n );\n }\n return (await create()) as Record<string, Record<string, string>>;\n };\n}\n\n/**\n * An HTTP facilitator.\n *\n * Auth headers are produced per request by the SDK client and never logged,\n * never echoed into `/.well-known`, and never included in `describe`.\n */\nexport function createRemoteFacilitatorBinding(\n options: RemoteFacilitatorOptions,\n): FacilitatorBinding {\n const auth = options.auth;\n let createAuthHeaders: AuthHeaderFactory | undefined;\n if (auth.type === 'bearer') {\n createAuthHeaders = async () => {\n // The SDK requires a path-keyed object; a flat headers object throws\n // rather than silently dropping auth on every request.\n const headers = { Authorization: `Bearer ${auth.token}` };\n return { verify: headers, settle: headers, supported: headers };\n };\n } else if (auth.type === 'cdp') {\n createAuthHeaders = cdpAuthHeaders(auth.apiKeyId, auth.apiKeySecret);\n }\n\n const client = new HTTPFacilitatorClient({\n url: options.url,\n timeoutMs: options.timeoutMs ?? SETTLEMENT_CONFIRMATION_TIMEOUT_MS,\n ...(createAuthHeaders ? { createAuthHeaders } : {}),\n });\n\n return {\n kind: 'remote',\n describe: `remote ${new URL(options.url).origin} (auth=${auth.type})`,\n open(): FacilitatorSession {\n let failed = false;\n const watch = async <T>(call: () => Promise<T>): Promise<T> => {\n try {\n return await call();\n } catch (err) {\n // *Any* throw out of the SDK client means no verdict was obtained.\n // A verdict arrives as a returned `VerifyResponse`/`SettleResponse`,\n // including a negative one; the client only throws when it could not\n // reach the facilitator, could not authenticate to it, got a non-2xx,\n // or could not parse what came back. None of those are facts about\n // the payment, and recording them against the payer would blame the\n // buyer for our credential or the facilitator's outage.\n //\n // Deliberately not a predicate over error shapes: the SDK throws a\n // bare `Error` for an HTTP status (`Facilitator verify failed (401)`)\n // and a `FacilitatorResponseError` for a bad body, so matching on\n // type or message would have missed exactly the credential case that\n // matters most. For settle() this also preserves the indeterminate\n // reading — a timeout may have settled after we stopped waiting.\n failed = true;\n throw err;\n }\n };\n return {\n verify: (payload, requirements) => watch(() => client.verify(payload, requirements)),\n settle: (payload, requirements) => watch(() => client.settle(payload, requirements)),\n transportFailed: () => failed,\n };\n },\n async supported(): Promise<readonly SupportedKind[]> {\n const response = await client.getSupported();\n return response.kinds as readonly SupportedKind[];\n },\n };\n}\n","/**\n * Decoding and validation for the base64 `PAYMENT-SIGNATURE` submission.\n *\n * A malformed payload (not base64, valid base64 but not JSON, valid JSON but\n * the wrong shape) must yield a `rejected` verification result, never a\n * thrown/crashed request — this module returns `undefined` on any failure so\n * callers can turn that into a typed rejection. That is why it parses the\n * schema itself rather than calling the SDK's `decodePaymentSignatureHeader`,\n * which throws.\n */\nimport { PaymentPayloadV2Schema } from '@x402/core/schemas';\nimport type { PaymentPayload } from '@x402/core/types';\nimport { type ExactEIP3009Payload, isEIP3009Payload } from '@x402/evm';\n\nexport function decodePaymentSubmission(payloadBase64: string): PaymentPayload | undefined {\n let json: unknown;\n try {\n const decoded = Buffer.from(payloadBase64, 'base64').toString('utf8');\n json = JSON.parse(decoded);\n } catch {\n return undefined;\n }\n\n const result = PaymentPayloadV2Schema.safeParse(json);\n return result.success ? (result.data as PaymentPayload) : undefined;\n}\n\n/**\n * Narrows a decoded payload to the EIP-3009 `exact`/EVM shape this provider\n * settles.\n *\n * x402 v2's `exact` scheme on EVM has two asset-transfer methods — EIP-3009\n * `transferWithAuthorization` and Permit2. Only the first is supported here,\n * and the challenge says so (`extra.assetTransferMethod`), so a Permit2\n * payload arriving anyway is rejected rather than handed to the SDK: the\n * Permit2 proxy is not deployed on the local chain and a failure there would\n * surface as an opaque settlement revert instead of a clear rejection.\n */\nexport function isExactEvmPayload(\n payload: PaymentPayload,\n): payload is PaymentPayload & { payload: ExactEIP3009Payload } {\n return (\n payload.accepted.scheme === 'exact' &&\n typeof payload.payload === 'object' &&\n payload.payload !== null &&\n isEIP3009Payload(payload.payload as ExactEIP3009Payload) &&\n typeof (payload.payload as ExactEIP3009Payload).signature === 'string'\n );\n}\n","/**\n * Replay-key derivation.\n *\n *Per docs/contracts.md, `PaymentResult.replayKey` MUST be\n * derived only from the payment authorisation (chain id, asset, payer,\n * nonce) — never from the request id — so that the same authorisation\n * replayed against a *different* request still collides in the gateway's\n * receipt-store reservation.\n */\nimport { encodeAbiParameters, keccak256 } from 'viem';\n\nexport interface ReplayKeyInput {\n readonly chainId: number;\n readonly asset: `0x${string}`;\n readonly from: `0x${string}`;\n readonly nonce: `0x${string}`;\n}\n\nexport function computeReplayKey(input: ReplayKeyInput): string {\n const encoded = encodeAbiParameters(\n [{ type: 'uint256' }, { type: 'address' }, { type: 'address' }, { type: 'bytes32' }],\n [BigInt(input.chainId), input.asset, input.from, input.nonce],\n );\n return keccak256(encoded);\n}\n","/**\n * x402 payment provider — protocol version 2, `exact` scheme, EVM,\n * EIP-3009 `transferWithAuthorization`.\n *\n * Implements the frozen `PaymentProvider` interface (src/core/domain/payment.ts).\n * `verify()` never moves funds; only `settle()` does, and only after a\n * successful `verify()` (enforced by the gateway's execution pipeline, not by\n * this file, but this file never calls settle-like RPCs from verify()).\n *\n * Verification and settlement run through the SDK's own `x402Facilitator`\n * with the `exact`/EVM scheme registered against a single CAIP-2 network. The\n * facilitator is in-process — it is the same code a hosted facilitator runs,\n * pointed at the local dev chain — so there is no network hop and no third\n * party in the settlement path.\n *\n * The SDK behaviour relied on here is verified, not assumed: see the notes\n * beside each call site below.\n */\n\nimport type {\n Network,\n PaymentRequired,\n PaymentRequirements,\n SettleResponse,\n VerifyResponse,\n} from '@x402/core/types';\nimport {\n ContractFunctionExecutionError,\n ContractFunctionRevertedError,\n getAddress,\n HttpRequestError,\n isAddress,\n TimeoutError,\n WaitForTransactionReceiptTimeoutError,\n} from 'viem';\nimport {\n type AdapterDescriptor,\n type AdapterHealth,\n type Clock,\n CommerceError,\n type IdGenerator,\n type Logger,\n NOOP_LOGGER,\n type PaymentContext,\n type PaymentProvider,\n type PaymentRequirement,\n type PaymentResult,\n type PaymentSettlementContext,\n type PaymentVerificationContext,\n systemClock,\n} from '../../core/index.js';\nimport { PACKAGE_VERSION } from '../../version.js';\nimport { formatCanonicalAmount, parseCanonicalAmount } from './amount.js';\nimport {\n chainIdFromCaip2,\n createLocalFacilitatorClient,\n createLocalPublicClient,\n type LocalFacilitatorClient,\n} from './chain.js';\nimport {\n assertDevKeyIsLocalOnly,\n assertPayToIsNotDevAddress,\n describeRpc,\n} from './dev-key-guard.js';\nimport {\n createLocalFacilitatorBinding,\n createRemoteFacilitatorBinding,\n type FacilitatorBinding,\n} from './facilitator.js';\nimport { resolveX402Deployment, type X402FacilitatorConfig } from './guardrails.js';\nimport { describeDeploymentMode } from './networks.js';\nimport { decodePaymentSubmission, isExactEvmPayload } from './payload.js';\nimport { computeReplayKey } from './replay-key.js';\n\nconst X402_VERSION = 2;\nconst X402_PROTOCOL_VERSION = String(X402_VERSION);\nconst DEFAULT_MAX_TIMEOUT_SECONDS = 60;\nconst DEFAULT_MIME_TYPE = 'application/json';\nconst HEALTH_TIMEOUT_MS = 4_000;\n/** `SettleResponse.errorReason` the SDK uses for \"broadcast, not confirmed\". */\nconst SETTLEMENT_PENDING_REASON = 'settlement_pending';\n/**\n * The SDK's catch-all for a throw from the broadcast call, and its reason for\n * a mined transaction that reverted. Only the second carries a hash. A revert\n * the SDK recognises during gas estimation gets its own reason instead.\n */\nconst TRANSACTION_FAILED_REASON = 'invalid_exact_evm_transaction_failed';\n/**\n * `invalidReason`/`errorReason` are `z.string()` in the SDK schema — no length\n * or charset bound. They become the message a buyer is told about their own\n * payment, a persisted and SSE-streamed event field, and a column in the\n * merchant's ledger. A remote facilitator is a counterparty this design\n * explicitly contemplates having no account or terms with, so treat its\n * strings as untrusted input rather than as diagnostics.\n */\nconst MAX_REASON_LENGTH = 64;\nconst REASON_SHAPE = /^[a-z0-9_.-]+$/i;\n\nfunction sanitiseReason(reason: string | undefined, fallback: string): string {\n if (reason === undefined) return fallback;\n const trimmed = reason.trim();\n if (trimmed.length === 0 || trimmed.length > MAX_REASON_LENGTH) return fallback;\n return REASON_SHAPE.test(trimmed) ? trimmed : fallback;\n}\n\nexport interface X402ProviderOptions {\n /**\n * CAIP-2 network identifier, e.g. `eip155:84532`. The chain id it carries is\n * part of the EIP-712 domain the buyer signs, so it is read from this value\n * rather than defaulted.\n */\n readonly network: string;\n /** RPC endpoint. Local chain: http://127.0.0.1:8545 */\n readonly rpcUrl: string;\n /** ERC-20 (EIP-3009) asset address used for settlement. */\n readonly asset: `0x${string}`;\n /** EIP-712 domain name of the asset, e.g. 'MockUSDC'. */\n readonly assetName: string;\n /** EIP-712 domain version of the asset, e.g. '2'. */\n readonly assetVersion: string;\n readonly assetDecimals: number;\n /** Merchant-controlled settlement destination. Never a gateway-owned wallet. */\n readonly payTo: `0x${string}`;\n readonly maxTimeoutSeconds?: number;\n /**\n * Which facilitator verifies and broadcasts.\n *\n * `local` runs the facilitator in this process against the dev chain, and\n * its `signerPrivateKey` must be an Anvil well-known key — LOCAL DEVELOPMENT\n * ONLY — DO NOT FUND. `remote` calls an HTTP facilitator, and this gateway\n * then holds no signing key at all.\n */\n readonly facilitator: X402FacilitatorConfig;\n /**\n * Required to be `true` before anything settles on a mainnet. Never a\n * default — see `guardrails.ts`.\n */\n readonly allowMainnet?: boolean;\n /**\n * Required to be `true` to settle on a mainnet through a facilitator that\n * takes no credential. Never a default.\n */\n readonly allowUnauthenticatedFacilitator?: boolean;\n readonly logger?: Logger;\n readonly clock?: Clock;\n readonly ids?: IdGenerator;\n}\n\nconst DEFAULT_IDS: IdGenerator = {\n next: (prefix?: string) => `${prefix ? `${prefix}_` : ''}${crypto.randomUUID()}`,\n};\n\nexport function createX402PaymentProvider(options: X402ProviderOptions): PaymentProvider {\n if (!isAddress(options.asset)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `x402 provider: \"asset\" is not a valid EVM address: ${options.asset}`,\n );\n }\n if (!isAddress(options.payTo)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `x402 provider: \"payTo\" is not a valid EVM address: ${options.payTo}`,\n );\n }\n // Applies regardless of facilitator.mode — which account signs settlement\n // has no bearing on whether the destination address's private key is\n // public knowledge. `resolveX402Deployment` below covers the other half of\n // the same question: a dev payTo on any non-local *deployment*, where the\n // RPC host says nothing about where the money lands.\n assertPayToIsNotDevAddress(options.rpcUrl, options.payTo);\n if (!Number.isInteger(options.assetDecimals) || options.assetDecimals < 0) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `x402 provider: \"assetDecimals\" must be a non-negative integer`,\n );\n }\n // The chain id is not a display detail: it is signed into the buyer's\n // EIP-712 domain, so a network identifier we cannot resolve one from is a\n // startup failure, never a request-time default. `resolveX402Deployment`\n // also decides what this deployment *is* — local, testnet or mainnet — and\n // refuses every combination that could move real money by accident.\n const { profile, mode } = resolveX402Deployment({\n network: options.network,\n payTo: options.payTo,\n asset: options.asset,\n assetName: options.assetName,\n assetVersion: options.assetVersion,\n facilitator: options.facilitator,\n ...(options.allowMainnet !== undefined ? { allowMainnet: options.allowMainnet } : {}),\n ...(options.allowUnauthenticatedFacilitator !== undefined\n ? { allowUnauthenticatedFacilitator: options.allowUnauthenticatedFacilitator }\n : {}),\n });\n const network = options.network as Network;\n // Constructed once, here, rather than inside settle(): assertDevKeyIsLocalOnly\n // above already proves the key is well-formed, so privateKeyToAccount is not\n // expected to throw — but if it somehow does (or the key/RPC combination is\n // otherwise unusable), that is a *configuration* problem, and a bad key\n // should fail the provider at startup, not on the first paying customer's\n // request, after their replayKey is already reserved. This mirrors the other\n // CONFIG_INVALID checks above, which are all one-time, construction-time\n // validation rather than per-request checks.\n let binding: FacilitatorBinding;\n if (options.facilitator.mode === 'local') {\n assertDevKeyIsLocalOnly(options.rpcUrl, options.facilitator.signerPrivateKey);\n let client: LocalFacilitatorClient;\n try {\n client = createLocalFacilitatorClient(\n options.rpcUrl,\n options.facilitator.signerPrivateKey as `0x${string}`,\n );\n } catch (cause) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n 'x402 provider: could not construct a local facilitator signer from ' +\n 'facilitator.signerPrivateKey — it must be a valid 32-byte hex private key',\n { cause },\n );\n }\n binding = createLocalFacilitatorBinding(client, network, isProviderUnavailableError);\n } else {\n binding = createRemoteFacilitatorBinding({\n url: options.facilitator.url,\n auth: options.facilitator.auth,\n });\n }\n\n // health()'s own read-only client, with a real transport-level timeout (see\n // createLocalPublicClient's doc comment). Verification and settlement read\n // the chain through the facilitator signer instead, so this is the only\n // public client the provider builds.\n // Health details are logged, so they name the RPC by origin only\n const rpcOrigin = describeRpc(options.rpcUrl);\n const healthPublicClient = createLocalPublicClient(\n options.rpcUrl,\n HEALTH_TIMEOUT_MS,\n profile.chainId,\n );\n\n const clock = options.clock ?? systemClock;\n const ids = options.ids ?? DEFAULT_IDS;\n const logger = options.logger ?? NOOP_LOGGER;\n const maxTimeoutSeconds = options.maxTimeoutSeconds ?? DEFAULT_MAX_TIMEOUT_SECONDS;\n\n const descriptor: AdapterDescriptor = {\n name: 'x402',\n kind: 'payment',\n implementationVersion: PACKAGE_VERSION,\n supportedSpec: `x402/v${X402_VERSION} scheme=exact family=eip155`,\n capabilities: [\n 'exact-evm',\n `${binding.kind}-facilitator`,\n 'eip-3009',\n 'caip-2',\n `mode=${mode}`,\n ],\n status: 'stable',\n unsupported: ['svm', 'permit2', 'upto scheme'],\n };\n\n async function createRequirement(context: PaymentContext): Promise<PaymentRequirement> {\n const amount = parseCanonicalAmount(context.amount, options.assetDecimals).toString();\n\n const requirements: PaymentRequirements = {\n scheme: 'exact',\n network,\n asset: options.asset,\n amount,\n payTo: options.payTo,\n maxTimeoutSeconds,\n // `name`/`version` are what let a buyer and the facilitator build the\n // same EIP-712 domain without an on-chain `version()` call, so\n // verification stays deterministic against a token that has none.\n //\n // `assetTransferMethod` is stated rather than left to default: x402 v2's\n // `exact`/EVM scheme also has a Permit2 path, and a client that picked it\n // would produce a payload this provider cannot settle. Declaring the one\n // supported method turns that into a client-side non-choice instead of a\n // server-side rejection.\n extra: {\n name: options.assetName,\n version: options.assetVersion,\n assetTransferMethod: 'eip3009',\n },\n };\n\n // The v2 challenge document, verbatim on the wire: the HTTP adapter\n // base64-encodes this into `PAYMENT-REQUIRED`, and MCP passes it through\n // in the payment-required envelope. Built once, here, so both surfaces\n // describe the same challenge rather than each assembling their own.\n //\n // `resource.url` is descriptive metadata: nothing in the EIP-3009\n // authorisation (`from`/`to`/`value`/`validAfter`/`validBefore`/`nonce`)\n // covers it, nothing verifies against it, and the replay key is keyed on\n // the authorisation instead. It still carries `network` and `payTo` —\n // both already public in this same challenge — because the\n // `agent-commerce` authority is not reserved to us across the wider x402\n // ecosystem, so the pair is what keeps it unambiguous.\n const envelope: PaymentRequired = {\n x402Version: X402_VERSION,\n resource: {\n url: `resource://agent-commerce/${encodeURIComponent(options.network)}/${options.payTo}/resources/${encodeURIComponent(context.resource.id)}`,\n description: context.resource.description ?? context.resource.name,\n mimeType: DEFAULT_MIME_TYPE,\n },\n accepts: [requirements],\n };\n\n const expiresAt = new Date(clock.now().getTime() + maxTimeoutSeconds * 1000).toISOString();\n\n return {\n id: ids.next('payreq'),\n requestId: context.requestId,\n resourceId: context.resource.id,\n provider: 'x402',\n amount: context.amount,\n currency: context.currency,\n destination: options.payTo,\n network: options.network,\n asset: options.asset,\n expiresAt,\n challenge: {\n provider: 'x402',\n version: X402_PROTOCOL_VERSION,\n accepts: [requirements as unknown as Record<string, unknown>],\n envelope: envelope as unknown as Record<string, unknown>,\n },\n };\n }\n\n /**\n * Verifies a payment submission against a payment requirement.\n *\n * Every check below runs against *our* requirement — the one this provider\n * built and the pipeline held onto — never against `payload.accepted`, the\n * copy of the requirements the client echoes back. That echo is attacker\n * data; the SDK's scheme facilitator likewise takes the requirements as an\n * explicit argument rather than reading them off the payload.\n *\n * The amount must match **exactly**. This once accepted overpayment on the\n * reading that `amount` names a floor — but the pinned `@x402/evm@2.23.0`\n * exact/EVM scheme compares with `!==` and rejects anything else as\n * `invalid_exact_evm_payload_authorization_value_mismatch`, in both verify\n * and settle, and hosted facilitators run that same code. Accepting more\n * here only moved the rejection downstream and turned a clean\n * `wrong_amount` into an opaque SDK reason.\n */\n async function verify(context: PaymentVerificationContext): Promise<PaymentResult> {\n const { requirement, submission } = context;\n\n const rejected = (reason: string): PaymentResult => ({\n status: 'rejected',\n provider: 'x402',\n amount: requirement.amount,\n currency: requirement.currency,\n ...(requirement.network !== undefined ? { network: requirement.network } : {}),\n ...(requirement.asset !== undefined ? { asset: requirement.asset } : {}),\n rejectionReason: reason,\n });\n\n if (requirement.provider !== 'x402' || requirement.challenge.provider !== 'x402') {\n return rejected('wrong_provider');\n }\n\n const requirements = requirement.challenge.accepts[0] as PaymentRequirements | undefined;\n if (!requirements) {\n return rejected('missing_payment_requirements');\n }\n\n // Defence in depth, not the real expiry: the pipeline calls\n // createRequirement() fresh on every request, so by the time verify()\n // runs this requirement is only ever seconds old — this check will\n // essentially never fire in the current flow. The actual expiry\n // enforcement is EIP-3009's validBefore, checked inside the SDK's scheme\n // facilitator. Kept because it is cheap and correct, not because it is\n // load-bearing.\n if (\n requirement.expiresAt !== undefined &&\n Date.parse(requirement.expiresAt) < clock.now().getTime()\n ) {\n return rejected('requirement_expired');\n }\n\n // Defensive invariant: the requirement we're verifying against must still\n // describe *this* provider's configured asset. It always will in normal\n // operation (we generated it), but a corrupted/mismatched requirement\n // must never be allowed to authorise a transfer for a different asset.\n if (\n !isAddress(requirements.asset) ||\n getAddress(requirements.asset) !== getAddress(options.asset)\n ) {\n return rejected('wrong_asset');\n }\n\n const payload = decodePaymentSubmission(submission.payload);\n if (!payload) {\n return rejected('malformed_payment_payload');\n }\n if (payload.x402Version !== X402_VERSION) {\n return rejected('unsupported_x402_version');\n }\n if (!isExactEvmPayload(payload)) {\n return rejected('unsupported_scheme');\n }\n\n const { authorization } = payload.payload;\n\n if (!isAddress(authorization.from) || !isAddress(authorization.to)) {\n return rejected('malformed_payment_payload');\n }\n // The network the buyer signed for is `accepted.network` — it is what the\n // scheme derives the EIP-712 chain id from — so a mismatch here means the\n // signature is bound to a different chain than the one we settle on.\n if (payload.accepted.network !== options.network) {\n return rejected('wrong_network');\n }\n if (getAddress(authorization.to) !== getAddress(options.payTo)) {\n return rejected('wrong_recipient');\n }\n let authorizedValue: bigint;\n let required: bigint;\n try {\n authorizedValue = BigInt(authorization.value);\n required = BigInt(requirements.amount);\n } catch {\n return rejected('malformed_payment_payload');\n }\n if (authorizedValue !== required) {\n // Both directions: the scheme enforces equality, so an overpayment is\n // rejected here with a reason the buyer can act on rather than by the\n // facilitator with one they cannot.\n return rejected('wrong_amount');\n }\n\n const scope = binding.open();\n let sdkResult: VerifyResponse;\n try {\n sdkResult = await scope.verify(payload, requirements);\n } catch (err) {\n if (isProviderUnavailableError(err) || scope.transportFailed()) {\n throw new CommerceError(\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n `x402 provider: ${binding.kind} facilitator unreachable during verify()`,\n {\n cause: err,\n },\n );\n }\n logger.warn({ err: describeError(err) }, 'x402 verify(): unexpected SDK error');\n return rejected('unexpected_verify_error');\n }\n\n if (!sdkResult.isValid) {\n // An RPC that never answered is not a payment that failed a check.\n if (scope.transportFailed()) {\n if (sdkResult.invalidReason !== undefined) {\n logger.debug(\n { reportedReason: sdkResult.invalidReason },\n 'x402 verify(): local facilitator transport failure reason',\n );\n }\n throw new CommerceError(\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n `x402 provider: ${binding.kind} facilitator unreachable during verify()`,\n );\n }\n // The raw string still reaches the operator's logs below; only what is\n // shown to the buyer and written to the ledger is constrained.\n if (sdkResult.invalidReason !== undefined) {\n logger.debug(\n { reportedReason: sdkResult.invalidReason },\n 'x402 verify(): facilitator rejection reason',\n );\n }\n return rejected(sanitiseReason(sdkResult.invalidReason, 'invalid_payment'));\n }\n\n // Derived from the chain id the authorisation is actually bound to, never\n // from a provider-instance constant, so the key stays correct the moment\n // there is more than one chain id in play.\n const payloadChainId = chainIdFromCaip2(payload.accepted.network);\n if (payloadChainId === undefined) {\n return rejected('wrong_network');\n }\n const replayKey = computeReplayKey({\n chainId: payloadChainId,\n asset: getAddress(requirements.asset),\n from: getAddress(authorization.from),\n nonce: authorization.nonce,\n });\n\n return {\n status: 'verified',\n provider: 'x402',\n payer: getAddress(authorization.from),\n payee: getAddress(authorization.to),\n amount: formatCanonicalAmount(authorizedValue, options.assetDecimals),\n currency: requirement.currency,\n network: payload.accepted.network,\n asset: getAddress(requirements.asset),\n replayKey,\n };\n }\n\n async function settle(context: PaymentSettlementContext): Promise<PaymentResult> {\n const { requirement, submission, verification } = context;\n\n if (verification.status !== 'verified') {\n throw new CommerceError(\n 'PAYMENT_INVALID',\n 'x402 provider: settle() called without a successful verify()',\n );\n }\n\n const requirements = requirement.challenge.accepts[0] as PaymentRequirements | undefined;\n if (!requirements) {\n throw new CommerceError(\n 'PAYMENT_INVALID',\n 'x402 provider: settle() found no payment requirements to settle against',\n );\n }\n\n const payload = decodePaymentSubmission(submission.payload);\n if (!payload || !isExactEvmPayload(payload)) {\n throw new CommerceError(\n 'PAYMENT_INVALID',\n 'x402 provider: settle() received an undecodable payment payload',\n );\n }\n\n const rejectedSettlement = (rejectionReason: string): PaymentResult => ({\n status: 'rejected',\n provider: 'x402',\n amount: verification.amount,\n currency: requirement.currency,\n ...(verification.network !== undefined ? { network: verification.network } : {}),\n ...(verification.asset !== undefined ? { asset: verification.asset } : {}),\n ...(verification.replayKey !== undefined ? { replayKey: verification.replayKey } : {}),\n rejectionReason,\n });\n\n const scope = binding.open();\n let sdkResult: SettleResponse;\n try {\n sdkResult = await scope.settle(payload, requirements);\n } catch (err) {\n if (isProviderUnavailableError(err) || scope.transportFailed()) {\n throw new CommerceError(\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n `x402 provider: ${binding.kind} facilitator unreachable during settle()`,\n { cause: err },\n );\n }\n // A revert is the chain's own statement that the transfer did not\n // happen, so it is a real rejection and the pipeline may release what\n // it holds. Anything else out of settle() is unclassified: we cannot\n // tell whether the transfer was broadcast, so it must not come back as\n // a rejection the buyer can be blamed for. It goes back as an\n // unavailable provider, and the pipeline records it unresolved.\n if (!isOnChainRevertError(err)) {\n logger.warn(\n { err: describeError(err) },\n 'x402 settle(): settlement failed with an unclassified error; outcome unknown',\n );\n throw new CommerceError(\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n 'x402 provider: settlement failed with an unclassified error; outcome unknown',\n { cause: err },\n );\n }\n logger.warn(\n { err: describeError(err), rejectionReason: 'transaction_reverted' },\n 'x402 settle(): settlement transaction reverted on chain',\n );\n return rejectedSettlement('transaction_reverted');\n }\n\n if (!sdkResult.success) {\n // \"Broadcast, never confirmed\" is not \"did not happen\": the transfer may\n // already be on-chain, so it surfaces as an *unavailable* provider\n // carrying the hash, letting the pipeline record the attempt\n // `settlement-uncertain` rather than `failed`. The SDK's catch-all with\n // no hash is treated the same way: its throw may have followed a\n // broadcast, and the message cannot tell, because viem reports an RPC\n // error on the send as a revert. Everything else is a real rejection.\n if (\n sdkResult.errorReason === TRANSACTION_FAILED_REASON &&\n !/^0x[0-9a-f]{64}$/i.test(sdkResult.transaction)\n ) {\n logger.warn(\n { reportedReason: sdkResult.errorReason },\n 'x402 settle(): the broadcast failed without a transaction hash; outcome unknown',\n );\n throw new CommerceError(\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n 'x402 provider: settlement failed with an unclassified error; outcome unknown',\n );\n }\n if (sdkResult.errorReason === SETTLEMENT_PENDING_REASON || scope.transportFailed()) {\n throw new CommerceError(\n 'PAYMENT_PROVIDER_UNAVAILABLE',\n 'x402 provider: settlement was broadcast but could not be confirmed',\n {\n ...(sdkResult.transaction\n ? { details: { transactionHash: sdkResult.transaction } }\n : {}),\n },\n );\n }\n if (sdkResult.errorReason !== undefined) {\n logger.debug(\n { reportedReason: sdkResult.errorReason },\n 'x402 settle(): facilitator failure reason',\n );\n }\n return {\n ...rejectedSettlement(sanitiseReason(sdkResult.errorReason, 'settlement_failed')),\n network: sdkResult.network,\n ...(sdkResult.payer !== undefined ? { payer: sdkResult.payer } : {}),\n };\n }\n\n return {\n status: 'settled',\n provider: 'x402',\n externalReference: sdkResult.transaction,\n ...(sdkResult.payer !== undefined ? { payer: sdkResult.payer } : {}),\n payee: requirements.payTo,\n amount: verification.amount,\n currency: requirement.currency,\n network: sdkResult.network,\n ...(verification.asset !== undefined ? { asset: verification.asset } : {}),\n ...(verification.replayKey !== undefined ? { replayKey: verification.replayKey } : {}),\n settledAt: clock.nowIso(),\n };\n }\n\n async function computeHealth(): Promise<AdapterHealth> {\n const startedAt = clock.monotonicMs();\n const checkedAt = clock.nowIso();\n\n try {\n const chainId = await healthPublicClient.getChainId();\n if (chainId !== profile.chainId) {\n return {\n status: 'fail',\n detail: `RPC at ${rpcOrigin} reports chain id ${chainId}, expected ${profile.chainId} (${profile.displayName})`,\n checkedAt,\n durationMs: clock.monotonicMs() - startedAt,\n };\n }\n\n const code = await healthPublicClient.getCode({ address: options.asset });\n if (!code || code === '0x') {\n return {\n status: 'fail',\n detail: `No contract code found at configured asset address ${options.asset}`,\n checkedAt,\n durationMs: clock.monotonicMs() - startedAt,\n };\n }\n\n if (binding.kind === 'remote') {\n // \"Reachable\" is not the question — \"will it settle *this*\" is. A\n // facilitator that is up but does not carry our scheme on our network\n // fails every payment, and does it after the buyer has signed.\n const kinds = await binding.supported();\n const supportsUs = kinds.some(\n (kind) =>\n kind.x402Version === X402_VERSION &&\n kind.scheme === 'exact' &&\n kind.network === options.network,\n );\n if (!supportsUs) {\n return {\n status: 'fail',\n detail:\n `Facilitator ${binding.describe} does not advertise x402 v${X402_VERSION} scheme=exact ` +\n `on ${options.network} (${profile.displayName}); no payment on this deployment can settle`,\n checkedAt,\n durationMs: clock.monotonicMs() - startedAt,\n };\n }\n return {\n status: 'pass',\n detail:\n `${describeDeploymentMode(mode)} — RPC ${rpcOrigin} reachable, chain id ` +\n `${profile.chainId} (${profile.displayName}), asset ${options.asset} has code, ` +\n `facilitator ${binding.describe} supports exact/${options.network}`,\n checkedAt,\n durationMs: clock.monotonicMs() - startedAt,\n };\n }\n\n // Chain id alone cannot prove this is a dev chain: real Base Sepolia\n // reports the same id (84532) as this project's local chain, by design.\n // Probe an Anvil-only RPC method — present only on a real Anvil node —\n // before trusting a well-known dev key against it.\n const isAnvil = await probeIsAnvilNode(healthPublicClient);\n if (!isAnvil) {\n return {\n status: 'fail',\n detail:\n `RPC at ${rpcOrigin} reports chain id ${profile.chainId} but does not answer ` +\n '\"anvil_nodeInfo\" — it does not look like a local Anvil dev node. Refusing to treat it ' +\n 'as safe for a local-facilitator dev key.',\n checkedAt,\n durationMs: clock.monotonicMs() - startedAt,\n };\n }\n\n return {\n status: 'pass',\n detail:\n `${describeDeploymentMode(mode)} — RPC ${rpcOrigin} reachable, chain id ` +\n `${profile.chainId}, asset ${options.asset} has code, confirmed Anvil dev node`,\n checkedAt,\n durationMs: clock.monotonicMs() - startedAt,\n };\n } catch (err) {\n return {\n status: 'fail',\n detail: `x402 health check failed: ${describeError(err)}`,\n checkedAt,\n durationMs: clock.monotonicMs() - startedAt,\n };\n }\n }\n\n // /ready has no auth, no cache and no\n // rate limit, and called computeHealth() — 3 live RPC calls — on every\n // single request; measured 3x amplification of billed upstream calls\n // under an unauthenticated flood. Memoise behind a short TTL and collapse\n // concurrent callers onto one in-flight probe, so N requests within the\n // window produce at most one round-trip instead of N.\n //\n // 5s: short enough that a readiness probe (Kubernetes' own default\n // `periodSeconds` is 10s) never observes data older than its own poll\n // interval, long enough to fully decouple RPC call volume from HTTP\n // request volume — which is the property that closes the amplification,\n // not the exact number of seconds.\n //\n // pass and fail are cached for the same TTL, deliberately: a shorter TTL\n // for fail would re-introduce the amplification exactly when an upstream\n // outage makes every call expensive/slow, which is the worst possible time\n // to remove the cache's protection. 5s of recovery latency after the RPC\n // comes back is an acceptable trade — it is already within the noise of a\n // single health probe's own round-trip time, and well inside a normal\n // probe's own poll interval.\n //\n // This only memoises this provider's own RPC probe. `core` separately\n // memoises the whole /ready aggregation (src/gateway/readiness.ts)\n // — a second, independent layer at a different scope; the two compose\n // without conflict since neither assumes anything about the other's TTL.\n //\n // Does not affect `doctor`'s deployment-mismatch cross-check: that reads\n // asset/network/payTo straight from `/.well-known/agent-commerce` (static\n // provider config, echoed live, never cached), not from health().\n const HEALTH_CACHE_MS = 5_000;\n let cachedHealth: { at: number; value: AdapterHealth } | undefined;\n let inFlightHealth: Promise<AdapterHealth> | undefined;\n\n async function health(): Promise<AdapterHealth> {\n const now = clock.monotonicMs();\n if (cachedHealth && now - cachedHealth.at < HEALTH_CACHE_MS) {\n return cachedHealth.value;\n }\n if (inFlightHealth) return inFlightHealth;\n\n inFlightHealth = computeHealth()\n .then((value) => {\n cachedHealth = { at: clock.monotonicMs(), value };\n return value;\n })\n .finally(() => {\n inFlightHealth = undefined;\n });\n return inFlightHealth;\n }\n\n return {\n name: 'x402',\n descriptor,\n createRequirement,\n verify,\n settle,\n health,\n };\n}\n\nfunction isOnChainRevertError(err: unknown): boolean {\n return (\n err instanceof ContractFunctionRevertedError || err instanceof ContractFunctionExecutionError\n );\n}\n\n/**\n * `instanceof` checks first — these are the real error classes the pinned\n * viem@2.55.18 HTTP transport throws (see viem's `utils/rpc/http.js`, which\n * wraps every fetch failure, including connection-refused, in\n * `HttpRequestError` unless it is already a `TimeoutError`), plus the error\n * `waitForTransactionReceipt` itself throws when it gives up polling for a\n * receipt — precisely the \"broadcast succeeded, confirmation didn't\" case\n * this classification exists to catch. Substring matching\n * is kept only as a fallback for shapes not covered by a typed viem class\n * (e.g. a raw Node/undici error surfacing through some other path) — pinning\n * behaviour to message text is brittle across viem/undici upgrades, so the\n * instanceof checks should be preferred and grown over time as more real\n * failure shapes are seen.\n */\nfunction isProviderUnavailableError(err: unknown): boolean {\n if (\n err instanceof HttpRequestError ||\n err instanceof TimeoutError ||\n err instanceof WaitForTransactionReceiptTimeoutError\n ) {\n return true;\n }\n const message = describeError(err).toLowerCase();\n return (\n message.includes('econnrefused') ||\n message.includes('fetch failed') ||\n message.includes('enotfound') ||\n message.includes('etimedout') ||\n message.includes('timed out') ||\n message.includes('network error')\n );\n}\n\n// Error class name and message. viem puts the request URL in its messages and\n// an RPC URL often carries an API key, so each URL is cut to its origin.\nfunction describeError(err: unknown): string {\n const text = err instanceof Error ? `${err.name}: ${err.message}` : String(err);\n return text.replace(/\\bhttps?:\\/\\/[^\\s\"'<>]+/gi, (url) => describeRpc(url));\n}\n\n/**\n * True only when the RPC answers Anvil's own `anvil_nodeInfo` method — a\n * real network (including real Base Sepolia, which shares chain id 84532\n * with this project's local chain by design) returns a JSON-RPC \"method\n * not found\" error instead. Never throws.\n */\nasync function probeIsAnvilNode(\n client: ReturnType<typeof createLocalPublicClient>,\n): Promise<boolean> {\n // Anvil-only method: not part of viem's typed PublicRpcSchema, hence the cast.\n const request = client.request as unknown as (args: {\n method: string;\n params: unknown[];\n }) => Promise<unknown>;\n try {\n await request({ method: 'anvil_nodeInfo', params: [] });\n return true;\n } catch {\n return false;\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommerceError } from './chunk-
|
|
1
|
+
import { CommerceError } from './chunk-5GEWKNIH.js';
|
|
2
2
|
|
|
3
3
|
// src/payments/x402/networks.ts
|
|
4
4
|
var PROFILES = [
|
|
@@ -137,93 +137,95 @@ function invalid(message, path) {
|
|
|
137
137
|
return new CommerceError("CONFIG_INVALID", message, { details: { path } });
|
|
138
138
|
}
|
|
139
139
|
function resolveX402Deployment(input) {
|
|
140
|
-
const
|
|
140
|
+
const at = input.configPath ?? "payments.x402";
|
|
141
|
+
const payTo = input.payToField ?? "payTo";
|
|
142
|
+
const profile = requireNetworkProfile(input.network, `${at}.network`);
|
|
141
143
|
const mode = resolveDeploymentMode(profile, input.facilitator.mode);
|
|
142
144
|
if (profile.kind === "mainnet" && input.facilitator.mode === "local") {
|
|
143
145
|
throw invalid(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
`${at}: network "${profile.id}" (${profile.displayName}) is a mainnet and cannot be served by facilitator.mode "local". A mainnet deployment must settle through a remote facilitator.`,
|
|
147
|
+
`${at}.facilitator.mode`
|
|
146
148
|
);
|
|
147
149
|
}
|
|
148
150
|
if (mode === "mainnet" && input.allowMainnet !== true) {
|
|
149
151
|
throw invalid(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
`${at}: network "${profile.id}" (${profile.displayName}) settles real funds. Set ${at}.allowMainnet: true to acknowledge this explicitly - it is never the default.`,
|
|
153
|
+
`${at}.allowMainnet`
|
|
152
154
|
);
|
|
153
155
|
}
|
|
154
156
|
if (input.facilitator.mode === "remote") {
|
|
155
|
-
assertFacilitatorUrlIsSafe(input.facilitator.url, mode);
|
|
157
|
+
assertFacilitatorUrlIsSafe(input.facilitator.url, mode, at);
|
|
156
158
|
if (mode === "mainnet" && input.facilitator.auth.type === "none" && input.allowUnauthenticatedFacilitator !== true) {
|
|
157
159
|
throw invalid(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
+
`${at}: facilitator ${describeOrigin(input.facilitator.url)} takes no credential, and this is a mainnet deployment. It will see every payment authorisation you handle, with no account, terms or support behind it. Set ${at}.allowUnauthenticatedFacilitator: true to accept that, or configure facilitator.auth.`,
|
|
161
|
+
`${at}.allowUnauthenticatedFacilitator`
|
|
160
162
|
);
|
|
161
163
|
}
|
|
162
164
|
for (const [field, value] of credentialFields(input.facilitator.auth)) {
|
|
163
165
|
if (value.trim() === "") {
|
|
164
166
|
throw invalid(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
+
`${at}: facilitator.auth.type is "${input.facilitator.auth.type}" but ${field} is empty. An empty credential is refused rather than sent.`,
|
|
168
|
+
`${at}.facilitator.auth.${field}`
|
|
167
169
|
);
|
|
168
170
|
}
|
|
169
171
|
}
|
|
170
172
|
}
|
|
171
173
|
if (/^0x0{40}$/i.test(input.payTo)) {
|
|
172
174
|
throw invalid(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
+
`${at}: "${payTo}" is the zero address. Every payment settled there is destroyed.`,
|
|
176
|
+
`${at}.${payTo}`
|
|
175
177
|
);
|
|
176
178
|
}
|
|
177
179
|
if (mode !== "local" && isWellKnownDevAddress(input.payTo)) {
|
|
178
180
|
throw invalid(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
`${at}: "${payTo}" (${input.payTo}) is a well-known Anvil development address and this is a ${mode} deployment. Anyone can spend what settles there. Set ${payTo} to your own merchant wallet.`,
|
|
182
|
+
`${at}.${payTo}`
|
|
181
183
|
);
|
|
182
184
|
}
|
|
183
185
|
const canonical = profile.canonicalAsset;
|
|
184
186
|
if (mode === "mainnet" && canonical) {
|
|
185
187
|
if (!sameAddress(input.asset, canonical.address)) {
|
|
186
188
|
throw invalid(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
+
`${at}: asset ${input.asset} is not ${canonical.symbol} on ${profile.displayName} (expected ${canonical.address}). Settling a mainnet payment in an unintended token is refused.`,
|
|
190
|
+
`${at}.asset`
|
|
189
191
|
);
|
|
190
192
|
}
|
|
191
193
|
if (input.assetName !== void 0 && input.assetName !== canonical.name) {
|
|
192
194
|
throw invalid(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
+
`${at}: assetName "${input.assetName}" is not the EIP-712 domain name ${canonical.symbol} reports on ${profile.displayName} (expected "${canonical.name}"). Every payment would be refused after the buyer signed.`,
|
|
196
|
+
`${at}.assetName`
|
|
195
197
|
);
|
|
196
198
|
}
|
|
197
199
|
if (input.assetVersion !== void 0 && input.assetVersion !== canonical.version) {
|
|
198
200
|
throw invalid(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
+
`${at}: assetVersion "${input.assetVersion}" is not the EIP-712 domain version ${canonical.symbol} reports on ${profile.displayName} (expected "${canonical.version}").`,
|
|
202
|
+
`${at}.assetVersion`
|
|
201
203
|
);
|
|
202
204
|
}
|
|
203
205
|
}
|
|
204
206
|
return { profile, mode };
|
|
205
207
|
}
|
|
206
|
-
function assertFacilitatorUrlIsSafe(url, mode) {
|
|
208
|
+
function assertFacilitatorUrlIsSafe(url, mode, at) {
|
|
207
209
|
let parsed;
|
|
208
210
|
try {
|
|
209
211
|
parsed = new URL(url);
|
|
210
212
|
} catch (cause) {
|
|
211
|
-
throw new CommerceError("CONFIG_INVALID",
|
|
213
|
+
throw new CommerceError("CONFIG_INVALID", `${at}: facilitator.url is not a valid URL`, {
|
|
212
214
|
cause,
|
|
213
|
-
details: { path:
|
|
215
|
+
details: { path: `${at}.facilitator.url` }
|
|
214
216
|
});
|
|
215
217
|
}
|
|
216
218
|
if (parsed.protocol === "https:") return;
|
|
217
219
|
if (parsed.protocol !== "http:") {
|
|
218
220
|
throw invalid(
|
|
219
|
-
|
|
220
|
-
|
|
221
|
+
`${at}: facilitator ${describeOrigin(url)} must be reached over https (or http on a local/private host); got "${parsed.protocol}//"`,
|
|
222
|
+
`${at}.facilitator.url`
|
|
221
223
|
);
|
|
222
224
|
}
|
|
223
225
|
if (mode !== "mainnet" && isLikelyLocalOrPrivateHost(parsed.hostname)) return;
|
|
224
226
|
throw invalid(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
+
`${at}: facilitator ${describeOrigin(url)} is reached over plain HTTP. Payment authorisations and settlement results would travel unencrypted. Use https, or point at a local/private host on a non-mainnet deployment.`,
|
|
228
|
+
`${at}.facilitator.url`
|
|
227
229
|
);
|
|
228
230
|
}
|
|
229
231
|
function describeOrigin(url) {
|
|
@@ -250,6 +252,6 @@ function sameAddress(a, b) {
|
|
|
250
252
|
return a.toLowerCase() === b.toLowerCase();
|
|
251
253
|
}
|
|
252
254
|
|
|
253
|
-
export { SUPPORTED_NETWORK_IDS, assertDevKeyIsLocalOnly, assertPayToIsNotDevAddress, describeDeploymentMode, requireNetworkProfile, resolveDeploymentMode, resolveX402Deployment };
|
|
254
|
-
//# sourceMappingURL=chunk-
|
|
255
|
-
//# sourceMappingURL=chunk-
|
|
255
|
+
export { SUPPORTED_NETWORK_IDS, assertDevKeyIsLocalOnly, assertPayToIsNotDevAddress, describeDeploymentMode, describeRpc, requireNetworkProfile, resolveDeploymentMode, resolveX402Deployment };
|
|
256
|
+
//# sourceMappingURL=chunk-PBYN7EK2.js.map
|
|
257
|
+
//# sourceMappingURL=chunk-PBYN7EK2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/payments/x402/networks.ts","../src/payments/x402/local-chain/accounts.ts","../src/payments/x402/dev-key-guard.ts","../src/payments/x402/guardrails.ts"],"names":[],"mappings":";;;AAiDA,IAAM,QAAA,GAAsC;AAAA,EAC1C;AAAA,IACE,EAAA,EAAI,cAAA;AAAA,IACJ,OAAA,EAAS,KAAA;AAAA,IACT,WAAA,EAAa,cAAA;AAAA,IACb,IAAA,EAAM,SAAA;AAAA,IACN,cAAA,EAAgB;AAAA,MACd,MAAA,EAAQ,MAAA;AAAA,MACR,OAAA,EAA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AAAA,EACF;AACA,EAAA,IAAI,IAAA,KAAS,SAAA,IAAa,0BAAA,CAA2B,MAAA,CAAO,QAAQ,CAAA,EAAG;AAKvE,EAAA,MAAM,OAAA;AAAA,IACJ,CAAA,EAAG,EAAE,CAAA,cAAA,EAAiB,cAAA,CAAe,GAAG,CAAC,CAAA,6KAAA,CAAA;AAAA,IACzC,GAAG,EAAE,CAAA,gBAAA;AAAA,GACP;AACF;AAGA,SAAS,eAAe,GAAA,EAAqB;AAC3C,EAAA,IAAI;AACF,IAAA,OAAO,IAAI,GAAA,CAAI,GAAG,CAAA,CAAE,MAAA;AAAA,EACtB,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,+BAAA;AAAA,EACT;AACF;AAGA,SAAS,iBAAiB,IAAA,EAA+D;AACvF,EAAA,QAAQ,KAAK,IAAA;AAAM,IACjB,KAAK,QAAA;AACH,MAAA,OAAO,CAAC,CAAC,OAAA,EAAS,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA,IAC/B,KAAK,KAAA;AACH,MAAA,OAAO;AAAA,QACL,CAAC,UAAA,EAAY,IAAA,CAAK,QAAQ,CAAA;AAAA,QAC1B,CAAC,cAAA,EAAgB,IAAA,CAAK,YAAY;AAAA,OACpC;AAAA,IACF;AACE,MAAA,OAAO,EAAC;AAAA;AAEd;AAEA,SAAS,WAAA,CAAY,GAAW,CAAA,EAAoB;AAClD,EAAA,OAAO,CAAA,CAAE,WAAA,EAAY,KAAM,CAAA,CAAE,WAAA,EAAY;AAC3C","file":"chunk-PBYN7EK2.js","sourcesContent":["/**\n * The networks this gateway will settle on, as data.\n *\n * x402 v2 identifies a network by its CAIP-2 id, so the only thing an\n * operator has to change to move between environments is that string. What\n * the code needs on top of it — the chain id to sign against, a name a human\n * recognises, and whether real money is involved — lives here rather than\n * being derived at each call site.\n *\n * A registry rather than \"parse any `eip155:*`\" on purpose. The chain id is\n * parseable from any such string, but `mainnet` is not, and every guardrail in\n * `guardrails.ts` keys off it. An unknown id is refused at startup instead of\n * being quietly treated as a testnet.\n *\n * Base Sepolia and the local dev chain share the id `eip155:84532`: the local\n * chain deliberately reuses Base Sepolia's chain id so the unmodified x402 SDK\n * can talk to it. Nothing may infer \"public network\" from the network id alone\n * — that is what `resolveDeploymentMode` and the Anvil probe in `provider.ts`\n * are for.\n */\nimport { CommerceError } from '../../core/index.js';\n\nexport interface NetworkProfile {\n /** CAIP-2 identifier, e.g. `eip155:84532`. */\n readonly id: string;\n /** Signed into the buyer's EIP-712 domain. */\n readonly chainId: number;\n readonly displayName: string;\n readonly kind: 'testnet' | 'mainnet';\n /**\n * The USDC deployment this network is expected to settle in, with the EIP-712\n * domain the token actually reports. Enforced only on mainnet (see\n * `guardrails.ts`) — a testnet is where a mock token is a legitimate thing to\n * point at.\n *\n * `name` is not decorative and is not the symbol: it is signed into every\n * buyer's EIP-712 domain, and the two USDC deployments disagree. Base Sepolia\n * reports `\"USDC\"`; Base mainnet reports `\"USD Coin\"`. Configure the wrong\n * one and every payment is refused `invalid_exact_evm_token_name_mismatch`\n * after the buyer has signed. Read back from the contracts, not assumed.\n */\n readonly canonicalAsset?: {\n readonly symbol: string;\n readonly address: string;\n readonly name: string;\n readonly version: string;\n };\n}\n\nconst PROFILES: readonly NetworkProfile[] = [\n {\n id: 'eip155:84532',\n chainId: 84532,\n displayName: 'Base Sepolia',\n kind: 'testnet',\n canonicalAsset: {\n symbol: 'USDC',\n address: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',\n name: 'USDC',\n version: '2',\n },\n },\n {\n id: 'eip155:8453',\n chainId: 8453,\n displayName: 'Base',\n kind: 'mainnet',\n canonicalAsset: {\n symbol: 'USDC',\n address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n name: 'USD Coin',\n version: '2',\n },\n },\n];\n\nconst BY_ID = new Map(PROFILES.map((profile) => [profile.id, profile]));\n\nexport const SUPPORTED_NETWORK_IDS: readonly string[] = PROFILES.map((p) => p.id);\n\nexport function findNetworkProfile(id: string): NetworkProfile | undefined {\n return BY_ID.get(id);\n}\n\nexport function requireNetworkProfile(id: string, path: string): NetworkProfile {\n const profile = BY_ID.get(id);\n if (!profile) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `${path}: \"${id}\" is not a supported network. Supported CAIP-2 identifiers: ${SUPPORTED_NETWORK_IDS.join(', ')}`,\n { details: { path, network: id } },\n );\n }\n return profile;\n}\n\n/**\n * What this deployment actually is, as opposed to what it is called.\n *\n * `local` is a property of the *facilitator*, not the network: settling\n * through the in-process facilitator against a dev node is local regardless of\n * the CAIP-2 id that node answers to. This distinction is the whole reason\n * diagnostics can say `eip155:84532` without claiming to be on public Base\n * Sepolia.\n */\nexport type DeploymentMode = 'local' | 'testnet' | 'mainnet';\n\nexport function resolveDeploymentMode(\n profile: NetworkProfile,\n facilitatorMode: 'local' | 'remote',\n): DeploymentMode {\n if (facilitatorMode === 'local') return 'local';\n return profile.kind;\n}\n\n/** The banner an operator must not be able to miss. Never printed for anything else. */\nexport const LIVE_MAINNET_BANNER = 'LIVE MAINNET MODE — REAL FUNDS';\n\nexport function describeDeploymentMode(mode: DeploymentMode): string {\n return mode === 'mainnet' ? LIVE_MAINNET_BANNER : mode.toUpperCase();\n}\n","/**\n * Anvil's well-known development accounts.\n *\n * LOCAL DEVELOPMENT ONLY — DO NOT FUND. These addresses and private keys are\n * derived from Foundry's public, well-documented default test mnemonic\n * (\"test test test test test test test test test test test junk\") and are\n * known to everyone who has ever run `anvil`. Anyone who sends real value to\n * one of these addresses on a real network will lose it.\n *\n * Index layout used by the local demo chain (see docs/contracts.md):\n * 0 — deployer / local facilitator signer (pays gas, broadcasts settlement)\n * 1 — merchant settlement destination (`payTo`)\n * 2 — buyer (signs EIP-3009 authorisations; never held by the gateway)\n */\nexport interface AnvilWellKnownAccount {\n readonly address: `0x${string}`;\n readonly privateKey: `0x${string}`;\n}\n\n/** Fixed-length tuple (not a bare array) so indexing by the documented layout above is fully typed. */\nexport const ANVIL_WELL_KNOWN_ACCOUNTS: readonly [\n AnvilWellKnownAccount,\n AnvilWellKnownAccount,\n AnvilWellKnownAccount,\n] = [\n {\n address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',\n privateKey: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',\n },\n {\n address: '0x70997970C51812dc3A010C7d01b50e0d17dc79C8',\n privateKey: '0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d',\n },\n {\n address: '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',\n privateKey: '0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a',\n },\n];\n\nexport const LOCAL_FACILITATOR_ACCOUNT = ANVIL_WELL_KNOWN_ACCOUNTS[0];\nexport const LOCAL_MERCHANT_ACCOUNT = ANVIL_WELL_KNOWN_ACCOUNTS[1];\nexport const LOCAL_BUYER_ACCOUNT = ANVIL_WELL_KNOWN_ACCOUNTS[2];\n\n/** Safe label used everywhere a dev key appears in output, logs or manifests. */\nexport const DEV_KEY_LABEL = 'LOCAL DEVELOPMENT ONLY - DO NOT FUND';\n","/**\n * Prevents a well-known Anvil development private key — or a well-known\n * Anvil development *address* — from ever being used against anything other\n * than a loopback/private/dev RPC. Two symmetric mistakes, both covered:\n * signing settlement with a dev key (`assertDevKeyIsLocalOnly`), and routing\n * settlement revenue to a dev address (`assertPayToIsNotDevAddress`). The\n * second is the more consequential of the two — a wrong key merely fails to\n * sign, a wrong payTo silently succeeds and gives the money away, since the\n * private key behind every well-known Anvil address is public knowledge.\n *\n * Chain id alone cannot tell a real network from this project's local dev\n * chain: Base Sepolia's own chain id is 84532, the same id this project\n * deliberately reuses for the local chain so the unmodified x402 SDK can talk\n * to it. A dev key or dev payTo pointed at a real RPC by a config mistake is\n * instantly drainable — this is checked once at provider construction, not per\n * payment.\n */\nimport { CommerceError } from '../../core/index.js';\nimport { ANVIL_WELL_KNOWN_ACCOUNTS } from './local-chain/accounts.js';\n\nconst WELL_KNOWN_DEV_KEYS: ReadonlySet<string> = new Set(\n ANVIL_WELL_KNOWN_ACCOUNTS.map((a) => a.privateKey.toLowerCase()),\n);\n\nconst WELL_KNOWN_DEV_ADDRESSES: ReadonlySet<string> = new Set(\n ANVIL_WELL_KNOWN_ACCOUNTS.map((a) => a.address.toLowerCase()),\n);\n\n/** `0x` + 64 hex chars — the only shape `privateKeyToAccount` accepts. */\nconst PRIVATE_KEY_SHAPE = /^0x[0-9a-fA-F]{64}$/;\n\nexport function isWellKnownDevKey(privateKey: string): boolean {\n return WELL_KNOWN_DEV_KEYS.has(privateKey.toLowerCase());\n}\n\nexport function isWellKnownDevAddress(address: string): boolean {\n return WELL_KNOWN_DEV_ADDRESSES.has(address.toLowerCase());\n}\n\n/**\n * True for loopback addresses, RFC1918 private ranges, and bare (dot-free)\n * hostnames — the shape of a docker-compose/k8s service name (e.g.\n * \"anvil\"), which a real public DNS name essentially never has.\n *\n * ASSUMPTION, and the loosest edge of this guard: every dot-free, colon-free\n * hostname is treated as private, with no exceptions. A single-label *public* hostname (no dots) is\n * essentially nonexistent in practice — ICANN does not delegate bare\n * gTLDs/TLDs as public A/AAAA records — but this function cannot tell \"no\n * dots because it's a compose service name\" from \"no dots because it's an\n * unusual real host\" if one somehow existed. If that assumption ever stops\n * holding, this is the line to revisit.\n */\nexport function isLikelyLocalOrPrivateHost(hostname: string): boolean {\n const h = hostname.toLowerCase().replace(/^\\[|\\]$/g, '');\n if (h === 'localhost' || h === '127.0.0.1' || h === '::1') return true;\n if (/^127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (/^10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (/^192\\.168\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (/^172\\.(1[6-9]|2\\d|3[01])\\.\\d{1,3}\\.\\d{1,3}$/.test(h)) return true;\n if (!h.includes('.') && !h.includes(':')) return true; // bare hostname\n return false;\n}\n\nfunction parseHostnameOrThrow(rpcUrl: string): string {\n try {\n return new URL(rpcUrl).hostname;\n } catch (cause) {\n // Not the URL itself: every commercial EVM RPC provider embeds an API key\n // in the path, and these messages reach `validate`, `doctor`, startup\n // output and CI logs.\n throw new CommerceError('CONFIG_INVALID', 'x402 provider: rpcUrl is not a valid URL', {\n cause,\n });\n }\n}\n\n/** Host only, for diagnostics. An RPC URL's path routinely carries a key. */\n/** Origin only: RPC URLs often carry an API key in the path or query */\nexport function describeRpc(rpcUrl: string): string {\n try {\n return new URL(rpcUrl).origin;\n } catch {\n return '[unparseable rpcUrl]';\n }\n}\n\n/**\n * Throws CONFIG_INVALID if a well-known dev key would sign against a non-local\n * RPC — or if `signerPrivateKey` isn't shaped like a private key at all.\n *\n * The shape check runs first and unconditionally. \"Not a key I recognise\"\n * (falls through `isWellKnownDevKey`, silently treated as someone's own real\n * facilitator key) and \"not a key at all\" (e.g. a truncated 63-char string)\n * must never share a code path: a malformed key that slips past this guard\n * only fails later, inside `settle()`, after the buyer's replayKey is already\n * reserved.\n */\nexport function assertDevKeyIsLocalOnly(rpcUrl: string, signerPrivateKey: string): void {\n if (!PRIVATE_KEY_SHAPE.test(signerPrivateKey)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n 'x402 provider: facilitator.signerPrivateKey is not a well-formed private key ' +\n '(expected \"0x\" followed by exactly 64 hex characters).',\n );\n }\n\n if (!isWellKnownDevKey(signerPrivateKey)) return; // a real facilitator key: not our business\n\n const hostname = parseHostnameOrThrow(rpcUrl);\n\n if (!isLikelyLocalOrPrivateHost(hostname)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n 'x402 provider: facilitator.signerPrivateKey is a well-known Anvil development key, but rpcUrl ' +\n `${describeRpc(rpcUrl)} does not look like a local/private chain. A public dev key must never sign against ` +\n 'a public network — it is instantly drainable and can grief real settlements via nonce exhaustion. ' +\n 'Use a real facilitator key for any non-local RPC, or point rpcUrl at your local/dev chain.',\n );\n }\n}\n\n/**\n * Throws CONFIG_INVALID if `payTo` (the settlement destination) is a\n * well-known Anvil development address and `rpcUrl` doesn't look\n * local/private.\n *\n * Mirrors `assertDevKeyIsLocalOnly`, but guards the *receiving* side of the\n * payment instead of the signing side, and — unlike the key guard — applies\n * regardless of facilitator mode: which account signs the settlement\n * transaction has no bearing on whether the destination address is one whose\n * private key is public knowledge. `agent-commerce init` defaults `payTo` to\n * a well-known Anvil address as a local-demo convenience; on a real network\n * that default routes every payment to an address anyone on earth can sweep.\n */\nexport function assertPayToIsNotDevAddress(rpcUrl: string, payTo: string): void {\n if (!isWellKnownDevAddress(payTo)) return; // not a dev address: not our business\n\n const hostname = parseHostnameOrThrow(rpcUrl);\n\n if (!isLikelyLocalOrPrivateHost(hostname)) {\n throw new CommerceError(\n 'CONFIG_INVALID',\n `x402 provider: \"payTo\" (${payTo}) is a well-known Anvil development address, but rpcUrl ` +\n `${describeRpc(rpcUrl)} does not look like a local/private chain. The private key behind that address ` +\n 'is public knowledge, so any revenue settled to it is immediately spendable by anyone. Set ' +\n '\"payTo\" to your own merchant wallet for any non-local RPC, or point rpcUrl at your ' +\n 'local/dev chain.',\n );\n }\n}\n","/**\n * Everything that must be true before this gateway is allowed to settle a\n * payment on the configured network.\n *\n * One definition, two callers: the provider runs it at construction so a\n * library consumer who never touches our config loader still gets the checks,\n * and `doctor` runs it against the parsed config so an operator sees the same\n * verdict without starting the gateway. Sharing a *call* is not sharing a\n * definition — the checks live here, and nothing re-implements them.\n *\n * Every failure is a startup failure. None of these are request-time\n * decisions: a deployment that is unsafe is unsafe before the first buyer\n * arrives, and finding out during `settle()` means the buyer's authorisation\n * is already burned.\n *\n * Peer-free by construction (no viem, no `@x402/*`) so the CLI can import it.\n */\nimport { CommerceError } from '../../core/index.js';\nimport { isLikelyLocalOrPrivateHost, isWellKnownDevAddress } from './dev-key-guard.js';\nimport {\n type DeploymentMode,\n type NetworkProfile,\n requireNetworkProfile,\n resolveDeploymentMode,\n} from './networks.js';\n\n/**\n * How the gateway authenticates to a remote facilitator.\n *\n * Deliberately a list, not a vendor: x402 facilitators are not a Coinbase-only\n * category, and a scheme that only fitted one vendor's credentials would make\n * the abstraction a fiction.\n *\n * - `none` — the facilitator takes no credential (the public testnet one).\n * - `bearer` — a static token. Covers most self-hosted and third-party\n * facilitators, and needs nothing installed.\n * - `cdp` — Coinbase Developer Platform, which signs a fresh JWT per request\n * over method + host + path, so a static header cannot express it. Handled by\n * the optional peer `@coinbase/x402`, imported only when this type is\n * configured. Anyone not using CDP never installs it.\n *\n * A facilitator whose scheme is none of these is refused at config load rather\n * than sent nothing.\n */\nexport type FacilitatorAuth =\n | { readonly type: 'none' }\n | { readonly type: 'bearer'; readonly token: string }\n | { readonly type: 'cdp'; readonly apiKeyId: string; readonly apiKeySecret: string };\n\nexport type X402FacilitatorConfig =\n | { readonly mode: 'local'; readonly signerPrivateKey: string }\n | { readonly mode: 'remote'; readonly url: string; readonly auth: FacilitatorAuth };\n\nexport interface X402DeploymentInput {\n readonly network: string;\n readonly payTo: string;\n readonly asset: string;\n /** EIP-712 domain of the asset, as the token itself reports it. */\n readonly assetName?: string;\n readonly assetVersion?: string;\n readonly facilitator: X402FacilitatorConfig;\n /** Required, and required to be `true`, before anything settles on a mainnet. */\n readonly allowMainnet?: boolean;\n /**\n * Required, and required to be `true`, to settle on a mainnet through a\n * facilitator that takes no credential.\n *\n * Separate from `allowMainnet` because it names a different decision: not\n * \"I meant to use real money\" but \"I accept this particular counterparty\n * without an account, terms, or anyone to call\".\n */\n readonly allowUnauthenticatedFacilitator?: boolean;\n /** Error-path prefix, `payments.x402` by default */\n readonly configPath?: string;\n /** Settlement-recipient field named in errors, `payTo` by default */\n readonly payToField?: string;\n}\n\nexport interface X402Deployment {\n readonly profile: NetworkProfile;\n readonly mode: DeploymentMode;\n}\n\nfunction invalid(message: string, path: string): CommerceError {\n return new CommerceError('CONFIG_INVALID', message, { details: { path } });\n}\n\n/**\n * Resolves the deployment and refuses every combination that could move real\n * money by accident. Order matters only in that the network must resolve\n * first; the rest are independent.\n */\nexport function resolveX402Deployment(input: X402DeploymentInput): X402Deployment {\n const at = input.configPath ?? 'payments.x402';\n const payTo = input.payToField ?? 'payTo';\n const profile = requireNetworkProfile(input.network, `${at}.network`);\n const mode = resolveDeploymentMode(profile, input.facilitator.mode);\n\n // The in-process facilitator signs with a key this process holds. Not a\n // custody problem — that signer never holds buyer or merchant funds, it pays\n // gas and broadcasts `transferWithAuthorization`, and the money moves buyer\n // to merchant directly on-chain. What it *is*, on a mainnet, is a funded key\n // inside the resource server: compromise that process and an attacker drains\n // the gas wallet and broadcasts from it. Separate processes, separate blast\n // radius — so it is refused, not warned about.\n if (profile.kind === 'mainnet' && input.facilitator.mode === 'local') {\n throw invalid(\n `${at}: network \"${profile.id}\" (${profile.displayName}) is a mainnet and cannot be served by facilitator.mode \"local\". A mainnet deployment must settle through a remote facilitator.`,\n `${at}.facilitator.mode`,\n );\n }\n\n if (mode === 'mainnet' && input.allowMainnet !== true) {\n throw invalid(\n `${at}: network \"${profile.id}\" (${profile.displayName}) settles real funds. Set ${at}.allowMainnet: true to acknowledge this explicitly - it is never the default.`,\n `${at}.allowMainnet`,\n );\n }\n\n if (input.facilitator.mode === 'remote') {\n assertFacilitatorUrlIsSafe(input.facilitator.url, mode, at);\n // Not a funds check. An EIP-3009 authorisation names its recipient, its\n // amount and its chain, so a facilitator can broadcast exactly that\n // transfer or nothing — it cannot redirect the money. What a credential\n // buys is a *relationship*: rate limits, terms, someone to call when\n // settlement stops. Running production payments through a counterparty you\n // have none of that with is a real choice, and this is where it gets made\n // explicitly rather than by omission.\n if (\n mode === 'mainnet' &&\n input.facilitator.auth.type === 'none' &&\n input.allowUnauthenticatedFacilitator !== true\n ) {\n throw invalid(\n `${at}: facilitator ${describeOrigin(input.facilitator.url)} takes no credential, and this is a mainnet deployment. It will see every payment authorisation you handle, with no account, terms or support behind it. Set ${at}.allowUnauthenticatedFacilitator: true to accept that, or configure facilitator.auth.`,\n `${at}.allowUnauthenticatedFacilitator`,\n );\n }\n // An empty credential is refused rather than sent: a blank token or key\n // reaches the facilitator as \"unauthenticated\" and fails every payment\n // after the buyer has already signed. `${VAR:- }` resolving to whitespace\n // is the realistic way this happens.\n for (const [field, value] of credentialFields(input.facilitator.auth)) {\n if (value.trim() === '') {\n throw invalid(\n `${at}: facilitator.auth.type is \"${input.facilitator.auth.type}\" but ${field} is empty. An empty credential is refused rather than sent.`,\n `${at}.facilitator.auth.${field}`,\n );\n }\n }\n }\n\n // The private key behind every well-known Anvil address is public knowledge.\n // `dev-key-guard` already refuses one against a public *RPC*; this refuses\n // one on any non-local *deployment*, which is the case a remote facilitator\n // creates — there the RPC host says nothing about where settlement lands.\n // The zero address lived only in the config loader, so a library consumer\n // calling `createX402PaymentProvider` directly — the path this shared\n // definition exists to cover — could boot a mainnet provider whose every\n // payment burns — sharing a *call* is not sharing a definition, and this\n // check had drifted out of the shared one.\n if (/^0x0{40}$/i.test(input.payTo)) {\n throw invalid(\n `${at}: \"${payTo}\" is the zero address. Every payment settled there is destroyed.`,\n `${at}.${payTo}`,\n );\n }\n\n if (mode !== 'local' && isWellKnownDevAddress(input.payTo)) {\n throw invalid(\n `${at}: \"${payTo}\" (${input.payTo}) is a well-known Anvil development address and this is a ${mode} deployment. Anyone can spend what settles there. Set ${payTo} to your own merchant wallet.`,\n `${at}.${payTo}`,\n );\n }\n\n // Mainnet only. A testnet is exactly where pointing at a mock token is the\n // right thing to do, so the same check there would block the normal case.\n const canonical = profile.canonicalAsset;\n if (mode === 'mainnet' && canonical) {\n if (!sameAddress(input.asset, canonical.address)) {\n throw invalid(\n `${at}: asset ${input.asset} is not ${canonical.symbol} on ${profile.displayName} (expected ${canonical.address}). Settling a mainnet payment in an unintended token is refused.`,\n `${at}.asset`,\n );\n }\n // The EIP-712 domain is signed by the buyer and checked by the scheme. Get\n // it wrong and every payment is refused `invalid_exact_evm_token_name_mismatch`\n // *after* the buyer signed — a config error charged to the buyer's patience.\n // Caught here instead, before the gateway starts.\n if (input.assetName !== undefined && input.assetName !== canonical.name) {\n throw invalid(\n `${at}: assetName \"${input.assetName}\" is not the EIP-712 domain name ${canonical.symbol} reports on ${profile.displayName} (expected \"${canonical.name}\"). Every payment would be refused after the buyer signed.`,\n `${at}.assetName`,\n );\n }\n if (input.assetVersion !== undefined && input.assetVersion !== canonical.version) {\n throw invalid(\n `${at}: assetVersion \"${input.assetVersion}\" is not the EIP-712 domain version ${canonical.symbol} reports on ${profile.displayName} (expected \"${canonical.version}\").`,\n `${at}.assetVersion`,\n );\n }\n }\n\n return { profile, mode };\n}\n\n/**\n * A facilitator sees every payment authorisation this gateway handles. Plain\n * HTTP to one on a public network puts those on the wire in the clear and\n * lets anyone in the path rewrite a settlement result, so it is allowed only\n * where the endpoint cannot leave the host — a local or private address.\n */\nfunction assertFacilitatorUrlIsSafe(url: string, mode: DeploymentMode, at: string): void {\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch (cause) {\n throw new CommerceError('CONFIG_INVALID', `${at}: facilitator.url is not a valid URL`, {\n cause,\n details: { path: `${at}.facilitator.url` },\n });\n }\n\n if (parsed.protocol === 'https:') return;\n if (parsed.protocol !== 'http:') {\n throw invalid(\n `${at}: facilitator ${describeOrigin(url)} must be reached over https (or http on a local/private host); got \"${parsed.protocol}//\"`,\n `${at}.facilitator.url`,\n );\n }\n if (mode !== 'mainnet' && isLikelyLocalOrPrivateHost(parsed.hostname)) return;\n\n // The origin, never the whole URL: the path can carry a tenant or an API\n // key, which is why `/.well-known` withholds this field entirely. A refusal\n // message goes to `validate`, `doctor`, startup output and CI logs.\n throw invalid(\n `${at}: facilitator ${describeOrigin(url)} is reached over plain HTTP. Payment authorisations and settlement results would travel unencrypted. Use https, or point at a local/private host on a non-mainnet deployment.`,\n `${at}.facilitator.url`,\n );\n}\n\n/** Host only — a facilitator URL can carry a tenant path or an API key. */\nfunction describeOrigin(url: string): string {\n try {\n return new URL(url).origin;\n } catch {\n return '[unparseable facilitator.url]';\n }\n}\n\n/** The secret-bearing fields of an auth block, for emptiness checks only. Never logged. */\nfunction credentialFields(auth: FacilitatorAuth): readonly (readonly [string, string])[] {\n switch (auth.type) {\n case 'bearer':\n return [['token', auth.token]];\n case 'cdp':\n return [\n ['apiKeyId', auth.apiKeyId],\n ['apiKeySecret', auth.apiKeySecret],\n ];\n default:\n return [];\n }\n}\n\nfunction sameAddress(a: string, b: string): boolean {\n return a.toLowerCase() === b.toLowerCase();\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommerceError } from './chunk-
|
|
1
|
+
import { CommerceError } from './chunk-5GEWKNIH.js';
|
|
2
2
|
import { existsSync, mkdirSync, accessSync, constants, closeSync, openSync, chmodSync } from 'fs';
|
|
3
3
|
import { dirname } from 'path';
|
|
4
4
|
import Database from 'better-sqlite3';
|
|
@@ -64,5 +64,5 @@ function restrictDatabasePermissions(path, label, logger) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export { AP2_CHECKOUT_MANDATE_VCT, AP2_CHECKOUT_PROFILE, AP2_DEFAULT_CLOCK_SKEW_SECONDS, AP2_DIGEST_ALGORITHM, AP2_JWK_COORDINATE_BYTES, AP2_JWK_CURVE, AP2_JWK_MEMBERS, AP2_KEY_TYPE, AP2_MAX_CLOCK_SKEW_SECONDS, AP2_MODES, AP2_SIGNING_ALGORITHM, AP2_SPEC_VERSION, openSqliteDatabase };
|
|
67
|
-
//# sourceMappingURL=chunk-
|
|
68
|
-
//# sourceMappingURL=chunk-
|
|
67
|
+
//# sourceMappingURL=chunk-US622BKF.js.map
|
|
68
|
+
//# sourceMappingURL=chunk-US622BKF.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/authorization/ap2/constants.ts","../src/storage/sqlite.ts"],"names":["fsConstants"],"mappings":";;;;;;AAQO,IAAM,gBAAA,GAAmB;AAOzB,IAAM,SAAA,GAAY,CAAC,QAAQ;AAO3B,IAAM,qBAAA,GAAwB;A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EAAc;AAChB,IAAA,IAAI;AACF,MAAA,SAAA,CAAU,QAAA,CAAS,IAAA,EAAM,GAAA,EAAK,GAAK,CAAC,CAAA;AAAA,IACtC,CAAA,CAAA,MAAQ;AAAA,IAIR;AAAA,EACF;AAEA,EAAA,MAAM,EAAA,GAAK,IAAI,QAAA,CAAS,IAAI,CAAA;AAC5B,EAAA,EAAA,CAAG,OAAO,oBAAoB,CAAA;AAC9B,EAAA,EAAA,CAAG,OAAO,mBAAmB,CAAA;AAC7B,EAAA,IAAI,YAAA,EAAc,2BAAA,CAA4B,IAAA,EAAM,KAAA,EAAO,MAAM,CAAA;AACjE,EAAA,OAAO,EAAA;AACT;AAkBA,SAAS,2BAAA,CAA4B,IAAA,EAAc,KAAA,EAAe,MAAA,EAAsB;AACtF,EAAA,KAAA,MAAW,IAAA,IAAQ,CAAC,IAAA,EAAM,CAAA,EAAG,IAAI,CAAA,IAAA,CAAA,EAAQ,CAAA,EAAG,IAAI,CAAA,IAAA,CAAM,CAAA,EAAG;AACvD,IAAA,IAAI;AACF,MAAA,SAAA,CAAU,MAAM,GAAK,CAAA;AAAA,IACvB,SAAS,KAAA,EAAO;AACd,MAAA,MAAM,OAAQ,KAAA,CAAgC,IAAA;AAC9C,MAAA,IAAI,SAAS,QAAA,EAAU;AACvB,MAAA,MAAA,CAAO,IAAA;AAAA,QACL,EAAE,IAAA,EAAM,KAAA,EAAO,KAAA,EAAO,QAAQ,SAAA,EAAU;AAAA,QACxC;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACF","file":"chunk-7NKWFGBY.js","sourcesContent":["/**\n * Pinned AP2 identifiers and key policy.\n *\n * AP2 v0.2.0 (2026-04-28, commit b4587ac) is the tagged release this gateway\n * verifies against; unversioned `main` is never implemented against. Config,\n * the verifier and `doctor` all read these, so a bump lands in one place.\n */\n\nexport const AP2_SPEC_VERSION = '0.2.0';\n\n/**\n * Autonomous mode needs open mandates, cnf-bound agent keys and constraint\n * evaluation over `checkout.line_items`. Half of that would be worse than a\n * declared Direct-only profile, so it is refused rather than partly served.\n */\nexport const AP2_MODES = ['direct'] as const;\nexport type Ap2Mode = (typeof AP2_MODES)[number];\n\n/**\n * One entry, so `alg=none` and the HMAC family are excluded by construction\n * rather than by a check that has to remember them\n */\nexport const AP2_SIGNING_ALGORITHM = 'ES256';\n\n/** The key type and curve ES256 implies. Any other pair is refused at load */\nexport const AP2_KEY_TYPE = 'EC';\nexport const AP2_JWK_CURVE = 'P-256';\n\n/** Byte length of a P-256 coordinate, before base64url encoding */\nexport const AP2_JWK_COORDINATE_BYTES = 32;\n\n/**\n * JWK members a verification key may carry.\n *\n * An allowlist, so private material (`d`) and anything naming a URL (`x5u`,\n * or a smuggled `jku`) is refused without this list having to name it. Keys\n * are configured inline and never fetched; see docs/security.md.\n */\nexport const AP2_JWK_MEMBERS = ['kty', 'crv', 'x', 'y', 'kid', 'alg', 'use'] as const;\n\n/**\n * Compared against this literal, never as a prefix. `mandate.checkout.open.1`\n * carries spending constraints this release does not evaluate, so accepting it\n * would tell a buyer their limits were checked when nothing read them.\n */\nexport const AP2_CHECKOUT_MANDATE_VCT = 'mandate.checkout.1';\n\n/**\n * The checkout profile every merchant checkout JWT must declare.\n *\n * Ours, not AP2's: AP2 leaves the checkout payload outside its scope, so the\n * claims a paid-resource invocation needs had to be specified somewhere.\n *\n * A bare name, matching the gateway's other wire identifiers\n * (`agent-commerce/delivery`, `agent-commerce/v1.0.0`). A profile id is a\n * namespace and is never dereferenced, so a URL would only tie the wire format\n * to a domain. Frozen once released: merchants sign it into every checkout JWT.\n */\nexport const AP2_CHECKOUT_PROFILE = 'agent-commerce/ap2/checkout/v1';\n\n/**\n * Taken from the SD-JWT `_sd_alg`, which defaults to sha-256 when absent.\n * Anything else is refused rather than hashed as sha-256 anyway, which would\n * check a presentation under an algorithm it never claimed.\n */\nexport const AP2_DIGEST_ALGORITHM = 'sha-256';\n\n/** Seconds of clock skew tolerated on mandate and checkout time claims */\nexport const AP2_DEFAULT_CLOCK_SKEW_SECONDS = 60;\n\n/**\n * Skew wide enough to cover a mandate's validity window stops `exp` rejecting\n * anything. An operator needing more than five minutes has a clock to fix.\n */\nexport const AP2_MAX_CLOCK_SKEW_SECONDS = 300;\n","/**\n * Opening a SQLite file safely.\n *\n * One definition, because every rule below was learned once and must not be\n * re-learned per store: the file is pre-created at 0600 before SQLite can\n * create it at `0666 & ~umask`, the WAL sidecars are narrowed after WAL is\n * enabled (they do not exist until then), and an existing but unwritable file\n * fails at startup instead of on the first write.\n *\n * Callers own their schema. This function opens and hardens; it migrates\n * nothing.\n */\nimport {\n accessSync,\n chmodSync,\n closeSync,\n existsSync,\n constants as fsConstants,\n mkdirSync,\n openSync,\n} from 'node:fs';\nimport { dirname } from 'node:path';\nimport Database from 'better-sqlite3';\nimport { CommerceError, type Logger } from '../core/index.js';\n\nexport interface OpenSqliteOptions {\n /** File path, or ':memory:' for tests. Parent directory is created if missing. */\n readonly path: string;\n /** Names the database in operator-facing errors, e.g. \"Receipt database\". */\n readonly label: string;\n readonly logger: Logger;\n}\n\nexport function openSqliteDatabase(options: OpenSqliteOptions): Database.Database {\n const { path, label, logger } = options;\n const isFileBacked = path !== ':memory:';\n\n if (isFileBacked) {\n const dir = dirname(path);\n if (dir !== '' && dir !== '.' && !existsSync(dir)) {\n // 0700 on directories we create ourselves. An existing directory is the\n // operator's to own and is deliberately left alone.\n mkdirSync(dir, { recursive: true, mode: 0o700 });\n }\n }\n\n // Fail at startup, not on the first write. `new Database(path)` happily opens\n // a file the process cannot write, and SQLite only says \"attempt to write a\n // readonly database\" once a write is attempted - which on a paid resource is\n // *after* the payment attempt reservation, surfacing as an opaque\n // STORAGE_ERROR per request. Readiness does catch it (503), but the operator\n // is left guessing. This is not hypothetical: switching the demo containers\n // to a non-root user left an existing named volume root-owned, and that is\n // exactly how it presented.\n if (isFileBacked && existsSync(path)) {\n try {\n accessSync(path, fsConstants.W_OK);\n } catch {\n throw new CommerceError(\n 'STORAGE_ERROR',\n `${label} \"${path}\" exists but is not writable by this process (uid ${typeof process.getuid === 'function' ? process.getuid() : 'unknown'}). If this is a container that recently changed user, an existing volume may still be owned by the previous one - recreate it (docker compose down -v) or fix its ownership.`,\n { details: { path } },\n );\n }\n }\n\n // Create the file ourselves, at 0600, *before* SQLite can create it at\n // `0666 & ~umask`. The chmod below only narrows the mode after the fact: a\n // local co-tenant who opens the file inside that window keeps a readable\n // descriptor across the chmod and reads everything written afterwards.\n // SQLite copies the main file's mode onto the -wal/-shm sidecars, so this one\n // call covers all three. `mode` applies on creation only, so an existing file\n // is untouched here and left to the chmod.\n if (isFileBacked) {\n try {\n closeSync(openSync(path, 'a', 0o600));\n } catch {\n // Deliberately silent: whatever stopped us (unwritable directory, exotic\n // filesystem) is about to be reported by `new Database` with a better\n // message, or is harmless and covered by the chmod below.\n }\n }\n\n const db = new Database(path);\n db.pragma('journal_mode = WAL');\n db.pragma('foreign_keys = ON');\n if (isFileBacked) restrictDatabasePermissions(path, label, logger);\n return db;\n}\n\n/**\n * Narrow the database and its WAL sidecars to owner-only.\n *\n * `new Database(path)` opens with `0666 & ~umask`, so on a standard host the\n * `.sqlite`, `-wal` and `-shm` files landed at 0644 - any other local user\n * could read the whole commerce ledger: payer and payee addresses, amounts,\n * settlement transaction hashes, replay keys and the entire event stream. No\n * key material (the gateway is non-custodial and `redact.ts` is recursive), but\n * business metadata all the same.\n *\n * Called *after* `journal_mode = WAL`, because the sidecars do not exist until\n * then. Belt-and-braces since the main file is pre-created at 0600 above: this\n * still tightens a database that already existed with a looser mode.\n * Best-effort by design: a filesystem without POSIX modes must not stop the\n * gateway from starting, so a failure warns rather than throws.\n */\nfunction restrictDatabasePermissions(path: string, label: string, logger: Logger): void {\n for (const file of [path, `${path}-wal`, `${path}-shm`]) {\n try {\n chmodSync(file, 0o600);\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code === 'ENOENT') continue;\n logger.warn(\n { file, label, error: code ?? 'unknown' },\n 'could not restrict database permissions to owner-only',\n );\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-28, commit b4587ac) is the tagged release this gateway\n * verifies against; unversioned `main` is never implemented against. Config,\n * the verifier and `doctor` all read these, so a bump lands in one place.\n */\n\nexport const AP2_SPEC_VERSION = '0.2.0';\n\n/**\n * Autonomous mode needs open mandates, cnf-bound agent keys and constraint\n * evaluation over `checkout.line_items`. Half of that would be worse than a\n * declared Direct-only profile, so it is refused rather than partly served.\n */\nexport const AP2_MODES = ['direct'] as const;\nexport type Ap2Mode = (typeof AP2_MODES)[number];\n\n/**\n * One entry, so `alg=none` and the HMAC family are excluded by construction\n * rather than by a check that has to remember them\n */\nexport const AP2_SIGNING_ALGORITHM = 'ES256';\n\n/** The key type and curve ES256 implies. Any other pair is refused at load */\nexport const AP2_KEY_TYPE = 'EC';\nexport const AP2_JWK_CURVE = 'P-256';\n\n/** Byte length of a P-256 coordinate, before base64url encoding */\nexport const AP2_JWK_COORDINATE_BYTES = 32;\n\n/**\n * JWK members a verification key may carry.\n *\n * An allowlist, so private material (`d`) and anything naming a URL (`x5u`,\n * or a smuggled `jku`) is refused without this list having to name it. Keys\n * are configured inline and never fetched; see docs/security.md.\n */\nexport const AP2_JWK_MEMBERS = ['kty', 'crv', 'x', 'y', 'kid', 'alg', 'use'] as const;\n\n/**\n * Compared against this literal, never as a prefix. `mandate.checkout.open.1`\n * carries spending constraints this release does not evaluate, so accepting it\n * would tell a buyer their limits were checked when nothing read them.\n */\nexport const AP2_CHECKOUT_MANDATE_VCT = 'mandate.checkout.1';\n\n/**\n * The checkout profile every merchant checkout JWT must declare.\n *\n * Ours, not AP2's: AP2 leaves the checkout payload outside its scope, so the\n * claims a paid-resource invocation needs had to be specified somewhere.\n *\n * A bare name, matching the gateway's other wire identifiers\n * (`agent-commerce/delivery`, `agent-commerce/v1.0.0`). A profile id is a\n * namespace and is never dereferenced, so a URL would only tie the wire format\n * to a domain. Frozen once released: merchants sign it into every checkout JWT.\n */\nexport const AP2_CHECKOUT_PROFILE = 'agent-commerce/ap2/checkout/v1';\n\n/**\n * Taken from the SD-JWT `_sd_alg`, which defaults to sha-256 when absent.\n * Anything else is refused rather than hashed as sha-256 anyway, which would\n * check a presentation under an algorithm it never claimed.\n */\nexport const AP2_DIGEST_ALGORITHM = 'sha-256';\n\n/** Seconds of clock skew tolerated on mandate and checkout time claims */\nexport const AP2_DEFAULT_CLOCK_SKEW_SECONDS = 60;\n\n/**\n * Skew wide enough to cover a mandate's validity window stops `exp` rejecting\n * anything. An operator needing more than five minutes has a clock to fix.\n */\nexport const AP2_MAX_CLOCK_SKEW_SECONDS = 300;\n","/**\n * Opening a SQLite file safely.\n *\n * One definition, because every rule below was learned once and must not be\n * re-learned per store: the file is pre-created at 0600 before SQLite can\n * create it at `0666 & ~umask`, the WAL sidecars are narrowed after WAL is\n * enabled (they do not exist until then), and an existing but unwritable file\n * fails at startup instead of on the first write.\n *\n * Callers own their schema. This function opens and hardens; it migrates\n * nothing.\n */\nimport {\n accessSync,\n chmodSync,\n closeSync,\n existsSync,\n constants as fsConstants,\n mkdirSync,\n openSync,\n} from 'node:fs';\nimport { dirname } from 'node:path';\nimport Database from 'better-sqlite3';\nimport { CommerceError, type Logger } from '../core/index.js';\n\nexport interface OpenSqliteOptions {\n /** File path, or ':memory:' for tests. Parent directory is created if missing. */\n readonly path: string;\n /** Names the database in operator-facing errors, e.g. \"Receipt database\". */\n readonly label: string;\n readonly logger: Logger;\n}\n\nexport function openSqliteDatabase(options: OpenSqliteOptions): Database.Database {\n const { path, label, logger } = options;\n const isFileBacked = path !== ':memory:';\n\n if (isFileBacked) {\n const dir = dirname(path);\n if (dir !== '' && dir !== '.' && !existsSync(dir)) {\n // 0700 on directories we create ourselves. An existing directory is the\n // operator's to own and is deliberately left alone.\n mkdirSync(dir, { recursive: true, mode: 0o700 });\n }\n }\n\n // Fail at startup, not on the first write. `new Database(path)` happily opens\n // a file the process cannot write, and SQLite only says \"attempt to write a\n // readonly database\" once a write is attempted - which on a paid resource is\n // *after* the payment attempt reservation, surfacing as an opaque\n // STORAGE_ERROR per request. Readiness does catch it (503), but the operator\n // is left guessing. This is not hypothetical: switching the demo containers\n // to a non-root user left an existing named volume root-owned, and that is\n // exactly how it presented.\n if (isFileBacked && existsSync(path)) {\n try {\n accessSync(path, fsConstants.W_OK);\n } catch {\n throw new CommerceError(\n 'STORAGE_ERROR',\n `${label} \"${path}\" exists but is not writable by this process (uid ${typeof process.getuid === 'function' ? process.getuid() : 'unknown'}). If this is a container that recently changed user, an existing volume may still be owned by the previous one - recreate it (docker compose down -v) or fix its ownership.`,\n { details: { path } },\n );\n }\n }\n\n // Create the file ourselves, at 0600, *before* SQLite can create it at\n // `0666 & ~umask`. The chmod below only narrows the mode after the fact: a\n // local co-tenant who opens the file inside that window keeps a readable\n // descriptor across the chmod and reads everything written afterwards.\n // SQLite copies the main file's mode onto the -wal/-shm sidecars, so this one\n // call covers all three. `mode` applies on creation only, so an existing file\n // is untouched here and left to the chmod.\n if (isFileBacked) {\n try {\n closeSync(openSync(path, 'a', 0o600));\n } catch {\n // Deliberately silent: whatever stopped us (unwritable directory, exotic\n // filesystem) is about to be reported by `new Database` with a better\n // message, or is harmless and covered by the chmod below.\n }\n }\n\n const db = new Database(path);\n db.pragma('journal_mode = WAL');\n db.pragma('foreign_keys = ON');\n if (isFileBacked) restrictDatabasePermissions(path, label, logger);\n return db;\n}\n\n/**\n * Narrow the database and its WAL sidecars to owner-only.\n *\n * `new Database(path)` opens with `0666 & ~umask`, so on a standard host the\n * `.sqlite`, `-wal` and `-shm` files landed at 0644 - any other local user\n * could read the whole commerce ledger: payer and payee addresses, amounts,\n * settlement transaction hashes, replay keys and the entire event stream. No\n * key material (the gateway is non-custodial and `redact.ts` is recursive), but\n * business metadata all the same.\n *\n * Called *after* `journal_mode = WAL`, because the sidecars do not exist until\n * then. Belt-and-braces since the main file is pre-created at 0600 above: this\n * still tightens a database that already existed with a looser mode.\n * Best-effort by design: a filesystem without POSIX modes must not stop the\n * gateway from starting, so a failure warns rather than throws.\n */\nfunction restrictDatabasePermissions(path: string, label: string, logger: Logger): void {\n for (const file of [path, `${path}-wal`, `${path}-shm`]) {\n try {\n chmodSync(file, 0o600);\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code === 'ENOENT') continue;\n logger.warn(\n { file, label, error: code ?? 'unknown' },\n 'could not restrict database permissions to owner-only',\n );\n }\n }\n}\n"]}
|