@bosonprotocol/x402-core 0.2.0 → 0.2.1-alpha-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.
@@ -1255,8 +1255,10 @@ declare const hex32Schema: z.ZodString;
1255
1255
  declare const decimalUintSchema: z.ZodString;
1256
1256
  declare const evmNetworkSchema: z.ZodString;
1257
1257
 
1258
+ declare function findEscrowAccept(body: unknown): unknown | undefined;
1259
+
1258
1260
  /** Stable identifier for the scheme. Use this in place of the raw string `"escrow"` to avoid typos. */
1259
1261
  declare const ESCROW_SCHEME: "escrow";
1260
1262
  type EscrowScheme = typeof ESCROW_SCHEME;
1261
1263
 
1262
- export { ACTION_CHANNELS, ADDRESS, type ActionChannel, type ActionsEnvelope, type ActionsFallback, type Address, type BosonCommitActionId, type BosonMetaTx, type BosonOfferRef, type BosonTokenAuth, DECIMAL_UINT, ESCROW_SCHEME, EVM_NETWORK, type Erc3009AuthData, type EscrowNextActions, type EscrowPaymentPayload, type EscrowPaymentPayloadInner, type EscrowPaymentRequirements, type EscrowScheme, type EvmNetwork, type FulfillmentOption, type FulfillmentRequirements, type FullOffer, HEX, HEX32, HEX_BYTES, type Hex, type NextAction, type OnchainHints, type Permit2AuthData, type PermitAuthData, TOKEN_AUTH_STRATEGIES, type TokenAuthStrategy, addressSchema, decimalUintSchema, escrowNextActionsSchema, escrowPaymentPayloadSchema, escrowPaymentRequirementsSchema, evmNetworkSchema, hex32Schema, hexBytesSchema, hexSchema, parseEscrowNextActions, parseEscrowPaymentPayload, parseEscrowPaymentRequirements };
1264
+ export { ACTION_CHANNELS, ADDRESS, type ActionChannel, type ActionsEnvelope, type ActionsFallback, type Address, type BosonCommitActionId, type BosonMetaTx, type BosonOfferRef, type BosonTokenAuth, DECIMAL_UINT, ESCROW_SCHEME, EVM_NETWORK, type Erc3009AuthData, type EscrowNextActions, type EscrowPaymentPayload, type EscrowPaymentPayloadInner, type EscrowPaymentRequirements, type EscrowScheme, type EvmNetwork, type FulfillmentOption, type FulfillmentRequirements, type FullOffer, HEX, HEX32, HEX_BYTES, type Hex, type NextAction, type OnchainHints, type Permit2AuthData, type PermitAuthData, TOKEN_AUTH_STRATEGIES, type TokenAuthStrategy, addressSchema, decimalUintSchema, escrowNextActionsSchema, escrowPaymentPayloadSchema, escrowPaymentRequirementsSchema, evmNetworkSchema, findEscrowAccept, hex32Schema, hexBytesSchema, hexSchema, parseEscrowNextActions, parseEscrowPaymentPayload, parseEscrowPaymentRequirements };
@@ -200,6 +200,20 @@ function parseEscrowNextActions(value) {
200
200
  return escrowNextActionsSchema.parse(value);
201
201
  }
202
202
 
203
+ // src/schemes/escrow/accepts.ts
204
+ function findEscrowAccept(body) {
205
+ if (typeof body !== "object" || body === null) {
206
+ return void 0;
207
+ }
208
+ const accepts = body.accepts;
209
+ if (!Array.isArray(accepts)) {
210
+ return void 0;
211
+ }
212
+ return accepts.find(
213
+ (entry) => typeof entry === "object" && entry !== null && entry.scheme === "escrow"
214
+ );
215
+ }
216
+
203
217
  // src/schemes/escrow/index.ts
204
218
  var ESCROW_SCHEME = "escrow";
205
219
 
@@ -218,6 +232,7 @@ exports.escrowNextActionsSchema = escrowNextActionsSchema;
218
232
  exports.escrowPaymentPayloadSchema = escrowPaymentPayloadSchema;
219
233
  exports.escrowPaymentRequirementsSchema = escrowPaymentRequirementsSchema;
220
234
  exports.evmNetworkSchema = evmNetworkSchema;
235
+ exports.findEscrowAccept = findEscrowAccept;
221
236
  exports.hex32Schema = hex32Schema;
222
237
  exports.hexBytesSchema = hexBytesSchema;
