Hrana-over-HTTP baton — an opaque, server-signed token that identifies a stream and enforces single-use, serial access.
Wire format (matching libsql): base64 (no padding) of a 48-byte string:
- payload (16 bytes):
stream_id(u64 big-endian) followed byseq(u64 big-endian) - MAC (32 bytes):
HMAC-SHA256(payload)keyed by a per-server secret
The MAC proves the baton was issued by this server. The seq rotates on every
request, so a baton is single-use and requests on a stream are serialized: the
next request must present the seq the server last handed back.
Summary
Functions
Decodes and verifies a baton, returning {:ok, {stream_id, seq}} or
{:error, :invalid} for any malformed, wrong-length, or unauthentic baton.
Encodes a baton for stream_id/seq, signed with key.
Generates a fresh 32-byte signing key for a server.
Functions
@spec decode(String.t(), binary()) :: {:ok, {non_neg_integer(), non_neg_integer()}} | {:error, :invalid}
Decodes and verifies a baton, returning {:ok, {stream_id, seq}} or
{:error, :invalid} for any malformed, wrong-length, or unauthentic baton.
@spec encode(non_neg_integer(), non_neg_integer(), binary()) :: String.t()
Encodes a baton for stream_id/seq, signed with key.
@spec new_key() :: binary()
Generates a fresh 32-byte signing key for a server.