Skip to main content
Version: v2.0_alpha

Poll

A representation of the Poll contract.

Implements

  • IPoll

Table of contents

Constructors

Properties

Methods

Constructors

constructor

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

Constructs a new Poll object.

Parameters

NameTypeDescription
pollEndTimestampbigintThe Unix timestamp at which the poll ends.
coordinatorKeypairKeypairThe keypair of the coordinator.
treeDepthsTreeDepthsThe depths of the trees used in the poll.
batchSizesBatchSizesThe sizes of the batches used in the poll.
maxValuesMaxValuesThe maximum values the MACI circuits can accept.
maciStateRefMaciStateThe reference to the MACI state.

Returns

Poll

Defined in

Poll.ts:132

Properties

actualStateTreeDepth

actualStateTreeDepth: number

Defined in

Poll.ts:66


ballotTree

Optional ballotTree: IncrementalQuinTree

Defined in

Poll.ts:72


ballots

ballots: Ballot[] = []

Defined in

Poll.ts:70


batchSizes

batchSizes: BatchSizes

Defined in

Poll.ts:58


commands

commands: PCommand[] = []

Defined in

Poll.ts:78


coordinatorKeypair

coordinatorKeypair: Keypair

Defined in

Poll.ts:54


currentMessageBatchIndex

Optional currentMessageBatchIndex: number

Defined in

Poll.ts:91


emptyBallot

emptyBallot: Ballot

Defined in

Poll.ts:116


emptyBallotHash

Optional emptyBallotHash: bigint

Defined in

Poll.ts:118


encPubKeys

encPubKeys: PubKey[] = []

Defined in

Poll.ts:80


maciStateRef

maciStateRef: MaciState

Defined in

Poll.ts:93


maxValues

maxValues: MaxValues

Defined in

Poll.ts:60


messageTree

messageTree: IncrementalQuinTree

Defined in

Poll.ts:76


messages

messages: Message[] = []

Defined in

Poll.ts:74


numBatchesProcessed

numBatchesProcessed: number = 0

Defined in

Poll.ts:89


numBatchesTallied

numBatchesTallied: number = 0

Defined in

Poll.ts:110


numSignups

Private numSignups: bigint

Defined in

Poll.ts:121


perVOSpentVoiceCredits

perVOSpentVoiceCredits: bigint[] = []

Defined in

Poll.ts:108


pollEndTimestamp

pollEndTimestamp: bigint

Defined in

Poll.ts:68


pollId

pollId: bigint

Defined in

Poll.ts:95


preVOSpentVoiceCreditsRootSalts

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

Defined in

Poll.ts:101


resultRootSalts

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

Defined in

Poll.ts:99


sbSalts

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

Defined in

Poll.ts:97


spentVoiceCreditSubtotalSalts

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

Defined in

Poll.ts:103


stateCopied

stateCopied: boolean = false

Defined in

Poll.ts:82


stateLeaves

stateLeaves: StateLeaf[]

Defined in

Poll.ts:84


stateTree

Optional stateTree: IncrementalQuinTree

Defined in

Poll.ts:86


stateTreeDepth

stateTreeDepth: number

Defined in

Poll.ts:63


tallyResult

tallyResult: bigint[] = []

Defined in

Poll.ts:106


totalSpentVoiceCredits

totalSpentVoiceCredits: bigint

Defined in

Poll.ts:112


treeDepths

treeDepths: TreeDepths

Defined in

Poll.ts:56

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:1182


equals

equals(p): boolean

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

Parameters

NameTypeDescription
pPollThe Poll object to compare.

Returns

boolean

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

Implementation of

IPoll.equals

Defined in

Poll.ts:1256


genPerVOSpentVoiceCreditsCommitment

genPerVOSpentVoiceCreditsCommitment(salt, numBallotsToCount, useQuadraticVoting?): bigint

This method generates a commitment to the spent voice credits per vote option.

This is the hash of the Merkle root of the spent voice credits per vote option and a salt, computed as Poseidon([root, _salt]).

Parameters

