mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-09 01:03:11 +00:00
16 lines
441 B
TypeScript
16 lines
441 B
TypeScript
|
|
import crypto from "crypto";
|
||
|
|
|
||
|
|
export function generateRandomUint8Array(sizeInBytes: number): Uint8Array {
|
||
|
|
const chunkSize = 65536; // Maximum entropy available
|
||
|
|
const chunks = Math.ceil(sizeInBytes / chunkSize);
|
||
|
|
const buffer = new Uint8Array(sizeInBytes);
|
||
|
|
|
||
|
|
for (let i = 0; i < chunks; i++) {
|
||
|
|
const chunk = new Uint8Array(chunkSize);
|
||
|
|
crypto.getRandomValues(chunk);
|
||
|
|
buffer.set(chunk, i * chunkSize);
|
||
|
|
}
|
||
|
|
|
||
|
|
return buffer;
|
||
|
|
}
|