blake3.ts

The blake3 host module: BLAKE3 hashing over bytes, one-shot or incremental, reaching nothing.

A digest is 32 bytes, a new Uint8Array each call. Bytes are a Uint8Array, its subclasses included, and anything else, a proxy of one among them, is a TypeError, so nothing a caller passes is converted or iterated. A view is read as it is when the call runs: one of a detached buffer is a TypeError, and a fixed-length one a resize left out of its buffer's bounds is empty. A derive-key context is a string, encoded as UTF-8 with each lone surrogate replaced, as TextEncoder encodes it.

A hasher holds its input's state, not its input, so a stream of any length is hashed in constant memory: update it with each chunk, and finalize for the digest of what it was given so far, as often as needed. Its state lives as long as it can be reached, with no call to end it, and a hasher is frozen, null-prototype, and recognized by its methods, which throw a TypeError called on any other object.

This is the Node implementation, which runs on the Node Gro, over @fuzdev/blake3-wasm. On fgro the module is the runtime's own, over the native blake3 crate, and grant-free, so the project and every package may import it. Its gap against the runtime's builtin, which it documents rather than the API weakening to match: a hasher's state is in the WASM module's memory, released when the hasher is collected, by the package's FinalizationRegistry.

view source

Declarations
#

5 declarations

Blake3Hasher
#

blake3.ts view source

Blake3Hasher import type {Blake3Hasher} from '@fuzdev/gro/blake3.js';

A hasher: BLAKE3's state over the input it has been given.

update

Adds data to the input.

type (data: Uint8Array<ArrayBufferLike>): void

data

type Uint8Array<ArrayBufferLike>
returns void

throws

  • TypeError - for `data` that isn't a `Uint8Array`

finalize

The digest of the input so far, 32 bytes, leaving the hasher as it was.

type (): Uint8Array<ArrayBufferLike>

returns Uint8Array<ArrayBufferLike>

create_derive_key_hasher
#

blake3.ts view source

(context: string): Blake3Hasher import {create_derive_key_hasher} from '@fuzdev/gro/blake3.js';

A new hasher for BLAKE3's key derivation in context, a string that names the application, whose digest of the key material it's given is the derived key.

context

type string

returns

Blake3Hasher

throws

  • TypeError - for a context that isn't a string

create_hasher
#

blake3.ts view source

(): Blake3Hasher import {create_hasher} from '@fuzdev/gro/blake3.js';

A new hasher, for BLAKE3's plain hash, the one hash computes.

returns

Blake3Hasher

create_keyed_hasher
#

blake3.ts view source

(key: Uint8Array<ArrayBufferLike>): Blake3Hasher import {create_keyed_hasher} from '@fuzdev/gro/blake3.js';

A new hasher for BLAKE3's keyed hash, a MAC, of key.

key

type Uint8Array<ArrayBufferLike>

returns

Blake3Hasher

throws

  • TypeError - for a key that isn't a `Uint8Array`
  • RangeError - for a key that isn't 32 bytes

hash
#

blake3.ts view source

(data: Uint8Array<ArrayBufferLike>): Uint8Array<ArrayBufferLike> import {hash} from '@fuzdev/gro/blake3.js';

The BLAKE3 digest of data, 32 bytes.

data

type Uint8Array<ArrayBufferLike>

returns

Uint8Array<ArrayBufferLike>

throws

  • TypeError - for `data` that isn't a `Uint8Array`