2019-09-05 13:06:46 +00:00
|
|
|
import path from "path";
|
2019-12-02 12:44:45 +00:00
|
|
|
import bls, {initBLS} from "../../src";
|
2019-08-05 15:48:26 +00:00
|
|
|
import {padLeft} from "../../src/helpers/utils";
|
2019-09-05 13:06:46 +00:00
|
|
|
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
2019-08-05 15:48:26 +00:00
|
|
|
|
2019-09-29 08:47:17 +00:00
|
|
|
interface ISignMessageTestCase {
|
2019-09-05 22:51:27 +00:00
|
|
|
data: {
|
|
|
|
input: {
|
|
|
|
privkey: string;
|
|
|
|
message: string;
|
|
|
|
domain: string;
|
2019-09-05 13:06:46 +00:00
|
|
|
};
|
2019-09-05 22:51:27 +00:00
|
|
|
output: string;
|
|
|
|
};
|
2019-09-05 13:06:46 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 20:58:41 +00:00
|
|
|
before(async function f() {
|
2019-12-02 12:44:45 +00:00
|
|
|
await initBLS();
|
2019-11-27 20:58:41 +00:00
|
|
|
});
|
|
|
|
|
2019-09-29 08:47:17 +00:00
|
|
|
describeDirectorySpecTest<ISignMessageTestCase, string>(
|
2019-09-05 22:51:27 +00:00
|
|
|
"priv_to_pub",
|
2019-09-29 08:47:17 +00:00
|
|
|
path.join(
|
|
|
|
__dirname,
|
|
|
|
"../../../../node_modules/@chainsafe/eth2-spec-tests/tests/general/phase0/bls/sign_msg/small"
|
|
|
|
),
|
2019-09-05 22:51:27 +00:00
|
|
|
(testCase => {
|
|
|
|
const signature = bls.sign(
|
|
|
|
Buffer.from(testCase.data.input.privkey.replace("0x", ""), "hex"),
|
|
|
|
Buffer.from(testCase.data.input.message.replace("0x", ""), "hex"),
|
2019-09-29 08:47:17 +00:00
|
|
|
padLeft(Buffer.from(testCase.data.input.domain.replace("0x", ""), "hex"), 8)
|
2019-09-05 22:51:27 +00:00
|
|
|
);
|
|
|
|
return `0x${signature.toString("hex")}`;
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
inputTypes: {
|
|
|
|
data: InputType.YAML,
|
|
|
|
},
|
|
|
|
getExpected: (testCase => testCase.data.output)
|
|
|
|
}
|
2019-09-05 13:06:46 +00:00
|
|
|
);
|