Minimal Anti Collusion Infrastructure (MACI) / Poll
Class: Poll
Defined in: Poll.ts:56
A representation of the Poll contract.
Implements
Constructors
Constructor
new Poll(
pollEndTimestamp
,coordinatorKeypair
,treeDepths
,batchSizes
,maciStateRef
,voteOptions
,mode
):Poll
Defined in: Poll.ts:151
Constructs a new Poll object.
Parameters
pollEndTimestamp
bigint
The Unix timestamp at which the poll ends.
coordinatorKeypair
Keypair
The keypair of the coordinator.
treeDepths
The depths of the trees used in the poll.
batchSizes
The sizes of the batches used in the poll.
maciStateRef
The reference to the MACI state.
voteOptions
bigint
mode
Returns
Poll
Properties
actualStateTreeDepth
actualStateTreeDepth:
number
Defined in: Poll.ts:70
ballots
ballots:
Ballot
[] =[]
Defined in: Poll.ts:74
ballotTree?
optional
ballotTree:IncrementalQuinTree
Defined in: Poll.ts:76
batchHashes
batchHashes:
bigint
[]
Defined in: Poll.ts:126
batchSizes
batchSizes:
IBatchSizes
Defined in: Poll.ts:63
chainHash
chainHash:
bigint
=NOTHING_UP_MY_SLEEVE
Defined in: Poll.ts:123
commands
commands:
VoteCommand
[] =[]
Defined in: Poll.ts:80
coordinatorKeypair
coordinatorKeypair:
Keypair
Defined in: Poll.ts:59
currentMessageBatchIndex
currentMessageBatchIndex:
number
Defined in: Poll.ts:93
emptyBallot
emptyBallot:
Ballot
Defined in: Poll.ts:118
emptyBallotHash?
optional
emptyBallotHash:bigint
Defined in: Poll.ts:120
encryptionPublicKeys
encryptionPublicKeys:
PublicKey
[] =[]
Defined in: Poll.ts:82
maciStateRef
maciStateRef:
MaciState
Defined in: Poll.ts:95
maxVoteOptions
maxVoteOptions:
number
Defined in: Poll.ts:67
messages
messages:
Message
[] =[]
Defined in: Poll.ts:78
numBatchesTallied
numBatchesTallied:
number
=0
Defined in: Poll.ts:112
perVoteOptionSpentVoiceCredits
perVoteOptionSpentVoiceCredits:
bigint
[] =[]
Defined in: Poll.ts:110
perVoteOptionSpentVoiceCreditsRootSalts
perVoteOptionSpentVoiceCreditsRootSalts:
Record
<number
|string
,bigint
> ={}
Defined in: Poll.ts:103
pollEndTimestamp
pollEndTimestamp:
bigint
Defined in: Poll.ts:72
pollId
pollId:
bigint
Defined in: Poll.ts:97
pollNullifiers
pollNullifiers:
Map
<bigint
,boolean
>
Defined in: Poll.ts:135
pollStateLeaves
pollStateLeaves:
StateLeaf
[]
Defined in: Poll.ts:129
pollStateTree?
optional
pollStateTree:IncrementalQuinTree
Defined in: Poll.ts:132
publicKeys
publicKeys:
PublicKey
[]
Defined in: Poll.ts:86
resultRootSalts
resultRootSalts:
Record
<number
|string
,bigint
> ={}
Defined in: Poll.ts:101
sbSalts
sbSalts:
Record
<number
|string
,bigint
> ={}
Defined in: Poll.ts:99
spentVoiceCreditSubtotalSalts
spentVoiceCreditSubtotalSalts:
Record
<number
|string
,bigint
> ={}
Defined in: Poll.ts:105
stateCopied
stateCopied:
boolean
=false
Defined in: Poll.ts:84
stateTree?
optional
stateTree:LeanIMT
<bigint
>
Defined in: Poll.ts:88
tallyResult
tallyResult:
bigint
[] =[]
Defined in: Poll.ts:108
totalBatchesProcessed
totalBatchesProcessed:
number
=0
Defined in: Poll.ts:91
totalSpentVoiceCredits
totalSpentVoiceCredits:
bigint
=0n
Defined in: Poll.ts:114
treeDepths
treeDepths:
ITreeDepths
Defined in: Poll.ts:61
voteOptions
voteOptions:
bigint
Defined in: Poll.ts:65
Methods
copy()
copy():
Poll
Defined in: Poll.ts:1273
Create a deep copy of the Poll object.
Returns
Poll
A new instance of the Poll object with the same properties.
Implementation of
equals()
equals(
poll
):boolean
Defined in: Poll.ts:1348
Check if the Poll object is equal to another Poll object.
Parameters
poll
Poll
The Poll object to compare.
Returns
boolean
True if the two Poll objects are equal, false otherwise.
Implementation of
gettotalSignups()
gettotalSignups():
bigint
Defined in: Poll.ts:1462
Get the number of signups
Returns
bigint
The number of signups
getVoiceCreditsLeft()
getVoiceCreditsLeft(
args
):bigint
Defined in: Poll.ts:400
Get voice credits left for the voting command.
Parameters
args
IGetVoiceCreditsLeft
arguments for getting voice credits
Returns
bigint
voice credits left
hasJoined()
hasJoined(
nullifier
):boolean
Defined in: Poll.ts:188
Check if user has already joined the poll by checking if the nullifier is registered
Parameters
nullifier
bigint
Returns
boolean
Implementation of
hasUnprocessedMessages()
hasUnprocessedMessages():
boolean
Defined in: Poll.ts:582
This method checks if there are any unprocessed messages in the Poll instance.
Returns
boolean
Returns true if the number of processed batches is less than the total number of batches, false otherwise.
Implementation of
hasUntalliedBallots()
hasUntalliedBallots():
boolean
Defined in: Poll.ts:1003
Checks whether there are any untallied ballots.
Returns
boolean
Whether there are any untallied ballots
Implementation of
joinedCircuitInputs()
joinedCircuitInputs(
args
):IPollJoinedCircuitInputs
Defined in: Poll.ts:539
Create circuit input for pollJoined
Parameters
args
IJoinedCircuitArgs
Poll joined circuit inputs
Returns
IPollJoinedCircuitInputs
stringified circuit inputs
joiningCircuitInputs()
joiningCircuitInputs(
args
):IPollJoiningCircuitInputs
Defined in: Poll.ts:485
Create circuit input for pollJoining
Parameters
args
Poll joining circuit inputs
Returns
stringified circuit inputs
joinPoll()
joinPoll(
nullifier
,publicKey
,newVoiceCreditBalance
):number
Defined in: Poll.ts:197
Join the anonymous user to the Poll (to the tree)
Parameters
nullifier
bigint
Hashed private key used as nullifier
publicKey
PublicKey
The poll public key.
newVoiceCreditBalance
bigint
New voice credit balance of the user.
Returns
number
The index of added state leaf
padLastBatch()
padLastBatch():
void
Defined in: Poll.ts:571
Pad last unclosed batch
Returns
void
Implementation of
processAllMessages()
processAllMessages():
object
Defined in: Poll.ts:987
Process all messages. This function does not update the ballots or state leaves; rather, it copies and then updates them. This makes it possible to test the result of multiple processMessage() invocations.
Returns
object
The state leaves and ballots of the poll
ballots
ballots:
Ballot
[]
stateLeaves
stateLeaves:
StateLeaf
[]
Implementation of
processMessage()
processMessage(
message
,encryptionPublicKey
):IProcessMessagesOutput
Defined in: Poll.ts:279
Process one message.
Parameters
message
Message
The message to process.
encryptionPublicKey
PublicKey
The public key associated with the encryption private key.
Returns
A number of variables which will be used in the zk-SNARK circuit.
processMessages()
processMessages(
pollId
,quiet
):IProcessMessagesCircuitInputs
Defined in: Poll.ts:608
Process _batchSize messages starting from the saved index. This function will process messages even if the number of messages is not an exact multiple of _batchSize. e.g. if there are 10 messages, index is 8, and _batchSize is 4, this function will only process the last two messages in this.messages, and finally update the zeroth state leaf. Note that this function will only process as many state leaves as there are ballots to prevent accidental inclusion of a new user after this poll has concluded.
Parameters
pollId
bigint
The ID of the poll associated with the messages to process
quiet
boolean
= true
Whether to log errors or not
Returns
stringified circuit inputs
Implementation of
publishMessage()
publishMessage(
message
,encryptionPublicKey
):void
Defined in: Poll.ts:432
Inserts a Message and the corresponding public key used to generate the ECDH shared key which was used to encrypt said message.
Parameters
message
Message
The message to insert
encryptionPublicKey
PublicKey
The public key used to encrypt the message
Returns
void
Implementation of
setCoordinatorKeypair()
setCoordinatorKeypair(
serializedPrivateKey
):void
Defined in: Poll.ts:1446
Set the coordinator's keypair
Parameters
serializedPrivateKey
string
the serialized private key
Returns
void
Implementation of
setTotalSignups()
setTotalSignups(
totalSignups
):void
Defined in: Poll.ts:1454
Set the number of signups to match the ones from the contract
Parameters
totalSignups
bigint
the number of signups
Returns
void
tallyVotes()
tallyVotes():
IVoteTallyCircuitInputs
Defined in: Poll.ts:1010
This method tallies a ballots and updates the tally results.
Returns
the circuit inputs for the VoteTally circuit.
Implementation of
toJSON()
toJSON():
IJsonPoll
Defined in: Poll.ts:1381
Serialize the Poll object to a JSON object
Returns
a JSON object
Implementation of
updateChainHash()
updateChainHash(
messageHash
):void
Defined in: Poll.ts:471
Updates message chain hash
Parameters
messageHash
bigint
hash of message with encryptionPublicKey
Returns
void
Implementation of
updatePoll()
updatePoll(
totalSignups
):void
Defined in: Poll.ts:219
Update a Poll with data from MaciState. This is the step where we copy the state from the MaciState instance, and set the number of signups we have so far.
Parameters
totalSignups
bigint
Returns
void
Note
It should be called to generate the state for poll joining with totalSignups set as the number of signups in the MaciState. For message processing, you should set totalSignups as the number of users who joined the poll.
fromJSON()
static
fromJSON(json
,maciState
):Poll
Defined in: Poll.ts:1412
Deserialize a json object into a Poll instance
Parameters
json
the json object to deserialize
maciState
the reference to the MaciState Class
Returns
Poll
a new Poll instance