223
238
  exports.hexSchema = hexSchema;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/schemes/escrow/types.ts","../../../../src/schemes/escrow/validators.ts","../../../../src/schemes/escrow/shared-schemas.ts","../../../../src/schemes/escrow/payment-requirements.ts","../../../../src/schemes/escrow/payment-payload.ts","../../../../src/state-machine/states.ts","../../../../src/schemes/escrow/next-actions.ts","../../../../src/schemes/escrow/index.ts"],"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CAAC,EACA,MAAA;AAEI,SAAS,0BAA0B,KAAA,EAAsC;AAC9E,EAAA,OAAO,0BAAA,CAA2B,MAAM,KAAK,CAAA;AAC/C;AC7JO,IAAM,gBAAgBE,gBAAA,CAAS,aAAA;AAI/B,IAAM,eAAeA,gBAAA,CAAS,YAAA;;;ACgBrC,IAAM,mBAAA,GAAsBF,KAAAA,CAAE,UAAA,CAAW,aAAa,CAAA;AACtD,IAAM,kBAAA,GAAqBA,KAAAA,CAAE,UAAA,CAAW,YAAY,CAAA;AAG7C,IAAM,uBAAA,GAA0BA,MACpC,MAAA,CAAO;AAAA,EACN,UAAA,EAAYA,KAAAA,CAAE,MAAA,EAAO,CAAE,IAAI,CAAC,CAAA;AAAA,EAC5B,aAAA,EAAe,mBAAA;AAAA,EACf,YAAA,EAAc,mBAAmB,QAAA,EAAS;AAAA,EAC1C,IAAA,EAAMA,KAAAA,CAAE,KAAA,CAAM,iBAAiB,CAAA;AAAA,EAC/B,QAAA,EAAU,sBAAsB,QAAA;AAClC,CAAC,CAAA,CACA,QAAO,CACP,MAAA;AAAA,EACC,CAAC,QAAA,KACC,QAAA,CAAS,aAAA,KAAkB,aAAA,CAAc,WACrC,QAAA,CAAS,YAAA,KAAiB,MAAA,GAC1B,QAAA,CAAS,YAAA,KAAiB,MAAA;AAAA,EAChC;AAAA,IACE,OAAA,EAAS,yDAAA;AAAA,IACT,IAAA,EAAM,CAAC,cAAc;AAAA;AAEzB;AAGK,SAAS,uBAAuB,KAAA,EAAmC;AACxE,EAAA,OAAO,uBAAA,CAAwB,MAAM,KAAK,CAAA;AAC5C;;;ACtDO,IAAM,aAAA,GAAgB","file":"index.js","sourcesContent":["// Shared wire-format types for the `escrow` scheme.\n// Source of truth: docs/boson-impl-01-escrow-scheme.md.\n\n/**\n * CAIP-2 network identifier for an EVM chain. Constrained to `eip155:<chainId>`\n * shape at runtime by the JSON Schema and zod regex; aliased to `string` here\n * for the same reason as `Address` / `Hex` — the wire format is JSON, where\n * everything is a string, and template-literal types cause friction with\n * zod's regex-based validators.\n */\nexport type EvmNetwork = string;\n\n/** BPIP-12 token-authorization strategies. */\nexport type TokenAuthStrategy = \"none\" | \"erc3009\" | \"permit\" | \"permit2\";\nexport const TOKEN_AUTH_STRATEGIES: readonly TokenAuthStrategy[] = [\n \"none\",\n \"erc3009\",\n \"permit\",\n \"permit2\",\n] as const;\n\n/** Boson commit-time action ids advertised by the server. */\nexport type BosonCommitActionId = \"boson-createOfferAndCommit\" | \"boson-createOfferCommitAndRedeem\";\n\n/** Channels through which a `nextAction` can be performed. */\nexport type ActionChannel = \"server\" | \"facilitator\" | \"onchain\" | \"mcp\" | \"xmtp\";\nexport const ACTION_CHANNELS: readonly ActionChannel[] = [\n \"server\",\n \"facilitator\",\n \"onchain\",\n \"mcp\",\n \"xmtp\",\n] as const;\n\n/**\n * BPIP-10 FullOffer. Treated as opaque at this layer — the on-chain shape lives\n * in `@bosonprotocol/core-sdk`, and validation against the protocol struct is\n * the EIP-712 builder's job. Here it's just \"an object echoed verbatim\".\n */\nexport type FullOffer = Record<string, unknown>;\n\n/**\n * 0x-prefixed hex string. Aliased to `string` in the wire format so JSON\n * shapes are easy to construct; runtime validation is handled by the JSON\n * Schema and zod regex. The strongly-typed `\\`0x${string}\\`` form is reserved\n * for the EIP-712 builder layer where viem's brands matter.\n */\nexport type Hex = string;\n/** 0x-prefixed 40-char hex string. See `Hex` for typing rationale. */\nexport type Address = string;\n\n/** Off-chain offer reference signed by the seller. */\nexport interface BosonOfferRef {\n fullOffer: FullOffer;\n sellerSig: Hex;\n creator: Address;\n}\n\nexport interface FulfillmentOption {\n id: string;\n /** JSON-Schema-shaped `type: object` description of the data the buyer must supply, or `null` for schemaless channels. */\n schema: Record<string, unknown> | null;\n /** Channel-specific hints advertised to the client, such as endpoint URLs or public keys. */\n metadata?: unknown;\n}\n\nexport interface FulfillmentRequirements {\n required: boolean;\n options: FulfillmentOption[];\n}\n\nexport interface NextAction {\n id: string;\n channels: ActionChannel[];\n endpoints?: Record<string, string>;\n /**\n * ISO 8601 absolute timestamp by which the action must be invoked.\n * Relevant for dispute-window-bounded actions like\n * `boson-resolveDispute`, `boson-escalateDispute`,\n * `boson-retractDispute`, and (post-commit) `boson-completeExchange`.\n */\n deadline?: string;\n}\n\nexport interface OnchainHints {\n /** Address of the Boson escrow contract. */\n escrow: Address;\n metaTxFacet: string;\n /**\n * Per-`tokenAuthStrategy` meta-tx entry points on `metaTxFacet`. The\n * Boson Diamond exposes two functions on `MetaTransactionsHandlerFacet`:\n *\n * - `executeMetaTransaction` — legacy BPIP-9 entry point. Used when\n * the buyer's `tokenAuthStrategy` is `none` (the buyer has\n * pre-approved the Diamond, so no token-transfer authorization\n * queue is needed). Also the right entry point for any\n * post-commit action that doesn't move tokens (`redeem`,\n * `complete`, dispute transitions).\n * - `executeMetaTransactionWithTokenTransferAuthorization` — BPIP-12\n * entry point. Carries the buyer's signed `MetaTransaction` *and*\n * a queue of token-transfer authorizations. Used when\n * `tokenAuthStrategy` is `erc3009`, `permit`, or `permit2`.\n *\n * Clients select the entry point by their chosen strategy at\n * dispatch time.\n */\n metaTxEntrypoints: Record<TokenAuthStrategy, string>;\n actionFacets: Record<string, string>;\n}\n\nexport interface ActionsFallback {\n xmtp?: string;\n /**\n * Identifier within the Boson MCP server (e.g. the\n * `bosonprotocol/agentic-commerce` server) that the buyer's\n * MCP-aware agent dispatches against. The MCP *server* is escrow-\n * level (one BosonMCP serving every Boson seller); this value is the\n * URI/identifier the BosonMCP routes to the right exchange / seller.\n */\n mcp?: string;\n onchainHints?: OnchainHints;\n}\n\nexport interface ActionsEnvelope {\n next: NextAction[];\n fallback?: ActionsFallback;\n}\n\n/** Boson protocol meta-transaction envelope (signed by the buyer). */\nexport interface BosonMetaTx {\n from: Address;\n /** Decimal string. */\n nonce: string;\n functionName: string;\n /**\n * ABI-encoded function-call data as a `0x`-prefixed hex string. Named\n * `functionSignature` to match the on-chain `MetaTransactionsHandlerFacet`\n * struct field — the value is the encoded calldata, not just the function\n * selector.\n */\n functionSignature: Hex;\n sig: { v: number; r: Hex; s: Hex };\n}\n\nexport interface Erc3009AuthData {\n from: Address;\n to: Address;\n /** Atomic units, decimal string. */\n value: string;\n validAfter: number;\n validBefore: number;\n /** 32-byte hex string. */\n nonce: Hex;\n v: number;\n r: Hex;\n s: Hex;\n}\n\nexport interface PermitAuthData {\n owner: Address;\n spender: Address;\n /** Atomic units, decimal string. */\n value: string;\n deadline: number;\n /** Token-internal sequential nonce, decimal string. */\n nonce: string;\n v: number;\n r: Hex;\n s: Hex;\n}\n\nexport interface Permit2AuthData {\n permitted: { token: Address; amount: string };\n spender: Address;\n /** Permit2 word-bitmap nonce, decimal string. */\n nonce: string;\n deadline: number;\n /** Concatenated 65-byte ECDSA signature. */\n signature: Hex;\n}\n\n/** Discriminated union of all token-authorization payloads. `none` is encoded by the absence of this field on the payload. */\nexport type BosonTokenAuth =\n | { kind: \"erc3009\"; data: Erc3009AuthData }\n | { kind: \"permit\"; data: PermitAuthData }\n | { kind: \"permit2\"; data: Permit2AuthData };\n","// Shared regex patterns + scalar zod schemas used across the `escrow`\n// scheme's payment-requirements and payment-payload validators. Keeping\n// them in one place ensures the JSON Schema's patterns and the zod regexes\n// stay in sync (see `schemas/*.json` for the JSON Schema source of truth).\n\nimport { z } from \"zod\";\n\n/** 0x-prefixed hex string, at least one nibble. */\nexport const HEX = /^0x[a-fA-F0-9]+$/;\n\n/** 0x-prefixed hex string, allowing the empty `0x` form for empty bytes. */\nexport const HEX_BYTES = /^0x[a-fA-F0-9]*$/;\n\n/** 0x-prefixed 32-byte (64-nibble) hex string. */\nexport const HEX32 = /^0x[a-fA-F0-9]{64}$/;\n\n/** 0x-prefixed 20-byte (40-nibble) hex address. */\nexport const ADDRESS = /^0x[a-fA-F0-9]{40}$/;\n\n/** Decimal unsigned integer string, no leading zeros (except \"0\" itself). */\nexport const DECIMAL_UINT = /^(0|[1-9][0-9]*)$/;\n\n/** CAIP-2 EVM network identifier: `eip155:<chainId>`. */\nexport const EVM_NETWORK = /^eip155:[1-9][0-9]*$/;\n\nexport const addressSchema = z.string().regex(ADDRESS);\nexport const hexSchema = z.string().regex(HEX);\nexport const hexBytesSchema = z.string().regex(HEX_BYTES);\nexport const hex32Schema = z.string().regex(HEX32);\nexport const decimalUintSchema = z.string().regex(DECIMAL_UINT);\nexport const evmNetworkSchema = z.string().regex(EVM_NETWORK);\n","// Shared zod fragments used by both `payment-requirements.ts` (the\n// pre-commit / 402 envelope) and `next-actions.ts` (the post-commit\n// envelope). Centralised here so the two wire-format validators can't\n// drift on shared sub-shapes like an action entry, the `fallback` block,\n// or the `onchainHints` block.\n\nimport { z } from \"zod\";\n\nimport { ACTION_CHANNELS, type ActionChannel } from \"./types.js\";\nimport { addressSchema } from \"./validators.js\";\n\n/** ISO 8601 absolute timestamp with timezone offset. */\nexport const actionDeadlineSchema = z.string().datetime({ offset: true });\n\n/** Non-empty unique `ActionChannel[]` for `next[i].channels`. */\nexport const actionChannelsSchema = z\n .array(z.enum(ACTION_CHANNELS as readonly [ActionChannel, ...ActionChannel[]]))\n .min(1)\n .refine((channels) => new Set(channels).size === channels.length, {\n message: \"channels must contain unique items\",\n });\n\n/** Single entry in the `next[]` array of any `nextActions` envelope. */\nexport const actionEntrySchema = z\n .object({\n id: z.string().min(1),\n channels: actionChannelsSchema,\n endpoints: z.record(z.string()).optional(),\n deadline: actionDeadlineSchema.optional(),\n })\n .strict();\n\n/**\n * Per-`tokenAuthStrategy` meta-tx entry points on\n * `onchainHints.metaTxFacet`. All four strategies are required so\n * clients can resolve any strategy they happen to advertise.\n */\nexport const metaTxEntrypointsSchema = z\n .object({\n none: z.string().min(1),\n erc3009: z.string().min(1),\n permit: z.string().min(1),\n permit2: z.string().min(1),\n })\n .strict();\n\n/** `fallback.onchainHints` block. */\nexport const onchainHintsSchema = z\n .object({\n escrow: addressSchema,\n metaTxFacet: z.string().min(1),\n metaTxEntrypoints: metaTxEntrypointsSchema,\n actionFacets: z.record(z.string()),\n })\n .strict();\n\n/** `fallback` block embedded in any `nextActions` envelope. */\nexport const actionsFallbackSchema = z\n .object({\n xmtp: z.string().optional(),\n mcp: z.string().optional(),\n onchainHints: onchainHintsSchema.optional(),\n })\n .strict();\n","// `escrow` scheme PaymentRequirements (server -> client, in 402 body).\n// Source of truth: docs/boson-impl-01-escrow-scheme.md §2.\n\nimport { z } from \"zod\";\n\nimport { actionEntrySchema, actionsFallbackSchema } from \"./shared-schemas.js\";\nimport {\n TOKEN_AUTH_STRATEGIES,\n type ActionsEnvelope,\n type Address,\n type BosonOfferRef,\n type EvmNetwork,\n type FulfillmentRequirements,\n type TokenAuthStrategy,\n} from \"./types.js\";\nimport { addressSchema, decimalUintSchema, evmNetworkSchema, hexSchema } from \"./validators.js\";\n\nconst offerRefSchema = z\n .object({\n fullOffer: z.record(z.unknown()),\n sellerSig: hexSchema,\n creator: addressSchema,\n })\n .strict();\n\nconst tokenAuthStrategySchema = z.enum(\n TOKEN_AUTH_STRATEGIES as readonly [TokenAuthStrategy, ...TokenAuthStrategy[]],\n);\n\nconst fulfillmentSchema = z\n .object({\n required: z.boolean(),\n options: z.array(\n z\n .object({\n id: z.string().min(1),\n schema: z.union([z.record(z.unknown()), z.null()]),\n metadata: z.unknown().optional(),\n })\n .strict(),\n ),\n })\n .strict();\n\n// Pre-commit (initial 402) `actions` envelope: `next[]` must be\n// non-empty (the buyer needs at least one path to commit) and the\n// `fallback` block is optional.\nconst actionsSchema = z\n .object({\n next: z.array(actionEntrySchema).min(1),\n fallback: actionsFallbackSchema.optional(),\n })\n .strict();\n\n/**\n * Wire-format type for the `escrow` PaymentRequirements that a server emits\n * inside a 402 `accepts[]` entry. See docs/boson-impl-01-escrow-scheme.md §2\n * for field semantics.\n */\nexport interface EscrowPaymentRequirements {\n scheme: \"escrow\";\n network: EvmNetwork;\n asset: Address;\n /** Atomic units, decimal string. */\n amount: string;\n /** Address of the Boson escrow contract — the custodian. */\n escrowAddress: Address;\n /** Routing-only seller identifier. May be a numeric `sellerId`, a `did:boson:seller:N`, or a wallet address. */\n recipientId: string;\n maxTimeoutSeconds: number;\n offer: BosonOfferRef;\n tokenAuthStrategies: TokenAuthStrategy[];\n fulfillment?: FulfillmentRequirements;\n actions: ActionsEnvelope;\n}\n\n/** Zod validator paired with `payment_requirements.schema.json`. */\nexport const escrowPaymentRequirementsSchema = z\n .object({\n scheme: z.literal(\"escrow\"),\n network: evmNetworkSchema,\n asset: addressSchema,\n amount: decimalUintSchema,\n escrowAddress: addressSchema,\n recipientId: z.string().min(1),\n maxTimeoutSeconds: z.number().int().positive(),\n offer: offerRefSchema,\n tokenAuthStrategies: z\n .array(tokenAuthStrategySchema)\n .min(1)\n .refine((strategies) => new Set(strategies).size === strategies.length, {\n message: \"tokenAuthStrategies must not contain duplicates\",\n }),\n fulfillment: fulfillmentSchema.optional(),\n actions: actionsSchema,\n })\n .strict();\n\n/** Type-guard form. Returns the parsed value on success, throws on failure (with a `ZodError` carrying the field path). */\nexport function parseEscrowPaymentRequirements(value: unknown): EscrowPaymentRequirements {\n return escrowPaymentRequirementsSchema.parse(value);\n}\n","// `escrow` scheme PaymentPayload (client -> server, base64'd in `X-PAYMENT`).\n// Source of truth: docs/boson-impl-01-escrow-scheme.md §3.\n\nimport { z } from \"zod\";\n\nimport {\n TOKEN_AUTH_STRATEGIES,\n type Address,\n type BosonMetaTx,\n type BosonTokenAuth,\n type EvmNetwork,\n type FullOffer,\n type Hex,\n type TokenAuthStrategy,\n} from \"./types.js\";\nimport {\n addressSchema,\n decimalUintSchema,\n evmNetworkSchema,\n hex32Schema,\n hexBytesSchema,\n hexSchema,\n} from \"./validators.js\";\n\nconst sigSchema = z\n .object({\n v: z.number().int(),\n r: hex32Schema,\n s: hex32Schema,\n })\n .strict();\n\nconst metaTxSchema = z\n .object({\n from: addressSchema,\n nonce: decimalUintSchema,\n functionName: z.string().min(1),\n functionSignature: hexBytesSchema,\n sig: sigSchema,\n })\n .strict();\n\nconst erc3009DataSchema = z\n .object({\n from: addressSchema,\n to: addressSchema,\n value: decimalUintSchema,\n validAfter: z.number().int().nonnegative(),\n validBefore: z.number().int().nonnegative(),\n nonce: hex32Schema,\n v: z.number().int(),\n r: hex32Schema,\n s: hex32Schema,\n })\n .strict();\n\nconst permitDataSchema = z\n .object({\n owner: addressSchema,\n spender: addressSchema,\n value: decimalUintSchema,\n deadline: z.number().int().nonnegative(),\n nonce: decimalUintSchema,\n v: z.number().int(),\n r: hex32Schema,\n s: hex32Schema,\n })\n .strict();\n\nconst permit2DataSchema = z\n .object({\n permitted: z\n .object({\n token: addressSchema,\n amount: decimalUintSchema,\n })\n .strict(),\n spender: addressSchema,\n nonce: decimalUintSchema,\n deadline: z.number().int().nonnegative(),\n signature: hexSchema,\n })\n .strict();\n\nconst tokenAuthSchema = z.discriminatedUnion(\"kind\", [\n z.object({ kind: z.literal(\"erc3009\"), data: erc3009DataSchema }).strict(),\n z.object({ kind: z.literal(\"permit\"), data: permitDataSchema }).strict(),\n z.object({ kind: z.literal(\"permit2\"), data: permit2DataSchema }).strict(),\n]);\n\nconst tokenAuthStrategySchema = z.enum(\n TOKEN_AUTH_STRATEGIES as readonly [TokenAuthStrategy, ...TokenAuthStrategy[]],\n);\n\n/** Inner `payload` field of `EscrowPaymentPayload`. */\nexport interface EscrowPaymentPayloadInner {\n action: string;\n tokenAuthStrategy: TokenAuthStrategy;\n offerRef: { fullOffer: FullOffer; sellerSig: Hex };\n buyer: Address;\n metaTx: BosonMetaTx;\n /** Required iff `tokenAuthStrategy !== \"none\"`. */\n tokenAuth?: BosonTokenAuth;\n}\n\n/**\n * Wire-format type for the `escrow` PaymentPayload that a client base64's into\n * the `X-PAYMENT` header. See docs/boson-impl-01-escrow-scheme.md §3.\n *\n * `fulfillment.option` is always the buyer's pick from the server-advertised\n * option set (capability negotiation). `fulfillment.data` is action-conditional:\n *\n * - For atomic Flow B (`boson-createOfferCommitAndRedeem`), `data` MUST be\n * present (or `null` when the option's schema is `null`). Atomic Flow B\n * completes the redeem on-chain inside the commit transaction, so there's\n * no later round trip in which the buyer could hand the seller delivery\n * data — it must travel with `X-PAYMENT`.\n * - For two-step Flow A (`boson-createOfferAndCommit`), `data` MUST be\n * omitted. The buyer attaches it to the redeem-time POST body that\n * accompanies `boson-redeem`, after a successful commit. See\n * `docs/boson-impl-03-fulfillment-channels.md`.\n *\n * The Zod schema parses both shapes structurally; the action-conditional\n * presence/absence rule is enforced by the server-side validator (rule 13).\n */\nexport interface EscrowPaymentPayload {\n x402Version: number;\n scheme: \"escrow\";\n network: EvmNetwork;\n payload: EscrowPaymentPayloadInner;\n fulfillment?: { option: string; data?: Record<string, unknown> | null };\n}\n\n/**\n * Zod validator paired with `payment_payload.schema.json`. Note: this only\n * validates structural shape; cross-field rules (per docs/boson-impl-01 §5)\n * such as \"tokenAuth must be omitted iff tokenAuthStrategy === 'none'\" are\n * enforced server-side and are not part of this schema.\n */\nexport const escrowPaymentPayloadSchema = z\n .object({\n x402Version: z.number().int(),\n scheme: z.literal(\"escrow\"),\n network: evmNetworkSchema,\n payload: z\n .object({\n action: z.string().min(1),\n tokenAuthStrategy: tokenAuthStrategySchema,\n offerRef: z\n .object({\n fullOffer: z.record(z.unknown()),\n sellerSig: hexSchema,\n })\n .strict(),\n buyer: addressSchema,\n metaTx: metaTxSchema,\n tokenAuth: tokenAuthSchema.optional(),\n })\n .strict(),\n fulfillment: z\n .object({\n option: z.string().min(1),\n // `data` is action-conditional (Flow B only). The structural\n // schema accepts both shapes; the server validator enforces\n // presence vs absence based on `payload.action`.\n data: z.union([z.record(z.unknown()), z.null()]).optional(),\n })\n .strict()\n .optional(),\n })\n .strict();\n\nexport function parseEscrowPaymentPayload(value: unknown): EscrowPaymentPayload {\n return escrowPaymentPayloadSchema.parse(value);\n}\n","// Boson exchange + dispute states.\n//\n// The protocol uses two separate state machines: every exchange has an\n// `ExchangeState` (CANCELLED / COMMITTED / COMPLETED / DISPUTED / REDEEMED\n// / REVOKED), and a Dispute (created when the buyer calls `raiseDispute`)\n// has its own `DisputeState` (RESOLVING / RESOLVED / ESCALATED / RETRACTED\n// / DECIDED / REFUSED). Both enums are sourced verbatim from\n// `@bosonprotocol/core-sdk`'s subgraph schema so this package stays in\n// lock-step with the deployed protocol.\n//\n// Source of truth: docs/boson-impl-04-state-machine-and-next-actions.md.\n// The diagram in that doc conflates the two for buyer-UX simplicity; here\n// we keep them split to match the protocol.\n\nimport { subgraph } from \"@bosonprotocol/core-sdk\";\n\n/** Exchange-level state. Re-exported from `@bosonprotocol/core-sdk`. */\nexport const ExchangeState = subgraph.ExchangeState;\nexport type ExchangeState = subgraph.ExchangeState;\n\n/** Dispute-level state. Re-exported from `@bosonprotocol/core-sdk`. */\nexport const DisputeState = subgraph.DisputeState;\nexport type DisputeState = subgraph.DisputeState;\n\n/**\n * Synthetic state for the implicit pre-exchange phase — the initial 402\n * response, before any exchange has been committed. Not part of the\n * on-chain enum; just lets the transition table treat the 402 uniformly\n * with post-commit responses when deriving `nextActions`.\n */\nexport const PRE_COMMIT = \"PRE_COMMIT\" as const;\nexport type PreCommit = typeof PRE_COMMIT;\n\n/**\n * Composite state used to look up buyer-invokable actions. Modelled as a\n * true discriminated union so callers can't construct impossible states\n * (e.g. `exchange: DISPUTED` with no dispute, or `exchange: COMMITTED`\n * with a dispute attached).\n *\n * - `PRE_COMMIT` — no exchange yet (the initial 402).\n * - `{ exchange: DISPUTED, dispute }` — dispute is active; the\n * `dispute` sub-state determines which actions are available.\n * - `{ exchange }` for any non-DISPUTED exchange state — `dispute`\n * must not be present. Covers COMMITTED / REDEEMED / COMPLETED /\n * CANCELLED / REVOKED.\n */\nexport type ClientState =\n | PreCommit\n | { exchange: typeof ExchangeState.DISPUTED; dispute: DisputeState }\n | { exchange: Exclude<ExchangeState, typeof ExchangeState.DISPUTED>; dispute?: never };\n","// Post-commit `nextActions` envelope (top level of every response after\n// the initial 402). The pre-commit variant lives nested inside\n// `EscrowPaymentRequirements.actions` — see `payment-requirements.ts`.\n//\n// Source of truth: docs/boson-impl-04-state-machine-and-next-actions.md\n// §\"`nextActions` envelope\" and `schemas/next_actions.schema.json`.\n\nimport { z } from \"zod\";\n\nimport { DisputeState, ExchangeState } from \"../../state-machine/states.js\";\nimport { actionEntrySchema, actionsFallbackSchema } from \"./shared-schemas.js\";\nimport { type ActionsFallback, type NextAction } from \"./types.js\";\n\n/**\n * Wire-format type for the post-commit `nextActions` envelope.\n *\n * The `exchangeState === DISPUTED ↔ disputeState present` invariant is\n * encoded structurally: `exchangeState: DISPUTED` requires\n * `disputeState`, and any other `exchangeState` forbids it. The zod\n * validator below enforces the same invariant at runtime.\n *\n * The wire field is named `exchangeState` (not `state`) for symmetry\n * with `disputeState` and to remove ambiguity with the `state` field\n * the subgraph entity itself carries.\n */\nexport type EscrowNextActions = {\n exchangeId: string;\n next: NextAction[];\n fallback?: ActionsFallback;\n} & (\n | {\n exchangeState: Exclude<ExchangeState, typeof ExchangeState.DISPUTED>;\n disputeState?: never;\n }\n | { exchangeState: typeof ExchangeState.DISPUTED; disputeState: DisputeState }\n);\n\nconst exchangeStateSchema = z.nativeEnum(ExchangeState);\nconst disputeStateSchema = z.nativeEnum(DisputeState);\n\n/** Zod validator paired with `next_actions.schema.json`. */\nexport const escrowNextActionsSchema = z\n .object({\n exchangeId: z.string().min(1),\n exchangeState: exchangeStateSchema,\n disputeState: disputeStateSchema.optional(),\n next: z.array(actionEntrySchema),\n fallback: actionsFallbackSchema.optional(),\n })\n .strict()\n .refine(\n (envelope) =>\n envelope.exchangeState === ExchangeState.DISPUTED\n ? envelope.disputeState !== undefined\n : envelope.disputeState === undefined,\n {\n message: \"disputeState is required iff exchangeState === DISPUTED\",\n path: [\"disputeState\"],\n },\n );\n\n/** Type-guard form. Returns the parsed value on success, throws on failure. */\nexport function parseEscrowNextActions(value: unknown): EscrowNextActions {\n return escrowNextActionsSchema.parse(value) as EscrowNextActions;\n}\n","// Public surface for the `escrow` scheme.\n// See docs/boson-impl-01-escrow-scheme.md for the wire format.\n\nexport * from \"./types.js\";\nexport * from \"./payment-requirements.js\";\nexport * from \"./payment-payload.js\";\nexport * from \"./next-actions.js\";\nexport * from \"./validators.js\";\n\n/** Stable identifier for the scheme. Use this in place of the raw string `\"escrow\"` to avoid typos. */\nexport const ESCROW_SCHEME = \"escrow\" as const;\nexport type EscrowScheme = typeof ESCROW_SCHEME;\n"]}
