Fix herumi tests
This commit is contained in:
parent
d3616e50f6
commit
6fe9b09a92
|
@ -3,3 +3,15 @@
|
||||||
* by the functional interface try / catch blocks
|
* by the functional interface try / catch blocks
|
||||||
*/
|
*/
|
||||||
export class ExpectedError extends Error {}
|
export class ExpectedError extends Error {}
|
||||||
|
|
||||||
|
export class ZeroPrivateKeyError extends Error {
|
||||||
|
constructor() {
|
||||||
|
super("PRIVATE_KEY_IS_ZERO");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ZeroPublicKeyError extends Error {
|
||||||
|
constructor() {
|
||||||
|
super("PUBLIC_KEY_IS_ZERO");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,11 +6,16 @@ import {PublicKey} from "./publicKey";
|
||||||
import {Signature} from "./signature";
|
import {Signature} from "./signature";
|
||||||
import {bytesToHex, hexToBytes} from "../helpers";
|
import {bytesToHex, hexToBytes} from "../helpers";
|
||||||
import {IPrivateKey} from "../interface";
|
import {IPrivateKey} from "../interface";
|
||||||
|
import {ZeroPrivateKeyError} from "../errors";
|
||||||
|
|
||||||
export class PrivateKey implements IPrivateKey {
|
export class PrivateKey implements IPrivateKey {
|
||||||
readonly value: SecretKeyType;
|
readonly value: SecretKeyType;
|
||||||
|
|
||||||
constructor(value: SecretKeyType) {
|
constructor(value: SecretKeyType) {
|
||||||
|
if (value.isZero()) {
|
||||||
|
throw new ZeroPrivateKeyError();
|
||||||
|
}
|
||||||
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,16 @@ import {getContext} from "./context";
|
||||||
import {EMPTY_PUBLIC_KEY, PUBLIC_KEY_LENGTH} from "../constants";
|
import {EMPTY_PUBLIC_KEY, PUBLIC_KEY_LENGTH} from "../constants";
|
||||||
import {bytesToHex, hexToBytes, isEqualBytes} from "../helpers";
|
import {bytesToHex, hexToBytes, isEqualBytes} from "../helpers";
|
||||||
import {IPublicKey} from "../interface";
|
import {IPublicKey} from "../interface";
|
||||||
|
import {ZeroPublicKeyError} from "../errors";
|
||||||
|
|
||||||
export class PublicKey implements IPublicKey {
|
export class PublicKey implements IPublicKey {
|
||||||
readonly value: PublicKeyType;
|
readonly value: PublicKeyType;
|
||||||
|
|
||||||
constructor(value: PublicKeyType) {
|
constructor(value: PublicKeyType) {
|
||||||
|
if (value.isZero()) {
|
||||||
|
throw new ZeroPublicKeyError();
|
||||||
|
}
|
||||||
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {describeDirectorySpecTest, InputType} from "@chainsafe/lodestar-spec-tes
|
||||||
import {bytesToHex, hexToBytes} from "../../src/helpers";
|
import {bytesToHex, hexToBytes} from "../../src/helpers";
|
||||||
import {SPEC_TESTS_DIR} from "../params";
|
import {SPEC_TESTS_DIR} from "../params";
|
||||||
import {describeForAllImplementations} from "../switch";
|
import {describeForAllImplementations} from "../switch";
|
||||||
|
import {ZeroPrivateKeyError} from "../../src/errors";
|
||||||
|
|
||||||
interface ISignMessageTestCase {
|
interface ISignMessageTestCase {
|
||||||
data: {
|
data: {
|
||||||
|
@ -19,9 +20,14 @@ describeForAllImplementations((bls) => {
|
||||||
"bls/sign/small",
|
"bls/sign/small",
|
||||||
path.join(SPEC_TESTS_DIR, "general/phase0/bls/sign/small"),
|
path.join(SPEC_TESTS_DIR, "general/phase0/bls/sign/small"),
|
||||||
(testCase) => {
|
(testCase) => {
|
||||||
const {privkey, message} = testCase.data.input;
|
try {
|
||||||
const signature = bls.sign(hexToBytes(privkey), hexToBytes(message));
|
const {privkey, message} = testCase.data.input;
|
||||||
return bytesToHex(signature);
|
const signature = bls.sign(hexToBytes(privkey), hexToBytes(message));
|
||||||
|
return bytesToHex(signature);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof ZeroPrivateKeyError) return null;
|
||||||
|
else throw e;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
inputTypes: {data: InputType.YAML},
|
inputTypes: {data: InputType.YAML},
|
||||||
|
|
Reference in New Issue