import type { CeremonyOrder } from "../ceremony/types.js"; import type { Amount, CheckoutConstraint, Merchant, PaymentConstraint, UcpCheckout, UcpLineItem } from "./types.js"; /** * The merchant identity a mandate binds to. Derived from the gate's own public URL. * * The id is the host PLUS the base path (#331): two stores mounted on one host at `/coffee` * and `/wine` are different merchants, and a permission signed for one must not be spendable * at the other. A store at the root keeps the bare host, so mandates already signed for it * still match. * * `name` is REQUIRED by `types/merchant.json`, so a caller that has no display name gets the * id — the one string that is true about this merchant whatever else we know. */ export declare function merchantFor(origin: string, name?: string): Merchant; /** * `CeremonyOrder` → UCP Checkout. * * The discount becomes its own `totals` entry rather than being folded into the subtotal, * because invariant 3 requires the line sum, the discount and the payable total to stay * separately checkable. A reader that can only see the final number cannot tell a * legitimate 10% off from a tampered one. * * Amounts in `totals` are plain integers in the checkout's currency's minor units, per * `ucp/types/total.json`: the currency lives once on the checkout, and repeating it per * entry is how two of them end up disagreeing. */ export declare function checkoutFromOrder(order: CeremonyOrder, merchant: Merchant): UcpCheckout; /** * Why {@link checkLineItems} refused a cart. Whose mistake it is decides the answer: * - `"quantity"` — a line's quantity is not a whole number of at least 1. The quantity is what the * agent asked for, so this is a bad request (a 400). * - `"price"` — an item's price is not a whole number of minor units above 0, and * - `"line-total"` — a line's `total` is not its price × quantity. Both come from your own catalog * and quote code, so they are your bug (a 500), not the agent's. * - `"malformed"` — no `line_items` list, or a line with no item id: the cart is not a UCP cart. */ export type LineItemsRefusal = "quantity" | "price" | "line-total" | "malformed"; /** {@link checkLineItems}'s answer. `detail` is for logs, never for a decision — branch on `code`. */ export type LineItemsCheck = { ok: true; } | { ok: false; code: LineItemsRefusal; detail: string; }; /** * What every cart line needs before anything adds it up: an item id, a whole quantity of at * least 1, a unit price that is a whole number of minor units above 0, and a `total` entry equal * to price × quantity — the number the cart total is actually summed from. * * One rule for the store that quotes a cart (`Ap2Issuer.signCheckout`) and the store that verifies * one (`verifyDelegatedPurchase`). A line of quantity −1 is skipped by the `checkout.line_items` * limit yet still subtracted from the total — "1 coffee and −1 tea" would fit every limit and * match an honest catalog's price (#286). So such a line is refused, never read. * * Exported so a store can check a cart built from an agent's request and answer it by `code`, * rather than catch `signCheckout`'s throw. */ export declare function checkLineItems(lines: readonly UcpLineItem[]): LineItemsCheck; /** The `total` entry — the one number a payment must match. Throws if the cart has none. */ export declare function totalOf(checkout: UcpCheckout): Amount; /** * Re-derive the payable total from the line items and the discount entry. * * This is the AP2-side expression of invariant 3, and it is deliberately a separate * function from {@link totalOf}: one reads what the cart CLAIMS, the other computes what * the cart's own parts ADD UP TO. Code that compares them catches a tampered total; code * that only ever reads the claim does not. */ export declare function rederiveTotal(checkout: UcpCheckout): Amount; export interface GrantBoundsInput { /** Merchant id the grant is scoped to. */ merchant: string; /** Cumulative budget, major units (the gate's historical representation). */ budget: number; /** Per-purchase ceiling, major units. */ perSpend: number; currency: string; /** Item ids the grant may buy. Required: an open checkout with no line_items buys nothing. */ skus: string[]; /** Additional merchants, when a grant names more than one (#156's enforcement already allows it). */ alsoAllowed?: Merchant[]; } /** * Constraints for `mandate.checkout.open.1`. MUST include `checkout.line_items`. * * `checkout.line_items` is a list of REQUIREMENTS, not bare ids: each one names the items that * satisfy it and how many are needed. A grant's allow-list is the simplest case of that, so each * sku becomes a one-item requirement. The gate's catalog keys ARE its product ids and carry no * separate display name, so `title` is the id — the only string that is true here. Anything * richer ("one coffee, either size") is a later feature, not a translation. */ export declare function checkoutConstraintsFromGrant(g: GrantBoundsInput, origin: string): CheckoutConstraint[]; /** * Constraints for `mandate.payment.open.1`. MUST include `payment.reference`, which is what * ties the two halves of a grant together: the payment authority is only valid for the * checkout authority whose digest it names. */ export declare function paymentConstraintsFromGrant(g: GrantBoundsInput, origin: string, openCheckoutDigest: string): PaymentConstraint[];