rustywallet_multisig/
lib.rs

1//! # rustywallet-multisig
2//!
3//! Bitcoin multi-signature wallet utilities with Shamir Secret Sharing.
4//!
5//! ## Features
6//!
7//! - Create M-of-N multisig wallets (up to 15-of-15)
8//! - Generate P2SH, P2WSH, and P2SH-P2WSH addresses
9//! - Sign and combine multisig transactions
10//! - Shamir Secret Sharing for key backup
11//!
12//! ## Quick Start
13//!
14//! ```rust
15//! use rustywallet_multisig::prelude::*;
16//! use rustywallet_keys::prelude::PrivateKey;
17//!
18//! // Generate 3 keys
19//! let key1 = PrivateKey::random();
20//! let key2 = PrivateKey::random();
21//! let key3 = PrivateKey::random();
22//!
23//! let pubkeys = vec![
24//!     key1.public_key().to_compressed(),
25//!     key2.public_key().to_compressed(),
26//!     key3.public_key().to_compressed(),
27//! ];
28//!
29//! // Create 2-of-3 multisig wallet
30//! let wallet = MultisigWallet::from_pubkeys(2, pubkeys, Network::Mainnet).unwrap();
31//!
32//! println!("P2SH address: {}", wallet.address_p2sh);
33//! println!("P2WSH address: {}", wallet.address_p2wsh);
34//! println!("P2SH-P2WSH address: {}", wallet.address_p2sh_p2wsh);
35//! ```
36//!
37//! ## Shamir Secret Sharing
38//!
39//! ```rust
40//! use rustywallet_multisig::{split_secret, combine_shares};
41//!
42//! // Split a 32-byte secret into 5 shares, requiring 3 to recover
43//! let secret = [0x42u8; 32];
44//! let shares = split_secret(&secret, 3, 5).unwrap();
45//!
46//! // Recover with any 3 shares
47//! let recovered = combine_shares(&shares[0..3]).unwrap();
48//! assert_eq!(recovered, secret);
49//! ```
50//!
51//! ## Signing Multisig Transactions
52//!
53//! ```rust,ignore
54//! use rustywallet_multisig::{sign_p2sh_multisig, combine_signatures};
55//!
56//! // Each party signs with their key
57//! let sig1 = sign_p2sh_multisig(&sighash, &key1, &wallet).unwrap();
58//! let sig2 = sign_p2sh_multisig(&sighash, &key2, &wallet).unwrap();
59//!
60//! // Combine signatures
61//! let combined = combine_signatures(&[sig1, sig2], &wallet).unwrap();
62//!
63//! // Build scriptSig for P2SH
64//! let script_sig = combined.build_script_sig();
65//!
66//! // Or build witness for P2WSH
67//! let witness = combined.build_witness();
68//! ```
69
70pub mod error;
71pub mod config;
72pub mod script;
73pub mod address;
74pub mod signer;
75pub mod combiner;
76pub mod shamir;
77
78pub use error::{MultisigError, Result};
79pub use config::MultisigConfig;
80pub use address::{MultisigWallet, Network, hash160, sha256};
81pub use script::{build_multisig_script, parse_multisig_script};
82pub use signer::{sign_p2sh_multisig, sign_p2wsh_multisig, PartialSignature};
83pub use combiner::{combine_signatures, CombinedSignatures};
84pub use shamir::{split_secret, combine_shares, ShamirShare};
85
86/// Prelude module for convenient imports.
87pub mod prelude {
88    pub use crate::{
89        MultisigConfig, MultisigWallet, Network,
90        MultisigError, Result,
91        sign_p2sh_multisig, sign_p2wsh_multisig,
92        combine_signatures, CombinedSignatures,
93        split_secret, combine_shares, ShamirShare,
94    };
95}