DIDs & keys
Signing keys
openvc.keys
openvc.keys — key backends implementing the SigningKey protocol.
Two software backends are provided:
- Ed25519SigningKey -> alg "EdDSA" (default for general OB 3.0 issuance; opt into the RFC 9864 fully-specified name "Ed25519" with alg="Ed25519")
- P256SigningKey -> alg "ES256" (P-256, required for EBSI/EUDI)
Both produce JWS-compatible signatures, which is the subtle part:
- Ed25519 : cryptography already returns the raw 64-byte signature — no change.
- ES256 : cryptography returns a DER-encoded ECDSA signature. JOSE requires the fixed-length raw form R||S (32 + 32 = 64 bytes). We convert on sign and back to DER on verify. Getting this wrong is the classic reason a locally-produced ES256 token fails to verify in another stack.
HSM / Vault backends: anything implementing SigningKey (alg, kid, sign returning
R||S for ES256) is a drop-in replacement — e.g. a PKCS#11 or Vault Transit backend
whose sign performs the operation without the private key ever entering the
process. These software classes are for dev, tests, and low-assurance issuance.
Ed25519SigningKey
An in-process Ed25519 (EdDSA) signing key — the general OB 3.0 default.
The JOSE algorithm name emitted in the header defaults to the (still-supported)
polymorphic "EdDSA"; pass alg="Ed25519" to emit the RFC 9864
fully-specified name instead. Both name the same Ed25519 signature.
Source code in src/openvc/keys.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
alg
property
The JOSE algorithm name in the header — "EdDSA" (default) or the RFC
9864 fully-specified "Ed25519".
kid
property
The verification-method id this key signs as.
sign(signing_input)
Sign signing_input; returns the raw 64-byte Ed25519 signature.
Source code in src/openvc/keys.py
107 108 109 110 | |
public_jwk()
The public key as an OKP JWK.
Source code in src/openvc/keys.py
112 113 114 115 116 117 | |
public_key_raw()
Raw 32-byte public key (used by the did:key encoder, multicodec 0xed01).
Source code in src/openvc/keys.py
119 120 121 122 123 | |
P256SigningKey
An in-process P-256 (ES256) signing key — required for EBSI/EUDI.
Source code in src/openvc/keys.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
kid
property
The verification-method id this key signs as.
sign(signing_input)
Sign signing_input; returns the raw R‖S signature (JOSE ES256, not DER).
Source code in src/openvc/keys.py
167 168 169 170 171 | |
public_jwk()
The public key as an EC P-256 JWK.
Source code in src/openvc/keys.py
173 174 175 176 177 178 179 180 181 | |
public_key_raw(*, compressed=True)
SEC1 point (compressed by default) — used by the did:key encoder (multicodec 0x1200 for P-256).
Source code in src/openvc/keys.py
183 184 185 186 187 188 | |
P384SigningKey
An in-process P-384 (ES384) signing key — the P-384 leg of the
Data Integrity ECDSA cryptosuites (ecdsa-jcs-2019 / ecdsa-rdfc-2019).
Source code in src/openvc/keys.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
kid
property
The verification-method id this key signs as.
sign(signing_input)
Sign signing_input over SHA-384; returns the raw R‖S signature (JOSE ES384, 96 bytes — not DER).
Source code in src/openvc/keys.py
231 232 233 234 235 236 | |
public_jwk()
The public key as an EC P-384 JWK.
Source code in src/openvc/keys.py
238 239 240 241 242 243 244 245 246 | |
public_key_raw(*, compressed=True)
SEC1 point (compressed by default) — used by the did:key encoder (multicodec 0x1201 for P-384).
Source code in src/openvc/keys.py
248 249 250 251 252 253 | |
KeyAgreementKey
Bases: Protocol
The recipient's static private half for JWE ECDH-ES key agreement.
The encryption counterpart of :class:~openvc.proof.vc_jwt.SigningKey: an
HSM/Vault backend that runs the raw ECDH on-device (never exporting the private
scalar) drops in by implementing crv, kid and agree — which returns
the raw ECDH shared secret Z; the public JWE Concat KDF is applied by the
caller (:mod:openvc.jwe), so no secret-derived material beyond Z crosses the
boundary.
Source code in src/openvc/keys.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
P256KeyAgreementKey
An in-process P-256 ECDH key-agreement key (JWE ECDH-ES, HAIP responses).
Source code in src/openvc/keys.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
kid
property
The id the recipient key is published under (JWE kid).
agree(peer_public_jwk)
Return the raw ECDH shared secret Z (the 32-byte big-endian X
coordinate of the shared point) with the peer's ephemeral public key (the JWE
epk). A non-P-256 peer key is rejected before any curve operation.
Source code in src/openvc/keys.py
317 318 319 320 321 322 323 324 325 326 327 328 329 | |
public_jwk()
The public key as an EC P-256 JWK marked use:"enc" — the verifier
publishes this (in client_metadata.jwks) for the wallet to encrypt to.
Source code in src/openvc/keys.py
331 332 333 334 335 336 337 338 339 | |
MLDSASigningKey
Experimental post-quantum ML-DSA (RFC 9964) signing key — opt-in, not a
production trust path (ADR-0004). Implements the :class:SigningKey protocol: alg
is the parameter set (ML-DSA-44 / ML-DSA-65 / ML-DSA-87), the private key
is a 32-byte seed, and sign returns the raw ML-DSA signature — no R‖S transform,
it is already the JOSE-wire form.
An HSM/Vault backend uses external-mu (sign_mu) so the message never reaches the
device in the clear; this in-process backend is for dev, tests and low-assurance
issuance, exactly like the EC / Ed backends.
Source code in src/openvc/keys.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
sign(signing_input)
Sign signing_input; returns the raw ML-DSA signature (JOSE-wire form).
Source code in src/openvc/keys.py
432 433 434 435 436 437 | |
public_jwk()
The public key as an RFC 9964 AKP JWK (kty / alg / pub).
Source code in src/openvc/keys.py
439 440 441 442 | |
private_jwk()
The private AKP JWK — adds the 32-byte seed priv. Handle with care.
Source code in src/openvc/keys.py
444 445 446 | |
mldsa_available()
True if ML-DSA is usable here — the module imports and the OpenSSL build
supports it (a wheel built against OpenSSL < 3.5 raises at first use even on
cryptography 49). Gate experimental ML-DSA paths and skip tests where unavailable.
Source code in src/openvc/keys.py
386 387 388 389 390 391 392 393 394 | |
verify_signature(*, alg, public_jwk, signing_input, signature)
Verify a JOSE signature directly from a public JWK, without PyJWT.
Handy for did:key (where the key is inside the DID) and for round-trip tests. The VC verification path uses the proof suite instead; this is complementary.
Source code in src/openvc/keys.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
signing_key_from_jwk(jwk, kid)
Dispatch to the right backend from a private JWK.
Source code in src/openvc/keys.py
537 538 539 540 541 542 543 544 545 546 547 548 | |
DID resolution
openvc.did.base
openvc.did.base — core DID resolution primitives.
Home of the generic types every DID method shares: VerificationMethod, DidDocument, the DidResolver protocol, a shared W3C DID-document parser, and a registry that dispatches a DID to the backend that supports it. No network, no method specifics.
(These types used to live in the EBSI plugin; they are generic to did:key, did:web and did:ebsi alike, so they belong in the core.)
VerificationMethod
dataclass
Source code in src/openvc/did/base.py
40 41 42 43 44 45 46 47 48 49 50 | |
kid
property
The verification-method id — the #fragment key identifier.
DidDocument
dataclass
Source code in src/openvc/did/base.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
key_by_kid(kid)
Match on the full verificationMethod id or its fragment (a JWS kid
may carry either). If kid is None, fall back to the sole key if unique.
Source code in src/openvc/did/base.py
63 64 65 66 67 68 69 70 71 72 | |
key_for_purpose(kid, proof_purpose)
Like :meth:key_by_kid, but authorized for proof_purpose.
If the document declares that relationship, the method must be referenced by it (returns None otherwise — the key exists but is not usable for this purpose). If the document does not declare the relationship at all, the binding cannot be enforced and the matched key is returned as-is.
Source code in src/openvc/did/base.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
DidResolver
Bases: Protocol
Source code in src/openvc/did/base.py
103 104 105 106 107 108 | |
supports(did)
Whether this resolver handles did (its DID method).
Source code in src/openvc/did/base.py
105 106 | |
resolve(did)
Resolve did to a :class:DidDocument, or raise :class:DidResolutionError.
Source code in src/openvc/did/base.py
107 108 | |
DidResolverRegistry
A registry that dispatches resolve to the first resolver that supports the DID.
Source code in src/openvc/did/base.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
register(resolver)
Add a resolver (consulted in registration order).
Source code in src/openvc/did/base.py
215 216 217 | |
resolve(did)
Resolve did via the first matching resolver, else raise UnsupportedDidMethod.
Source code in src/openvc/did/base.py
219 220 221 222 223 224 | |
AsyncDidResolver
Bases: Protocol
The async counterpart of :class:DidResolver: supports stays a plain
predicate (no I/O), resolve is awaitable so a backend can await a non-blocking
fetch. A sync resolver is adapted to this shape by :func:as_async_resolver.
Source code in src/openvc/did/base.py
231 232 233 234 235 236 237 238 239 | |
supports(did)
Whether this resolver handles did (its DID method).
Source code in src/openvc/did/base.py
236 237 | |
resolve(did)
Resolve did to a :class:DidDocument, or raise :class:DidResolutionError.
Source code in src/openvc/did/base.py
238 239 | |
AsyncDidResolverRegistry
The async counterpart of :class:DidResolverRegistry: dispatches an awaitable
resolve to the first :class:AsyncDidResolver that supports the DID.
Source code in src/openvc/did/base.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
register(resolver)
Add a resolver (consulted in registration order).
Source code in src/openvc/did/base.py
270 271 272 | |
resolve(did)
async
Resolve did via the first matching resolver, else raise UnsupportedDidMethod.
Source code in src/openvc/did/base.py
274 275 276 277 278 279 | |
multikey_to_jwk(multibase_key)
Decode a publicKeyMultibase Multikey to a public JWK.
Handles the key types openvc verifies with — Ed25519 (multicodec 0xed) and the
NIST curves P-256 (0x1200) / P-384 (0x1201, SEC1 compressed points) — the same
set as :mod:openvc.did.did_key. Raises :class:~openvc.multibase.MultibaseError
(or ValueError for an off-curve point / unknown codec) so the caller can skip an
undecodable method rather than crash.
Source code in src/openvc/did/base.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
parse_did_document(raw)
Parse a W3C DID document. Tolerates a didDocument wrapper or a bare doc
(the EBSI DID Registry returns it bare, as application/did+ld+json). Verification
methods may carry publicKeyJwk or a publicKeyMultibase Multikey (did:webvh and
modern did:web documents use the latter).
The parser is context-agnostic — it reads the document shape
(verificationMethod / relationships), never @context — so DID 1.1 / CID 1.0
documents (the https://www.w3.org/ns/did/v1.1 context) resolve unchanged. The DID 1.1
relationship-semantics diff is revisited when it reaches Proposed Recommendation.
Source code in src/openvc/did/base.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
as_async_resolver(resolver)
Wrap a sync :class:DidResolver as an :class:AsyncDidResolver (its
resolve awaits nothing). Lets an offline did:key / did:jwk resolver — or any
sync resolver whose blocking is acceptable — drop into an async registry.
Source code in src/openvc/did/base.py
256 257 258 259 260 | |
openvc.did.did_key
openvc.did.did_key — offline resolver for the did:key method (Ed25519, P-256).
did:key is self-contained: the public key is encoded in the identifier itself, so resolution is pure decoding — no network. Format:
did:key:z<base58btc( <multicodec-varint> || <raw-public-key> )>
Supported multicodecs
0xed Ed25519 public key -> OKP / Ed25519 JWK 0x1200 P-256 public key -> EC / P-256 JWK (from the compressed point)
openvc.did.did_jwk
openvc.did.did_jwk — offline resolver for the did:jwk method.
did:jwk is self-contained like did:key: the public key is the identifier, a base64url-encoded JSON JWK, so resolution is pure decoding — no network. Format:
did:jwk:<base64url-nopad( utf8( JSON public JWK ) )>
The verification method fragment is always #0, and it is referenced by every
signing verification relationship. Common in EUDI / OID4VC test stacks.
openvc.did.did_web
openvc.did.did_web — resolver for the did:web method.
did:web maps a DID to an https URL and fetches the DID document from the issuer's own domain:
did:web:example.edu -> https://example.edu/.well-known/did.json
did:web:example.edu:issuers:physics -> https://example.edu/issuers/physics/did.json
did:web:example.edu%3A3000 -> https://example.edu:3000/.well-known/did.json
SSRF note
did:web is intentionally cross-host — the whole point is to resolve a controller's
own domain — so a fixed host allow-list does NOT apply here (unlike the EBSI client).
Pass a general-purpose fetch for this resolver, ideally one that still enforces
https and blocks private/link-local address ranges. Do NOT reuse the EBSI client,
whose allow-list would reject every legitimate did:web host.
AsyncDidWebResolver
The async counterpart of :class:DidWebResolver: same URL mapping and id
integrity check, but awaits an injected async fetch (pass
:func:openvc.fetch.https_json_fetch_async for the SSRF-guarded one).
Source code in src/openvc/did/did_web.py
67 68 69 70 71 72 73 74 75 76 77 78 | |
SSRF-guarded fetch
openvc.fetch
openvc.fetch — an SSRF-guarded, stdlib-only https JSON fetch for did:web.
did:web is intentionally cross-host (it resolves a controller's own domain), so it cannot use a host allow-list like the EBSI client. This fetch instead blocks the dangerous targets: it requires https, resolves the host and refuses any private / loopback / link-local / reserved / multicast address (the cloud metadata endpoint 169.254.169.254 is link-local, so it is covered), and refuses HTTP redirects — a common SSRF pivot.
DNS-rebinding is closed, not just documented: the connection is pinned to the validated IP (we resolve, validate every resolved address, then open the TCP socket to that exact IP) while TLS SNI, certificate validation, and the Host header still use the hostname. So an attacker who flips DNS between the check and the connect cannot redirect us to an internal address — we never re-resolve.
Dependency-light on purpose: pure stdlib (http.client + ssl + socket +
ipaddress). Pass https_json_fetch wherever a Fetch is expected, or use
default_did_web_resolver().
UnsafeUrlError
Bases: DidResolutionError
The URL or a resolved address is not allowed (scheme, host, or IP range).
Source code in src/openvc/fetch.py
45 46 | |
https_json_fetch(url, *, timeout_s=DEFAULT_TIMEOUT_S, max_bytes=MAX_RESPONSE_BYTES)
Fetch url as a JSON object with the SSRF guards above. Returns the parsed object.
Raises :class:UnsafeUrlError for a disallowed scheme/host/address or a
redirect (a subclass of :class:~openvc.did.base.DidResolutionError), and
DidResolutionError for transport / oversize / non-JSON failures.
Source code in src/openvc/fetch.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
https_text_fetch(url, *, timeout_s=DEFAULT_TIMEOUT_S, max_bytes=MAX_RESPONSE_BYTES)
Fetch url as UTF-8 text with the same SSRF guards as :func:https_json_fetch.
For resources that are not JSON objects — a compact-JWS status-list credential
(VC-JWT) or an IETF statuslist+jwt token. Raises the same error family.
Source code in src/openvc/fetch.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
https_bytes_fetch(url, *, timeout_s=DEFAULT_TIMEOUT_S, max_bytes=MAX_RESPONSE_BYTES)
Fetch url as raw bytes with the same SSRF guards as :func:https_json_fetch.
For resources whose exact bytes matter — a credentialSchema whose
digestSRI is verified over the response before parsing. Raises the same
error family.
Source code in src/openvc/fetch.py
192 193 194 195 196 197 198 199 200 201 202 203 | |
default_did_web_resolver()
A :class:~openvc.did.did_web.DidWebResolver wired to the SSRF-guarded
fetch — the batteries-included way to resolve did:web offline of any HTTP
client dependency.
Source code in src/openvc/fetch.py
206 207 208 209 210 | |
default_did_webvh_resolver()
A :class:~openvc.did.did_webvh.DidWebvhResolver wired to the SSRF-guarded
text fetch (did.jsonl is JSON Lines, not one JSON object) — the
batteries-included did:webvh resolver.
Source code in src/openvc/fetch.py
213 214 215 216 217 218 | |
https_json_fetch_async(url, *, timeout_s=DEFAULT_TIMEOUT_S, max_bytes=MAX_RESPONSE_BYTES)
async
Async :func:https_json_fetch — same SSRF guards, run off the event loop.
Source code in src/openvc/fetch.py
233 234 235 236 237 | |
https_text_fetch_async(url, *, timeout_s=DEFAULT_TIMEOUT_S, max_bytes=MAX_RESPONSE_BYTES)
async
Async :func:https_text_fetch — same SSRF guards, run off the event loop.
Source code in src/openvc/fetch.py
240 241 242 243 244 | |
https_bytes_fetch_async(url, *, timeout_s=DEFAULT_TIMEOUT_S, max_bytes=MAX_RESPONSE_BYTES)
async
Async :func:https_bytes_fetch — same SSRF guards, run off the event loop.
Source code in src/openvc/fetch.py
247 248 249 250 251 | |
default_async_did_web_resolver()
An :class:~openvc.did.did_web.AsyncDidWebResolver wired to the SSRF-guarded
async fetch — the async counterpart of :func:default_did_web_resolver.
Source code in src/openvc/fetch.py
254 255 256 257 | |
default_async_did_webvh_resolver()
The async counterpart of :func:default_did_webvh_resolver — an
:class:~openvc.did.did_webvh.AsyncDidWebvhResolver on the SSRF-guarded async
text fetch.
Source code in src/openvc/fetch.py
260 261 262 263 264 265 | |