import type { PublicJwkP256 } from "../keys.js"; import { type OpenCheckoutMandate, type OpenPaymentMandate, type PaymentInstrument, type PaymentMandate, type UcpCheckout } from "../types.js"; import { type AgentKey } from "./agent-key.js"; import { type Spent, type Violation } from "./constraints.js"; import { type ChainRefusalCode } from "./verify.js"; /** What the agent hands the merchant: one chain per mandate type. */ export interface DelegatedPurchaseProof { checkout: string; payment: string; } /** * The permission an agent holds: the wallet's presentation and the two open mandates it signed. * Plain data — `JSON.stringify` it to store it, and pass the parsed value back to * {@link DelegatedIntent.fromWalletPresentation}: what it serializes to is exactly what that takes. * * Holding it is not a secret in itself: spending it needs the {@link AgentKey} its mandates name, * which this object never sees until `spend` is called with it. */ export declare class DelegatedIntent { readonly presentation: string; readonly disclosures: { checkout: string; payment: string; }; private constructor(); /** From what the intent-sign rail holds after the ceremony: `vp_token` and the request's disclosures. */ static fromWalletPresentation(args: { presentation: string; disclosures: readonly string[]; }): DelegatedIntent; /** The open payment mandate — what the agent may spend. UNVERIFIED: read it to plan, not to decide. */ get openPayment(): OpenPaymentMandate; /** The open checkout mandate — what the agent may buy. UNVERIFIED, like `openPayment`. */ get openCheckout(): OpenCheckoutMandate; /** Serializes to `fromWalletPresentation`'s own input, so storing and loading is one door. */ toJSON(): { presentation: string; disclosures: string[]; }; /** This permission's id — the same one a merchant's verdict reports as `permissionId`. */ get permissionId(): string; /** * Spend the permission on ONE purchase: sign a closed checkout mandate naming the merchant's * checkout, and a closed payment mandate bound to it, each as the agent's hop on its chain. * * The payee and the amount are the cart's own — its merchant and its total — so the agent names * only how it pays. `audience` and `nonce` are the merchant's. They are what keep this proof from * being replayed at another store, or twice at this one. */ spend(args: { /** The key the permission names in `cnf` — the agent's own, from `AgentKey`. */ agentKey: AgentKey; /** The merchant-signed UCP Checkout (`Ap2Issuer.signCheckout`). */ checkoutJwt: string; /** How the agent pays — the one fact of the payment the cart does not already state. */ instrument: PaymentInstrument; audience: string; nonce: string; }): Promise; } export type PurchaseRefusalCode = ChainRefusalCode | "trust" | "splice" | "unexpected-type" | "no-checkout-key" | "checkout-unbound" | "payment-unbound" | "payee" | "constraint" | "amount" | "price"; export interface PurchaseRefusal { ok: false; code: PurchaseRefusalCode; detail: string; /** Present for `constraint`: every limit the purchase broke. */ violations?: Violation[]; } export interface PurchaseVerdict { ok: true; /** * This permission's stable id — the same for every purchase under it, at every merchant. Key what * you record as spent on it; `spent` is called with it. */ permissionId: string; checkout: UcpCheckout; payment: PaymentMandate; open: { checkout: OpenCheckoutMandate; payment: OpenPaymentMandate; }; /** No issuer trust anchor yet (#14): the credential's certificate is self-minted. */ trust_level: "presence-only-demo"; } export interface VerifyPurchaseOptions { /** * REQUIRED, and the only value there is: `"presence-only-demo"`. * * The credential at the root of the chain is checked against the certificate it carries itself, * and nothing anchors that certificate to a real issuer yet (#14). So an agent can mint its own * "permission", with any limits it likes, and it verifies. The limits are enforced; nothing proves * a person set them. Saying so here is the opt-in — demo use only, never a real safety control. */ trust: "presence-only-demo"; /** This merchant — who the agent's hops must be addressed to. */ audience: string; /** The nonce this merchant issued for this purchase. Consuming it is yours (invariant 6). */ nonce: string; /** The key that signed the checkout — this merchant's (`credentagent.ap2.checkoutPublicJwk`). */ checkoutKey: PublicJwkP256; /** * What THIS merchant already spent under the permission. Required by budget / recurrence limits. * * Pass a function and it is called with the VERIFIED `permissionId`, after the chains check out — * so you look your ledger up by an id the signatures vouch for, never by bytes read from an * unverified token. A budget holds per merchant: one permission works at every store it names * (each checks carts against its own `checkoutKey`), and each store sees only its own spending. */ spent?: Spent | ((permissionId: string) => Spent | Promise); /** Your catalog's total for this cart, in minor units. The price authority — never the proof. */ price: (checkout: UcpCheckout) => number | Promise; nowMs?: number; } /** * Verify a delegated purchase. Fail-closed: every chain link, both chains resting on the same * permission, the checkout being this merchant's, the payment paying exactly that checkout, every * limit the person set, and the catalog's own price. */ export declare function verifyDelegatedPurchase(proof: DelegatedPurchaseProof, opts: VerifyPurchaseOptions): Promise;