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

39 lines
907 B
TypeScript
Raw Permalink Normal View History

2020-02-26 08:19:15 +00:00
import path from "path";
import bls, {initBLS} from "../../src";
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
interface ISignMessageTestCase {
data: {
input: {
privkey: string;
message: string;
};
output: string;
};
}
before(async function f() {
await initBLS();
});
describeDirectorySpecTest<ISignMessageTestCase, string>(
"BLS - sign",
path.join(
__dirname,
"../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/sign/small"
),
(testCase => {
const signature = bls.sign(
Buffer.from(testCase.data.input.privkey.replace("0x", ""), "hex"),
Buffer.from(testCase.data.input.message.replace("0x", ""), "hex")
);
return `0x${signature.toString("hex")}`;
}),
{
inputTypes: {
data: InputType.YAML,
},
getExpected: (testCase => testCase.data.output)
}
);