> ## Documentation Index
> Fetch the complete documentation index at: https://docs.prava.space/llms.txt
> Use this file to discover all available pages before exploring further.

# Verify webhook signatures

> Authenticate raw bytes and reject stale or tampered requests.

You can receive Prava webhooks in any backend language or framework. Verify every request on your server with the **endpoint signing secret** (`whsec_...`) before you process the event.

> [!NOTE]
>
> Your application API secret (`sk_test_...` or `sk_live_...`) is a different credential. Never use it to verify webhook signatures.

## Request headers

| Header | What it contains |
| - | - |
| `Prava-Signature` | `t=UNIX_SECONDS,v1=HEX_DIGEST`. During a secret rotation it can carry more than one `v1` value. |
| `Prava-Event-Id` | The event ID. For deduplication, use the `id` in the signed body, which is authoritative. |
| `Prava-Delivery-Id` | The delivery generation. It can change on replay, so don't deduplicate on it. |

## How the signature is computed

The `v1` digest is **HMAC-SHA256** over `timestamp + "." + raw_body`, keyed with the complete `whsec_...` secret as UTF-8. During a 24-hour rotation overlap the header can contain several `v1` values; a match against either active secret is enough.

## Verify a request

1. Read the **raw request bytes**. Verify before JSON parsing, reserialization or any application processing; rebuilding JSON changes the bytes.
2. Reject a missing or malformed `Prava-Signature`, or one with duplicate timestamps.
3. Reject timestamps more than five minutes in the past or future. Keep your receiver's clock synchronized.
4. Compute the expected digest with each active secret and compare it to every `v1` value in constant time.
5. Only then parse the body, and check that the environment and account are the ones you expect.

### Example in JavaScript

Pass the exact request bytes from your HTTP framework as `rawBody`.

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

export function verifyWebhook(rawBody, signature, secrets, now = Date.now()) {
  if (!Buffer.isBuffer(rawBody) || typeof signature !== 'string') return false;
  const parts = signature.split(',').map(value => value.trim());
  const timestamps = parts.filter(value => value.startsWith('t='));
  if (timestamps.length !== 1 || !/^t=\d+$/.test(timestamps[0])) return false;
  const timestamp = timestamps[0].slice(2);
  const seconds = Number(timestamp);
  if (!Number.isSafeInteger(seconds) || Math.abs(now / 1000 - seconds) > 300) return false;
  const candidates = parts.filter(value => /^v1=[0-9a-f]{64}$/.test(value))
    .map(value => Buffer.from(value.slice(3), 'hex'));
  return secrets.some(secret => {
    const expected = createHmac('sha256', secret)
      .update(timestamp + '.').update(rawBody).digest();
    return candidates.some(candidate => timingSafeEqual(candidate, expected));
  });
}
```

## Handle the verified request

| Request | What to do |
| - | - |
| `webhook.endpoint_verification` | Echo its `challenge` as JSON with HTTP `200`. |
| Event with `test: true` | Acknowledge it with `2xx`, but don't perform financial or other business side effects. |
| Any other subscribed event | Atomically store its ID and enqueue your work, then respond `2xx`. |
| An event you already stored | Still respond `2xx`. |

* Put a unique database constraint on the event ID.
* Process slow business logic asynchronously, after you respond.
* A receiver timeout is an unknown outcome, so Prava may send the same event again.

## Rotate your signing secret

Administrators can rotate an endpoint's secret.

1. Rotate, then save the new secret when it's shown. You can't retrieve it later, and an idempotent retry returns the completion status without showing it again.
2. Prava signs with both the old and new secrets for 24 hours. Deploy verification with the new secret during that overlap.
3. Retire the old secret.

You can't rotate again until the overlap ends.

## Next steps

* For a runnable starting point, use the [Node.js or Python receiver examples](https://docs.prava.space/webhooks/receiver-examples.md). Their runtime and storage requirements apply only to those examples; you can implement the same verification and delivery handling in your existing application.
* See [Test your integration](https://docs.prava.space/webhooks/testing.md) to verify your destination, send test events, and check retries and secret rotation.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.