silent_tweak_sdk/lib.rs
1//! # silent-tweak-sdk
2//!
3//! Zero-trust BIP352 Silent Payment client SDK.
4//!
5//! The scan key (`b_scan`) never leaves the client. All cryptographic
6//! derivation happens locally. The remote server is treated as an
7//! *untrusted* tweak provider: its data is always verified against a
8//! Merkle commitment before use.
9//!
10//! ## Quick start
11//!
12//! ```rust,no_run
13//! use silent_tweak_sdk::{SilentTweakClient, SilentTweakClientConfig, ScanKeys};
14//!
15//! #[tokio::main]
16//! async fn main() -> anyhow::Result<()> {
17//! let keys = ScanKeys::from_secret_bytes(
18//! &hex::decode("b_scan_hex_here").unwrap(),
19//! &hex::decode("b_spend_hex_here").unwrap(),
20//! )?;
21//! let cfg = SilentTweakClientConfig::new("http://localhost:8080");
22//! let client = SilentTweakClient::new(keys, cfg)?;
23//! let outputs = client.scan_range(840_000, 840_100).await?;
24//! println!("Found {} matching outputs", outputs.len());
25//! Ok(())
26//! }
27//! ```
28
29#![deny(unsafe_code)]
30#![warn(missing_docs, clippy::all, clippy::pedantic)]
31#![allow(clippy::module_name_repetitions)]
32
33pub mod client;
34pub mod crypto;
35pub mod filters;
36pub mod memo;
37pub mod proto;
38
39pub use client::{SilentTweakClient, SilentTweakClientConfig};
40pub use crypto::{ScanKeys, SilentPaymentOutput};
41pub use filters::gcs_encode;
42pub use memo::ScanMemo;
43
44/// Library-level error type.
45#[derive(Debug, thiserror::Error)]
46pub enum Error {
47 /// Cryptographic error.
48 #[error("crypto: {0}")]
49 Crypto(String),
50
51 /// Network / HTTP error.
52 #[error("network: {0}")]
53 Network(#[from] reqwest::Error),
54
55 /// Serialization error.
56 #[error("serialization: {0}")]
57 Serialization(#[from] serde_json::Error),
58
59 /// Merkle commitment verification failed.
60 #[error("commitment verification failed for block {block_hash}")]
61 CommitmentMismatch {
62 /// The block hash whose commitment failed verification.
63 block_hash: String,
64 },
65
66 /// Invalid server response.
67 #[error("invalid server response: {0}")]
68 InvalidResponse(String),
69
70 /// Bitcoin library error.
71 #[error("bitcoin: {0}")]
72 Bitcoin(String),
73}
74
75/// Library result alias.
76pub type Result<T> = std::result::Result<T, Error>;