-
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
114 changed files
with
821 additions
and
765 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,7 +169,6 @@ orchestrator | |
osx | ||
overriden | ||
params | ||
peerDependency | ||
pid | ||
plaintext | ||
pre | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export type {IBlsVerifier} from "./interface.js"; | ||
export type {JobQueueItemType} from "./jobItem.js"; | ||
export type {BlsMultiThreadWorkerPoolModules} from "./multiThread.js"; | ||
export {BlsMultiThreadWorkerPool} from "./multiThread.js"; | ||
export type {BlsMultiThreadWorkerPoolModules, JobQueueItemType} from "./multithread/index.js"; | ||
export {BlsMultiThreadWorkerPool} from "./multithread/index.js"; | ||
export {BlsSingleThreadVerifier} from "./singleThread.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {CoordType, PublicKey} from "@chainsafe/bls/types"; | ||
import bls from "@chainsafe/bls"; | ||
|
||
const MIN_SET_COUNT_TO_BATCH = 2; | ||
|
||
export type SignatureSetDeserialized = { | ||
publicKey: PublicKey; | ||
message: Uint8Array; | ||
signature: Uint8Array; | ||
}; | ||
|
||
/** | ||
* Verify signatures sets with batch verification or regular core verify depending on the set count. | ||
* Abstracted in a separate file to be consumed by the threaded pool and the main thread implementation. | ||
*/ | ||
export function verifySignatureSetsMaybeBatch(sets: SignatureSetDeserialized[]): boolean { | ||
try { | ||
if (sets.length >= MIN_SET_COUNT_TO_BATCH) { | ||
return bls.Signature.verifyMultipleSignatures( | ||
sets.map((s) => ({ | ||
publicKey: s.publicKey, | ||
message: s.message, | ||
// true = validate signature | ||
signature: bls.Signature.fromBytes(s.signature, CoordType.affine, true), | ||
})) | ||
); | ||
} | ||
|
||
// .every on an empty array returns true | ||
if (sets.length === 0) { | ||
throw Error("Empty signature set"); | ||
} | ||
|
||
// If too few signature sets verify them without batching | ||
return sets.every((set) => { | ||
// true = validate signature | ||
const sig = bls.Signature.fromBytes(set.signature, CoordType.affine, true); | ||
return sig.verify(set.publicKey, set.message); | ||
}); | ||
} catch (_) { | ||
// A signature could be malformed, in that case fromBytes throws error | ||
// blst-ts `verifyMultipleSignatures` is also a fallible operation if mul_n_aggregate fails | ||
// see https://github.com/ChainSafe/blst-ts/blob/b1ba6333f664b08e5c50b2b0d18c4f079203962b/src/lib.ts#L291 | ||
return false; | ||
} | ||
} |
Oops, something went wrong.