iso-base
Version:
Isomorphic Utils
14 lines (12 loc) • 342 B
JavaScript
export const webcrypto = globalThis.crypto
/**
* Secure PRNG - Random bytes from webcrypto
*
* @param {number} length
*/
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")
}