tap_http/lib.rs
1//! HTTP server implementation for the Transaction Authorization Protocol (TAP).
2//!
3//! This crate provides an HTTP server for handling DIDComm messages as part of the
4//! Transaction Authorization Protocol (TAP). It leverages the new optimized message
5//! routing architecture of TAP Node.
6//!
7//! # Architecture
8//!
9//! The HTTP server acts as a gateway between external clients and the TAP Node. It:
10//!
11//! - **Validates Security**: Ensures only signed or encrypted messages are accepted
12//! - **Parses Messages**: Converts HTTP requests to JSON for TAP Node processing
13//! - **Routes Efficiently**: Leverages TAP Node's optimized message routing
14//! - **Provides Monitoring**: Health checks and event logging capabilities
15//!
16//! # Message Processing Flow
17//!
18//! 1. **HTTP Request**: Client sends POST to `/didcomm` with DIDComm message
19//! 2. **Security Validation**: Content-Type header validated (must be signed or encrypted)
20//! 3. **JSON Parsing**: Request body parsed as JSON Value
21//! 4. **Node Processing**: JSON passed to TAP Node's `receive_message()`
22//! 5. **Optimized Routing**: TAP Node handles verification/decryption and agent routing
23//! 6. **HTTP Response**: Result returned to client
24//!
25//! # Security Features
26//!
27//! - **No Plain Messages**: Plain DIDComm messages are rejected for security
28//! - **Content-Type Validation**: Strict validation of message security types
29//! - **Event Logging**: All message processing events are logged for audit
30//!
31//! # Key Components
32//!
33//! - **Handler**: Request/response processing with validation
34//! - **Server**: Warp-based HTTP server with configurable endpoints
35//! - **Client**: HTTP client for outgoing message delivery
36//! - **Event Bus**: Comprehensive event logging and monitoring
37//!
38//! # Example Usage
39//!
40//! ```rust,no_run
41//! use tap_http::{TapHttpConfig, TapHttpServer};
42//! use tap_node::{TapNode, NodeConfig};
43//! use tap_agent::TapAgent;
44//! use std::sync::Arc;
45//!
46//! #[tokio::main]
47//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
48//! // Create TAP Node
49//! let node_config = NodeConfig::default();
50//! let mut node = TapNode::new(node_config);
51//!
52//! // Register an agent
53//! let (agent, _did) = TapAgent::from_ephemeral_key().await?;
54//! node.register_agent(Arc::new(agent)).await?;
55//!
56//! // Configure and create the HTTP server
57//! let config = TapHttpConfig::default();
58//! let mut server = TapHttpServer::new(config, node);
59//!
60//! // Start the server
61//! server.start().await?;
62//!
63//! // Server now accepts signed and encrypted DIDComm messages
64//! // Messages are efficiently routed by the TAP Node
65//!
66//! Ok(())
67//! }
68//! ```
69
70// Public modules
71pub mod client;
72pub mod config;
73pub mod error;
74pub mod event;
75pub mod external_decision;
76pub mod handler;
77pub mod server;
78
79// Re-exports
80pub use client::DIDCommClient;
81pub use config::TapHttpConfig;
82pub use error::{Error, Result};
83pub use server::TapHttpServer;