# `Ankusa.SDK.Signature`
[🔗](https://github.com/jamescarr/ankusa/blob/sdk-elixir-v0.6.0/packages/sdk-elixir/lib/ankusa/sdk/signature.ex#L1)

Verify the [Standard Webhooks](https://www.standardwebhooks.com/) signature
an `Ankusa.Sink.Http` sink with a `secret` adds to every delivery.

`webhook-signature` holds space-separated `v1,<base64>` entries, each an
HMAC-SHA256 over `<webhook-id>.<webhook-timestamp>.<body>`. A delivery
passes when any `v1` entry matches any configured secret (several during a
rotation), compared in constant time, and `webhook-timestamp` is within the
tolerance of now.

Secrets are `whsec_` + base64, or any other string used as its own bytes.
`Ankusa.SDK.Receiver` calls this for you when given `:secret`.

# `verified`

```elixir
@type verified() :: %{id: String.t(), timestamp: non_neg_integer()}
```

A verified delivery's `webhook-id` and `webhook-timestamp`.

# `verify`

```elixir
@spec verify(Enumerable.t(), binary(), String.t() | [String.t()], keyword()) ::
  {:ok, verified()} | {:error, Ankusa.SDK.InvalidSignatureError.t()}
```

Verify one delivery. `headers` is a map or a list of `{name, value}` pairs
(names case-insensitive; in a list the first occurrence wins); `body` must
be the raw bytes received; `secrets` is one secret or a list.

Options: `:tolerance_seconds` (default 300) and
`:now` (unix seconds; default the system clock).

The checks run in this order, the first failure deciding the error's
`:code`: `"invalid_secret"`, `"missing_header"` (`webhook-id`,
`webhook-timestamp`, `webhook-signature`), `"invalid_timestamp"`,
`"timestamp_out_of_tolerance"`, `"no_matching_signature"`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
