Skip to content

Commit

Permalink
chore: Some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
peacekeeper committed Oct 22, 2023
1 parent 06fe6b2 commit 681113f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 26 deletions.
47 changes: 29 additions & 18 deletions src/main/java/foundation/identity/did/DIDDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,34 @@ public DIDDocument build() {
super.build();

// add JSON-LD properties
if (this.controllers != null) JsonLDUtils.jsonLdAddAsJsonArray(this.jsonLdObject, DIDKeywords.JSONLD_TERM_CONTROLLER, this.controllers.stream().map(JsonLDUtils::uriToString).collect(Collectors.toList()));
if (this.alsoKnownAses != null) JsonLDUtils.jsonLdAddAsJsonArray(this.jsonLdObject, DIDKeywords.JSONLD_TERM_ALSOKNOWNAS, this.alsoKnownAses.stream().map(JsonLDUtils::uriToString).collect(Collectors.toList()));
if (this.verificationMethods != null) for (VerificationMethod verificationMethod : this.verificationMethods) verificationMethod.addToJsonLDObjectAsJsonArray(this.jsonLdObject);
if (this.authenticationVerificationMethods != null) for (VerificationMethod authenticationVerificationMethod : this.authenticationVerificationMethods) authenticationVerificationMethod.addToJsonLDObjectAsJsonArray(this.jsonLdObject, VerificationRelationships.AUTHENTICATION);
if (this.assertionMethodVerificationMethods != null) for (VerificationMethod assertionMethodVerificationMethod : this.assertionMethodVerificationMethods) assertionMethodVerificationMethod.addToJsonLDObjectAsJsonArray(this.jsonLdObject, VerificationRelationships.ASSERTIONMETHOD);
if (this.keyAgreementVerificationMethods != null) for (VerificationMethod keyAgreementVerificationMethod : this.keyAgreementVerificationMethods) keyAgreementVerificationMethod.addToJsonLDObjectAsJsonArray(this.jsonLdObject, VerificationRelationships.KEYAGREEMENT);
if (this.capabilityInvocationVerificationMethods != null) for (VerificationMethod capabilityInvocationVerificationMethod : this.capabilityInvocationVerificationMethods) capabilityInvocationVerificationMethod.addToJsonLDObjectAsJsonArray(this.jsonLdObject, VerificationRelationships.CAPABILITYINVOCATION);
if (this.capabilityDelegationVerificationMethods != null) for (VerificationMethod capabilityDelegationVerificationMethod : this.capabilityDelegationVerificationMethods) capabilityDelegationVerificationMethod.addToJsonLDObjectAsJsonArray(this.jsonLdObject, VerificationRelationships.CAPABILITYDELEGATION);
if (this.services != null) for (Service service : this.services) service.addToJsonLDObjectAsJsonArray(this.jsonLdObject);

if (this.controllers != null) {
JsonLDUtils.jsonLdAddAsJsonArray(this.jsonLdObject, DIDKeywords.JSONLD_TERM_CONTROLLER, this.controllers.stream().map(JsonLDUtils::uriToString).collect(Collectors.toList()));
}
if (this.alsoKnownAses != null) {
JsonLDUtils.jsonLdAddAsJsonArray(this.jsonLdObject, DIDKeywords.JSONLD_TERM_ALSOKNOWNAS, this.alsoKnownAses.stream().map(JsonLDUtils::uriToString).collect(Collectors.toList()));
}
if (this.verificationMethods != null) {
for (VerificationMethod verificationMethod : this.verificationMethods) verificationMethod.addToJsonLDObjectAsJsonArray(this.jsonLdObject);
}
if (this.authenticationVerificationMethods != null) {
for (VerificationMethod authenticationVerificationMethod : this.authenticationVerificationMethods) authenticationVerificationMethod.addToJsonLDObjectAsJsonArray(this.jsonLdObject, VerificationRelationships.AUTHENTICATION);
}
if (this.assertionMethodVerificationMethods != null) {
for (VerificationMethod assertionMethodVerificationMethod : this.assertionMethodVerificationMethods) assertionMethodVerificationMethod.addToJsonLDObjectAsJsonArray(this.jsonLdObject, VerificationRelationships.ASSERTIONMETHOD);
}
if (this.keyAgreementVerificationMethods != null) {
for (VerificationMethod keyAgreementVerificationMethod : this.keyAgreementVerificationMethods) keyAgreementVerificationMethod.addToJsonLDObjectAsJsonArray(this.jsonLdObject, VerificationRelationships.KEYAGREEMENT);
}
if (this.capabilityInvocationVerificationMethods != null) {
for (VerificationMethod capabilityInvocationVerificationMethod : this.capabilityInvocationVerificationMethods) capabilityInvocationVerificationMethod.addToJsonLDObjectAsJsonArray(this.jsonLdObject, VerificationRelationships.CAPABILITYINVOCATION);
}
if (this.capabilityDelegationVerificationMethods != null) {
for (VerificationMethod capabilityDelegationVerificationMethod : this.capabilityDelegationVerificationMethods) capabilityDelegationVerificationMethod.addToJsonLDObjectAsJsonArray(this.jsonLdObject, VerificationRelationships.CAPABILITYDELEGATION);
}
if (this.services != null) {
for (Service service : this.services) service.addToJsonLDObjectAsJsonArray(this.jsonLdObject);
}

return (DIDDocument) this.jsonLdObject;
}
Expand Down Expand Up @@ -188,15 +207,7 @@ public static void removeFromJsonLdObject(JsonLDObject jsonLdObject) {
JsonLDObject.removeFromJsonLdObject(DIDDocument.class, jsonLdObject);
}

