Skip to content

Commit 2805a92

Browse files
committed
Add support for capabilities
1 parent b42cc55 commit 2805a92

File tree

3 files changed

+112
-12
lines changed

3 files changed

+112
-12
lines changed

src/main/java/com/danubetech/dataintegrity/DataIntegrityProof.java

Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ public static class Builder<B extends Builder<B>> extends JsonLDObject.Builder<B
4444
private URI verificationMethod;
4545
private String proofPurpose;
4646
private String previousProof;
47+
private URI capability;
48+
private List<URI> capabilityChains;
49+
private String capabilityAction;
4750
private String proofValue;
4851
private String jws;
4952

@@ -57,17 +60,49 @@ public DataIntegrityProof build() {
5760
super.build();
5861

5962
// add JSON-LD properties
60-
if (this.cryptosuite != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_CRYPTOSUITE, this.cryptosuite);
61-
if (this.created != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_CREATED, JsonLDUtils.dateToString(this.created));
62-
if (this.expires != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_EXPIRES, JsonLDUtils.dateToString(this.expires));
63-
if (this.domain != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_DOMAIN, this.domain);
64-
if (this.challenge != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_CHALLENGE, this.challenge);
65-
if (this.nonce != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_NONCE, this.nonce);
66-
if (this.verificationMethod != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_VERIFICATIONMETHOD, JsonLDUtils.uriToString(this.verificationMethod));
67-
if (this.proofPurpose != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_PROOFPURPOSE, this.proofPurpose);
68-
if (this.previousProof != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_PREVIOUSPROOF, this.previousProof);
69-
if (this.proofValue != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_PROOFVALUE, this.proofValue);
70-
if (this.jws != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_JWS, this.jws);
63+
64+
if (this.cryptosuite != null) {
65+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_CRYPTOSUITE, this.cryptosuite);
66+
}
67+
if (this.created != null) {
68+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_CREATED, JsonLDUtils.dateToString(this.created));
69+
}
70+
if (this.expires != null) {
71+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_EXPIRES, JsonLDUtils.dateToString(this.expires));
72+
}
73+
if (this.domain != null) {
74+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_DOMAIN, this.domain);
75+
}
76+
if (this.challenge != null) {
77+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_CHALLENGE, this.challenge);
78+
}
79+
if (this.nonce != null) {
80+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_NONCE, this.nonce);
81+
}
82+
if (this.verificationMethod != null) {
83+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_VERIFICATIONMETHOD, JsonLDUtils.uriToString(this.verificationMethod));
84+
}
85+
if (this.proofPurpose != null) {
86+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_PROOFPURPOSE, this.proofPurpose);
87+
}
88+
if (this.previousProof != null) {
89+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_PREVIOUSPROOF, this.previousProof);
90+
}
91+
if (this.capability != null) {
92+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_CAPABILITY, JsonLDUtils.uriToString(this.capability));
93+
}
94+
if (this.capabilityChains != null) {
95+
JsonLDUtils.jsonLdAddAsJsonArray(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_CAPABILITYCHAIN, this.capabilityChains.stream().map(JsonLDUtils::uriToString).toList());
96+
}
97+
if (this.capabilityAction != null) {
98+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_CAPABILITYACTION, this.capabilityAction);
99+
}
100+
if (this.proofValue != null) {
101+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_PROOFVALUE, this.proofValue);
102+
}
103+
if (this.jws != null) {
104+
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DataIntegrityKeywords.JSONLD_TERM_JWS, this.jws);
105+
}
71106

72107
return (DataIntegrityProof) this.jsonLdObject;
73108
}
@@ -117,6 +152,21 @@ public B previousProof(String previousProof) {
117152
return (B) this;
118153
}
119154

