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

# Assinaturas

> Headers enviados e como validar HMAC-SHA256 nos webhooks.

Cada entrega de webhook inclui headers para identificação, deduplicação e assinatura.

## Headers

| Header               | Descrição                          |
| -------------------- | ---------------------------------- |
| `x-atriby-event`     | Evento enviado, como `order.paid`. |
| `x-atriby-delivery`  | ID único da entrega.               |
| `x-atriby-timestamp` | Timestamp usado na assinatura.     |
| `x-atriby-signature` | `sha256=<hmac>`.                   |

## Como a assinatura é calculada

```text theme={null}
HMAC_SHA256(secret, timestamp + "." + rawBody)
```

O valor final é enviado como:

```text theme={null}
sha256=<hex>
```

## Exemplo conceitual em Node.js

```js theme={null}
import crypto from "node:crypto"

function verifyWebhook({ secret, timestamp, rawBody, signature }) {
  const expected =
    "sha256=" +
    crypto
      .createHmac("sha256", secret)
      .update(`${timestamp}.${rawBody}`)
      .digest("hex")

  return crypto.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(expected),
  )
}
```

Use o raw body original. Se você fizer parse JSON antes de validar e serializar novamente, a assinatura pode não bater.

## Boas práticas

* Rejeite timestamps antigos.
* Deduplicate por `x-atriby-delivery`.
* Responda 2xx apenas depois de aceitar o evento.
* Guarde o segredo em cofre/variável de ambiente.