1
+ {"version":3,"sources":["../../../../src/schemes/escrow/types.ts","../../../../src/schemes/escrow/validators.ts","../../../../src/schemes/escrow/shared-schemas.ts","../../../../src/schemes/escrow/payment-requirements.ts","../../../../src/schemes/escrow/payment-payload.ts","../../../../src/state-machine/states.ts","../../../../src/schemes/escrow/next-actions.ts","../../../../src/schemes/escrow/accepts.ts","../../../../src/schemes/escrow/index.ts"],"names":["z","tokenAuthStrategySchema","subgraph"],"mappings":";;;;;;AAcO,IAAM,qBAAA,GAAsD;AAAA,EACjE,MAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF;AAOO,IAAM,eAAA,GAA4C;AAAA,EACvD,QAAA;AAAA,EACA,aAAA;AAAA,EACA,SAAA;AAAA,EACA,KAAA;AAAA,EACA;AACF;ACxBO,IAAM,GAAA,GAAM;AAGZ,IAAM,SAAA,GAAY;AAGlB,IAAM,KAAA,GAAQ;AAGd,IAAM,OAAA,GAAU;AAGhB,IAAM,YAAA,GAAe;AAGrB,IAAM,WAAA,GAAc;AAEpB,IAAM,aAAA,GAAgBA,KAAA,CAAE,MAAA,EAAO,CAAE,MAAM,OAAO;AAC9C,IAAM,SAAA,GAAYA,KAAA,CAAE,MAAA,EAAO,CAAE,MAAM,GAAG;AACtC,IAAM,cAAA,GAAiBA,KAAA,CAAE,MAAA,EAAO,CAAE,MAAM,SAAS;AACjD,IAAM,WAAA,GAAcA,KAAA,CAAE,MAAA,EAAO,CAAE,MAAM,KAAK;AAC1C,IAAM,iBAAA,GAAoBA,KAAA,CAAE,MAAA,EAAO,CAAE,MAAM,YAAY;AACvD,IAAM,gBAAA,G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,MAAA,GAC1B,QAAA,CAAS,YAAA,KAAiB,MAAA;AAAA,EAChC;AAAA,IACE,OAAA,EAAS,yDAAA;AAAA,IACT,IAAA,EAAM,CAAC,cAAc;AAAA;AAEzB;AAGK,SAAS,uBAAuB,KAAA,EAAmC;AACxE,EAAA,OAAO,uBAAA,CAAwB,MAAM,KAAK,CAAA;AAC5C;;;AC/CO,SAAS,iBAAiB,IAAA,EAAoC;AACnE,EAAA,IAAI,OAAO,IAAA,KAAS,QAAA,IAAY,IAAA,KAAS,IAAA,EAAM;AAC7C,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,MAAM,UAAW,IAAA,CAA+B,OAAA;AAChD,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,EAAG;AAC3B,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,OAAO,OAAA,CAAQ,IAAA;AAAA,IACb,CAAC,UACC,OAAO,KAAA,KAAU,YACjB,KAAA,KAAU,IAAA,IACT,MAA+B,MAAA,KAAW;AAAA,GAC/C;AACF;;;ACpBO,IAAM,aAAA,GAAgB","file":"index.js","sourcesContent":["// Shared wire-format types for the `escrow` scheme.\n// Source of truth: docs/boson-impl-01-escrow-scheme.md.\n\n/**\n * CAIP-2 network identifier for an EVM chain. Constrained to `eip155:<chainId>`\n * shape at runtime by the JSON Schema and zod regex; aliased to `string` here\n * for the same reason as `Address` / `Hex` — the wire format is JSON, where\n * everything is a string, and template-literal types cause friction with\n * zod's regex-based validators.\n */\nexport type EvmNetwork = string;\n\n/** BPIP-12 token-authorization strategies. */\nexport type TokenAuthStrategy = \"none\" | \"erc3009\" | \"permit\" | \"permit2\";\nexport const TOKEN_AUTH_STRATEGIES: readonly TokenAuthStrategy[] = [\n \"none\",\n \"erc3009\",\n \"permit\",\n \"permit2\",\n] as const;\n\n/** Boson commit-time action ids advertised by the server. */\nexport type BosonCommitActionId = \"boson-createOfferAndCommit\" | \"boson-createOfferCommitAndRedeem\";\n\n/** Channels through which a `nextAction` can be performed. */\nexport type ActionChannel = \"server\" | \"facilitator\" | \"onchain\" | \"mcp\" | \"xmtp\";\nexport const ACTION_CHANNELS: readonly ActionChannel[] = [\n \"server\",\n \"facilitator\",\n \"onchain\",\n \"mcp\",\n \"xmtp\",\n] as const;\n\n/**\n * BPIP-10 FullOffer. Treated as opaque at this layer — the on-chain shape lives\n * in `@bosonprotocol/core-sdk`, and validation against the protocol struct is\n * the EIP-712 builder's job. Here it's just \"an object echoed verbatim\".\n */\nexport type FullOffer = Record<string, unknown>;\n\n/**\n * 0x-prefixed hex string. Aliased to `string` in the wire format so JSON\n * shapes are easy to construct; runtime validation is handled by the JSON\n * Schema and zod regex. The strongly-typed `\\`0x${string}\\`` form is reserved\n * for the EIP-712 builder layer where viem's brands matter.\n */\nexport type Hex = string;\n/** 0x-prefixed 40-char hex string. See `Hex` for typing rationale. */\nexport type Address = string;\n\n/** Off-chain offer reference signed by the seller. */\nexport interface BosonOfferRef {\n fullOffer: FullOffer;\n sellerSig: Hex;\n creator: Address;\n}\n\nexport interface FulfillmentOption {\n id: string;\n /** JSON-Schema-shaped `type: object` description of the data the buyer must supply, or `null` for schemaless channels. */\n schema: Record<string, unknown> | null;\n /** Channel-specific hints advertised to the client, such as endpoint URLs or public keys. */\n metadata?: unknown;\n}\n\nexport interface FulfillmentRequirements {\n required: boolean;\n options: FulfillmentOption[];\n}\n\nexport interface NextAction {\n id: string;\n channels: ActionChannel[];\n endpoints?: Record<string, string>;\n /**\n * ISO 8601 absolute timestamp by which the action must be invoked.\n * Relevant for dispute-window-bounded actions like\n * `boson-resolveDispute`, `boson-escalateDispute`,\n * `boson-retractDispute`, and (post-commit) `boson-completeExchange`.\n */\n deadline?: string;\n}\n\nexport interface OnchainHints {\n /** Address of the Boson escrow contract. */\n escrow: Address;\n metaTxFacet: string;\n /**\n * Per-`tokenAuthStrategy` meta-tx entry points on `metaTxFacet`. The\n * Boson Diamond exposes two functions on `MetaTransactionsHandlerFacet`:\n *\n * - `executeMetaTransaction` — legacy BPIP-9 entry point. Used when\n * the buyer's `tokenAuthStrategy` is `none` (the buyer has\n * pre-approved the Diamond, so no token-transfer authorization\n * queue is needed). Also the right entry point for any\n * post-commit action that doesn't move tokens (`redeem`,\n * `complete`, dispute transitions).\n * - `executeMetaTransactionWithTokenTransferAuthorization` — BPIP-12\n * entry point. Carries the buyer's signed `MetaTransaction` *and*\n * a queue of token-transfer authorizations. Used when\n * `tokenAuthStrategy` is `erc3009`, `permit`, or `permit2`.\n *\n * Clients select the entry point by their chosen strategy at\n * dispatch time.\n */\n metaTxEntrypoints: Record<TokenAuthStrategy, string>;\n actionFacets: Record<string, string>;\n}\n\nexport interface ActionsFallback {\n xmtp?: string;\n /**\n * Identifier within the Boson MCP server (e.g. the\n * `bosonprotocol/agentic-commerce` server) that the buyer's\n * MCP-aware agent dispatches against. The MCP *server* is escrow-\n * level (one BosonMCP serving every Boson seller); this value is the\n * URI/identifier the BosonMCP routes to the right exchange / seller.\n */\n mcp?: string;\n onchainHints?: OnchainHints;\n}\n\nexport interface ActionsEnvelope {\n next: NextAction[];\n fallback?: ActionsFallback;\n}\n\n/** Boson protocol meta-transaction envelope (signed by the buyer). */\nexport interface BosonMetaTx {\n from: Address;\n /** Decimal string. */\n nonce: string;\n functionName: string;\n /**\n * ABI-encoded function-call data as a `0x`-prefixed hex string. Named\n * `functionSignature` to match the on-chain `MetaTransactionsHandlerFacet`\n * struct field — the value is the encoded calldata, not just the function\n * selector.\n */\n functionSignature: Hex;\n sig: { v: number; r: Hex; s: Hex };\n}\n\nexport interface Erc3009AuthData {\n from: Address;\n to: Address;\n /** Atomic units, decimal string. */\n value: string;\n validAfter: number;\n validBefore: number;\n /** 32-byte hex string. */\n nonce: Hex;\n v: number;\n r: Hex;\n s: Hex;\n}\n\nexport interface PermitAuthData {\n owner: Address;\n spender: Address;\n /** Atomic units, decimal string. */\n value: string;\n deadline: number;\n /** Token-internal sequential nonce, decimal string. */\n nonce: string;\n v: number;\n r: Hex;\n s: Hex;\n}\n\nexport interface Permit2AuthData {\n permitted: { token: Address; amount: string };\n spender: Address;\n /** Permit2 word-bitmap nonce, decimal string. */\n nonce: string;\n deadline: number;\n /** Concatenated 65-byte ECDSA signature. */\n signature: Hex;\n}\n\n/** Discriminated union of all token-authorization payloads. `none` is encoded by the absence of this field on the payload. */\nexport type BosonTokenAuth =\n | { kind: \"erc3009\"; data: Erc3009AuthData }\n | { kind: \"permit\"; data: PermitAuthData }\n | { kind: \"permit2\"; data: Permit2AuthData };\n","// Shared regex patterns + scalar zod schemas used across the `escrow`\n// scheme's payment-requirements and payment-payload validators. Keeping\n// them in one place ensures the JSON Schema's patterns and the zod regexes\n// stay in sync (see `schemas/*.json` for the JSON Schema source of truth).\n\nimport { z } from \"zod\";\n\n/** 0x-prefixed hex string, at least one nibble. */\nexport const HEX = /^0x[a-fA-F0-9]+$/;\n\n/** 0x-prefixed hex string, allowing the empty `0x` form for empty bytes. */\nexport const HEX_BYTES = /^0x[a-fA-F0-9]*$/;\n\n/** 0x-prefixed 32-byte (64-nibble) hex string. */\nexport const HEX32 = /^0x[a-fA-F0-9]{64}$/;\n\n/** 0x-prefixed 20-byte (40-nibble) hex address. */\nexport const ADDRESS = /^0x[a-fA-F0-9]{40}$/;\n\n/** Decimal unsigned integer string, no leading zeros (except \"0\" itself). */\nexport const DECIMAL_UINT = /^(0|[1-9][0-9]*)$/;\n\n/** CAIP-2 EVM network identifier: `eip155:<chainId>`. */\nexport const EVM_NETWORK = /^eip155:[1-9][0-9]*$/;\n\nexport const addressSchema = z.string().regex(ADDRESS);\nexport const hexSchema = z.string().regex(HEX);\nexport const hexBytesSchema = z.string().regex(HEX_BYTES);\nexport const hex32Schema = z.string().regex(HEX32);\nexport const decimalUintSchema = z.string().regex(DECIMAL_UINT);\nexport const evmNetworkSchema = z.string().regex(EVM_NETWORK);\n","// Shared zod fragments used by both `payment-requirements.ts` (the\n// pre-commit / 402 envelope) and `next-actions.ts` (the post-commit\n// envelope). Centralised here so the two wire-format validators can't\n// drift on shared sub-shapes like an action entry, the `fallback` block,\n// or the `onchainHints` block.\n\nimport { z } from \"zod\";\n\nimport { ACTION_CHANNELS, type ActionChannel } from \"./types.js\";\nimport { addressSchema } from \"./validators.js\";\n\n/** ISO 8601 absolute timestamp with timezone offset. */\nexport const actionDeadlineSchema = z.string().datetime({ offset: true });\n\n/** Non-empty unique `ActionChannel[]` for `next[i].channels`. */\nexport const actionChannelsSchema = z\n .array(z.enum(ACTION_CHANNELS as readonly [ActionChannel, ...ActionChannel[]]))\n .min(1)\n .refine((channels) => new Set(channels).size === channels.length, {\n message: \"channels must contain unique items\",\n });\n\n/** Single entry in the `next[]` array of any `nextActions` envelope. */\nexport const actionEntrySchema = z\n .object({\n id: z.string().min(1),\n channels: actionChannelsSchema,\n endpoints: z.record(z.string()).optional(),\n deadline: actionDeadlineSchema.optional(),\n })\n .strict();\n\n/**\n * Per-`tokenAuthStrategy` meta-tx entry points on\n * `onchainHints.metaTxFacet`. All four strategies are required so\n * clients can resolve any strategy they happen to advertise.\n */\nexport const metaTxEntrypointsSchema = z\n .object({\n none: z.string().min(1),\n erc3009: z.string().min(1),\n permit: z.string().min(1),\n permit2: z.string().min(1),\n })\n .strict();\n\n/** `fallback.onchainHints` block. */\nexport const onchainHintsSchema = z\n .object({\n escrow: addressSchema,\n metaTxFacet: z.string().min(1),\n metaTxEntrypoints: metaTxEntrypointsSchema,\n actionFacets: z.record(z.string()),\n })\n .strict();\n\n/** `fallback` block embedded in any `nextActions` envelope. */\nexport const actionsFallbackSchema = z\n .object({\n xmtp: z.string().optional(),\n mcp: z.string().optional(),\n onchainHints: onchainHintsSchema.optional(),\n })\n .strict();\n","// `escrow` scheme PaymentRequirements (server -> client, in 402 body).\n// Source of truth: docs/boson-impl-01-escrow-scheme.md §2.\n\nimport { z } from \"zod\";\n\nimport { actionEntrySchema, actionsFallbackSchema } from \"./shared-schemas.js\";\nimport {\n TOKEN_AUTH_STRATEGIES,\n type ActionsEnvelope,\n type Address,\n type BosonOfferRef,\n type EvmNetwork,\n type FulfillmentRequirements,\n type TokenAuthStrategy,\n} from \"./types.js\";\nimport { addressSchema, decimalUintSchema, evmNetworkSchema, hexSchema } from \"./validators.js\";\n\nconst offerRefSchema = z\n .object({\n fullOffer: z.record(z.unknown()),\n sellerSig: hexSchema,\n creator: addressSchema,\n })\n .strict();\n\nconst tokenAuthStrategySchema = z.enum(\n TOKEN_AUTH_STRATEGIES as readonly [TokenAuthStrategy, ...TokenAuthStrategy[]],\n);\n\nconst fulfillmentSchema = z\n .object({\n required: z.boolean(),\n options: z.array(\n z\n .object({\n id: z.string().min(1),\n schema: z.union([z.record(z.unknown()), z.null()]),\n metadata: z.unknown().optional(),\n })\n .strict(),\n ),\n })\n .strict();\n\n// Pre-commit (initial 402) `actions` envelope: `next[]` must be\n// non-empty (the buyer needs at least one path to commit) and the\n// `fallback` block is optional.\nconst actionsSchema = z\n .object({\n next: z.array(actionEntrySchema).min(1),\n fallback: actionsFallbackSchema.optional(),\n })\n .strict();\n\n/**\n * Wire-format type for the `escrow` PaymentRequirements that a server emits\n * inside a 402 `accepts[]` entry. See docs/boson-impl-01-escrow-scheme.md §2\n * for field semantics.\n */\nexport interface EscrowPaymentRequirements {\n scheme: \"escrow\";\n network: EvmNetwork;\n asset: Address;\n /** Atomic units, decimal string. */\n amount: string;\n /** Address of the Boson escrow contract — the custodian. */\n escrowAddress: Address;\n /** Routing-only seller identifier. May be a numeric `sellerId`, a `did:boson:seller:N`, or a wallet address. */\n recipientId: string;\n maxTimeoutSeconds: number;\n offer: BosonOfferRef;\n tokenAuthStrategies: TokenAuthStrategy[];\n fulfillment?: FulfillmentRequirements;\n actions: ActionsEnvelope;\n}\n\n/** Zod validator paired with `payment_requirements.schema.json`. */\nexport const escrowPaymentRequirementsSchema = z\n .object({\n scheme: z.literal(\"escrow\"),\n network: evmNetworkSchema,\n asset: addressSchema,\n amount: decimalUintSchema,\n escrowAddress: addressSchema,\n recipientId: z.string().min(1),\n maxTimeoutSeconds: z.number().int().positive(),\n offer: offerRefSchema,\n tokenAuthStrategies: z\n .array(tokenAuthStrategySchema)\n .min(1)\n .refine((strategies) => new Set(strategies).size === strategies.length, {\n message: \"tokenAuthStrategies must not contain duplicates\",\n }),\n fulfillment: fulfillmentSchema.optional(),\n actions: actionsSchema,\n })\n .strict();\n\n/** Type-guard form. Returns the parsed value on success, throws on failure (with a `ZodError` carrying the field path). */\nexport function parseEscrowPaymentRequirements(value: unknown): EscrowPaymentRequirements {\n return escrowPaymentRequirementsSchema.parse(value);\n}\n","// `escrow` scheme PaymentPayload (client -> server, base64'd in `X-PAYMENT`).\n// Source of truth: docs/boson-impl-01-escrow-scheme.md §3.\n\nimport { z } from \"zod\";\n\nimport {\n TOKEN_AUTH_STRATEGIES,\n type Address,\n type BosonMetaTx,\n type BosonTokenAuth,\n type EvmNetwork,\n type FullOffer,\n type Hex,\n type TokenAuthStrategy,\n} from \"./types.js\";\nimport {\n addressSchema,\n decimalUintSchema,\n evmNetworkSchema,\n hex32Schema,\n hexBytesSchema,\n hexSchema,\n} from \"./validators.js\";\n\nconst sigSchema = z\n .object({\n v: z.number().int(),\n r: hex32Schema,\n s: hex32Schema,\n })\n .strict();\n\nconst metaTxSchema = z\n .object({\n from: addressSchema,\n nonce: decimalUintSchema,\n functionName: z.string().min(1),\n functionSignature: hexBytesSchema,\n sig: sigSchema,\n })\n .strict();\n\nconst erc3009DataSchema = z\n .object({\n from: addressSchema,\n to: addressSchema,\n value: decimalUintSchema,\n validAfter: z.number().int().nonnegative(),\n validBefore: z.number().int().nonnegative(),\n nonce: hex32Schema,\n v: z.number().int(),\n r: hex32Schema,\n s: hex32Schema,\n })\n .strict();\n\nconst permitDataSchema = z\n .object({\n owner: addressSchema,\n spender: addressSchema,\n value: decimalUintSchema,\n deadline: z.number().int().nonnegative(),\n nonce: decimalUintSchema,\n v: z.number().int(),\n r: hex32Schema,\n s: hex32Schema,\n })\n .strict();\n\nconst permit2DataSchema = z\n .object({\n permitted: z\n .object({\n token: addressSchema,\n amount: decimalUintSchema,\n })\n .strict(),\n spender: addressSchema,\n nonce: decimalUintSchema,\n deadline: z.number().int().nonnegative(),\n signature: hexSchema,\n })\n .strict();\n\nconst tokenAuthSchema = z.discriminatedUnion(\"kind\", [\n z.object({ kind: z.literal(\"erc3009\"), data: erc3009DataSchema }).strict(),\n z.object({ kind: z.literal(\"permit\"), data: permitDataSchema }).strict(),\n z.object({ kind: z.literal(\"permit2\"), data: permit2DataSchema }).strict(),\n]);\n\nconst tokenAuthStrategySchema = z.enum(\n TOKEN_AUTH_STRATEGIES as readonly [TokenAuthStrategy, ...TokenAuthStrategy[]],\n);\n\n/** Inner `payload` field of `EscrowPaymentPayload`. */\nexport interface EscrowPaymentPayloadInner {\n action: string;\n tokenAuthStrategy: TokenAuthStrategy;\n offerRef: { fullOffer: FullOffer; sellerSig: Hex };\n buyer: Address;\n metaTx: BosonMetaTx;\n /** Required iff `tokenAuthStrategy !== \"none\"`. */\n tokenAuth?: BosonTokenAuth;\n}\n\n/**\n * Wire-format type for the `escrow` PaymentPayload that a client base64's into\n * the `X-PAYMENT` header. See docs/boson-impl-01-escrow-scheme.md §3.\n *\n * `fulfillment.option` is always the buyer's pick from the server-advertised\n * option set (capability negotiation). `fulfillment.data` is action-conditional:\n *\n * - For atomic Flow B (`boson-createOfferCommitAndRedeem`), `data` MUST be\n * present (or `null` when the option's schema is `null`). Atomic Flow B\n * completes the redeem on-chain inside the commit transaction, so there's\n * no later round trip in which the buyer could hand the seller delivery\n * data — it must travel with `X-PAYMENT`.\n * - For two-step Flow A (`boson-createOfferAndCommit`), `data` MUST be\n * omitted. The buyer attaches it to the redeem-time POST body that\n * accompanies `boson-redeem`, after a successful commit. See\n * `docs/boson-impl-03-fulfillment-channels.md`.\n *\n * The Zod schema parses both shapes structurally; the action-conditional\n * presence/absence rule is enforced by the server-side validator (rule 13).\n */\nexport interface EscrowPaymentPayload {\n x402Version: number;\n scheme: \"escrow\";\n network: EvmNetwork;\n payload: EscrowPaymentPayloadInner;\n fulfillment?: { option: string; data?: Record<string, unknown> | null };\n}\n\n/**\n * Zod validator paired with `payment_payload.schema.json`. Note: this only\n * validates structural shape; cross-field rules (per docs/boson-impl-01 §5)\n * such as \"tokenAuth must be omitted iff tokenAuthStrategy === 'none'\" are\n * enforced server-side and are not part of this schema.\n */\nexport const escrowPaymentPayloadSchema = z\n .object({\n x402Version: z.number().int(),\n scheme: z.literal(\"escrow\"),\n network: evmNetworkSchema,\n payload: z\n .object({\n action: z.string().min(1),\n tokenAuthStrategy: tokenAuthStrategySchema,\n offerRef: z\n .object({\n fullOffer: z.record(z.unknown()),\n sellerSig: hexSchema,\n })\n .strict(),\n buyer: addressSchema,\n metaTx: metaTxSchema,\n tokenAuth: tokenAuthSchema.optional(),\n })\n .strict(),\n fulfillment: z\n .object({\n option: z.string().min(1),\n // `data` is action-conditional (Flow B only). The structural\n // schema accepts both shapes; the server validator enforces\n // presence vs absence based on `payload.action`.\n data: z.union([z.record(z.unknown()), z.null()]).optional(),\n })\n .strict()\n .optional(),\n })\n .strict();\n\nexport function parseEscrowPaymentPayload(value: unknown): EscrowPaymentPayload {\n return escrowPaymentPayloadSchema.parse(value);\n}\n","// Boson exchange + dispute states.\n//\n// The protocol uses two separate state machines: every exchange has an\n// `ExchangeState` (CANCELLED / COMMITTED / COMPLETED / DISPUTED / REDEEMED\n// / REVOKED), and a Dispute (created when the buyer calls `raiseDispute`)\n// has its own `DisputeState` (RESOLVING / RESOLVED / ESCALATED / RETRACTED\n// / DECIDED / REFUSED). Both enums are sourced verbatim from\n// `@bosonprotocol/core-sdk`'s subgraph schema so this package stays in\n// lock-step with the deployed protocol.\n//\n// Source of truth: docs/boson-impl-04-state-machine-and-next-actions.md.\n// The diagram in that doc conflates the two for buyer-UX simplicity; here\n// we keep them split to match the protocol.\n\nimport { subgraph } from \"@bosonprotocol/core-sdk\";\n\n/** Exchange-level state. Re-exported from `@bosonprotocol/core-sdk`. */\nexport const ExchangeState = subgraph.ExchangeState;\nexport type ExchangeState = subgraph.ExchangeState;\n\n/** Dispute-level state. Re-exported from `@bosonprotocol/core-sdk`. */\nexport const DisputeState = subgraph.DisputeState;\nexport type DisputeState = subgraph.DisputeState;\n\n/**\n * Synthetic state for the implicit pre-exchange phase — the initial 402\n * response, before any exchange has been committed. Not part of the\n * on-chain enum; just lets the transition table treat the 402 uniformly\n * with post-commit responses when deriving `nextActions`.\n */\nexport const PRE_COMMIT = \"PRE_COMMIT\" as const;\nexport type PreCommit = typeof PRE_COMMIT;\n\n/**\n * Composite state used to look up buyer-invokable actions. Modelled as a\n * true discriminated union so callers can't construct impossible states\n * (e.g. `exchange: DISPUTED` with no dispute, or `exchange: COMMITTED`\n * with a dispute attached).\n *\n * - `PRE_COMMIT` — no exchange yet (the initial 402).\n * - `{ exchange: DISPUTED, dispute }` — dispute is active; the\n * `dispute` sub-state determines which actions are available.\n * - `{ exchange }` for any non-DISPUTED exchange state — `dispute`\n * must not be present. Covers COMMITTED / REDEEMED / COMPLETED /\n * CANCELLED / REVOKED.\n */\nexport type ClientState =\n | PreCommit\n | { exchange: typeof ExchangeState.DISPUTED; dispute: DisputeState }\n | { exchange: Exclude<ExchangeState, typeof ExchangeState.DISPUTED>; dispute?: never };\n","// Post-commit `nextActions` envelope (top level of every response after\n// the initial 402). The pre-commit variant lives nested inside\n// `EscrowPaymentRequirements.actions` — see `payment-requirements.ts`.\n//\n// Source of truth: docs/boson-impl-04-state-machine-and-next-actions.md\n// §\"`nextActions` envelope\" and `schemas/next_actions.schema.json`.\n\nimport { z } from \"zod\";\n\nimport { DisputeState, ExchangeState } from \"../../state-machine/states.js\";\nimport { actionEntrySchema, actionsFallbackSchema } from \"./shared-schemas.js\";\nimport { type ActionsFallback, type NextAction } from \"./types.js\";\n\n/**\n * Wire-format type for the post-commit `nextActions` envelope.\n *\n * The `exchangeState === DISPUTED ↔ disputeState present` invariant is\n * encoded structurally: `exchangeState: DISPUTED` requires\n * `disputeState`, and any other `exchangeState` forbids it. The zod\n * validator below enforces the same invariant at runtime.\n *\n * The wire field is named `exchangeState` (not `state`) for symmetry\n * with `disputeState` and to remove ambiguity with the `state` field\n * the subgraph entity itself carries.\n */\nexport type EscrowNextActions = {\n exchangeId: string;\n next: NextAction[];\n fallback?: ActionsFallback;\n} & (\n | {\n exchangeState: Exclude<ExchangeState, typeof ExchangeState.DISPUTED>;\n disputeState?: never;\n }\n | { exchangeState: typeof ExchangeState.DISPUTED; disputeState: DisputeState }\n);\n\nconst exchangeStateSchema = z.nativeEnum(ExchangeState);\nconst disputeStateSchema = z.nativeEnum(DisputeState);\n\n/** Zod validator paired with `next_actions.schema.json`. */\nexport const escrowNextActionsSchema = z\n .object({\n exchangeId: z.string().min(1),\n exchangeState: exchangeStateSchema,\n disputeState: disputeStateSchema.optional(),\n next: z.array(actionEntrySchema),\n fallback: actionsFallbackSchema.optional(),\n })\n .strict()\n .refine(\n (envelope) =>\n envelope.exchangeState === ExchangeState.DISPUTED\n ? envelope.disputeState !== undefined\n : envelope.disputeState === undefined,\n {\n message: \"disputeState is required iff exchangeState === DISPUTED\",\n path: [\"disputeState\"],\n },\n );\n\n/** Type-guard form. Returns the parsed value on success, throws on failure. */\nexport function parseEscrowNextActions(value: unknown): EscrowNextActions {\n return escrowNextActionsSchema.parse(value) as EscrowNextActions;\n}\n","// Locate the `escrow` entry inside a parsed x402 402 challenge body.\n//\n// The 402 JSON envelope is `{ x402Version, accepts: [requirements...] }`\n// (see `respondWithChallenge` in `@bosonprotocol/x402-server-express`). A\n// server may advertise several schemes in `accepts[]`; this returns the\n// first entry whose `scheme === \"escrow\"`, or `undefined` when the body\n// isn't an object, has no `accepts[]` array, or carries only other\n// schemes.\n//\n// Single-sourced here so the buyer-side fetch wrapper\n// (`@bosonprotocol/x402-client-fetch`) and the browser paywall\n// (`@bosonprotocol/x402-paywall`) pick the entry identically. The input\n// is the already-parsed JSON body rather than a `Response` so the helper\n// stays environment-agnostic — each caller owns how it decodes the\n// response (clone-then-`json()` for the wrapper, plain `json()` for the\n// paywall).\n\nexport function findEscrowAccept(body: unknown): unknown | undefined {\n if (typeof body !== \"object\" || body === null) {\n return undefined;\n }\n const accepts = (body as { accepts?: unknown }).accepts;\n if (!Array.isArray(accepts)) {\n return undefined;\n }\n return accepts.find(\n (entry) =>\n typeof entry === \"object\" &&\n entry !== null &&\n (entry as { scheme?: unknown }).scheme === \"escrow\",\n );\n}\n","// Public surface for the `escrow` scheme.\n// See docs/boson-impl-01-escrow-scheme.md for the wire format.\n\nexport * from \"./types.js\";\nexport * from \"./payment-requirements.js\";\nexport * from \"./payment-payload.js\";\nexport * from \"./next-actions.js\";\nexport * from \"./validators.js\";\nexport * from \"./accepts.js\";\n\n/** Stable identifier for the scheme. Use this in place of the raw string `\"escrow\"` to avoid typos. */\nexport const ESCROW_SCHEME = \"escrow\" as const;\nexport type EscrowScheme = typeof ESCROW_SCHEME;\n"]}
@@ -194,9 +194,23 @@ function parseEscrowNextActions(value) {
194
194
  return escrowNextActionsSchema.parse(value);
195
195
  }
