API reference / @evolu/common / Crypto / RandomBytes

Interface: RandomBytes

Defined in: packages/common/src/Crypto.ts:13

Methods

create()

Defined in: packages/common/src/Crypto.ts:40

Creates cryptographically secure random bytes with type-safe length branding.

Uses the operating system's cryptographically secure random number generator (crypto.getRandomValues) to generate high-quality entropy suitable for cryptographic operations.

Type Safety

Returns specific branded types for common sizes:

  • Random16 for 16-byte values (128 bits)
  • Random32 for 32-byte values (256 bits)
  • Random64 for 64-byte values (512 bits)
  • Random for any other size

Example

const nonce = randomBytes.create(16); // Type: Random16
const key = randomBytes.create(32); // Type: Random32
const seed = randomBytes.create(64); // Type: Random64
const custom = randomBytes.create(48); // Type: Random
Parameters
ParameterType
bytesLength16
Returns

Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length16">

Defined in: packages/common/src/Crypto.ts:41

Parameters
ParameterType
bytesLength32
Returns

Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length32">

Defined in: packages/common/src/Crypto.ts:42

Parameters
ParameterType
bytesLength64
Returns

Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length64">

Defined in: packages/common/src/Crypto.ts:43

Parameters
ParameterType
bytesLengthnumber
Returns

Uint8Array<ArrayBufferLike> & Brand<"Entropy">

Was this page helpful?