| Crates.io | dig-wallet |
| lib.rs | dig-wallet |
| version | 2.0.0 |
| created_at | 2025-09-06 00:30:20.549035+00 |
| updated_at | 2025-12-09 14:26:11.949381+00 |
| description | A comprehensive Rust wallet implementation for Chia blockchain with full DataLayer-Driver integration |
| homepage | https://github.com/DIG-Network/digwallet-rust |
| repository | https://github.com/DIG-Network/digwallet-rust |
| max_upload_size | |
| id | 1826511 |
| size | 226,686 |
A comprehensive Rust implementation of a Chia wallet with full feature parity to the TypeScript version, built using the DataLayer-Driver v0.1.50.
connect_randomAdd 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
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 walletswallet.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 addresswallet.create_key_ownership_signature(nonce) - Create signatureWallet::verify_key_ownership_signature(nonce, sig, pubkey) - Verify signatureWallet::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 statusWallet::address_to_puzzle_hash(address) - Decode addressWallet::puzzle_hash_to_address(hash, prefix) - Encode addresssrc/
โโโ 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 |
cargo test -- --test-threads=1This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
Production Ready: This implementation provides a complete, secure, and performant Rust wallet with full feature parity to the TypeScript version.