program module provides data structures for Aleo programs and their execution. These types represent program state, function parameters, and return values.
Identifier
A named identifier for program components (variables, functions, structs, etc.).Structure
Rules
- Must be lowercase alphanumeric with underscores
- Cannot be a reserved keyword
- Maximum length depends on context
Example
ProgramID
A unique identifier for an Aleo program.Structure
Identifier<N>
The program name (lowercase alphanumeric)
Identifier<N>
The network-level domain (NLD), must be “aleo”
Methods
fn name(&self) -> &Identifier<N>
Returns the program name
fn network(&self) -> &Identifier<N>
Returns the network-level domain
fn is_aleo(&self) -> bool
Returns true if the network-level domain is “aleo”
Format
Program IDs follow the format{name}.{network}:
Literal
A primitive value in Aleo programs.Variants
Type Checking
Literals have an associatedLiteralType:
Example
Casting
Literals support type casting:Plaintext
A plaintext value that can be a literal, struct, or array.Variants
(Literal<N>, OnceLock<Vec<bool>>)
A primitive value with cached bit representation
(IndexMap<Identifier<N>, Plaintext<N>>, OnceLock<Vec<bool>>)
A struct with named fields and cached bit representation
(Vec<Plaintext<N>>, OnceLock<Vec<bool>>)
An array of plaintext values with cached bit representation
Methods
fn from_bit_array(bits: Vec<bool>, length: u32) -> Result<Self>
Creates a plaintext from a bit array
fn as_bit_array(&self) -> Result<Vec<bool>>
Returns the plaintext as a bit array
fn as_byte_array(&self) -> Result<Vec<u8>>
Returns the plaintext as a byte array
fn as_field_array(&self) -> Result<Vec<Field<N>>>
Returns the plaintext as a field array
Example - Literals
Example - Structs
Example - Arrays
Nested Structures
Plaintext supports arbitrary nesting:Record
A record is an encrypted state object with an owner.Structure
Owner<N, Private>
The owner of the record (address or ciphertext)
IndexMap<Identifier<N>, Entry<N, Private>>
The record data (named entries)
Group<N>
The nonce used for encryption and commitment
U8<N>
Version 0 uses BHP hash, version 1 uses BHP commitment
Owner
Entry
Record entries can be public or private:Methods
fn from_plaintext(...) -> Result<Record<N, Plaintext<N>>>
Creates a plaintext record
fn from_ciphertext(...) -> Result<Record<N, Ciphertext<N>>>
Creates a ciphertext record
fn owner(&self) -> &Owner<N, Private>
Returns the record owner
fn data(&self) -> &IndexMap<Identifier<N>, Entry<N, Private>>
Returns the record data
fn nonce(&self) -> &Group<N>
Returns the nonce
fn version(&self) -> &U8<N>
Returns the version
fn is_hiding(&self) -> bool
Returns true if using hiding commitments (version != 0)
fn encrypt(&self, randomizer: Scalar<N>) -> Result<Record<N, Ciphertext<N>>>
Encrypts the record
fn decrypt(view_key: &ViewKey<N>) -> Result<Record<N, Plaintext<N>>>
Decrypts a ciphertext record
Example
Value
A value can be a plaintext, record, or future.Variants
Plaintext<N>
A plaintext value (literal, struct, or array)
Record<N, Plaintext<N>>
A record value with owner and data
Future<N>
A future representing deferred computation
Conversions
Value implementsFrom for all its variants:
Example
Request and Response
Types for function calls.Request
Represents a signed function request:fn sign(...) -> Result<Self>
Signs a request with a private key
fn verify(&self, ...) -> bool
Verifies the request signature
Response
Represents function outputs:Access Paths
Access nested data in structs and arrays:Example
Type System
Types are checked at compile time:See Also
- Console Types - Primitive types used in programs
- Account Types - Keys and addresses
- Network Module - Network parameters and limits