import type { Branding, Credential, ReaderIdentity, VerificationStore } from "../types.js"; import { type Origin, type RequestLike } from "./origin.js"; import type { CeremonyCatalog, CeremonyOrder, CeremonyOrderStore, CompletionSeam, DelegatedVerifier, SettlementSeam } from "./types.js"; /** Minimal Express-app shape mount() needs (no `express` dependency). */ export interface CeremonyApp { locals: Record; get?(path: string, ...handlers: unknown[]): unknown; post?(path: string, ...handlers: unknown[]): unknown; use?(path: string, ...handlers: unknown[]): unknown; } /** What the host injects. Required seams throw if missing (CT2); `origin`, * `settlement`, and the signing-key escape hatch have safe behaviors. */ export interface CeremonySeams { /** Per-order verification state (never process-global — invariant 4). */ verificationStore: VerificationStore; /** Resolve a created order by id (totals are re-priced from `catalog`). */ orderStore: CeremonyOrderStore; /** Server-side re-pricing — the amount source of truth (invariant 2). */ catalog: CeremonyCatalog; /** Host-bound completion (idempotent record + cart/verification clear). */ completion: CompletionSeam; /** Stable HMAC key for the challenge nonce. Required so options→verify survive * an instance split (D6) UNLESS `allowEphemeralKey` is explicitly set. */ signingKey?: string; /** RP-id / origin derivation; defaults to the built-in `deriveOrigin`. */ origin?: (req: RequestLike) => Origin; /** Optional demo-mode settlement seam (absent ⇒ mock-complete). */ settlement?: SettlementSeam; /** Optional external verifier/processor (008, #60). When present, the delegated rail * is served and verification/settlement are delegated to it — the gate still owns * pricing, binding, policy and recording. Absent ⇒ the delegated rail registers * NOTHING and every existing path is byte-unchanged (genuinely optional, like * `settlement`). */ verifier?: DelegatedVerifier; /** Dev-only: allow an ephemeral per-process signing key. NEVER inferred — * mount() does not guess "serverless". */ allowEphemeralKey?: boolean; /** Opt-in (default false): treat a VERIFIED Cart Mandate as the created-order * transport, so `resolveOrder` reconstructs the order from it with no * `orderStore` read (FR-007 / US3). Off ⇒ the store stays the source of truth * and the mandate is an additive integrity envelope only. */ statelessOrders?: boolean; /** Stable reader identity the rails present in their OpenID4VP request (clears * the wallet's "unknown verifier" warning). Absent ⇒ per-request self-signed * reader (presence-only). Normally set once on `new CredentAgent({ readerIdentity })`. */ readerIdentity?: ReaderIdentity; /** The gate's in-process credential registry (id → Credential), populated by * `requirements()` and passed here by `CredentAgent.mount()` (007). The rails read * it to serve a custom credential's own request/verify; it is re-published on * `app.locals.credentagent` so the host's `completion` seam can hand it to * `completeOrder` for the custom-gate sweep. Holds CODE (never the wire). */ credentialRegistry?: ReadonlyMap; /** Per-order resolved policy (order id → the policy's custom-credential ids), remembered by * `requirements()` and passed by `CredentAgent.mount()` (#59 finding 2 / PR #131). When present, * `mountCeremony` enriches every rail's completion call with `policyCredentialIds` from it, so * the custom-gate sweep is scoped to THIS order's policy under the plain `mount(app, ceremony)` * path — not only via `orders.serve`. Absent / order missing ⇒ the registry-wide sweep (fail-closed). */ orderPolicies?: ReadonlyMap; /** Where a rail returns the buyer after they prove (the "continue to checkout" link + * the post-proof redirect). Absent ⇒ each rail's default `/checkout?order=` (the * storefront's route). A host that serves its checkout elsewhere — e.g. `orders.serve` * at `/credentagent/orders/:id` — sets this so the buyer lands back on the right page. */ returnUrl?: (orderId: string) => string; /** Where the store serves an order's status record (JSON, with what was proven for it). The * payment pages link it as "Order record ›" once the order completes. The storefront sets * `/checkout/order-status?orderId=`; `orders.serve` its `/credentagent/orders//status`. * Absent ⇒ no link. */ statusUrl?: (orderId: string) => string; /** Host brand for the ceremony pages (wordmark / accent / logo / demo-pill). Normally set * once on `new CredentAgent({ branding })` and threaded here; every rail page picks it up. * Absent ⇒ the built-in look. Never affects the honesty trust footer. */ branding?: Branding; /** Return the wallet's decrypted DeviceResponse to the page that presented it, with an * "Inspect this presentation" link (see `CredentAgentOptions.inspectPresentations`). * Absent/false ⇒ off. */ inspectPresentations?: boolean; /** The path the browser reaches these routes under when a proxy mounts the app below one * (e.g. `/marketplace` for https://shop.example/marketplace/* → this server's /*). Every * URL a rail page fetches, links or redirects to carries it. Normally derived from a * `walletOrigin` that includes the path. Absent ⇒ "" (served at the root). */ basePath?: string; } /** The resolved context each rail receives (every required seam present). */ export interface CeremonyContext { verificationStore: VerificationStore; orderStore: CeremonyOrderStore; catalog: CeremonyCatalog; completion: CompletionSeam; signingKey: string; origin: (req: RequestLike) => Origin; settlement?: SettlementSeam; /** The external verifier/processor, when the host configured one (008). Absent ⇒ * the delegated rail is inert and no delegated route exists. */ verifier?: DelegatedVerifier; /** FR-007: when true, `resolveOrder` may reconstruct from a verified Cart Mandate * with no store read (absent/false — store is the source of truth). `mountCeremony` * always sets it; optional here so a hand-built context literal need not. */ statelessOrders?: boolean; /** Stable reader identity the rails present (absent ⇒ per-request self-signed). */ readerIdentity?: ReaderIdentity; /** The gate's credential registry (007) — the rails read it to serve a custom * credential's own request/verify. Absent when no CredentAgent registry was passed. */ credentialRegistry?: ReadonlyMap; /** Per-order resolved policy (#59 finding 2 / PR #131) — `mountCeremony` uses it to scope the * completion sweep to THIS order's policy. Absent ⇒ the sweep stays registry-wide (fail-closed). */ orderPolicies?: ReadonlyMap; /** Build the buyer's return-to-checkout URL for an order (absent ⇒ the rail default). */ returnUrl?: (orderId: string) => string; /** The store's order-status record URL for an order (absent ⇒ no "Order record" link). */ statusUrl?: (orderId: string) => string; /** Host brand for the ceremony pages (absent ⇒ the built-in look). Never brands the footer. */ branding?: Branding; /** Hand the presented DeviceResponse back to the page for inspection (absent ⇒ off). */ inspectPresentations?: boolean; /** The browser-visible path prefix every page URL carries ("" at the root). */ basePath?: string; } /** A rail attaches its routes to the host app given the resolved context. */ export type RailRegistrar = (app: CeremonyApp, ctx: CeremonyContext) => void; /** * Read + validate the injected seams, build the CeremonyContext, and register * every rail's routes. Throws on a missing required seam (CT2). Seams may arrive * via `options` OR `app.locals.credentagent` — options win. */ export declare function mountCeremony(app: CeremonyApp, options?: Partial): CeremonyContext; /** * Shared order resolution + re-pricing (T003a). Resolve a created order by id, * then RE-PRICE it from the catalog — the displayed and bound amounts come from * the catalog, never the id/token (CT3, invariants 2/3). A tampered or unknown id * resolves to `null` (the rail refuses). * * FR-007 (opt-in `statelessOrders`): when the host has no shared order store, a * VERIFIED Cart Mandate carried on the request is the order transport — pass it as * `opts.cartMandate` and the created order is reconstructed from it with NO store * read, so a created order survives an instance split (US3). It stays fail-closed: * a forged / tampered / replayed (wrong-order) / expired mandate does not resolve * an order, and the catalog STILL reprices (the mandate carries the items, never * the price — invariant 2). Off (default), the store is the source of truth and any * mandate is an additive integrity envelope checked at completion, not a transport. */ export declare function resolveOrder(ctx: CeremonyContext, orderId: string | undefined | null, opts?: { cartMandate?: unknown; }): Promise;