-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental notarization/revocation features.
Signed-off-by: Markus Sabadello <[email protected]>
- Loading branch information
1 parent
e3ab4c5
commit 02a185b
Showing
2 changed files
with
317 additions
and
0 deletions.
There are no files selected for viewing
206 changes: 206 additions & 0 deletions
206
...m/danubetech/verifiablecredentials/jsonld/credentialstatus/RevocationQuery2020Status.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
package com.danubetech.verifiablecredentials.jsonld.credentialstatus; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
|
||
import com.github.jsonldjava.core.JsonLdConsts; | ||
|
||
public class RevocationQuery2020Status { | ||
|
||
public static final LinkedHashMap<String, Object> JSONLD_CONTEXT; | ||
|
||
public static final String JSONLD_TERM_CREDENTIALSTATUS = "credentialStatus"; | ||
public static final String JSONLD_TERM_TYPE = "type"; | ||
public static final String JSONLD_TERM_REVOCATIONQUERY2020STATUS = "RevocationQuery2020Status"; | ||
public static final String JSONLD_TERM_CREDENTIALREFERENCE = "credentialReference"; | ||
public static final String JSONLD_TERM_REVOCATIONSERVICE = "revocationService"; | ||
|
||
private final LinkedHashMap<String, Object> jsonLdCredentialStatusObject; | ||
|
||
static { | ||
|
||
JSONLD_CONTEXT = new LinkedHashMap<String, Object> (); | ||
JSONLD_CONTEXT.put(JSONLD_TERM_REVOCATIONQUERY2020STATUS, "https://danubetech.com/schema/2020/proofs/v1#RevocationQuery2020Status"); | ||
JSONLD_CONTEXT.put(JSONLD_TERM_CREDENTIALREFERENCE, "https://danubetech.com/schema/2020/proofs/v1#credentialReference"); | ||
JSONLD_CONTEXT.put(JSONLD_TERM_REVOCATIONSERVICE, "https://danubetech.com/schema/2020/proofs/v1#revocationService"); | ||
} | ||
|
||
protected RevocationQuery2020Status(LinkedHashMap<String, Object> jsonLdCredentialStatusObject) { | ||
|
||
this.jsonLdCredentialStatusObject = jsonLdCredentialStatusObject; | ||
} | ||
|
||
public RevocationQuery2020Status() { | ||
|
||
this.jsonLdCredentialStatusObject = new LinkedHashMap<String, Object> (); | ||
} | ||
|
||
public static RevocationQuery2020Status fromJsonLdObject(LinkedHashMap<String, Object> jsonLdCredentialStatusObject) { | ||
|
||
return new RevocationQuery2020Status(jsonLdCredentialStatusObject); | ||
} | ||
|
||
public LinkedHashMap<String, Object> getJsonLdCredentialStatusObject() { | ||
|
||
return this.jsonLdCredentialStatusObject; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static void addContextToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) { | ||
|
||
Object context = jsonLdObject.get(JsonLdConsts.CONTEXT); | ||
ArrayList<Object> contexts; | ||
|
||
// add as single value | ||
|
||
if (context == null) { | ||
|
||
jsonLdObject.put(JsonLdConsts.CONTEXT, JSONLD_CONTEXT); | ||
return; | ||
} | ||
|
||
// add as array member | ||
|
||
if (context instanceof ArrayList<?>) { | ||
|
||
contexts = (ArrayList<Object>) context; | ||
} else { | ||
|
||
contexts = new ArrayList<Object> (); | ||
contexts.add(context); | ||
jsonLdObject.put(JsonLdConsts.CONTEXT, contexts); | ||
} | ||
|
||
if (! contexts.contains(JSONLD_CONTEXT)) { | ||
|
||
contexts.add(JSONLD_CONTEXT); | ||
} | ||
} | ||
|
||
public static void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject, LinkedHashMap<String, Object> jsonLdCredentialStatusObject) { | ||
|
||
Object credentialStatus = jsonLdObject.get(JSONLD_TERM_CREDENTIALSTATUS); | ||
|
||
// add as single value | ||
|
||
if (credentialStatus == null) { | ||
|
||
jsonLdObject.put(JSONLD_TERM_CREDENTIALSTATUS, jsonLdCredentialStatusObject); | ||
return; | ||
} | ||
|
||
// add as array member | ||
|
||
ArrayList<Object> proofs; | ||
|
||
if (credentialStatus instanceof ArrayList<?>) { | ||
|
||
proofs = (ArrayList<Object>) credentialStatus; | ||
} else { | ||
|
||
proofs = new ArrayList<Object> (); | ||
proofs.add(credentialStatus); | ||
jsonLdObject.put(JSONLD_TERM_CREDENTIALSTATUS, jsonLdCredentialStatusObject); | ||
} | ||
|
||
if (! proofs.contains(jsonLdCredentialStatusObject)) { | ||
|
||
proofs.add(jsonLdCredentialStatusObject); | ||
} | ||
} | ||
|
||
public void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject, boolean addContext) { | ||
|
||
if (addContext) addContextToJsonLdObject(jsonLdObject); | ||
|
||
addToJsonLdObject(jsonLdObject, this.getJsonLdCredentialStatusObject()); | ||
} | ||
|
||
public void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) { | ||
|
||
this.addToJsonLdObject(jsonLdObject, false); | ||
} | ||
|
||
public static void removeFromJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) { | ||
|
||
jsonLdObject.remove(JSONLD_TERM_CREDENTIALSTATUS); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static RevocationQuery2020Status getFromJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) { | ||
|
||
Object jsonLdProofObjectEntry = jsonLdObject.get(JSONLD_TERM_CREDENTIALSTATUS); | ||
|
||
if (jsonLdProofObjectEntry instanceof List) { | ||
|
||
List<LinkedHashMap<String, Object>> jsonLdProofObjectList = (List<LinkedHashMap<String, Object>>) jsonLdProofObjectEntry; | ||
|
||
for (LinkedHashMap<String, Object> jsonLdProofObject : jsonLdProofObjectList) { | ||
|
||
if (JSONLD_TERM_REVOCATIONQUERY2020STATUS.equals(jsonLdProofObject.get("type"))) return RevocationQuery2020Status.fromJsonLdObject(jsonLdProofObject); | ||
} | ||
} else if (jsonLdProofObjectEntry instanceof LinkedHashMap) { | ||
|
||
LinkedHashMap<String, Object> jsonLdProofObject = (LinkedHashMap<String, Object>) jsonLdProofObjectEntry; | ||
|
||
if (JSONLD_TERM_REVOCATIONQUERY2020STATUS.equals(jsonLdProofObject.get("type"))) return RevocationQuery2020Status.fromJsonLdObject(jsonLdProofObject); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public String getType() { | ||
return (String) this.jsonLdCredentialStatusObject.get(JSONLD_TERM_TYPE); | ||
} | ||
|
||
public void setType(String type) { | ||
this.jsonLdCredentialStatusObject.put(JSONLD_TERM_TYPE, type); | ||
} | ||
|
||
public String getCredentialReference() { | ||
return (String) this.jsonLdCredentialStatusObject.get(JSONLD_TERM_CREDENTIALREFERENCE); | ||
} | ||
|
||
public void setCredentialReference(String credentialReference) { | ||
this.jsonLdCredentialStatusObject.put(JSONLD_TERM_CREDENTIALREFERENCE, credentialReference); | ||
} | ||
|
||
public String getRevocationService() { | ||
return (String) this.jsonLdCredentialStatusObject.get(JSONLD_TERM_REVOCATIONSERVICE); | ||
} | ||
|
||
public void setRevocationService(String revocationService) { | ||
this.jsonLdCredentialStatusObject.put(JSONLD_TERM_REVOCATIONSERVICE, revocationService); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((jsonLdCredentialStatusObject == null) ? 0 : jsonLdCredentialStatusObject.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
RevocationQuery2020Status other = (RevocationQuery2020Status) obj; | ||
if (jsonLdCredentialStatusObject == null) { | ||
if (other.jsonLdCredentialStatusObject != null) | ||
return false; | ||
} else if (!jsonLdCredentialStatusObject.equals(other.jsonLdCredentialStatusObject)) | ||
return false; | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RevocationQuery2020Status [jsonLdObject=" + jsonLdCredentialStatusObject + "]"; | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
src/main/java/com/danubetech/verifiablecredentials/jsonld/proof/BlockchainHashProof2020.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.danubetech.verifiablecredentials.jsonld.proof; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
|
||
import com.github.jsonldjava.core.JsonLdConsts; | ||
|
||
import info.weboftrust.ldsignatures.LdSignature; | ||
|
||
public class BlockchainHashProof2020 extends LdSignature { | ||
|
||
public static final LinkedHashMap<String, Object> JSONLD_CONTEXT; | ||
|
||
public static final String JSONLD_TERM_BLOCKCHAINHASHPROOF2020 = "BlockchainHashProof2020"; | ||
|
||
static { | ||
|
||
JSONLD_CONTEXT = new LinkedHashMap<String, Object> (); | ||
JSONLD_CONTEXT.put(JSONLD_TERM_BLOCKCHAINHASHPROOF2020, "https://danubetech.com/schema/2020/proofs/v1#BlockchainHashProof2020"); | ||
} | ||
|
||
protected BlockchainHashProof2020(LinkedHashMap<String, Object> jsonLdProofObject) { | ||
|
||
super(jsonLdProofObject); | ||
} | ||
|
||
public BlockchainHashProof2020() { | ||
|
||
super(); | ||
} | ||
|
||
public static BlockchainHashProof2020 fromJsonLdObject(LinkedHashMap<String, Object> jsonLdProofObject) { | ||
|
||
return new BlockchainHashProof2020(jsonLdProofObject); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static void addContextToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) { | ||
|
||
LdSignature.addContextToJsonLdObject(jsonLdObject); | ||
|
||
Object context = jsonLdObject.get(JsonLdConsts.CONTEXT); | ||
ArrayList<Object> contexts; | ||
|
||
// add as single value | ||
|
||
if (context == null) { | ||
|
||
jsonLdObject.put(JsonLdConsts.CONTEXT, JSONLD_CONTEXT); | ||
return; | ||
} | ||
|
||
// add as array member | ||
|
||
if (context instanceof ArrayList<?>) { | ||
|
||
contexts = (ArrayList<Object>) context; | ||
} else { | ||
|
||
contexts = new ArrayList<Object> (); | ||
contexts.add(context); | ||
jsonLdObject.put(JsonLdConsts.CONTEXT, contexts); | ||
} | ||
|
||
if (! contexts.contains(JSONLD_CONTEXT)) { | ||
|
||
contexts.add(JSONLD_CONTEXT); | ||
} | ||
} | ||
|
||
public void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject, boolean addContext) { | ||
|
||
if (addContext) addContextToJsonLdObject(jsonLdObject); | ||
|
||
addToJsonLdObject(jsonLdObject, this.getJsonLdProofObject()); | ||
} | ||
|
||
public void addToJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) { | ||
|
||
this.addToJsonLdObject(jsonLdObject, false); | ||
} | ||
|
||
public static void removeFromJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) { | ||
|
||
jsonLdObject.remove(JSONLD_TERM_PROOF); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static BlockchainHashProof2020 getFromJsonLdObject(LinkedHashMap<String, Object> jsonLdObject) { | ||
|
||
Object jsonLdProofObjectEntry = jsonLdObject.get(JSONLD_TERM_PROOF); | ||
|
||
if (jsonLdProofObjectEntry instanceof List) { | ||
|
||
List<LinkedHashMap<String, Object>> jsonLdProofObjectList = (List<LinkedHashMap<String, Object>>) jsonLdProofObjectEntry; | ||
|
||
for (LinkedHashMap<String, Object> jsonLdProofObject : jsonLdProofObjectList) { | ||
|
||
if (JSONLD_TERM_BLOCKCHAINHASHPROOF2020.equals(jsonLdProofObject.get("type"))) return BlockchainHashProof2020.fromJsonLdObject(jsonLdProofObject); | ||
} | ||
} else if (jsonLdProofObjectEntry instanceof LinkedHashMap) { | ||
|
||
LinkedHashMap<String, Object> jsonLdProofObject = (LinkedHashMap<String, Object>) jsonLdProofObjectEntry; | ||
|
||
if (JSONLD_TERM_BLOCKCHAINHASHPROOF2020.equals(jsonLdProofObject.get("type"))) return BlockchainHashProof2020.fromJsonLdObject(jsonLdProofObject); | ||
} | ||
|
||
return null; | ||
} | ||
} |