196
196
 
197
+ // src/schemes/escrow/accepts.ts
198
+ function findEscrowAccept(body) {
199
+ if (typeof body !== "object" || body === null) {
200
+ return void 0;
201
+ }
202
+ const accepts = body.accepts;
203
+ if (!Array.isArray(accepts)) {
204
+ return void 0;
205
+ }
206
+ return accepts.find(
207
+ (entry) => typeof entry === "object" && entry !== null && entry.scheme === "escrow"
208
+ );
209
+ }
210
+
197
211
  // src/schemes/escrow/index.ts
198
212
  var ESCROW_SCHEME = "escrow";
199
213
 
200
- export { ACTION_CHANNELS, ADDRESS, DECIMAL_UINT, ESCROW_SCHEME, EVM_NETWORK, HEX, HEX32, HEX_BYTES, TOKEN_AUTH_STRATEGIES, addressSchema, decimalUintSchema, escrowNextActionsSchema, escrowPaymentPayloadSchema, escrowPaymentRequirementsSchema, evmNetworkSchema, hex32Schema, hexBytesSchema, hexSchema, parseEscrowNextActions, parseEscrowPaymentPayload, parseEscrowPaymentRequirements };
214
+ export { ACTION_CHANNELS, ADDRESS, DECIMAL_UINT, ESCROW_SCHEME, EVM_NETWORK, HEX, HEX32, HEX_BYTES, TOKEN_AUTH_STRATEGIES, addressSchema, decimalUintSchema, escrowNextActionsSchema, escrowPaymentPayloadSchema, escrowPaymentRequirementsSchema, evmNetworkSchema, findEscrowAccept, hex32Schema, hexBytesSchema, hexSchema, parseEscrowNextActions, parseEscrowPaymentPayload, parseEscrowPaymentRequirements };
201
215
  //# sourceMappingURL=index.js.map
