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
| Param | Type | Description |
|---|---|---|
| name | string | The name of the plaintext member to find |
| return | Plaintext | The plaintext member |
encrypt
Encrypt a plaintext with an address and randomizer
encrypt(address, randomizer) ► Ciphertext
| Param | Type | Description |
|---|---|---|
| address | Address | The address to encrypt the plaintext for |
| randomizer | Scalar | The randomizer to use for encryption |
| return | Ciphertext | The encrypted ciphertext |
encryptSymmetric
Encrypt a plaintext with a transition view key
encryptSymmetric(transition_view_key) ► Ciphertext
| Param | Type | Description |
|---|---|---|
| transition_view_key | Field | The transition view key of the transition associated with the plaintext |
| return | Ciphertext | The encrypted ciphertext |
fromString
Creates a plaintext object from a string representation of a plaintext
fromString(plaintext) ► Plaintext
| Param | Type | Description |
|---|---|---|
| plaintext | string | The string representation of the plaintext |
| return | Plaintext | The plaintext object |
fromBytesLe
Get a plaintext object from a series of bytes
fromBytesLe(bytes) ► Plaintext
| Param | Type | Description |
|---|---|---|
| bytes | Uint8Array | A left endian byte array representing the plaintext |
| return | Plaintext | The plaintext object |
toBytesLe
Get the left endian byte array representation of the plaintext
toBytesLe() ► Uint8Array
| Param | Type | Description |
|---|---|---|
| return | Uint8Array | The 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
| Param | Type | Description |
|---|---|---|
| bits | Array | A left endian boolean array representing the bits plaintext |
| return | Plaintext | The plaintext object |
toBitsLe
Get the left endian boolean array representation of the bits of the plaintext
toBitsLe() ► Array
| Param | Type | Description |
|---|---|---|
| return | Array | The left endian boolean array representation of the bits of the plaintext |
fromFields
Get a plaintext object from an array of fields
fromFields(fields) ► Plaintext
| Param | Type | Description |
|---|---|---|
| fields | Array | An array of fields |
| return | Plaintext | The plaintext object |
toFields
Get the field array representation of the plaintext
toFields() ► Array
| Param | Type | Description |
|---|---|---|
| return | Array | The field array representation of the plaintext |
toString
Returns the string representation of the plaintext
toString() ► string
| Param | Type | Description |
|---|---|---|
| return | string | The string representation of the plaintext |
plaintextType
Gives the type of the plaintext
plaintextType() ► string
| Param | Type | Description |
|---|---|---|
| return | string | The type of the plaintext |
toObject
Attempt to convert the plaintext to a JS object
toObject() ► Object
| Param | Type | Description |
|---|---|---|
| return | Object | The JS object representation of the plaintext |