Documentation
¶
Overview ¶
Package jwt issues self-signed JSON Web Tokens. It parses a private signing key from a JSON Web Key (JWK) once and mints compact-serialized tokens on demand, stamping the key's id into the token header so verifiers can locate the matching public key.
The signing algorithm is derived from the key type for key types that map to a single unambiguous algorithm:
ed25519.PrivateKey -> EdDSA *ecdsa.PrivateKey -> ES256 / ES384 / ES512 (by curve: P-256 / P-384 / P-521) *mldsa.PrivateKey -> ML-DSA-44 / ML-DSA-65 / ML-DSA-87 (from the JWK "alg")
ML-DSA keys use the RFC 9964 "AKP" key type, whose key material does not identify a parameter set: "kty":"AKP" with opaque "pub"/"priv" bytes may be any of ML-DSA-44, ML-DSA-65 or ML-DSA-87. RFC 9964 therefore requires the "alg" member on every AKP key, and for AKP it is the only source of the algorithm. It is still never trusted on its own: it must name an ML-DSA algorithm and the key must be an ML-DSA key, so it cannot disagree with the key.
RSA is intentionally unsupported: an RSA key does not determine a single algorithm (RS256/384/512, PS256/384/512), so signing one would require the library to pick on the caller's behalf.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SigningKey ¶
type SigningKey struct {
// contains filtered or unexported fields
}
SigningKey is a private signing key, parsed from a JWK, that mints signed JWTs using the algorithm determined by the key.
func ParseJWK ¶
func ParseJWK(jwk string) (*SigningKey, error)
ParseJWK parses jwk, a single JSON Web Key, and returns its private signing key. The key must be of a type that maps to a single signing algorithm: an Ed25519 private key (kty "OKP", crv "Ed25519"), an ECDSA private key (kty "EC", crv "P-256", "P-384", or "P-521"), or an ML-DSA private key (kty "AKP", RFC 9964), all carrying the private component. RSA keys are rejected because their algorithm is ambiguous.
An AKP key carries no "crv", so its "alg" member is required and selects the ML-DSA parameter set. For every other key type "alg" is ignored.
func (*SigningKey) Issue ¶
Issue mints a compact-serialized JWT signed with the key, using the algorithm determined by the key. The signing key's id is set in the "kid" header field. The token carries all seven registered claims (RFC 7519): iss, sub, and every audience in auds, iat at the current time, nbf backdated by a small clock-skew leeway, exp ttl after issuance, and a random jti. aud is always encoded as a JSON array, which RFC 7519 permits for any number of audiences.