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.
2022-04-11 19:10:42 +00:00
|
|
|
import {expose} from "@chainsafe/threads/worker";
|
2022-04-11 15:08:15 +00:00
|
|
|
import {bls, init, CoordType, Implementation} from "../../../../src/index.js";
|
2021-04-04 23:44:55 +00:00
|
|
|
|
|
|
|
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);
|