Skip to main content
Version: v3.x

Minimal Anti Collusion Infrastructure (MACI) / Ballot

Class: Ballot

Defined in: ballot.ts:11

A Ballot represents a User's votes in a Poll, as well as their next valid nonce.

Constructors

Constructor

new Ballot(totalVoteOptions, voteOptionTreeDepth): Ballot

Defined in: ballot.ts:25

Create a new Ballot instance

Parameters

totalVoteOptions

number

How many vote options are available in the poll

voteOptionTreeDepth

number

The depth of the merkle tree holding the vote options

Returns

Ballot

Properties

nonce

nonce: bigint

Defined in: ballot.ts:14


totalVoteOptions

totalVoteOptions: number

Defined in: ballot.ts:18


voteOptionTreeDepth

voteOptionTreeDepth: number

Defined in: ballot.ts:16


votes

votes: bigint[] = []

Defined in: ballot.ts:12

Methods

asArray()

asArray(): bigint[]

Defined in: ballot.ts:57

Convert in a an array of bigints

Returns

bigint[]

the ballot as a bigint array

Notice

this is the nonce and the root of the vote option tree


asCircuitInputs()

asCircuitInputs(): bigint[]

Defined in: ballot.ts:50

Convert in a format suitable for the circuit

Returns

bigint[]

the ballot as a BigInt array


copy()

copy(): Ballot

Defined in: ballot.ts:74

Create a deep clone of this Ballot

Returns

Ballot

a copy of the ballot


equals()

equals(b): boolean

Defined in: ballot.ts:87

Check if two ballots are equal (same votes and same nonce)

Parameters

b

Ballot

The ballot to compare with

Returns

boolean

whether the two ballots are equal


hash()

hash(): bigint

Defined in: ballot.ts:41

Generate an hash of this ballot

Returns

bigint

The hash of the ballot


toJSON()

toJSON(): IJsonBallot

Defined in: ballot.ts:117

Serialize to a JSON object

Returns

IJsonBallot


fromJSON()

static fromJSON(json): Ballot

Defined in: ballot.ts:130

Deserialize into a Ballot instance

Parameters

json

IJsonBallot

the json representation

Returns

Ballot

the deserialized object as a Ballot instance


generateBlank()

static generateBlank(totalVoteOptions, voteOptionTreeDepth): Ballot

Defined in: ballot.ts:110

Generate a blank ballot

Parameters

totalVoteOptions

number

How many vote options are available

voteOptionTreeDepth

number

How deep is the merkle tree holding the vote options

Returns

Ballot

a Blank Ballot object


generateRandom()

static generateRandom(totalVoteOptions, voteOptionTreeDepth): Ballot

Defined in: ballot.ts:98

Generate a random ballot

Parameters

totalVoteOptions

number

How many vote options are available

voteOptionTreeDepth

number

How deep is the merkle tree holding the vote options

Returns

Ballot

a random Ballot