Skip to content

Get started

Start with the root package. It exposes the supported public ceremony: honest-majority GJKR, one explicit global manifest scoreRange, ballot-close, and full ceremony verification.

  • The public manifest shape is rosterHash, optionList, and scoreRange.
  • The library derives the threshold from the accepted registration roster as k = ceil(n / 2).
  • Ballots are complete and must stay inside the manifest-declared score range.
  • The organizer closes counting with one signed ballot-close payload.
  • Each trustee prepares the accepted aggregate with prepareAggregateForDecryption(...), computes a partial reveal with createDecryptionShare(...), proves it with createDLEQProof(...), and then signs createDecryptionSharePayload(...), all from the root package.
  • Tally verification must be done against the close-selected ballot set, not against a server-supplied aggregate.
import {
tryVerifyElectionCeremony,
type VerifyElectionCeremonyInput,
} from "threshold-elgamal";
const bundle: VerifyElectionCeremonyInput = {
manifest,
sessionId,
dkgTranscript,
ballotPayloads,
ballotClosePayloads: [ballotClosePayload],
decryptionSharePayloads,
tallyPublications,
};
const result = await tryVerifyElectionCeremony(bundle);
if (!result.ok) {
console.error(result.error.stage, result.error.code, result.error.reason);
} else {
console.log(result.verified.qualifiedParticipantIndices);
console.log(result.verified.countedParticipantIndices);
console.log(result.verified.perOptionTallies);
console.log(result.verified.boardAudit.overall.fingerprint);
}

Use verifyElectionCeremony(...) when you want the same checks but prefer exceptions over a structured result. Pass the full published ballot-close slot in ballotClosePayloads, even when that slot only contains one organizer payload.

  • Keep rosterHash, manifest, manifestHash, and sessionId together. They define the public ceremony context.
  • Persist the signed board payloads exactly as published. The verifier expects the original { payload, signature } objects.
  • If you store verifier output, convert bigint values such as tallies to strings first.