Expand description
§rustywallet-address
Cryptocurrency address generation and validation for Bitcoin and Ethereum.
This crate provides type-safe APIs for generating and validating addresses from public keys, supporting multiple address formats:
- Bitcoin Legacy (P2PKH) - Addresses starting with
1(mainnet) orm/n(testnet) - Bitcoin SegWit (P2WPKH) - Addresses starting with
bc1q(mainnet) ortb1q(testnet) - Bitcoin Taproot (P2TR) - Addresses starting with
bc1p(mainnet) ortb1p(testnet) - Ethereum - Addresses starting with
0xwith EIP-55 checksum support
§Quick Start
use rustywallet_keys::prelude::PrivateKey;
use rustywallet_address::prelude::*;
// Generate a random private key
let private_key = PrivateKey::random();
// Bitcoin addresses
let public_key = private_key.public_key();
// Legacy P2PKH address
let p2pkh = P2PKHAddress::from_public_key(&public_key, Network::BitcoinMainnet).unwrap();
println!("P2PKH: {}", p2pkh); // 1...
// SegWit P2WPKH address
let p2wpkh = P2WPKHAddress::from_public_key(&public_key, Network::BitcoinMainnet).unwrap();
println!("P2WPKH: {}", p2wpkh); // bc1q...
// Taproot P2TR address
let p2tr = P2TRAddress::from_public_key(&public_key, Network::BitcoinMainnet).unwrap();
println!("P2TR: {}", p2tr); // bc1p...
// Ethereum address
let eth_addr = EthereumAddress::from_public_key(&public_key).unwrap();
println!("Ethereum: {}", eth_addr); // 0x...§Address Validation
use rustywallet_address::prelude::*;
// Validate any address
let result = Address::validate("bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4");
assert!(result.is_ok());
// Validate specific types
let result = P2WPKHAddress::validate("bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4");
assert!(result.is_ok());
// Validate Ethereum checksum
let result = EthereumAddress::validate_checksum("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed");
assert!(result.is_ok());§Address Type Detection
use rustywallet_address::prelude::*;
let addr: Address = "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4".parse().unwrap();
assert!(addr.is_bitcoin());
let addr: Address = "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed".parse().unwrap();
assert!(addr.is_ethereum());Re-exports§
pub use address::Address;pub use address::AddressFormat;pub use bitcoin::BitcoinAddress;pub use bitcoin::BitcoinAddressType;pub use bitcoin::P2PKHAddress;pub use bitcoin::P2TRAddress;pub use bitcoin::P2WPKHAddress;pub use error::AddressError;pub use ethereum::EthereumAddress;pub use network::Network;pub use silent_payments::SilentPaymentAddress;pub use silent_payments::SilentPaymentDeriver;pub use silent_payments::SilentPaymentLabel;
Modules§
- address
- Unified address type for all supported blockchains.
- bitcoin
- Bitcoin address types and generation.
- encoding
- Encoding utilities for address generation.
- error
- Error types for address operations.
- ethereum
- Ethereum address types and generation.
- network
- Network types for address generation.
- prelude
- Convenient re-exports for common usage.
- silent_
payments - Silent Payments (BIP352) support.