verifiable-credentials-java
verifiable-credentials-java copied to clipboard
Support multiple subjects in a Verifiable Credential
Implementing #32, this change adds support for an array of subjects in the credentialSubject field of a Verifiable Credential to improve conformance with the Verifiable Credential Data Model v1.1, Section 4.4.
Behavior is maintained for credentials with a single subject object.
Implementation
Because the credentialSubject field may be an object or an array, I've added support for a list of credential subjects that is populated with however many subjects are in the credential.
If there is a single subject, the new VerifiableCredential::getCredentialSubjects() will return an array of size 1. The subject in the array will match the subject returned by VerifiableCredential::getCredentialSubject().
If there are multiple subjects, the new VerifiableCredential::getCredentialSubjects() will return an array with all the subjects in the same order as the source JSON-LD. The first subject will be returned by VerifiableCredential::getCredentialSubject().
Note that conversion to a JWT is unsupported for a credential with multiple subjects, as indicated by the Verifiable Credential Data Model v1.1, Section 6.3.1, heading JWT Encoding.
I've added unit tests for verifying, signing, and verifiable presentations for credentials with multiple subjects.
@peacekeeper or @azuzi, let me know if you need any more information about this PR, or if there is someone else who should be reviewing it when you get a chance. Thank you!
@provTheodoreNewell
The credentialSubject can be Json Array or Json Object as per the spec. Therefore, supporting both type of object will be the suitable approach.
I think this has been addressed in https://github.com/danubetech/verifiable-credentials-java/commit/b91065bcb40ded543ea0d9e67fc1f383ae9e05d1