UNPKG

@kya-os/agentshield-nextjs

Version:

Next.js middleware for AgentShield AI agent detection

34 lines (32 loc) 1.2 kB
/** * Ed25519 Signature Verification for HTTP Message Signatures * Implements proper cryptographic verification for ChatGPT and other agents * * Based on RFC 9421 (HTTP Message Signatures) and ChatGPT's implementation * Reference: https://help.openai.com/en/articles/9785974-chatgpt-user-allowlisting */ /** * Signature verification result */ interface SignatureVerificationResult { isValid: boolean; agent?: string; keyid?: string; confidence: number; reason?: string; verificationMethod: 'signature' | 'none'; } /** * Verify HTTP Message Signature for AI agents */ declare function verifyAgentSignature(method: string, path: string, headers: Record<string, string>): Promise<SignatureVerificationResult>; /** * Quick check if signature headers are present (for performance) */ declare function hasSignatureHeaders(headers: Record<string, string>): boolean; /** * Check if this is a ChatGPT signature based on headers * Uses secure URL parsing to prevent spoofing attacks */ declare function isChatGPTSignature(headers: Record<string, string>): boolean; export { type SignatureVerificationResult, hasSignatureHeaders, isChatGPTSignature, verifyAgentSignature };