Skip to main content

Encrypted Types & Handles

A handle is a 128-bit reference to an encrypted value stored off-chain by the covalidator network.

Handle Types

use inco_lightning::types::{Euint128, Ebool};

// Euint128 - handle to an encrypted unsigned 128-bit integer
pub struct Euint128(pub u128);

// Ebool - handle to an encrypted boolean
pub struct Ebool(pub u128);

Deterministic Derivation

Handles are deterministically derived from operations, so the same operation with the same inputs always produces the same handle. This allows programs to store and reference encrypted values without storing the actual ciphertext on-chain.

Storing Handles

Store handles in your Anchor account structs. Handles are only 16 bytes each:
#[account]
pub struct ConfidentialAccount {
    pub balance: Euint128,      // Handle to encrypted balance (16 bytes)
    pub is_active: Ebool,       // Handle to encrypted boolean (16 bytes)
}

Account Size Example

#[account]
pub struct Vault {
    pub owner: Pubkey,           // 32 bytes
    pub balance: Euint128,       // 16 bytes (handle only!)
    pub bump: u8,                // 1 byte
}
// Total: 49 bytes + 8 bytes discriminator = 57 bytes
Always check if handles are initialized before performing operations:
if !handle.is_initialized() {
    return Err(ErrorCode::UninitializedHandle.into());
}

Handle Lifecycle

  1. Creation: Handle is created when encrypting a value via new_euint128 or new_ebool
  2. Operations: New handles are created as results of encrypted operations
  3. Storage: Handles are stored on-chain in account data
  4. Decryption: Authorized parties can request decryption of handles they have access to