Skip to content

Commit

Permalink
Merge pull request #83 from koptan/pr/36-remove-duplicate-jsonvalidator
Browse files Browse the repository at this point in the history
Fix: Remove duplicate JsonValidator
  • Loading branch information
borisrizov-zf authored Jan 22, 2024
2 parents d142838 + 3ce0f58 commit a556077
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

package org.eclipse.tractusx.ssi.lib.proof;

import java.util.logging.Logger;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.eclipse.tractusx.ssi.lib.did.resolver.DidResolver;
import org.eclipse.tractusx.ssi.lib.exception.InvalidJsonLdException;
import org.eclipse.tractusx.ssi.lib.exception.UnsupportedSignatureTypeException;
import org.eclipse.tractusx.ssi.lib.model.verifiable.Verifiable;
import org.eclipse.tractusx.ssi.lib.model.verifiable.Verifiable.VerifiableType;
Expand All @@ -36,12 +38,13 @@
import org.eclipse.tractusx.ssi.lib.proof.transform.TransformedLinkedData;
import org.eclipse.tractusx.ssi.lib.proof.types.ed25519.Ed25519ProofVerifier;
import org.eclipse.tractusx.ssi.lib.proof.types.jws.JWSProofVerifier;
import org.eclipse.tractusx.ssi.lib.serialization.jsonLd.JsonLdValidator;
import org.eclipse.tractusx.ssi.lib.serialization.jsonLd.JsonLdValidatorImpl;
import org.eclipse.tractusx.ssi.lib.validation.JsonLdValidator;
import org.eclipse.tractusx.ssi.lib.validation.JsonLdValidatorImpl;

/** The type Linked data proof validation. */
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class LinkedDataProofValidation {
static final Logger LOG = Logger.getLogger(LinkedDataProofValidation.class.getName());

/**
* New instance linked data proof validation.
Expand Down Expand Up @@ -99,9 +102,14 @@ public boolean verify(Verifiable verifiable) {
final TransformedLinkedData transformedData = transformer.transform(verifiable);
final HashedLinkedData hashedData = hasher.hash(transformedData);

return jsonLdValidator.validate(verifiable)
&& verifier.verify(hashedData, verifiable)
&& validateVerificationMethodOfVC(verifiable);
try {
jsonLdValidator.validate(verifiable);
return verifier.verify(hashedData, verifiable) && validateVerificationMethodOfVC(verifiable);
} catch (InvalidJsonLdException e) {
LOG.severe("Could not valiate " + verifiable.getId());
LOG.throwing(this.getClass().getName(), "verify", e);
return false;
}
}

/**
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,9 @@
package org.eclipse.tractusx.ssi.lib.validation;

import org.eclipse.tractusx.ssi.lib.exception.InvalidJsonLdException;
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential;
import org.eclipse.tractusx.ssi.lib.model.verifiable.presentation.VerifiablePresentation;
import org.eclipse.tractusx.ssi.lib.model.verifiable.Verifiable;

/** The interface Json ld validator. */
public interface JsonLdValidator {

/**
* Validate.
*
* @param verifiablePresentation the verifiable presentation
* @throws InvalidJsonLdException the invalid json ld exception
*/
void validate(VerifiablePresentation verifiablePresentation) throws InvalidJsonLdException;

/**
* Validate.
*
* @param verifiableCredential the verifiable credential
* @throws InvalidJsonLdException the invalid json ld exception
*/
void validate(VerifiableCredential verifiableCredential) throws InvalidJsonLdException;
void validate(Verifiable verifiable) throws InvalidJsonLdException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,35 @@
import jakarta.json.JsonObject;
import jakarta.json.JsonValue;
import java.util.Map;
import java.util.logging.Logger;
import org.eclipse.tractusx.ssi.lib.exception.InvalidJsonLdException;
import org.eclipse.tractusx.ssi.lib.model.JsonLdObject;
import org.eclipse.tractusx.ssi.lib.model.RemoteDocumentLoader;
import org.eclipse.tractusx.ssi.lib.model.verifiable.Verifiable;
import org.eclipse.tractusx.ssi.lib.model.verifiable.credential.VerifiableCredential;
import org.eclipse.tractusx.ssi.lib.model.verifiable.presentation.VerifiablePresentation;

/** The type Json ld validator. */
public class JsonLdValidatorImpl implements JsonLdValidator {
static final Logger LOG = Logger.getLogger(JsonLdValidatorImpl.class.getName());
private static final String UNDEFINED_TERM_URI = "urn:UNDEFINEDTERM";

public void validate(VerifiablePresentation verifiablePresentation)
throws InvalidJsonLdException {
for (VerifiableCredential verifiableCredential :
verifiablePresentation.getVerifiableCredentials()) {
validate(verifiableCredential);
public void validate(Verifiable verifiable) throws InvalidJsonLdException {
if (verifiable instanceof VerifiableCredential) {
validateJsonLd(verifiable);
} else if (verifiable instanceof VerifiablePresentation) {
VerifiablePresentation verifiablePresentation = (VerifiablePresentation) verifiable;
for (VerifiableCredential verifiableCredential :
verifiablePresentation.getVerifiableCredentials()) {
validate(verifiableCredential);
}
} else {
LOG.warning("Unsupported Verifiable type: " + verifiable.getClass().getName());
throw new InvalidJsonLdException(
String.format("Unsupported Verifiable type: %s", verifiable.getClass().getName()));
}
}

@Override
public void validate(VerifiableCredential verifiableCredential) throws InvalidJsonLdException {
validateJsonLd(verifiableCredential);
}

private void validateJsonLd(JsonLdObject jsonLdObject) throws InvalidJsonLdException {
try {

Expand Down

0 comments on commit a556077

Please sign in to comment.