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

38 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-09-05 22:51:27 +00:00
import path from "path";
import {padLeft} from "../../src/helpers/utils";
import {G2point} from "../../src/helpers/g2point";
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
interface IMsgHHashCOmpressed {
2019-09-05 22:51:27 +00:00
data: {
input: {
message: string;
domain: string;
};
output: string[];
};
}
describeDirectorySpecTest<IMsgHHashCOmpressed, string>(
2019-09-05 22:51:27 +00:00
"msg_hash_compressed",
path.join(
__dirname,
"../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/msg_hash_compressed/small"
),
2019-09-05 22:51:27 +00:00
(testCase => {
const domain = padLeft(Buffer.from(testCase.data.input.domain.replace("0x", ""), "hex"), 8);
const input = Buffer.from(testCase.data.input.message.replace("0x", ""), "hex");
2019-09-05 22:51:27 +00:00
const result = G2point.hashToG2(input, domain);
return `0x${result.toBytesCompressed().toString("hex")}`;
2019-09-05 22:51:27 +00:00
}),
{
inputTypes: {
data: InputType.YAML,
},
getExpected: (testCase => {
const xReExpected = padLeft(Buffer.from(testCase.data.output[0].replace("0x", ""), "hex"), 48);
const xImExpected = padLeft(Buffer.from(testCase.data.output[1].replace("0x", ""), "hex"), 48);
return "0x" + Buffer.concat([xReExpected, xImExpected]).toString("hex");
2019-09-05 22:51:27 +00:00
})
}
);