rialo-cdk

Crates.iorialo-cdk
lib.rsrialo-cdk
version0.1.10
created_at2025-10-28 12:38:12.723602+00
updated_at2025-12-09 20:56:16.819291+00
descriptionRialo CDK - A comprehensive toolkit for building with the Rialo blockchain
homepage
repositoryhttps://github.com/SubzeroLabs/rialo
max_upload_size
id1904706
size617,192
(subzerolabs-eng-ops)

documentation

README

Rialo Client Development Kit (CDK)

License

The Rialo CDK is a comprehensive toolkit that provides the fundamental building blocks for interacting with the Rialo blockchain. It serves as the foundation for wallet management, transaction processing, RPC communication, and configuration handling.

Features

  • Wallet Management: Create, load, and manage wallets with secure key handling
  • HD Wallet Support: BIP39 mnemonic generation and hierarchical deterministic wallet features
  • Transaction Building: Create, sign, and serialize blockchain transactions
  • RPC Client: Communicate with Rialo blockchain nodes using JSON-RPC
  • Configuration Management: Flexible configuration system with multiple storage backends
  • Secure Key Storage: Encrypted wallet storage with password protection

Feature Flags

Rialo CDK uses Cargo feature flags to allow customization of the library's functionality:

  • file-storage (default: enabled): Provides file-based wallet and configuration storage. Disable this in environments where filesystem access is unavailable.
  • encryption (default: enabled): Includes encryption/decryption functionality for wallet security. Can be disabled for testing or specific security environments.
  • hd-wallet (default: enabled): Enables hierarchical deterministic wallet functionality. Disable for a slimmer build without HD wallet support.
  • mnemonic (default: enabled): Provides mnemonic phrase generation and recovery (depends on hd-wallet). Can be disabled for simpler applications.
  • rpc-client (default: enabled): Includes the HTTP RPC client implementation. Disable to use custom RPC implementations without HTTP client dependencies.

Using Feature Flags

To use Rialo CDK with specific features, specify them in your Cargo.toml:

[dependencies]
rialo-cdk = { version = "0.1.0", default-features = false, features = ["file-storage", "encryption"] }

Getting Started

Installation

Add Rialo CDK to your project's dependencies:

[dependencies]
rialo-cdk = "0.1.0"

Basic Usage Examples

Creating and Managing Wallets

use rialo_cdk::wallet::{FileWalletProvider, WalletProvider};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize wallet provider with default path
    let wallet_dir = FileWalletProvider::default_path()?;
    let provider = FileWalletProvider::new(wallet_dir);

    // Create a new wallet with mnemonic
    let wallet = provider.create_with_mnemonic("my_wallet", "password123").await?;
    println!("Created wallet with address: {}", wallet.pubkey_string());

    // Load wallet
    let loaded_wallet = provider.load("my_wallet", "password123").await?;

    // List all wallets
    let wallets = provider.list().await?;
    for wallet_name in wallets {
        println!("Found wallet: {}", wallet_name);
    }

    Ok(())
}

Building and Sending Transactions

use rialo_cdk::transaction::TransactionBuilder;
use rialo_cdk::rpc::HttpRpcClient;

async fn send_transaction(wallet: &Wallet, recipient: &str, amount: u64) -> Result<String> {
    // Connect to a Rialo node
    let rpc_client = HttpRpcClient::new("http://localhost:4104".to_string());

    // Get current time in milliseconds for valid_from
    let valid_from = std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)
        .expect("Time went backwards")
        .as_millis() as i64;

    // Build transaction
    let tx_builder = TransactionBuilder::new(wallet.pubkey_string(), valid_from);
    let signed_tx = tx_builder
        .add_transfer_instruction(&wallet.pubkey_string(), recipient, amount)
        .sign(wallet)?;

    // Submit transaction
    let signature = rpc_client.send_transaction(&signed_tx).await?;

    Ok(signature)
}

Managing Configuration

use rialo_cdk::config::{FileConfigProvider, ConfigProvider, Config};

async fn manage_config() -> Result<()> {
    // Get config from default location
    let config_path = FileConfigProvider::default_path()?;
    let provider = FileConfigProvider::new(config_path);

    // Load existing config or create default
    let mut config = provider.load().await?;

    // Update settings
    config.set_network("devnet");
    config.default_balance_unit = "RLO".to_string();

    // Save changes
    provider.save(&config).await?;

    Ok(())
}

Core Components

Wallet Module

The wallet module provides a comprehensive set of tools for secure key management:

  • WalletProvider: Trait for wallet storage backends
  • FileWalletProvider: Implementation that stores wallets in the filesystem
  • InMemoryWalletProvider: Implementation that keeps wallets in memory (for testing)
  • Mnemonic Functions: For generating and using BIP39 seed phrases
  • Encryption Utilities: For secure storage of sensitive wallet data

Transaction Module

The transaction module handles the creation and signing of blockchain transactions:

  • TransactionBuilder: Fluent interface for constructing transactions
  • Instruction: Representation of individual operations within a transaction
  • AccountMeta: Metadata about accounts referenced in a transaction

RPC Module

The RPC module provides communication with Rialo blockchain nodes:

  • RpcClient: Trait defining the RPC interface
  • HttpRpcClient: Implementation using HTTP for JSON-RPC communication
  • Response Types: Structured data models for RPC responses

Configuration Module

The configuration module manages user preferences and network settings:

  • Config: Structure holding configuration parameters
  • ConfigProvider: Trait for configuration storage backends
  • FileConfigProvider: Implementation using JSON files for storage
  • InMemoryConfigProvider: Implementation keeping configuration in memory

Security Considerations

  • Wallet private keys are encrypted at rest
  • Passwords are never stored
  • Secure random number generation is used for cryptographic operations
  • Network communication supports TLS

License

This project is licensed under the Apache License, Version 2.0.

Commit count: 0

cargo fmt