import { HTTPAdapter, PaymentCancellationDispatcher, CompletedSettlement, HTTPRequestContext, SettlementOverrides, x402HTTPResourceServer, PaywallConfig, PaywallProvider, RoutesConfig, x402ResourceServer, FacilitatorClient } from '@bankofai/x402-core/server'; export { PaywallConfig, PaywallProvider, RouteConfigurationError, RouteValidationError, SETTLEMENT_OVERRIDES_HEADER, x402HTTPResourceServer, x402ResourceServer } from '@bankofai/x402-core/server'; import { PaymentPayload, PaymentRequirements, Network, SchemeNetworkServer } from '@bankofai/x402-core/types'; export { Network, PaymentPayload, PaymentRequired, PaymentRequirements, SchemeNetworkServer } from '@bankofai/x402-core/types'; import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify'; /** * Fastify adapter implementation for the x402 HTTP protocol. */ declare class FastifyAdapter implements HTTPAdapter { private request; /** * Creates a new FastifyAdapter instance. * * @param request - The Fastify request object */ constructor(request: FastifyRequest); /** * Gets a header value from the request. * * @param name - The header name * @returns The header value or undefined */ getHeader(name: string): string | undefined; /** * Gets the HTTP method of the request. * * @returns The HTTP method */ getMethod(): string; /** * Gets the path of the request. * * @returns The request path without query string */ getPath(): string; /** * Gets the full URL of the request. * * @returns The full request URL */ getUrl(): string; /** * Gets the Accept header from the request. * * @returns The Accept header value or empty string */ getAcceptHeader(): string; /** * Gets the User-Agent header from the request. * * @returns The User-Agent header value or empty string */ getUserAgent(): string; /** * Gets all query parameters from the request URL. * * @returns Record of query parameter key-value pairs */ getQueryParams(): Record; /** * Gets a specific query parameter by name. * * @param name - The query parameter name * @returns The query parameter value(s) or undefined */ getQueryParam(name: string): string | string[] | undefined; /** * Gets the parsed request body. * Fastify automatically parses JSON bodies. * * @returns The parsed request body */ getBody(): unknown; } /** * Sets settlement overrides on a Fastify reply for partial settlement (upto scheme). * The middleware extracts these before settlement and strips the header from the client response. * * @param reply - The Fastify reply object * @param overrides - Settlement overrides (e.g., { amount: "500" } for partial settlement) */ declare function setSettlementOverrides(reply: FastifyReply, overrides: SettlementOverrides): void; interface X402PaymentContext { cancellationDispatcher: PaymentCancellationDispatcher; beforeHandlerSettlement?: CompletedSettlement; paymentPayload: PaymentPayload; paymentRequirements: PaymentRequirements; declaredExtensions?: Record; requestContext: HTTPRequestContext; } interface BufferedWriteHead { method: "writeHead"; statusCode: number; headers?: Record; } interface BufferedWrite { method: "write"; data: string | Buffer; } interface BufferedEnd { method: "end"; data?: string | Buffer; } interface BufferedFlushHeaders { method: "flushHeaders"; } type BufferedRawCall = BufferedWriteHead | BufferedWrite | BufferedEnd | BufferedFlushHeaders; interface RawGuard { triggered: boolean; buffer: BufferedRawCall[]; deactivate: () => void; } declare module "fastify" { interface FastifyRequest { x402Context?: X402PaymentContext; x402RawGuard?: RawGuard; } } /** * Configuration for registering a payment scheme with a specific network. */ interface SchemeRegistration { /** * The network identifier (e.g., 'eip155:84532', 'solana:mainnet') */ network: Network; /** * The scheme server implementation for this network */ server: SchemeNetworkServer; } /** * Registers x402 payment middleware on a Fastify instance using a pre-configured HTTP server. * * Use this when you need to configure HTTP-level hooks. * * @param app - The Fastify instance * @param httpServer - Pre-configured x402HTTPResourceServer instance * @param paywallConfig - Optional configuration for the built-in paywall UI * @param paywall - Optional custom paywall provider (overrides default) * @param syncFacilitatorOnStart - Whether to sync with the facilitator on startup (defaults to true) * * @example * ```typescript * import { paymentMiddlewareFromHTTPServer, x402ResourceServer, x402HTTPResourceServer } from "@bankofai/x402-fastify"; * * const resourceServer = new x402ResourceServer(facilitatorClient) * .register(NETWORK, new ExactEvmScheme()); * * const httpServer = new x402HTTPResourceServer(resourceServer, routes) * .onProtectedRequest(requestHook); * * paymentMiddlewareFromHTTPServer(app, httpServer); * ``` */ declare function paymentMiddlewareFromHTTPServer(app: FastifyInstance, httpServer: x402HTTPResourceServer, paywallConfig?: PaywallConfig, paywall?: PaywallProvider, syncFacilitatorOnStart?: boolean): void; /** * Registers x402 payment middleware on a Fastify instance using a pre-configured resource server. * * Use this when you want to pass a pre-configured x402ResourceServer instance. * This provides more flexibility for testing, custom configuration, and reusing * server instances across multiple middlewares. * * @param app - The Fastify instance * @param routes - Route configurations for protected endpoints * @param server - Pre-configured x402ResourceServer instance * @param paywallConfig - Optional configuration for the built-in paywall UI * @param paywall - Optional custom paywall provider (overrides default) * @param syncFacilitatorOnStart - Whether to sync with the facilitator on startup (defaults to true) * * @example * ```typescript * import { paymentMiddleware } from "@bankofai/x402-fastify"; * * const server = new x402ResourceServer(myFacilitatorClient) * .register(NETWORK, new ExactEvmScheme()); * * paymentMiddleware(app, routes, server, paywallConfig); * ``` */ declare function paymentMiddleware(app: FastifyInstance, routes: RoutesConfig, server: x402ResourceServer, paywallConfig?: PaywallConfig, paywall?: PaywallProvider, syncFacilitatorOnStart?: boolean): void; /** * Registers x402 payment middleware on a Fastify instance using configuration. * * Use this when you want to quickly set up middleware with simple configuration. * This function creates and configures the x402ResourceServer internally. * * @param app - The Fastify instance * @param routes - Route configurations for protected endpoints * @param facilitatorClients - Optional facilitator client(s) for payment processing * @param schemes - Optional array of scheme registrations for server-side payment processing * @param paywallConfig - Optional configuration for the built-in paywall UI * @param paywall - Optional custom paywall provider (overrides default) * @param syncFacilitatorOnStart - Whether to sync with the facilitator on startup (defaults to true) * * @example * ```typescript * import { paymentMiddlewareFromConfig } from "@bankofai/x402-fastify"; * * paymentMiddlewareFromConfig( * app, * routes, * myFacilitatorClient, * [{ network: "eip155:8453", server: evmSchemeServer }], * paywallConfig * ); * ``` */ declare function paymentMiddlewareFromConfig(app: FastifyInstance, routes: RoutesConfig, facilitatorClients?: FacilitatorClient | FacilitatorClient[], schemes?: SchemeRegistration[], paywallConfig?: PaywallConfig, paywall?: PaywallProvider, syncFacilitatorOnStart?: boolean): void; export { FastifyAdapter, type SchemeRegistration, paymentMiddleware, paymentMiddlewareFromConfig, paymentMiddlewareFromHTTPServer, setSettlementOverrides };