canonical_bytes

Function canonical_bytes 

Source
pub fn canonical_bytes(value: &str) -> Vec<u8> ⓘ
Expand description

NFC-normalized UTF-8 bytes: the sort key, and the bytes the encoder writes.

This is v0’s rule, and following it is a correctness requirement rather than a compatibility nicety. packages/provenance/SPEC.md §3 normalizes every string before hashing and sorts sets by those same normalized bytes, with the reason stated: sorting raw while encoding normalized lets the producer’s spelling pick the order. Pset_Béton spelled NFC (…c3a9…) and NFD (…65cc81…) is one string canonically and two byte sequences rawly, so a raw sort against Pset_Z orders the same set two ways and one canonical input yields two hashes — “worse than a collision for a verifier”, since recompute-and-compare then fails on honest data.

An earlier draft of this crate sorted by UTF-16 code unit and normalized nothing, on the mistaken belief that it was inheriting v0’s rule. It was inheriting rust/diff’s, which is a different compatibility format: that one exists to reproduce V8’s JSON.stringify byte for byte and has no bearing here.