Skip to main content

Plaintext

Overview

SnarkVM Plaintext object. Plaintext is a fundamental monadic type used to represent Aleo primitive types (boolean, field, group, i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, scalar, and signature), struct types, and array types.

In the context of a web or NodeJS application, this type is useful for turning an Aleo type into a JS value, object, or array that might be necessary for performing computations within the application.

Examples

// Get the bond state of an existing address.
const bondState = await fetch(https://api.explorer.provable.com/v1/mainnet/program/credits.aleo/mapping/bond_state/aleo12zlythl7htjdtjjjz3ahdj4vl6wk3zuzm37s80l86qpx8fyx95fqnxcn2f);
// Convert the bond state to a Plaintext object.
const bondStatePlaintext = Plaintext.fromString(bond_state);
// Convert the Plaintext object to a JS object.
const bondStateObject = bond_state_plaintext.toObject();
// Check if the bond state matches the expected object.
const expectedObject = { validator: "aleo12zlythl7htjdtjjjz3ahdj4vl6wk3zuzm37s80l86qpx8fyx95fqnxcn2f", microcredits: 100000000u64 };
assert( JSON.stringify(bondStateObject) === JSON.stringify(expectedObject) );

Methods

find

Find plaintext member if the plaintext is a struct. Returns null if the plaintext is not a struct or the member does not exist

find(name)Plaintext
ParamTypeDescription
namestringThe name of the plaintext member to find
returnPlaintextThe plaintext member

encrypt

Encrypt a plaintext with an address and randomizer

encrypt(address, randomizer)Ciphertext
ParamTypeDescription
addressAddressThe address to encrypt the plaintext for
randomizerScalarThe randomizer to use for encryption
returnCiphertextThe encrypted ciphertext

encryptSymmetric

Encrypt a plaintext with a transition view key

encryptSymmetric(transition_view_key)Ciphertext
ParamTypeDescription
transition_view_keyFieldThe transition view key of the transition associated with the plaintext
returnCiphertextThe encrypted ciphertext

fromString

Creates a plaintext object from a string representation of a plaintext

fromString(plaintext)Plaintext
ParamTypeDescription
plaintextstringThe string representation of the plaintext
returnPlaintextThe plaintext object

fromBytesLe

Get a plaintext object from a series of bytes

fromBytesLe(bytes)Plaintext
ParamTypeDescription
bytesUint8ArrayA left endian byte array representing the plaintext
returnPlaintextThe plaintext object

toBytesLe

Get the left endian byte array representation of the plaintext

toBytesLe()Uint8Array
ParamTypeDescription
returnUint8ArrayThe left endian byte array representation of the plaintext

fromBitsLe

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

fromBitsLe(bits)Plaintext
ParamTypeDescription
bitsArrayA left endian boolean array representing the bits plaintext
returnPlaintextThe plaintext object

toBitsLe

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

toBitsLe()Array
ParamTypeDescription
returnArrayThe left endian boolean array representation of the bits of the plaintext

fromFields

Get a plaintext object from an array of fields

fromFields(fields)Plaintext
ParamTypeDescription
fieldsArrayAn array of fields
returnPlaintextThe plaintext object

toFields

Get the field array representation of the plaintext

toFields()Array
ParamTypeDescription
returnArrayThe field array representation of the plaintext

toString

Returns the string representation of the plaintext

toString() ► string
ParamTypeDescription
returnstringThe string representation of the plaintext

plaintextType

Gives the type of the plaintext

plaintextType() ► string
ParamTypeDescription
returnstringThe type of the plaintext

toObject

Attempt to convert the plaintext to a JS object

toObject()Object
ParamTypeDescription
returnObjectThe JS object representation of the plaintext