2020-02-26 08:19:15 +00:00
|
|
|
import path from "path";
|
2020-11-05 20:55:25 +00:00
|
|
|
import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-test-util";
|
2022-04-11 15:08:15 +00:00
|
|
|
import {bytesToHex, hexToBytes} from "../../src/helpers/index.js";
|
|
|
|
import {SPEC_TESTS_DIR} from "../params.js";
|
|
|
|
import {describeForAllImplementations} from "../switch.js";
|
|
|
|
import {ZeroSecretKeyError} from "../../src/errors.js";
|
2020-02-26 08:19:15 +00:00
|
|
|
|
|
|
|
interface ISignMessageTestCase {
|
|
|
|
data: {
|
|
|
|
input: {
|
|
|
|
privkey: string;
|
|
|
|
message: string;
|
|
|
|
};
|
|
|
|
output: string;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-20 19:35:32 +00:00
|
|
|
describeForAllImplementations((bls) => {
|
2020-12-06 11:38:05 +00:00
|
|
|
describeDirectorySpecTest<ISignMessageTestCase, string | null>(
|
2020-11-19 14:41:45 +00:00
|
|
|
"bls/sign/small",
|
2020-12-01 08:17:25 +00:00
|
|
|
path.join(SPEC_TESTS_DIR, "tests/general/phase0/bls/sign/small"),
|
2020-11-19 13:22:41 +00:00
|
|
|
(testCase) => {
|
2020-11-29 23:35:42 +00:00
|
|
|
try {
|
|
|
|
const {privkey, message} = testCase.data.input;
|
|
|
|
const signature = bls.sign(hexToBytes(privkey), hexToBytes(message));
|
|
|
|
return bytesToHex(signature);
|
|
|
|
} catch (e) {
|
2020-11-30 18:01:13 +00:00
|
|
|
if (e instanceof ZeroSecretKeyError) return null;
|
2020-11-29 23:35:42 +00:00
|
|
|
else throw e;
|
|
|
|
}
|
2020-02-26 08:19:15 +00:00
|
|
|
},
|
2020-11-19 13:22:41 +00:00
|
|
|
{
|
|
|
|
inputTypes: {data: InputType.YAML},
|
|
|
|
getExpected: (testCase) => testCase.data.output,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|