mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-08 00:33:12 +00:00
* add 1MB restriction to LightPush and Relay * fix condition * improve lightPush test * update test * add isomorphic-webcrypto * import module * add errors to SendResult and tests * fix lint
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;
|
|
}
|