agentic_payments/lib.rs
1//! # Agentic Payments - Autonomous Multi-Agent Ed25519 Signature Verification
2//!
3//! A production-ready implementation of distributed cryptographic signature verification
4//! with Byzantine fault tolerance, self-healing agent coordination, and AP2 (Agent Payments
5//! Protocol) integration.
6//!
7//! ## Features
8//!
9//! - **Autonomous Verification**: Multi-agent consensus with BFT voting (⅔+ quorum)
10//! - **Self-Healing**: Automatic agent recovery with <2s downtime
11//! - **High Performance**: 10,000+ verifications/second with 100-agent pools
12//! - **Byzantine Tolerance**: Survives up to f malicious agents in 2f+1 pools
13//! - **AP2 Integration**: Verifiable Credentials and mandate-based authentication
14//! - **Zero SPOF**: Mesh topology eliminates single points of failure
15//!
16//! ## Architecture
17//!
18//! The system uses 6 types of autonomous agents:
19//! 1. **Verification Agents**: Parallel Ed25519 signature validation
20//! 2. **Trust Chain Validators**: Certificate chain traversal with DFS
21//! 3. **Authority Coordinators**: Multi-issuer quorum management
22//! 4. **Key Management Agents**: Secure key lifecycle with HSM support
23//! 5. **Anomaly Detection Agents**: Statistical threat detection
24//! 6. **Recovery Agents**: Self-healing with automatic respawning
25//!
26//! ## Quick Start
27//!
28//! ```rust,no_run
29//! use agentic_payments::prelude::*;
30//!
31//! #[tokio::main]
32//! async fn main() -> Result<()> {
33//! // Initialize the agentic verification system
34//! let system = AgenticVerificationSystem::builder()
35//! .pool_size(5)
36//! .consensus_threshold(0.67)
37//! .build()
38//! .await?;
39//!
40//! // Create agent identity
41//! let identity = AgentIdentity::generate()?;
42//!
43//! // Sign a message
44//! let message = b"Autonomous payment authorization";
45//! let signature = identity.sign(message)?;
46//!
47//! // Verify with multi-agent consensus
48//! let result = system.verify_with_consensus(
49//! signature,
50//! message,
51//! identity.verifying_key()
52//! ).await?;
53//!
54//! assert!(result.is_valid());
55//! println!("Consensus: {}/{} agents agreed", result.votes_for, result.total_votes);
56//!
57//! Ok(())
58//! }
59//! ```
60
61#![deny(unsafe_code)]
62#![warn(missing_docs, rust_2018_idioms)]
63
64pub mod agents;
65pub mod ap2;
66pub mod consensus;
67pub mod crypto;
68pub mod error;
69pub mod system;
70pub mod workflows;
71
72#[cfg(feature = "acp")]
73pub mod acp;
74
75pub mod prelude {
76 //! Convenience re-exports for common types and traits
77 #[cfg(feature = "acp")]
78 pub use crate::acp;
79 pub use crate::agents::*;
80 pub use crate::ap2::*;
81 pub use crate::consensus::*;
82 pub use crate::crypto::*;
83 pub use crate::error::{Error, Result};
84 pub use crate::system::*;
85 pub use crate::workflows::*;
86}
87
88#[cfg(target_arch = "wasm32")]
89pub mod wasm;
90
91use error::Result;
92
93/// Library version
94pub const VERSION: &str = env!("CARGO_PKG_VERSION");
95
96/// Maximum number of agents in a verification pool
97pub const MAX_POOL_SIZE: usize = 100;
98
99/// Minimum number of agents for BFT consensus (2f+1 where f=1)
100pub const MIN_POOL_SIZE: usize = 3;
101
102/// Default verification timeout in milliseconds
103pub const DEFAULT_TIMEOUT_MS: u64 = 100;
104
105/// Default consensus threshold (⅔+ = 0.67)
106pub const DEFAULT_CONSENSUS_THRESHOLD: f64 = 0.67;
107
108/// Initialize the agentic payments system with tracing
109pub fn init() -> Result<()> {
110 #[cfg(not(target_arch = "wasm32"))]
111 {
112 use tracing_subscriber::EnvFilter;
113
114 tracing_subscriber::fmt()
115 .with_env_filter(
116 EnvFilter::try_from_default_env()
117 .unwrap_or_else(|_| EnvFilter::new("info"))
118 )
119 .init();
120 }
121
122 Ok(())
123}
124
125#[cfg(test)]
126mod tests {
127 use super::*;
128
129 #[test]
130 fn test_constants() {
131 assert!(MAX_POOL_SIZE >= MIN_POOL_SIZE);
132 assert!(DEFAULT_CONSENSUS_THRESHOLD > 0.5 && DEFAULT_CONSENSUS_THRESHOLD <= 1.0);
133 assert!(DEFAULT_TIMEOUT_MS > 0);
134 }
135
136 #[test]
137 fn test_version() {
138 assert!(!VERSION.is_empty());
139 }
140}