Skip to main content

Types

The Inco Lightning SDK provides encrypted types that serve as handles to encrypted values stored off-chain by the covalidator network.

Euint128

Handle to an encrypted unsigned 128-bit integer.
use inco_lightning::types::Euint128;

pub struct Euint128(pub u128);
The Euint128 type represents a reference to an encrypted value, not the encrypted data itself. The actual encrypted data is stored and processed by the covalidator network.

Ebool

Handle to an encrypted boolean value.
use inco_lightning::types::Ebool;

pub struct Ebool(pub u128);

Storing Handles

Handles are 16 bytes and can be stored directly in your account structs:
#[account]
pub struct ConfidentialAccount {
    pub balance: Euint128,      // Handle to encrypted balance
    pub is_active: Ebool,       // Handle to encrypted boolean
}
Handles are deterministically derived from operations, so the same operation with the same inputs always produces the same handle.

Input Functions

Create encrypted values from client-encrypted ciphertext or plaintext.
FunctionDescriptionSignature
new_euint128Create encrypted u128 from ciphertext(CpiContext, Vec<u8>, u8) -> Result<Euint128>
new_eboolCreate encrypted bool from ciphertext(CpiContext, Vec<u8>, u8) -> Result<Ebool>
as_euint128Convert plaintext u128 to encrypted handle(CpiContext, u128) -> Result<Euint128>
as_eboolConvert plaintext bool to encrypted handle(CpiContext, bool) -> Result<Ebool>

Example: Creating encrypted values

pub fn deposit(
    ctx: Context<Deposit>,
    ciphertext: Vec<u8>,  // Client-encrypted amount
) -> Result<()> {
    // Create CPI context
    let cpi_ctx = CpiContext::new(
        ctx.accounts.inco_lightning_program.to_account_info(),
        Operation {
            signer: ctx.accounts.authority.to_account_info(),
        },
    );

    // Create encrypted handle from ciphertext
    let encrypted_amount: Euint128 = new_euint128(cpi_ctx, ciphertext, 0)?;

    // Store the handle
    ctx.accounts.vault.balance = encrypted_amount;

    Ok(())
}
The last parameter in input and operation calls identifies whether the left-hand side operand is ciphertext (0) or plaintext (1). Always pass 0 when working with encrypted handles.