/** * RFC 8785 (JSON Canonicalization Scheme) as profiled by AWR/2 (`awr/SPEC.md` §4). * * Two places in WARDEN turn a JSON value into bytes that a *different* * implementation has to reproduce exactly: the signed threat feed (a publisher * signs, ARGUS verifies) and the tool-def pin (a sha256 quoted in receipts and * re-checked by `argus verify`). `JSON.stringify` cannot do that job — its output * depends on the key order the wire happened to use, so one logical document * serialises to different bytes on the two sides and the signature fails for no * security reason at all. * * The profile implemented here, rule by rule: * * 1. **Property names sort as arrays of UTF-16 code units** (RFC 8785 §3.2.3). * JavaScript's default `Array.prototype.sort()` on strings compares exactly * that, so this is the one rule the platform gives away for free. * `String.prototype.localeCompare` does *not*: it depends on the host locale * and ICU version, which makes it unusable as a digest input. * 2. **No Unicode normalization, ever** (SPEC §4.1 item 2). NFC would collide two * property names that RFC 8785 keeps distinct. * 3. **Two-character escapes plus lowercase `\uXXXX` for the remaining C0 * controls** (§3.2.2.2) — which is precisely what `JSON.stringify` emits for a * string, so string bodies are delegated to it rather than re-implemented. * 4. **Lone surrogates terminate with an error** instead of being substituted * (§4.1 item 4). `JSON.stringify` would quietly escape them into * valid-looking bytes, so they are rejected before it is called. * 5. **Integers only, within ±(2^53−1)**; every non-integer number is refused * rather than arbitrated (§4.3), because whether `1` parses as an integer or * as a double is a language accident that silently changes the signed bytes. * * Scope: this module is *only* the byte-level canonicalization. It knows nothing * about AWR documents, Data Integrity proofs, `did:key` or profiles. */ /** Reason codes from the SPEC §11.2 `AWR-CANON-*` registry that this module raises. */ export type CanonicalizationCode = /** Non-integer JSON number present. */ "AWR-CANON-001" /** Integer outside ±(2^53−1). */ | "AWR-CANON-002" /** Invalid Unicode (lone surrogate) in string data. */ | "AWR-CANON-003" /** Duplicate object property name. */ | "AWR-CANON-004" /** Input is not well-formed JSON / not representable in JSON. */ | "AWR-CANON-005"; /** * A value could not be canonicalized (or parsed) under the AWR profile. * * Callers are expected to *handle* this rather than let it escape: refusing to * produce bytes is the honest outcome, but it must not crash a connection check. */ export declare class CanonicalizationError extends Error { readonly code: CanonicalizationCode; constructor(code: CanonicalizationCode, detail: string); } /** Largest magnitude of a JSON integer permitted in canonical bytes (2^53−1). */ export declare const MAX_SAFE_JSON_INTEGER = 9007199254740991; /** * Return the RFC 8785 canonical serialization of `value` as a UTF-8-ready string. * * Throws {@link CanonicalizationError} rather than emitting bytes it cannot * defend: a non-integer number, an integer beyond 2^53−1, a lone surrogate, an * `undefined` property (which `JSON.stringify` would silently drop), a * non-plain object, or a cycle. */ export declare function canonicalize(value: unknown): string; /** * Plain RFC 8785, outside the AWR profile: the same bytes as {@link canonicalize} * wherever that succeeds, and every other finite number in the ECMAScript form * RFC 8785 §3.2.2.3 specifies (`0.7`, `1e+21`). A host's own pins use it, and so * does the MTL/1.1 tool-set digest (mtl.ts), which HISTOR's Python reproduces: * its number writer matched `JSON.stringify` on 399,880 doubles. Not for an AWR/2 * signed document, whose §4.3 still admits integers only. */ export declare function canonicalizeRfc8785(value: unknown): string; /** * Parse JSON with the profile's parser requirements, for input whose bytes were * signed by someone else. * * `JSON.parse` alone is not enough on a verification path: * * - **Duplicate property names** (§4.1 item 5, `AWR-CANON-004`) are resolved * last-wins and silently, which would let the parser — not the signer — decide * which of two records was the signed one. * - **Non-integer number literals** (§4.3, `AWR-CANON-001`) are rejected * *lexically*, not by value: `2340.0` and `2340` parse to the same JavaScript * number, and a publisher written in a language that distinguishes them would * have signed different bytes. * * Both checks run over the received text after `JSON.parse` has confirmed it is * well-formed, so the scanner below only has to find tokens, never validate * grammar. */ export declare function parseJsonStrict(text: string): unknown; //# sourceMappingURL=jcs.d.ts.map