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/sign.test.ts

35 lines
895 B
TypeScript
Raw Normal View History

2020-11-13 21:43:20 +00:00
import path from "path";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
import {SecretKey} from "@chainsafe/blst-ts";
import {fromHexString, toHexString} from "../util";
interface ISignMessageTestCase {
data: {
input: {
privkey: string;
message: string;
};
output: string;
};
}
describeDirectorySpecTest<ISignMessageTestCase, string>(
"BLS - sign",
path.join(__dirname, "../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/sign/small"),
(testCase) => {
const {privkey, message} = testCase.data.input;
const sk = SecretKey.fromBytes(fromHexString(privkey));
const msg = fromHexString(message);
const sig = sk.sign(msg);
return toHexString(sig.toBytes());
},
{
inputTypes: {
data: InputType.YAML,
},
getExpected: (testCase) => testCase.data.output,
}
);