Exosphere.ATProto.OAuth.JWK (Exosphere v0.6.0)

Copy Markdown View Source

JSON Web Keys (RFC 7517) for the ATProto OAuth profile.

ATProto OAuth uses elliptic-curve JWKs — P-256 for the spec-required ES256 (and optionally secp256k1 for ES256K) — as the client's long-term authentication key and as the per-session DPoP key.

Keys are represented as plain maps (%{"kty" => "EC", "crv" => ..., "x" => ..., "y" => ..., "d" => ...} with x/y/d base64url-encoded coordinates); private keys additionally carry "d" and must never be embedded in a client metadata document or DPoP proof header.

Examples

{:ok, jwk} = Exosphere.ATProto.OAuth.JWK.generate(:p256)
public = Exosphere.ATProto.OAuth.JWK.to_public(jwk)

Summary

Functions

Convert an ATProto.Crypto keypair into a private JWK map.

Generate a new keypair as a private JWK map.

RFC 7638 JWK thumbprint: BASE64URL(SHA256(canonical JSON)) over the required members for the key type, in lexicographic order.

Strip the private "d" member, returning the public JWK map.

Parse a public JWK map back into an ATProto.Crypto compressed public key.

Types

curve()

@type curve() :: :p256 | :secp256k1

t()

@type t() :: %{optional(binary()) => binary()}

Functions

from_keypair(map, curve)

@spec from_keypair(Exosphere.ATProto.Crypto.keypair(), curve()) ::
  {:ok, t()} | {:error, term()}

Convert an ATProto.Crypto keypair into a private JWK map.

The public key may be compressed (33 bytes) or uncompressed (65 bytes).

generate(curve)

@spec generate(curve()) :: {:ok, t()}

Generate a new keypair as a private JWK map.

thumbprint(arg1)

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

RFC 7638 JWK thumbprint: BASE64URL(SHA256(canonical JSON)) over the required members for the key type, in lexicographic order.

to_public(jwk)

@spec to_public(t()) :: t()

Strip the private "d" member, returning the public JWK map.

to_public_key(arg1)

@spec to_public_key(t()) ::
  {:ok, binary(), Exosphere.ATProto.Crypto.curve()} | {:error, term()}

Parse a public JWK map back into an ATProto.Crypto compressed public key.

Only elliptic-curve keys on the supported curves parse.