Skip to content

Commit

Permalink
chore: cleanup spec test compatibility layer
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeetagain committed Jul 18, 2024
1 parent a1be5a8 commit d5b3442
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions test/spec/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
verifyMultipleAggregateSignatures,
SignatureSet,
} from "../../index.js";
import {fromHex} from "../utils";
import {CodeError, fromHex} from "../utils";
import {G2_POINT_AT_INFINITY} from "./utils";

export const testFnByName: Record<string, (data: any) => any> = {
Expand All @@ -26,6 +26,11 @@ export const testFnByName: Record<string, (data: any) => any> = {
deserialization_G2,
};

function catchBLSTError(e: unknown): boolean {
if ((e as CodeError).code?.startsWith("BLST")) return false;
throw e;
}

/**
* ```
* input: List[BLS Signature] -- list of input BLS signatures
Expand Down Expand Up @@ -54,7 +59,7 @@ function aggregate_verify(input: {pubkeys: string[]; messages: string[]; signatu
Signature.fromHex(signature)
);
} catch (e) {
return false;
return catchBLSTError(e);
}
}

Expand Down Expand Up @@ -91,7 +96,7 @@ function eth_fast_aggregate_verify(input: {pubkeys: string[]; message: string; s
Signature.fromHex(signature)
);
} catch (e) {
return false;
return catchBLSTError(e);
}
}

Expand All @@ -114,7 +119,7 @@ function fast_aggregate_verify(input: {pubkeys: string[]; message: string; signa
Signature.fromHex(signature)
);
} catch (e) {
return false;
return catchBLSTError(e);
}
}

Expand All @@ -141,7 +146,7 @@ function verify(input: {pubkey: string; message: string; signature: string}): bo
try {
return VERIFY(fromHex(message), PublicKey.fromHex(pubkey), Signature.fromHex(signature));
} catch (e) {
return false;
return catchBLSTError(e);
}
}

Expand All @@ -161,14 +166,18 @@ function batch_verify(input: {pubkeys: string[]; messages: string[]; signatures:
throw new Error("Invalid spec test. Must have same number in each array. Check spec yaml file");
}
const sets: SignatureSet[] = [];
for (let i = 0; i < length; i++) {
sets.push({
msg: fromHex(input.messages[i]),
pk: PublicKey.fromHex(input.pubkeys[i]),
sig: Signature.fromHex(input.signatures[i]),
});
try {
for (let i = 0; i < length; i++) {
sets.push({
msg: fromHex(input.messages[i]),
pk: PublicKey.fromHex(input.pubkeys[i]),
sig: Signature.fromHex(input.signatures[i]),
});
}
return verifyMultipleAggregateSignatures(sets);
} catch (e) {
return catchBLSTError(e);
}
return verifyMultipleAggregateSignatures(sets);
}

/**
Expand All @@ -182,8 +191,8 @@ function deserialization_G1(input: {pubkey: string}): boolean {
try {
PublicKey.fromHex(input.pubkey, true);
return true;
} catch {
return false;
} catch (e) {
return catchBLSTError(e);
}
}

Expand All @@ -198,7 +207,7 @@ function deserialization_G2(input: {signature: string}): boolean {
try {
Signature.fromHex(input.signature, true);
return true;
} catch {
return false;
} catch (e) {
return catchBLSTError(e);
}
}

0 comments on commit d5b3442

Please sign in to comment.