Dig Wallet Rust
A comprehensive Rust implementation of a Chia wallet with full feature parity to the TypeScript version, built using the DataLayer-Driver v0.1.50.
๐ Features
โ Complete Wallet Management
- 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
โ Full Cryptographic Support
- 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
โ Blockchain Integration
- 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
โ Advanced Features
- 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
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= "0.1.50"
= { = "1.0", = ["full"] }
๐ง Usage
Basic Wallet Operations
use ;
async
Peer Connection and Coin Operations
use Wallet;
use NetworkType;
async
Digital Signatures
use Wallet;
async
Address Conversion
use Wallet;
๐งช Testing
The project includes comprehensive test coverage with 24 tests covering all functionality:
# Run all tests
# Run only unit tests
# Run only integration tests
# Run example
Test Coverage
- โ 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.
๐ API Reference
Core Types
Main Methods
Wallet Management
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
Key Operations
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
Signatures
wallet.create_key_ownership_signature(nonce)- Create signatureWallet::verify_key_ownership_signature(nonce, sig, pubkey)- Verify signature
Peer Operations
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
Address Utilities
Wallet::address_to_puzzle_hash(address)- Decode addressWallet::puzzle_hash_to_address(hash, prefix)- Encode address
๐ Security Features
Encryption
- AES-256-GCM: Industry-standard encryption for mnemonic storage
- Random Salts: Each encryption uses unique random salt
- Secure Nonces: Cryptographically secure random nonces
Key Management
- BIP39 Compliance: Standard mnemonic generation and validation
- Deterministic Keys: Same mnemonic always produces same keys
- Memory Safety: Rust prevents buffer overflows and memory leaks
Network Security
- SSL/TLS: Encrypted peer connections using Chia SSL certificates
- Signature Verification: BLS signature validation for authenticity
๐๏ธ Architecture
Dependencies
- 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
File Structure
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
๐ Comparison with TypeScript Version
| 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 |
Improvements Over TypeScript
- ๐ 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
๐ Performance
- Fast Compilation: Optimized for development workflow
- Efficient Runtime: Zero-cost abstractions
- Low Memory Usage: Rust's ownership system
- Concurrent Safe: Built-in thread safety
๐ค Contributing
- Fork the repository
- Create a feature branch
- Add comprehensive tests
- Ensure all tests pass:
cargo test -- --test-threads=1 - Submit a pull request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Related Projects
- DataLayer-Driver - Core Chia blockchain integration
- Chia Blockchain - Official Chia implementation
๐ Support
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.