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