import type { PublicJwkP256 } from "./keys.js"; import { type AnyMandate, type CheckoutMandate, type UcpCheckout, type Vct } from "./types.js"; /** Why a mandate was refused. Distinct from the draw-level `RefusalCode` on purpose: * these are WIRE failures, and collapsing them into business refusals hides bugs. */ export type MandateRefusalCode = "malformed" | "signature" | "issuer" | "unexpected-type" | "expired" | "not-yet-valid" | "key-binding" | "audience" | "nonce" | "checkout-unbound"; export interface MandateRefusal { ok: false; code: MandateRefusalCode; detail?: string; } export interface MandateVerdict { ok: true; mandate: T; /** Present when the token carried a key-binding hop. */ keyBound?: { aud: string; nonce: string; }; } export type VerifyResult = MandateVerdict | MandateRefusal; export interface VerifyOptions { /** The issuer key the signature must verify against. Its `kid` (as `mount()` publishes it, * or as {@link publicJwkFromDidDocument} returns it) also names the expected issuer. */ publicJwk: PublicJwkP256; /** The DID the mandate's `iss` must equal. Defaults to the DID in `publicJwk.kid`; one of * the two is required, because a signature that verifies says nothing about who CLAIMS to * have issued it. */ issuer?: string; /** Refuse anything whose `vct` is not this. Omit only when routing by type afterwards. */ expect?: Vct; /** Required when the token is key-bound: who the KB-JWT must be addressed to. */ audience?: string; /** * Required when the token is key-bound: the nonce WE issued for this presentation. * * This checks the nonce MATCHES; it does not remember it. The same presentation verifies * again if you pass the same nonce again — making a nonce single-use (consume it from your * store on first success) is the caller's job, per security invariant 6. */ nonce?: string; /** * Read a holder-bound mandate (one whose payload names a `cnf` key) WITHOUT a key binding — * i.e. as a bearer token. Off by default: such a mandate means something only when its holder * proves possession, so verifying it unbound would let anyone holding a copy pass. Opt in by * name for the cases that genuinely need it, such as the issuer inspecting what it minted. */ allowUnbound?: boolean; /** Epoch ms. Injectable so expiry is testable without faking the global clock. */ nowMs?: number; } /** * Verify one AP2 mandate. * * Fail-closed on every axis: an unparseable token, a bad signature, a disallowed `alg`, an * issuer that is not the key's, a wrong type, a missing or passed expiry, a key-binding hop * we cannot check, or an audience/nonce mismatch all refuse. There is no "valid but * unverified" outcome, because callers reliably mistake one for the other. */ export declare function verifyMandate(token: string, opts: VerifyOptions): Promise>; /** * Open the Checkout a Checkout Mandate wraps, re-checking the wrapper's own binding. * * The mandate carries both `checkout_jwt` and `checkout_hash`; a caller that reads the * line items straight out of the JWT without re-hashing has trusted an unbound blob. This * function is the only supported way in, so that mistake is not available. */ export declare function openCheckoutPayload(mandate: CheckoutMandate, publicJwk: PublicJwkP256, digest: (token: string) => string): Promise<{ ok: true; checkout: UcpCheckout; } | MandateRefusal>; /** Read a token's `vct` without verifying it — for routing only, never for a decision. */ export declare function peekVct(token: string): Vct | undefined;