Minimal Anti Collusion Infrastructure (MACI) / Poll
Class: Poll
Defined in: Poll.ts:58
A representation of the Poll contract.
Implements
Constructors
Constructor
new Poll(
pollEndTimestamp,coordinatorKeypair,treeDepths,batchSizes,maciStateRef,voteOptions,mode):Poll
Defined in: Poll.ts:161
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:72
ballots
ballots:
Ballot[] =[]
Defined in: Poll.ts:76
ballotTree?
optionalballotTree:IncrementalQuinTree
Defined in: Poll.ts:78
batchHashes
batchHashes:
bigint[]
Defined in: Poll.ts:136
batchSizes
batchSizes:
IBatchSizes
Defined in: Poll.ts:65
chainHash
chainHash:
bigint=NOTHING_UP_MY_SLEEVE
Defined in: Poll.ts:133
commands
commands:
VoteCommand[] =[]
Defined in: Poll.ts:86
coordinatorKeypair
coordinatorKeypair:
Keypair
Defined in: Poll.ts:61
currentMessageBatchIndex
currentMessageBatchIndex:
number
Defined in: Poll.ts:99
emptyBallot
emptyBallot:
Ballot
Defined in: Poll.ts:123
emptyBallotHash
emptyBallotHash:
bigint
Defined in: Poll.ts:125
emptyVoteCounts
emptyVoteCounts:
VoteCounts
Defined in: Poll.ts:128
emptyVoteCountsHash
emptyVoteCountsHash:
bigint
Defined in: Poll.ts:130
encryptionPublicKeys
encryptionPublicKeys:
PublicKey[] =[]
Defined in: Poll.ts:88
maciStateRef
maciStateRef:
MaciState
Defined in: Poll.ts:101
maxVoteOptions
maxVoteOptions:
number
Defined in: Poll.ts:69
messages
messages:
Message[] =[]
Defined in: Poll.ts:84
numBatchesTallied
numBatchesTallied:
number=0
Defined in: Poll.ts:118
perVoteOptionSpentVoiceCredits
perVoteOptionSpentVoiceCredits:
bigint[] =[]
Defined in: Poll.ts:116
perVoteOptionSpentVoiceCreditsRootSalts
perVoteOptionSpentVoiceCreditsRootSalts:
Record<number|string,bigint> ={}
Defined in: Poll.ts:109
pollEndTimestamp
pollEndTimestamp:
bigint
Defined in: Poll.ts:74
pollId
pollId:
bigint
Defined in: Poll.ts:103
pollNullifiers
pollNullifiers:
Map<bigint,boolean>
Defined in: Poll.ts:145
pollStateLeaves
pollStateLeaves:
StateLeaf[]
Defined in: Poll.ts:139
pollStateTree?
optionalpollStateTree:IncrementalQuinTree
Defined in: Poll.ts:142
publicKeys
publicKeys:
PublicKey[]
Defined in: Poll.ts:92
resultRootSalts
resultRootSalts:
Record<number|string,bigint> ={}
Defined in: Poll.ts:107
sbSalts
sbSalts:
Record<number|string,bigint> ={}
Defined in: Poll.ts:105
spentVoiceCreditSubtotalSalts
spentVoiceCreditSubtotalSalts:
Record<number|string,bigint> ={}
Defined in: Poll.ts:111
stateCopied
stateCopied:
boolean=false
Defined in: Poll.ts:90
stateTree?
optionalstateTree:LeanIMT<bigint>
Defined in: Poll.ts:94
tallyResult
tallyResult:
bigint[] =[]
Defined in: Poll.ts:114
totalBatchesProcessed
totalBatchesProcessed:
number=0
Defined in: Poll.ts:97
totalSpentVoiceCredits
totalSpentVoiceCredits:
bigint=0n
Defined in: Poll.ts:120
treeDepths
treeDepths:
ITreeDepths
Defined in: Poll.ts:63
voteCounts
voteCounts:
VoteCounts[] =[]
Defined in: Poll.ts:80
voteCountsTree?
optionalvoteCountsTree:IncrementalQuinTree
Defined in: Poll.ts:82
voteOptions
voteOptions:
bigint
Defined in: Poll.ts:67
Methods
copy()
copy():
Poll
Defined in: Poll.ts:1330
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:1410
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:1528
Get the number of signups
Returns
bigint
The number of signups
getVoiceCreditsLeft()
getVoiceCreditsLeft(
args):bigint
Defined in: Poll.ts:429
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:204
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:601
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:1023
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:559
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:514
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:213
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:590
Pad last unclosed batch
Returns
void
Implementation of
processAllMessages()
processAllMessages():
object
Defined in: Poll.ts:1007
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:308
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:627
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:461
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:1512
Set the coordinator's keypair
Parameters
serializedPrivateKey
string
the serialized private key
Returns
void
Implementation of
setTotalSignups()
setTotalSignups(
totalSignups):void
Defined in: Poll.ts:1520
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:1030
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:1445
Serialize the Poll object to a JSON object
Returns
a JSON object
Implementation of
updateChainHash()
updateChainHash(
messageHash):void
Defined in: Poll.ts:500
Updates message chain hash
Parameters
messageHash
bigint
hash of message with encryptionPublicKey
Returns
void
Implementation of
updatePoll()
updatePoll(
totalSignups):void
Defined in: Poll.ts:235
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()
staticfromJSON(json,maciState):Poll
Defined in: Poll.ts:1477
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