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 CorrelationId,
86 EventMessage,
87 EventPayload,
88 EventType,
89 MessageType,
90 // Traits
91 Module,
92 ModuleContext,
93 ModuleError,
94 // IPC
95 ModuleIpcClient,
96 // Manifest
97 ModuleManifest,
98 // IPC Protocol
99 ModuleMessage,
100 ModuleMetadata,
101 ModuleState,
102 NodeAPI,
103 // Security
104 Permission,
105 PermissionSet,
106 RequestMessage,
107 RequestPayload,
108 ResponseMessage,
109 ResponsePayload,
110 open_module_db,
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;