Skip to main content

Module binary_format

Module binary_format 

Source
Expand description

Binary container formats — Rust mirror of TS binary-format.ts.

.tfbundle — sealed/serialized proof bundle, L4/L5 capable. magic = “TFBND” 0x01 0x00 0x00 (8 bytes) body_len = u32 BE body = CBOR-encoded ProofBundleEncrypted | ProofBundle sig_len = u32 BE (0 when unsigned) signature = sig_len bytes (raw ed25519)

.tfpkt — packet-on-the-wire envelope. magic = “TFPKT” 0x01 0x00 0x00 (8 bytes) body_len = u32 BE body = CBOR-encoded Packet

The Rust encoder must produce byte-identical output to the TS encoder for the same canonical input — verified by conformance/binary-format-vectors.yaml.

— CBOR DETERMINISM (READ BEFORE EDITING) —

For wire-level parity with the TS encoder, the Rust encoder converts through serde_json::Value first and explicitly sorts every object’s keys lexicographically (canonicalize_json); the in-house crate::cbor encoder then emits map entries in exactly that order with the smallest definite-length headers. Without this intermediate, a native #[derive(Serialize)] struct would emit fields in declaration order and break parity.

Yes, this costs one extra ser/deser per encode. The packets are small (typical .tfpkt <1 KiB) and constrained-mode use cases never hot-loop the encoder, so the trade for a stable wire format is correct. Do NOT remove the round-trip without first updating conformance/binary-format-vectors.yaml and the matching TS test.

Structs§

TfbundleParts

Enums§

BinaryFormatError

Constants§

TFBUNDLE_MAGIC
TFPKT_MAGIC

Functions§

read_tfbundle
read_tfbundle_typed
Read a .tfbundle and deserialize the body into a typed T.
read_tfpkt
write_tfbundle
write_tfpkt