mirror of https://github.com/waku-org/js-waku.git
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;
|
|
}
|