import type { CeremonyOrder } from "./types.js"; import type { Origin } from "./origin.js"; export declare const DEFAULT_LOYALTY_DISCOUNT_PCT = 10; export interface BindingFields { amount: number; currency: string; payee: { id: string; name: string; }; orderId: string; } export declare function buildBindingFields(order: CeremonyOrder, origin: Origin, payeeName?: string): BindingFields; export interface VerifiedAuthenticator { credentialID: string; userVerified: boolean; credentialDeviceType: "singleDevice" | "multiDevice"; credentialBackedUp: boolean; } export interface PasskeyMandate { type: "ap2.PaymentMandate"; version: "0.1-mock"; id: string; issuedAt: string; expiresAt: string; issuer: string; subject: { credentialID: string; }; cart: CeremonyOrder; payment: { instrument: string; instrumentReference: string; network: string; amount: number; currency: string; }; userAuthorization: { type: "webauthn.assertion"; credentialID: string; userVerified: boolean; hardwareBacked: boolean; deviceType: string; backedUp: boolean; rpID: string; origin: string; ceremonyTimestamp: string; }; payeeId: string; trust_level: "presence-only-demo"; signature: { alg: "MOCK-DEV-SIGNER"; value: string; note: string; }; } export declare function buildPasskeyMandate(args: { order: CeremonyOrder; authenticator: VerifiedAuthenticator; origin: Origin; issuer?: string; payeeName?: string; }): PasskeyMandate; export interface GateResult { gate: string; pass: boolean; detail: string; } export declare function runGates(mandate: PasskeyMandate, opts?: { loyaltyDiscountPct?: number; }): GateResult[]; import { webcrypto } from "node:crypto"; import { type Refusal } from "./refusals.js"; type CryptoKey = webcrypto.CryptoKey; /** The delegate key K_s — the ONLY key that may sign draws — as a public JWK. */ export interface DelegateJwk { kty: "EC"; crv: "P-256"; x: string; y: string; } /** The user-sealed Intent Mandate bounds (intent-bounds-schema-draft.md: AP2 intent * fields + EUDI SCA TS12 `PaymentTransaction` amounts). Content-addressed: `intentId` * transitively commits to every other field, delegate key and honesty labels included. */ export interface IntentBounds { type: "credentagent.IntentBounds/v0"; intentId: string; /** The human-readable mandate the user actually approved (AP2 natural-language field). */ naturalLanguageDescription?: string; /** Merchant allowlist; absent/empty ⇒ any suitable merchant (multi-merchant is native under B). */ merchants?: string[]; /** SKU/GTIN scope allowlist (checked by the wallet/rail; the seam checks merchants). */ skus?: string[]; currency: string; /** Per-draw cap (TS12 max_amount) — an absolute ceiling, tolerance 0. */ maxAmount: number; /** Cumulative cap (TS12 total_amount) across all committed draws. */ totalAmount: number; /** Presence-required threshold: a draw above it needs a fresh human tap (step-up ≤ cap). */ stepUpOver?: number; intentExpiry?: string; notBefore?: string; delegate: DelegateJwk; /** Credentials the agent MAY present under this grant. An identity claim is never something * the AGENT presents — an age proof rides `ageProof` below, captured from the human's own * wallet at approval time. */ mayPresent?: string[]; /** The human's age claim, proved at approval time and sealed into these bounds (#172). Absent * ⇒ an age-restricted draw steps up exactly as before. Covered by `intentId`. */ ageProof?: SealedAgeProof; /** The human's loyalty membership, proved at approval time and sealed into these bounds (#172). * Absent ⇒ every draw prices at full catalog price, exactly as before. Covered by `intentId`, * so the rate cannot move after the human approved it. */ membershipProof?: SealedMembershipProof; /** Honesty axes (constitution VII v1.1.0): when consent happened / how strongly bound. */ presence: "delegated" | "delegated-demo"; trust_level: string; subject?: string; } /** * An age claim the human proved AT APPROVAL TIME, sealed into the intent (issue #172). * * The delegation rule this reverses: age used to be non-delegable, full stop — an agent could * never buy an age-restricted item, so a grant scoped to a category of 21+ goods could spend * nothing and the human had no way to unblock it. The reversal is narrow: the human proves age * ONCE, on their own phone, with their own wallet, at the exact moment they grant the authority. * Nothing is delegated to the agent — the identity claim is the human's, captured while they are * present, and it rides the grant rather than the agent. * * Because `sealIntent` content-addresses the WHOLE bounds object into `intentId`, this field is * covered by the grant's identity: it cannot be added, raised, or extended after the fact * without producing a different grant. * * HONESTY: `trust_level` is "presence-only-demo" — the wire crypto behind the proof is real * (signed OpenID4VP request, sealed nonce, JWE/HPKE decrypt, ISO-mdoc parse) but there is NO * issuer trust anchor yet, so a self-crafted mdoc would pass. This is DISCLOSURE + BINDING, not * a real safety control, until issuer-verified trust lands (#14). */ export interface SealedAgeProof { /** The threshold actually disclosed (`age_over_N === true`). A draw whose order demands a * HIGHER threshold still steps up — an 18+ proof never opens a 21+ item. */ provenAge: number; /** When the ceremony ran (ISO 8601) — the audit line on the sealed record. */ verifiedAt: string; /** The underlying credential's own validity horizon (ISO 8601). Past ⇒ fail closed. UNSET * today: the mdoc's validity window is not parsed yet, so nothing may claim one (#14). */ expiresAt?: string; /** Honesty axis — how strongly the claim is bound. "presence-only-demo" in v0.1. */ trust_level: string; } /** * Does a sealed age proof cover an order that demands `requiredAge`? The ONE definition, read by * the delegated-draw branch of `completeOrder` and by any host pre-check that wants to answer the * same question before spending (the storefront's `spend-from-grant`). * * FAIL-CLOSED on every axis: no proof, a malformed/non-finite threshold, a threshold BELOW what * the order demands, or a credential whose stated validity has passed. `requiredAge` must always * be re-derived from the catalog-priced lines — never read off a token or a request body. * `nowMs` is epoch milliseconds (the same clock seam `checkDraw` reads). */ export declare function ageProofCovers(proof: SealedAgeProof | undefined, requiredAge: number, nowMs?: number): boolean; /** * A loyalty membership the human proved AT APPROVAL TIME, sealed into the intent (issue #172). * * Same shape of consent as {@link SealedAgeProof}: the credential is the HUMAN's, presented by * THEIR wallet while they are present, and the agent never holds or presents one. Where the age * proof UNLOCKS items, this one LOWERS the price of every purchase made under the grant. * * `discountPct` is sealed here rather than read from config at spend time on purpose. The rate is * part of what the human approved ("10% off"), so it must be tamper-evident — and BOTH sides of * the amount binding read this one number: the draw signer prices with it, and `completeOrder` * re-prices with it. A rate that could move between those two moments would break invariant 3 * (the line sum, the order total and the signed amount must agree on every path). * * HONESTY: `trust_level` is "presence-only-demo" — real wire crypto, no issuer trust anchor yet. */ export interface SealedMembershipProof { /** The membership id the wallet disclosed — a real, non-empty one (invariant 5). */ membershipNumber: string; /** The percentage off, as approved and shown to the human. Sealed; never re-read from config. */ discountPct: number; /** When the ceremony ran (ISO 8601) — the audit line on the sealed record. */ verifiedAt: string; /** Honesty axis — how strongly the claim is bound. "presence-only-demo" in v0.1. */ trust_level: string; } /** One draw — the per-purchase spend against an intent, signed by the delegate key. */ export interface Draw { type: "credentagent.Draw/v0"; intentId: string; paymentMandateId: string; merchant: string; amount: number; currency: string; /** The PSP-issued settlement transaction id — single-use per intent (replay guard). */ pspTransactionId: string; presentments?: string[]; /** b64url ES256 signature by the delegate key over the canonical draw (sans this field). */ signature?: string; } /** A committed (already-drawn) spend, as the RevocationStore records it. */ export interface CommittedDraw { amount: number; pspTransactionId: string; } /** Canonical JSON (stable, recursive key sort) — the exact bytes hashed + signed. Any * edit to any field changes these bytes, so a signature/hash covers the whole document. */ export declare function canonical(value: unknown): string; /** intentId = "int_" + b64url(SHA-256(canonical(bounds \ intentId))) — no circularity, * and it transitively commits to EVERY other field. */ export declare function contentAddressId(bounds: object): Promise; export declare function sealIntent(boundsWithoutId: Omit): Promise; /** Generate a delegate keypair K_s (ES256 / P-256). The bounds carry the PUBLIC JWK. */ export declare function generateDelegate(): Promise<{ privateKey: CryptoKey; delegate: DelegateJwk; }>; /** Sign a draw with the delegate key over its canonical form (any prior signature stripped). */ export declare function signDraw(draw: Draw, privateKey: CryptoKey): Promise; /** Signer-agnostic verification seam: the default verifies ES256/P-256 (the wallet * server's K_s — the Option-B target); hosts may inject e.g. an HMAC verifier. */ export type DrawVerifier = (draw: Draw, delegate: DelegateJwk) => Promise; export declare const verifyDrawEs256: DrawVerifier; export interface CheckDrawContext { now?: number; priorDraws?: CommittedDraw[]; verify?: DrawVerifier; } export interface DrawVerdict { ok: boolean; refusals: Refusal[]; } /** THE DETERMINISTIC GATES: is this draw in-bounds? Pure and total — injected `now` / * `priorDraws`, never throws, accumulates typed refusals (no first-fail) so the surface * can act on the full picture. This is defense-in-depth's inner ring: the completion * seam re-runs it server-side on EVERY path (invariant 1). */ export declare function checkDraw(intent: IntentBounds, draw: Draw, ctx?: CheckDrawContext): Promise; export {};