onyx_sdk/lib.rs
1//! # Solana Stealth SDK
2//!
3//! A library for private payments on Solana using Stealth Addresses.
4//!
5//! ## Overview
6//!
7//! Stealth addresses allow a sender to pay a recipient without revealing the
8//! connection between them. Each payment generates a unique one-time address
9//! that only the recipient can detect and spend from.
10//!
11//! ## Quick Start
12//!
13//! ### Receiving Payments
14//!
15//! ```rust,ignore
16//! use solana_stealth::{StealthMetaAddress, Scanner};
17//!
18//! // Generate a meta-address (do this once)
19//! let meta = StealthMetaAddress::generate();
20//! println!("Share this publicly: {}", meta.to_public_string());
21//!
22//! // Save your keys securely
23//! meta.save_to_file("~/.stealth/keys.json").unwrap();
24//!
25//! // Scan for incoming payments
26//! let scanner = Scanner::new(&meta);
27//! let payments = scanner.scan("https://api.devnet.solana.com").await.unwrap();
28//!
29//! for payment in payments {
30//! println!("Received {} lamports at {}", payment.amount.unwrap_or(0), payment.stealth_address);
31//!
32//! // Derive the keypair to spend these funds
33//! let keypair = scanner.derive_spend_keypair(&payment).unwrap();
34//! let solana_keypair = keypair.to_solana_keypair().unwrap();
35//! }
36//! ```
37//!
38//! ### Sending Payments
39//!
40//! ```rust,ignore
41//! use solana_stealth::{PublicMetaAddress, StealthPayment};
42//!
43//! // Parse recipient's meta-address
44//! let recipient = PublicMetaAddress::from_string("stealth1abc...").unwrap();
45//!
46//! // Create a stealth payment
47//! let payment = StealthPayment::create(&recipient, 1_000_000_000).unwrap(); // 1 SOL
48//!
49//! // The payment contains:
50//! // - stealth_address: where to send the funds
51//! // - ephemeral_pubkey: publish this on-chain so recipient can detect the payment
52//! ```
53//!
54//! ## How It Works
55//!
56//! 1. **Recipient** generates a stealth meta-address (spending + viewing keypairs)
57//! 2. **Recipient** publishes their meta-address publicly
58//! 3. **Sender** generates a unique stealth address using ECDH with the meta-address
59//! 4. **Sender** sends funds to the stealth address and publishes an announcement
60//! 5. **Recipient** scans announcements and detects payments addressed to them
61//! 6. **Recipient** derives the private key to spend the received funds
62//!
63//! ## Privacy Properties
64//!
65//! - Each payment uses a unique one-time address
66//! - Only the recipient can detect which payments are theirs
67//! - The sender cannot be linked to the recipient on-chain
68//! - Amounts are visible on-chain (v1 limitation)
69
70pub mod address;
71pub mod error;
72pub mod keys;
73pub mod scanner;
74pub mod spend;
75
76// Re-export main types
77pub use address::{derive_stealth_address, check_stealth_address, StealthPayment};
78pub use error::{Result, StealthError};
79pub use keys::{PublicMetaAddress, StealthMetaAddress};
80pub use scanner::{Announcement, DetectedPayment, Scanner, ScannerConfig};
81pub use spend::StealthKeypair;
82
83/// Version of the protocol
84pub const PROTOCOL_VERSION: &str = "v1";
85
86/// Prefix for encoded meta-addresses
87pub const META_ADDRESS_PREFIX: &str = "stealth1";