Skip to content

Kdf

BLAKE2b-based key derivation - derives independent subkeys from a single master key. Each subkey is identified by a numeric ID and an 8-character ASCII context string. The context namespaces subkeys within the master key; use distinct contexts per subsystem. Shorter contexts are zero-padded to 8 bytes; longer contexts will error.

Kdf . keygen ( )  -> buffer

Generates a random 32-byte master key via libsodium’s CSPRNG.

Returns

buffer
Kdf . deriveKey ( masterKey subkeyId context outputBytes )  -> buffer

Derives a subkey from masterKey (32 bytes) identified by subkeyId and an 8-char context string. outputBytes controls the subkey length (16–64, default 32); errors if context or outputBytes is out of range.

Parameters

masterKey: buffer
subkeyId: number
context: string
outputBytes: number?

Returns

buffer