155+
public B capability(URI capability) {
156+
this.capability = capability;
157+
return (B) this;
158+
}
159+
160+
public B capabilityChains(List<URI> capabilityChains) {
161+
this.capabilityChains = capabilityChains;
162+
return (B) this;
163+
}
164+
165+
public B capabilityAction(String capabilityAction) {
166+
this.capabilityAction = capabilityAction;
167+
return (B) this;
168+
}
169+
120170
public B proofValue(String proofValue) {
121171
this.proofValue = proofValue;
122172
return (B) this;
@@ -216,6 +266,19 @@ public String getPreviousProof() {
216266
return JsonLDUtils.jsonLdGetString(this.getJsonObject(), DataIntegrityKeywords.JSONLD_TERM_PREVIOUSPROOF);
217267
}
218268

269+
public URI getCapability() {
270+
return JsonLDUtils.stringToUri(JsonLDUtils.jsonLdGetString(this.getJsonObject(), DataIntegrityKeywords.JSONLD_TERM_CAPABILITY));
271+
}
272+
273+
public List<URI> getCapabilityChains() {
274+
List<Object> jsonArray = JsonLDUtils.jsonLdGetJsonArray(this.getJsonObject(), DataIntegrityKeywords.JSONLD_TERM_CAPABILITYCHAIN);
275+
return jsonArray == null ? null : jsonArray.stream().map(String.class::cast).map(JsonLDUtils::stringToUri).toList();
276+
}
277+
278+
public String getCapabilityAction() {
279+
return JsonLDUtils.jsonLdGetString(this.getJsonObject(), DataIntegrityKeywords.JSONLD_TERM_CAPABILITYACTION);
280+
}
281+
219282
public String getProofValue() {
220283
return JsonLDUtils.jsonLdGetString(this.getJsonObject(), DataIntegrityKeywords.JSONLD_TERM_PROOFVALUE);
221284
}

src/main/java/com/danubetech/dataintegrity/jsonld/DataIntegrityKeywords.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public class DataIntegrityKeywords {
1717
public static final String JSONLD_TERM_VERIFICATIONMETHOD = "verificationMethod";
1818
public static final String JSONLD_TERM_PROOFPURPOSE = "proofPurpose";
1919
public static final String JSONLD_TERM_PREVIOUSPROOF = "previousProof";
20+
public static final String JSONLD_TERM_CAPABILITY = "capability";
21+
public static final String JSONLD_TERM_CAPABILITYCHAIN = "capabilityChain";
22+
public static final String JSONLD_TERM_CAPABILITYACTION = "capabilityAction";
2023
public static final String JSONLD_TERM_PROOFVALUE = "proofValue";
2124
public static final String JSONLD_TERM_JWS = "jws";
2225

src/main/java/com/danubetech/dataintegrity/signer/LdSigner.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.net.URI;
1717
import java.security.GeneralSecurityException;
1818
import java.util.Date;
19+
import java.util.List;
1920
import java.util.Objects;
2021

2122
public abstract class LdSigner<DATAINTEGRITYSUITE extends DataIntegritySuite> {
@@ -35,13 +36,16 @@ public abstract class LdSigner<DATAINTEGRITYSUITE extends DataIntegritySuite> {
3536
private URI verificationMethod;
3637
private String proofPurpose;
3738
private String previousProof;
39+
private URI capability;
40+
private List<URI> capabilityChains;
41+
private String capabilityAction;
3842

3943
protected LdSigner(DATAINTEGRITYSUITE dataIntegritySuite, ByteSigner signer) {
4044
this.dataIntegritySuite = dataIntegritySuite;
4145
this.signer = signer;
4246
}
4347

44-
protected LdSigner(DATAINTEGRITYSUITE dataIntegritySuite, ByteSigner signer, String cryptosuite, Date created, Date expires, String domain, String challenge, String nonce, URI verificationMethod, String proofPurpose, String previousProof) {
48+
protected LdSigner(DATAINTEGRITYSUITE dataIntegritySuite, ByteSigner signer, String cryptosuite, Date created, Date expires, String domain, String challenge, String nonce, URI verificationMethod, String proofPurpose, String previousProof, URI capability, List<URI> capabilityChains, String capabilityAction) {
4549
this.dataIntegritySuite = dataIntegritySuite;
4650
this.signer = signer;
4751
this.cryptosuite = cryptosuite;
@@ -52,6 +56,9 @@ protected LdSigner(DATAINTEGRITYSUITE dataIntegritySuite, ByteSigner signer, Str
5256
this.nonce = nonce;
5357
this.verificationMethod = verificationMethod;
5458
this.proofPurpose = proofPurpose;
59+
this.capability = capability;
60+
this.capabilityChains = capabilityChains;
61+
this.capabilityAction = capabilityAction;
5562
}
5663

5764
/**
@@ -89,6 +96,9 @@ public DataIntegrityProof sign(JsonLDObject jsonLdObject, boolean addToJsonLdObj
8996
.verificationMethod(this.getVerificationMethod())
9097
.proofPurpose(this.getProofPurpose())
9198
.previousProof(this.getPreviousProof())
99+
.capability(this.getCapability())
100+
.capabilityChains(this.getCapabilityChains())
101+
.capabilityAction(this.getCapabilityAction())
92102
.build();
93103
if (log.isDebugEnabled()) log.debug("Constructed data integrity proof: {}", dataIntegrityProof);
94104

@@ -246,4 +256,28 @@ public String getPreviousProof() {
246256
public void setPreviousProof(String previousProof) {
247257
this.previousProof = previousProof;
248258
}
259+
260+
public URI getCapability() {
261+
return capability;
262+
}
263+
264+
public void setCapability(URI capability) {
265+
this.capability = capability;
266+
}
267+
268+
public List<URI> getCapabilityChains() {
269+
return capabilityChains;
270+
}
271+
272+
public void setCapabilityChains(List<URI> capabilityChains) {
273+
this.capabilityChains = capabilityChains;
274+
}
275+
276+
public String getCapabilityAction() {
277+
return capabilityAction;
278+
}
279+
280+
public void setCapabilityAction(String capabilityAction) {
281+
this.capabilityAction = capabilityAction;
282+
}
249283
}

0 commit comments

Comments
 (0)