import type { KeyObject } from "node:crypto"; import { type GateSigningKey, type PublicJwkP256 } from "./keys.js"; import { type Amount, type CheckoutConstraint, type Cnf, type Merchant, type PaymentConstraint, type PaymentInstrument, type UcpCheckout } from "./types.js"; /** Default mandate lifetime. Short: a mandate is evidence of a moment, not a standing grant. */ export declare const DEFAULT_MANDATE_TTL_MS: number; /** A minted mandate: the compact SD-JWT, plus the digest other mandates bind to. */ export interface IssuedMandate { /** Compact SD-JWT serialization — what travels on the wire. */ token: string; /** base64url `sd_hash` of `token`. The value a sibling mandate references. */ digest: string; } export interface IssuedCheckout extends IssuedMandate { /** The merchant-signed Checkout JWT the mandate wraps — needed to bind a payment to it. */ checkoutJwt: string; /** base64url hash of `checkoutJwt`. A Payment Mandate's `transaction_id`. */ checkoutHash: string; } export interface IssueCheckoutArgs { checkout: UcpCheckout; ttlMs?: number; } export interface IssuePaymentArgs { /** The Checkout Mandate's `checkoutHash` — the binding to the cart being paid for. */ transactionId: string; payee: Merchant; amount: Amount; instrument: PaymentInstrument; /** * Ceremony evidence (the WebAuthn assertion, the mdoc presentation). AP2 models this as * risk signals collected by the trusted surface — which is exactly what it is. It is * NOT the mandate's signature, and nothing downstream may treat it as one. */ riskData?: Record; executionDate?: string; ttlMs?: number; } export interface IssueOpenArgs { constraints: C[]; /** REQUIRED by AP2 on both open mandates. The holder key that authorized this. */ cnf: Cnf; /** Absolute expiry (epoch seconds). Open mandates outlive a ceremony, so callers set it. */ exp: number; } export interface IssueOpenPaymentArgs extends IssueOpenArgs { payee?: Merchant; amount?: Amount; instrument?: PaymentInstrument; } export interface Ap2IssuerOptions { /** * The merchant key carts are quoted with (spec 014, FR-6) — distinct from the mandate key, its * `kid` ending `#merchant-checkout-key`. Absent ⇒ one is generated, flagged `ephemeral`. */ checkoutKey?: GateSigningKey; /** * This merchant, as a permission names it — what `signCheckout` puts in a cart that names none. * `CredentAgent` passes the one for its `walletOrigin`, the same identity a grant's mandates carry. */ merchant?: Merchant; } /** * Mints AP2 mandates with the gate's key, and signs the carts it quotes with the merchant's. * * ```ts * const issuer = new Ap2Issuer(key, { checkoutKey }); * const checkout = await issuer.checkout({ checkout: ucp }); * const payment = await issuer.payment({ transactionId: checkout.checkoutHash, ... }); * ``` */ export declare class Ap2Issuer { #private; constructor(key: GateSigningKey, opts?: Ap2IssuerOptions); /** The mandate key's public half — what `mount()` publishes and what `verifyMandate` imports. */ get publicJwk(): PublicJwkP256; /** * The checkout key's public half — what a cart this merchant quoted verifies against * (`verifyDelegatedPurchase({ checkoutKey })`, `openCheckoutPayload`). Published beside the * mandate key in the DID document: `/.well-known/did.json` for a root store, * `/did.json` for a store served under a path. */ get checkoutPublicJwk(): PublicJwkP256; /** This merchant, as a delegated permission names it in `checkout.allowed_merchants`. */ get merchant(): Merchant | undefined; get issuer(): string; /** * The merchant-signed UCP Checkout — what a merchant quotes to an agent, and what the agent's * closed checkout mandate then names by `checkout_jwt` and its hash. Signed with the CHECKOUT * key, never the mandate key: verify it against {@link checkoutPublicJwk}. * * The cart's `merchant` is this merchant. Leave it out and it is filled in. A cart naming * another merchant is refused, because no permission would ever match it. * * Every line must be a real purchase: a quantity that is a whole number of at least 1, an item * price that is a whole number of minor units above 0, and a line total of price × quantity. * A cart with any other line is refused — a line of * −1 tea would lower the total without breaking any limit (#286). * * @throws Error when a line is not a real purchase, or the cart names another merchant. Check a * cart built from an agent's request with `checkLineItems` first, and answer by its `code`. */ signCheckout(checkout: UcpCheckout): string; /** `mandate.checkout.1` — "I authorize THIS checkout." */ checkout(args: IssueCheckoutArgs): Promise; /** `mandate.payment.1` — "I authorize THIS payment", bound to a checkout. */ payment(args: IssuePaymentArgs): Promise; /** * `mandate.checkout.open.1` — "I authorize FUTURE checkouts within these constraints." * * SIGNED BY THE GATE. Use it when the gate itself is the party granting the authority. When the * PERSON grants it on their phone, the wallet signs the open mandates instead — the intent-sign * rail builds that content with `openMandatesForGrant` and never signs it with this key. */ openCheckout(args: IssueOpenArgs): Promise; /** `mandate.payment.open.1` — "I authorize FUTURE payments within these constraints." */ openPayment(args: IssueOpenPaymentArgs): Promise; } /** * Append a key-bound delegation hop: the holder signs a KB-JWT over the token, proving * possession of the key the mandate's `cnf` names. * * `nonce` and `aud` are what stop a hop being replayed somewhere else — a caller that * passes a constant for either has defeated the point, so neither is optional. */ export declare function presentWithKeyBinding(args: { token: string; holderKey: KeyObject; aud: string; nonce: string; }): Promise;