Class SdJwtParser

java.lang.Object
ch.admin.bj.swiyu.sdjwtvalidator.SdJwtParser

public final class SdJwtParser extends Object
Parses the compact serialization format of an SD-JWT.

An SD-JWT has the following structure (RFC 9901 ยง4):

   <Issuer-signed JWT>~<Disclosure 1>~...~<Disclosure N>~
 
The trailing ~ after the last Disclosure is mandatory.
  • Method Details

    • extractIssuerSignedJwt

      public static String extractIssuerSignedJwt(String sdJwt)
      Extracts the Issuer-Signed JWT (the first segment before the first ~).
      Parameters:
      sdJwt - the full SD-JWT string; must not be null or blank
      Returns:
      the compact serialized Issuer-Signed JWT
      Throws:
      JwtValidatorException - if the input is null, blank, or does not contain ~
    • extractDisclosures

      public static List<String> extractDisclosures(String sdJwt)
      Extracts all Disclosure strings from the SD-JWT.

      Disclosures are the ~-separated segments between the Issuer-Signed JWT. Empty segments are excluded.

      Parameters:
      sdJwt - the full SD-JWT string; must not be null or blank
      Returns:
      an immutable list of base64url-encoded Disclosure strings (may be empty)
    • decodeDisclosure

      public static String decodeDisclosure(String disclosure)
      Decodes a single base64url-encoded Disclosure into its raw JSON string.
      Parameters:
      disclosure - the base64url-encoded Disclosure segment
      Returns:
      the decoded JSON string (e.g. ["salt","given_name","Max"])
      Throws:
      JwtValidatorException - if decoding fails