mpc_wallet_core/lib.rs
1//! # MPC Wallet Core
2//!
3//! Core library for MPC-secured AI agent wallets using 2-of-3 threshold signing.
4//!
5//! ## Architecture
6//!
7//! This crate provides:
8//! - **2-of-3 Threshold ECDSA**: AI agent holds 1 share, user holds 1 share, recovery guardian holds 1 share
9//! - **Policy Engine**: Configurable rules enforced before signing (spending limits, whitelists, time bounds)
10//! - **Key Share Storage**: Secure encrypted storage for key shares
11//! - **Chain Adapters**: Unified interface for EVM and Solana chains
12//! - **ERC-4337 Support**: Account abstraction with UserOperations and paymasters
13//!
14//! ## Quick Start
15//!
16//! ```rust,ignore
17//! use mpc_wallet_core::{AgentWallet, PartyRole, PolicyConfig};
18//! use mpc_wallet_core::chain::{ChainAdapter, EvmAdapter, EvmConfig};
19//!
20//! // Create a new wallet with policy configuration
21//! let policy = PolicyConfig::default()
22//! .with_daily_limit("1.0", "ETH")
23//! .with_whitelist(vec!["0x..."]);
24//!
25//! let wallet = AgentWallet::create(policy).await?;
26//!
27//! // Generate key shares for all parties
28//! let shares = wallet.generate_shares().await?;
29//!
30//! // Use chain adapter for transactions
31//! let evm = EvmAdapter::new(EvmConfig::ethereum_mainnet())?;
32//! let balance = evm.get_balance("0x...").await?;
33//!
34//! // Sign a transaction (requires AI + User or AI + Recovery)
35//! let signature = wallet.sign_transaction(tx, &[PartyRole::Agent, PartyRole::User]).await?;
36//! ```
37//!
38//! ## Security Model
39//!
40//! The 2-of-3 threshold ensures:
41//! - AI agent cannot sign alone (prevents rogue AI)
42//! - User maintains control (can approve/reject)
43//! - Recovery possible if user loses access (with guardian)
44//!
45//! All signing operations pass through the policy engine before MPC execution.
46
47pub mod chain;
48pub mod error;
49pub mod keygen;
50pub mod policy;
51pub mod sign;
52pub mod types;
53
54// Runtime-dependent modules (require tokio)
55#[cfg(feature = "runtime")]
56pub mod mpc;
57#[cfg(feature = "runtime")]
58pub mod storage;
59
60pub use error::{Error, Result};
61pub use policy::{PolicyConfig, PolicyDecision, PolicyEngine};
62
63#[cfg(feature = "runtime")]
64pub use storage::{EncryptedKeyShare, KeyShareStore};
65pub use types::{
66 AgentKeyShare, ChainType, KeyShareMetadata, Message, PartyId, PartyRole, PublicKey,
67 SessionConfig, SessionId, Signature, TransactionRequest, keccak256_hash,
68};
69
70// Re-export chain types for convenience
71#[cfg(feature = "evm")]
72pub use chain::{EvmAdapter, EvmConfig};
73
74#[cfg(feature = "solana")]
75pub use chain::{SolanaAdapter, SolanaConfig};
76
77#[cfg(feature = "aa")]
78pub use chain::evm::aa::{SmartAccountConfig, SmartAccountModule, UserOperation};
79
80pub use chain::{Balance, ChainAdapter, ChainId, SignedTx, TxHash, TxParams, UnsignedTx};
81
82/// Protocol version
83pub const VERSION: &str = env!("CARGO_PKG_VERSION");
84
85/// Fixed number of parties for AI agent wallet (AI, User, Recovery)
86pub const N_PARTIES: usize = 3;
87
88/// Fixed threshold (2-of-3)
89pub const THRESHOLD: usize = 2;
90
91/// Party IDs
92pub const PARTY_AGENT: PartyId = 0;
93pub const PARTY_USER: PartyId = 1;
94pub const PARTY_RECOVERY: PartyId = 2;