TAP HTTP
HTTP DIDComm server implementation for the Transaction Authorization Protocol (TAP).
Features
- DIDComm HTTP Endpoint: Exposes a secure HTTP endpoint for DIDComm messaging
- Integration with tap-node: Seamlessly forwards messages to a tap-node instance
- Message Validation: Validates incoming DIDComm messages
- Response Handling: Proper handling of responses and errors
- Outgoing Message Delivery: HTTP client for sending outgoing DIDComm messages
- Security: Support for HTTPS/TLS and rate limiting (configurable)
- Comprehensive Error Handling: Structured error responses with appropriate HTTP status codes
Usage
use ;
use ;
use Duration;
async
HTTP Endpoints
POST /{didcomm_endpoint}
The main endpoint for receiving DIDComm messages. The endpoint path is configurable (default is /didcomm
):
POST /didcomm HTTP/1.1
Host: example.com
Content-Type: application/didcomm-message+json
{
"id": "1234567890",
"type": "https://tap.rsvp/schema/1.0#transfer",
"body": {
"amount": "100.00",
"asset": "eip155:1/erc20:0x6b175474e89094c44da98b954eedeac495271d0f",
"transaction_id": "tx-123456"
},
"from": "did:example:sender",
"to": ["did:example:recipient"],
"created_time": 1620000000
}
GET /health
Health check endpoint for monitoring system availability:
GET /health HTTP/1.1
Host: example.com
Response:
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "ok",
"version": "0.1.0"
}
Response Formats
Success Response
For successfully processed messages:
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "success",
"message": "Message received and processed"
}
Error Response
For validation and other errors:
HTTP/1.1 400 Bad Request
Content-Type: application/json
{
"status": "error",
"error": {
"type": "validation_error",
"message": "Unsupported message type: https://didcomm.org/basicmessage/2.0/message, expected TAP protocol message"
}
}
Message Validation
The server performs several validation steps on incoming messages:
-
Basic Format Validation:
- Ensures the message has required fields (id, type, from, to)
- Validates message timestamps
-
Protocol Validation:
- Checks that the message type is a valid TAP protocol message
- Validates sender and recipient information
-
TAP Node Validation:
- Messages are forwarded to the TAP Node for further validation
- Authentication and signature verification is performed
Configuration Options
The server can be configured with the following options in TapHttpConfig
:
TLS Configuration
Enable HTTPS with TLS certificates:
let config = TapHttpConfig ;
Rate Limiting
Configure rate limiting to prevent abuse:
let config = TapHttpConfig ;
Client
The package also includes an HTTP client for sending DIDComm messages to other endpoints:
use DIDCommClient;
// Create client with default timeout
let client = default;
// Send a DIDComm message
client.deliver_message.await?;
Security Considerations
- Use TLS in production environments
- Configure rate limiting to prevent abuse
- Ensure proper validation and authentication of messages
- Consider running behind a reverse proxy for additional security layers
Error Handling
The server uses a comprehensive error handling system with appropriate HTTP status codes:
400 Bad Request
: Format and validation errors401 Unauthorized
: Authentication errors429 Too Many Requests
: Rate limiting500 Internal Server Error
: Server-side errors503 Service Unavailable
: Configuration errors
Command Line Usage
The tap-http package includes a binary executable that can be run from the command line:
# Install the package
# Run the HTTP server with default settings
# Run with custom options
Command Line Options
USAGE:
tap-http [OPTIONS]
OPTIONS:
-h, --host <HOST> Host to bind to [default: 127.0.0.1]
-p, --port <PORT> Port to listen on [default: 8000]
-e, --endpoint <ENDPOINT> Path for the DIDComm endpoint [default: /didcomm]
-t, --timeout <SECONDS> Request timeout in seconds [default: 30]
-v, --verbose Enable verbose logging
--help Print help information
--version Print version information
Environment Variables
You can also configure the server using environment variables:
# Set configuration options
# Run the server (will use environment variables)
Examples
Check the examples directory for complete usage examples:
http_message_flow.rs
: Basic HTTP message flowwebsocket_message_flow.rs
: WebSocket message flow example
To run the examples:
# Run the HTTP message flow example
# Run the WebSocket message flow example (with websocket feature)