> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.drazill.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.drazill.com/_mcp/server.

# Signing & verification

The signature is `v1=` + hex HMAC-SHA256, keyed by your endpoint secret, over the bytes
`"{timestamp}.{delivery_id}." + raw_request_body`. Verify with a **constant time** compare
and reject anything older than **300 seconds**. During a secret rotation grace window the
header carries more than one comma-separated `v1=` candidate — accept the delivery if
**any** candidate matches your secret.

Always verify against the **raw** request bytes, before any JSON parsing.

## With the SDKs (recommended)

The SDK helpers implement the scheme (multi-candidate + tolerance) for you.

```python
# Python — see sdks/python/tests/test_webhooks.py for the tested calls.
from drazill.webhooks import construct_webhook_event

event = construct_webhook_event(raw_body, request.headers, endpoint_secret)
print(event.type, event.data)  # raises ValueError if the signature is invalid
```

```ts
// TypeScript — see sdks/typescript/src/__tests__/webhooks.test.ts.
import { constructWebhookEvent } from "drazill";

const event = await constructWebhookEvent(rawBody, request.headers, endpointSecret);
console.log(event.type, event.data); // throws if the signature is invalid
```

## Raw recipe (no SDK)

This recipe is exercised verbatim by
`tests/test_webhooks.py::test_guide_raw_verification_recipe`:

```python
import hashlib, hmac, time

def verify(raw_body: bytes, headers: dict, secret: str, tolerance: int = 300) -> bool:
    timestamp = headers["Drazill-Webhook-Timestamp"]
    delivery_id = headers["Drazill-Webhook-Id"]
    if abs(int(time.time()) - int(timestamp)) > tolerance:
        return False
    signed = f"{timestamp}.{delivery_id}.".encode() + raw_body
    expected = "v1=" + hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
    # A rotation grace window sends multiple comma-separated candidates.
    return any(
        hmac.compare_digest(expected, candidate.strip())
        for candidate in headers["Drazill-Webhook-Signature"].split(",")
    )
```

Respond `2xx` once you have durably accepted the event. Any non-`2xx` (or a timeout) is a
failed attempt and will be [retried](/webhooks/delivery).

> **Warning**
>
> Verify against the raw bytes **before** parsing JSON, and use a constant-time compare
> (`hmac.compare_digest`) — never `==`. A webhook is a notification: re-read authoritative
> state from the REST API before moving money.