js-waku/packages/tests/src/random_array.ts
Sasha 72f97d4545
feat: add 1MB restriction to LightPush and Relay (#1351)
* 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
2023-05-17 23:40:52 +02:00

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;
}