Package ch.admin.bj.swiyu.sdjwtvalidator
Class SdJwtVcValidator
java.lang.Object
ch.admin.bj.swiyu.sdjwtvalidator.SdJwtVcValidator
Validates SD-JWT VC tokens according to the Swiss Profile VC specification (RFC 9901).
Extends the base DID-based JWT validation provided by DidJwtValidator with
SD-JWT VC specific rules mandated by the Swiss Profile:
typJOSE header must bedc+sd-jwt(configurable for migration phase)_sd_algclaim must besha-256- Registered claims (
iss,nbf,exp,iat,cnf,vct,vct#integrity,status,vct_metadata_uri,vct_metadata_uri#integrity,_sd,_sd_alg) MUST NOT appear as selectively disclosed claims (RFC 9901 §3.2.2.2)
Typical usage – Flow B (two-step, no internal HTTP calls):
// Step 1: get the DID resolution URL, caller performs the HTTP GET
String didUrl = validator.getAndValidateResolutionUrl(sdJwt);
// Step 2: validate with the fetched DID Document
boolean valid = validator.validateSdJwtVc(sdJwt, didDocument);
Migration phase (accepting both dc+sd-jwt and vc+sd-jwt):
new SdJwtVcValidator(didJwtValidator,
Set.of(SdJwtVcValidator.TYP_DC_SD_JWT, SdJwtVcValidator.TYP_VC_SD_JWT));
This class is framework-agnostic and has no Spring dependencies.
-
Field Summary
FieldsModifier and TypeFieldDescriptionRegistered JWT claims that MUST NOT appear in any Disclosure per RFC 9901 §3.2.2.2 and the Swiss Profile VC specification.static final Stringtypvalue required by SD-JWT VC spec (post-migration).static final Stringtypvalue accepted during the migration phase alongsideTYP_DC_SD_JWT. -
Constructor Summary
ConstructorsConstructorDescriptionSdJwtVcValidator(DidJwtValidator didJwtValidator) Creates anSdJwtVcValidatorthat accepts onlydc+sd-jwtastyp.SdJwtVcValidator(DidJwtValidator didJwtValidator, Set<String> acceptedTypValues) Creates anSdJwtVcValidatorwith a configurable set of acceptedtypvalues. -
Method Summary
Modifier and TypeMethodDescriptionStep 1 of Flow B – validates thetypheader and returns the DID resolution URL.voidvalidateSdJwtVc(String sdJwt, ch.admin.eid.did_sidekicks.DidDoc didDocument) Step 2 of Flow B – validates the full SD-JWT VC against the pre-fetched DID Document.voidvalidateSdJwtVc(String sdJwt, com.nimbusds.jose.jwk.JWKSet jwkSet) Flow A – validates the SD-JWT VC directly against the provided JWK set.
-
Field Details
-
TYP_DC_SD_JWT
typvalue required by SD-JWT VC spec (post-migration).- See Also:
-
TYP_VC_SD_JWT
typvalue accepted during the migration phase alongsideTYP_DC_SD_JWT.- See Also:
-
PROTECTED_CLAIMS
Registered JWT claims that MUST NOT appear in any Disclosure per RFC 9901 §3.2.2.2 and the Swiss Profile VC specification.
-
-
Constructor Details
-
SdJwtVcValidator
Creates anSdJwtVcValidatorthat accepts onlydc+sd-jwtastyp.- Parameters:
didJwtValidator- the underlying DID-based JWT validator; must not benull
-
SdJwtVcValidator
Creates anSdJwtVcValidatorwith a configurable set of acceptedtypvalues.Use this constructor during the migration phase to accept both
dc+sd-jwtandvc+sd-jwt.- Parameters:
didJwtValidator- the underlying DID-based JWT validator; must not benullacceptedTypValues- the set of acceptedtypheader values; must not be empty
-
-
Method Details
-
getAndValidateResolutionUrl
Step 1 of Flow B – validates thetypheader and returns the DID resolution URL.The caller is expected to perform the HTTP GET to the returned URL to fetch the DID Document, and then call
validateSdJwtVc(String, DidDoc).- Parameters:
sdJwt- the SD-JWT string (<issuer-jwt>~[<disclosure>~]*)- Returns:
- the validated DID resolution URL for the caller to fetch
- Throws:
JwtValidatorException- if thetypis invalid or DID resolution fails
-
validateSdJwtVc
Step 2 of Flow B – validates the full SD-JWT VC against the pre-fetched DID Document.Checks performed in order:
typheader is in the configured set of accepted values_sd_algclaim equalssha-256- No registered/protected claim appears in any Disclosure
- DID-based signature verification (delegated to
DidJwtValidator)
- Parameters:
sdJwt- the SD-JWT stringdidDocument- the pre-fetched DID Document for signature verification- Throws:
JwtValidatorException- if any check fails
-
validateSdJwtVc
Flow A – validates the SD-JWT VC directly against the provided JWK set.Use this when the JWK set is already available and no DID resolution is needed. Same structural checks (
typ,_sd_alg, protected claims) are applied.- Parameters:
sdJwt- the SD-JWT stringjwkSet- the JWK set containing the public key(s) to verify against- Throws:
JwtValidatorException- if any check fails
-