Advanced Verification
This guide covers verification utilities and manual verification processes available in both TypeScript and Rust SDKs.
Middleware functions
PipeGate provides middleware functions as well for the same methods and they can be used as such:
use pipegate::middleware::payment_channel::{payment_channel_auth_fn_middleware, PaymentChannelFnMiddlewareState};
use pipegate::middleware::onetime_payment::{onetime_payment_auth_fn_middlewar, OneTimePaymentFnMiddlewareState };
use pipegate::middleware::superfluid_streams::{superfluid_streams_auth_fn_middleware, SuperfluidStreamsFnMiddlewareState};
let payment_channel_state = PaymentChannelFnMiddlewareState {
config: payment_channel_config,
state: channel_state,
}
let onetime_state = OneTimePaymentFnMiddlewareState {
config: onetime_payment_config,
}
let stream_state = SuperfluidStreamsFnMiddlewareState {
config: stream_payment_config,
state: stream_state,
}
// another example with middleware based on fn with state method
let app = Router::new()
.route(
"/",
get(root).route_layer(middleware::from_fn_with_state(
payment_channel_state,
payment_channel_auth_fn_middleware,
)),
)
.route(
"/one-time",
get(one_time).route_layer(middleware::from_fn_with_state(
onetime_state,
onetime_payment_auth_fn_middleware,
)),
)
.route(
"/stream",
get(stream).route_layer(middleware::from_fn_with_state(
stream_state,
superfluid_streams_auth_fn_middleware,
)),
);
Verification Utilities
Using TypeScript SDK
import { verify_channel_no_state } from "pipegate-sdk";
const updatedChannel = await verify_channel_no_state({
config,
message,
signature,
channelState,
paymentAmount,
bodyBytes,
});
Other available functions are verify_onetime_payment_tx
, verify_stream
& verify_channel_no_state
, more info about methods are available in docs
Using Rust SDK
use pipegate::verify::{verify_channel, verify_stream, verify_tx};
// Verify payment channel
let updated_channel = verify_channel(
message,
signature,
channel_state,
payment_amount,
body
).await?;
// Verify stream
let is_valid = verify_stream(
sender,
recipient,
min_flow_rate
).await?;
// Verify onetime payment
let is_valid = verify_tx(signed_payment_tx, onetime_payment_config).await;
Detailed documentation for these functions can be found in the github docs
Header Processing
Crate provide utilities for parsing and modifying PipeGate headers:
// Rust
use pipegate::middleware::payment_channel::utils::{parse_headers, modify_headers};
let (message, signature, channel) = parse_headers(&request)?;
modify_headers(&mut response, &updated_channel);
Each type of payment has its own set of headers, which can be parsed and modified using these functions. More info on helper functions here
Custom Integration Examples
Serverless Function
import { verifyChannel } from "pipegate-sdk/server";
export async function handler(request) {
const { message, signature, channelState } = parseHeaders(request.headers);
const result = await verifyChannel({
message,
signature,
channelState,
paymentAmount: 1000,
body: request.body,
});
return {
statusCode: 200,
headers: getUpdatedHeaders(result),
body: JSON.stringify({ success: true }),
};
}
Custom Middleware
use pipegate::verify::verify_and_update_channel;
async fn custom_middleware<B>(
mut request: Request<B>,
next: Next<B>,
) -> Result<Response, Error> {
let (message, signature, channel) = parse_headers(&request)?;
let updated_channel = verify_and_update_channel(
message,
signature,
&channel,
payment_amount,
&request.body
).await?;
let response = next.run(request).await;
modify_headers(&mut response, &updated_channel);
Ok(response)
}
When to Use Manual Verification
- Building custom middleware
- Serverless environments
- Complex verification workflows
- Integration with existing systems
- Custom caching requirements