> For the complete documentation index, see [llms.txt](https://docs.violetlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.violetlabs.com/features/api/outbound-webhooks/verify-signatures.md).

# Verify signatures

Confirm each request came from Violet and was not changed on the way.

Every request is signed with the webhook's signing secret, so you can confirm it came from Violet and was not changed on the way.

The `Violet-Signature` header looks like `t=1792951514,v1=5f2b…`:

* `t` is the time of this attempt, in Unix seconds. It is new on every retry.
* `v1` is a hex HMAC-SHA256 of the string `<t>.<raw request body>`, keyed with your secret. Use the whole secret, including its `whsec_` prefix.

To verify a request:

1. Read the raw body bytes before any JSON parsing.
2. Reject the request if `t` is more than 5 minutes from your clock.
3. Compute the HMAC and compare it with each `v1` value. Accept the request if any one matches. As a best practice, compare the HMAC using your language's constant-time function (`crypto.timingSafeEqual` in Node.js, `hmac.compare_digest` in Python) rather than `==`, so response times can't hint at how close a forged signature is.

{% tabs %}
{% tab title="Node.js" %}

```javascript
import { createHmac, timingSafeEqual } from 'node:crypto';

export function verify(rawBody, header, secret, toleranceSeconds = 300) {
  const parts = header.split(',').map((p) => p.split('='));
  const t = Number(parts.find(([k]) => k === 't')?.[1]);
  if (!t || Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false;
  const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest();
  return parts
    .filter(([k]) => k === 'v1')
    .some(([, sig]) => {
      const given = Buffer.from(sig, 'hex');
      return given.length === expected.length && timingSafeEqual(given, expected);
    });
}
```

{% endtab %}

{% tab title="Python" %}

```python
import hashlib, hmac, time

def verify(raw_body: bytes, header: str, secret: str, tolerance_seconds: int = 300) -> bool:
    parts = [p.split("=", 1) for p in header.split(",")]
    t = next((v for k, v in parts if k == "t"), None)
    if not t or abs(time.time() - int(t)) > tolerance_seconds:
        return False
    expected = hmac.new(secret.encode(), t.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
    return any(hmac.compare_digest(v, expected) for k, v in parts if k == "v1")
```

{% endtab %}
{% endtabs %}

## Rotating the secret

The secret is shown once, when you create the webhook or rotate its secret. For 24 hours after a rotation, requests carry two `v1` values: one signed with the new secret and one with the old. Switch your receiver to the new secret within that window.

Only the latest rotation keeps the old secret signing. If you rotate twice within 24 hours, the first old secret stops working at once, so switch to the newest secret before rotating again.

Custom headers are not part of the signature; the signature covers the body only.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.violetlabs.com/features/api/outbound-webhooks/verify-signatures.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