/*
* Helper methods
*/

public Map<String, Object> toMap() {
return this.getJsonObject();
}

/*
/*
* Getters
*/

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/foundation/identity/did/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public Service build() {
super.build();

// add JSON-LD properties
if (this.serviceEndpoint != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_SERVICEENDPOINT, this.serviceEndpoint);

if (this.serviceEndpoint != null) {
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_SERVICEENDPOINT, this.serviceEndpoint);
}

return (Service) this.jsonLdObject;
}
Expand Down
29 changes: 22 additions & 7 deletions src/main/java/foundation/identity/did/VerificationMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,28 @@ public VerificationMethod build() {
super.build();

// add JSON-LD properties
if (this.controller != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_CONTROLLER, this.controller);
if (this.publicKeyBase64 != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_PUBLICKEYBASE64, this.publicKeyBase64);
if (this.publicKeyBase58 != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_PUBLICKEYBASE58, this.publicKeyBase58);
if (this.publicKeyHex != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_PUBLICKEYHEX, this.publicKeyHex);
if (this.publicKeyPem != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_PUBLICKEYPEM, this.publicKeyPem);
if (this.publicKeyMultibase != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_PUBLICKEYMULTIBASE, this.publicKeyMultibase);
if (this.publicKeyJwk != null) JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_PUBLICKEYJWK, this.publicKeyJwk);

if (this.controller != null) {
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_CONTROLLER, JsonLDUtils.uriToString(this.controller));
}
if (this.publicKeyBase64 != null) {
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_PUBLICKEYBASE64, this.publicKeyBase64);
}
if (this.publicKeyBase58 != null) {
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_PUBLICKEYBASE58, this.publicKeyBase58);
}
if (this.publicKeyHex != null) {
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_PUBLICKEYHEX, this.publicKeyHex);
}
if (this.publicKeyPem != null) {
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_PUBLICKEYPEM, this.publicKeyPem);
}
if (this.publicKeyMultibase != null) {
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_PUBLICKEYMULTIBASE, this.publicKeyMultibase);
}
if (this.publicKeyJwk != null) {
JsonLDUtils.jsonLdAdd(this.jsonLdObject, DIDKeywords.JSONLD_TERM_PUBLICKEYJWK, this.publicKeyJwk);
}

return (VerificationMethod) this.jsonLdObject;
}
Expand Down

0 comments on commit 681113f

Please sign in to comment.