/** * The normative JSON Schema 2020-12 execution profile for contract schemas (SPEC §13.7, D27). * * A contract schema is a CLOSED resource bundle: fully self-contained (local `#/…` refs) or * referencing other contract-store artifacts by digest (`cotal:sha256:`) only. Ambient * HTTP/file/URI resolution never happens; every external reference must be supplied by the * caller as an already-fetched, digest-verified bundle member. Registration-time violations are * `contract-invalid` (distinct from invocation-time `bad-request`), and all bounds are enforced * BEFORE compilation so a hostile descriptor cannot turn registration into a DoS. */ import { type ValidateFunction } from "ajv/dist/2020.js"; /** Registration-time bounds (SPEC §13.7/§13.8). Fixed by the profile, not caller-tunable, and * RUNTIME-frozen (the afa715b class): a post-import `maxDepth = MAX_SAFE_INTEGER` would remove * the pre-compilation recursion/DoS ceiling, so mutation throws instead. */ export declare const SCHEMA_PROFILE: Readonly<{ /** One schema document's canonical form, bytes. */ readonly maxDocumentBytes: number; /** The complete resolved closure (root + digest-referenced members), bytes. */ readonly maxClosureBytes: number; /** Structural nesting depth of any document. */ readonly maxDepth: 32; /** Digest-reference chain depth (root → member → member …). */ readonly maxRefChain: 32; /** Compile budget per closure, ms. */ readonly compileBudgetMs: 100; /** Bounded pattern complexity: max characters of any `pattern` / `patternProperties` regex. */ readonly maxPatternChars: 256; /** Per-value validation budget at the serving boundary, ms (§13.8 reference). REPORTED on the * request path, not enforced — no available instrument can justify refusing a caller on it; see * `reportValidateBudget` in endpoint-envelope.ts. */ readonly validateBudgetMs: 10; /** Compiled-schema cache entries (the SPEC's reference 256-entry LRU). */ readonly compiledCacheEntries: 256; }>; /** The canonical void schema (§13.7): the one artifact a side with no payload declares, so both * `op` digests exist for every command. Validation against it means the payload is absent or * `null`. */ export declare const VOID_SCHEMA: Readonly<{ readonly type: "null"; }>; /** Artifact digest of the void schema document — one fixed value by construction. */ export declare const VOID_SCHEMA_ARTIFACT_DIGEST: string; /** The void schema's CLOSURE digest (the §13.7 manifest of a self-contained document) — the * value `op.inputDigest`/`op.outputDigest` carry for a payload-free side. */ export declare const VOID_SCHEMA_DIGEST: string; /** Thrown for every profile violation at registration/ingest time; maps to the wire error * code `contract-invalid` (never `bad-request`, which is for invocation-time args). */ export declare class ContractInvalidError extends Error { readonly code: "contract-invalid"; constructor(message: string); } /** A closed schema bundle: the root document plus every digest-referenced member, already * fetched and digest-verified (see `verifyArtifact`). Keyed by `sha256:`. */ export interface SchemaBundle { root: unknown; /** Digest → verified member document. Every `cotal:` ref in the closure must resolve here. */ members?: Record; } /** A registered contract schema: the compiled validator plus the bundle's CLOSURE digest — * the artifact digest of the §13.7 manifest `{ v: 1, root, members[] }` (members = every * artifact transitively REACHABLE from the root, sorted and deduplicated). The closure digest * is the contract identity `op.inputDigest`/`op.outputDigest` pin. * * The interface is structural for CONSUMERS, but authority seams never accept structure: a * compiled contract is FROZEN and brand-registered by this compiler ({@link compileContract}), * and {@link assertCompiledContract} refuses any object the profile compiler did not produce — * so a hand-built `{validate, closureDigest}` pair (an arbitrary validator wearing a * registered digest) can never enter a serve table (§13.7: the digest and its enforcing * validator are one value). */ export interface CompiledContract { validate: ValidateFunction; closureDigest: string; } /** True iff `c` is a frozen contract this profile compiler produced (never structural). */ export declare function isCompiledContract(c: unknown): c is CompiledContract; /** Refuse anything that is not a compiler-produced contract: authority seams (the serve table, * the grant mint) call this so a fabricated validator/digest pair fails loud, never serves. */ export declare function assertCompiledContract(c: unknown, what: string): CompiledContract; /** Validate the whole closure against the profile and compile it with a real 2020-12 * validator. No network, no filesystem: `loadSchema` is never installed, and every * `cotal:` reference must be present in `bundle.members`. */ export declare function compileContract(bundle: SchemaBundle): CompiledContract; /** {@link compileContract} without the closure identity, kept for validation-only callers. */ export declare function compileContractSchema(bundle: SchemaBundle): ValidateFunction; /** A bounded compiled-schema LRU (SPEC §13.7's reference 256-entry cache), keyed by CLOSURE * digest. The profile walk (incl. member digest verification) runs on EVERY call — only the * ajv compilation is skipped on a hit. Sound across callers: two bundles with one closure * digest are byte-identical closures, so a hit can never serve another caller's * mis-assembled bundle. */ export declare function createCompiledContractCache(capacity?: number): { compile: (bundle: SchemaBundle) => CompiledContract; size: () => number; }; //# sourceMappingURL=schema-profile.d.ts.map