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
Name | Type | Description |
---|---|---|
stateIndex | bigint | the state index of the user |
newPubKey | PubKey | 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
Defined in
Properties
cmdType
• cmdType: bigint
Implementation of
Defined in
newPubKey
• newPubKey: PubKey
Defined in
newVoteWeight
• newVoteWeight: bigint
Defined in
nonce
• nonce: bigint
Defined in
pollId
• pollId: bigint
Defined in
salt
• salt: bigint
Defined in
stateIndex
• stateIndex: bigint
Defined in
voteOptionIndex
• voteOptionIndex: bigint
Defined in
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
asCircuitInputs
▸ asCircuitInputs(): bigint
[]
Returns
bigint
[]
Defined in
copy
▸ copy<T
>(): T
Create a deep clone of this PCommand
Type parameters
Name | Type |
---|---|
T | extends PCommand |
Returns
T
a copy of the PCommand
Implementation of
Defined in
encrypt
▸ encrypt(signature
, sharedKey
): Message
Parameters
Name | Type |
---|---|
signature | Signature <SnarkBigNumber > |
sharedKey | EcdhSharedKey |
Returns
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
equals
▸ equals(command
): boolean
Parameters
Name | Type |
---|---|
command | PCommand |
Returns
boolean
Implementation of
Defined in
hash
▸ hash(): bigint
Returns
bigint
Defined in
sign
▸ sign(privKey
): Signature
<SnarkBigNumber
>
Parameters
Name | Type |
---|---|
privKey | PrivKey |
Returns
Signature
<SnarkBigNumber
>
Notice
Signs this command and returns a Signature.
Defined in
toJSON
▸ toJSON(): IJsonPCommand
Serialize into a JSON object
Returns
Implementation of
Defined in
verifySignature
▸ verifySignature(signature
, pubKey
): boolean
Parameters
Name | Type |
---|---|
signature | Signature <SnarkBigNumber > |
pubKey | PubKey |
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
decrypt
▸ decrypt(message
, sharedKey
, force?
): IDecryptMessage
Decrypts a Message to produce a Command.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
message | Message | undefined | the message to decrypt |
sharedKey | EcdhSharedKey | undefined | 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.
Defined in
fromJSON
▸ fromJSON(json
): PCommand
Deserialize into a PCommand instance
Parameters
Name | Type |
---|---|
json | IJsonPCommand |
Returns
a PComamnd instance