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

Redeem claim-check refs against a deployment's claim-check gateway (the
`:claim_check` role, `claim_check.port`, default `4001`).

The gateway does no authentication or authorization (see
[`docs/claim-check.md`](https://github.com/jamescarr/ankusa/blob/main/docs/claim-check.md)),
and it does not verify integrity itself: `redeem/3` fetches the bytes and
checks them against the message's `sha256` before returning them, so
tampering in transit — or a claim object that has since been overwritten —
surfaces as `Ankusa.SDK.ClaimIntegrityError` rather than as someone else's
data.

Every failure carries `retryable`, so a consumer needs exactly one bit to
decide dead-letter (`false`) or retry (`true`):

| Error | `retryable` | Cause |
| --- | --- | --- |
| `Ankusa.SDK.InvalidClaimRefError` | `false` | bad ref, or `sha256` not 64-char lowercase hex |
| `Ankusa.SDK.ClaimNotFoundError` | `false` | gateway `404`: expired by retention, or never written |
| `Ankusa.SDK.ClaimRejectedError` | `false` | gateway `4xx` other than `404`, `408`, `429` |
| `Ankusa.SDK.ClaimIntegrityError` | `false` | sha256 of the returned bytes doesn't match |
| `Ankusa.SDK.ClaimCheckUnavailableError` | `true` | gateway unreachable, `408`, `429`, or anything else |

```elixir
client = Ankusa.SDK.ClaimCheck.new("http://localhost:4001")
{:ok, bytes} = Ankusa.SDK.ClaimCheck.redeem(client, message.claim, message.sha256)
```

# `t`

```elixir
@type t() :: %Ankusa.SDK.ClaimCheck{http: term()}
```

# `health`

```elixir
@spec health(t()) ::
  {:ok, term()} | {:error, Ankusa.SDK.ClaimCheckUnavailableError.t()}
```

Liveness probe: `GET /health`.

A `200` with a JSON body succeeds; anything else — a non-200 status, a
transport error, or a non-JSON body — is a
`Ankusa.SDK.ClaimCheckUnavailableError`.

# `new`

```elixir
@spec new(String.t(), keyword()) :: t()
```

Build a client for `base_url`.

Options are `:headers` (a map or `{name, value}` list sent on every request),
`:timeout_ms` (default `10_000`, applied to connect *and* receive — to receive
only with a `:finch` pool, which owns its connect options), and
`:req_options` (transport tuning: `:finch`, `:connect_options`,
`:pool_timeout`, `:plug`; `:finch` and `:connect_options` are exclusive).

# `redeem`

```elixir
@spec redeem(t(), term(), term()) :: {:ok, binary()} | {:error, Exception.t()}
```

Fetch the bytes a claim ref names, verifying them against `sha256`.

Returns `{:ok, bytes}` or `{:error, error}`. Nothing is requested when `ref`
or `sha256` is malformed.

---

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