diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java index b9d67e0..193a3f0 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java @@ -1,6 +1,6 @@ package org.oneedtech.inspect.vc; -import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -9,7 +9,6 @@ import org.oneedtech.inspect.schema.SchemaKey; import org.oneedtech.inspect.util.resource.Resource; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; @@ -34,6 +33,11 @@ public class Assertion extends Credential { return assertionType.toString(); } + @Override + public List getContext() { + return List.of("https://w3id.org/openbadges/v2"); + } + @Override public String toString() { return MoreObjects.toStringHelper(this) diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Credential.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Credential.java index 82ba4e2..3d74a87 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Credential.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Credential.java @@ -59,6 +59,8 @@ public abstract class Credential extends GeneratedObject { public abstract String getCredentialType(); + public abstract List getContext(); + @Override public String toString() { return MoreObjects.toStringHelper(this) diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java index b388379..60f48a0 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/VerifiableCredential.java @@ -6,7 +6,9 @@ import static org.oneedtech.inspect.vc.VerifiableCredential.Type.EndorsementCred import static org.oneedtech.inspect.vc.VerifiableCredential.Type.VerifiablePresentation; import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import org.oneedtech.inspect.schema.Catalog; @@ -37,6 +39,15 @@ public class VerifiableCredential extends Credential { return credentialType.toString(); } + @Override + public List getContext() { + return values.get(values.keySet() + .stream() + .filter(s->s.contains(credentialType)) + .findFirst() + .orElseThrow(()-> new IllegalArgumentException(credentialType.name() + " not recognized"))); + } + public ProofType getProofType() { return jwt == null ? ProofType.EMBEDDED : ProofType.EXTERNAL; } @@ -48,6 +59,19 @@ public class VerifiableCredential extends Credential { .put(EndorsementCredential, Catalog.OB_30_ENDORSEMENTCREDENTIAL_JSON) .build(); + private static final Map, List> values = new ImmutableMap.Builder, List>() + .put(Set.of(Type.OpenBadgeCredential, AchievementCredential, EndorsementCredential), + List.of("https://www.w3.org/2018/credentials/v1", + //"https://purl.imsglobal.org/spec/ob/v3p0/context.json")) //dev legacy + "https://purl.imsglobal.org/spec/ob/v3p0/context.json")) + .put(Set.of(ClrCredential), + List.of("https://www.w3.org/2018/credentials/v1", + // "https://dc.imsglobal.org/draft/clr/v2p0/context", //dev legacy + // "https://purl.imsglobal.org/spec/ob/v3p0/context.json")) //dev legacy + "https://purl.imsglobal.org/spec/clr/v2p0/context.json", + "https://purl.imsglobal.org/spec/ob/v3p0/context.json")) + + .build(); public enum Type { AchievementCredential, @@ -104,5 +128,4 @@ public class VerifiableCredential extends Credential { } public static final String ID = VerifiableCredential.class.getCanonicalName(); - }