Skip to main content

bsv_rs/
lib.rs

1//! # BSV SDK
2//!
3//! A comprehensive Rust SDK for building BSV (Bitcoin SV) applications.
4//! Feature-complete and production-ready.
5//!
6//! ## Modules
7//!
8//! - **primitives**: Cryptographic primitives (hash, EC, encoding, AES-256-GCM)
9//! - **script**: Bitcoin Script parsing, execution, and templates (P2PKH, RPuzzle, PushDrop)
10//! - **transaction**: Transaction construction, signing, BEEF/MerklePath SPV proofs
11//! - **wallet**: BRC-42 key derivation, ProtoWallet, WalletClient
12//!
13//! ## Feature Flags
14//!
15//! - `primitives` (default): Core cryptographic primitives
16//! - `script` (default): Script parsing, execution, and templates
17//! - `transaction`: Transaction building, signing, BEEF format, fee models
18//! - `wallet`: BRC-42 key derivation, ProtoWallet, WalletClient
19//! - `full`: All features
20//! - `http`: HTTP client for ARC broadcaster, WhatsOnChain, WalletClient
21//! - `wasm`: WebAssembly support
22//!
23//! ## Quick Start
24//!
25//! ```rust
26//! use bsv_rs::primitives::{PrivateKey, sha256};
27//!
28//! // Generate a key pair
29//! let private_key = PrivateKey::random();
30//! let public_key = private_key.public_key();
31//!
32//! // Hash some data
33//! let hash = sha256(b"Hello, BSV!");
34//!
35//! // Sign a message
36//! let signature = private_key.sign(&hash).unwrap();
37//! assert!(public_key.verify(&hash, &signature));
38//! ```
39
40// Error types (shared across modules)
41pub mod error;
42pub use error::{Error, Result};
43
44// Internal utilities (wasm32-safe time helpers, etc.). Not part of the
45// public API — see `src/util/mod.rs`.
46pub(crate) mod util;
47
48// Feature-gated modules
49#[cfg(feature = "primitives")]
50pub mod primitives;
51
52#[cfg(feature = "script")]
53pub mod script;
54
55#[cfg(feature = "transaction")]
56pub mod transaction;
57
58#[cfg(feature = "wallet")]
59pub mod wallet;
60
61#[cfg(feature = "messages")]
62pub mod messages;
63
64#[cfg(feature = "compat")]
65pub mod compat;
66
67#[cfg(feature = "totp")]
68pub mod totp;
69
70#[cfg(feature = "auth")]
71pub mod auth;
72
73#[cfg(feature = "overlay")]
74pub mod overlay;
75
76#[cfg(feature = "storage")]
77pub mod storage;
78
79#[cfg(feature = "registry")]
80pub mod registry;
81
82#[cfg(feature = "kvstore")]
83pub mod kvstore;
84
85#[cfg(feature = "identity")]
86pub mod identity;
87
88// Convenience re-exports from primitives (most common items)
89#[cfg(feature = "primitives")]
90pub use primitives::{
91    from_hex, hash160, sha256, sha256d, to_hex, BigNumber, PrivateKey, PublicKey, Signature,
92    SymmetricKey,
93};
94
95// Convenience re-exports from script
96#[cfg(feature = "script")]
97pub use script::{Address, LockingScript, Script, ScriptChunk, UnlockingScript};
98
99// Convenience re-exports from transaction
100#[cfg(feature = "transaction")]
101pub use transaction::{ChangeDistribution, Transaction, TransactionInput, TransactionOutput};
102
103// Convenience re-exports from wallet
104#[cfg(feature = "wallet")]
105pub use wallet::{
106    CacheConfig, CachedKeyDeriver, Counterparty, KeyDeriver, KeyDeriverApi, ProtoWallet, Protocol,
107    SecurityLevel,
108};
109
110// Convenience re-exports from messages
111#[cfg(feature = "messages")]
112pub use messages::{decrypt, encrypt, sign, verify};
113
114// Convenience re-exports from compat
115#[cfg(feature = "compat")]
116pub use compat::{Language, Mnemonic, WordCount};
117
118// Convenience re-exports from totp
119#[cfg(feature = "totp")]
120pub use totp::{Algorithm as TotpAlgorithm, Totp, TotpOptions, TotpValidateOptions};
121
122// Convenience re-exports from auth
123#[cfg(feature = "socketio")]
124pub use auth::{
125    install_app_event_listener, run_dispatch, AppEvent, SocketIoFrameSource, SocketIoSink,
126    SocketIoTransport,
127};
128#[cfg(feature = "auth")]
129pub use auth::{
130    AuthMessage, Certificate, MasterCertificate, MessageType, Peer, PeerOptions, PeerSession,
131    RequestedCertificateSet, SessionManager, SimplifiedFetchTransport, Transport,
132    VerifiableCertificate,
133};
134#[cfg(feature = "websocket")]
135pub use auth::{WebSocketTransport, WebSocketTransportOptions};
136
137// Convenience re-exports from overlay
138#[cfg(feature = "overlay")]
139pub use overlay::{
140    LookupAnswer, LookupQuestion, LookupResolver, NetworkPreset, Steak, TaggedBEEF,
141    TopicBroadcaster,
142};
143// Note: overlay::Protocol is separate from wallet::Protocol
144
145// Convenience re-exports from storage
146#[cfg(feature = "storage")]
147pub use storage::{
148    get_hash_from_url, get_url_for_file, is_valid_url, DownloadResult, StorageDownloader,
149    StorageUploader, UploadFileResult, UploadableFile,
150};
151
152// Convenience re-exports from registry
153#[cfg(feature = "registry")]
154pub use registry::{
155    BasketDefinitionData, BasketQuery, BroadcastFailure, BroadcastSuccess,
156    CertificateDefinitionData, CertificateFieldDescriptor, CertificateQuery, DefinitionData,
157    DefinitionType, ProtocolDefinitionData, ProtocolQuery, RegisterDefinitionResult,
158    RegistryClient, RegistryClientConfig, RegistryRecord, RevokeDefinitionResult, TokenData,
159};
160
161// Convenience re-exports from kvstore
162#[cfg(feature = "kvstore")]
163pub use kvstore::{
164    GlobalKVStore, KVStoreConfig, KVStoreEntry, KVStoreGetOptions, KVStoreQuery,
165    KVStoreRemoveOptions, KVStoreSetOptions, KVStoreToken, LocalKVStore,
166};
167
168// Convenience re-exports from identity
169#[cfg(feature = "identity")]
170pub use identity::{
171    Contact, ContactsManager, ContactsManagerConfig, DisplayableIdentity, IdentityClient,
172    IdentityClientConfig, IdentityQuery, KnownCertificateType,
173};