/**
 * WebAuthn Middleware for Fastify
 *
 * Provides Fastify middleware and routes for WebAuthn authentication:
 * - Registration flow routes
 * - Authentication flow routes
 * - Credential management routes
 * - Session/JWT integration for user context
 *
 * @packageDocumentation
 */
import type { FastifyInstance, FastifyRequest, FastifyReply, preHandlerHookHandler } from 'fastify';
import { type WebAuthnConfig, type WebAuthnCredential } from './types.js';
import { WebAuthnService } from './service.js';
/**
 * User context from session/JWT
 */
export interface WebAuthnUserContext {
    /** User ID */
    userId: string;
    /** User email/username */
    userName?: string;
    /** User display name */
    displayName?: string;
    /** Tenant ID (optional) */
    tenantId?: string;
}
/**
 * Middleware options
 */
export interface WebAuthnMiddlewareOptions {
    /** WebAuthn service instance */
    service?: WebAuthnService;
    /** WebAuthn configuration */
    config?: Partial<WebAuthnConfig>;
    /** Route prefix (default: /webauthn) */
    prefix?: string;
    /** Function to get user context from request */
    getUserContext?: (request: FastifyRequest) => WebAuthnUserContext | null | Promise<WebAuthnUserContext | null>;
    /** Function to create session/token after authentication */
    createSession?: (userId: string, credential: WebAuthnCredential, request: FastifyRequest, reply: FastifyReply) => Promise<{
        token?: string;
        sessionId?: string;
    }>;
}
/**
 * Plugin options
 */
export interface WebAuthnPluginOptions extends WebAuthnMiddlewareOptions {
    /** Register routes */
    registerRoutes?: boolean;
}
declare module 'fastify' {
    interface FastifyRequest {
        /** WebAuthn user context */
        webauthnUser?: WebAuthnUserContext;
    }
    interface FastifyInstance {
        /** WebAuthn service */
        webauthnService?: WebAuthnService;
    }
}
/**
 * Create user context extraction middleware
 */
export declare function createUserContextMiddleware(getUserContext: (request: FastifyRequest) => WebAuthnUserContext | null | Promise<WebAuthnUserContext | null>): preHandlerHookHandler;
/**
 * Require authenticated user middleware
 */
export declare function requireWebAuthnUser(): preHandlerHookHandler;
/**
 * Fastify plugin for WebAuthn authentication
 *
 * @example
 * ```typescript
 * await fastify.register(webauthnPlugin, {
 *   config: {
 *     rpName: 'My App',
 *     rpId: 'myapp.com',
 *     origin: 'https://myapp.com',
 *   },
 *   getUserContext: async (request) => {
 *     // Extract user from JWT/session
 *     const token = request.headers.authorization?.replace('Bearer ', '');
 *     if (!token) return null;
 *     const user = await verifyToken(token);
 *     return { userId: user.id, userName: user.email };
 *   },
 *   createSession: async (userId, credential, request, reply) => {
 *     const token = await createJWT({ userId });
 *     return { token };
 *   },
 * });
 * ```
 */
export declare const webauthnPlugin: (fastify: FastifyInstance, options: WebAuthnPluginOptions) => Promise<void>;
/**
 * Get WebAuthn user context from request
 */
export declare function getWebAuthnUser(request: FastifyRequest): WebAuthnUserContext | undefined;
/**
 * Check if request has WebAuthn user context
 */
export declare function hasWebAuthnUser(request: FastifyRequest): boolean;
/**
 * Get user ID from WebAuthn context
 */
export declare function getWebAuthnUserId(request: FastifyRequest): string | undefined;
//# sourceMappingURL=middleware.d.ts.map