Prevent "BLS not initialized" error from causing a false negative
This commit is contained in:
parent
5db911d470
commit
2245559e0e
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
* Indicate that this error is expected and should not be ignored
|
||||
* by the functional interface try / catch blocks
|
||||
*/
|
||||
export class ExpectedError extends Error {}
|
|
@ -1,5 +1,6 @@
|
|||
import {validateBytes} from "./helpers";
|
||||
import {IBls} from "./interface";
|
||||
import {validateBytes} from "./helpers";
|
||||
import {ExpectedError} from "./errors";
|
||||
|
||||
// Returned type is enforced at each implementation's index
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
|
@ -53,6 +54,7 @@ export function functionalInterfaceFactory({
|
|||
try {
|
||||
return Signature.fromBytes(signature).verify(PublicKey.fromBytes(publicKey), message);
|
||||
} catch (e) {
|
||||
if (e instanceof ExpectedError) throw e;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +76,7 @@ export function functionalInterfaceFactory({
|
|||
message
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof ExpectedError) throw e;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -99,6 +102,7 @@ export function functionalInterfaceFactory({
|
|||
messages.map((msg) => msg)
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof ExpectedError) throw e;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* eslint-disable require-atomic-updates */
|
||||
import bls from "bls-eth-wasm";
|
||||
import {ExpectedError} from "../errors";
|
||||
|
||||
type Bls = typeof bls;
|
||||
let blsGlobal: Bls | null = null;
|
||||
|
@ -27,7 +28,7 @@ export function destroy(): void {
|
|||
|
||||
export function getContext(): Bls {
|
||||
if (!blsGlobal) {
|
||||
throw new Error("BLS not initialized");
|
||||
throw new ExpectedError("BLS not initialized");
|
||||
}
|
||||
return blsGlobal;
|
||||
}
|
||||
|
|
Reference in New Issue