202
216
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/schemes/escrow/types.ts","../../../../src/schemes/escrow/validators.ts","../../../../src/schemes/escrow/shared-schemas.ts","../../../../src/schemes/escrow/payment-requirements.ts","../../../../src/schemes/escrow/payment-payload.ts","../../../../src/schemes/escrow/next-actions.ts","../../../../src/schemes/escrow/index.ts"],"names":["z","tokenAuthStrategySchema"],"mappings":";;;;AAcO,IAAM,qBAAA,GAAsD;AAAA,EACjE,MAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF;AAOO,IAAM,eAAA,GAA4C;AAAA,EACvD,QAAA;AAAA,EACA,aAAA;AAAA,EACA,SAAA;AAAA,EACA,KAAA;AAAA,EACA;AACF;ACxBO,IAAM,GAAA,GAAM;AAGZ,IAAM,SAAA,GAAY;AAGlB,IAAM,KAAA,GAAQ;AAGd,IAAM,OAAA,GAAU;AAGhB,IAAM,YAAA,GAAe;AAGrB,IAAM,WAAA,GAAc;AAEpB,IAAM,aAAA,GAAgB,CAAA,CAAE,MAAA,EAAO,CAAE,MAAM,OAAO;AAC9C,IAAM,SAAA,GAAY,CAAA,CAAE,MAAA,EAAO,CAAE,MAAM,GAAG;AACtC,IAAM,cAAA,GAAiB,CAAA,CAAE,MAAA,EAAO,CAAE,MAAM,SAAS;AACjD,IAAM,WAAA,GAAc,CAAA,CAAE,MAAA,EAAO,CAAE,MAAM,KAAK;AAC1C,IAAM,iBAAA,G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A,CAAS,YAAA,KAAiB,MAAA;AAAA,EAChC;AAAA,IACE,OAAA,EAAS,yDAAA;AAAA,IACT,IAAA,EAAM,CAAC,cAAc;AAAA;AAEzB;AAGK,SAAS,uBAAuB,KAAA,EAAmC;AACxE,EAAA,OAAO,uBAAA,CAAwB,MAAM,KAAK,CAAA;AAC5C;;;ACtDO,IAAM,aAAA,GAAgB","file":"index.js","sourcesContent":["// Shared wire-format types for the `escrow` scheme.\n// Source of truth: docs/boson-impl-01-escrow-scheme.md.\n\n/**\n * CAIP-2 network identifier for an EVM chain. Constrained to `eip155:<chainId>`\n * shape at runtime by the JSON Schema and zod regex; aliased to `string` here\n * for the same reason as `Address` / `Hex` — the wire format is JSON, where\n * everything is a string, and template-literal types cause friction with\n * zod's regex-based validators.\n */\nexport type EvmNetwork = string;\n\n/** BPIP-12 token-authorization strategies. */\nexport type TokenAuthStrategy = \"none\" | \"erc3009\" | \"permit\" | \"permit2\";\nexport const TOKEN_AUTH_STRATEGIES: readonly TokenAuthStrategy[] = [\n \"none\",\n \"erc3009\",\n \"permit\",\n \"permit2\",\n] as const;\n\n/** Boson commit-time action ids advertised by the server. */\nexport type BosonCommitActionId = \"boson-createOfferAndCommit\" | \"boson-createOfferCommitAndRedeem\";\n\n/** Channels through which a `nextAction` can be performed. */\nexport type ActionChannel = \"server\" | \"facilitator\" | \"onchain\" | \"mcp\" | \"xmtp\";\nexport const ACTION_CHANNELS: readonly ActionChannel[] = [\n \"server\",\n \"facilitator\",\n \"onchain\",\n \"mcp\",\n \"xmtp\",\n] as const;\n\n/**\n * BPIP-10 FullOffer. Treated as opaque at this layer — the on-chain shape lives\n * in `@bosonprotocol/core-sdk`, and validation against the protocol struct is\n * the EIP-712 builder's job. Here it's just \"an object echoed verbatim\".\n */\nexport type FullOffer = Record<string, unknown>;\n\n/**\n * 0x-prefixed hex string. Aliased to `string` in the wire format so JSON\n * shapes are easy to construct; runtime validation is handled by the JSON\n * Schema and zod regex. The strongly-typed `\\`0x${string}\\`` form is reserved\n * for the EIP-712 builder layer where viem's brands matter.\n */\nexport type Hex = string;\n/** 0x-prefixed 40-char hex string. See `Hex` for typing rationale. */\nexport type Address = string;\n\n/** Off-chain offer reference signed by the seller. */\nexport interface BosonOfferRef {\n fullOffer: FullOffer;\n sellerSig: Hex;\n creator: Address;\n}\n\nexport interface FulfillmentOption {\n id: string;\n /** JSON-Schema-shaped `type: object` description of the data the buyer must supply, or `null` for schemaless channels. */\n schema: Record<string, unknown> | null;\n /** Channel-specific hints advertised to the client, such as endpoint URLs or public keys. */\n metadata?: unknown;\n}\n\nexport interface FulfillmentRequirements {\n required: boolean;\n options: FulfillmentOption[];\n}\n\nexport interface NextAction {\n id: string;\n channels: ActionChannel[];\n endpoints?: Record<string, string>;\n /**\n * ISO 8601 absolute timestamp by which the action must be invoked.\n * Relevant for dispute-window-bounded actions like\n * `boson-resolveDispute`, `boson-escalateDispute`,\n * `boson-retractDispute`, and (post-commit) `boson-completeExchange`.\n */\n deadline?: string;\n}\n\nexport interface OnchainHints {\n /** Address of the Boson escrow contract. */\n escrow: Address;\n metaTxFacet: string;\n /**\n * Per-`tokenAuthStrategy` meta-tx entry points on `metaTxFacet`. The\n * Boson Diamond exposes two functions on `MetaTransactionsHandlerFacet`:\n *\n * - `executeMetaTransaction` — legacy BPIP-9 entry point. Used when\n * the buyer's `tokenAuthStrategy` is `none` (the buyer has\n * pre-approved the Diamond, so no token-transfer authorization\n * queue is needed). Also the right entry point for any\n * post-commit action that doesn't move tokens (`redeem`,\n * `complete`, dispute transitions).\n * - `executeMetaTransactionWithTokenTransferAuthorization` — BPIP-12\n * entry point. Carries the buyer's signed `MetaTransaction` *and*\n * a queue of token-transfer authorizations. Used when\n * `tokenAuthStrategy` is `erc3009`, `permit`, or `permit2`.\n *\n * Clients select the entry point by their chosen strategy at\n * dispatch time.\n */\n metaTxEntrypoints: Record<TokenAuthStrategy, string>;\n actionFacets: Record<string, string>;\n}\n\nexport interface ActionsFallback {\n xmtp?: string;\n /**\n * Identifier within the Boson MCP server (e.g. the\n * `bosonprotocol/agentic-commerce` server) that the buyer's\n * MCP-aware agent dispatches against. The MCP *server* is escrow-\n * level (one BosonMCP serving every Boson seller); this value is the\n * URI/identifier the BosonMCP routes to the right exchange / seller.\n */\n mcp?: string;\n onchainHints?: OnchainHints;\n}\n\nexport interface ActionsEnvelope {\n next: NextAction[];\n fallback?: ActionsFallback;\n}\n\n/** Boson protocol meta-transaction envelope (signed by the buyer). */\nexport interface BosonMetaTx {\n from: Address;\n /** Decimal string. */\n nonce: string;\n functionName: string;\n /**\n * ABI-encoded function-call data as a `0x`-prefixed hex string. Named\n * `functionSignature` to match the on-chain `MetaTransactionsHandlerFacet`\n * struct field — the value is the encoded calldata, not just the function\n * selector.\n */\n functionSignature: Hex;\n sig: { v: number; r: Hex; s: Hex };\n}\n\nexport interface Erc3009AuthData {\n from: Address;\n to: Address;\n /** Atomic units, decimal string. */\n value: string;\n validAfter: number;\n validBefore: number;\n /** 32-byte hex string. */\n nonce: Hex;\n v: number;\n r: Hex;\n s: Hex;\n}\n\nexport interface PermitAuthData {\n owner: Address;\n spender: Address;\n /** Atomic units, decimal string. */\n value: string;\n deadline: number;\n /** Token-internal sequential nonce, decimal string. */\n nonce: string;\n v: number;\n r: Hex;\n s: Hex;\n}\n\nexport interface Permit2AuthData {\n permitted: { token: Address; amount: string };\n spender: Address;\n /** Permit2 word-bitmap nonce, decimal string. */\n nonce: string;\n deadline: number;\n /** Concatenated 65-byte ECDSA signature. */\n signature: Hex;\n}\n\n/** Discriminated union of all token-authorization payloads. `none` is encoded by the absence of this field on the payload. */\nexport type BosonTokenAuth =\n | { kind: \"erc3009\"; data: Erc3009AuthData }\n | { kind: \"permit\"; data: PermitAuthData }\n | { kind: \"permit2\"; data: Permit2AuthData };\n","// Shared regex patterns + scalar zod schemas used across the `escrow`\n// scheme's payment-requirements and payment-payload validators. Keeping\n// them in one place ensures the JSON Schema's patterns and the zod regexes\n// stay in sync (see `schemas/*.json` for the JSON Schema source of truth).\n\nimport { z } from \"zod\";\n\n/** 0x-prefixed hex string, at least one nibble. */\nexport const HEX = /^0x[a-fA-F0-9]+$/;\n\n/** 0x-prefixed hex string, allowing the empty `0x` form for empty bytes. */\nexport const HEX_BYTES = /^0x[a-fA-F0-9]*$/;\n\n/** 0x-prefixed 32-byte (64-nibble) hex string. */\nexport const HEX32 = /^0x[a-fA-F0-9]{64}$/;\n\n/** 0x-prefixed 20-byte (40-nibble) hex address. */\nexport const ADDRESS = /^0x[a-fA-F0-9]{40}$/;\n\n/** Decimal unsigned integer string, no leading zeros (except \"0\" itself). */\nexport const DECIMAL_UINT = /^(0|[1-9][0-9]*)$/;\n\n/** CAIP-2 EVM network identifier: `eip155:<chainId>`. */\nexport const EVM_NETWORK = /^eip155:[1-9][0-9]*$/;\n\nexport const addressSchema = z.string().regex(ADDRESS);\nexport const hexSchema = z.string().regex(HEX);\nexport const hexBytesSchema = z.string().regex(HEX_BYTES);\nexport const hex32Schema = z.string().regex(HEX32);\nexport const decimalUintSchema = z.string().regex(DECIMAL_UINT);\nexport const evmNetworkSchema = z.string().regex(EVM_NETWORK);\n","// Shared zod fragments used by both `payment-requirements.ts` (the\n// pre-commit / 402 envelope) and `next-actions.ts` (the post-commit\n// envelope). Centralised here so the two wire-format validators can't\n// drift on shared sub-shapes like an action entry, the `fallback` block,\n// or the `onchainHints` block.\n\nimport { z } from \"zod\";\n\nimport { ACTION_CHANNELS, type ActionChannel } from \"./types.js\";\nimport { addressSchema } from \"./validators.js\";\n\n/** ISO 8601 absolute timestamp with timezone offset. */\nexport const actionDeadlineSchema = z.string().datetime({ offset: true });\n\n/** Non-empty unique `ActionChannel[]` for `next[i].channels`. */\nexport const actionChannelsSchema = z\n .array(z.enum(ACTION_CHANNELS as readonly [ActionChannel, ...ActionChannel[]]))\n .min(1)\n .refine((channels) => new Set(channels).size === channels.length, {\n message: \"channels must contain unique items\",\n });\n\n/** Single entry in the `next[]` array of any `nextActions` envelope. */\nexport const actionEntrySchema = z\n .object({\n id: z.string().min(1),\n channels: actionChannelsSchema,\n endpoints: z.record(z.string()).optional(),\n deadline: actionDeadlineSchema.optional(),\n })\n .strict();\n\n/**\n * Per-`tokenAuthStrategy` meta-tx entry points on\n * `onchainHints.metaTxFacet`. All four strategies are required so\n * clients can resolve any strategy they happen to advertise.\n */\nexport const metaTxEntrypointsSchema = z\n .object({\n none: z.string().min(1),\n erc3009: z.string().min(1),\n permit: z.string().min(1),\n permit2: z.string().min(1),\n })\n .strict();\n\n/** `fallback.onchainHints` block. */\nexport const onchainHintsSchema = z\n .object({\n escrow: addressSchema,\n metaTxFacet: z.string().min(1),\n metaTxEntrypoints: metaTxEntrypointsSchema,\n actionFacets: z.record(z.string()),\n })\n .strict();\n\n/** `fallback` block embedded in any `nextActions` envelope. */\nexport const actionsFallbackSchema = z\n .object({\n xmtp: z.string().optional(),\n mcp: z.string().optional(),\n onchainHints: onchainHintsSchema.optional(),\n })\n .strict();\n","// `escrow` scheme PaymentRequirements (server -> client, in 402 body).\n// Source of truth: docs/boson-impl-01-escrow-scheme.md §2.\n\nimport { z } from \"zod\";\n\nimport { actionEntrySchema, actionsFallbackSchema } from \"./shared-schemas.js\";\nimport {\n TOKEN_AUTH_STRATEGIES,\n type ActionsEnvelope,\n type Address,\n type BosonOfferRef,\n type EvmNetwork,\n type FulfillmentRequirements,\n type TokenAuthStrategy,\n} from \"./types.js\";\nimport { addressSchema, decimalUintSchema, evmNetworkSchema, hexSchema } from \"./validators.js\";\n\nconst offerRefSchema = z\n .object({\n fullOffer: z.record(z.unknown()),\n sellerSig: hexSchema,\n creator: addressSchema,\n })\n .strict();\n\nconst tokenAuthStrategySchema = z.enum(\n TOKEN_AUTH_STRATEGIES as readonly [TokenAuthStrategy, ...TokenAuthStrategy[]],\n);\n\nconst fulfillmentSchema = z\n .object({\n required: z.boolean(),\n options: z.array(\n z\n .object({\n id: z.string().min(1),\n schema: z.union([z.record(z.unknown()), z.null()]),\n metadata: z.unknown().optional(),\n })\n .strict(),\n ),\n })\n .strict();\n\n// Pre-commit (initial 402) `actions` envelope: `next[]` must be\n// non-empty (the buyer needs at least one path to commit) and the\n// `fallback` block is optional.\nconst actionsSchema = z\n .object({\n next: z.array(actionEntrySchema).min(1),\n fallback: actionsFallbackSchema.optional(),\n })\n .strict();\n\n/**\n * Wire-format type for the `escrow` PaymentRequirements that a server emits\n * inside a 402 `accepts[]` entry. See docs/boson-impl-01-escrow-scheme.md §2\n * for field semantics.\n */\nexport interface EscrowPaymentRequirements {\n scheme: \"escrow\";\n network: EvmNetwork;\n asset: Address;\n /** Atomic units, decimal string. */\n amount: string;\n /** Address of the Boson escrow contract — the custodian. */\n escrowAddress: Address;\n /** Routing-only seller identifier. May be a numeric `sellerId`, a `did:boson:seller:N`, or a wallet address. */\n recipientId: string;\n maxTimeoutSeconds: number;\n offer: BosonOfferRef;\n tokenAuthStrategies: TokenAuthStrategy[];\n fulfillment?: FulfillmentRequirements;\n actions: ActionsEnvelope;\n}\n\n/** Zod validator paired with `payment_requirements.schema.json`. */\nexport const escrowPaymentRequirementsSchema = z\n .object({\n scheme: z.literal(\"escrow\"),\n network: evmNetworkSchema,\n asset: addressSchema,\n amount: decimalUintSchema,\n escrowAddress: addressSchema,\n recipientId: z.string().min(1),\n maxTimeoutSeconds: z.number().int().positive(),\n offer: offerRefSchema,\n tokenAuthStrategies: z\n .array(tokenAuthStrategySchema)\n .min(1)\n .refine((strategies) => new Set(strategies).size === strategies.length, {\n message: \"tokenAuthStrategies must not contain duplicates\",\n }),\n fulfillment: fulfillmentSchema.optional(),\n actions: actionsSchema,\n })\n .strict();\n\n/** Type-guard form. Returns the parsed value on success, throws on failure (with a `ZodError` carrying the field path). */\nexport function parseEscrowPaymentRequirements(value: unknown): EscrowPaymentRequirements {\n return escrowPaymentRequirementsSchema.parse(value);\n}\n","// `escrow` scheme PaymentPayload (client -> server, base64'd in `X-PAYMENT`).\n// Source of truth: docs/boson-impl-01-escrow-scheme.md §3.\n\nimport { z } from \"zod\";\n\nimport {\n TOKEN_AUTH_STRATEGIES,\n type Address,\n type BosonMetaTx,\n type BosonTokenAuth,\n type EvmNetwork,\n type FullOffer,\n type Hex,\n type TokenAuthStrategy,\n} from \"./types.js\";\nimport {\n addressSchema,\n decimalUintSchema,\n evmNetworkSchema,\n hex32Schema,\n hexBytesSchema,\n hexSchema,\n} from \"./validators.js\";\n\nconst sigSchema = z\n .object({\n v: z.number().int(),\n r: hex32Schema,\n s: hex32Schema,\n })\n .strict();\n\nconst metaTxSchema = z\n .object({\n from: addressSchema,\n nonce: decimalUintSchema,\n functionName: z.string().min(1),\n functionSignature: hexBytesSchema,\n sig: sigSchema,\n })\n .strict();\n\nconst erc3009DataSchema = z\n .object({\n from: addressSchema,\n to: addressSchema,\n value: decimalUintSchema,\n validAfter: z.number().int().nonnegative(),\n validBefore: z.number().int().nonnegative(),\n nonce: hex32Schema,\n v: z.number().int(),\n r: hex32Schema,\n s: hex32Schema,\n })\n .strict();\n\nconst permitDataSchema = z\n .object({\n owner: addressSchema,\n spender: addressSchema,\n value: decimalUintSchema,\n deadline: z.number().int().nonnegative(),\n nonce: decimalUintSchema,\n v: z.number().int(),\n r: hex32Schema,\n s: hex32Schema,\n })\n .strict();\n\nconst permit2DataSchema = z\n .object({\n permitted: z\n .object({\n token: addressSchema,\n amount: decimalUintSchema,\n })\n .strict(),\n spender: addressSchema,\n nonce: decimalUintSchema,\n deadline: z.number().int().nonnegative(),\n signature: hexSchema,\n })\n .strict();\n\nconst tokenAuthSchema = z.discriminatedUnion(\"kind\", [\n z.object({ kind: z.literal(\"erc3009\"), data: erc3009DataSchema }).strict(),\n z.object({ kind: z.literal(\"permit\"), data: permitDataSchema }).strict(),\n z.object({ kind: z.literal(\"permit2\"), data: permit2DataSchema }).strict(),\n]);\n\nconst tokenAuthStrategySchema = z.enum(\n TOKEN_AUTH_STRATEGIES as readonly [TokenAuthStrategy, ...TokenAuthStrategy[]],\n);\n\n/** Inner `payload` field of `EscrowPaymentPayload`. */\nexport interface EscrowPaymentPayloadInner {\n action: string;\n tokenAuthStrategy: TokenAuthStrategy;\n offerRef: { fullOffer: FullOffer; sellerSig: Hex };\n buyer: Address;\n metaTx: BosonMetaTx;\n /** Required iff `tokenAuthStrategy !== \"none\"`. */\n tokenAuth?: BosonTokenAuth;\n}\n\n/**\n * Wire-format type for the `escrow` PaymentPayload that a client base64's into\n * the `X-PAYMENT` header. See docs/boson-impl-01-escrow-scheme.md §3.\n *\n * `fulfillment.option` is always the buyer's pick from the server-advertised\n * option set (capability negotiation). `fulfillment.data` is action-conditional:\n *\n * - For atomic Flow B (`boson-createOfferCommitAndRedeem`), `data` MUST be\n * present (or `null` when the option's schema is `null`). Atomic Flow B\n * completes the redeem on-chain inside the commit transaction, so there's\n * no later round trip in which the buyer could hand the seller delivery\n * data — it must travel with `X-PAYMENT`.\n * - For two-step Flow A (`boson-createOfferAndCommit`), `data` MUST be\n * omitted. The buyer attaches it to the redeem-time POST body that\n * accompanies `boson-redeem`, after a successful commit. See\n * `docs/boson-impl-03-fulfillment-channels.md`.\n *\n * The Zod schema parses both shapes structurally; the action-conditional\n * presence/absence rule is enforced by the server-side validator (rule 13).\n */\nexport interface EscrowPaymentPayload {\n x402Version: number;\n scheme: \"escrow\";\n network: EvmNetwork;\n payload: EscrowPaymentPayloadInner;\n fulfillment?: { option: string; data?: Record<string, unknown> | null };\n}\n\n/**\n * Zod validator paired with `payment_payload.schema.json`. Note: this only\n * validates structural shape; cross-field rules (per docs/boson-impl-01 §5)\n * such as \"tokenAuth must be omitted iff tokenAuthStrategy === 'none'\" are\n * enforced server-side and are not part of this schema.\n */\nexport const escrowPaymentPayloadSchema = z\n .object({\n x402Version: z.number().int(),\n scheme: z.literal(\"escrow\"),\n network: evmNetworkSchema,\n payload: z\n .object({\n action: z.string().min(1),\n tokenAuthStrategy: tokenAuthStrategySchema,\n offerRef: z\n .object({\n fullOffer: z.record(z.unknown()),\n sellerSig: hexSchema,\n })\n .strict(),\n buyer: addressSchema,\n metaTx: metaTxSchema,\n tokenAuth: tokenAuthSchema.optional(),\n })\n .strict(),\n fulfillment: z\n .object({\n option: z.string().min(1),\n // `data` is action-conditional (Flow B only). The structural\n // schema accepts both shapes; the server validator enforces\n // presence vs absence based on `payload.action`.\n data: z.union([z.record(z.unknown()), z.null()]).optional(),\n })\n .strict()\n .optional(),\n })\n .strict();\n\nexport function parseEscrowPaymentPayload(value: unknown): EscrowPaymentPayload {\n return escrowPaymentPayloadSchema.parse(value);\n}\n","// Post-commit `nextActions` envelope (top level of every response after\n// the initial 402). The pre-commit variant lives nested inside\n// `EscrowPaymentRequirements.actions` — see `payment-requirements.ts`.\n//\n// Source of truth: docs/boson-impl-04-state-machine-and-next-actions.md\n// §\"`nextActions` envelope\" and `schemas/next_actions.schema.json`.\n\nimport { z } from \"zod\";\n\nimport { DisputeState, ExchangeState } from \"../../state-machine/states.js\";\nimport { actionEntrySchema, actionsFallbackSchema } from \"./shared-schemas.js\";\nimport { type ActionsFallback, type NextAction } from \"./types.js\";\n\n/**\n * Wire-format type for the post-commit `nextActions` envelope.\n *\n * The `exchangeState === DISPUTED ↔ disputeState present` invariant is\n * encoded structurally: `exchangeState: DISPUTED` requires\n * `disputeState`, and any other `exchangeState` forbids it. The zod\n * validator below enforces the same invariant at runtime.\n *\n * The wire field is named `exchangeState` (not `state`) for symmetry\n * with `disputeState` and to remove ambiguity with the `state` field\n * the subgraph entity itself carries.\n */\nexport type EscrowNextActions = {\n exchangeId: string;\n next: NextAction[];\n fallback?: ActionsFallback;\n} & (\n | {\n exchangeState: Exclude<ExchangeState, typeof ExchangeState.DISPUTED>;\n disputeState?: never;\n }\n | { exchangeState: typeof ExchangeState.DISPUTED; disputeState: DisputeState }\n);\n\nconst exchangeStateSchema = z.nativeEnum(ExchangeState);\nconst disputeStateSchema = z.nativeEnum(DisputeState);\n\n/** Zod validator paired with `next_actions.schema.json`. */\nexport const escrowNextActionsSchema = z\n .object({\n exchangeId: z.string().min(1),\n exchangeState: exchangeStateSchema,\n disputeState: disputeStateSchema.optional(),\n next: z.array(actionEntrySchema),\n fallback: actionsFallbackSchema.optional(),\n })\n .strict()\n .refine(\n (envelope) =>\n envelope.exchangeState === ExchangeState.DISPUTED\n ? envelope.disputeState !== undefined\n : envelope.disputeState === undefined,\n {\n message: \"disputeState is required iff exchangeState === DISPUTED\",\n path: [\"disputeState\"],\n },\n );\n\n/** Type-guard form. Returns the parsed value on success, throws on failure. */\nexport function parseEscrowNextActions(value: unknown): EscrowNextActions {\n return escrowNextActionsSchema.parse(value) as EscrowNextActions;\n}\n","// Public surface for the `escrow` scheme.\n// See docs/boson-impl-01-escrow-scheme.md for the wire format.\n\nexport * from \"./types.js\";\nexport * from \"./payment-requirements.js\";\nexport * from \"./payment-payload.js\";\nexport * from \"./next-actions.js\";\nexport * from \"./validators.js\";\n\n/** Stable identifier for the scheme. Use this in place of the raw string `\"escrow\"` to avoid typos. */\nexport const ESCROW_SCHEME = \"escrow\" as const;\nexport type EscrowScheme = typeof ESCROW_SCHEME;\n"]}
1
+ {"version":3,"sources":["../../../../src/schemes/escrow/types.ts","../../../../src/schemes/escrow/validators.ts","../../../../src/schemes/escrow/shared-schemas.ts","../../../../src/schemes/escrow/payment-requirements.ts","../../../../src/schemes/escrow/payment-payload.ts","../../../../src/schemes/escrow/next-actions.ts","../../../../src/schemes/escrow/accepts.ts","../../../../src/schemes/escrow/index.ts"],"names":["z","tokenAuthStrategySchema"],"mappings":";;;;AAcO,IAAM,qBAAA,GAAsD;AAAA,EACjE,MAAA;AAAA,EACA,SAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF;AAOO,IAAM,eAAA,GAA4C;AAAA,EACvD,QAAA;AAAA,EACA,aAAA;AAAA,EACA,SAAA;AAAA,EACA,KAAA;AAAA,EACA;AACF;ACxBO,IAAM,GAAA,GAAM;AAGZ,IAAM,SAAA,GAAY;AAGlB,IAAM,KAAA,GAAQ;AAGd,IAAM,OAAA,GAAU;AAGhB,IAAM,YAAA,G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aAAA,EAAe,mBAAA;AAAA,EACf,YAAA,EAAc,mBAAmB,QAAA,EAAS;AAAA,EAC1C,IAAA,EAAMA,CAAAA,CAAE,KAAA,CAAM,iBAAiB,CAAA;AAAA,EAC/B,QAAA,EAAU,sBAAsB,QAAA;AAClC,CAAC,CAAA,CACA,QAAO,CACP,MAAA;AAAA,EACC,CAAC,QAAA,KACC,QAAA,CAAS,aAAA,KAAkB,aAAA,CAAc,WACrC,QAAA,CAAS,YAAA,KAAiB,MAAA,GAC1B,QAAA,CAAS,YAAA,KAAiB,MAAA;AAAA,EAChC;AAAA,IACE,OAAA,EAAS,yDAAA;AAAA,IACT,IAAA,EAAM,CAAC,cAAc;AAAA;AAEzB;AAGK,SAAS,uBAAuB,KAAA,EAAmC;AACxE,EAAA,OAAO,uBAAA,CAAwB,MAAM,KAAK,CAAA;AAC5C;;;AC/CO,SAAS,iBAAiB,IAAA,EAAoC;AACnE,EAAA,IAAI,OAAO,IAAA,KAAS,QAAA,IAAY,IAAA,KAAS,IAAA,EAAM;AAC7C,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,MAAM,UAAW,IAAA,CAA+B,OAAA;AAChD,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,OAAO,CAAA,EAAG;AAC3B,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,OAAO,OAAA,CAAQ,IAAA;AAAA,IACb,CAAC,UACC,OAAO,KAAA,KAAU,YACjB,KAAA,KAAU,IAAA,IACT,MAA+B,MAAA,KAAW;AAAA,GAC/C;AACF;;;ACpBO,IAAM,aAAA,GAAgB","file":"index.js","sourcesContent":["// Shared wire-format types for the `escrow` scheme.\n// Source of truth: docs/boson-impl-01-escrow-scheme.md.\n\n/**\n * CAIP-2 network identifier for an EVM chain. Constrained to `eip155:<chainId>`\n * shape at runtime by the JSON Schema and zod regex; aliased to `string` here\n * for the same reason as `Address` / `Hex` — the wire format is JSON, where\n * everything is a string, and template-literal types cause friction with\n * zod's regex-based validators.\n */\nexport type EvmNetwork = string;\n\n/** BPIP-12 token-authorization strategies. */\nexport type TokenAuthStrategy = \"none\" | \"erc3009\" | \"permit\" | \"permit2\";\nexport const TOKEN_AUTH_STRATEGIES: readonly TokenAuthStrategy[] = [\n \"none\",\n \"erc3009\",\n \"permit\",\n \"permit2\",\n] as const;\n\n/** Boson commit-time action ids advertised by the server. */\nexport type BosonCommitActionId = \"boson-createOfferAndCommit\" | \"boson-createOfferCommitAndRedeem\";\n\n/** Channels through which a `nextAction` can be performed. */\nexport type ActionChannel = \"server\" | \"facilitator\" | \"onchain\" | \"mcp\" | \"xmtp\";\nexport const ACTION_CHANNELS: readonly ActionChannel[] = [\n \"server\",\n \"facilitator\",\n \"onchain\",\n \"mcp\",\n \"xmtp\",\n] as const;\n\n/**\n * BPIP-10 FullOffer. Treated as opaque at this layer — the on-chain shape lives\n * in `@bosonprotocol/core-sdk`, and validation against the protocol struct is\n * the EIP-712 builder's job. Here it's just \"an object echoed verbatim\".\n */\nexport type FullOffer = Record<string, unknown>;\n\n/**\n * 0x-prefixed hex string. Aliased to `string` in the wire format so JSON\n * shapes are easy to construct; runtime validation is handled by the JSON\n * Schema and zod regex. The strongly-typed `\\`0x${string}\\`` form is reserved\n * for the EIP-712 builder layer where viem's brands matter.\n */\nexport type Hex = string;\n/** 0x-prefixed 40-char hex string. See `Hex` for typing rationale. */\nexport type Address = string;\n\n/** Off-chain offer reference signed by the seller. */\nexport interface BosonOfferRef {\n fullOffer: FullOffer;\n sellerSig: Hex;\n creator: Address;\n}\n\nexport interface FulfillmentOption {\n id: string;\n /** JSON-Schema-shaped `type: object` description of the data the buyer must supply, or `null` for schemaless channels. */\n schema: Record<string, unknown> | null;\n /** Channel-specific hints advertised to the client, such as endpoint URLs or public keys. */\n metadata?: unknown;\n}\n\nexport interface FulfillmentRequirements {\n required: boolean;\n options: FulfillmentOption[];\n}\n\nexport interface NextAction {\n id: string;\n channels: ActionChannel[];\n endpoints?: Record<string, string>;\n /**\n * ISO 8601 absolute timestamp by which the action must be invoked.\n * Relevant for dispute-window-bounded actions like\n * `boson-resolveDispute`, `boson-escalateDispute`,\n * `boson-retractDispute`, and (post-commit) `boson-completeExchange`.\n */\n deadline?: string;\n}\n\nexport interface OnchainHints {\n /** Address of the Boson escrow contract. */\n escrow: Address;\n metaTxFacet: string;\n /**\n * Per-`tokenAuthStrategy` meta-tx entry points on `metaTxFacet`. The\n * Boson Diamond exposes two functions on `MetaTransactionsHandlerFacet`:\n *\n * - `executeMetaTransaction` — legacy BPIP-9 entry point. Used when\n * the buyer's `tokenAuthStrategy` is `none` (the buyer has\n * pre-approved the Diamond, so no token-transfer authorization\n * queue is needed). Also the right entry point for any\n * post-commit action that doesn't move tokens (`redeem`,\n * `complete`, dispute transitions).\n * - `executeMetaTransactionWithTokenTransferAuthorization` — BPIP-12\n * entry point. Carries the buyer's signed `MetaTransaction` *and*\n * a queue of token-transfer authorizations. Used when\n * `tokenAuthStrategy` is `erc3009`, `permit`, or `permit2`.\n *\n * Clients select the entry point by their chosen strategy at\n * dispatch time.\n */\n metaTxEntrypoints: Record<TokenAuthStrategy, string>;\n actionFacets: Record<string, string>;\n}\n\nexport interface ActionsFallback {\n xmtp?: string;\n /**\n * Identifier within the Boson MCP server (e.g. the\n * `bosonprotocol/agentic-commerce` server) that the buyer's\n * MCP-aware agent dispatches against. The MCP *server* is escrow-\n * level (one BosonMCP serving every Boson seller); this value is the\n * URI/identifier the BosonMCP routes to the right exchange / seller.\n */\n mcp?: string;\n onchainHints?: OnchainHints;\n}\n\nexport interface ActionsEnvelope {\n next: NextAction[];\n fallback?: ActionsFallback;\n}\n\n/** Boson protocol meta-transaction envelope (signed by the buyer). */\nexport interface BosonMetaTx {\n from: Address;\n /** Decimal string. */\n nonce: string;\n functionName: string;\n /**\n * ABI-encoded function-call data as a `0x`-prefixed hex string. Named\n * `functionSignature` to match the on-chain `MetaTransactionsHandlerFacet`\n * struct field — the value is the encoded calldata, not just the function\n * selector.\n */\n functionSignature: Hex;\n sig: { v: number; r: Hex; s: Hex };\n}\n\nexport interface Erc3009AuthData {\n from: Address;\n to: Address;\n /** Atomic units, decimal string. */\n value: string;\n validAfter: number;\n validBefore: number;\n /** 32-byte hex string. */\n nonce: Hex;\n v: number;\n r: Hex;\n s: Hex;\n}\n\nexport interface PermitAuthData {\n owner: Address;\n spender: Address;\n /** Atomic units, decimal string. */\n value: string;\n deadline: number;\n /** Token-internal sequential nonce, decimal string. */\n nonce: string;\n v: number;\n r: Hex;\n s: Hex;\n}\n\nexport interface Permit2AuthData {\n permitted: { token: Address; amount: string };\n spender: Address;\n /** Permit2 word-bitmap nonce, decimal string. */\n nonce: string;\n deadline: number;\n /** Concatenated 65-byte ECDSA signature. */\n signature: Hex;\n}\n\n/** Discriminated union of all token-authorization payloads. `none` is encoded by the absence of this field on the payload. */\nexport type BosonTokenAuth =\n | { kind: \"erc3009\"; data: Erc3009AuthData }\n | { kind: \"permit\"; data: PermitAuthData }\n | { kind: \"permit2\"; data: Permit2AuthData };\n","// Shared regex patterns + scalar zod schemas used across the `escrow`\n// scheme's payment-requirements and payment-payload validators. Keeping\n// them in one place ensures the JSON Schema's patterns and the zod regexes\n// stay in sync (see `schemas/*.json` for the JSON Schema source of truth).\n\nimport { z } from \"zod\";\n\n/** 0x-prefixed hex string, at least one nibble. */\nexport const HEX = /^0x[a-fA-F0-9]+$/;\n\n/** 0x-prefixed hex string, allowing the empty `0x` form for empty bytes. */\nexport const HEX_BYTES = /^0x[a-fA-F0-9]*$/;\n\n/** 0x-prefixed 32-byte (64-nibble) hex string. */\nexport const HEX32 = /^0x[a-fA-F0-9]{64}$/;\n\n/** 0x-prefixed 20-byte (40-nibble) hex address. */\nexport const ADDRESS = /^0x[a-fA-F0-9]{40}$/;\n\n/** Decimal unsigned integer string, no leading zeros (except \"0\" itself). */\nexport const DECIMAL_UINT = /^(0|[1-9][0-9]*)$/;\n\n/** CAIP-2 EVM network identifier: `eip155:<chainId>`. */\nexport const EVM_NETWORK = /^eip155:[1-9][0-9]*$/;\n\nexport const addressSchema = z.string().regex(ADDRESS);\nexport const hexSchema = z.string().regex(HEX);\nexport const hexBytesSchema = z.string().regex(HEX_BYTES);\nexport const hex32Schema = z.string().regex(HEX32);\nexport const decimalUintSchema = z.string().regex(DECIMAL_UINT);\nexport const evmNetworkSchema = z.string().regex(EVM_NETWORK);\n","// Shared zod fragments used by both `payment-requirements.ts` (the\n// pre-commit / 402 envelope) and `next-actions.ts` (the post-commit\n// envelope). Centralised here so the two wire-format validators can't\n// drift on shared sub-shapes like an action entry, the `fallback` block,\n// or the `onchainHints` block.\n\nimport { z } from \"zod\";\n\nimport { ACTION_CHANNELS, type ActionChannel } from \"./types.js\";\nimport { addressSchema } from \"./validators.js\";\n\n/** ISO 8601 absolute timestamp with timezone offset. */\nexport const actionDeadlineSchema = z.string().datetime({ offset: true });\n\n/** Non-empty unique `ActionChannel[]` for `next[i].channels`. */\nexport const actionChannelsSchema = z\n .array(z.enum(ACTION_CHANNELS as readonly [ActionChannel, ...ActionChannel[]]))\n .min(1)\n .refine((channels) => new Set(channels).size === channels.length, {\n message: \"channels must contain unique items\",\n });\n\n/** Single entry in the `next[]` array of any `nextActions` envelope. */\nexport const actionEntrySchema = z\n .object({\n id: z.string().min(1),\n channels: actionChannelsSchema,\n endpoints: z.record(z.string()).optional(),\n deadline: actionDeadlineSchema.optional(),\n })\n .strict();\n\n/**\n * Per-`tokenAuthStrategy` meta-tx entry points on\n * `onchainHints.metaTxFacet`. All four strategies are required so\n * clients can resolve any strategy they happen to advertise.\n */\nexport const metaTxEntrypointsSchema = z\n .object({\n none: z.string().min(1),\n erc3009: z.string().min(1),\n permit: z.string().min(1),\n permit2: z.string().min(1),\n })\n .strict();\n\n/** `fallback.onchainHints` block. */\nexport const onchainHintsSchema = z\n .object({\n escrow: addressSchema,\n metaTxFacet: z.string().min(1),\n metaTxEntrypoints: metaTxEntrypointsSchema,\n actionFacets: z.record(z.string()),\n })\n .strict();\n\n/** `fallback` block embedded in any `nextActions` envelope. */\nexport const actionsFallbackSchema = z\n .object({\n xmtp: z.string().optional(),\n mcp: z.string().optional(),\n onchainHints: onchainHintsSchema.optional(),\n })\n .strict();\n","// `escrow` scheme PaymentRequirements (server -> client, in 402 body).\n// Source of truth: docs/boson-impl-01-escrow-scheme.md §2.\n\nimport { z } from \"zod\";\n\nimport { actionEntrySchema, actionsFallbackSchema } from \"./shared-schemas.js\";\nimport {\n TOKEN_AUTH_STRATEGIES,\n type ActionsEnvelope,\n type Address,\n type BosonOfferRef,\n type EvmNetwork,\n type FulfillmentRequirements,\n type TokenAuthStrategy,\n} from \"./types.js\";\nimport { addressSchema, decimalUintSchema, evmNetworkSchema, hexSchema } from \"./validators.js\";\n\nconst offerRefSchema = z\n .object({\n fullOffer: z.record(z.unknown()),\n sellerSig: hexSchema,\n creator: addressSchema,\n })\n .strict();\n\nconst tokenAuthStrategySchema = z.enum(\n TOKEN_AUTH_STRATEGIES as readonly [TokenAuthStrategy, ...TokenAuthStrategy[]],\n);\n\nconst fulfillmentSchema = z\n .object({\n required: z.boolean(),\n options: z.array(\n z\n .object({\n id: z.string().min(1),\n schema: z.union([z.record(z.unknown()), z.null()]),\n metadata: z.unknown().optional(),\n })\n .strict(),\n ),\n })\n .strict();\n\n// Pre-commit (initial 402) `actions` envelope: `next[]` must be\n// non-empty (the buyer needs at least one path to commit) and the\n// `fallback` block is optional.\nconst actionsSchema = z\n .object({\n next: z.array(actionEntrySchema).min(1),\n fallback: actionsFallbackSchema.optional(),\n })\n .strict();\n\n/**\n * Wire-format type for the `escrow` PaymentRequirements that a server emits\n * inside a 402 `accepts[]` entry. See docs/boson-impl-01-escrow-scheme.md §2\n * for field semantics.\n */\nexport interface EscrowPaymentRequirements {\n scheme: \"escrow\";\n network: EvmNetwork;\n asset: Address;\n /** Atomic units, decimal string. */\n amount: string;\n /** Address of the Boson escrow contract — the custodian. */\n escrowAddress: Address;\n /** Routing-only seller identifier. May be a numeric `sellerId`, a `did:boson:seller:N`, or a wallet address. */\n recipientId: string;\n maxTimeoutSeconds: number;\n offer: BosonOfferRef;\n tokenAuthStrategies: TokenAuthStrategy[];\n fulfillment?: FulfillmentRequirements;\n actions: ActionsEnvelope;\n}\n\n/** Zod validator paired with `payment_requirements.schema.json`. */\nexport const escrowPaymentRequirementsSchema = z\n .object({\n scheme: z.literal(\"escrow\"),\n network: evmNetworkSchema,\n asset: addressSchema,\n amount: decimalUintSchema,\n escrowAddress: addressSchema,\n recipientId: z.string().min(1),\n maxTimeoutSeconds: z.number().int().positive(),\n offer: offerRefSchema,\n tokenAuthStrategies: z\n .array(tokenAuthStrategySchema)\n .min(1)\n .refine((strategies) => new Set(strategies).size === strategies.length, {\n message: \"tokenAuthStrategies must not contain duplicates\",\n }),\n fulfillment: fulfillmentSchema.optional(),\n actions: actionsSchema,\n })\n .strict();\n\n/** Type-guard form. Returns the parsed value on success, throws on failure (with a `ZodError` carrying the field path). */\nexport function parseEscrowPaymentRequirements(value: unknown): EscrowPaymentRequirements {\n return escrowPaymentRequirementsSchema.parse(value);\n}\n","// `escrow` scheme PaymentPayload (client -> server, base64'd in `X-PAYMENT`).\n// Source of truth: docs/boson-impl-01-escrow-scheme.md §3.\n\nimport { z } from \"zod\";\n\nimport {\n TOKEN_AUTH_STRATEGIES,\n type Address,\n type BosonMetaTx,\n type BosonTokenAuth,\n type EvmNetwork,\n type FullOffer,\n type Hex,\n type TokenAuthStrategy,\n} from \"./types.js\";\nimport {\n addressSchema,\n decimalUintSchema,\n evmNetworkSchema,\n hex32Schema,\n hexBytesSchema,\n hexSchema,\n} from \"./validators.js\";\n\nconst sigSchema = z\n .object({\n v: z.number().int(),\n r: hex32Schema,\n s: hex32Schema,\n })\n .strict();\n\nconst metaTxSchema = z\n .object({\n from: addressSchema,\n nonce: decimalUintSchema,\n functionName: z.string().min(1),\n functionSignature: hexBytesSchema,\n sig: sigSchema,\n })\n .strict();\n\nconst erc3009DataSchema = z\n .object({\n from: addressSchema,\n to: addressSchema,\n value: decimalUintSchema,\n validAfter: z.number().int().nonnegative(),\n validBefore: z.number().int().nonnegative(),\n nonce: hex32Schema,\n v: z.number().int(),\n r: hex32Schema,\n s: hex32Schema,\n })\n .strict();\n\nconst permitDataSchema = z\n .object({\n owner: addressSchema,\n spender: addressSchema,\n value: decimalUintSchema,\n deadline: z.number().int().nonnegative(),\n nonce: decimalUintSchema,\n v: z.number().int(),\n r: hex32Schema,\n s: hex32Schema,\n })\n .strict();\n\nconst permit2DataSchema = z\n .object({\n permitted: z\n .object({\n token: addressSchema,\n amount: decimalUintSchema,\n })\n .strict(),\n spender: addressSchema,\n nonce: decimalUintSchema,\n deadline: z.number().int().nonnegative(),\n signature: hexSchema,\n })\n .strict();\n\nconst tokenAuthSchema = z.discriminatedUnion(\"kind\", [\n z.object({ kind: z.literal(\"erc3009\"), data: erc3009DataSchema }).strict(),\n z.object({ kind: z.literal(\"permit\"), data: permitDataSchema }).strict(),\n z.object({ kind: z.literal(\"permit2\"), data: permit2DataSchema }).strict(),\n]);\n\nconst tokenAuthStrategySchema = z.enum(\n TOKEN_AUTH_STRATEGIES as readonly [TokenAuthStrategy, ...TokenAuthStrategy[]],\n);\n\n/** Inner `payload` field of `EscrowPaymentPayload`. */\nexport interface EscrowPaymentPayloadInner {\n action: string;\n tokenAuthStrategy: TokenAuthStrategy;\n offerRef: { fullOffer: FullOffer; sellerSig: Hex };\n buyer: Address;\n metaTx: BosonMetaTx;\n /** Required iff `tokenAuthStrategy !== \"none\"`. */\n tokenAuth?: BosonTokenAuth;\n}\n\n/**\n * Wire-format type for the `escrow` PaymentPayload that a client base64's into\n * the `X-PAYMENT` header. See docs/boson-impl-01-escrow-scheme.md §3.\n *\n * `fulfillment.option` is always the buyer's pick from the server-advertised\n * option set (capability negotiation). `fulfillment.data` is action-conditional:\n *\n * - For atomic Flow B (`boson-createOfferCommitAndRedeem`), `data` MUST be\n * present (or `null` when the option's schema is `null`). Atomic Flow B\n * completes the redeem on-chain inside the commit transaction, so there's\n * no later round trip in which the buyer could hand the seller delivery\n * data — it must travel with `X-PAYMENT`.\n * - For two-step Flow A (`boson-createOfferAndCommit`), `data` MUST be\n * omitted. The buyer attaches it to the redeem-time POST body that\n * accompanies `boson-redeem`, after a successful commit. See\n * `docs/boson-impl-03-fulfillment-channels.md`.\n *\n * The Zod schema parses both shapes structurally; the action-conditional\n * presence/absence rule is enforced by the server-side validator (rule 13).\n */\nexport interface EscrowPaymentPayload {\n x402Version: number;\n scheme: \"escrow\";\n network: EvmNetwork;\n payload: EscrowPaymentPayloadInner;\n fulfillment?: { option: string; data?: Record<string, unknown> | null };\n}\n\n/**\n * Zod validator paired with `payment_payload.schema.json`. Note: this only\n * validates structural shape; cross-field rules (per docs/boson-impl-01 §5)\n * such as \"tokenAuth must be omitted iff tokenAuthStrategy === 'none'\" are\n * enforced server-side and are not part of this schema.\n */\nexport const escrowPaymentPayloadSchema = z\n .object({\n x402Version: z.number().int(),\n scheme: z.literal(\"escrow\"),\n network: evmNetworkSchema,\n payload: z\n .object({\n action: z.string().min(1),\n tokenAuthStrategy: tokenAuthStrategySchema,\n offerRef: z\n .object({\n fullOffer: z.record(z.unknown()),\n sellerSig: hexSchema,\n })\n .strict(),\n buyer: addressSchema,\n metaTx: metaTxSchema,\n tokenAuth: tokenAuthSchema.optional(),\n })\n .strict(),\n fulfillment: z\n .object({\n option: z.string().min(1),\n // `data` is action-conditional (Flow B only). The structural\n // schema accepts both shapes; the server validator enforces\n // presence vs absence based on `payload.action`.\n data: z.union([z.record(z.unknown()), z.null()]).optional(),\n })\n .strict()\n .optional(),\n })\n .strict();\n\nexport function parseEscrowPaymentPayload(value: unknown): EscrowPaymentPayload {\n return escrowPaymentPayloadSchema.parse(value);\n}\n","// Post-commit `nextActions` envelope (top level of every response after\n// the initial 402). The pre-commit variant lives nested inside\n// `EscrowPaymentRequirements.actions` — see `payment-requirements.ts`.\n//\n// Source of truth: docs/boson-impl-04-state-machine-and-next-actions.md\n// §\"`nextActions` envelope\" and `schemas/next_actions.schema.json`.\n\nimport { z } from \"zod\";\n\nimport { DisputeState, ExchangeState } from \"../../state-machine/states.js\";\nimport { actionEntrySchema, actionsFallbackSchema } from \"./shared-schemas.js\";\nimport { type ActionsFallback, type NextAction } from \"./types.js\";\n\n/**\n * Wire-format type for the post-commit `nextActions` envelope.\n *\n * The `exchangeState === DISPUTED ↔ disputeState present` invariant is\n * encoded structurally: `exchangeState: DISPUTED` requires\n * `disputeState`, and any other `exchangeState` forbids it. The zod\n * validator below enforces the same invariant at runtime.\n *\n * The wire field is named `exchangeState` (not `state`) for symmetry\n * with `disputeState` and to remove ambiguity with the `state` field\n * the subgraph entity itself carries.\n */\nexport type EscrowNextActions = {\n exchangeId: string;\n next: NextAction[];\n fallback?: ActionsFallback;\n} & (\n | {\n exchangeState: Exclude<ExchangeState, typeof ExchangeState.DISPUTED>;\n disputeState?: never;\n }\n | { exchangeState: typeof ExchangeState.DISPUTED; disputeState: DisputeState }\n);\n\nconst exchangeStateSchema = z.nativeEnum(ExchangeState);\nconst disputeStateSchema = z.nativeEnum(DisputeState);\n\n/** Zod validator paired with `next_actions.schema.json`. */\nexport const escrowNextActionsSchema = z\n .object({\n exchangeId: z.string().min(1),\n exchangeState: exchangeStateSchema,\n disputeState: disputeStateSchema.optional(),\n next: z.array(actionEntrySchema),\n fallback: actionsFallbackSchema.optional(),\n })\n .strict()\n .refine(\n (envelope) =>\n envelope.exchangeState === ExchangeState.DISPUTED\n ? envelope.disputeState !== undefined\n : envelope.disputeState === undefined,\n {\n message: \"disputeState is required iff exchangeState === DISPUTED\",\n path: [\"disputeState\"],\n },\n );\n\n/** Type-guard form. Returns the parsed value on success, throws on failure. */\nexport function parseEscrowNextActions(value: unknown): EscrowNextActions {\n return escrowNextActionsSchema.parse(value) as EscrowNextActions;\n}\n","// Locate the `escrow` entry inside a parsed x402 402 challenge body.\n//\n// The 402 JSON envelope is `{ x402Version, accepts: [requirements...] }`\n// (see `respondWithChallenge` in `@bosonprotocol/x402-server-express`). A\n// server may advertise several schemes in `accepts[]`; this returns the\n// first entry whose `scheme === \"escrow\"`, or `undefined` when the body\n// isn't an object, has no `accepts[]` array, or carries only other\n// schemes.\n//\n// Single-sourced here so the buyer-side fetch wrapper\n// (`@bosonprotocol/x402-client-fetch`) and the browser paywall\n// (`@bosonprotocol/x402-paywall`) pick the entry identically. The input\n// is the already-parsed JSON body rather than a `Response` so the helper\n// stays environment-agnostic — each caller owns how it decodes the\n// response (clone-then-`json()` for the wrapper, plain `json()` for the\n// paywall).\n\nexport function findEscrowAccept(body: unknown): unknown | undefined {\n if (typeof body !== \"object\" || body === null) {\n return undefined;\n }\n const accepts = (body as { accepts?: unknown }).accepts;\n if (!Array.isArray(accepts)) {\n return undefined;\n }\n return accepts.find(\n (entry) =>\n typeof entry === \"object\" &&\n entry !== null &&\n (entry as { scheme?: unknown }).scheme === \"escrow\",\n );\n}\n","// Public surface for the `escrow` scheme.\n// See docs/boson-impl-01-escrow-scheme.md for the wire format.\n\nexport * from \"./types.js\";\nexport * from \"./payment-requirements.js\";\nexport * from \"./payment-payload.js\";\nexport * from \"./next-actions.js\";\nexport * from \"./validators.js\";\nexport * from \"./accepts.js\";\n\n/** Stable identifier for the scheme. Use this in place of the raw string `\"escrow\"` to avoid typos. */\nexport const ESCROW_SCHEME = \"escrow\" as const;\nexport type EscrowScheme = typeof ESCROW_SCHEME;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bosonprotocol/x402-core",
3
- "version": "0.2.0",
3
+ "version": "0.2.1-alpha-0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Boson Protocol escrow scheme for x402 — JSON schemas, TypeScript types, EIP-712 builders, and exchange state machine.",
6
6
  "repository": {