import type { Secrets } from "./env.js"; import type { NormalizedAuth } from "./skills.js"; export interface InboundRequest { /** Lower-cased header names; repeated headers joined with ", ". */ headers: Record; rawBody: Buffer; query: URLSearchParams; ip: string; /** Override for tests. */ nowSeconds?: number; } export type AuthOutcome = { ok: true; deliveryId?: string; } | { ok: false; status: 401 | 403 | 503; code: string; reason: string; }; /** Constant-time comparison that does not leak length (compares SHA-256 digests). */ export declare function safeEqual(a: string | Buffer, b: string | Buffer): boolean; export declare function normalizeIp(ip: string): string; export declare function ipMatches(ip: string, patterns: string[]): boolean; /** * Splits an `Authorization`-style header value into scheme and parameter with plain string operations: a regex such * as `/^\s*Bearer\s+(.+?)\s*$/` backtracks quadratically on long runs of whitespace, and the header is attacker * controlled. Returns the trimmed parameter when the scheme matches case-insensitively and is followed by whitespace. */ export declare function parseAuthorizationScheme(headerValue: string | undefined, scheme: string): string | undefined; export declare function verifyRequest(auth: NormalizedAuth, secrets: Secrets, req: InboundRequest): AuthOutcome; /** Standard Webhooks secrets are `whsec_` + base64; anything else is used as raw bytes. */ export declare function standardWebhooksKey(secret: string): Buffer; export interface SignOptions { nowSeconds?: number; deliveryId?: string; } /** Produces the headers a real sender would attach for the given auth scheme. */ export declare function signRequest(auth: NormalizedAuth, secret: string, rawBody: Buffer, options?: SignOptions): Record;