Skip to content

Commit 86153de

Browse files
committed
feat: Support lists of JSON-LD objects
1 parent 4ca2f62 commit 86153de

File tree

11 files changed

+391
-99
lines changed

11 files changed

+391
-99
lines changed

pom.xml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,25 @@
158158
<dependency>
159159
<groupId>org.junit.jupiter</groupId>
160160
<artifactId>junit-jupiter-engine</artifactId>
161-
<version>5.11.0</version>
161+
<version>5.11.4</version>
162162
<scope>test</scope>
163163
</dependency>
164164
<dependency>
165165
<groupId>org.junit.jupiter</groupId>
166166
<artifactId>junit-jupiter</artifactId>
167-
<version>5.11.0</version>
167+
<version>5.11.4</version>
168168
<scope>test</scope>
169169
</dependency>
170170
<dependency>
171171
<groupId>org.mockito</groupId>
172172
<artifactId>mockito-core</artifactId>
173-
<version>5.13.0</version>
173+
<version>5.14.2</version>
174174
<scope>test</scope>
175175
</dependency>
176176
<dependency>
177177
<groupId>org.mockito</groupId>
178178
<artifactId>mockito-junit-jupiter</artifactId>
179-
<version>5.13.0</version>
179+
<version>5.14.2</version>
180180
<scope>test</scope>
181181
</dependency>
182182
<dependency>
@@ -194,23 +194,28 @@
194194
<dependency>
195195
<groupId>com.google.crypto.tink</groupId>
196196
<artifactId>tink</artifactId>
197-
<version>1.15.0</version>
197+
<version>1.16.0</version>
198198
<scope>test</scope>
199199
</dependency>
200+
<dependency>
201+
<groupId>decentralized-identity</groupId>
202+
<artifactId>jsonld-common-java</artifactId>
203+
<version>1.12.0</version>
204+
</dependency>
200205
<dependency>
201206
<groupId>info.weboftrust</groupId>
202207
<artifactId>ld-signatures-java</artifactId>
203-
<version>1.10.0</version>
208+
<version>1.11.0</version>
204209
</dependency>
205210
<dependency>
206211
<groupId>com.nimbusds</groupId>
207212
<artifactId>nimbus-jose-jwt</artifactId>
208-
<version>9.41.1</version>
213+
<version>9.48</version>
209214
</dependency>
210215
<dependency>
211216
<groupId>com.fasterxml.jackson.core</groupId>
212217
<artifactId>jackson-databind</artifactId>
213-
<version>2.17.2</version>
218+
<version>2.18.2</version>
214219
</dependency>
215220
</dependencies>
216221

src/main/java/com/danubetech/verifiablecredentials/CredentialSubject.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.Reader;
1414
import java.net.URI;
1515
import java.util.LinkedHashMap;
16+
import java.util.List;
1617
import java.util.Map;
1718

