vael:crypto
Symmetric AES-256 encryption, SHA-2 hashes/HMACs, PBKDF2, bcrypt, and Shamir secret sharing.
Available in the vjs (vaeljs) runtime with both synchronous APIs and
worker-pool *Async APIs. In vjs-lite, only the synchronous exports are
available (hashAsync, hmacAsync, pbkdf2Async, bcryptHashAsync,
bcryptVerifyAsync, shamirSplitAsync, and shamirCombineAsync are absent).
import ... from "vael:crypto"
vaeljs-core; vael-crypto (default) in vaeljs-lite-core*Async worker-pool helpers (hashAsync, hmacAsync, pbkdf2Async, bcryptHashAsync, bcryptVerifyAsync, shamirSplitAsync, shamirCombineAsync) are V8-only (vjs). Sync exports (including BLAKE2 and BLAKE3) run on both vjs and vjs-lite.Example
Section titled “Example”import { createHash, decrypt, encrypt, generateEnvelopeKey } from "vael:crypto";
const key = generateEnvelopeKey();const envelope = encrypt(key, new Uint8Array([1, 2, 3, 4]));const plain = decrypt(key, envelope);const digest = createHash("sha256").update("hello").digest("hex");console.log(plain.length, digest);generateEnvelopeKeyv0.0.0-alpha.0randomBytesv0.0.0-alpha.0length bytes (0..=8_388_608) from the OS CSPRNG.encryptv0.0.0-alpha.0plaintext (max 8 MiB) into a versioned NEO1 AES-256-GCM envelope with a fresh random 96-bit nonce.decryptv0.0.0-alpha.0createEncryptorv0.0.0-alpha.0"aes-256-cbc" or "aes-256-gcm".createDecryptorv0.0.0-alpha.0"aes-256-cbc" or "aes-256-gcm".createHashv0.0.0-alpha.0"sha256", "sha384", or "sha512").createHmacv0.0.0-alpha.0"sha256", "sha384", or "sha512").hashAsyncvjs onlyv0.0.0-alpha.0hmacAsyncvjs onlyv0.0.0-alpha.0pbkdf2v0.0.0-alpha.0pbkdf2Asyncvjs onlyv0.0.0-alpha.0bcryptHashv0.0.0-alpha.0$2b$ modular-crypt string.bcryptHashAsyncvjs onlyv0.0.0-alpha.0$2b$ format, max 72 bytes, cost in 4..=16, default 10).bcryptVerifyv0.0.0-alpha.0password against a $2a$/$2b$/$2y$ bcrypt hash in constant time.bcryptVerifyAsyncvjs onlyv0.0.0-alpha.0password against a bcrypt hash on the bounded worker pool.shamirSplitv0.0.0-alpha.0secret into shareCount GF(256) Shamir shares requiring threshold shares to reconstruct.shamirSplitAsyncvjs onlyv0.0.0-alpha.0secret into GF(256) Shamir shares on the bounded worker pool.shamirCombinev0.0.0-alpha.0shamirCombineAsyncvjs onlyv0.0.0-alpha.0blake3v0.0.0-alpha.2data.blake3Keyedv0.0.0-alpha.2data using a 32-byte key.blake3DeriveKeyv0.0.0-alpha.2keyMaterial using BLAKE3 key derivation with domain-separation context.blake2bv0.0.0-alpha.2data.blake2sv0.0.0-alpha.2data.CipherOptionsv0.0.0-alpha.0createEncryptor and createDecryptor (aes-256-cbc only; aes-256-gcm accepts no options).Blake3Optionsv0.0.0-alpha.2blake3, blake3Keyed, and blake3DeriveKey.Blake2Optionsv0.0.0-alpha.2blake2b and blake2s.ShamirSharev0.0.0-alpha.0shamirSplit / shamirSplitAsync and consumed by shamirCombine / shamirCombineAsync.Cipherv0.0.0-alpha.0createEncryptor or createDecryptor.Hashv0.0.0-alpha.0createHash or createHmac.HashAlgorithmv0.0.0-alpha.0CipherAlgorithmv0.0.0-alpha.0InputEncodingv0.0.0-alpha.0DigestEncodingv0.0.0-alpha.0CryptoErrorCodev0.0.0-alpha.0Error.code by vael:crypto operations.Functions
Section titled “Functions”generateEnvelopeKey
Section titled “generateEnvelopeKey”export function generateEnvelopeKey(): Uint8Array;
Generate a 32-byte AES-256 key from the operating system CSPRNG.
Retire keys well before 2^32 encryptions under AES-GCM.
Uint8Array — A fresh 32-byte random Uint8Array key.TypeError— when any argument is supplied.Error— withcode = "VAEL_CRYPTO_RANDOM"when the CSPRNG fails.
import { generateEnvelopeKey } from "vael:crypto";
const key = generateEnvelopeKey();console.log(key.byteLength); // 32randomBytes
Section titled “randomBytes”export function randomBytes(length: number): Uint8Array;
Synchronously read length bytes (0..=8_388_608) from the OS CSPRNG.
| Name | Type | Description |
|---|---|---|
length | number | Non-negative integer up to 8 MiB (8_388_608). |
Uint8Array — Random bytes of length length.TypeError— whenlengthis not a number or arity is wrong.RangeError— whenlengthis not an integer in0..=8_388_608.Error— withcode = "VAEL_CRYPTO_RANDOM"when the CSPRNG fails.
import { randomBytes } from "vael:crypto";
const nonce = randomBytes(12);console.log(nonce.byteLength); // 12encrypt
Section titled “encrypt”export function encrypt(
key: Uint8Array,
plaintext: Uint8Array,
associatedData?: Uint8Array,
): Uint8Array;
Synchronously encrypt plaintext (max 8 MiB) into a versioned NEO1
AES-256-GCM envelope with a fresh random 96-bit nonce.
| Name | Type | Description |
|---|---|---|
key | Uint8Array | Exactly 32 bytes. |
plaintext | Uint8Array | Up to 8 MiB (8_388_608 bytes). |
associatedData optional | Uint8Array | Optional authenticated non-encrypted bytes (max 8 MiB). |
Uint8Array — Versioned NEO1 authenticated envelope bytes.TypeError— on invalid argument types or arity.Error— withcode"VAEL_CRYPTO_KEY","VAEL_CRYPTO_RANDOM","VAEL_CRYPTO_LIMIT", or"VAEL_CRYPTO_DETACHED".
import { decrypt, encrypt, generateEnvelopeKey } from "vael:crypto";
const key = generateEnvelopeKey();const aad = new Uint8Array([1, 2]);const sealed = encrypt(key, new Uint8Array([10, 20, 30]), aad);console.log(decrypt(key, sealed, aad));decrypt
Section titled “decrypt”export function decrypt(
key: Uint8Array,
envelope: Uint8Array,
associatedData?: Uint8Array,
): Uint8Array;
Synchronously verify and decrypt a NEO1 AES-256-GCM envelope.
Returns no plaintext when tag verification fails.
| Name | Type | Description |
|---|---|---|
key | Uint8Array | Exactly 32 bytes. |
envelope | Uint8Array | Up to 8 MiB + 34 bytes. |
associatedData optional | Uint8Array | Must match the value passed to encrypt. |
Uint8Array — Authenticated plaintext bytes.TypeError— on invalid argument types or arity.Error— withcode"VAEL_CRYPTO_AUTH","VAEL_CRYPTO_FORMAT","VAEL_CRYPTO_KEY","VAEL_CRYPTO_LIMIT", or"VAEL_CRYPTO_DETACHED".
createEncryptor
Section titled “createEncryptor”export function createEncryptor(
algorithm: CipherAlgorithm,
key: Uint8Array,
iv: Uint8Array,
options?: CipherOptions,
): Cipher;
Create a bounded stateful encryptor for "aes-256-cbc" or "aes-256-gcm".
| Name | Type | Description |
|---|---|---|
algorithm | CipherAlgorithm | "aes-256-cbc" or "aes-256-gcm" (case-insensitive). |
key | Uint8Array | Exactly 32 bytes. |
iv | Uint8Array | 16 bytes for CBC, 12 bytes for GCM. |
options optional | CipherOptions | CBC only ({ padding?: boolean }). |
TypeError— on invalid arguments or unsupported options.Error— withcode"VAEL_CRYPTO_ALGORITHM","VAEL_CRYPTO_KEY","VAEL_CRYPTO_IV","VAEL_CRYPTO_DETACHED", or"VAEL_CRYPTO_TOO_MANY_OBJECTS".
import { createDecryptor, createEncryptor, randomBytes } from "vael:crypto";
const key = randomBytes(32);const iv = randomBytes(12);const enc = createEncryptor("aes-256-gcm", key, iv);try { enc.update("secret"); const ct = enc.final(); const tag = enc.getAuthTag(); const dec = createDecryptor("aes-256-gcm", key, iv); try { dec.setAuthTag(tag); dec.update(ct); console.log(dec.final().byteLength); } finally { dec.close(); }} finally { enc.close();}createDecryptor
Section titled “createDecryptor”export function createDecryptor(
algorithm: CipherAlgorithm,
key: Uint8Array,
iv: Uint8Array,
options?: CipherOptions,
): Cipher;
Create a bounded stateful decryptor for "aes-256-cbc" or "aes-256-gcm".
GCM decryptors must call setAuthTag(tag) before final().
| Name | Type | Description |
|---|---|---|
algorithm | CipherAlgorithm | "aes-256-cbc" or "aes-256-gcm" (case-insensitive). |
key | Uint8Array | Exactly 32 bytes. |
iv | Uint8Array | 16 bytes for CBC, 12 bytes for GCM. |
options optional | CipherOptions | CBC only ({ padding?: boolean }). |
TypeError— on invalid arguments or unsupported options.Error— withcode"VAEL_CRYPTO_ALGORITHM","VAEL_CRYPTO_KEY","VAEL_CRYPTO_IV","VAEL_CRYPTO_DETACHED", or"VAEL_CRYPTO_TOO_MANY_OBJECTS".
createHash
Section titled “createHash”export function createHash(algorithm: HashAlgorithm): Hash;
Create a synchronous incremental SHA-2 hash ("sha256", "sha384", or "sha512").
| Name | Type | Description |
|---|---|---|
algorithm | HashAlgorithm | SHA-2 algorithm name ("sha256", "sha384", or "sha512"). |
Hash — Incremental Hash instance.TypeError— on wrong argument type or arity.Error— withcode"VAEL_CRYPTO_ALGORITHM"or"VAEL_CRYPTO_TOO_MANY_OBJECTS".
import { createHash } from "vael:crypto";
const hex = createHash("sha256").update("vael").digest("hex");console.log(hex);createHmac
Section titled “createHmac”export function createHmac(algorithm: HashAlgorithm, key: Uint8Array | string): Hash;
Create a synchronous incremental HMAC ("sha256", "sha384", or "sha512").
| Name | Type | Description |
|---|---|---|
algorithm | HashAlgorithm | SHA-2 algorithm name ("sha256", "sha384", or "sha512"). |
key | Uint8Array | string | Key bytes or UTF-8 string (max 1 MiB). |
Hash — Incremental Hash HMAC instance.TypeError— on wrong argument types or arity.Error— withcode"VAEL_CRYPTO_ALGORITHM","VAEL_CRYPTO_TOO_MANY_OBJECTS","VAEL_CRYPTO_LIMIT", or"VAEL_CRYPTO_DETACHED".
import { createHmac } from "vael:crypto";
const mac = createHmac("sha256", "secret-key").update("payload").digest("hex");console.log(mac);hashAsync
Section titled “hashAsync”export function hashAsync(algorithm: HashAlgorithm, data: Uint8Array | string): Promise<Uint8Array>;
export function hashAsync(
algorithm: HashAlgorithm,
data: Uint8Array | string,
encoding: DigestEncoding,
): Promise<string>;
Compute a one-shot SHA-2 digest on the bounded worker pool (max 64 pending jobs / 64 MiB total across async crypto workers; input max 16 MiB).
Rejects with VAEL_CRYPTO_BUSY if the worker budget is exhausted.
Compute a one-shot encoded SHA-2 digest string on the bounded worker pool.
| Name | Type | Description |
|---|---|---|
algorithm | HashAlgorithm | SHA-2 algorithm name ("sha256", "sha384", or "sha512"). |
data | Uint8Array | string | Input bytes or UTF-8 string (max 16 MiB). |
encoding optional | DigestEncoding | Output digest encoding ("hex", "base64", "base64url", "latin1", or "binary"). |
Promise<Uint8Array>— Promise resolving to raw digest bytes.Promise<string>— Promise resolving to the encoded digest string.
TypeError— on invalid arguments or unsupported encoding.Error— withcode"VAEL_CRYPTO_ALGORITHM","VAEL_CRYPTO_LIMIT","VAEL_CRYPTO_DETACHED","VAEL_CRYPTO_BUSY", or"VAEL_CRYPTO_NO_EXECUTOR".
import { hashAsync } from "vael:crypto";
const hex = await hashAsync("sha256", "hello", "hex");console.log(hex);hmacAsync
Section titled “hmacAsync”export function hmacAsync(
algorithm: HashAlgorithm,
key: Uint8Array | string,
data: Uint8Array | string,
): Promise<Uint8Array>;
export function hmacAsync(
algorithm: HashAlgorithm,
key: Uint8Array | string,
data: Uint8Array | string,
encoding: DigestEncoding,
): Promise<string>;
Compute a one-shot HMAC digest on the bounded worker pool (max 64 pending jobs / 64 MiB total).
Compute a one-shot encoded HMAC digest string on the bounded worker pool.
| Name | Type | Description |
|---|---|---|
algorithm | HashAlgorithm | SHA-2 algorithm name ("sha256", "sha384", or "sha512"). |
key | Uint8Array | string | Key bytes or UTF-8 string (max 1 MiB). |
data | Uint8Array | string | Input bytes or UTF-8 string (max 16 MiB). |
encoding optional | DigestEncoding | Output digest encoding. |
Promise<Uint8Array>— Promise resolving to raw HMAC digest bytes.Promise<string>— Promise resolving to the encoded HMAC digest string.
TypeError— on invalid arguments or unsupported encoding.Error— withcode"VAEL_CRYPTO_ALGORITHM","VAEL_CRYPTO_LIMIT","VAEL_CRYPTO_DETACHED","VAEL_CRYPTO_BUSY", or"VAEL_CRYPTO_NO_EXECUTOR".
pbkdf2
Section titled “pbkdf2”export function pbkdf2(
algorithm: HashAlgorithm,
password: Uint8Array | string,
salt: Uint8Array | string,
iterations: number,
length: number,
): Uint8Array;
Synchronously derive key material using PBKDF2-HMAC-SHA2.
| Name | Type | Description |
|---|---|---|
algorithm | HashAlgorithm | "sha256", "sha384", or "sha512" (case-insensitive). |
password | Uint8Array | string | Bytes or UTF-8 string (max 1 MiB). |
salt | Uint8Array | string | Bytes or UTF-8 string (max 1 MiB). |
iterations | number | Integer in 1..=1_000_000. |
length | number | Output byte length in 1..=1024. |
Uint8Array — Derived key bytes of length length.TypeError— on wrong argument types or arity.RangeError— wheniterationsorlengthis outside its bounds.Error— withcode"VAEL_CRYPTO_ALGORITHM","VAEL_CRYPTO_LIMIT", or"VAEL_CRYPTO_DETACHED".
import { pbkdf2, randomBytes } from "vael:crypto";
const salt = randomBytes(16);const derived = pbkdf2("sha256", "passphrase", salt, 100_000, 32);console.log(derived.byteLength); // 32pbkdf2Async
Section titled “pbkdf2Async”export function pbkdf2Async(
algorithm: HashAlgorithm,
password: Uint8Array | string,
salt: Uint8Array | string,
iterations: number,
length: number,
): Promise<Uint8Array>;
Derive key material using PBKDF2-HMAC-SHA2 on the bounded worker pool.
Shares the 64-job / 64 MiB pending async crypto budget (VAEL_CRYPTO_BUSY).
| Name | Type | Description |
|---|---|---|
algorithm | HashAlgorithm | "sha256", "sha384", or "sha512" (case-insensitive). |
password | Uint8Array | string | Bytes or UTF-8 string (max 1 MiB). |
salt | Uint8Array | string | Bytes or UTF-8 string (max 1 MiB). |
iterations | number | Integer in 1..=1_000_000. |
length | number | Output byte length in 1..=1024. |
Promise<Uint8Array> — Promise resolving to derived key bytes of length length.TypeError— on wrong argument types or arity.RangeError— wheniterationsorlengthis outside its bounds.Error— withcode"VAEL_CRYPTO_ALGORITHM","VAEL_CRYPTO_LIMIT","VAEL_CRYPTO_DETACHED","VAEL_CRYPTO_BUSY", or"VAEL_CRYPTO_NO_EXECUTOR".
bcryptHash
Section titled “bcryptHash”export function bcryptHash(password: Uint8Array | string, cost?: number): string;
Synchronously hash a password with bcrypt, returning a 60-character $2b$
modular-crypt string.
| Name | Type | Description |
|---|---|---|
password | Uint8Array | string | Bytes or UTF-8 string (max 72 bytes; never truncated). |
cost optional | number | Logarithmic work factor integer in 4..=16 (default: 10). |
string — 60-character $2b$ bcrypt hash string.TypeError— on wrong argument types or arity.RangeError— whencostis not an integer in4..=16.Error— withcode"VAEL_CRYPTO_LIMIT","VAEL_CRYPTO_RANDOM", or"VAEL_CRYPTO_DETACHED".
import { bcryptHash, bcryptVerify } from "vael:crypto";
const hash = bcryptHash("correct horse battery staple", 4);console.log(bcryptVerify("correct horse battery staple", hash)); // truebcryptHashAsync
Section titled “bcryptHashAsync”export function bcryptHashAsync(password: Uint8Array | string, cost?: number): Promise<string>;
Hash a password with bcrypt on the bounded worker pool ($2b$ format,
max 72 bytes, cost in 4..=16, default 10).
| Name | Type | Description |
|---|---|---|
password | Uint8Array | string | Bytes or UTF-8 string (max 72 bytes; never truncated). |
cost optional | number | Logarithmic work factor integer in 4..=16 (default: 10). |
Promise<string> — Promise resolving to a 60-character $2b$ bcrypt hash string.TypeError— on wrong argument types or arity.RangeError— whencostis not an integer in4..=16.Error— withcode"VAEL_CRYPTO_LIMIT","VAEL_CRYPTO_RANDOM","VAEL_CRYPTO_DETACHED","VAEL_CRYPTO_BUSY", or"VAEL_CRYPTO_NO_EXECUTOR".
bcryptVerify
Section titled “bcryptVerify”export function bcryptVerify(password: Uint8Array | string, hash: string): boolean;
Synchronously verify password against a $2a$/$2b$/$2y$ bcrypt hash
in constant time.
Passwords over 72 bytes and malformed or over-cost (> 16) hashes return false.
| Name | Type | Description |
|---|---|---|
password | Uint8Array | string | Candidate password bytes or UTF-8 string. |
hash | string | Modular-crypt bcrypt hash string ($2a$, $2b$, or $2y$). |
boolean — true if password matches hash.TypeError— on wrong argument types or arity.Error— withcode = "VAEL_CRYPTO_DETACHED"when a detached buffer is supplied.
bcryptVerifyAsync
Section titled “bcryptVerifyAsync”export function bcryptVerifyAsync(password: Uint8Array | string, hash: string): Promise<boolean>;
Verify password against a bcrypt hash on the bounded worker pool.
| Name | Type | Description |
|---|---|---|
password | Uint8Array | string | Candidate password bytes or UTF-8 string. |
hash | string | Modular-crypt bcrypt hash string. |
TypeError— on wrong argument types or arity.Error— withcode"VAEL_CRYPTO_DETACHED","VAEL_CRYPTO_BUSY", or"VAEL_CRYPTO_NO_EXECUTOR".
shamirSplit
Section titled “shamirSplit”export function shamirSplit(
secret: Uint8Array,
threshold: number,
shareCount: number,
): ShamirShare[];
Synchronously split secret into shareCount GF(256) Shamir shares
requiring threshold shares to reconstruct.
Shares are not authenticated. Limits: secret 1..=8 MiB,
2 <= threshold <= shareCount <= 255, secret.length * shareCount <= 64 MiB.
Rejects SharedArrayBuffer-backed views with VAEL_CRYPTO_SHAMIR_SHARED.
| Name | Type | Description |
|---|---|---|
secret | Uint8Array | Non-empty secret byte slice (1..=8 MiB). |
threshold | number | Minimum shares needed for reconstruction (2..=shareCount). |
shareCount | number | Total number of shares to produce (threshold..=255). |
TypeError— on wrong argument types or arity.RangeError— whenthresholdorshareCountis out of range.Error— withcode"VAEL_CRYPTO_LIMIT","VAEL_CRYPTO_RANDOM","VAEL_CRYPTO_DETACHED", or"VAEL_CRYPTO_SHAMIR_SHARED".
import { shamirCombine, shamirSplit } from "vael:crypto";
const shares = shamirSplit(new Uint8Array([1, 2, 3, 4]), 2, 3);const recovered = shamirCombine([shares[0], shares[2]]);console.log(recovered);shamirSplitAsync
Section titled “shamirSplitAsync”export function shamirSplitAsync(
secret: Uint8Array,
threshold: number,
shareCount: number,
): Promise<ShamirShare[]>;
Split secret into GF(256) Shamir shares on the bounded worker pool.
| Name | Type | Description |
|---|---|---|
secret | Uint8Array | Non-empty secret byte slice (1..=8 MiB). |
threshold | number | Minimum shares needed for reconstruction (2..=shareCount). |
shareCount | number | Total number of shares to produce (threshold..=255). |
TypeError— on wrong argument types or arity.RangeError— whenthresholdorshareCountis out of range.Error— withcode"VAEL_CRYPTO_LIMIT","VAEL_CRYPTO_RANDOM","VAEL_CRYPTO_DETACHED","VAEL_CRYPTO_SHAMIR_SHARED","VAEL_CRYPTO_BUSY", or"VAEL_CRYPTO_NO_EXECUTOR".
shamirCombine
Section titled “shamirCombine”export function shamirCombine(shares: readonly ShamirShare[], threshold?: number): Uint8Array;
Synchronously reconstruct a secret from GF(256) Shamir shares.
Shares are not authenticated. Limits: 2..=255 shares with identical
non-zero length (max 8 MiB per share, 64 MiB total).
| Name | Type | Description |
|---|---|---|
shares | readonly ShamirShare[] | At least 2 valid ShamirShare records with identical non-zero byte lengths. |
threshold optional | number | Optional minimum share count (2..=255, <= shares.length). |
Uint8Array — Reconstructed secret bytes.TypeError— on wrong argument types or arity.RangeError— whenthresholdor share index is out of range.Error— withcode"VAEL_CRYPTO_LIMIT","VAEL_CRYPTO_DETACHED","VAEL_CRYPTO_SHAMIR_DUPLICATE","VAEL_CRYPTO_SHAMIR_LENGTH", or"VAEL_CRYPTO_SHAMIR_SHARED".
shamirCombineAsync
Section titled “shamirCombineAsync”export function shamirCombineAsync(
shares: readonly ShamirShare[],
threshold?: number,
): Promise<Uint8Array>;
Reconstruct a secret from GF(256) Shamir shares on the bounded worker pool.
| Name | Type | Description |
|---|---|---|
shares | readonly ShamirShare[] | At least 2 valid ShamirShare records with identical non-zero byte lengths. |
threshold optional | number | Optional minimum share count (2..=255, <= shares.length). |
Promise<Uint8Array> — Promise resolving to reconstructed secret bytes.TypeError— on wrong argument types or arity.RangeError— whenthresholdor share index is out of range.Error— withcode"VAEL_CRYPTO_LIMIT","VAEL_CRYPTO_DETACHED","VAEL_CRYPTO_SHAMIR_DUPLICATE","VAEL_CRYPTO_SHAMIR_LENGTH","VAEL_CRYPTO_SHAMIR_SHARED","VAEL_CRYPTO_BUSY", or"VAEL_CRYPTO_NO_EXECUTOR".
blake3
Section titled “blake3”export function blake3(data: Uint8Array | string, options?: Blake3Options): Uint8Array;
Compute a synchronous BLAKE3 digest or extendable output (XOF) of data.
| Name | Type | Description |
|---|---|---|
data | Uint8Array | string | Input bytes or UTF-8 string. |
options optional | Blake3Options | Optional XOF output length (1..=65_536, default 32). |
Uint8Array — Digest bytes of length options?.outputLength ?? 32.TypeError— on invalid argument types or arity.RangeError— whenoutputLengthis outside1..=65_536.Error— withcode"VAEL_CRYPTO_DETACHED"or"VAEL_CRYPTO_LIMIT".
import { blake3 } from "vael:crypto";
const digest = blake3("hello");const xof = blake3("hello", { outputLength: 64 });console.log(digest.byteLength, xof.byteLength);blake3Keyed
Section titled “blake3Keyed”export function blake3Keyed(
key: Uint8Array,
data: Uint8Array | string,
options?: Blake3Options,
): Uint8Array;
Compute a synchronous keyed BLAKE3 MAC/PRF over data using a 32-byte
key.
| Name | Type | Description |
|---|---|---|
key | Uint8Array | Exactly 32 key bytes. |
data | Uint8Array | string | Input bytes or UTF-8 string. |
options optional | Blake3Options | Optional XOF output length (1..=65_536, default 32). |
Uint8Array — Keyed digest bytes of length options?.outputLength ?? 32.TypeError— on invalid argument types or arity.RangeError— whenoutputLengthis outside1..=65_536.Error— withcode"VAEL_CRYPTO_KEY","VAEL_CRYPTO_DETACHED", or"VAEL_CRYPTO_LIMIT".
blake3DeriveKey
Section titled “blake3DeriveKey”export function blake3DeriveKey(
context: string,
keyMaterial: Uint8Array | string,
options?: Blake3Options,
): Uint8Array;
Synchronously derive key material from keyMaterial using BLAKE3 key
derivation with domain-separation context.
| Name | Type | Description |
|---|---|---|
context | string | Domain-separation context string. |
keyMaterial | Uint8Array | string | Input key material bytes or UTF-8 string. |
options optional | Blake3Options | Optional XOF output length (1..=65_536, default 32). |
Uint8Array — Derived key bytes of length options?.outputLength ?? 32.TypeError— on invalid argument types or arity.RangeError— whenoutputLengthis outside1..=65_536.Error— withcode"VAEL_CRYPTO_DETACHED"or"VAEL_CRYPTO_LIMIT".
blake2b
Section titled “blake2b”export function blake2b(data: Uint8Array | string, options?: Blake2Options): Uint8Array;
Compute a synchronous BLAKE2b digest or keyed MAC over data.
| Name | Type | Description |
|---|---|---|
data | Uint8Array | string | Input bytes or UTF-8 string. |
options optional | Blake2Options | Optional outputLength (1..=64, default 64) and key (0..=64 bytes). |
Uint8Array — Digest bytes of length options?.outputLength ?? 64.TypeError— on invalid argument types or arity.RangeError— whenoutputLengthis outside1..=64.Error— withcode"VAEL_CRYPTO_KEY","VAEL_CRYPTO_DETACHED", or"VAEL_CRYPTO_LIMIT".
blake2s
Section titled “blake2s”export function blake2s(data: Uint8Array | string, options?: Blake2Options): Uint8Array;
Compute a synchronous BLAKE2s digest or keyed MAC over data.
| Name | Type | Description |
|---|---|---|
data | Uint8Array | string | Input bytes or UTF-8 string. |
options optional | Blake2Options | Optional outputLength (1..=32, default 32) and key (0..=32 bytes). |
Uint8Array — Digest bytes of length options?.outputLength ?? 32.TypeError— on invalid argument types or arity.RangeError— whenoutputLengthis outside1..=32.Error— withcode"VAEL_CRYPTO_KEY","VAEL_CRYPTO_DETACHED", or"VAEL_CRYPTO_LIMIT".
Interfaces
Section titled “Interfaces”CipherOptions
Section titled “CipherOptions”export interface CipherOptions {
padding?: boolean;
}
Options accepted by createEncryptor and createDecryptor (aes-256-cbc
only; aes-256-gcm accepts no options).
| Property | Type | Description | Since |
|---|---|---|---|
padding optional | boolean | Enable or disable PKCS#7 padding for aes-256-cbc (default: true). | v0.0.0-alpha.0 |
Blake3Options
Section titled “Blake3Options”export interface Blake3Options {
outputLength?: number;
}
Options accepted by blake3, blake3Keyed, and blake3DeriveKey.
| Property | Type | Description | Since |
|---|---|---|---|
outputLength optional | number | Output XOF digest length in bytes (1..=65_536, default: 32). | v0.0.0-alpha.2 |
Blake2Options
Section titled “Blake2Options”export interface Blake2Options {
outputLength?: number;
key?: Uint8Array;
}
Options accepted by blake2b and blake2s.
| Property | Type | Description | Since |
|---|---|---|---|
outputLength optional | number | Output digest length in bytes (1..=64 for blake2b, default 64; 1..=32 for blake2s, default 32). | v0.0.0-alpha.2 |
key optional | Uint8Array | Optional MAC key bytes (0..=64 for blake2b, 0..=32 for blake2s; an empty Uint8Array behaves as unkeyed per RFC 7693 Section 2.5). | v0.0.0-alpha.2 |
ShamirShare
Section titled “ShamirShare”export interface ShamirShare {
readonly index: number;
readonly value: Uint8Array;
}
Frozen share record produced by shamirSplit / shamirSplitAsync and
consumed by shamirCombine / shamirCombineAsync.
| Property | Type | Description | Since |
|---|---|---|---|
index readonly | number | One-based GF(256) share index (1..=255). | v0.0.0-alpha.0 |
value readonly | Uint8Array | Share bytes (same length as the secret; record property is frozen, array elements remain mutable). | v0.0.0-alpha.0 |
Cipher
Section titled “Cipher”export interface Cipher {
update(data: Uint8Array | string, encoding?: InputEncoding): Uint8Array;
final(): Uint8Array;
setAAD(aad: Uint8Array): this;
setAuthTag(tag: Uint8Array): this;
getAuthTag(): Uint8Array;
setAutoPadding(enabled: boolean): this;
close(): void;
dispose(): void;
}
Bounded, stateful synchronous AES-256-CBC or AES-256-GCM cipher returned
by createEncryptor or createDecryptor.
Call close() or dispose() in a finally block (even after final())
to stay within the per-runtime open-object (64) and buffered-byte (64 MiB) caps.
Cipher.update
Section titled “Cipher.update”update(data: Uint8Array | string, encoding?: InputEncoding): Uint8Array;
Accumulate bytes or a UTF-8 string into the cipher (at most 8 MiB per call).
Always returns an empty Uint8Array; output is produced by final().
| Name | Type | Description |
|---|---|---|
data | Uint8Array | string | Input bytes or UTF-8 string (max 8 MiB per call). |
encoding optional | InputEncoding | Optional string input encoding ("utf8" / "utf-8" when data is a string). |
TypeError— on wrong argument types or supplying an encoding with binary input.Error— withcode"VAEL_CRYPTO_CLOSED","VAEL_CRYPTO_STATE","VAEL_CRYPTO_LIMIT", or"VAEL_CRYPTO_DETACHED".
Cipher.final
Section titled “Cipher.final”final(): Uint8Array;
Perform the cipher operation over all buffered input and finalize the cipher. For GCM decryption, verifies the authentication tag before returning any plaintext.
Uint8Array — Finalized ciphertext or authenticated plaintext bytes.TypeError— when any argument is supplied.Error— withcode"VAEL_CRYPTO_CLOSED","VAEL_CRYPTO_STATE","VAEL_CRYPTO_AUTH","VAEL_CRYPTO_PADDING","VAEL_CRYPTO_TAG", or"VAEL_CRYPTO_LIMIT".
Cipher.setAAD
Section titled “Cipher.setAAD”setAAD(aad: Uint8Array): this;
Set GCM associated data (aes-256-gcm only, at most once before
update or final; max 8 MiB).
| Name | Type | Description |
|---|---|---|
aad | Uint8Array | Associated authenticated data bytes (max 8 MiB). |
this — this for chaining.TypeError— whenaadis not aUint8Arrayor arity is wrong.Error— withcode"VAEL_CRYPTO_CLOSED","VAEL_CRYPTO_STATE","VAEL_CRYPTO_UNSUPPORTED", or"VAEL_CRYPTO_LIMIT".
Cipher.setAuthTag
Section titled “Cipher.setAuthTag”setAuthTag(tag: Uint8Array): this;
Set the expected 16-byte GCM authentication tag before final()
(aes-256-gcm decryptors only).
| Name | Type | Description |
|---|---|---|
tag | Uint8Array | Expected 16-byte GCM authentication tag. |
this — this for chaining.TypeError— whentagis not aUint8Arrayor arity is wrong.Error— withcode"VAEL_CRYPTO_CLOSED","VAEL_CRYPTO_STATE","VAEL_CRYPTO_UNSUPPORTED", or"VAEL_CRYPTO_TAG".
Cipher.getAuthTag
Section titled “Cipher.getAuthTag”getAuthTag(): Uint8Array;
Return the 16-byte GCM authentication tag produced by final()
(aes-256-gcm encryptors only, after final()).
Uint8Array — The 16-byte GCM authentication tag.TypeError— when any argument is supplied.Error— withcode"VAEL_CRYPTO_CLOSED","VAEL_CRYPTO_STATE", or"VAEL_CRYPTO_UNSUPPORTED".
Cipher.setAutoPadding
Section titled “Cipher.setAutoPadding”setAutoPadding(enabled: boolean): this;
Enable or disable CBC PKCS#7 padding before final() (aes-256-cbc only).
| Name | Type | Description |
|---|---|---|
enabled | boolean | Whether PKCS#7 padding is enabled (true by default). |
this — this for chaining.TypeError— whenenabledis not a boolean or arity is wrong.Error— withcode"VAEL_CRYPTO_CLOSED","VAEL_CRYPTO_STATE", or"VAEL_CRYPTO_UNSUPPORTED".
Cipher.close
Section titled “Cipher.close”close(): void;
Release this cipher’s native slot and buffered bytes. Idempotent.
Later calls throw VAEL_CRYPTO_CLOSED.
voidCipher.dispose
Section titled “Cipher.dispose”dispose(): void;
Alias for close(). Idempotent.
voidexport interface Hash {
update(data: Uint8Array | string, encoding?: InputEncoding): this;
digest(): Uint8Array;
digest(encoding: DigestEncoding): string;
close(): void;
dispose(): void;
}
Synchronous incremental SHA-2 hash or HMAC returned by createHash or
createHmac.
Open digest objects are capped at 1024 per runtime; call close() or
dispose() if not calling digest().
Hash.update
Section titled “Hash.update”update(data: Uint8Array | string, encoding?: InputEncoding): this;
Add bytes or a UTF-8 string (max 16 MiB per update).
| Name | Type | Description |
|---|---|---|
data | Uint8Array | string | Input bytes or UTF-8 string (max 16 MiB). |
encoding optional | InputEncoding | Optional string encoding ("utf8" / "utf-8" when data is a string). |
this — this for chaining.TypeError— on wrong argument types or supplying an encoding with binary input.Error— withcode"VAEL_CRYPTO_CLOSED","VAEL_CRYPTO_DIGESTED","VAEL_CRYPTO_LIMIT", or"VAEL_CRYPTO_DETACHED".
Hash.digest
Section titled “Hash.digest”digest(): Uint8Array;
digest(encoding: DigestEncoding): string;
Consume the hash state and return raw digest bytes.
Consume the hash state and return the digest encoded as a string.
| Name | Type | Description |
|---|---|---|
encoding optional | DigestEncoding | Output digest encoding ("hex", "base64", "base64url", "latin1", or "binary"). |
Uint8Array— Raw digest bytes.string— Encoded digest string.
Error— withcode"VAEL_CRYPTO_CLOSED","VAEL_CRYPTO_DIGESTED", or"VAEL_CRYPTO_LIMIT".TypeError— on unsupported encoding (checked before consuming state).
Hash.close
Section titled “Hash.close”close(): void;
Release native state without producing a digest. Idempotent.
voidHash.dispose
Section titled “Hash.dispose”dispose(): void;
Alias for close(). Idempotent.
voidType Aliases
Section titled “Type Aliases”HashAlgorithm
Section titled “HashAlgorithm”export type HashAlgorithm = "sha256" | "sha384" | "sha512" | (string & {});
Supported SHA-2 hash and HMAC algorithms (case-insensitive).
CipherAlgorithm
Section titled “CipherAlgorithm”export type CipherAlgorithm = "aes-256-cbc" | "aes-256-gcm" | (string & {});
Supported symmetric cipher algorithms (case-insensitive).
InputEncoding
Section titled “InputEncoding”export type InputEncoding = "utf8" | "utf-8" | (string & {});
Supported string input encoding (UTF-8 only, case-insensitive).
DigestEncoding
Section titled “DigestEncoding”export type DigestEncoding = "hex" | "base64" | "base64url" | "latin1" | "binary" | (string & {});
Supported digest output encodings (case-insensitive).
CryptoErrorCode
Section titled “CryptoErrorCode”export type CryptoErrorCode =
| "VAEL_CRYPTO_KEY"
| "VAEL_CRYPTO_FORMAT"
| "VAEL_CRYPTO_AUTH"
| "VAEL_CRYPTO_RANDOM"
| "VAEL_CRYPTO_LIMIT"
| "VAEL_CRYPTO_DETACHED"
| "VAEL_CRYPTO_ALGORITHM"
| "VAEL_CRYPTO_IV"
| "VAEL_CRYPTO_TAG"
| "VAEL_CRYPTO_PADDING"
| "VAEL_CRYPTO_STATE"
| "VAEL_CRYPTO_CLOSED"
| "VAEL_CRYPTO_UNSUPPORTED"
| "VAEL_CRYPTO_TOO_MANY_OBJECTS"
| "VAEL_CRYPTO_ENCODING"
| "VAEL_CRYPTO_DIGESTED"
| "VAEL_CRYPTO_BUSY"
| "VAEL_CRYPTO_NO_EXECUTOR"
| "VAEL_CRYPTO_INTERNAL"
| "VAEL_CRYPTO_SHAMIR_DUPLICATE"
| "VAEL_CRYPTO_SHAMIR_LENGTH"
| "VAEL_CRYPTO_SHAMIR_SHARED";
Error codes reported on Error.code by vael:crypto operations.
