Skip to main content
Version: v2.x

Minimal Anti Collusion Infrastructure (MACI) v2.5.0 / Poll

Class: Poll

A representation of the Poll contract.

Implements

Constructors

new Poll()

new Poll(pollEndTimestamp, coordinatorKeypair, treeDepths, batchSizes, maciStateRef): Poll

Constructs a new Poll object.

Parameters

pollEndTimestamp: bigint

The Unix timestamp at which the poll ends.

coordinatorKeypair: Keypair

The keypair of the coordinator.

treeDepths: TreeDepths

The depths of the trees used in the poll.

batchSizes: BatchSizes

The sizes of the batches used in the poll.

maciStateRef: MaciState

The reference to the MACI state.

Returns

Poll

Defined in

Poll.ts:148

Properties

actualStateTreeDepth

actualStateTreeDepth: number

Defined in

Poll.ts:69


ballots

ballots: Ballot[] = []

Defined in

Poll.ts:73


ballotTree?

optional ballotTree: IncrementalQuinTree

Defined in

Poll.ts:75


batchHashes

batchHashes: bigint[]

Defined in

Poll.ts:125


batchSizes

batchSizes: BatchSizes

Defined in

Poll.ts:61


chainHash

chainHash: bigint = NOTHING_UP_MY_SLEEVE

Defined in

Poll.ts:122


commands

commands: PCommand[] = []

Defined in

Poll.ts:79


coordinatorKeypair

coordinatorKeypair: Keypair

Defined in

Poll.ts:57


currentMessageBatchIndex

currentMessageBatchIndex: number

Defined in

Poll.ts:92


emptyBallot

emptyBallot: Ballot

Defined in

Poll.ts:117


emptyBallotHash?

optional emptyBallotHash: bigint

Defined in

Poll.ts:119


encPubKeys

encPubKeys: PubKey[] = []

Defined in

Poll.ts:81


maciStateRef

maciStateRef: MaciState

Defined in

Poll.ts:94


maxVoteOptions

maxVoteOptions: number

Defined in

Poll.ts:63


messages

messages: Message[] = []

Defined in

Poll.ts:77


numBatchesProcessed

numBatchesProcessed: number = 0

Defined in

Poll.ts:90


numBatchesTallied

numBatchesTallied: number = 0

Defined in

Poll.ts:111


perVOSpentVoiceCredits

perVOSpentVoiceCredits: bigint[] = []

Defined in

Poll.ts:109


pollEndTimestamp

pollEndTimestamp: bigint

Defined in

Poll.ts:71


pollId

pollId: bigint

Defined in

Poll.ts:96


pollNullifiers

pollNullifiers: Map<bigint, boolean>

Defined in

Poll.ts:134


pollStateLeaves

pollStateLeaves: StateLeaf[]

Defined in

Poll.ts:128


pollStateTree?

optional pollStateTree: IncrementalQuinTree

Defined in

Poll.ts:131


preVOSpentVoiceCreditsRootSalts

preVOSpentVoiceCreditsRootSalts: Record<string | number, bigint> = {}

Defined in

Poll.ts:102


pubKeys

pubKeys: PubKey[]

Defined in

Poll.ts:85


resultRootSalts

resultRootSalts: Record<string | number, bigint> = {}

Defined in

Poll.ts:100


sbSalts

sbSalts: Record<string | number, bigint> = {}

Defined in

Poll.ts:98


spentVoiceCreditSubtotalSalts

spentVoiceCreditSubtotalSalts: Record<string | number, bigint> = {}

Defined in

Poll.ts:104


stateCopied

stateCopied: boolean = false

Defined in

Poll.ts:83


stateTree?

optional stateTree: LeanIMT<bigint>

Defined in

Poll.ts:87


stateTreeDepth

stateTreeDepth: number

Defined in

Poll.ts:66


tallyResult

tallyResult: bigint[] = []

Defined in

Poll.ts:107


totalSpentVoiceCredits

totalSpentVoiceCredits: bigint = 0n

Defined in

Poll.ts:113


treeDepths

treeDepths: TreeDepths

Defined in

Poll.ts:59

Methods

copy()

copy(): Poll

Create a deep copy of the Poll object.

Returns

Poll

A new instance of the Poll object with the same properties.

Implementation of

IPoll.copy

Defined in

Poll.ts:1285


equals()

equals(p): boolean

Check if the Poll object is equal to another Poll object.

Parameters

p: Poll

The Poll object to compare.

Returns

boolean

True if the two Poll objects are equal, false otherwise.

Implementation of

IPoll.equals

Defined in

Poll.ts:1353


getNumSignups()

getNumSignups(): bigint

Get the number of signups

