UNPKG

ws402

Version:

WebSocket implementation of X402 protocol for pay-as-you-go digital resources with automatic refunds

38 lines (37 loc) 1.41 kB
import { Request, Response, NextFunction } from 'express'; import { WS402 } from './WS402'; /** * Middleware for serving HTTP resources with WS402 time tracking * * Use case: PDFs, images, videos served via HTTP but tracked via WebSocket */ export declare class WS402HTTPMiddleware { private ws402; private activeHTTPSessions; constructor(ws402: WS402); /** * Middleware to protect HTTP resources * Returns 402 if no valid WS402 session exists */ protectHTTPResource: () => (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined; /** * Register a new HTTP session (called after WS402 payment verification) */ registerHTTPSession(sessionId: string, resourceId: string): string; /** * Remove HTTP session (called when WS402 session ends) */ removeHTTPSession(sessionId: string): void; /** * Get all active HTTP sessions */ getActiveHTTPSessions(): Array<any>; /** * Generate unique session token */ private generateToken; } /** * Helper to create Express route for HTTP resource with WS402 tracking */ export declare function createHTTPResourceRoute(ws402: WS402, httpMiddleware: WS402HTTPMiddleware, resourceGetter: (resourceId: string) => any): ((req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined)[];