/** * Bounded canonical JSON for stable integrity digests. Keys are sorted, undefined values * omitted, and sparse-array handling is explicit. Descriptor-only reads never invoke * getters; node budgets are charged before reflection and sorting. Ancestor cycles fail * while shared references remain valid. Typed rejections expose structural context without * attacker-controlled property names. */ /** Classification for a canonical walk that refused to keep going. */ export declare const CANONICAL_JSON_UNBOUNDED = "CANONICAL_JSON_UNBOUNDED"; /** * Rejection hook. Call sites with their own domain error type (export/import * failures are `AgentExportError`) pass their own so callers keep catching what * they always caught; everything else uses {@link failCanonicalJsonUnbounded}. */ export type CanonicalJsonUnbounded = (context: Record, cause?: unknown) => never; export type CanonicalJsonOptions = { /** Rejected strictly above this. Honest documents are a handful deep. */ maxDepth: number; /** Node ceiling across the whole walk, including sparse array slots. */ maxNodes: number; /** * Optional ceiling on the number of characters the canonical form may emit. * A cycle guard that is path-local (as it must be, to keep honest DAGs * hashing unchanged) still lets a shared-reference graph expand * exponentially when it is flattened to a tree; this is the budget that * bounds that expansion in output terms rather than input terms. Omit it at * a call site whose payload size is already capped upstream. */ maxOutputChars?: number; /** * How a sparse array hole is rendered. `"omit"` reproduces * `array.map(fn).join(",")` (an empty slot); `"null"` reproduces * `JSON.stringify`, which renders a hole as `null`. Both are historical * behaviours in this repo and both are load-bearing for already-stored * digests, so the caller must say which one it is preserving. */ sparseArrayHoles: "omit" | "null"; /** Typed rejection for this call site. */ onUnbounded: CanonicalJsonUnbounded; }; /** Default typed rejection: an {@link ElizaError} with a fatal severity. */ export declare const failCanonicalJsonUnbounded: CanonicalJsonUnbounded; /** * Budgets for the agent-backup integrity digests. * * `maxDepth` matches the export walk's 64: an honest backup state — config * record, memory log, workspace file map, manifest — is a handful of objects * deep, while a decrypted or stored payload can still be legal JSON nested * deeply enough to overflow the stack. * * The node and output ceilings are pinned to * {@link MAX_RESTORABLE_AGENT_BACKUP_BYTES} rather than to a smaller round * number on purpose: every JSON node costs at least one character in the * canonical form, so NO state the restore path is willing to accept can reach * either ceiling. That makes them unreachable by honest data by construction — * the point that matters, because a state that newly failed to hash would * invalidate the backups already stored for it — while still bounding the * shared-reference expansion that has no wire-size bound at all. */ export declare const AGENT_BACKUP_CANONICAL_JSON: CanonicalJsonOptions; /** * One immutable `length` read for a caller that must publish a digest and a * count taken from the same snapshot. Pass the result back in as * `knownArrayLength`. */ export declare function readCanonicalArrayLength(value: object, options: CanonicalJsonOptions): number; /** @see readCanonicalArrayLength */ export declare function isCanonicalJsonArray(value: object, options: CanonicalJsonOptions): boolean; /** * Canonical JSON text for `value`, bounded by `options`. * * Mirrors `JSON.stringify` for every value the unbounded predecessors reached: * keys sorted, `undefined`-valued object keys dropped, `undefined` array slots * rendered `null`, non-plain objects (`Date`, `Map`, `Set`) rendered from their * own enumerable string keys — which is exactly what the sorted-key recursion * they replace already did. */ export declare function canonicalJsonString(value: unknown, options: CanonicalJsonOptions, knownArrayLength?: number): string; /** * `JSON.stringify`-faithful wrapper for the call sites that spelled this * `JSON.stringify(canonicalize(value))`. * * `JSON.stringify(undefined)` is `undefined`, not `"null"`, and callers such as * the backup differ rely on that to tell an absent config value apart from a * `null` one (same for a bare function or symbol at the root). */ export declare function stableJsonString(value: unknown, options: CanonicalJsonOptions): string | undefined;