Returns

bigint

The number of signups

Defined in

Poll.ts:1454


hasJoined()

hasJoined(nullifier): boolean

Check if user has already joined the poll by checking if the nullifier is registered

Parameters

nullifier: bigint

Returns

boolean

Implementation of

IPoll.hasJoined

Defined in

Poll.ts:179


hasUnprocessedMessages()

hasUnprocessedMessages(): boolean

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

IPoll.hasUnprocessedMessages

Defined in

Poll.ts:506


hasUntalliedBallots()

hasUntalliedBallots(): boolean

Checks whether there are any untallied ballots.

Returns

boolean

Whether there are any untallied ballots

Implementation of

IPoll.hasUntalliedBallots

Defined in

Poll.ts:910


joiningCircuitInputs()

joiningCircuitInputs(__namedParameters): IPollJoiningCircuitInputs

Create circuit input for pollJoining

Parameters

__namedParameters: IJoiningCircuitArgs

Returns

IPollJoiningCircuitInputs

stringified circuit inputs

Defined in

Poll.ts:441


joinPoll()

joinPoll(nullifier, pubKey, newVoiceCreditBalance, timestamp): number

Join the anonymous user to the Poll (to the tree)

Parameters

nullifier: bigint

Hashed private key used as nullifier

pubKey: PubKey

The poll public key.

newVoiceCreditBalance: bigint

New voice credit balance of the user.

timestamp: bigint

The timestamp of the sign-up.

Returns

number

The index of added state leaf

Defined in

Poll.ts:189


padLastBatch()

padLastBatch(): void

Pad last unclosed batch

Returns

void

Implementation of

IPoll.padLastBatch

Defined in

Poll.ts:495


processAllMessages()

processAllMessages(): object

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

IPoll.processAllMessages

Defined in

Poll.ts:894


processMessage()

processMessage(message, encPubKey, qv): IProcessMessagesOutput

Process one message.

Parameters

message: Message

The message to process.

encPubKey: PubKey

The public key associated with the encryption private key.

qv: boolean = true

Returns

IProcessMessagesOutput

A number of variables which will be used in the zk-SNARK circuit.

Defined in

Poll.ts:266


processMessages()

processMessages(pollId, qv, quiet): IProcessMessagesCircuitInputs

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

qv: boolean = true

quiet: boolean = true

Whether to log errors or not

Returns

IProcessMessagesCircuitInputs

stringified circuit inputs

Implementation of

IPoll.processMessages

Defined in

Poll.ts:532


publishMessage()

publishMessage(message, encPubKey): void

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

encPubKey: PubKey

The public key used to encrypt the message

Returns

void

Implementation of

IPoll.publishMessage

Defined in

Poll.ts:385


setCoordinatorKeypair()

setCoordinatorKeypair(serializedPrivateKey): void

Set the coordinator's keypair

Parameters

serializedPrivateKey: string

the serialized private key

Returns

void

Implementation of

IPoll.setCoordinatorKeypair

Defined in

Poll.ts:1438


setNumSignups()

setNumSignups(numSignups): void

Set the number of signups to match the ones from the contract

Parameters

numSignups: bigint

the number of signups

Returns

void

Defined in

Poll.ts:1446


tallyVotes()

tallyVotes(): ITallyCircuitInputs

This method tallies a ballots and updates the tally results.

Returns

ITallyCircuitInputs

the circuit inputs for the TallyVotes circuit.

Implementation of

IPoll.tallyVotes

Defined in

Poll.ts:916


tallyVotesNonQv()

tallyVotesNonQv(): ITallyCircuitInputs

Returns

ITallyCircuitInputs

Defined in

Poll.ts:1088


toJSON()

toJSON(): IJsonPoll

Serialize the Poll object to a JSON object

Returns

IJsonPoll

a JSON object

Implementation of

IPoll.toJSON

Defined in

Poll.ts:1386


updateChainHash()

updateChainHash(messageHash): void

Updates message chain hash

Parameters

messageHash: bigint

hash of message with encPubKey

Returns

void

Implementation of

IPoll.updateChainHash

Defined in

Poll.ts:424


updatePoll()

updatePoll(numSignups): void

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

numSignups: bigint

Returns

void

Note

It should be called to generate the state for poll joining with numSignups set as the number of signups in the MaciState. For message processing, you should set numSignups as the number of users who joined the poll.

Defined in

Poll.ts:211


fromJSON()

static fromJSON(json, maciState): Poll

Deserialize a json object into a Poll instance

Parameters

json: IJsonPoll

the json object to deserialize

maciState: MaciState

the reference to the MaciState Class

Returns

Poll

a new Poll instance

Defined in

Poll.ts:1413