Caracola.StirShaken.Passport (Caracola v0.1.0-rc.1)

Copy Markdown View Source

Personal Assertion Tokens (PASSporT, RFC 8225) with the SHAKEN extension (RFC 8588), signed with ES256.

A PASSporT is a JSON Web Token in compact serialization: the base64url encoded header, claims and signature, separated by dots. The JSON objects have their keys sorted and no whitespace (RFC 8225 §9).

Summary

Types

The claims of a PASSporT (RFC 8225, RFC 8588), by name.

t()

A decoded PASSporT: header, claims, signing input and signature.

Functions

Decodes a PASSporT, without checking its signature.

Encodes and signs a PASSporT. header gets alg (ES256) and typ (passport).

Checks the ES256 signature of a decoded PASSporT with a public key.

Types

claims()

@type claims() :: %{required(String.t()) => term()}

The claims of a PASSporT (RFC 8225, RFC 8588), by name.

t()

@type t() :: %{
  header: map(),
  claims: claims(),
  signing_input: binary(),
  signature: binary()
}

A decoded PASSporT: header, claims, signing input and signature.

Functions

decode(token)

@spec decode(String.t()) :: {:ok, t()} | :error

Decodes a PASSporT, without checking its signature.

iex> token = "eyJhbGciOiJFUzI1NiJ9.eyJpYXQiOjF9.AAAA"
iex> {:ok, %{header: header, claims: claims}} = Caracola.StirShaken.Passport.decode(token)
iex> {header, claims}
{%{"alg" => "ES256"}, %{"iat" => 1}}
iex> Caracola.StirShaken.Passport.decode("nope")
:error

encode(header, claims, key)

@spec encode(map(), claims(), :public_key.private_key()) :: String.t()

Encodes and signs a PASSporT. header gets alg (ES256) and typ (passport).

verify(arg1, public_key)

@spec verify(t(), :public_key.public_key()) :: boolean()

Checks the ES256 signature of a decoded PASSporT with a public key.