-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Hello,
The current implementation of at.asitplus.wallet.lib.data.VerifiableCredential uses @Polymorphic annotation on the credentialSubject property:
@Polymorphic
@SerialName("credentialSubject")
val credentialSubject: CredentialSubjectThis approach assumes that the serialization mechanism can discriminate between different CredentialSubject implementations, typically using a type field as a class discriminator. However, according to the W3C Verifiable Credentials Data Model 1.1 specification, there is no guarantee that a type field will be present in the credentialSubject object.
Problem
The polymorphic serialization strategy currently employed may fail or behave unexpectedly when:
- The
credentialSubjectdoes not contain atypefield - The
credentialSubjectstructure varies significantly between different credential types - Interoperability with credentials from external issuers that don't follow the assumed discriminator pattern
This creates a potential incompatibility with valid W3C Verifiable Credentials that don't include the expected discriminator field.
Proposed Solution
Replace the @Polymorphic annotation and CredentialSubject type with JsonElement to handle the credentialSubject as a flexible JSON structure:
@SerialName("credentialSubject")
val credentialSubject: JsonElementBenefits
- ✅ Spec compliance: Aligns with W3C VC Data Model 1.1 specification
- ✅ Flexibility: Handles any valid JSON structure for
credentialSubject - ✅ Interoperability: Works with credentials from any compliant issuer
- ✅ No assumptions: Doesn't require a specific discriminator field
Impact
This change would affect:
- Any code that currently expects
credentialSubjectto be a specificCredentialSubjectsubtype - Serialization/deserialization logic that relies on polymorphic behavior
- Type-safe access to credential subject properties (would require manual JSON parsing)
I've tested it locally, the openid4vci and openid4vp flows still works after those modifications. I can propose a pull request to fix this.
Best regards