#pragma once // Webhook signature verification for Managed Agents and organization // webhooks. Scheme: Standard Webhooks (what the official SDK's `unwrap` // delegates to): headers webhook-id, webhook-timestamp, webhook-signature; // signature = base64(HMAC-SHA256(key, "..")), // header value "v1,[ v1,...]"; key is "whsec_". Timestamp // tolerance is capped (Caps::kWebhookToleranceSeconds). #include #include #include "clients/body/json.h" namespace molo::anthropic::admin { class WebhookVerifier { public: explicit WebhookVerifier(const std::string& signing_key); // Signature header value for a message (used by tests and by senders). std::string sign(const std::string& id, long timestamp, const std::string& payload) const; // True when some v1 signature matches and |now - timestamp| is within the // tolerance. `headers` keys are matched case-insensitively. Never throws. bool verify(const std::string& payload, const std::map& headers, long now, std::string* why = nullptr) const; // Verifies, then parses the payload. Throws llm::ApiError on failure. clients::body::Json unwrap(const std::string& payload, const std::map& headers, long now) const; private: std::string key_; }; } // namespace molo::anthropic::admin