This repository has been archived on 2023-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
chainsafe-bls/test/util.ts

24 lines
606 B
TypeScript

import {randomBytes} from "../src/helpers/index.js";
export function randomMessage(): Uint8Array {
return randomBytes(32);
}
export function getN<T>(n: number, getter: () => T): T[] {
return Array.from({length: n}, () => getter());
}
export function range(n: number): number[] {
const nums: number[] = [];
for (let i = 0; i < n; i++) nums.push(i);
return nums;
}
/**
* ONLY for NodeJS tests, for any other use src/helpers/hex hexToBytes()
* Serves as a "ground-truth" reference
*/
export function hexToBytesNode(hex: string): Buffer {
return Buffer.from(hex.replace("0x", ""), "hex");
}