Skip to content

hashString

hashString(input): string

Defined in: packages/contracts/src/fingerprint.ts:285

FNV-1a over UTF-8 bytes, returned as 16 hex chars. Pure and dependency-free so it runs identically in the browser and in Bun (no crypto import). A fingerprint, not a security primitive — used both for the registry shape fingerprint (ADR-0004) and for the apply-function DDL fingerprint embedded in the generated migration (ADR-0018).

The 64-bit state is carried in TWO 32-bit Number lanes rather than a BigInt, because this runs over multi-KB payloads on the boot critical path (the local-schema fingerprint hashes the whole generated durable DDL) and a BigInt allocates per byte. The output is IDENTICAL — same algorithm, same offset basis, same prime, same modulo-2^64 truncation — and it MUST stay that way: the values are PERSISTED (registry_fingerprint, the lsf1 local-schema fingerprint, the apply DDL fingerprint), so a changed value would silently wipe every existing store’s read cache. tests/unit/registry-fingerprint pins goldens against the original BigInt implementation as the oracle.

Why plain Numbers are exact here: the prime 0x100000001b3 splits into small halves (high 0x100, low 0x1b3), so every partial product stays under 2^42 — far inside the 2^53 integer-exact range. The lane arithmetic therefore needs no Math.imul truncation games; only the final % 2^32 per lane.

string

string