Skip to content

generateRandomBytes()

SIP Protocol API Reference v0.7.0


SIP Protocol API Reference / generateRandomBytes

generateRandomBytes(length): `0x${string}`

Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:3399

Generate cryptographically secure random bytes

Uses the platform’s secure random source (Web Crypto API in browsers, crypto.randomBytes in Node.js) to generate unpredictable random data.

Use cases:

  • Generate private keys
  • Create nonces for encryption
  • Produce blinding factors for commitments
  • Generate ephemeral keypairs

number

Number of random bytes to generate

`0x${string}`

Random bytes as hex string with 0x prefix

const privateKey = generateRandomBytes(32)
console.log(privateKey) // "0xabc123...def" (64 hex chars)
const nonce = generateRandomBytes(24) // For XChaCha20