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// Feature-gated modules
45#[cfg(feature = "primitives")]
46pub mod primitives;
47
48#[cfg(feature = "script")]
49pub mod script;
50
51#[cfg(feature = "transaction")]
52pub mod transaction;
53
54#[cfg(feature = "wallet")]
55pub mod wallet;
56
57#[cfg(feature = "messages")]
58pub mod messages;
59
60#[cfg(feature = "compat")]
61pub mod compat;
62
63#[cfg(feature = "totp")]
64pub mod totp;
65
66#[cfg(feature = "auth")]
67pub mod auth;
68
69#[cfg(feature = "overlay")]
70pub mod overlay;
71
72#[cfg(feature = "storage")]
73pub mod storage;
74
75#[cfg(feature = "registry")]
76pub mod registry;
77
78#[cfg(feature = "kvstore")]
79pub mod kvstore;
80
81#[cfg(feature = "identity")]
82pub mod identity;
83
84// Convenience re-exports from primitives (most common items)
85#[cfg(feature = "primitives")]
86pub use primitives::{
87    from_hex, hash160, sha256, sha256d, to_hex, BigNumber, PrivateKey, PublicKey, Signature,
88    SymmetricKey,
89};
90
91// Convenience re-exports from script
92#[cfg(feature = "script")]
93pub use script::{Address, LockingScript, Script, ScriptChunk, UnlockingScript};
94
95// Convenience re-exports from transaction
96#[cfg(feature = "transaction")]
97pub use transaction::{ChangeDistribution, Transaction, TransactionInput, TransactionOutput};
98
99// Convenience re-exports from wallet
100#[cfg(feature = "wallet")]
101pub use wallet::{
102    CacheConfig, CachedKeyDeriver, Counterparty, KeyDeriver, KeyDeriverApi, ProtoWallet, Protocol,
103    SecurityLevel,
104};
105
106// Convenience re-exports from messages
107#[cfg(feature = "messages")]
108pub use messages::{decrypt, encrypt, sign, verify};
109
110// Convenience re-exports from compat
111#[cfg(feature = "compat")]
112pub use compat::{Language, Mnemonic, WordCount};
113
114// Convenience re-exports from totp
115#[cfg(feature = "totp")]
116pub use totp::{Algorithm as TotpAlgorithm, Totp, TotpOptions, TotpValidateOptions};
117
118// Convenience re-exports from auth
119#[cfg(feature = "auth")]
120pub use auth::{
121    AuthMessage, Certificate, MasterCertificate, MessageType, Peer, PeerOptions, PeerSession,
122    RequestedCertificateSet, SessionManager, SimplifiedFetchTransport, Transport,
123    VerifiableCertificate,
124};
125#[cfg(feature = "websocket")]
126pub use auth::{WebSocketTransport, WebSocketTransportOptions};
127
128// Convenience re-exports from overlay
129#[cfg(feature = "overlay")]
130pub use overlay::{
131    LookupAnswer, LookupQuestion, LookupResolver, NetworkPreset, Steak, TaggedBEEF,
132    TopicBroadcaster,
133};
134// Note: overlay::Protocol is separate from wallet::Protocol
135
136// Convenience re-exports from storage
137#[cfg(feature = "storage")]
138pub use storage::{
139    get_hash_from_url, get_url_for_file, is_valid_url, DownloadResult, StorageDownloader,
140    StorageUploader, UploadFileResult, UploadableFile,
141};
142
143// Convenience re-exports from registry
144#[cfg(feature = "registry")]
145pub use registry::{
146    BasketDefinitionData, BasketQuery, BroadcastFailure, BroadcastSuccess,
147    CertificateDefinitionData, CertificateFieldDescriptor, CertificateQuery, DefinitionData,
148    DefinitionType, ProtocolDefinitionData, ProtocolQuery, RegisterDefinitionResult,
149    RegistryClient, RegistryClientConfig, RegistryRecord, RevokeDefinitionResult, TokenData,
150};
151
152// Convenience re-exports from kvstore
153#[cfg(feature = "kvstore")]
154pub use kvstore::{
155    GlobalKVStore, KVStoreConfig, KVStoreEntry, KVStoreGetOptions, KVStoreQuery,
156    KVStoreRemoveOptions, KVStoreSetOptions, KVStoreToken, LocalKVStore,
157};
158
159// Convenience re-exports from identity
160#[cfg(feature = "identity")]
161pub use identity::{
162    Contact, ContactsManager, ContactsManagerConfig, DisplayableIdentity, IdentityClient,
163    IdentityClientConfig, IdentityQuery, KnownCertificateType,
164};