TAP Node
A high-performance, asynchronous node implementation for the Transaction Authorization Protocol (TAP). This crate provides a complete node infrastructure for managing TAP agents, routing messages, and coordinating secure financial transactions.
Installation
Overview
The TAP Node acts as a central hub for TAP communications, managing multiple agents, processing messages, and coordinating the transaction lifecycle. It is designed for high-throughput environments, with support for concurrent message processing, event-driven architecture, and robust error handling.
Key Features
- Multi-Agent Management: Register and manage multiple TAP agents with different roles and capabilities
- Message Processing Pipeline: Process messages through configurable middleware chains
- Travel Rule Compliance: Automatic IVMS101 data generation and attachment for regulatory compliance
- Customer Data Management: Automatic extraction and storage of party information from TAP messages
- Message Routing: Intelligently route messages to the appropriate agent based on DID addressing
- Concurrent Processing: Scale to high throughput with worker pools for message processing
- Event Publishing: Comprehensive event system for monitoring and reacting to node activities
- Flexible Message Delivery: Send messages via HTTP or WebSockets with robust error handling
- Cross-Platform Support: Native and WASM environments for both HTTP and WebSocket transports
- DID Resolution: Resolve DIDs for message verification and routing
- Configurable Components: Customize node behavior with pluggable components
- Thread-Safe Design: Safely share the node across threads with appropriate synchronization
- WASM Compatibility: Optional WASM support for browser environments
- Persistent Storage: SQLite-based storage using async SQLx with comprehensive functionality:
- Transaction tracking for Transfer and Payment messages
- Complete audit trail of all incoming/outgoing messages
- Message delivery tracking with status monitoring, retry counts, and error logging
- Customer profiles with Schema.org JSON-LD format and IVMS101 caching
- Relationship tracking for TAIP-9 compliance
Installation
Add the crate to your Cargo.toml:
[]
= { = "../tap-node" }
= { = "../tap-agent" }
= { = "../tap-msg" }
# Optional features
= { = "../tap-node", = ["native"] } # Enable HTTP support
= { = "../tap-node", = ["websocket"] } # Enable WebSocket support
= { = "../tap-node", = ["native-with-websocket"] } # Enable both HTTP and WebSocket
= { = "../tap-node", = ["wasm"] } # Enable WASM support
= { = "../tap-node", = ["wasm-with-websocket"] } # Enable WASM with WebSocket
= { = "../tap-node", = ["storage"] } # Enable persistent storage (enabled by default)
Architecture
The TAP Node is built with a modular architecture:
┌─────────────────────────────────────────────────────────────────────┐
│ TAP Node │
├───────────────┬───────────────┬─────────────────┬───────────────────┤
│ Agent Registry│ Message Router│ Event Bus │ AgentStorageManager│
├───────────────┼───────────────┼─────────────────┼───────────────────┤
│ Message │ Processor Pool│ DID Resolver │ Per-Agent Storage │
│ Processors │ │ │ Isolation │
├───────────────┼───────────────┼─────────────────┼───────────────────┤
│ Travel Rule │ Customer │ Event Handlers │ IVMS101 Data │
│ Processor │ Manager │ │ Generation │
└───────────────┴───────────────┴─────────────────┴───────────────────┘
│ │ │ │
▼ ▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌───────────────┐ ┌─────────────────┐
│ TAP Agent │ │ TAP Agent │ │ TAP Agent │ │ ~/.tap/{did}/ │
│ Agent A │ │ Agent B │ │ Agent C │ │ transactions.db │
└───────────────┘ └───────────────┘ └───────────────┘ └─────────────────┘
│ │ │ │
▼ ▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌───────────────┐ ┌─────────────────┐
│ SQLite DB │ │ SQLite DB │ │ SQLite DB │ │ Multi-Recipient │
│ Agent A │ │ Agent B │ │ Agent C │ │ Message Delivery│
└───────────────┘ └───────────────┘ └───────────────┘ └─────────────────┘
Usage
Basic Setup
use ;
use ;
use ;
use MultiResolver;
use Arc;
use Duration;
async
Processing Messages
use PlainMessage;
use json;
// Receive and process an incoming message
async
// Send a message from one agent to multiple recipients
async
// Example: Creating a multi-recipient message
async
Event Handling and Logging
The TAP Node includes a powerful event system with configurable logging capabilities:
use Arc;
use async_trait;
use ;
use ;
use ;
// Create a TAP Node with event logging enabled
let mut config = default;
config.event_logger = Some;
// Initialize node with event logging
let node = new;
// Create a custom event subscriber
;
// Subscribe to events
async
Event Logger Configuration
The event logger supports different destinations:
// Log to console
let config = EventLoggerConfig ;
// Log to file with rotation
let config = EventLoggerConfig ;
// Custom logging function
let custom_logger = new;
let config = EventLoggerConfig ;
Custom Message Processors
You can create custom message processors to extend the node's capabilities:
use async_trait;
use Result;
use MessageProcessor;
use PlainMessage;
;
Message Transport
TAP Node provides multiple options for sending messages between nodes with optional delivery tracking:
HTTP Message Sender
For standard request-response communication patterns:
use ;
// Create an HTTP sender with default settings
let sender = new;
// Create with custom settings (timeout and retries)
let sender = with_options;
// Send a packed message to recipients
sender.send.await?;
HTTP Message Sender with Delivery Tracking
For HTTP delivery with comprehensive tracking and monitoring:
use ;
use Arc;
// Create storage for tracking deliveries
let storage = new;
// Create a sender with delivery tracking
let sender = new;
// Send message - delivery will be tracked automatically
sender.send.await?;
// Check delivery status later using storage queries
This sender automatically:
- Creates delivery records before sending with status
pending - Updates status to
successorfailedafter delivery attempts - Records HTTP status codes and error messages
- Tracks retry counts for future automatic retry processing
WebSocket Message Sender
For real-time bidirectional communication:
use ;
// Create a WebSocket sender with default settings
let sender = new;
// Create with custom settings
let sender = with_options;
// Send a message over an established WebSocket connection
sender.send.await?;
Key benefits of the WebSocket transport:
- Persistent connections for lower latency
- Bidirectional communication
- Connection state awareness
- Reduced overhead for frequent messages
Per-Agent Storage Architecture
The TAP Node features a sophisticated per-agent storage system using SQLite databases. This architecture provides complete data isolation between agents while ensuring all involved parties receive relevant transaction data.
- Transaction Storage: Automatic storage of Transfer and Payment messages for business logic processing
- Message Audit Trail: Complete logging of all incoming and outgoing messages for compliance and debugging
- Message Delivery Tracking: Comprehensive tracking of message delivery attempts with status monitoring
Message Delivery Tracking
TAP Node provides comprehensive delivery tracking for both external HTTP deliveries and internal agent-to-agent message routing. This feature enables monitoring, debugging, and automatic retry processing.
Delivery Types
The system tracks four types of message delivery:
https: HTTP/HTTPS delivery to external endpointsinternal: Delivery to agents within the same TAP Nodereturn_path: Return path delivery (future implementation)pickup: Pickup delivery (future implementation)
Automatic Tracking
Delivery tracking is automatic for:
- HTTP External Deliveries: When using
HttpPlainMessageSenderWithTracking - Internal Agent Deliveries: When messages are processed by the node and delivered to registered agents
- Router-based Deliveries: When messages are routed through the default router to fallback agents
Tracking Information
Each delivery record includes:
- Message identification: Message ID and full message text
- Recipient details: Target DID and delivery URL (for HTTP)
- Status tracking:
pending,success, orfailed - Error information: HTTP status codes and error messages
- Retry tracking: Count for automatic retry processing
- Timestamps: Creation, update, and delivery completion times
Querying Delivery Status
use ;
// Get storage from the node (agent-specific storage)
if let Some = node.agent_storage_manager
### Storage Configuration
Configure per-agent storage when creating the node:
```rust
use ;
use PathBuf;
// Use default TAP root (~/.tap) for per-agent storage
let config = NodeConfig ;
// Or specify a custom TAP root directory
let config = NodeConfig ;
// Agent storage locations:
// - Default: ~/.tap/{sanitized_did}/transactions.db
// - Custom: /custom/tap/root/{sanitized_did}/transactions.db
Accessing Stored Data
use MessageDirection;
// Access agent-specific storage
if let Some = node.agent_storage_manager
// Access legacy centralized storage (if available)
if let Some = node.storage
Storage Features
- Agent Isolation: Each agent has its own dedicated SQLite database
- Multi-Agent Transactions: Transactions automatically stored in all involved agents' databases
- Multi-Recipient Delivery: Messages delivered to ALL recipients in the
tofield - Async Database Operations: Built on SQLx for native async support
- Automatic Migration: Database schema is automatically created and migrated on startup
- Dual-Table Design: Separate tables for transactions and message audit trail per agent
- Append-Only Design: All data is immutable for compliance and auditing
- SQLite WAL Mode: Optimized for concurrent reads and writes
- Connection Pooling: SQLx connection pool for efficient database access per agent
- JSON Column Support: Message content stored as validated JSON
- WASM Compatibility: Storage is automatically disabled in WASM builds
- Duplicate Handling: Duplicate messages are silently ignored (idempotent)
- Directory Management: Automatic creation of agent-specific directories
Database Schema
The storage system maintains seven tables:
transactions Table
Business logic for Transfer and Payment messages:
- Transaction ID and type (Transfer/Payment)
- Sender and recipient DIDs
- Thread ID for conversation tracking
- Full message content stored in JSON column type
- Status tracking (pending/confirmed/failed/cancelled/reverted)
- Timestamps for creation and updates
messages Table
Complete audit trail of all messages:
- Message ID and type (all TAP message types)
- Direction (incoming/outgoing)
- Sender and recipient DIDs
- Thread IDs (including parent threads)
- Full message content stored in JSON column type
- Creation timestamp
deliveries Table
Message delivery tracking and monitoring:
- Delivery ID (auto-incrementing primary key)
- Message ID and full message text
- Recipient DID and delivery URL (for HTTP)
- Delivery type (
https,internal,return_path,pickup) - Status (
pending,success,failed) - Retry count for automatic retry processing
- HTTP status code and error message for debugging
- Timestamps for creation, updates, and delivery completion
customers Table
Customer profiles with Schema.org JSON-LD data:
- Customer ID (UUID or DID)
- Agent DID (owner of the customer record)
- Schema type (Person/Organization)
- Name fields (given, family, display, legal)
- Address fields (country, locality, postal, street)
- Profile data (full Schema.org JSON-LD)
- IVMS101 data (cached compliance data)
- Verification and timestamps
customer_identifiers Table
Multiple identifiers per customer:
- Identifier (DID, email, phone, URL, etc.)
- Customer ID reference
- Identifier type classification
- Verification status and method
- Creation timestamp
customer_relationships Table
TAIP-9 compliant relationship tracking:
- Relationship ID
- Customer ID reference
- Relationship type (controls, owns, manages)
- Related identifier
- Proof of relationship (JSON)
- Confirmation timestamp
decision_log Table
Durable decision tracking for external decision systems:
- Decision ID (auto-incrementing primary key)
- Transaction ID and agent DID
- Decision type (
authorization_required,policy_satisfaction_required,settlement_required) - Context JSON (transaction state, pending agents, etc.)
- Status (
pending,delivered,resolved,expired) - Resolution action and detail
- Timestamps (created, delivered, resolved)
The decision log is used by tap-http's poll mode (--decision-mode poll) and exec mode (--decision-exec) to durably track decisions requiring external input. Decisions are automatically resolved when the corresponding action tool succeeds, and expired when a transaction reaches a terminal state.
Event Handlers
The event system includes decision-related handlers:
DecisionStateHandler: Listens forTransactionStateChangedevents and manages decision lifecycle — expires decisions on terminal states, resolves decisions when actions are observed (e.g.,authorization_required→ resolved when state reachesready_to_settle)DecisionLogHandler: Implements theDecisionHandlertrait to write decisions to thedecision_logtable, enabling poll-based decision architecturesDecisionExpirationHandler: Legacy handler for expiring decisions on terminal states
Disabling Storage
To disable storage (for example, in memory-only deployments):
[]
= { = "../tap-node", = false, = ["native"] }
Integration with Other Crates
The TAP Node integrates with the TAP ecosystem:
- tap-agent: Provides the agent implementation used by the node
- tap-msg: Defines the message types and formats
- tap-caip: Handles chain-agnostic identifiers used in transactions
- tap-http: Can be used to create HTTP endpoints for the node
- tap-wasm: Enables WASM compatibility for browser environments
Performance Considerations
The TAP Node is designed for high performance:
- Use processor pools for concurrent message processing
- Configure worker counts based on your hardware
- Consider message validation trade-offs
- Use appropriate channel capacities for your workload
- Profile your specific use case for optimal settings
Travel Rule Support
The TAP Node includes comprehensive Travel Rule support through the Travel Rule Processor and Customer Manager:
Automatic IVMS101 Attachment
When sending Transfer messages, the node automatically:
- Checks if IVMS101 data should be attached based on policies
- Generates IVMS101 data from customer profiles
- Attaches data as Verifiable Presentations
- Handles policy-based presentation requests
See TRAVEL-RULE.md for detailed documentation.
Customer Data Management
The Customer Manager automatically:
- Extracts party information from TAP messages
- Creates/updates customer profiles
- Manages multiple identifiers per customer
- Tracks relationships between parties
- Generates IVMS101-compliant data
See CUSTOMER-MANAGEMENT.md for detailed documentation.
Examples
The package includes several examples:
benches/stress_test.rs- Benchmark of node performance with different message loadsexamples/http_message_flow.rs- Example of using HTTP for message deliveryexamples/websocket_message_flow.rs- Example of using WebSockets for real-time communicationexamples/travel_rule_flow.rs- Complete Travel Rule compliance example with IVMS101
Run examples with:
# Run with HTTP support
# Run with WebSocket support
# Run Travel Rule example
Related Tools
- tap-cli — Command-line interface for interacting with tap-node from the terminal
- tap-mcp — Model Context Protocol server for AI assistant integration
- tap-http — HTTP server for DIDComm transport
License
This crate is licensed under the terms of the MIT license.