Skip to content

feat: add jwk and jwk-set key codecs#403

Open
lidel wants to merge 1 commit intomasterfrom
add-jwk-key-codecs
Open

feat: add jwk and jwk-set key codecs#403
lidel wants to merge 1 commit intomasterfrom
add-jwk-key-codecs

Conversation

@lidel
Copy link
Copy Markdown
Member

@lidel lidel commented Apr 30, 2026

Summary

Adds two self-describing JSON key container codecs, the JSON twin of the cose-key/cose-key-set pair proposed in #400.

name code format spec
jwk 0x44 JSON-encoded JSON Web Key (application/jwk+json) RFC 7517 §4
jwk-set 0x45 JSON-encoded JWK Set (application/jwk-set+json) RFC 7517 §5

The payload identifies its own algorithm via the kty/alg/crv parameters. The same container carries public or private key material; private parameters (d, p, q, dp, dq, qi) mark a private key.

Suggested by @achingbrain in #400 (comment).

Motivation

Same as #400: stop gating new key types in libp2p peer IDs and IPNS records on per-algorithm multicodec registrations. Once IETF/IANA registers a new kty/alg value, JWK producers can emit it and JWK consumers can parse it. No multicodec update required.

JSON web stacks already speak JWK everywhere: OAuth and OIDC JWKS endpoints, WebCrypto's importKey/exportKey, every JOSE library, WebAuthn passkey enrollment. cose-key covers the CBOR-native side of the same story; jwk covers the JSON-native side and lets JS and web stacks participate without a CBOR dependency.

Relationship to existing jwk_jcs-pub / jwk_jcs-priv

The registry already contains:

  • jwk_jcs-pub (0xeb51)
  • jwk_jcs-priv (0x1316)

Those constrain the format on purpose: required-members-only JWK, JCS-canonicalized per RFC 8785. They give peer-ID-style identifiers a deterministic encoding, so the same key always hashes to the same bytes.

The new jwk/jwk-set codecs complement them as the loose-container counterparts:

  • jwk / jwk-set: any well-formed RFC 7517 JWK or JWK Set, arbitrary members allowed, no canonicalization promised. Use when wrapping or referencing an as-is JWK (a JWKS fetched from an OIDC provider, a WebCrypto export, a JWK with kid/use/x5c metadata).
  • jwk_jcs-pub / jwk_jcs-priv: minimal, canonical, deterministic. Use when the codec output is the identifier itself (peer IDs, content addressing of bare keys).

cose-key (loose) lacks a canonical-subset codec too, so the same asymmetry already exists on the CBOR side.

Code placement

0x44 and 0x45 extend the single-byte block #400 establishes at 0x40-0x43. All six codes stay single-byte varints (< 0x80), so identifiers built on top (peer IDs, IPNS names) keep the one-byte prefix forever. Same argument as #400.

The existing jwk_jcs-* codes sit at two-byte varints (0x1316, 0xeb51); a single-byte option is genuinely new real estate, not duplication.

Dependencies

This PR touches 0x44-0x45; #400 touches 0x40-0x43. The diffs are independent. If #400 lands first, the four containers sit consecutively. If this lands first, 0x40-0x43 stay vacant until #400 merges. No conflict either way.

Adds the JSON sister of the cose-key family from #400. Uses single-byte
codes adjacent to that block so JWK-based identifiers do not pay an
extra prefix byte forever.

* jwk (0x44): JSON-encoded JWK per RFC 7517 section 4
* jwk-set (0x45): JSON-encoded JWK Set per RFC 7517 section 5

The existing jwk_jcs-pub (0xeb51) and jwk_jcs-priv (0x1316) entries
remain; they are a strict canonical-JCS subset suited to stable peer
IDs. The new entries cover full RFC 7517 JWK as a self-describing
container; choose jwk_jcs-* when deterministic encoding matters and
jwk/jwk-set when interoperating with arbitrary RFC 7517 producers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant