danubetech / verifiable-credentials-java

Java implementation of Verifiable Credentials
Apache License 2.0
31 stars 20 forks source link

Add support for multiple Verifiable Credentials in a Verifiable Presentation #48

Open robertschubert opened 4 months ago

robertschubert commented 4 months ago

This issue strongly relates to this issue

The current implementation assumes to have one Verifiable Credential inside a Verifiable Presentation. The Builder component inside the VerifiablePresentation class has an attribute verifiableCredential instead of a List.

Moreover the getVerifiableCredential() method will fail if the presentation has more than one `` Verifiable Credential:

    public VerifiableCredential getVerifiableCredential() {
        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;
    }

The code produces an error when we are in the case of the verifiableCredentialObject instanceof List

The class VerifiableCredential should have another method like this to be called in the List case: public static Set<VerifiableCredential> getFromJsonLDObject(JsonLDObject jsonLdObject) which iterates over the List.

Are you planning to merge the PR mentioned in the other issue? Are you planning to support multiple VCs in a VP?