NameTypeDefault valueDescription
saltbigintundefinedThe salt used in the hash function.
numBallotsToCountnumberundefinedThe number of ballots to count for the calculation.
useQuadraticVotingbooleantrueWhether to use quadratic voting or not. Default is true.

Returns

bigint

Returns the hash of the Merkle root of the spent voice credits per vote option and a salt, computed as Poseidon([root, _salt]).

Defined in

Poll.ts:1156


genProcessMessagesCircuitInputsPartial

genProcessMessagesCircuitInputsPartial(index): CircuitInputs

Generates partial circuit inputs for processing a batch of messages

Parameters

NameTypeDescription
indexnumberThe index of the partial batch.

Returns

CircuitInputs

stringified partial circuit inputs

Defined in

Poll.ts:680


genSpentVoiceCreditSubtotalCommitment

genSpentVoiceCreditSubtotalCommitment(salt, numBallotsToCount, useQuadraticVoting?): bigint

This method generates a commitment to the total spent voice credits.

This is the hash of the total spent voice credits and a salt, computed as Poseidon([totalCredits, _salt]).

Parameters

NameTypeDefault valueDescription
saltbigintundefinedThe salt used in the hash function.
numBallotsToCountnumberundefinedThe number of ballots to count for the calculation.
useQuadraticVotingbooleantrueWhether to use quadratic voting or not. Default is true.

Returns

bigint

Returns the hash of the total spent voice credits and a salt, computed as Poseidon([totalCredits, _salt]).

Defined in

Poll.ts:1128


getNumSignups

getNumSignups(): bigint

Get the number of signups

Returns

bigint

The number of signups

Defined in

Poll.ts:1367


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:370


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:801


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

NameType
ballotsBallot[]
stateLeavesStateLeaf[]

Implementation of

IPoll.processAllMessages

Defined in

Poll.ts:785


processMessage

processMessage(message, encPubKey, qv?): IProcessMessagesOutput

Process one message.

Parameters

NameTypeDefault valueDescription
messageMessageundefinedThe message to process.
encPubKeyPubKeyundefinedThe public key associated with the encryption private key.
qvbooleantrue-

Returns

IProcessMessagesOutput

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

Defined in

Poll.ts:213


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

NameTypeDefault valueDescription
pollIdbigintundefinedThe ID of the poll associated with the messages to process
qvbooleantrue-
quietbooleantrueWhether to log errors or not

Returns

IProcessMessagesCircuitInputs

stringified circuit inputs

Implementation of

IPoll.processMessages

Defined in

Poll.ts:396


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

NameTypeDescription
messageMessageThe message to insert
encPubKeyPubKeyThe public key used to encrypt the message

Returns

void

Implementation of

IPoll.publishMessage

Defined in

Poll.ts:332


setCoordinatorKeypair

setCoordinatorKeypair(serializedPrivateKey): void

Set the coordinator's keypair

Parameters

NameTypeDescription
serializedPrivateKeystringthe serialized private key

Returns

void

Implementation of

IPoll.setCoordinatorKeypair

Defined in

Poll.ts:1351


setNumSignups

setNumSignups(numSignups): void

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

Parameters

NameTypeDescription
numSignupsbigintthe number of signups

Returns

void

Defined in

Poll.ts:1359


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:807


tallyVotesNonQv

tallyVotesNonQv(): ITallyCircuitInputs

Returns

ITallyCircuitInputs

Defined in

Poll.ts:982


toJSON

toJSON(): IJsonPoll

Serialize the Poll object to a JSON object

Returns

IJsonPoll

a JSON object

Implementation of

IPoll.toJSON

Defined in

Poll.ts:1292


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

NameType
numSignupsbigint

Returns

void

Defined in

Poll.ts:170


fromJSON

fromJSON(json, maciState): Poll

Deserialize a json object into a Poll instance

Parameters

NameTypeDescription
jsonIJsonPollthe json object to deserialize
maciStateMaciStatethe reference to the MaciState Class

Returns

Poll

a new Poll instance

Defined in

Poll.ts:1316