Skip to content

Commit

Permalink
fix: Better support for JWT VC inside JSON-LD VP.
Browse files Browse the repository at this point in the history
  • Loading branch information
peacekeeper committed Oct 3, 2023
1 parent 29f4802 commit b8222a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.io.Reader;
import java.net.URI;
import java.util.List;
import java.util.Map;

public class VerifiablePresentation extends JsonLDObject {
Expand Down Expand Up @@ -146,7 +147,23 @@ public URI getHolder() {
}

public VerifiableCredential getVerifiableCredential() {
return VerifiableCredential.getFromJsonLDObject(this);
Object verifiableCredentialObject = this.getJsonObject().get(VerifiableCredentialKeywords.JSONLD_TERM_VERIFIABLECREDENTIAL);
if ((verifiableCredentialObject instanceof List && ! ((List) verifiableCredentialObject).isEmpty() && ((List) verifiableCredentialObject).get(0) instanceof Map)) {
return VerifiableCredential.getFromJsonLDObject(this);
} else if (verifiableCredentialObject instanceof Map) {
return VerifiableCredential.getFromJsonLDObject(this);
}
return null;
}

public String getJwtVerifiableCredentialString() {
Object verifiableCredentialObject = this.getJsonObject().get(VerifiableCredentialKeywords.JSONLD_TERM_VERIFIABLECREDENTIAL);
if (verifiableCredentialObject instanceof List && ! ((List) verifiableCredentialObject).isEmpty() && ((List) verifiableCredentialObject).get(0) instanceof String) {
return (String) ((List) verifiableCredentialObject).get(0);
} else if (verifiableCredentialObject instanceof String) {
return (String) verifiableCredentialObject;
}
return null;
}

public LdProof getLdProof() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ public static void validate(VerifiablePresentation verifiablePresentation) throw

validateRun(() -> { validateTrue(verifiablePresentation.getTypes().size() > 0); }, "Bad or missing 'type'.");
validateRun(() -> { validateTrue(verifiablePresentation.getTypes().contains(VerifiablePresentation.DEFAULT_JSONLD_TYPES[0])); }, "type must contain VerifiablePresentation: " + verifiablePresentation.getTypes());
validateRun(() -> { validateTrue(verifiablePresentation.getVerifiableCredential() != null); }, "Bad or missing 'verifiableCredential'.");
validateRun(() -> { validateTrue(verifiablePresentation.getVerifiableCredential() != null || verifiablePresentation.getJwtVerifiableCredentialString() != null); }, "Bad or missing 'verifiableCredential'.");
}
}

0 comments on commit b8222a6

Please sign in to comment.