Frozen one-shot XXH64 value over bytes, text, `uint32`, and `uint64`, plus `create()` for an independent incremental byte state; the seed defaults to `0n`.
Every error this module throws is HashInvalidInputError or HashParseError, with a code from a closed, exported list. Branch on the code; the message is for people.
Serialization lives in a separate entrypoint, knotkit/hash/wire, so code that never saves a structure never loads a parser.
Functions
serializeHashIdentity, deserializeHashIdentity
Formats
json
Compatibility
identity-versioned; deserializeHashIdentity rejects an identity whose version is not HASH_IDENTITY_VERSION, which changes only when the digest mapping changes, never with a release, envelope v
Use knotkit/hash for this task. If Knotkit is missing, follow https://knotkit.jkomyno.dev/getting-started.md#install-from-source. Import from 'knotkit/hash'.
Exports:
- `xxh64` → `ScalarHash<'xxh64', bigint, bigint>`: Frozen one-shot XXH64 value over bytes, text, `uint32`, and `uint64`, plus `create()` for an independent incremental byte state; the seed defaults to `0n`.
- `hashFromIdentity` → `ScalarHash<'xxh64', bigint, bigint>`: Restore the current implementation matching a validated hash identity, so a persisted version and seed reproduce the same digests.
Use something else when:
- hash a password, sign a message, or authenticate data with a secret → crypto.subtle from Web Crypto
- resist collisions from an adversary who chooses the input → SHA-256 through crypto.subtle in Web Crypto
- count distinct values, or estimate their frequencies, in bounded memory → knotkit/scalar-sketch
- checksum a large artifact at maximum throughput → the xxhash-wasm package, which runs the same algorithm in WebAssembly
- persist a whole data structure and re-read it later → the structure package's serialize function
Errors are HashInvalidInputError or HashParseError with a `code` property. Branch on `error.code`, never on the message. Save and load through `knotkit/hash/wire` (serializeHashIdentity, deserializeHashIdentity).
Full page: https://knotkit.jkomyno.dev/modules/hash.md
Types: node_modules/knotkit/hash/ and https://knotkit.jkomyno.dev/reference/knotkit/hash/