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

# Verify signatures

> Check that a webhook delivery came from Hammock and wasn't replayed.

Anyone can send a `POST` to your webhook URL. Hammock signs every delivery with the endpoint's
secret so you can tell the real ones apart.

## The signature header

```
Hammock-Signature: t=1805558400,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
```

| Part | Meaning |
| - | - |
| `t` | When Hammock sent the delivery, in Unix seconds |
| `v1` | An HMAC-SHA256 signature, hex-encoded. There can be more than one. |

Ignore any parts you don't recognize. New schemes may be added alongside `v1`.

## Verify a delivery

**1. Read the raw body**

Use the exact bytes Hammock sent. Parsing the JSON and serializing it again changes the bytes
and breaks the signature.

**2. Build the signed payload**

Join the timestamp, a period and the raw body: `{t}.{body}`.

**3. Compute the expected signature**

Take the HMAC-SHA256 of the signed payload, keyed with the endpoint's `whsec_` secret, and
hex-encode it.

**4. Compare**

Compare your result with each `v1` value using a constant-time comparison. The delivery is
valid if any of them matches.

**5. Check the timestamp**

Reject deliveries whose `t` is more than five minutes from your clock. This stops a captured
delivery from being replayed later.

```javascript Node.js theme={null}
import crypto from 'node:crypto';

const TOLERANCE_SECONDS = 300;

export const verify = (rawBody, header, secret) => {
  const parts = header.split(',').map((part) => part.split('='));
  const timestamp = parts.find(([key]) => key === 't')?.[1];
  const signatures = parts.filter(([key]) => key === 'v1').map(([, value]) => value);
  if (!timestamp || signatures.length === 0) return false;

  const age = Math.abs(Date.now() / 1000 - Number(timestamp));
  if (age > TOLERANCE_SECONDS) return false;

  const expected = crypto
    .createHmac('sha256', secret)
    .update(`${timestamp}.${rawBody}`)
    .digest('hex');

  return signatures.some((signature) => {
    if (signature.length !== expected.length) return false;
    return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
  });
};
```

Each retry is signed again with a fresh timestamp, so a retried delivery passes the timestamp
check.

## Roll a secret

Roll a secret on a schedule, or whenever it may have been exposed.

```bash theme={null}
curl -X POST https://api.usehammock.co/webhook_endpoints/we_6Yt2Bn8mKp4S/roll_secret \
  -H "Authorization: Bearer hmk_live_..." \
  -H "Idempotency-Key: 57e314f3-a374-4fe0-a3c1-5fa07782baae"
```

The response contains the new secret. The old one keeps working for 24 hours, and during that
time each delivery carries two `v1` signatures, one per secret. Deploy the new secret within the
24 hours and no delivery fails verification.


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