ReqDPoP.Key (ReqDPoP v0.8.0)

Copy Markdown View Source

Helpers for DPoP signing keys.

Production clients should persist their DPoP key when they need stable sender binding across process restarts.

inspect/1 shows only the algorithm, never key material.

Summary

Functions

Exports the private JWK as a map.

Generates a private signing key for :es256 or :rs256.

Returns the underlying JOSE.JWK.

Loads a ReqDPoP.Key from a key struct, JOSE.JWK, or JWK map.

Returns the public JWK placed in the proof jwk header.

Exports the public JWK as a map.

Returns the RFC 7638 SHA-256 JWK thumbprint, base64url unpadded.

Types

alg()

@type alg() :: :es256 | :rs256

t()

@type t() :: %ReqDPoP.Key{alg: alg(), jwk: JOSE.JWK.t()}

Functions

export(key)

@spec export(t()) :: map()

Exports the private JWK as a map.

generate(alg)

@spec generate(alg()) :: t()

Generates a private signing key for :es256 or :rs256.

jose_jwk(key)

@spec jose_jwk(t()) :: JOSE.JWK.t()

Returns the underlying JOSE.JWK.

load!(jwk)

@spec load!(t() | JOSE.JWK.t() | map()) :: t()

Loads a ReqDPoP.Key from a key struct, JOSE.JWK, or JWK map.

The key must be a complete private signing key: a P-256 EC key with 32-byte x, y, and d, or an RSA key of at least 2048 bits with n, e, and d. A JWK that carries use or key_ops (RFC 7517 sections 4.2 and 4.3) must allow signing: use must be "sig", and key_ops must be a list of strings that contains "sign". A key with neither member is accepted. Anything else raises ReqDPoP.Error with reason :invalid_key or :unsupported_key. Error messages never include key material.

proof_jwk(key)

@spec proof_jwk(t()) :: map()

Returns the public JWK placed in the proof jwk header.

Only the RFC 7638 thumbprint members are included: crv, kty, x, and y for EC keys; e, kty, and n for RSA keys. Any other member of a loaded JWK map stays out of the proof, so application-specific fields never travel with it.

public_jwk(key)

@spec public_jwk(t()) :: map()

Exports the public JWK as a map.

The map keeps every public member of the loaded JWK, such as kid, except key_ops: the private key's operations (sign) do not describe what its public half may do. The proof header uses proof_jwk/1 instead.

thumbprint(jwk)

@spec thumbprint(t() | JOSE.JWK.t() | map()) :: binary()

Returns the RFC 7638 SHA-256 JWK thumbprint, base64url unpadded.

Accepts public keys as well as private ones.