import { type KeyObject } from "node:crypto"; import { z } from "zod"; import { type UsagePeriod } from "./UsagePeriod.js"; import type { PeriodUsage } from "./UsageTally.js"; /** The JWS `typ` of a usage report, as Decionis ingestion checks it. */ export declare const USAGE_REPORT_TYPE = "decionis-edge-usage+jwt"; /** The claims of a usage report (Edge evaluator phase 4, section 3). */ export declare const UsageReportClaimsSchema: z.ZodObject<{ iss: z.ZodString; aud: z.ZodString; iat: z.ZodNumber; jti: z.ZodString; period: z.ZodString; period_start: z.ZodString; period_end: z.ZodString; counts: z.ZodObject<{ by_mode: z.ZodObject<{ ENFORCEMENT: z.ZodNumber; SHADOW: z.ZodNumber; }, z.core.$strict>; by_verdict: z.ZodObject<{ ALLOW: z.ZodNumber; ESCALATE: z.ZodNumber; BLOCK: z.ZodNumber; }, z.core.$strict>; total: z.ZodNumber; }, z.core.$strict>; delegated: z.ZodNumber; chain: z.ZodObject<{ stream: z.ZodString; first_seq: z.ZodNullable; last_seq: z.ZodNullable; first_hash: z.ZodNullable; last_hash: z.ZodNullable; }, z.core.$strict>; bundles: z.ZodArray; }, z.core.$strict>; export type UsageReportClaims = z.infer; /** The usage report's claims for one period, as this installation counted it. */ export declare function usageReportClaims(input: { readonly installationId: string; readonly orgId: string; readonly period: UsagePeriod; readonly usage: PeriodUsage; readonly stream: string; readonly now: number; /** The report's id; a fresh UUID unless a fixed vector names one. */ readonly jti?: string; }): UsageReportClaims; /** The usage the claims state, in the tally's shape, for a recount to compare with. */ export declare function claimedUsage(claims: UsageReportClaims): PeriodUsage & { readonly stream: string; }; /** * Whether the claims agree with themselves: the period's bounds are the * period's, each breakdown sums to the total, no more were delegated than * decided, and the range is named exactly when something was counted. */ export declare function consistentClaims(claims: UsageReportClaims): boolean; /** An installation's usage-report key: Ed25519, with the `kid` it is registered under. */ export interface UsageSigningKey { readonly kid: string; readonly privateKey: KeyObject; /** The public half, as `POST /v1/execution/provider-keys` takes it. */ readonly publicJwk: { readonly kty: "OKP"; readonly crv: "Ed25519"; readonly x: string; }; } /** * Reads a PKCS#8 PEM Ed25519 key. The `kid` is the one configured, or the * key's RFC 7638 thumbprint, so the same key always has the same id. */ export declare function usageSigningKey(pem: string, kid?: string | null): UsageSigningKey; /** The compact JWS Decionis ingests: `alg` EdDSA, `typ` the usage report's, `kid` the key's. */ export declare function signUsageReport(claims: UsageReportClaims, key: UsageSigningKey): Promise; export type UsageReportRead = { readonly ok: true; readonly kid: string; readonly claims: UsageReportClaims; } | { readonly ok: false; readonly code: string; }; /** * Checks a usage report's signature against a public key and its claims * against the schema and themselves. It does not recount: `verifyUsage` * does that against the chain. */ export declare function readUsageReport(token: string, publicJwk: Readonly>): Promise; //# sourceMappingURL=UsageReport.d.ts.map