Skip to main content

Ciphertext

Overview

SnarkVM Ciphertext object. A Ciphertext represents a symmetrically encrypted plaintext. This object provides decryption methods to recover the plaintext from the ciphertext given the proper decryption materials like view keys, transition keys, or nonces.

Methods

decrypt

Decrypt the ciphertext using the given view key

decrypt(viewKey, nonce)Plaintext
ParamTypeDescription
viewKeyViewKeyThe view key of the account that encrypted the ciphertext
nonceGroupThe nonce used to encrypt the ciphertext
returnPlaintextThe decrypted plaintext

decryptWithTransitionInfo

Decrypt a ciphertext using the view key of the transition signer, transition public key, and (program, function, index) tuple

decryptWithTransitionInfo(view_key, transition_public_key, program, function_name, index)Plaintext
ParamTypeDescription
view_keyViewKeyThe view key of the transition signer
transition_public_keyGroupThe transition public key used to encrypt the ciphertext
programstringThe program ID associated with the ciphertext
function_namestringThe name of the function associated with the encrypted inputs and outputs
indexu16The index of the input or output parameter that was encrypted
returnPlaintextThe decrypted plaintext

decryptWithTransitionViewKey

Decrypt a ciphertext using the transition view key and a (program, function, index) tuple

decryptWithTransitionViewKey(transition_view_key, program, function_name, index)Plaintext
ParamTypeDescription
transition_view_keyFieldThe transition view key that was used to encrypt the ciphertext
programstringThe program ID associated with the ciphertext
function_namestringThe name of the function associated with the encrypted inputs and outputs
indexu16The index of the input or output parameter that was encrypted
returnPlaintextThe decrypted plaintext

decryptSymmetric

Decrypts a ciphertext into plaintext using the given ciphertext view key

decryptSymmetric(transition_view_key)Plaintext
ParamTypeDescription
transition_view_keyFieldThe transition view key that was used to encrypt the ciphertext
returnPlaintextThe decrypted plaintext

fromBytesLe

Deserialize a left endian byte array into a Ciphertext

fromBytesLe(bytes)Ciphertext
ParamTypeDescription
bytesUint8ArrayThe byte array representing the Ciphertext
returnCiphertextThe Ciphertext object

toBytesLe

Get the left endian byte array representation of the ciphertext

toBytesLe()Uint8Array
ParamType
returnUint8Array

fromBitsLe

Get a ciphertext object from a series of bits represented as a boolean array

fromBitsLe(bits)Ciphertext
ParamTypeDescription
bitsArrayA left endian boolean array representing the bits of the ciphertext
returnCiphertextThe ciphertext object

toBitsLe

Get the left endian boolean array representation of the bits of the ciphertext

toBitsLe()Array.<any>
ParamType
returnArray.<any>

fromFields

Get a ciphertext object from an array of fields

fromFields(fields)Ciphertext
ParamTypeDescription
fieldsArrayAn array of fields
returnCiphertextThe ciphertext object

toFields

Get the field array representation of the ciphertext

toFields()Array.<any>
ParamType
returnArray.<any>

fromString

Deserialize a Ciphertext string into a Ciphertext object

fromString(ciphertext)Ciphertext
ParamTypeDescription
ciphertextstringA string representation of the ciphertext
returnCiphertextThe Ciphertext object

toBytes

Serialize a Ciphertext object into a byte array

toBytes()Uint8Array
ParamType
returnUint8Array

toString

Serialize a Ciphertext into a js string

toString() ► string
ParamType
returnstring