fact_hash.ts

Fact hash producers.

A FactHash is a blake3:-prefixed hex64 blake3 digest. The prefix makes the hash self-identifying — any text scanner can find it without prior knowledge of the source.

The vocabulary — FactHashSchema, FACT_HASH_PREFIX, FACT_HASH_PATTERN, is_fact_hash — lives in hash_schemas.ts, which imports no WASM. This module holds the functions that actually hash, so importing it costs the @fuzdev/blake3_wasm binary. Client code validating a hash it received should import from hash_schemas.ts instead.

Runtime validation happens at construction (fact_hash_bytes / fact_hash_stream cast at the source; FactHashSchema.parse / is_fact_hash validate inputs from external boundaries).

The hash-producing helpers carry the fact_hash_ prefix so they namespace cleanly alongside the branded FactHash type and the FACT_HASH_* constants, and stay distinct from the raw-hex hash_blake3 / hash_sha256 family in hash.ts (those return bare digests; these return the branded, blake3:-prefixed wire form).

view source

Declarations
#

4 declarations

fact_hash_bytes
#

fact_hash.ts view source

(data: string | Uint8Array<ArrayBufferLike>): string & $brand<"FactHash"> import {fact_hash_bytes} from '@fuzdev/fuz_util/fact_hash.js';

Synchronously hash bytes into a fact hash.

Delegates to hash_blake3 (the fuz_util wrapper around @fuzdev/blake3_wasm) and prefixes the result with blake3:. Strings are UTF-8 encoded.

data

type string | Uint8Array<ArrayBufferLike>

returns

string & $brand<"FactHash">

fact_hash_extract_refs
#

fact_hash.ts view source

(value: Json): (string & $brand<"FactHash">)[] import {fact_hash_extract_refs} from '@fuzdev/fuz_util/fact_hash.js';

Walk a JSON value collecting every blake3:-prefixed string match.

Strings, object values, and array elements are scanned; object keys are intentionally skipped (a hash as an object key is exotic enough that callers should declare it explicitly via FactStore.put({refs})). The same hash appearing twice is deduplicated. Order follows depth-first traversal of the input.

Used by application code on cell snapshot writes and JSON fact writes.

value

type Json

returns

(string & $brand<"FactHash">)[]

fact_hash_stream
#

fact_hash.ts view source

(stream: ReadableStream<Uint8Array<ArrayBufferLike>>): Promise<string & $brand<"FactHash">> import {fact_hash_stream} from '@fuzdev/fuz_util/fact_hash.js';

Hash a ReadableStream<Uint8Array> into a fact hash without buffering the full content. Used by FactStore.put_ref for large external content.

stream

type ReadableStream<Uint8Array<ArrayBufferLike>>

returns

Promise<string & $brand<"FactHash">>

fact_hash_verify
#

fact_hash.ts view source

(hash_value: string & $brand<"FactHash">, bytes: Uint8Array<ArrayBufferLike>): boolean import {fact_hash_verify} from '@fuzdev/fuz_util/fact_hash.js';

Verify that bytes produce the claimed hash.

Returns false on any mismatch, including a malformed hash. Callers doing security-sensitive integrity checks should treat false as not-found / corrupt and refuse to use the bytes.

hash_value

type string & $brand<"FactHash">

bytes

type Uint8Array<ArrayBufferLike>

returns

boolean

Depends on
#