1819
public class CredentialSubject extends JsonLDObject {
@@ -90,6 +91,10 @@ public static CredentialSubject getFromJsonLDObject(JsonLDObject jsonLdObject) {
9091
return JsonLDObject.getFromJsonLDObject(CredentialSubject.class, jsonLdObject);
9192
}
9293

94+
public static List<CredentialSubject> getFromJsonLDObjectAsList(JsonLDObject jsonLdObject) {
95+
return JsonLDObject.getFromJsonLDObjectAsList(CredentialSubject.class, jsonLdObject);
96+
}
97+
9398
public static void removeFromJsonLdObject(JsonLDObject jsonLdObject) {
9499
JsonLDObject.removeFromJsonLdObject(CredentialSubject.class, jsonLdObject);
95100
}

src/main/java/com/danubetech/verifiablecredentials/VerifiableCredential.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.io.Reader;
1313
import java.net.URI;
1414
import java.util.Date;
15+
import java.util.List;
1516
import java.util.Map;
1617

1718
public class VerifiableCredential extends JsonLDObject {
@@ -128,6 +129,10 @@ public static VerifiableCredential getFromJsonLDObject(JsonLDObject jsonLdObject
128129
return JsonLDObject.getFromJsonLDObject(VerifiableCredential.class, jsonLdObject);
129130
}
130131

132+
public static List<VerifiableCredential> getFromJsonLDObjectAsList(JsonLDObject jsonLdObject) {
133+
return JsonLDObject.getFromJsonLDObjectAsList(VerifiableCredential.class, jsonLdObject);
134+
}
135+
131136
public static void removeFromJsonLdObject(JsonLDObject jsonLdObject) {
132137
JsonLDObject.removeFromJsonLdObject(VerifiableCredential.class, jsonLdObject);
133138
}
@@ -156,6 +161,10 @@ public LdProof getLdProof() {
156161
return LdProof.getFromJsonLDObject(this);
157162
}
158163

164+
public List<LdProof> getLdProofAsList() {
165+
return LdProof.getFromJsonLDObjectAsList(this);
166+
}
167+
159168
public CredentialStatus getCredentialStatus() {
160169
return CredentialStatus.getFromJsonLDObject(this);
161170
}

src/main/java/com/danubetech/verifiablecredentials/VerifiableCredentialV2.java

Lines changed: 102 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515

1616
import java.io.Reader;
1717
import java.net.URI;
18-
import java.util.Date;
19-
import java.util.List;
20-
import java.util.Map;
21-
import java.util.Set;
18+
import java.util.*;
2219

2320
public class VerifiableCredentialV2 extends JsonLDObject {
2421

@@ -46,17 +43,17 @@ public static class Builder<B extends Builder<B>> extends JsonLDObject.Builder<B
4643
private Date validFrom;
4744
private Date validUntil;
4845
private CredentialSubject credentialSubject;
49-
private Object credentialStatus;
46+
private List<CredentialStatus> credentialStatus;
5047
private String name;
5148
private String description;
52-
private LdProof ldProof;
49+
private List<LdProof> ldProof;
5350

5451
//extensions
5552

5653
private List<CredentialSchema> credentialSchema;
57-
private Set<Evidence> evidence;
58-
private TermsOfUse termsOfUse;
59-
private RefreshService refreshService;
54+
private List<Evidence> evidence;
55+
private List<TermsOfUse> termsOfUse;
56+
private List<RefreshService> refreshService;
6057

6158
public Builder(VerifiableCredentialV2 jsonLdObject) {
6259
super(jsonLdObject);
@@ -76,16 +73,16 @@ public VerifiableCredentialV2 build() {
7673
if (this.validFrom != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_VALIDFROM, JsonLDUtils.dateToString(this.validFrom));
7774
if (this.validUntil != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_VALIDUNTIL, JsonLDUtils.dateToString(this.validUntil));
7875
if (this.credentialSubject != null) this.credentialSubject.addToJsonLDObject(this.jsonLdObject);
79-
if (this.credentialStatus != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_CREDENTIALSTATUS, this.credentialStatus);
80-
if(this.name != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_NAME, this.name);
81-
if(this.description != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_NAME, this.description);
82-
if (this.ldProof != null) this.ldProof.addToJsonLDObject(this.jsonLdObject);
76+
if (this.credentialStatus != null) this.credentialStatus.forEach(credentialStatus -> credentialStatus.addToJsonLDObject(this.jsonLdObject));
77+
if (this.name != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_NAME, this.name);
78+
if (this.description != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_NAME, this.description);
79+
if (this.ldProof != null) this.ldProof.forEach(ldProof -> ldProof.addToJsonLDObject(this.jsonLdObject));
8380

84-
//add extensions
85-
if (this.credentialSchema != null) JsonLDUtils.jsonLdAddAsJsonArray(this.jsonLdObject,VerifiableCredentialKeywords.JSONLD_TERM_CREDENTIALSCHEMA, credentialSchema);
86-
if (this.termsOfUse != null) this.termsOfUse.addToJsonLDObject(this.jsonLdObject);
87-
if (this.evidence != null && !this.evidence.isEmpty()) JsonLDUtils.jsonLdAdd(this.jsonLdObject, VerifiableCredentialKeywords.JSONLD_TERM_EVIDENCE, this.evidence);
88-
if (this.refreshService != null) this.refreshService.addToJsonLDObject(this.jsonLdObject);
81+
// add extensions
82+
if (this.credentialSchema != null) this.credentialSchema.forEach(credentialSchema -> credentialSchema.addToJsonLDObject(this.jsonLdObject));
83+
if (this.evidence != null) this.evidence.forEach(evidence -> evidence.addToJsonLDObject(this.jsonLdObject));
84+
if (this.termsOfUse != null) this.termsOfUse.forEach(termsOfUse -> termsOfUse.addToJsonLDObject(this.jsonLdObject));
85+
if (this.refreshService != null) this.refreshService.forEach(refreshService -> refreshService.addToJsonLDObject(this.jsonLdObject));
8986

9087
return (VerifiableCredentialV2) this.jsonLdObject;
9188
}
@@ -116,17 +113,14 @@ public B credentialSubject(CredentialSubject credentialSubject) {
116113
}
117114

118115
public B credentialStatus(CredentialStatus credentialStatus) {
119-
this.credentialStatus = credentialStatus;
116+
if (this.credentialStatus == null) this.credentialStatus = new ArrayList<>();
117+
this.credentialStatus.add(credentialStatus);
120118
return (B) this;
121119
}
122120

123-
public B credentialStatus(List<CredentialStatus> credentialStatus) {
124-
this.credentialStatus = credentialStatus;
125-
return (B) this;
126-
}
127-
128-
public B ldProof(LdProof ldProof) {
129-
this.ldProof = ldProof;
121+
public B credentialStatus(Collection<CredentialStatus> credentialStatus) {
122+
if (this.credentialStatus == null) this.credentialStatus = new ArrayList<>();
123+
this.credentialStatus.addAll(credentialStatus);
130124
return (B) this;
131125
}
132126

@@ -140,22 +134,63 @@ public B description(String description) {
140134
return (B) this;
141135
}
142136

143-
public B evidence(Set<Evidence> evidence) {
144-
this.evidence = evidence;
137+
public B ldProof(LdProof ldProof) {
138+
if (this.ldProof == null) this.ldProof = new ArrayList<>();
139+
this.ldProof.add(ldProof);
140+
return (B) this;
141+
}
142+
143+
public B ldProof(Collection<LdProof> ldProof) {
144+
if (this.ldProof == null) this.ldProof = new ArrayList<>();
145+
this.ldProof.addAll(ldProof);
146+
return (B) this;
147+
}
148+
149+
public B credentialSchema(CredentialSchema credentialSchema) {
150+
if (this.credentialSchema == null) this.credentialSchema = new ArrayList<>();
151+
this.credentialSchema.add(credentialSchema);
145152
return (B) this;
146153
}
147-
public B credentialSchema(List<CredentialSchema> credentialSchema) {
148-
this.credentialSchema = credentialSchema;
154+
155+
public B credentialSchema(Collection<CredentialSchema> credentialSchema) {
156+
if (this.credentialSchema == null) this.credentialSchema = new ArrayList<>();
157+
this.credentialSchema.addAll(credentialSchema);
158+
return (B) this;
159+
}
160+
161+
public B evidence(Evidence evidence) {
162+
if (this.evidence == null) this.evidence = new ArrayList<>();
163+
this.evidence.add(evidence);
164+
return (B) this;
165+
}
166+
167+
public B evidence(Collection<Evidence> evidence) {
168+
if (this.evidence == null) this.evidence = new ArrayList<>();
169+
this.evidence.addAll(evidence);
149170
return (B) this;
150171
}
151172

152173
public B termsOfUse(TermsOfUse termsOfUse) {
153-
this.termsOfUse = termsOfUse;
174+
if (this.termsOfUse == null) this.termsOfUse = new ArrayList<>();
175+
this.termsOfUse.add(termsOfUse);
176+
return (B) this;
177+
}
178+
179+
public B termsOfUse(Collection<TermsOfUse> termsOfUse) {
180+
if (this.termsOfUse == null) this.termsOfUse = new ArrayList<>();
181+
this.termsOfUse.addAll(termsOfUse);
154182
return (B) this;
155183
}
156184

157185
public B refreshService(RefreshService refreshService) {
158-
this.refreshService = refreshService;
186+
if (this.refreshService == null) this.refreshService = new ArrayList<>();
187+
this.refreshService.add(refreshService);
188+
return (B) this;
189+
}
190+
191+
public B refreshService(Collection<RefreshService> refreshService) {
192+
if (this.refreshService == null) this.refreshService = new ArrayList<>();
193+
this.refreshService.addAll(refreshService);
159194
return (B) this;
160195
}
161196
}
@@ -190,6 +225,10 @@ public static VerifiableCredentialV2 getFromJsonLDObject(JsonLDObject jsonLdObje
190225
return JsonLDObject.getFromJsonLDObject(VerifiableCredentialV2.class, jsonLdObject);
191226
}
192227

228+
public static List<VerifiableCredentialV2> getFromJsonLDObjectAsList(JsonLDObject jsonLdObject) {
229+
return JsonLDObject.getFromJsonLDObjectAsList(VerifiableCredentialV2.class, jsonLdObject);
230+
}
231+
193232
public static void removeFromJsonLdObject(JsonLDObject jsonLdObject) {
194233
JsonLDObject.removeFromJsonLdObject(VerifiableCredentialV2.class, jsonLdObject);
195234
}
@@ -203,9 +242,7 @@ public Object getIssuer() {
203242
}
204243

205244
public URI getIssuerUri() {
206-
207245
Object issuer = JsonLDUtils.jsonLdGetJsonValue(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_ISSUER);
208-
209246
return (issuer instanceof String) ? URI.create(issuer.toString()) : URI.create((((Map<String,Object>)issuer).get(VerifiableCredentialKeywords.JSONLD_TERM_ISSUER)).toString());
210247
}
211248

@@ -221,16 +258,14 @@ public CredentialSubject getCredentialSubject() {
221258
return CredentialSubject.getFromJsonLDObject(this);
222259
}
223260

224-
public LdProof getLdProof() {
225-
return LdProof.getFromJsonLDObject(this);
261+
public CredentialStatus getCredentialStatus() {
262+
return CredentialStatus.getFromJsonLDObject(this);
226263
}
227264

228-
//The object can be either CredentialStatus object or list of CredentialStatus objects
229-
public Object getCredentialStatus() {
230-
return CredentialStatus.getFromJsonLDObject(this);
265+
public List<CredentialStatus> getCredentialStatusAsList() {
266+
return CredentialStatus.getFromJsonLDObjectAsList(this);
231267
}
232268

233-
234269
public String getName(){
235270
return JsonLDUtils.jsonLdGetString(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_NAME);
236271
}
@@ -239,21 +274,43 @@ public String getDescription(){
239274
return JsonLDUtils.jsonLdGetString(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_DESCRIPTION);
240275
}
241276

242-
public Set<Evidence> getEvidence() {
243-
return (Set<Evidence>) JsonLDUtils.jsonLdGetJsonValue(this.getJsonObject(),VerifiableCredentialKeywords.JSONLD_TERM_EVIDENCE);
277+
public LdProof getLdProof() {
278+
return LdProof.getFromJsonLDObject(this);
279+
}
280+
281+
public List<LdProof> getLdProofAsList() {
282+
return LdProof.getFromJsonLDObjectAsList(this);
283+
}
284+
285+
public CredentialSchema getCredentialSchema() {
286+
return CredentialSchema.getFromJsonLDObject(this);
244287
}
245288

246-
public List<CredentialSchema> getCredentialSchema() {
247-
return (List<CredentialSchema>) JsonLDUtils.jsonLdGetJsonValue(this.getJsonObject(), VerifiableCredentialKeywords.JSONLD_TERM_CREDENTIALSCHEMA);
289+
public List<CredentialSchema> getCredentialSchemaAsList() {
290+
return CredentialSchema.getFromJsonLDObjectAsList(this);
291+
}
292+
293+
public Evidence getEvidence() {
294+
return Evidence.getFromJsonLDObject(this);
295+
}
296+
297+
public List<Evidence> getEvidenceAsList() {
298+
return Evidence.getFromJsonLDObjectAsList(this);
248299
}
249300

250301
public TermsOfUse getTermsOfUse() {
251302
return TermsOfUse.getFromJsonLDObject(this);
252303
}
253304

305+
public List<TermsOfUse> getTermsOfUseAsList() {
306+
return TermsOfUse.getFromJsonLDObjectAsList(this);
307+
}
308+
254309
public RefreshService getRefreshService() {
255310
return RefreshService.getFromJsonLDObject(this);
256311
}
257312

258-
313+
public List<RefreshService> getRefreshServiceAsList() {
314+
return RefreshService.getFromJsonLDObjectAsList(this);
315+
}
259316
}

0 commit comments

Comments
 (0)