Fix blst tests
This commit is contained in:
parent
32266dae20
commit
60d795c694
|
@ -1,4 +1,5 @@
|
||||||
import * as blst from "@chainsafe/blst";
|
import * as blst from "@chainsafe/blst";
|
||||||
|
import {ZeroPublicKeyError} from "../errors";
|
||||||
import {bytesToHex, hexToBytes} from "../helpers";
|
import {bytesToHex, hexToBytes} from "../helpers";
|
||||||
import {IPublicKey} from "../interface";
|
import {IPublicKey} from "../interface";
|
||||||
|
|
||||||
|
@ -13,6 +14,10 @@ export class PublicKey implements IPublicKey {
|
||||||
|
|
||||||
static fromBytes(bytes: Uint8Array): PublicKey {
|
static fromBytes(bytes: Uint8Array): PublicKey {
|
||||||
const affine = blst.PublicKey.fromBytes(bytes);
|
const affine = blst.PublicKey.fromBytes(bytes);
|
||||||
|
if (affine.value.is_inf()) {
|
||||||
|
throw new ZeroPublicKeyError();
|
||||||
|
}
|
||||||
|
|
||||||
const jacobian = blst.AggregatePublicKey.fromPublicKey(affine);
|
const jacobian = blst.AggregatePublicKey.fromPublicKey(affine);
|
||||||
return new PublicKey(affine, jacobian);
|
return new PublicKey(affine, jacobian);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import * as blst from "@chainsafe/blst";
|
||||||
import {bytesToHex, hexToBytes} from "../helpers";
|
import {bytesToHex, hexToBytes} from "../helpers";
|
||||||
import {ISignature} from "../interface";
|
import {ISignature} from "../interface";
|
||||||
import {PublicKey} from "./publicKey";
|
import {PublicKey} from "./publicKey";
|
||||||
|
import {ZeroSignatureError} from "../errors";
|
||||||
|
|
||||||
export class Signature implements ISignature {
|
export class Signature implements ISignature {
|
||||||
readonly affine: blst.Signature;
|
readonly affine: blst.Signature;
|
||||||
|
@ -11,7 +12,12 @@ export class Signature implements ISignature {
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromBytes(bytes: Uint8Array): Signature {
|
static fromBytes(bytes: Uint8Array): Signature {
|
||||||
return new Signature(blst.Signature.fromBytes(bytes));
|
const affine = blst.Signature.fromBytes(bytes);
|
||||||
|
if (affine.value.is_inf()) {
|
||||||
|
throw new ZeroSignatureError();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Signature(affine);
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromHex(hex: string): Signature {
|
static fromHex(hex: string): Signature {
|
||||||
|
|
|
@ -15,3 +15,9 @@ export class ZeroPublicKeyError extends Error {
|
||||||
super("PUBLIC_KEY_IS_ZERO");
|
super("PUBLIC_KEY_IS_ZERO");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ZeroSignatureError extends Error {
|
||||||
|
constructor() {
|
||||||
|
super("SIGNATURE_IS_ZERO");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in New Issue