Skip to main content
Version: v1.2

PCommand

Notice

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

Implements​

Table of contents​

Constructors​

Properties​

Methods​

Constructors​

constructor​

• new PCommand(stateIndex, newPubKey, voteOptionIndex, newVoteWeight, nonce, pollId, salt?): PCommand

Create a new PCommand

Parameters​

NameTypeDescription
stateIndexbigintthe state index of the user
newPubKeyPubKeythe new public key of the user
voteOptionIndexbigintthe index of the vote option
newVoteWeightbigintthe new vote weight of the user
noncebigintthe nonce of the message
pollIdbigintthe poll ID
saltbigintthe salt of the message

Returns​

PCommand

Defined in​

commands/PCommand.ts:59

Properties​

cmdType​

• cmdType: bigint

Implementation of​

ICommand.cmdType

Defined in​

commands/PCommand.ts:33


newPubKey​

• newPubKey: PubKey

Defined in​

commands/PCommand.ts:37


newVoteWeight​

• newVoteWeight: bigint

Defined in​

commands/PCommand.ts:41


nonce​

• nonce: bigint

Defined in​

commands/PCommand.ts:43


pollId​

• pollId: bigint

Defined in​

commands/PCommand.ts:45


salt​

• salt: bigint

Defined in​

commands/PCommand.ts:47


stateIndex​

• stateIndex: bigint

Defined in​

commands/PCommand.ts:35


voteOptionIndex​

• voteOptionIndex: bigint

Defined in​

commands/PCommand.ts:39

Methods​

asArray​

▸ asArray(): bigint[]

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.

Defined in​

commands/PCommand.ts:107


asCircuitInputs​

▸ asCircuitInputs(): bigint[]

Returns​

bigint[]

Defined in​

commands/PCommand.ts:123


copy​

▸ copy<T>(): T

Create a deep clone of this PCommand

Type parameters​

NameType
Textends PCommand

Returns​

T

a copy of the PCommand

Implementation of​

ICommand.copy

Defined in​

commands/PCommand.ts:90


encrypt​

▸ encrypt(signature, sharedKey): Message

Parameters​

NameType
signatureSignature<SnarkBigNumber>
sharedKeyEcdhSharedKey

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

Defined in​

commands/PCommand.ts:162


equals​

▸ equals(command): boolean

Parameters​

NameType
commandPCommand

Returns​

boolean

Implementation of​

ICommand.equals

Defined in​

commands/PCommand.ts:128


hash​

▸ hash(): bigint

Returns​

bigint

Defined in​

commands/PCommand.ts:137


sign​

▸ sign(privKey): Signature<SnarkBigNumber>

Parameters​

NameType
privKeyPrivKey

Returns​

Signature<SnarkBigNumber>

Notice

Signs this command and returns a Signature.

Defined in​

commands/PCommand.ts:142


toJSON​

▸ toJSON(): IJsonPCommand

Serialize into a JSON object

Returns​

IJsonPCommand

Implementation of​

ICommand.toJSON

Defined in​

commands/PCommand.ts:226


verifySignature​

▸ verifySignature(signature, pubKey): boolean

Parameters​

NameType
signatureSignature<SnarkBigNumber>
pubKeyPubKey

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.

Defined in​

commands/PCommand.ts:149


decrypt​

▸ decrypt(message, sharedKey, force?): IDecryptMessage

Decrypts a Message to produce a Command.

Parameters​

NameTypeDefault valueDescription
messageMessageundefinedthe message to decrypt
sharedKeyEcdhSharedKeyundefinedthe shared key to use for decryption
forcebooleanfalsewhether 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.

Defined in​

commands/PCommand.ts:182


fromJSON​

▸ fromJSON(json): PCommand

Deserialize into a PCommand instance

Parameters​

NameType
jsonIJsonPCommand

Returns​

PCommand

a PCommand instance

Defined in​

commands/PCommand.ts:244