A comprehensive Rust implementation of a Chia wallet with full feature parity to the TypeScript version, built using the DataLayer-Driver v0.1.50.
- Wallet Creation: Generate new wallets with secure 24-word BIP39 mnemonics
 - Wallet Import: Import existing wallets from mnemonic seed phrases
 - Multiple Wallets: Support for managing multiple named wallets
 - Secure Storage: AES-256-GCM encrypted keyring storage
 
- Key Derivation: BIP39 compliant mnemonic to key derivation
 - Digital Signatures: BLS signature creation and verification
 - Address Generation: Proper XCH address encoding using bech32m
 - Deterministic: Same mnemonic always generates same keys/addresses
 
- Peer Connection: Connect to random Chia peers using 
connect_random - Coin Operations: Select unspent coins and check spendability
 - Network Support: Both mainnet and testnet11 support
 - SSL Integration: Automatic Chia SSL certificate detection
 
- File Caching: Generic file-based caching system
 - Error Handling: Comprehensive error types and handling
 - Address Conversion: Bidirectional puzzle hash β address conversion
 - Memory Safety: Rust's ownership system prevents common security issues
 
Add this to your Cargo.toml:
[dependencies]
dig-wallet = "0.1.0"
datalayer-driver = "0.1.50"
tokio = { version = "1.0", features = ["full"] }use dig_wallet::{Wallet, WalletError};
#[tokio::main]
async fn main() -> Result<(), WalletError> {
    // Create or load a wallet
    let wallet = Wallet::load(Some("my_wallet".to_string()), true).await?;
    
    // Get wallet information
    let mnemonic = wallet.get_mnemonic()?;
    let address = wallet.get_owner_public_key().await?;
    
    println!("Address: {}", address);
    Ok(())
}use dig_wallet::Wallet;
use datalayer_driver::NetworkType;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Connect to a random mainnet peer
    let peer = Wallet::connect_mainnet_peer().await?;
    
    // Or connect with custom SSL certificates
    let peer = Wallet::connect_random_peer(
        NetworkType::Mainnet,
        "/path/to/cert.crt",
        "/path/to/key.key"
    ).await?;
    
    // Load wallet and select coins
    let wallet = Wallet::load(Some("my_wallet".to_string()), true).await?;
    let coins = wallet.select_unspent_coins(&peer, 1000000, 1000, vec![]).await?;
    
    println!("Selected {} coins", coins.len());
    Ok(())
}use dig_wallet::Wallet;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let wallet = Wallet::load(Some("my_wallet".to_string()), true).await?;
    
    // Create a signature
    let signature = wallet.create_key_ownership_signature("my_nonce").await?;
    
    // Verify the signature
    let public_key = wallet.get_public_synthetic_key().await?;
    let public_key_hex = hex::encode(public_key.to_bytes());
    
    let is_valid = Wallet::verify_key_ownership_signature(
        "my_nonce", 
        &signature, 
        &public_key_hex
    ).await?;
    
    println!("Signature valid: {}", is_valid);
    Ok(())
}use dig_wallet::Wallet;
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let address = "xch1qm9g5qxq4xrqqkpvmk6j64ckpjp7xeq78mdmfz48lp8g5zgq4sxs2370ec";
    
    // Convert address to puzzle hash
    let puzzle_hash = Wallet::address_to_puzzle_hash(address)?;
    
    // Convert back to address
    let converted_address = Wallet::puzzle_hash_to_address(puzzle_hash, "xch")?;
    
    assert_eq!(address, converted_address);
    Ok(())
}The project includes comprehensive test coverage with 24 tests covering all functionality:
# Run all tests
cargo test -- --test-threads=1
# Run only unit tests
cargo test --lib -- --test-threads=1
# Run only integration tests
cargo test --test integration_tests -- --test-threads=1
# Run example
cargo run --example wallet_usage- β 17 Unit Tests: Core functionality, cryptography, error handling
 - β 7 Integration Tests: Full lifecycle, edge cases, concurrency
 - β 100% Pass Rate: All tests consistently pass
 - β Comprehensive Coverage: All public APIs and error paths tested
 
