From 60d795c694890f40c1a7c6f2a9e365240bf62c0e Mon Sep 17 00:00:00 2001 From: dapplion Date: Mon, 30 Nov 2020 00:01:48 +0000 Subject: [PATCH] Fix blst tests --- src/blst/publicKey.ts | 5 +++++ src/blst/signature.ts | 8 +++++++- src/errors.ts | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) 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"); + } +}