A fast, asynchronous Rust library for the BSV PayMail protocol, enabling seamless integration with Bitcoin SV services. ⚡
- Host and Capability Discovery: Resolves PayMail domains via DNS SRV and A/AAAA records, fetching capabilities over HTTP. 🔍
- PKI Resolution: Retrieves public keys for PayMail addresses (BRFC 759684b1a19a). 🔑
- Payment Address Resolution: Supports signed payment destination requests (BRFC 759684b1a19a). 💸
- P2P Transactions: Implements P2P payment destinations and transaction submission (BRFCs 2a40af698840, 5f1323cddf31). 🔗
- Extensible: Handles custom BRFC extensions via the
call_extensionmethod. 🛠️ - Fully Asynchronous: Built with Tokio for high-performance async operations. 🕒
- BSV Primitives: Leverages
rust-svfor robust cryptographic operations. 🔒
Add to your Cargo.toml:
[dependencies]
paymail-rs = { git = "https://github.com/your-repo/paymail-rs.git", tag = "v0.1.2" }Ensure you have Rust 1.86 or later installed.
- Install Rust: Follow the official Rust installation guide.
- Clone the Repository:
git clone https://github.com/murphsicles/paymail-rs.git cd paymail-rs - Build the Project:
cargo build
- Run Examples:
See
cargo run --example client
examples/client.rsfor a sample client implementation that demonstrates fetching public keys and payment destinations.
Create a PaymailClient with a private key and use it to interact with PayMail services:
use paymail_rs::PaymailClient;
use secp256k1::SecretKey;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load a valid secp256k1 private key (replace with your own)
let priv_key = SecretKey::from_slice(&[
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
])?;
let client = PaymailClient::builder().build(priv_key);
// Get public key
let pubkey = client.get_pubkey("[email protected]").await?;
println!("Pubkey: {pubkey}");
// Get payment destination
use paymail_rs::models::PaymentRequest;
let req = PaymentRequest {
sender_name: Some("Sender".to_string()),
sender_handle: "[email protected]".to_string(),
dt: "".to_string(),
amount: Some(10000),
purpose: Some("Test".to_string()),
signature: "".to_string(),
};
let output = client.get_payment_destination("[email protected]", req).await?;
println!("Output: {output}");
// P2P transaction
let tx_resp = client.send_p2p_tx("[email protected]", "txhex", json!({}), "ref").await?;
println!("Tx: {tx_resp:?}");
Ok(())
}The library includes integration tests for core functionality:
- Capabilities Resolution: Tests fetching PayMail capabilities (
tests/integration.rs). - Public Key Resolution: Tests retrieving public keys for PayMail addresses (
tests/integration.rs). - Tests use
wiremockandmockallto mock HTTP and DNS responses, ensuring reliability.
Run tests with:
cargo testFor benchmarks:
cargo benchContributions are welcome! Please:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/my-feature). - Commit changes (
git commit -am 'Add my feature'). - Push to the branch (
git push origin feature/my-feature). - Open a pull request.
Ensure all code passes cargo fmt, cargo clippy, and cargo test.
This project is licensed under the Open BSV License. See the LICENSE file for details.
- Built with rust-sv for BSV primitives.
- Inspired by the BSV Alias (PayMail) specifications.