See TEST_COVERAGE.md for detailed test documentation.
pub struct Wallet {
    // Private fields
}
pub enum WalletError {
    MnemonicRequired,
    InvalidMnemonic,
    MnemonicNotLoaded,
    WalletNotFound(String),
    CryptoError(String),
    NetworkError(String),
    FileSystemError(String),
    // ... more error types
}Wallet::load(name, create_on_undefined)- Load or create walletWallet::create_new_wallet(name)- Create wallet with new mnemonicWallet::import_wallet(name, mnemonic)- Import wallet from mnemonicWallet::delete_wallet(name)- Delete wallet from keyringWallet::list_wallets()- List all stored wallets
wallet.get_mnemonic()- Get mnemonic seed phrasewallet.get_master_secret_key()- Get master secret keywallet.get_public_synthetic_key()- Get public synthetic keywallet.get_private_synthetic_key()- Get private synthetic keywallet.get_owner_puzzle_hash()- Get puzzle hashwallet.get_owner_public_key()- Get XCH address
wallet.create_key_ownership_signature(nonce)- Create signatureWallet::verify_key_ownership_signature(nonce, sig, pubkey)- Verify signature
Wallet::connect_mainnet_peer()- Connect to mainnet with default SSLWallet::connect_testnet_peer()- Connect to testnet with default SSLWallet::connect_random_peer(network, cert, key)- Connect with custom SSLwallet.select_unspent_coins(peer, amount, fee, omit)- Select coinsWallet::is_coin_spendable(peer, coin_id)- Check coin status
Wallet::address_to_puzzle_hash(address)- Decode addressWallet::puzzle_hash_to_address(hash, prefix)- Encode address
- AES-256-GCM: Industry-standard encryption for mnemonic storage
 - Random Salts: Each encryption uses unique random salt
 - Secure Nonces: Cryptographically secure random nonces
 
- BIP39 Compliance: Standard mnemonic generation and validation
 - Deterministic Keys: Same mnemonic always produces same keys
 - Memory Safety: Rust prevents buffer overflows and memory leaks
 
- SSL/TLS: Encrypted peer connections using Chia SSL certificates
 - Signature Verification: BLS signature validation for authenticity
 
- DataLayer-Driver v0.1.50: Core Chia blockchain integration
 - bip39: Mnemonic generation and validation
 - aes-gcm: AES-256-GCM encryption
 - tokio: Async runtime for network operations
 - serde: Serialization for data persistence
 
src/
βββ lib.rs          # Public API exports
βββ wallet.rs       # Core wallet implementation
βββ error.rs        # Error types and handling
βββ file_cache.rs   # Generic file caching system
tests/
βββ integration_tests.rs  # Comprehensive integration tests
examples/
βββ wallet_usage.rs       # Usage examples
| Feature | TypeScript | Rust | Status | 
|---|---|---|---|
| Wallet Management | β | β | Complete | 
| Cryptographic Operations | β | β | Complete | 
| Peer Connection | β | β | Complete | 
| Address Encoding | β | β | Complete | 
| Coin Operations | β | β | Complete | 
| Encrypted Storage | β | β | Enhanced | 
| Error Handling | β | β | Enhanced | 
| Memory Safety | β | β | Rust Advantage | 
| Performance | Good | β | Rust Advantage | 
| Type Safety | Good | β | Rust Advantage | 
- π Better Security: AES-256-GCM vs simpler encryption
 - β‘ Higher Performance: Native compiled code
 - π‘οΈ Memory Safety: No buffer overflows or memory leaks
 - π Type Safety: Compile-time error prevention
 - π§ͺ Better Testing: Comprehensive test coverage
 
- Fast Compilation: Optimized for development workflow
 - Efficient Runtime: Zero-cost abstractions
 - Low Memory Usage: Rust's ownership system
 - Concurrent Safe: Built-in thread safety
 
- Fork the repository
 - Create a feature branch
 - Add comprehensive tests
 - Ensure all tests pass: 
cargo test -- --test-threads=1 - Submit a pull request
 
This project is licensed under the MIT License - see the LICENSE file for details.
- DataLayer-Driver - Core Chia blockchain integration
 - Chia Blockchain - Official Chia implementation
 
For issues and questions:
- Create an issue in the GitHub repository
 - Check the test coverage documentation
 - Review the example usage code
 
Production Ready: This implementation provides a complete, secure, and performant Rust wallet with full feature parity to the TypeScript version.