Skip to content

Commit

Permalink
chore: Various code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
peacekeeper committed Oct 22, 2023
1 parent 4d5f199 commit 2fd98bc
Show file tree
Hide file tree
Showing 22 changed files with 112 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.apicatalog.jsonld.loader.DocumentLoader;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialContexts;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialKeywords;
import com.danubetech.verifiablecredentials.proof.BlockchainHashProof2020;
import com.fasterxml.jackson.annotation.JsonCreator;
import foundation.identity.jsonld.JsonLDKeywords;
import foundation.identity.jsonld.JsonLDObject;
Expand All @@ -14,7 +15,6 @@
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;

public class CredentialSubject extends JsonLDObject {

Expand Down Expand Up @@ -62,7 +62,7 @@ public B claims(Map<String, Object> claims) {
}

public static Builder<? extends Builder<?>> builder() {
return new Builder(new CredentialSubject());
return new Builder<? extends BlockchainHashProof2020.Builder<?>>(new CredentialSubject());
}

public static CredentialSubject fromJsonObject(Map<String, Object> jsonObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.danubetech.verifiablecredentials.credentialstatus.CredentialStatus;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialContexts;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialKeywords;
import com.danubetech.verifiablecredentials.proof.BlockchainHashProof2020;
import com.fasterxml.jackson.annotation.JsonCreator;
import foundation.identity.jsonld.JsonLDObject;
import foundation.identity.jsonld.JsonLDUtils;
Expand Down Expand Up @@ -99,7 +100,7 @@ public B ldProof(LdProof ldProof) {
}

public static Builder<? extends Builder<?>> builder() {
return new Builder(new VerifiableCredential());
return new Builder<? extends BlockchainHashProof2020.Builder<?>>(new VerifiableCredential());
}

public static VerifiableCredential fromJsonObject(Map<String, Object> jsonObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.apicatalog.jsonld.loader.DocumentLoader;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialContexts;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialKeywords;
import com.danubetech.verifiablecredentials.proof.BlockchainHashProof2020;
import com.fasterxml.jackson.annotation.JsonCreator;
import foundation.identity.jsonld.JsonLDObject;
import foundation.identity.jsonld.JsonLDUtils;
Expand Down Expand Up @@ -77,7 +78,7 @@ public B ldProof(LdProof ldProof) {
}

public static Builder<? extends Builder<?>> builder() {
return new Builder(new VerifiablePresentation());
return new Builder<? extends BlockchainHashProof2020.Builder<?>>(new VerifiablePresentation());
}

public static VerifiablePresentation fromJsonObject(Map<String, Object> jsonObject) {
Expand Down Expand Up @@ -148,7 +149,7 @@ public URI getHolder() {

public VerifiableCredential getVerifiableCredential() {
Object verifiableCredentialObject = this.getJsonObject().get(VerifiableCredentialKeywords.JSONLD_TERM_VERIFIABLECREDENTIAL);
if ((verifiableCredentialObject instanceof List && ! ((List) verifiableCredentialObject).isEmpty() && ((List) verifiableCredentialObject).get(0) instanceof Map)) {
if ((verifiableCredentialObject instanceof List<?> && ! ((List<?>) verifiableCredentialObject).isEmpty() && ((List<?>) verifiableCredentialObject).get(0) instanceof Map)) {
return VerifiableCredential.getFromJsonLDObject(this);
} else if (verifiableCredentialObject instanceof Map) {
return VerifiableCredential.getFromJsonLDObject(this);
Expand All @@ -158,8 +159,8 @@ public VerifiableCredential getVerifiableCredential() {

public String getJwtVerifiableCredentialString() {
Object verifiableCredentialObject = this.getJsonObject().get(VerifiableCredentialKeywords.JSONLD_TERM_VERIFIABLECREDENTIAL);
if (verifiableCredentialObject instanceof List && ! ((List) verifiableCredentialObject).isEmpty() && ((List) verifiableCredentialObject).get(0) instanceof String) {
return (String) ((List) verifiableCredentialObject).get(0);
if (verifiableCredentialObject instanceof List<?> && ! ((List<?>) verifiableCredentialObject).isEmpty() && ((List<?>) verifiableCredentialObject).get(0) instanceof String) {
return (String) ((List<?>) verifiableCredentialObject).get(0);
} else if (verifiableCredentialObject instanceof String) {
return (String) verifiableCredentialObject;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.danubetech.verifiablecredentials.credentialstatus;

import com.apicatalog.jsonld.loader.DocumentLoader;
import com.danubetech.verifiablecredentials.CredentialSubject;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialContexts;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialKeywords;
import com.danubetech.verifiablecredentials.proof.BlockchainHashProof2020;
import com.fasterxml.jackson.annotation.JsonCreator;
import foundation.identity.jsonld.JsonLDObject;
import foundation.identity.jsonld.JsonLDUtils;

import java.io.Reader;
import java.net.URI;
Expand Down Expand Up @@ -48,7 +47,7 @@ public CredentialStatus build() {
}

public static Builder<? extends Builder<?>> builder() {
return new Builder(new CredentialStatus());
return new Builder<? extends BlockchainHashProof2020.Builder<?>>(new CredentialStatus());
}

public static CredentialStatus fromJsonObject(Map<String, Object> jsonObject) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.danubetech.verifiablecredentials.credentialstatus;

import com.apicatalog.jsonld.loader.DocumentLoader;
import com.danubetech.verifiablecredentials.CredentialSubject;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialContexts;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialKeywords;
import com.danubetech.verifiablecredentials.proof.BlockchainHashProof2020;
import com.fasterxml.jackson.annotation.JsonCreator;
import foundation.identity.jsonld.JsonLDObject;
import foundation.identity.jsonld.JsonLDUtils;
Expand Down Expand Up @@ -66,7 +66,7 @@ public B revocationListCredential(URI revocationListCredential) {
}

public static Builder<? extends Builder<?>> builder() {
return new Builder(new RevocationList2020Status());
return new Builder<? extends BlockchainHashProof2020.Builder<?>>(new RevocationList2020Status());
}

public static RevocationList2020Status fromJsonObject(Map<String, Object> jsonObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import foundation.identity.jsonld.JsonLDObject;
import foundation.identity.jsonld.JsonLDUtils;
import info.weboftrust.ldsignatures.LdProof;

import java.io.Reader;
import java.net.URI;
Expand Down Expand Up @@ -67,7 +66,7 @@ public B revocationService(String revocationService) {
}

public static Builder<? extends Builder<?>> builder() {
return new Builder(new RevocationQuery2020Status());
return new Builder<? extends BlockchainHashProof2020.Builder<?>>(new RevocationQuery2020Status());
}

public static RevocationQuery2020Status fromJsonObject(Map<String, Object> jsonObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.apicatalog.jsonld.loader.DocumentLoader;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialContexts;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialKeywords;
import com.danubetech.verifiablecredentials.proof.BlockchainHashProof2020;
import com.fasterxml.jackson.annotation.JsonCreator;
import foundation.identity.jsonld.JsonLDObject;
import foundation.identity.jsonld.JsonLDUtils;
Expand Down Expand Up @@ -73,7 +74,7 @@ public B statusPurpose(String statusPurpose) {
}

public static StatusList2021Entry.Builder<? extends StatusList2021Entry.Builder<?>> builder() {
return new StatusList2021Entry.Builder(new StatusList2021Entry());
return new StatusList2021Entry.Builder<? extends BlockchainHashProof2020.Builder<?>>(new StatusList2021Entry());
}

public static StatusList2021Entry fromJsonObject(Map<String, Object> jsonObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class VerifiableCredentialContexts {

Expand All @@ -34,21 +35,21 @@ public class VerifiableCredentialContexts {
CONTEXTS.putAll(LDSecurityContexts.CONTEXTS);

CONTEXTS.put(JSONLD_CONTEXT_W3C_2018_CREDENTIALS_V1,
JsonDocument.of(MediaType.JSON_LD, VerifiableCredentialContexts.class.getResourceAsStream("credentials-v1.jsonld")));
JsonDocument.of(MediaType.JSON_LD, Objects.requireNonNull(VerifiableCredentialContexts.class.getResourceAsStream("credentials-v1.jsonld"))));
CONTEXTS.put(JSONLD_CONTEXT_W3C_2018_CREDENTIALS_V2,
JsonDocument.of(MediaType.JSON_LD, VerifiableCredentialContexts.class.getResourceAsStream("credentials-v2-unstable.jsonld")));
JsonDocument.of(MediaType.JSON_LD, Objects.requireNonNull(VerifiableCredentialContexts.class.getResourceAsStream("credentials-v2-unstable.jsonld"))));
CONTEXTS.put(JSONLD_CONTEXT_W3C_2018_CREDENTIALS_EXAMPLES_V1,
JsonDocument.of(MediaType.JSON_LD, VerifiableCredentialContexts.class.getResourceAsStream("credentials-examples-v1.jsonld")));
JsonDocument.of(MediaType.JSON_LD, Objects.requireNonNull(VerifiableCredentialContexts.class.getResourceAsStream("credentials-examples-v1.jsonld"))));
CONTEXTS.put(JSONLD_CONTEXT_W3C_NS_ODRL,
JsonDocument.of(MediaType.JSON_LD, VerifiableCredentialContexts.class.getResourceAsStream("odrl.jsonld")));
JsonDocument.of(MediaType.JSON_LD, Objects.requireNonNull(VerifiableCredentialContexts.class.getResourceAsStream("odrl.jsonld"))));
CONTEXTS.put(JSONLD_CONTEXT_DANUBETECH_2020_CREDENTIALS_V1,
JsonDocument.of(MediaType.JSON_LD, VerifiableCredentialContexts.class.getResourceAsStream("danubetech-v1.jsonld")));
JsonDocument.of(MediaType.JSON_LD, Objects.requireNonNull(VerifiableCredentialContexts.class.getResourceAsStream("danubetech-v1.jsonld"))));
CONTEXTS.put(JSONLD_CONTEXT_W3ID_VC_REVOCATION_LIST_2020_V1,
JsonDocument.of(MediaType.JSON_LD, VerifiableCredentialContexts.class.getResourceAsStream("vc-revocation-list-2020-v1.jsonld")));
JsonDocument.of(MediaType.JSON_LD, Objects.requireNonNull(VerifiableCredentialContexts.class.getResourceAsStream("vc-revocation-list-2020-v1.jsonld"))));
CONTEXTS.put(JSONLD_CONTEXT_W3ID_VC_STATUS_LIST_2021_V1,
JsonDocument.of(MediaType.JSON_LD, VerifiableCredentialContexts.class.getResourceAsStream("vc-status-list-2021-v1.jsonld")));
JsonDocument.of(MediaType.JSON_LD, Objects.requireNonNull(VerifiableCredentialContexts.class.getResourceAsStream("vc-status-list-2021-v1.jsonld"))));
CONTEXTS.put(JSONLD_CONTEXT_DIF_PRESENTATION_EXCHANGE_SUBMISSIONS_V1,
JsonDocument.of(MediaType.JSON_LD, VerifiableCredentialContexts.class.getResourceAsStream("presentation-exchange-submissions-v1.jsonld")));
JsonDocument.of(MediaType.JSON_LD, Objects.requireNonNull(VerifiableCredentialContexts.class.getResourceAsStream("presentation-exchange-submissions-v1.jsonld"))));

for (Map.Entry<URI, JsonDocument> context : CONTEXTS.entrySet()) {
context.getValue().setDocumentUrl(context.getKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.danubetech.verifiablecredentials.VerifiableCredential;
import com.danubetech.verifiablecredentials.VerifiablePresentation;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialKeywords;
import com.danubetech.verifiablecredentials.proof.BlockchainHashProof2020;
import com.nimbusds.jwt.JWTClaimsSet;
import foundation.identity.jsonld.JsonLDUtils;

Expand All @@ -23,7 +24,7 @@ public static VerifiableCredential fromJwtVerifiableCredential(JwtVerifiableCred
CredentialSubject payloadCredentialSubject = payloadVerifiableCredential.getCredentialSubject();
CredentialSubject.removeFromJsonLdObject(payloadVerifiableCredential);

VerifiableCredential.Builder verifiableCredentialBuilder = VerifiableCredential.builder()
VerifiableCredential.Builder<? extends BlockchainHashProof2020.Builder<?>> verifiableCredentialBuilder = VerifiableCredential.builder()
.base(payloadVerifiableCredential)
.defaultContexts(false)
.defaultTypes(false);
Expand All @@ -37,7 +38,7 @@ public static VerifiableCredential fromJwtVerifiableCredential(JwtVerifiableCred

if (payloadCredentialSubject != null) {

CredentialSubject.Builder credentialSubjectBuilder = CredentialSubject.builder()
CredentialSubject.Builder<? extends BlockchainHashProof2020.Builder<?>> credentialSubjectBuilder = CredentialSubject.builder()
.base(payloadCredentialSubject);

String subject = payload.getSubject();
Expand Down Expand Up @@ -74,7 +75,7 @@ public static VerifiablePresentation fromJwtVerifiablePresentation(JwtVerifiable

VerifiablePresentation payloadVerifiablePresentation = VerifiablePresentation.fromJson(jwtVerifiablePresentation.getPayloadObject().toString());

VerifiablePresentation.Builder verifiablePresentationBuilder = VerifiablePresentation.builder()
VerifiablePresentation.Builder<? extends BlockchainHashProof2020.Builder<?>> verifiablePresentationBuilder = VerifiablePresentation.builder()
.base(payloadVerifiablePresentation)
.defaultContexts(false)
.defaultTypes(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private JwtJwtVerifiablePresentation(JWTClaimsSet payload, JwtVerifiableCredenti
* Factory methods
*/

public static JwtJwtVerifiablePresentation fromJwtVerifiableCredential(JwtVerifiableCredential jwtVerifiableCredential, String aud) throws IOException {
public static JwtJwtVerifiablePresentation fromJwtVerifiableCredential(JwtVerifiableCredential jwtVerifiableCredential, String aud) throws IOException {

JwtVerifiableCredential payloadJwtVerifiableCredential = jwtVerifiableCredential;
VerifiablePresentation verifiablePresentation = FromJwtConverter.fromJwtVerifiableCredentialToVerifiablePresentation(payloadJwtVerifiableCredential);
Expand All @@ -28,7 +28,7 @@ public static JwtJwtVerifiablePresentation fromJwtVerifiableCredential(JwtVerifi

Date issueTime = new Date();

payloadBuilder.jwtID("urn:uuid:" + UUID.randomUUID().toString());
payloadBuilder.jwtID("urn:uuid:" + UUID.randomUUID());
payloadBuilder.issuer(jwtVerifiableCredential.getPayload().getSubject());
payloadBuilder.issueTime(issueTime);
payloadBuilder.notBeforeTime(issueTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@ public boolean verify_P_521_ES512(com.nimbusds.jose.jwk.ECKey publicKey) throws

private static class EscapedSlashWorkaroundJWSObject extends JWSObject {

private static final long serialVersionUID = -587898962717783109L;

public EscapedSlashWorkaroundJWSObject(final JWSHeader jwsHeader, final JWTClaimsSet jwtClaimsSet, boolean canonicalize) {
super(jwsHeader, makePayload(jwtClaimsSet, canonicalize));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.danubetech.verifiablecredentials.VerifiableCredential;
import com.nimbusds.jose.JWSObject;
import com.nimbusds.jose.util.JSONObjectUtils;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.SignedJWT;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.danubetech.verifiablecredentials.jwt;

import com.danubetech.verifiablecredentials.VerifiableCredential;
import com.danubetech.verifiablecredentials.VerifiablePresentation;
import com.nimbusds.jose.JWSObject;
import com.nimbusds.jwt.JWTClaimsSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.danubetech.verifiablecredentials.proof;

import com.apicatalog.jsonld.loader.DocumentLoader;
import com.danubetech.verifiablecredentials.CredentialSubject;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialContexts;
import com.danubetech.verifiablecredentials.jsonld.VerifiableCredentialKeywords;
import com.fasterxml.jackson.annotation.JsonCreator;
Expand Down Expand Up @@ -50,7 +49,7 @@ public BlockchainHashProof2020 build() {
}

public static Builder<? extends Builder<?>> builder() {
return new Builder(new BlockchainHashProof2020());
return new Builder<? extends Builder<?>>(new BlockchainHashProof2020());
}

public static BlockchainHashProof2020 fromJsonObject(Map<String, Object> jsonObject) {
Expand Down
Loading

0 comments on commit 2fd98bc

Please sign in to comment.