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/spec-blst/aggregate_sigs_verify.test.ts

40 lines
1.1 KiB
TypeScript

import path from "path";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
import {aggregateVerify, Signature, PublicKey} from "@chainsafe/blst-ts";
import {fromHexString} from "../util";
interface IAggregateSigsVerifyTestCase {
data: {
input: {
pubkeys: string[];
messages: string[];
signature: string;
};
output: boolean;
};
}
describeDirectorySpecTest<IAggregateSigsVerifyTestCase, boolean>(
"BLS - aggregate sigs verify",
path.join(__dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/aggregate_verify/small"),
(testCase) => {
const {pubkeys, messages, signature} = testCase.data.input;
try {
const msgs = messages.map(fromHexString);
const pks = pubkeys.map((pubkey) => PublicKey.fromBytes(fromHexString(pubkey)));
const sig = Signature.fromBytes(fromHexString(signature));
return aggregateVerify(msgs, pks, sig);
} catch (e) {
return false;
}
},
{
inputTypes: {
data: InputType.YAML,
},
getExpected: (testCase) => testCase.data.output,
}
);