diff --git a/src/blst/index.ts b/src/blst/index.ts index 380f1d7..49d9bbf 100644 --- a/src/blst/index.ts +++ b/src/blst/index.ts @@ -8,10 +8,10 @@ export * from "../constants"; export {Keypair, PrivateKey, PublicKey, Signature}; -export async function initBLS() { +export async function initBLS(): Promise { // Native bindings require no init() call } -export function destroy() { +export function destroy(): void { // Native bindings require no destroy() call } diff --git a/src/blst/signature.ts b/src/blst/signature.ts index 508fedf..eed4ded 100644 --- a/src/blst/signature.ts +++ b/src/blst/signature.ts @@ -42,6 +42,14 @@ export class Signature { ); } + toBytes(): Buffer { + return Buffer.from(this.affine.toBytes()); + } + + toHex(): string { + return bytesToHex(this.toBytes()); + } + private aggregateVerify(msgs: Uint8Array[], pks: blst.PublicKey[]): boolean { // If this set is simply an infinity signature and infinity pubkey then skip verification. // This has the effect of always declaring that this sig/pubkey combination is valid. @@ -52,12 +60,4 @@ export class Signature { return blst.aggregateVerify(msgs, pks, this.affine); } - - toBytes(): Buffer { - return Buffer.from(this.affine.toBytes()); - } - - toHex(): string { - return bytesToHex(this.toBytes()); - } } diff --git a/src/herumi/index.ts b/src/herumi/index.ts index c4de6f8..4ee3138 100644 --- a/src/herumi/index.ts +++ b/src/herumi/index.ts @@ -3,7 +3,6 @@ import {PrivateKey} from "./privateKey"; import {PublicKey} from "./publicKey"; import {Signature} from "./signature"; import {initBLS, destroy} from "./context"; -import {PUBLIC_KEY_LENGTH} from "../constants"; import assert from "assert"; import {toBuffer} from "../helpers/utils"; diff --git a/test/benchmark/runner.ts b/test/benchmark/runner.ts index 19f06fa..6b28931 100644 --- a/test/benchmark/runner.ts +++ b/test/benchmark/runner.ts @@ -8,7 +8,7 @@ export function runBenchmark({ testRunner: (input: T) => R; runs?: number; id: string; -}) { +}): void { const diffsNanoSec: bigint[] = []; for (let i = 0; i < runs; i++) { diff --git a/test/switch.ts b/test/switch.ts index 06ce9c6..19765bb 100644 --- a/test/switch.ts +++ b/test/switch.ts @@ -4,6 +4,7 @@ import herumi from "../src/herumi"; export type Implementation = "blst" | "herumi"; export const implementations: Implementation[] = ["blst", "herumi"]; +// eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function getBls(implementation: Implementation) { switch (implementation) { case "blst": diff --git a/test/unit/index.test.ts b/test/unit/index.test.ts index 0733edc..4001b82 100644 --- a/test/unit/index.test.ts +++ b/test/unit/index.test.ts @@ -1,16 +1,9 @@ import {expect} from "chai"; import {forEachImplementation} from "../switch"; -import {getRandomBytes} from "../../src/helpers/utils"; - -function randomMessage(): Uint8Array { - return getRandomBytes(32); -} - -function getN(n: number, getter: () => T): T[] { - return Array.from({length: n}, () => getter()); -} +import {getN, randomMessage} from "../util"; forEachImplementation((bls) => { + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type function getRandomData() { const sk = bls.PrivateKey.fromKeygen(); const pk = sk.toPublicKey(); @@ -53,7 +46,7 @@ forEachImplementation((bls) => { }); describe("verify multiple", () => { - it(`should verify aggregated signatures`, () => { + it("should verify aggregated signatures", () => { const sks = getN(4, () => bls.PrivateKey.fromKeygen()); const msgs = getN(2, () => randomMessage()); const pks = sks.map((sk) => sk.toPublicKey()); diff --git a/test/util.ts b/test/util.ts index 50478de..2a97bf4 100644 --- a/test/util.ts +++ b/test/util.ts @@ -1,3 +1,5 @@ +import {getRandomBytes} from "../src/helpers/utils"; + export function fromHexString(hex: string): Buffer { return Buffer.from(hex.replace("0x", ""), "hex"); } @@ -5,3 +7,11 @@ export function fromHexString(hex: string): Buffer { export function toHexString(bytes: Buffer | Uint8Array): string { return `0x${Buffer.from(bytes).toString("hex")}`; } + +export function randomMessage(): Uint8Array { + return getRandomBytes(32); +} + +export function getN(n: number, getter: () => T): T[] { + return Array.from({length: n}, () => getter()); +}