import { Request, Response, NextFunction } from "express"; export type AuthScope = "read" | "write"; export interface AuraAuthContext { authenticated: boolean; tenantId: string; scopes: AuthScope[]; isByok: boolean; isAdmin: boolean; callerToken?: string; deniedReason?: string; httpStatus?: number; } declare global { namespace Express { interface Request { auraAuth?: AuraAuthContext; rawBody?: string | Buffer; } } } export interface AuditEntry { timestamp: string; tenant: string; tool: string; args_hash: string; outcome: "ok" | "denied" | "error"; } export declare const auditLogBuffer: AuditEntry[]; /** * F10 Fix: Accept BYOK credentials STRICTLY from request headers. * Query parameters are completely ignored to avoid leaking secrets in proxy/access logs. */ export declare function hasByokCredentials(req: Request): boolean; export declare function extractBearerToken(req: Request): string | undefined; /** * In-memory / env-configured tenant API keys registry. * Maps sha256(token) -> { tenantId, scopes, isAdmin } */ export interface DynamicKeyRecord { tokenHash: string; tenantId: string; storeName?: string; scopes: AuthScope[]; isAdmin: boolean; status: string; updatedAt: string; } export declare function initDynamicAuthStore(pool: any): Promise; export declare function upsertDynamicKeyHash(opts: { tokenHash?: string; rawToken?: string; tenantId: string; storeName?: string; scopes?: AuthScope[]; isAdmin?: boolean; status?: string; }): Promise; export declare function setTenantDynamicKeyStatus(tenantId: string, status: string): Promise; export declare function listDynamicKeySummaries(): { hashPrefix: string; tenantId: string; storeName: string; status: string; scopes: AuthScope[]; updatedAt: string; }[]; export declare function registerApiKey(token: string, tenantId: string, scopes?: AuthScope[], isAdmin?: boolean): void; /** * F01 Fix: Cryptographic Token Resolution without prefix bypass. * Prefix matching (aura_rw_*, aura_tenant_*) is strictly abolished. */ export declare function resolveAuthContext(req: Request): AuraAuthContext; /** * Middleware: Evaluates auth context for all requests */ export declare function resolveAuthContextAsync(req: Request): Promise; export declare function optionalAuthMiddleware(req: Request, _res: Response, next: NextFunction): Promise; /** * Strict /mcp Authentication & Per-Key Rate Limit Guard * Allows unauthenticated discovery handshakes (initialize, notifications/initialized, tools/list, ping, list_couriers) * so AI agent connectors (Claude Desktop, Cursor, Glama, LibreChat, Smithery) can connect seamlessly. */ export declare function requireMcpAuth(req: Request, res: Response, next: NextFunction): void; /** * Verify scope permission for a specific tool and record a privacy-safe audit log entry */ export declare function isActionPermitted(req: Request, toolName: string, args?: Record): { permitted: boolean; reason?: string; }; /** * Record privacy-safe audit log: hashes sanitized arguments; NEVER logs raw phone numbers or addresses. */ export declare function recordAuditLog(tenant: string, tool: string, args: Record | undefined, outcome: "ok" | "denied" | "error"): void; /** * F09 Fix: Native Carrier Webhook HMAC-SHA256 & Token Verification. * Pathao uses HMAC-SHA256 with PATHAO_CLIENT_SECRET over raw request body. * Steadfast uses secret key header comparison. */ export declare function verifyWebhookSignature(req: Request, provider: string): boolean;