API reference › @evolu/common › Crypto › RandomBytes
Defined in: packages/common/src/Crypto.ts:28
Methods
create()
Call Signature
create(bytesLength: 16): Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length16">;
Defined in: packages/common/src/Crypto.ts:57
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:
Random16for 16-byte values (128 bits)Random24for 24-byte values (192 bits)Random32for 32-byte values (256 bits)Random64for 64-byte values (512 bits)Randomfor any other size
Example
const nonce = randomBytes.create(16); // Type: Random16
const nonce24 = randomBytes.create(24); // Type: Random24
const key = randomBytes.create(32); // Type: Random32
const seed = randomBytes.create(64); // Type: Random64
const custom = randomBytes.create(48); // Type: Random
Parameters
| Parameter | Type |
|---|---|
bytesLength | 16 |
Returns
Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length16">
Call Signature
create(bytesLength: 24): Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length24">;
Defined in: packages/common/src/Crypto.ts:58
Parameters
| Parameter | Type |
|---|---|
bytesLength | 24 |
Returns
Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length24">
Call Signature
create(bytesLength: 32): Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length32">;
Defined in: packages/common/src/Crypto.ts:59
Parameters
| Parameter | Type |
|---|---|
bytesLength | 32 |
Returns
Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length32">
Call Signature
create(bytesLength: 64): Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length64">;
Defined in: packages/common/src/Crypto.ts:60
Parameters
| Parameter | Type |
|---|---|
bytesLength | 64 |
Returns
Uint8Array<ArrayBufferLike> & Brand<"Entropy"> & Brand<"Length64">
Call Signature
create(bytesLength: number): Uint8Array<ArrayBufferLike> & Brand<"Entropy">;
Defined in: packages/common/src/Crypto.ts:61
Parameters
| Parameter | Type |
|---|---|
bytesLength | number |
Returns
Uint8Array<ArrayBufferLike> & Brand<"Entropy">