Skip to main content
Version: v3.x

Minimal Anti Collusion Infrastructure (MACI) / VoteCommand

Class: VoteCommand

Defined in: commands/VoteCommand.ts:31

Notice​

Unencrypted data whose fields include the user's public key, vote etc. This represents a Vote command.

Constructors​

Constructor​

new VoteCommand(stateIndex, newPublicKey, voteOptionIndex, newVoteWeight, nonce, pollId, salt): VoteCommand

Defined in: commands/VoteCommand.ts:56

Create a new VoteCommand

Parameters​

stateIndex​

bigint

the state index of the user

newPublicKey​

PublicKey

the new public key of the user

voteOptionIndex​

bigint

the index of the vote option

newVoteWeight​

bigint

the new vote weight of the user

nonce​

bigint

the nonce of the message

pollId​

bigint

the poll ID

salt​

bigint = ...

the salt of the message

Returns​

VoteCommand

Properties​

newPublicKey​

newPublicKey: PublicKey

Defined in: commands/VoteCommand.ts:34


newVoteWeight​

newVoteWeight: bigint

Defined in: commands/VoteCommand.ts:38


nonce​

nonce: bigint

Defined in: commands/VoteCommand.ts:40


pollId​

pollId: bigint

Defined in: commands/VoteCommand.ts:42


salt​

salt: bigint

Defined in: commands/VoteCommand.ts:44


stateIndex​

stateIndex: bigint

Defined in: commands/VoteCommand.ts:32


voteOptionIndex​

voteOptionIndex: bigint

Defined in: commands/VoteCommand.ts:36

Methods​

asArray()​

asArray(): bigint[]

Defined in: commands/VoteCommand.ts:102

Returns​

bigint[]

bigint[] - the command as an array

Notice​

Returns this Command as an array. Note that 5 of the Command's fields are packed into a single 250-bit value. This allows Messages to be smaller and thereby save gas when the user publishes a message.


asCircuitInputs()​

asCircuitInputs(): bigint[]

Defined in: commands/VoteCommand.ts:118

Returns​

bigint[]


copy()​

copy<T>(): T

Defined in: commands/VoteCommand.ts:85

Create a deep clone of this VoteCommand

Type Parameters​

T​

T extends VoteCommand

Returns​

T

a copy of the VoteCommand


encrypt()​

encrypt(signature, sharedKey): Message

Defined in: commands/VoteCommand.ts:157

Parameters​

signature​

Signature

sharedKey​

EcdhSharedKey

Returns​

Message

Notice​

Encrypts this command along with a signature to produce a Message. To save gas, we can constrain the following values to 50 bits and pack them into a 250-bit value: 0. state index 3. vote option index 4. new vote weight 5. nonce 6. poll ID


equals()​

equals(command): boolean

Defined in: commands/VoteCommand.ts:123

Parameters​

command​

VoteCommand

Returns​

boolean


hash()​

hash(): bigint

Defined in: commands/VoteCommand.ts:132

Returns​

bigint


sign()​

sign(privateKey): Signature

Defined in: commands/VoteCommand.ts:137

Parameters​

privateKey​

PrivateKey

Returns​

Signature

Notice​

Signs this command and returns a Signature.


toJSON()​

toJSON(): IJsonPCommand

Defined in: commands/VoteCommand.ts:223

Serialize into a JSON object

Returns​

IJsonPCommand


verifySignature()​

verifySignature(signature, publicKey): boolean

Defined in: commands/VoteCommand.ts:144

Parameters​

signature​

Signature

publicKey​

PublicKey

Returns​

boolean

Notice​

Returns true if the given signature is a correct signature of this command and signed by the private key associated with the given public key.


decrypt()​

static decrypt(message, sharedKey, force): IDecryptMessage

Defined in: commands/VoteCommand.ts:177

Decrypts a Message to produce a Command.

Parameters​

message​

Message

the message to decrypt

sharedKey​

EcdhSharedKey

the shared key to use for decryption

force​

boolean = false

whether to force decryption or not

Returns​

IDecryptMessage

Dev​

You can force decrypt the message by setting force to true. This is useful in case you don't want an invalid message to throw an error.


fromJSON()​

static fromJSON(json): VoteCommand

Defined in: commands/VoteCommand.ts:240

Deserialize into a VoteCommand instance

Parameters​

json​

IJsonPCommand

Returns​

VoteCommand

a VoteCommand instance