Skip to main content

blvm_sdk/
lib.rs

1//! # Developer SDK
2//!
3//! Governance infrastructure and composition framework for Bitcoin.
4//!
5//! This crate provides the **institutional layer** for Bitcoin governance, offering
6//! reusable governance primitives and a composition framework for building alternative
7//! Bitcoin implementations.
8//!
9//! ## Architecture Position
10//!
11//! This is **Tier 5** of the 5-tier BTCDecoded architecture:
12//!
13//! <!--
14//! blvm-spec (Orange Paper) -> blvm-consensus -> blvm-protocol -> blvm-node -> blvm-sdk
15//! -->
16//!
17//! ## Core Components
18//!
19//! ### Governance Primitives
20//! - **Cryptographic key management** for governance operations
21//! - **Signature creation and verification** using Bitcoin-compatible standards
22//! - **Multisig threshold logic** for collective decision making
23//! - **Message formats** for releases, module approvals, and budget decisions
24//!
25//! ### CLI Tools
26//! - `blvm-keygen` - Generate governance keypairs
27//! - `blvm-sign` - Sign governance messages
28//! - `blvm-verify` - Verify signatures and multisig thresholds
29//!
30//! ## Quick Start
31//!
32//! ```rust
33//! use blvm_sdk::{
34//!     GovernanceKeypair, GovernanceMessage, Multisig, sign_message
35//! };
36//!
37//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
38//! // Generate a keypair
39//! let keypair = GovernanceKeypair::generate()?;
40//!
41//! // Create a message to sign
42//! let message = GovernanceMessage::Release {
43//!     version: "v1.0.0".to_string(),
44//!     commit_hash: "abc123".to_string(),
45//! };
46//!
47//! // Sign the message
48//! let signature = sign_message(&keypair.secret_key, &message.to_signing_bytes())?;
49//!
50//! // Verify with multisig (example with 1-of-1)
51//! let maintainer_keys = vec![keypair.public_key()];
52//! let multisig = Multisig::new(1, 1, maintainer_keys)?;
53//! let valid = multisig.verify(&message.to_signing_bytes(), &[signature])?;
54//! assert!(valid);
55//! # Ok(())
56//! # }
57//! ```
58
59pub mod cli;
60#[cfg(feature = "node")]
61pub mod composition;
62pub mod governance;
63#[cfg(any(feature = "node", feature = "wasm-modules"))]
64pub mod module;
65
66// Re-export main types for convenience
67pub use governance::{
68    GovernanceError, GovernanceKeypair, GovernanceMessage, GovernanceResult, Multisig, PublicKey,
69    Signature,
70};
71
72// Re-export governance functions
73pub use governance::signatures::{sign_message, verify_signature};
74
75// Re-export composition framework (requires node)
76#[cfg(feature = "node")]
77pub use composition::{
78    ComposedNode, ModuleHealth, ModuleInfo, ModuleLifecycle, ModuleRegistry, ModuleSource,
79    ModuleSpec, ModuleStatus, NetworkType, NodeComposer, NodeConfig, NodeSpec,
80};
81
82// Re-export module development APIs (requires node)
83#[cfg(feature = "node")]
84pub use module::{
85    open_module_db,
86    CorrelationId,
87    EventMessage,
88    EventPayload,
89    EventType,
90    MessageType,
91    // Traits
92    Module,
93    ModuleContext,
94    ModuleError,
95    // IPC
96    ModuleIpcClient,
97    // Manifest
98    ModuleManifest,
99    // IPC Protocol
100    ModuleMessage,
101    ModuleMetadata,
102    ModuleState,
103    NodeAPI,
104    // Security
105    Permission,
106    PermissionSet,
107    RequestMessage,
108    RequestPayload,
109    ResponseMessage,
110    ResponsePayload,
111};
112
113/// WASM module runtime (when `wasm-modules` feature is enabled).
114#[cfg(feature = "wasm-modules")]
115pub use module::wasm::{WasmHostContext, WasmModuleInstance, WasmStorage, WasmTree};
116
117/// WASM loader for blvm-node (when both `node` and `wasm-modules` are enabled).
118#[cfg(all(feature = "node", feature = "wasm-modules"))]
119pub use module::wasm::BlvmSdkWasmLoader;