parsing/stable_hash_utils library
Order-stable structural checksum with no crypto dependency — roadmap #649.
Produces a deterministic canonical text for JSON-like data and an FNV-1a 64-bit hash of it. Map key insertion order does NOT affect the result (keys are sorted), but list order DOES (lists preserve order). Useful for cache keys, change detection, and deduplication where a stable, repeatable digest is needed without pulling in a cryptographic hash.
The digest is identical on every platform, including the web. The 64-bit
FNV-1a is computed with 32-bit limbs (see _mulMod64) because a native
int * prime relies on the VM's 64-bit two's-complement wrap, which the
web's 53-bit-double int model lacks; the limb form reproduces the exact
mod-2^64 arithmetic everywhere. The result also matches the value the older
native implementation produced on the VM, so previously persisted digests
stay valid. See https://dart.dev/resources/language/number-representation.
Functions
-
canonicalString(
Object? value) → String -
Builds a deterministic canonical string for
value. -
stableHash(
Object? value) → String -
Returns the FNV-1a 64-bit hash of canonicalString of
valueas a lowercase hex string.