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";
|
|
|
|
|
2019-09-29 08:47:17 +00:00
|
|
|
interface IMsgHHashUnCompressed {
|
2019-09-05 22:51:27 +00:00
|
|
|
data: {
|
|
|
|
input: {
|
|
|
|
message: string;
|
|
|
|
domain: string;
|
|
|
|
};
|
|
|
|
output: string[][];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-29 08:47:17 +00:00
|
|
|
describeDirectorySpecTest<IMsgHHashUnCompressed, string>(
|
2019-09-05 22:51:27 +00:00
|
|
|
"msg_hash_uncompressed",
|
2019-09-29 08:47:17 +00:00
|
|
|
path.join(
|
|
|
|
__dirname,
|
|
|
|
"../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/msg_hash_uncompressed/small"
|
|
|
|
),
|
2019-09-05 22:51:27 +00:00
|
|
|
(testCase => {
|
2019-09-29 08:47:17 +00:00
|
|
|
const domain = padLeft(Buffer.from(testCase.data.input.domain.replace("0x", ""), "hex"), 8);
|
2019-09-05 22:51:27 +00:00
|
|
|
const input = Buffer.from(testCase.data.input.message.replace("0x", ""), "hex");
|
|
|
|
const result = G2point.hashToG2(input, domain);
|
2019-09-29 08:47:17 +00:00
|
|
|
return `0x${result.toBytesCompressed().toString("hex")}`;
|
2019-09-05 22:51:27 +00:00
|
|
|
}),
|
|
|
|
{
|
|
|
|
inputTypes: {
|
|
|
|
data: InputType.YAML,
|
|
|
|
},
|
|
|
|
getExpected: (testCase => {
|
2019-09-29 08:47:17 +00:00
|
|
|
return "0x" + G2point.fromUncompressedInput(
|
|
|
|
Buffer.from(testCase.data.output[0][0].replace("0x", ""), "hex"),
|
|
|
|
Buffer.from(testCase.data.output[0][1].replace("0x", ""), "hex"),
|
|
|
|
Buffer.from(testCase.data.output[1][0].replace("0x", ""), "hex"),
|
|
|
|
Buffer.from(testCase.data.output[1][1].replace("0x", ""), "hex"),
|
|
|
|
Buffer.from(testCase.data.output[2][0].replace("0x", ""), "hex"),
|
|
|
|
Buffer.from(testCase.data.output[2][1].replace("0x", ""), "hex"),
|
|
|
|
).toBytesCompressed().toString("hex");
|
2019-09-05 22:51:27 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
);
|