import { type IntentBoundsInput } from "./bounds.js"; import { type DelegateHashAlg, type DelegateJwk, type MandateContent } from "./mandates.js"; import type { TrustLevel } from "../../types.js"; /** Single-use nonce ledger: `consume` records a nonce and returns true only the FIRST * time (false on replay). In-process (grants are process-local); a multi-instance * deploy would back this with a shared store, like the grant records themselves. */ export interface NonceGuard { consume(nonce: string): boolean; } /** A trivial in-memory NonceGuard (a Set). */ export declare function memoryNonceGuard(): NonceGuard; /** What a verify backend establishes about a parsed presentation: whether the holder * binding is proven, at what trust level, and by whom. The gate re-checks bounds + * the required claim itself either way. */ export interface IntentTrustVerdict { ok: boolean; reason?: string; /** How strongly bound, AS REPORTED BY THE BACKEND (relayed verbatim; never upgraded). */ trustLevel: TrustLevel; /** Who verified — "gate" (in-gate) or an external verifier's id. */ verifiedBy: string; /** Disclosed issuer-signed claims, for the gate's own required-claim check. */ disclosed?: Record; /** The credential type that signed (SD-JWT `vct`). */ credentialType?: string; /** The KB-JWT's `delegate_payload` claim, verbatim — an array of RFC 9901 array-element * digests (`{"...": ""}`) since Delegate SD-JWT §7.1. The gate recomputes the * digests from its OWN grant record and requires every one of them to be present here. */ delegatePayload?: MandateContent[]; } /** The verify seam: given the wallet's SD-JWT presentation and the audience/nonce the gate * issued, decide trust. Swappable per FR-4 (in-gate default; delegated later). * * CONTRACT — a backend MUST verify the holder's key-binding signature itself, against the key * the credential commits to in `cnf`, and MUST check the audience and nonce (the in-gate * default does all three). The gate re-checks the bounds and the mandates regardless of * backend, but the PROOF-OF-SIGNATURE travels WITH the backend: "delegation moves trust, not * binding" must NOT be read to exclude the signature. A permissive stub returning * `{ ok: true }` would accept a presentation nobody signed, so a real delegated verifier is * responsible for that check. */ export type IntentVerifyBackend = (args: { /** The compact SD-JWT presentation from `vp_token`. */ sdjwt: string; /** Who the key binding must be addressed to. */ audience: string; /** The nonce this ceremony issued. */ nonce: string; }) => Promise; /** The v1 in-gate backend: verify the holder's key-binding signature in-process. */ export declare const inGateBackend: IntentVerifyBackend; export type IntentVerifyResult = { ok: true; boundsHash: string; signedAt: string; trustLevel: TrustLevel; verifiedBy: string; /** The credential type that signed. An SD-JWT `vct` since spec 014 (was an mdoc doctype). */ credentialType: string; /** The AP2 Mandate Content the human authorized — the grant's record of what was signed. */ mandates: MandateContent[]; /** The signed permission: the wallet's presentation and the `delegate` disclosures it signed * over — what an agent holding the key the mandates name spends (spec 014, FR-5). */ intent: { presentation: string; disclosures: string[]; }; } | { ok: false; reason: string; }; /** * Verify a device-signed Intent Mandate presentation and return typed plain data. * * `bounds` is the grant's CURRENT bounds, read from the server's own record — /verify * re-derives boundsHash from it and requires equality with the sealed value. */ export declare function verifyIntentPresentation(args: { result: { protocol?: string; data?: unknown; }; readerContextToken: string; secret: string; /** The grant's bounds from the SERVER's record (never the client). */ bounds: IntentBoundsInput; origin: { origin: string; }; /** The store's public URL — `walletOrigin`, path included — which names the merchant the * mandates bind to (`merchantFor`, the same id the store's own checkouts carry). Separate * from `origin`, the bare origin the wallet presentation is bound to: a store served under * a path is a different merchant from its host's root (#331). Required — no default could * know the path, and guessing the root would let a sibling store accept the permission. */ merchantUrl: string; nonceGuard: NonceGuard; /** The agent's public key, from the SERVER's grant record — the `cnf` the mandates name. */ delegate: DelegateJwk; /** The agent holds that key (`grants.create({ agentKey })`): this permission is handed to the * agent and spent at a merchant, whose chain verifier requires the wallet's hop typed * `kb+sd-jwt+kb` — so this check requires it too. From the SERVER's grant record. */ agentHeld?: boolean; /** The absolute expiry used when the request was built, epoch seconds. */ mandateExp: number; /** The product ids the grant may buy, re-resolved from the SERVER\'s record. */ allowedSkus: string[]; /** The digest algorithm `/request` asked for — must match, or the digests cannot line up. */ hashAlg?: DelegateHashAlg; /** Trust backend (FR-4). Defaults to the in-gate key-binding check. */ backend?: IntentVerifyBackend; }): Promise;