Skip to main content

bsv_wallet_toolbox_rs/
lib.rs

1//! BSV Wallet Toolbox
2//!
3//! Rust implementation of `@bsv/wallet-toolbox`, providing storage and services
4//! for BSV wallets. Built on top of `bsv-sdk` which provides cryptographic
5//! primitives, transaction building, and the `WalletInterface` trait.
6//!
7//! # Architecture
8//!
9//! ```text
10//! ┌─────────────────────────────────────────────────────────────────┐
11//! │                    bsv-wallet-toolbox                           │
12//! ├─────────────────────────────────────────────────────────────────┤
13//! │  Wallet (implements WalletInterface with full storage/services) │
14//! ├───────────────┬──────────────────────┬──────────────────────────┤
15//! │  WalletSigner │ WalletStorageManager │ Services │ Monitor       │
16//! ├───────────────┴──────────────────────┴──────────┴───────────────┤
17//! │  Storage: StorageSqlx (SQLite/MySQL) | StorageClient (Remote)   │
18//! └─────────────────────────────────────────────────────────────────┘
19//!                                 │
20//!                                 ▼
21//! ┌─────────────────────────────────────────────────────────────────┐
22//! │                        bsv-sdk                                   │
23//! │  primitives | script | transaction | wallet (ProtoWallet)       │
24//! └─────────────────────────────────────────────────────────────────┘
25//! ```
26//!
27//! # Features
28//!
29//! - `sqlite` (default) - SQLite storage backend
30//! - `mysql` - MySQL storage backend
31//! - `remote` - Remote storage via StorageClient (storage.babbage.systems)
32//! - `full` - All features enabled
33//!
34//! # Example
35//!
36//! ```rust,ignore
37//! use bsv_wallet_toolbox_rs::{Wallet, StorageSqlx, Services};
38//! use bsv_rs::wallet::WalletInterface;
39//!
40//! #[tokio::main]
41//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
42//!     // Open local SQLite storage
43//!     let storage = StorageSqlx::open("wallet.db").await?;
44//!
45//!     // Configure mainnet services
46//!     let services = Services::mainnet();
47//!
48//!     // Create wallet with root key
49//!     let wallet = Wallet::new(Some(root_key), storage, services).await?;
50//!
51//!     // Use WalletInterface methods
52//!     let outputs = wallet.list_outputs(args, "app.example.com").await?;
53//!
54//!     Ok(())
55//! }
56//! ```
57
58pub mod chaintracks;
59pub mod error;
60pub mod lock_utils;
61pub mod managers;
62pub mod monitor;
63pub mod services;
64pub mod storage;
65pub mod tsc_proof;
66pub mod wallet;
67
68pub use error::{Error, Result};
69
70// Re-export storage types
71pub use storage::{
72    AuthId, MonitorStorage, WalletStorageProvider, WalletStorageReader, WalletStorageSync,
73    WalletStorageWriter,
74};
75
76// Re-export StorageSqlx and BroadcastOutcome when sqlite or mysql feature is enabled
77#[cfg(any(feature = "sqlite", feature = "mysql"))]
78pub use storage::{classify_broadcast_results, BroadcastOutcome, StorageSqlx};
79
80// Re-export StorageClient when remote feature is enabled
81#[cfg(feature = "remote")]
82pub use storage::StorageClient;
83
84// Re-export commonly used bsv-sdk types
85pub use bsv_rs::wallet::{
86    AbortActionArgs, AbortActionResult, CreateActionArgs, CreateActionResult,
87    InternalizeActionArgs, InternalizeActionResult, ListActionsArgs, ListActionsResult,
88    ListCertificatesArgs, ListCertificatesResult, ListOutputsArgs, ListOutputsResult,
89    RelinquishCertificateArgs, RelinquishOutputArgs, WalletInterface,
90};
91
92// Re-export Chaintracks types
93pub use chaintracks::{
94    BaseBlockHeader, Chaintracks, ChaintracksClient, ChaintracksInfo, ChaintracksManagement,
95    ChaintracksOptions, ChaintracksStorage, HeightRange, InsertHeaderResult, LiveBlockHeader,
96};
97
98// Re-export Services types
99pub use services::{
100    AdaptiveTimeoutConfig, Arc, ArcConfig, BhsConfig, Bitails, BitailsConfig, BlockHeader,
101    BlockHeaderService, BsvExchangeRate, Chain, FallbackChainTracker, FiatCurrency,
102    FiatExchangeRates, GetMerklePathResult, GetRawTxResult, GetScriptHashHistoryResult,
103    GetStatusForTxidsResult, GetUtxoStatusOutputFormat, GetUtxoStatusResult, NLockTimeInput,
104    PostBeefResult, PostTxResultForTxid, ScriptHistoryItem, ServiceCallHistory, ServiceCollection,
105    Services, ServicesOptions, TxStatusDetail, UtxoDetail, WalletServices, WhatsOnChain,
106    WhatsOnChainConfig,
107};
108
109// Re-export Wallet types
110pub use wallet::{
111    HttpLookupResolver, OverlayCertificate, OverlayLookupResolver, ScriptType, SignerInput,
112    UnlockingScriptTemplate, UtxoInfo, Wallet, WalletBalance, WalletOptions, WalletSigner,
113};
114
115// Re-export Monitor types
116pub use monitor::{
117    Monitor, MonitorOptions, MonitorTask, TaskConfig, TaskResult, TransactionStatusUpdate,
118};
119
120// Re-export Managers types
121pub use managers::{
122    setup_wallet,
123    // Permissions manager
124    BasketUsageType,
125    // CWI-style wallet manager
126    CWIStyleWalletManager,
127    CWIStyleWalletManagerConfig,
128    CertificateUsageType,
129    // Settings manager
130    Certifier,
131    GroupedPermissions,
132    // Storage manager
133    ManagedStorage,
134    PermissionRequest,
135    PermissionRequestHandler,
136    PermissionToken,
137    PermissionUsageType,
138    PermissionsModule,
139    Profile,
140    // Setup helpers
141    SetupWalletOptions,
142    // Simple wallet manager
143    SimpleWalletManager,
144    TrustSettings,
145    UmpToken,
146    // Authentication manager
147    WalletAuthenticationManager,
148    WalletLogEntry,
149    // Logger
150    WalletLogger,
151    WalletPermissionsManager,
152    WalletPermissionsManagerConfig,
153    WalletSettings,
154    WalletSettingsManager,
155    WalletSettingsManagerConfig,
156    WalletSnapshot,
157    WalletStorageManager,
158    WalletTheme,
159    DEFAULT_SETTINGS,
160    TESTNET_DEFAULT_SETTINGS,
161};