This repository has been archived on 2023-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
chainsafe-bls/test/unit/multithread/naive/worker.ts

30 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

2022-04-11 19:10:42 +00:00
import {expose} from "@chainsafe/threads/worker";
2022-04-14 17:16:06 +00:00
import {CoordType, Implementation} from "../../../../src/types.js";
import bls, {init} from "../../../../src/switchable.js";
export type WorkerApi = typeof workerApi;
const workerApi = {
async verify(impl: Implementation, publicKey: Uint8Array, message: Uint8Array, signature: Uint8Array) {
await init(impl);
const pk = bls.PublicKey.fromBytes(publicKey, CoordType.affine);
const sig = bls.Signature.fromBytes(signature, CoordType.affine, true);
return sig.verify(pk, message);
},
async verifyMultipleAggregateSignatures(
impl: Implementation,
sets: {publicKey: Uint8Array; message: Uint8Array; signature: Uint8Array}[]
) {
await init(impl);
return bls.Signature.verifyMultipleSignatures(
sets.map((s) => ({
publicKey: bls.PublicKey.fromBytes(s.publicKey, CoordType.affine),
message: s.message,
signature: bls.Signature.fromBytes(s.signature, CoordType.affine, true),
}))
);
},
};
expose(workerApi);