import type { CeremonyCatalog } from "./ceremony/types.js"; import { type RevocationStore } from "./ceremony/revocation.js"; import { generateDelegate, type DelegateJwk, type IntentBounds, type SealedAgeProof, type SealedMembershipProof } from "./ceremony/mandate.js"; import { type CompletionContext } from "./ceremony/completion.js"; import type { RefusalCode, RefusalRetryable } from "./ceremony/refusals.js"; /** The delegate private key type, without naming the DOM `CryptoKey` global. */ type DelegateKey = Awaited>["privateKey"]; /** A catalog entry: a bare price, or a price plus an age restriction, a category and/or a * display name (categories feed the grants `allow` bounds — what a delegated agent may buy; * `name` is what the approve page calls the product instead of its bare sku id — #172). */ export type CatalogEntry = number | { price: number; minAge?: number; category?: string; name?: string; }; export interface DelegatedGateOptions { /** Your priced catalog: item id → price, or → { price, minAge }. */ catalog: Record; /** Shared revocation + single-use ledger (defaults to in-memory, single-process). */ revocation?: RevocationStore; } export interface PreApproveOptions { /** The one merchant this grant may spend at. */ merchant: string; /** Per-purchase ceiling (an absolute cap). */ perOrder: number; /** Cumulative LIFETIME cap across every draw — it does NOT reset (there is no time * window in v0.1). Once total spend reaches it, the grant is spent out. */ total: number; /** A human sentence describing the grant (shown in your UI). */ description?: string; /** The agent keypair this grant delegates to. Supply it when the human must sign over the * key BEFORE the grant is sealed (the device-signed path); omit it and one is minted here. */ delegateKeys?: Awaited>; /** Who delegated — informational in v0.1 (an audit key; not yet an enforced identity). */ subject?: string; /** An age claim the HUMAN proved before authorizing, sealed into the grant's bounds (#172). * Absent ⇒ an age-restricted purchase steps up exactly as before. Present ⇒ purchases at or * below its proven threshold complete unattended; anything above still steps up. */ ageProof?: SealedAgeProof; /** A loyalty membership the HUMAN proved before authorizing (#172). Present ⇒ every purchase * under this grant prices at its sealed rate, on BOTH the signing and the re-pricing side. */ membershipProof?: SealedMembershipProof; /** Honesty override (spec 012): how consent happened / how strongly it is bound. Default * "delegated-demo" / "server-issued-demo" (the demo approve page). A device-signed grant * passes "delegated" / "device-signed" so the SEALED bounds carry the real trust level — * honesty lives in the content-addressed record, not just the handle. Additive: page-mode * callers pass neither and the sealed bounds are byte-identical to today. */ presence?: "delegated" | "delegated-demo"; trustLevel?: string; } export interface Purchase { /** A stable idempotency key for THIS purchase (Stripe's model). REUSE it to retry safely — * a timed-out retry with the same key returns the ORIGINAL result, charged once, never a * double-charge. Use a UNIQUE key per distinct purchase; a distinct key is a new draw. * The caller owns retry-safety: it must reuse the key, not mint a fresh one, on retry. */ idempotencyKey: string; item: string; quantity?: number; /** Spend at a merchant other than the approved one (to exercise scope). */ merchant?: string; } export interface SpendResult { /** Did the gate complete the purchase? */ ok: boolean; /** The amount the gate priced from the catalog (never trusted from the caller). */ amount: number; /** Headroom left on the grant's cumulative cap AFTER this spend (a completed spend * draws it down; a refused one leaves it unchanged). Reaches 0 when spent out. */ remaining: number; /** Why it was refused — present when `!ok` (e.g. "over-cap", "replay", "revoked"). */ reason?: RefusalCode; /** How to recover from a refusal — the bit an unattended loop branches on: * "needs-human" (surface an approve link), "retry" (transient), "terminal". */ retryable?: RefusalRetryable; /** The authorizing grant id — present when `ok` (the audit link on the record). */ delegationId?: string; } export declare const priceOf: (e: CatalogEntry) => number; export declare const minAgeOf: (e: CatalogEntry | undefined) => number | undefined; export declare const categoryOf: (e: CatalogEntry | undefined) => string | undefined; export declare const nameOf: (e: CatalogEntry | undefined) => string | undefined; /** * The configure-once gate: give it a priced catalog, get `preApprove()`. It holds * the revocation ledger and per-order stores so callers never wire them. Mint as many * grants as you like from one gate — each is isolated. */ export declare class DelegatedGate { private readonly catalog; private readonly ctx; constructor(opts: DelegatedGateOptions); /** Mint ONE grant and hand it back for your agent to hold. */ preApprove(opts: PreApproveOptions): Promise; } /** * A minted grant your agent holds. `spend()` signs one draw and runs it through the * gate; `revoke()` flips the ledger so the next spend dies. */ export declare class DelegatedGrant { private readonly grant; private readonly key; private readonly catalog; private readonly ctx; constructor(grant: IntentBounds, key: DelegateKey, catalog: CeremonyCatalog, ctx: CompletionContext); /** The grant's content-addressed id (the delegationId written on each draw). */ get id(): string; /** * The agent's PUBLIC key this grant delegates to — the sole key whose signature `spend()` * produces, and the key a device-signed mandate names in `cnf`. * * Readable so the two can be compared. On a device-signed grant the human's signature covers * this key, so "the key that was authorized" and "the key that can spend" being the same key * is a property worth being able to check rather than assume. */ get delegate(): DelegateJwk; /** When consent happened — "delegated-demo" in v0.1 (constitution VII honesty axis). */ get presence(): string; /** How strongly the authorization is bound — "server-issued-demo" in v0.1 (demo-fenced). */ get trustLevel(): string; /** The age claim sealed into these bounds at approval time, if the human proved one (#172). */ get ageProof(): SealedAgeProof | undefined; /** The loyalty membership sealed into these bounds at approval time, if any (#172). */ get membershipProof(): SealedMembershipProof | undefined; /** The human sentence this grant was described with, if any. */ get description(): string | undefined; /** * Spend against the grant. Returns `{ ok, amount, reason?, retryable?, delegationId? }` * for any GATE decision — it never throws to signal a refusal. (It does throw on a * programming error, e.g. an item id not in the catalog.) */ spend({ idempotencyKey, item, quantity, merchant }: Purchase): Promise; /** Live money read for a projection/display: how much this grant has drawn down so far and * how much cumulative headroom is left. Reads the SAME committed-draws ledger `spend()` * returns `remaining` from, so a projection never re-derives money the engine owns. In the * engine's integer cents (the caller converts to its display units). */ usage(): Promise<{ spent: number; remaining: number; }>; /** Revoke the grant — the very next spend is refused, fail-closed. Async so a remote * revocation store (the wallet-custody increment) can be awaited before the next spend. */ revoke(): Promise; } export {};