UNPKG

kestrel.markets

Version:

A typed, token-efficient language + runtime for agentic trading: agents author bounded plans, the runtime fires them at the tick. CLI + typed library + MCP server.

41 lines 3.15 kB
/** * # canonical/json — the one canonical JSON + content-hash owner (kestrel-zs2f) * * Content-addressing runs through the whole grade/blotter path as **pure, synchronous** functions: the * Blotter's {@link ../blotter/serialize.ts serialize}, a receipt's identity/plan hashes, the * {@link ../session/harness/plan-fixture.ts plan_fixture_sha}, the session genesis/entry hashes, the * ConfigId, and every content address in the grade transcript take a sha256 of a value's CANONICAL bytes. * Those bytes must depend only on the DATA — never on construction/insertion order — so the same value * always hashes and serializes byte-identically, the substrate the determinism certification leg * byte-compares (RUNTIME §0). This module is the ONE owner of that canonical byte order: it was * copy-pasted byte-identical across blotter/serialize, grade/receipt, grade/receipts, * session/harness/plan-fixture, session/controller (`deepSort`), and session/config (`deepSort`) — * parity by comment, not by import (ARCH-REVIEW C1). It is now a single import; the platform imports the * SAME bytes via the `./engine` entry (`engine.canonical`) so cross-repo certification is byte-identical, * not a reimplementation (kestrel-markets-5l3). * * Canonicalization sorts every object's keys lexicographically, recursively, so the bytes depend only on * the data. Arrays keep their order (it is meaningful — bus/seq order). Numbers serialize via the * platform's shortest round-trippable form (`JSON.stringify`), which is deterministic. `undefined` object * entries are dropped (a canonical value carries no `undefined` — optional fields are simply absent). * Output is compact machine-JSON with NO trailing newline; a serializer that pins a stored artifact adds * its own single trailing newline (that newline is the artifact's canon, not this function's). * No wall clock, no RNG. */ /** A JSON-representable value (a canonical value is exactly this shape). */ export type Json = null | boolean | number | string | Json[] | { [k: string]: Json; }; /** Recursively rebuild a value with every object's keys sorted lexicographically. Arrays keep their * order (it is meaningful — bus/seq order); objects are reordered to a canonical key sequence, and every * `undefined` entry is dropped. Pure. */ export declare function canonicalize(value: unknown): Json; /** Canonical JSON of a value: compact machine-JSON with lexicographically ordered keys and no trailing * newline — the bytes a content hash is taken over and the substrate every canonical serializer is built * on. Pure and total; the same value always yields byte-identical text. */ export declare function canonicalizeJson(value: unknown): string; /** sha256 over the {@link canonicalizeJson canonical JSON} of a value — the one content-address of a * value, order-insensitive and deterministic. Hashes through the portable {@link ../crypto/sha256.ts} * digest so it is byte-identical under Bun and inside a Worker isolate (kestrel-zs2f.1 / kestrel-alw.17). */ export declare function jsonHash(value: unknown): string; //# sourceMappingURL=json.d.ts.map