PipeGate Server Middleware Documentation
Overview
The pipegate middleware provides server-side verification and payment channel management for the PipeGate protocol. This guide covers the setup and configuration for API providers using the Rust implementation.
NOTE : Only live on Base sepolia ( rpc: "https://base-sepolia-rpc.publicnode.com" )
Installation
Add the following dependencies to your Cargo.toml:
[]
= { = "0.1.0" } # PipeGate server middleware
= "0.7" # Web framework
= { = "1.0", = ["full"] }
= { = "0.1", = ["full"] }
Basic Setup
Simple Server Implementation
use ;
use ;
use ;
async
async
Closing channel & withdraw
use ;
pub async
Verify one time payment tx
Use the verify_tx function to verify a one-time payment transaction. The function takes a SignedPaymentTx and OneTimePaymentConfig as input and returns a Result with the verification status or an error.
async
Verification functions
-
Verify and Update Channel State:
verify_and_update_channel- Verifies the signed request and updates the channel state.ChannelStateis required to be persisted, better suited for serverful applications. -
Verify Channel:
verify_channel- Verifies the signed request and returns the updated channel.ChannelStateis not required to be persisted, better suited for serverless applications, but would add latency due to extra RPC calls to verify the channel info on each call.
Helper functions
-
Parse headers for payment channel with axum:
parse_headers_axum- Parsing and extracting signed request with payment channel from request headers in axum. -
Modify headers for updated channel with axum:
modify_headers_axum- Modifying response headers with updated channel state in axum. -
Parse headers for payment channel with HTTP:
parse_headers- Parsing and extracting signed request with payment channel from HTTP headers. -
Modify headers for updated channel with HTTP:
modify_headers- Modifying response headers with updated channel state in HTTP. -
Parse headers for onetime payment tx:
parse_tx_headers_axum- Parsing and extracting signed request with onetime payment tx from request headers in axum.
Error Handling
use AuthError;
async
WASM Compatibility
The PipeGate middleware can be compiled to WebAssembly (WASM) for use in browser-based applications. The middleware can be compiled using the wasm-pack tool and integrated into web applications using JavaScript. Only a subset of functions are exported currently with wasm-bindgen and can be found in wasm.rs. But other functions which are available can be easily exported as needed.
Example usage can be found at tests/index.ts
Middleware Configuration Options
Environment Variables
# .env
RPC_URL=https://base-sepolia-rpc.publicnode.com
MIN_PAYMENT_AMOUNT=1000
CHANNEL_FACTORY_ADDRESS=0x...
Loading Configuration
use dotenv;
use env;
async
Best Practices
-
Security
- Always verify signatures and nonces
- Implement rate limiting
- Monitor for suspicious activity
- Keep RPC endpoint secure
-
Performance
- Use connection pooling for RPC calls
- Implement caching for channel states
- Monitor middleware performance
-
Maintenance
- Regularly update dependencies
- Monitor channel states
- Implement proper logging
- Set up monitoring and alerts
-
Error Handling
- Implement comprehensive error handling
- Provide meaningful error messages
- Log errors appropriately
- Handle edge cases
Note: This middleware is part of the PipeGate protocol. Ensure you're using compatible versions of both client SDK and server middleware.