Skip to content

Commit 02a185b

Browse files
committed
Add experimental notarization/revocation features.
Signed-off-by: Markus Sabadello <[email protected]>
1 parent e3ab4c5 commit 02a185b

File tree

2 files changed

+317
-0
lines changed

2 files changed

+317
-0
lines changed
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
package com.danubetech.verifiablecredentials.jsonld.credentialstatus;
2+
3+
import java.util.ArrayList;
4+
import java.util.LinkedHashMap;
5+
import java.util.List;
6+
7+
import com.github.jsonldjava.core.JsonLdConsts;
8+
9+
public class RevocationQuery2020Status {
10+
11+
public static final LinkedHashMap<String, Object> JSONLD_CONTEXT;
12+
13+
public static final String JSONLD_TERM_CREDENTIALSTATUS = "credentialStatus";
14+
public static final String JSONLD_TERM_TYPE = "type";
15+
public static final String JSONLD_TERM_REVOCATIONQUERY2020STATUS = "RevocationQuery2020Status";
16+
public static final String JSONLD_TERM_CREDENTIALREFERENCE = "credentialReference";
17+
public static final String JSONLD_TERM_REVOCATIONSERVICE = "revocationService";
18+
19+
private final LinkedHashMap<String, Object> jsonLdCredentialStatusObject;
20+
21+
static {
22+
23+
JSONLD_CONTEXT = new LinkedHashMap<String, Object> ();
24+
JSONLD_CONTEXT.put(JSONLD_TERM_REVOCATIONQUERY2020STATUS, "https://danubetech.com/schema/2020/proofs/v1#RevocationQuery2020Status");
25+
JSONLD_CONTEXT.put(JSONLD_TERM_CREDENTIALREFERENCE, "https://danubetech.com/schema/2020/proofs/v1#credentialReference");
26+
JSONLD_CONTEXT.put(JSONLD_TERM_REVOCATIONSERVICE, "https://danubetech.com/schema/2020/proofs/v1#revocationService");
27+
}
28+
29+
protected RevocationQuery2020Status(LinkedHashMap<String, Object> jsonLdCredentialStatusObject) {
30+
31+
this.jsonLdCredentialStatusObject = jsonLdCredentialStatusObject;
32+
}
33+
34+
public RevocationQuery2020Status() {
35+
36+
this.jsonLdCredentialStatusObject = new LinkedHashMap<String, Object> ();
37+
}
38+
39+
public static RevocationQuery2020Status fromJsonLdObject(LinkedHashMap<String, Object> jsonLdCredentialStatusObject) {
40+
41+
return new RevocationQuery2020Status(jsonLdCredentialStatusObject);
42+
}
43+
44+
public LinkedHashMap<String, Object> getJsonLdCredentialStatusObject() {
45+
46+
return this.jsonLdCredentialStatusObject;
47+
}
48+
49+
@SuppressWarnings("unchecked")
50+
public static void addContextToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) {
51+
52+
Object context = jsonLdObject.get(JsonLdConsts.CONTEXT);
53+
ArrayList<Object> contexts;
54+
55+
// add as single value
56+
57+
if (context == null) {
58+
59+
jsonLdObject.put(JsonLdConsts.CONTEXT, JSONLD_CONTEXT);
60+
return;
61+
}
62+
63+
// add as array member
64+
65+
if (context instanceof ArrayList<?>) {
66+
67+
contexts = (ArrayList<Object>) context;
68+
} else {
69+
70+
contexts = new ArrayList<Object> ();
71+
contexts.add(context);
72+
jsonLdObject.put(JsonLdConsts.CONTEXT, contexts);
73+
}
74+
75+
if (! contexts.contains(JSONLD_CONTEXT)) {
76+
77+
contexts.add(JSONLD_CONTEXT);
78+
}
79+
}
80+
81+
public static void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject, LinkedHashMap<String, Object> jsonLdCredentialStatusObject) {
82+
83+
Object credentialStatus = jsonLdObject.get(JSONLD_TERM_CREDENTIALSTATUS);
84+
85+
// add as single value
86+
87+
if (credentialStatus == null) {
88+
89+
jsonLdObject.put(JSONLD_TERM_CREDENTIALSTATUS, jsonLdCredentialStatusObject);
90+
return;
91+
}
92+
93+
// add as array member
94+
95+
ArrayList<Object> proofs;
96+
97+
if (credentialStatus instanceof ArrayList<?>) {
98+
99+
proofs = (ArrayList<Object>) credentialStatus;
100+
} else {
101+
102+
proofs = new ArrayList<Object> ();
103+
proofs.add(credentialStatus);
104+
jsonLdObject.put(JSONLD_TERM_CREDENTIALSTATUS, jsonLdCredentialStatusObject);
105+
}
106+
107+
if (! proofs.contains(jsonLdCredentialStatusObject)) {
108+
109+
proofs.add(jsonLdCredentialStatusObject);
110+
}
111+
}
112+
113+
public void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject, boolean addContext) {
114+
115+
if (addContext) addContextToJsonLdObject(jsonLdObject);
116+
117+
addToJsonLdObject(jsonLdObject, this.getJsonLdCredentialStatusObject());
118+
}
119+
120+
public void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) {
121+
122+
this.addToJsonLdObject(jsonLdObject, false);
123+
}
124+
125+
public static void removeFromJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) {
126+
127+
jsonLdObject.remove(JSONLD_TERM_CREDENTIALSTATUS);
128+
}
129+
130+
@SuppressWarnings("unchecked")
131+
public static RevocationQuery2020Status getFromJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) {
132+
133+
Object jsonLdProofObjectEntry = jsonLdObject.get(JSONLD_TERM_CREDENTIALSTATUS);
134+
135+
if (jsonLdProofObjectEntry instanceof List) {
136+
137+
List<LinkedHashMap<String, Object>> jsonLdProofObjectList = (List<LinkedHashMap<String, Object>>) jsonLdProofObjectEntry;
138+
139+
for (LinkedHashMap<String, Object> jsonLdProofObject : jsonLdProofObjectList) {
140+
141+
if (JSONLD_TERM_REVOCATIONQUERY2020STATUS.equals(jsonLdProofObject.get("type"))) return RevocationQuery2020Status.fromJsonLdObject(jsonLdProofObject);
142+
}
143+
} else if (jsonLdProofObjectEntry instanceof LinkedHashMap) {
144+
145+
LinkedHashMap<String, Object> jsonLdProofObject = (LinkedHashMap<String, Object>) jsonLdProofObjectEntry;
146+
147+
if (JSONLD_TERM_REVOCATIONQUERY2020STATUS.equals(jsonLdProofObject.get("type"))) return RevocationQuery2020Status.fromJsonLdObject(jsonLdProofObject);
148+
}
149+
150+
return null;
151+
}
152+
153+
public String getType() {
154+
return (String) this.jsonLdCredentialStatusObject.get(JSONLD_TERM_TYPE);
155+
}
156+
157+
public void setType(String type) {
158+
this.jsonLdCredentialStatusObject.put(JSONLD_TERM_TYPE, type);
159+
}
160+
161+
public String getCredentialReference() {
162+
return (String) this.jsonLdCredentialStatusObject.get(JSONLD_TERM_CREDENTIALREFERENCE);
163+
}
164+
165+
public void setCredentialReference(String credentialReference) {
166+
this.jsonLdCredentialStatusObject.put(JSONLD_TERM_CREDENTIALREFERENCE, credentialReference);
167+
}
168+
169+
public String getRevocationService() {
170+
return (String) this.jsonLdCredentialStatusObject.get(JSONLD_TERM_REVOCATIONSERVICE);
171+
}
172+
173+
public void setRevocationService(String revocationService) {
174+
this.jsonLdCredentialStatusObject.put(JSONLD_TERM_REVOCATIONSERVICE, revocationService);
175+
}
176+
177+
@Override
178+
public int hashCode() {
179+
final int prime = 31;
180+
int result = 1;
181+
result = prime * result + ((jsonLdCredentialStatusObject == null) ? 0 : jsonLdCredentialStatusObject.hashCode());
182+
return result;
183+
}
184+
185+
@Override
186+
public boolean equals(Object obj) {
187+
if (this == obj)
188+
return true;
189+
if (obj == null)
190+
return false;
191+
if (getClass() != obj.getClass())
192+
return false;
193+
RevocationQuery2020Status other = (RevocationQuery2020Status) obj;
194+
if (jsonLdCredentialStatusObject == null) {
195+
if (other.jsonLdCredentialStatusObject != null)
196+
return false;
197+
} else if (!jsonLdCredentialStatusObject.equals(other.jsonLdCredentialStatusObject))
198+
return false;
199+
return true;
200+
}
201+
202+
@Override
203+
public String toString() {
204+
return "RevocationQuery2020Status [jsonLdObject=" + jsonLdCredentialStatusObject + "]";
205+
}
206+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package com.danubetech.verifiablecredentials.jsonld.proof;
2+
3+
import java.util.ArrayList;
4+
import java.util.LinkedHashMap;
5+
import java.util.List;
6+
7+
import com.github.jsonldjava.core.JsonLdConsts;
8+
9+
import info.weboftrust.ldsignatures.LdSignature;
10+
11+
public class BlockchainHashProof2020 extends LdSignature {
12+
13+
public static final LinkedHashMap<String, Object> JSONLD_CONTEXT;
14+
15+
public static final String JSONLD_TERM_BLOCKCHAINHASHPROOF2020 = "BlockchainHashProof2020";
16+
17+
static {
18+
19+
JSONLD_CONTEXT = new LinkedHashMap<String, Object> ();
20+
JSONLD_CONTEXT.put(JSONLD_TERM_BLOCKCHAINHASHPROOF2020, "https://danubetech.com/schema/2020/proofs/v1#BlockchainHashProof2020");
21+
}
22+
23+
protected BlockchainHashProof2020(LinkedHashMap<String, Object> jsonLdProofObject) {
24+
25+
super(jsonLdProofObject);
26+
}
27+
28+
public BlockchainHashProof2020() {
29+
30+
super();
31+
}
32+
33+
public static BlockchainHashProof2020 fromJsonLdObject(LinkedHashMap<String, Object> jsonLdProofObject) {
34+
35+
return new BlockchainHashProof2020(jsonLdProofObject);
36+
}
37+
38+
@SuppressWarnings("unchecked")
39+
public static void addContextToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) {
40+
41+
LdSignature.addContextToJsonLdObject(jsonLdObject);
42+
43+
Object context = jsonLdObject.get(JsonLdConsts.CONTEXT);
44+
ArrayList<Object> contexts;
45+
46+
// add as single value
47+
48+
if (context == null) {
49+
50+
jsonLdObject.put(JsonLdConsts.CONTEXT, JSONLD_CONTEXT);
51+
return;
52+
}
53+
54+
// add as array member
55+
56+
if (context instanceof ArrayList<?>) {
57+
58+
contexts = (ArrayList<Object>) context;
59+
} else {
60+
61+
contexts = new ArrayList<Object> ();
62+
contexts.add(context);
63+
jsonLdObject.put(JsonLdConsts.CONTEXT, contexts);
64+
}
65+
66+
if (! contexts.contains(JSONLD_CONTEXT)) {
67+
68+
contexts.add(JSONLD_CONTEXT);
69+
}
70+
}
71+
72+
public void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject, boolean addContext) {
73+
74+
if (addContext) addContextToJsonLdObject(jsonLdObject);
75+
76+
addToJsonLdObject(jsonLdObject, this.getJsonLdProofObject());
77+
}
78+
79+
public void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) {
80+
81+
this.addToJsonLdObject(jsonLdObject, false);
82+
}
83+
84+
public static void removeFromJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) {
85+
86+
jsonLdObject.remove(JSONLD_TERM_PROOF);
87+
}
88+
89+
@SuppressWarnings("unchecked")
90+
public static BlockchainHashProof2020 getFromJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) {
91+
92+
Object jsonLdProofObjectEntry = jsonLdObject.get(JSONLD_TERM_PROOF);
93+
94+
if (jsonLdProofObjectEntry instanceof List) {
95+
96+
List<LinkedHashMap<String, Object>> jsonLdProofObjectList = (List<LinkedHashMap<String, Object>>) jsonLdProofObjectEntry;
97+
98+
for (LinkedHashMap<String, Object> jsonLdProofObject : jsonLdProofObjectList) {
99+
100+
if (JSONLD_TERM_BLOCKCHAINHASHPROOF2020.equals(jsonLdProofObject.get("type"))) return BlockchainHashProof2020.fromJsonLdObject(jsonLdProofObject);
101+
}
102+
} else if (jsonLdProofObjectEntry instanceof LinkedHashMap) {
103+
104+
LinkedHashMap<String, Object> jsonLdProofObject = (LinkedHashMap<String, Object>) jsonLdProofObjectEntry;
105+
106+
if (JSONLD_TERM_BLOCKCHAINHASHPROOF2020.equals(jsonLdProofObject.get("type"))) return BlockchainHashProof2020.fromJsonLdObject(jsonLdProofObject);
107+
}
108+
109+
return null;
110+
}
111+
}

0 commit comments

Comments
 (0)