UNPKG

iso-web

Version:

Isomorphic web apis utilities for fetch, event target, signals, crypto and doh.

14 lines (12 loc) 375 B
export const webcrypto = globalThis.crypto /** * Secure PRNG - Random bytes from webcrypto * * @param {number} length - The length of the random bytes */ export function randomBytes(length = 32) { if (globalThis.crypto) { return globalThis.crypto.getRandomValues(new Uint8Array(length)) } throw new Error("The environment doesn't have randomBytes function") }