Add required default-context value to VerifiableCredential (#30959)

closes #30958

Signed-off-by: Pascal Knüppel <pascal.knueppel@governikus.de>
This commit is contained in:
Pascal Knüppel 2024-07-11 18:25:11 +02:00 committed by GitHub
parent 96234d42cf
commit 4028ada2a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View file

@ -38,8 +38,16 @@ import java.util.Map;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class VerifiableCredential {
public static final String VC_CONTEXT_V1 = "https://www.w3.org/ns/credentials/v1";
public static final String VC_CONTEXT_V2 = "https://www.w3.org/ns/credentials/v2";
/**
* @context: The value of the @context property MUST be an ordered set where the first item is a URL with the
* value https://www.w3.org/ns/credentials/v2. Subsequent items in the ordered set MUST be composed of any
* combination of URLs and/or objects, where each is processable as a JSON-LD Context.
*/
@JsonProperty("@context")
private List<String> context;
private List<String> context = new ArrayList<>(List.of(VC_CONTEXT_V1));
private List<String> type = new ArrayList<>();
private URI issuer;
private Date issuanceDate;
@ -127,4 +135,4 @@ public class VerifiableCredential {
this.additionalProperties = additionalProperties;
return this;
}
}
}

View file

@ -374,6 +374,9 @@ public class OID4VCIssuerEndpointTest extends OID4VCTest {
assertNotNull("A valid credential string should have been responded", jsonWebToken);
assertNotNull("The credentials should be included at the vc-claim.", jsonWebToken.getOtherClaims().get("vc"));
VerifiableCredential credential = objectMapper.convertValue(jsonWebToken.getOtherClaims().get("vc"), VerifiableCredential.class);
assertNotNull("@context is a required VC property", credential.getContext());
assertEquals(1, credential.getContext().size());
assertEquals(VerifiableCredential.VC_CONTEXT_V1, credential.getContext().get(0));
assertTrue("The static claim should be set.", credential.getCredentialSubject().getClaims().containsKey("VerifiableCredential"));
assertFalse("Only mappers supported for the requested type should have been evaluated.", credential.getCredentialSubject().getClaims().containsKey("AnotherCredentialType"));
}));