silent-tweak-sdk 0.1.0

Zero-trust BIP352 Silent Payment client SDK — local scan key, verifiable tweaks, delta sync.
Documentation
//! # silent-tweak-sdk
//!
//! Zero-trust BIP352 Silent Payment client SDK.
//!
//! The scan key (`b_scan`) never leaves the client.  All cryptographic
//! derivation happens locally.  The remote server is treated as an
//! *untrusted* tweak provider: its data is always verified against a
//! Merkle commitment before use.
//!
//! ## Quick start
//!
//! ```rust,no_run
//! use silent_tweak_sdk::{SilentTweakClient, SilentTweakClientConfig, ScanKeys};
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//!     let keys = ScanKeys::from_secret_bytes(
//!         &hex::decode("b_scan_hex_here").unwrap(),
//!         &hex::decode("b_spend_hex_here").unwrap(),
//!     )?;
//!     let cfg = SilentTweakClientConfig::new("http://localhost:8080");
//!     let client = SilentTweakClient::new(keys, cfg)?;
//!     let outputs = client.scan_range(840_000, 840_100).await?;
//!     println!("Found {} matching outputs", outputs.len());
//!     Ok(())
//! }
//! ```

#![deny(unsafe_code)]
#![warn(missing_docs, clippy::all, clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]

pub mod client;
pub mod crypto;
pub mod filters;
pub mod memo;
pub mod proto;

pub use client::{SilentTweakClient, SilentTweakClientConfig};
pub use crypto::{ScanKeys, SilentPaymentOutput};
pub use filters::gcs_encode;
pub use memo::ScanMemo;

/// Library-level error type.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// Cryptographic error.
    #[error("crypto: {0}")]
    Crypto(String),

    /// Network / HTTP error.
    #[error("network: {0}")]
    Network(#[from] reqwest::Error),

    /// Serialization error.
    #[error("serialization: {0}")]
    Serialization(#[from] serde_json::Error),

    /// Merkle commitment verification failed.
    #[error("commitment verification failed for block {block_hash}")]
    CommitmentMismatch {
        /// The block hash whose commitment failed verification.
        block_hash: String,
    },

    /// Invalid server response.
    #[error("invalid server response: {0}")]
    InvalidResponse(String),

    /// Bitcoin library error.
    #[error("bitcoin: {0}")]
    Bitcoin(String),
}

/// Library result alias.
pub type Result<T> = std::result::Result<T, Error>;