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.
2020-11-25 15:11:02 +00:00
|
|
|
import crypto from "crypto";
|
2020-11-20 12:27:30 +00:00
|
|
|
|
2020-11-25 16:09:44 +00:00
|
|
|
export function fromHexString(hex: string): Uint8Array {
|
|
|
|
return Uint8Array.from(Buffer.from(hex.replace("0x", ""), "hex"));
|
2020-11-13 21:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function toHexString(bytes: Buffer | Uint8Array): string {
|
|
|
|
return `0x${Buffer.from(bytes).toString("hex")}`;
|
|
|
|
}
|
2020-11-20 12:27:30 +00:00
|
|
|
|
|
|
|
export function randomMessage(): Uint8Array {
|
2020-11-25 15:11:02 +00:00
|
|
|
return crypto.randomBytes(32);
|
2020-11-20 12:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getN<T>(n: number, getter: () => T): T[] {
|
|
|
|
return Array.from({length: n}, () => getter());
|
|
|
|
}
|