Examples (and Benchmarks)

May 14, 2026 · View on GitHub

Runnable usage patterns for github.com/lestrrat-go/jwx/v4 and its companion modules. Every file in this repo is a single Example_* test function with extensive inline comments — read them as documentation, run them with go test.

Build/run requires GOEXPERIMENT=jsonv2 (jwx v4 depends on encoding/json/v2).

Per-package entry points

Start here if you want a representative overview of a package:

The topical index below lists every example file by purpose. Filenames follow <package>_<action>_example_test.go.

JWT — tokens, claims, validation

Constructing

Parsing / verifying

Validating

Signing / serialization

Filtering claims

JWS — sign and verify arbitrary payloads

Signing

Verifying / parsing

Filtering headers

JWE — encrypt and decrypt arbitrary payloads

Encrypting

Decrypting / parsing

Filtering headers

JWK — keys and key sets

Parsing

Generating / converting

Extending (custom key types / formats)

Fetching

  • Fetch — one-shot HTTP retrieval via the jwkfetch companion
  • Cache — background-refreshed JWK Set store
  • Cached set as a JWKS — pass a cache to jwt.WithKeySet
  • URL whitelist — restrict which URLs jwkfetch will dereference (required for jku)

Comparing / filtering

Extension modules

Each extension is a separate module under github.com/jwx-go/*. Import for side effects.

Post-quantum signatures (ML-DSA)

Post-quantum key encapsulation (ML-KEM)

Hybrid PQ HPKE

Composite signatures

  • Sign / verify — ML-DSA + classical via github.com/jwx-go/compsig/v4 (experimental)

Niche curves

Tooling / backends

Library-wide

Contributing a new example

  1. One example per file. File name: <topic>_<action>_example_test.go.
  2. Function name: Example_<topic>_<action>() — the matching slug without _example_test.go.
  3. Add a line to the topical index above in the same PR.
  4. Include ample inline comments that explain why the code is shaped the way it is.
  5. End with an // OUTPUT: block — even an empty one if the function prints nothing.

See CLAUDE.md for the full conventions.