diff --git a/src/blst/publicKey.ts b/src/blst/publicKey.ts index 657aef2..187e191 100644 --- a/src/blst/publicKey.ts +++ b/src/blst/publicKey.ts @@ -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); } diff --git a/src/blst/signature.ts b/src/blst/signature.ts index d3a74f4..de4379a 100644 --- a/src/blst/signature.ts +++ b/src/blst/signature.ts @@ -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 { diff --git a/src/errors.ts b/src/errors.ts index 62b2daa..80ff3fc 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -15,3 +15,9 @@ export class ZeroPublicKeyError extends Error { super("PUBLIC_KEY_IS_ZERO"); } } + +export class ZeroSignatureError extends Error { + constructor() { + super("SIGNATURE_IS_ZERO"); + } +}