Ballot
A Ballot represents a User's votes in a Poll, as well as their next valid nonce.
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new Ballot(_numVoteOptions
, _voteOptionTreeDepth
): Ballot
Create a new Ballot instance
Parameters
Name | Type | Description |
---|---|---|
_numVoteOptions | number | How many vote options are available in the poll |
_voteOptionTreeDepth | number | The depth of the merkle tree holding the vote options |
Returns
Defined in
ballot.ts:23
Properties
nonce
• nonce: bigint
Defined in
ballot.ts:14
voteOptionTreeDepth
• voteOptionTreeDepth: number
Defined in
ballot.ts:16
votes
• votes: bigint
[] = []
Defined in
ballot.ts:12
Methods
asArray
▸ asArray(): bigint
[]
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
Defined in
ballot.ts:52
asCircuitInputs
▸ asCircuitInputs(): bigint
[]
Convert in a format suitable for the circuit
Returns
bigint
[]
the ballot as a BigInt array
Defined in
ballot.ts:45
copy
▸ copy(): Ballot
Create a deep clone of this Ballot
Returns
a copy of the ballot
Defined in
ballot.ts:68
equals
▸ equals(b
): boolean
Check if two ballots are equal (same votes and same nonce)
Parameters
Name | Type | Description |
---|---|---|
b | Ballot | The ballot to compare with |
Returns
boolean
whether the two ballots are equal
Defined in
ballot.ts:81
hash
▸ hash(): bigint
Generate an hash of this ballot
Returns
bigint
The hash of the ballot
Defined in
ballot.ts:36
toJSON
▸ toJSON(): IJsonBallot
Serialize to a JSON object
Returns
Defined in
ballot.ts:112
fromJSON
▸ fromJSON(json
): Ballot
Deserialize into a Ballot instance
Parameters
Name | Type | Description |
---|---|---|
json | IJsonBallot | the json representation |
Returns
the deserialized object as a Ballot instance
Defined in
ballot.ts:125
genBlankBallot
▸ genBlankBallot(numVoteOptions
, voteOptionTreeDepth
): Ballot
Generate a blank ballot
Parameters
Name | Type | Description |
---|---|---|
numVoteOptions | number | How many vote options are available |
voteOptionTreeDepth | number | How deep is the merkle tree holding the vote options |
Returns
a Blank Ballot object
Defined in
ballot.ts:104
genRandomBallot
▸ genRandomBallot(numVoteOptions
, voteOptionTreeDepth
): Ballot
Generate a random ballot
Parameters
Name | Type | Description |
---|---|---|
numVoteOptions | number | How many vote options are available |
voteOptionTreeDepth | number | How deep is the merkle tree holding the vote options |
Returns
a random Ballot
Defined in
ballot.ts:92