@assemblyvoting/js-client
    Preparing search index...

    Class AVClient

    Assembly Voting Client API

    The API is responsible for handling all the cryptographic operations and all network communication with:

    • the Digital Ballot Box
    • the Voter Authorization Coordinator service
    • the OTP provider(s)
    Method Description
    initialize Initializes the library by fetching election configuration
    requestAccessCode Initiates the authorization process, in case voter has not authorized yet. Requests access code to be sent to voter email
    validateAccessCode Gets voter authorized to vote.
    registerVoter Registers the voter on the bulletin board
    AVClient.constructBallotCryptograms constructBallotCryptograms
    spoilBallot Optional. Initiates process of testing the ballot encryption.
    castBallot Finalizes the voting process.
    [[include:readme_example.test.ts]]
    

    Implements

    Index

    Constructors

    • Parameters

      • bulletinBoardURL: string

        URL to the Assembly Voting backend server, specific for election.

      • OptionaldbbPublicKey: string

      Returns AVClient

    Methods

    • Initializes the client with an election config. If no config is provided, it fetches one from the backend.

      Parameters

      • OptionallatestConfig: LatestConfig

        Allows injection of an election configuration for testing purposes

      • OptionalkeyPair: KeyPair

        Allows injection of a keypair to support automatic testing

      Returns Promise<void>

      Returns undefined if succeeded or throws an error

      NetworkError if any request failed to get a response

    • Should be called when a voter chooses digital vote submission (instead of mail-in).

      Will attempt to get backend services to send an access code (one time password, OTP) to voter's email address.

      Should be followed by validateAccessCode to submit access code for validation.

      Parameters

      • opaqueVoterId: string

        Voter ID that preserves voter anonymity.

      • email: string

        where the voter expects to receive otp code.

      • OptionalballotReference: string

        The ballot which which voter voter intends to vote on

      Returns Promise<void>

      Returns undefined or throws an error.

      VoterRecordNotFound if no voter was found

      NetworkError if any request failed to get a response

    • Should be called after requestAccessCode.

      Takes an access code (OTP) that voter received, uses it to authorize to submit votes.

      Internally, generates a private/public key pair, then attempts to authorize the public key with each OTP provider.

      Should be followed by AVClient.constructBallotCryptograms | constructBallotCryptograms.

      Parameters

      • code: string

        An access code string.

      Returns Promise<void>

      Returns undefined if authorization succeeded or throws an error

      InvalidStateError if called before required data is available

      AccessCodeExpired if an OTP code has expired

      AccessCodeInvalid if an OTP code is invalid

      NetworkError if any request failed to get a response

    • Parameters

      • electionCodes: string[]

      Returns void

    • Parameters

      • token: string

      Returns void

    • Returns Promise<AxiosResponse<any, any, {}>>

    • Registers a voter based on the authorization mode of the Voter Authorizer Authorization is done by 'proof-of-identity' or 'proof-of-election-codes'

      Parameters

      • votingRoundReference: string = "voting-round-1"

      Returns Promise<void>

    • Registers a voter based on the authorization mode of the Voter Authorizer

      Returns Promise<void>

      undefined or throws an error

    • Parameters

      • votingRoundReference: string

      Returns Promise<AxiosResponse<any, any, {}>>

    • Parameters

      • extendedBy: number

      Returns Promise<void>

    • Should be called after validateAccessCode.

      Encrypts a ballot-selection (CVR) and generates vote cryptograms.

      Example:

      const client = new AVClient(url);
      const cvr = { '1': 'option1', '2': 'optiona' };
      const trackingCode = await client.constructBallotCryptograms(cvr);

      Example of handling errors:

      try {
      await client.constructBallotCryptograms({});
      } catch(error) {
      if(error instanceof AvClientError) {
      switch(error.name) {
      case 'InvalidStateError':
      console.log("State is not valid for this call");
      break;
      case 'NetworkError':
      console.log("It's a network error");
      break;
      default:
      console.log('Something else was wrong');
      }
      }
      }

      Where '1' and '2' are contest ids, and 'option1' and 'optiona' are values internal to the AV election config.

      Should be followed by either spoilBallot or castBallot.

      Parameters

      • ballotSelection: BallotSelection

        BallotSelection containing the selections for each contest.

      Returns Promise<string>

      Returns the ballot tracking code. Example:

      '5e4d8fe41fa3819cc064e2ace0eda8a847fe322594a6fd5a9a51c699e63804b7'
      

      InvalidStateError if called before required data is available

      CorruptCvrError if the cast vote record is invalid

      NetworkError if any request failed to get a response

    • Should be the last call in the entire voting process.

      Requests that the previously constructed ballot is cast.

      Parameters

      • locale: string = "en"

        The locale which the email with the vote receipt should be sent in

      Returns Promise<BallotBoxReceipt>

      Returns the vote receipt. Example of a receipt:

      {
      previousBoardHash: 'd8d9742271592d1b212bbd4cbvobbe357aef8e00cdbdf312df95e9cf9a1a921465',
      boardHash: '5a9175c2b3617298d78be7d0244a68f34bc8b2a37061bb4d3fdf97edc1424098',
      registeredAt: '2020-03-01T10:00:00.000+01:00',
      serverSignature: 'dbcce518142b8740a5c911f727f3c02829211a8ddfccabeb89297877e4198bc1,46826ddfccaac9ca105e39c8a2d015098479624c411b4783ca1a3600daf4e8fa',
      voteSubmissionId: 6
      }

      NetworkError if any request failed to get a response

    • Should be called when voter chooses to test the encryption of their ballot. Gets commitment opening of the digital ballot box and validates it.

      Returns Promise<string>

      Returns undefined if the validation succeeds or throws an error

      InvalidStateError if called before required data is available

      ServerCommitmentError if the server commitment is invalid

      NetworkError if any request failed to get a response

    • Should be called when the voter has 'paired' the verifier and the voting app. Computes and encrypts the clientEncryptionCommitment and posts it to the DBB

      Returns Promise<void>

      Returns void if the computation was succesful

      InvalidStateError if called before required data is available

      NetworkError if any request failed to get a response

    • Returns VoterSessionItem

    • Returns string

    • Returns BallotConfig

    • Returns ContestConfig[]

    • Returns string

    • Parameters

      • payload: string

      Returns string

    • Should be called after spoilBallot. Gets the verifier public key from the DBB

      Returns Promise<string>

      Returns the pairing code based on the address of the verifier item in the DBB

      InvalidStateError if called before required data is available

      TimeoutError if the verifier doesn't register itself to the DBB in time

      NetworkError if any request failed to get a response

    • Finds the ballot status corresponding to the given trackingcode. Also returns the activities associated with the ballot

      Parameters

      • trackingCode: string

        base58-encoded trackingcode

      Returns Promise<BallotStatus>

    • Disables the voter in the VA, so that they can no longer vote or sign in.

      Returns Promise<AxiosResponse<any, any, {}>>

    • Returns Promise<AxiosResponse<any, any, {}>>