Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AsyncBallotEncryptor

This class wraps all the state and machinery necessary to offload encryption computations on a contest-by-contest basis. The idea is that you initialize it with all the state it will ever need as well as specifying the particular ballot style. Then, you can call encrypt(), which will immediately return while running the computation in a webworker or equivalent.

If you encrypt the same contest twice, the latter one will replace the earlier one.

When you're done, you call getEncryptedBallot(), which will block until all the contest encryption is complete, and will then return the encrypted ballot. This call has the potential to fail, for example, if you haven't encrypted all the necessary contests for the given ballot style.

For truly all-in-one behavior, you can instead call getSerializedEncryptedBallot(), which returns an instance of SerializedEncryptedBallot, or might again throw an exception if something went wrong.

Also of note: while elsewhere in the ElectionGuard-Python codebase, errors are indicated by returning undefined, here it's different. Errors are indicated by throwing an Error class, which will contain enough context to assist in tracking down any problems.

Hierarchy

  • AsyncBallotEncryptor

Index

Constructors

  • Builds an instance of AsyncBallotEncryptor. For ease of use, you may prefer the static {@link AsyncBallotEncryptor#create} method instead, which allows you to pass in JavaScript objects for external types like the manifest, and it will let you know if there's a problem.

    Parameters

    • manifest: Manifest

      Defines everything about the election contests, candidates, etc.

    • electionContext: ElectionContext

      Defines everything about the election cryptographic settings.

    • validate: boolean

      Specifies whether each encryption is validated immediately after it is created. Significant performance penalty, but might catch one-in-a-million hardware failures on unreliable clients.

    • group: GroupContext

      GroupContext for all mathematical operations

    • codeSeed: ElementModQ
    • seed: ElementModQ

      The root of all randomness used for encrypting the ballot.

    • ballotStyleId: string

      The manifest might specify multiple ballot styles. This names the ballot style to be used for this particular ballot.

    • ballotId: string

      Every ballot needs a string identifier which should be globally unique.

    • Optional timestamp: number

      Optional timestamp for the ballot, in seconds since the Unix epoch. If not provided, the current time will be used (Math.floor(Date.now() / 1000)) when the final ballot is completed and returned.

    Returns AsyncBallotEncryptor

Properties

ballotId: string
ballotNonce: ElementModQ
ballotStyleId: string
codeSeed: ElementModQ
contestIds: string[]
encryptedContests: Map<string, Promise<CiphertextContest>>
encryptionState: EncryptionState
manifestContests: Map<string, ManifestContestDescription>
sequenceOrderMap: Map<string, number>
timestamp?: number

Methods

  • Fetches the encrypted ballot, possibly blocking until all the async computation is complete. If a contest wasn't submitted, then it's not possible to derive the result, so an Error is thrown.

    For one-stop-shopping, to get exactly what you need for printing something, writing something to disk, sending something across the network, etc., you might prefer to use {@link AsyncBallotEncryptor#getSerializedEncryptedBallot}.

    Returns Promise<CiphertextBallot>

  • Fetches the encrypted ballot, possibly blocking until all the async computation is complete, and doing all the necessary work to serialize it. Returns that ballot (as a vanilla JavaScript object suitable for conversion to JSON) plus the ballot hash and the cryptographic seed.

    see

    SerializedEncryptedBallot

    Returns Promise<SerializedEncryptedBallot>

  • Builds an instance of AsyncBallotEncryptor with good default values when appropriate.

    Parameters

    • group: GroupContext

      GroupContext for all mathematical operations

    • manifestObj: object

      A JavaScript object corresponding to an ElectionGuard Manifest.

    • electionContextObj: object

      A JavaScript object corresponding to an ElectionGuard ElectionContext.

    • validate: boolean

      Specifies whether each encryption is validated immediately after it is created. Significant performance penalty, but might catch one-in-a-million hardware failures on unreliable clients.

    • ballotStyleId: string

      The manifest might specify multiple ballot styles. This names the ballot style to be used for this particular ballot.

    • ballotId: string

      Every ballot needs a string identifier which should be globally unique.

    • codeSeed: ElementModQ

      The hash of the previous ballot. Initially set to the hash of the encryption device.

    • Optional seed: ElementModQ

      The root of all randomness used for encrypting the ballot. If not provided, a new random number will be securely generated.

    • Optional timestamp: number

      Optional timestamp for the ballot, in seconds since the Unix epoch. If not provided, the current time will be used (Math.floor(Date.now() / 1000)) when the final ballot is completed and returned.

    Returns AsyncBallotEncryptor

Generated using TypeDoc