import type { Credential, TrustLevel, VerificationStore } from "../types.js"; import type { CeremonyCatalog, CompletionInput, CompletionResult, GateOutcome } from "./types.js"; import { type DrawVerifier } from "./mandate.js"; import type { RevocationStore } from "./revocation.js"; import { type ProofEntry } from "./proofs.js"; export interface SettlementRecordLike { network: string; txId: string; status: string; [k: string]: unknown; } export interface CompletedRecord { orderId: string; mandateId: string; amount: number; currency: string; method: string; instrument?: unknown; gates: GateOutcome[]; completedAt: string; settlement?: SettlementRecordLike; /** The authorizing Intent Mandate id, when this order completed via a delegated draw * (005) — the audit link from an unattended completion back to its grant. */ delegationId?: string; /** How strongly this completion was trusted, RELAYED from an external verifier's verdict * (008). `"issuer-verified"` only when a real trust anchor produced it; the built-in rails * omit this (their honesty level is the manifest's `presence-only-demo`). Never synthesized * here — the gate only records a level it received. */ trustLevel?: TrustLevel; /** What was proven for this order — the credential proofs, then the payment's — each with * its own trust_level (the order proof receipt). Absent on records written before it. */ proofs?: ProofEntry[]; } export interface CompletedOrderStore { read(orderId: string): CompletedRecord | undefined | Promise; write(record: CompletedRecord): void | Promise; } export interface ClearableCart { clear(): void | Promise; } export interface CompletionContext { catalog: CeremonyCatalog; verificationStore: VerificationStore; /** Idempotent completed-order store, keyed by order id. */ records: CompletedOrderStore; /** Cart to empty on completion (optional). */ cart?: ClearableCart; /** Optional demo-mode settlement; throwing GATES completion (no record). */ settle?: (order: CompletionInput["order"]) => Promise; /** Optional HMAC key for Cart Mandate verification. When set AND the input carries a * `cartMandate`, completion verifies it (signature + order-id binding + expiry) * before re-pricing. Absent ⇒ the cart-mandate check is skipped (additive). */ signingKey?: string; /** Optional revocation + committed-draw store (005). REQUIRED when the input carries a * `draw`: its absence is fail-closed (a draw without a store to check it is refused). * Consulted fail-closed (a throwing read refuses) and holds the atomic single-use consume. */ revocation?: RevocationStore; /** Optional signer-agnostic draw verifier (defaults to ES256/P-256). */ verifyDraw?: DrawVerifier; /** Injectable clock for the draw window check (testability). */ now?: () => number; /** * The gate's in-process credential registry (id → Credential), populated by * `requirements()` and injected by `mount()` (007). When present, completion * enforces EVERY applicable custom `gate()` credential — re-deriving applicability * from the RE-PRICED order (invariant 2) and refusing any not in the order's * `verifiedGates` (invariant 1). Reserved built-ins are excluded (they keep their * own enforcement). Absent ⇒ the custom-gate sweep is skipped (additive). */ credentialRegistry?: ReadonlyMap; } export declare function completeOrder(input: CompletionInput, ctx: CompletionContext): Promise;