Expand description
In-house CBOR codec (RFC 8949) — TrustForge owns its codec layer; see
docs/dependency-audit.md. Mirror of tools/tf-types-ts/src/core/cbor.ts.
Scope: exactly what the TrustForge wire formats need.
- Encoding is deterministic: smallest-width integer/length headers,
definite lengths only, floats always emitted as 8-byte doubles.
Map entries are emitted in the order provided — canonical key
ordering is the caller’s contract (
binary_formatsorts JSON keys lexicographically before building the tree; see the determinism notes there). This module must stay byte-parity with the TS encoder overconformance/binary-format-vectors.yaml. - Decoding is hardened for externally produced CBOR (WebAuthn attestation objects, COSE keys): depth-limited, length headers are validated against remaining input before any allocation, and indefinite-length items are accepted (CTAP1-era encoders emit them) but bounded by the same limits. Trailing bytes after the first value are ignored, matching the previous decoder.
Enums§
Functions§
- decode
- Decode the first CBOR value in
bytes. Trailing bytes are ignored, matching the replaced decoder’s behavior. - encode
- from_
json - Build a CBOR value from a JSON value. Object key order is preserved as-is — sort beforehand for canonical output.
- to_json
- Convert a decoded CBOR value back to JSON. Fails on shapes JSON cannot express (byte strings, non-text map keys, tags) — the typed wire bodies never contain them.