Ankusa.SDK.ClaimCheck (ankusa_sdk v0.6.0)

Copy Markdown View Source

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), 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):

ErrorretryableCause
Ankusa.SDK.InvalidClaimRefErrorfalsebad ref, or sha256 not 64-char lowercase hex
Ankusa.SDK.ClaimNotFoundErrorfalsegateway 404: expired by retention, or never written
Ankusa.SDK.ClaimRejectedErrorfalsegateway 4xx other than 404, 408, 429
Ankusa.SDK.ClaimIntegrityErrorfalsesha256 of the returned bytes doesn't match
Ankusa.SDK.ClaimCheckUnavailableErrortruegateway unreachable, 408, 429, or anything else
client = Ankusa.SDK.ClaimCheck.new("http://localhost:4001")
{:ok, bytes} = Ankusa.SDK.ClaimCheck.redeem(client, message.claim, message.sha256)

Summary

Functions

Liveness probe: GET /health.

Build a client for base_url.

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

Types

t()

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

Functions

health(claim_check)

@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(base_url, opts \\ [])

@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(claim_check, ref, sha256)

@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.