Skip to content

Commit

Permalink
removed expansion inside the transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Oct 5, 2023
1 parent 5629972 commit 2e85a84
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@

package org.eclipse.edc.iam.identitytrust.transform.to;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.json.JsonObject;
import jakarta.json.JsonValue;
import org.eclipse.edc.identitytrust.model.CredentialStatus;
import org.eclipse.edc.identitytrust.model.CredentialSubject;
import org.eclipse.edc.identitytrust.model.VerifiableCredential;
import org.eclipse.edc.jsonld.spi.JsonLd;
import org.eclipse.edc.jsonld.spi.JsonLdKeywords;
import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer;
import org.eclipse.edc.transform.spi.TransformerContext;
Expand All @@ -41,23 +39,13 @@
import static org.eclipse.edc.identitytrust.model.VerifiableCredential.VERIFIABLE_CREDENTIAL_VALIDUNTIL_PROPERTY;

/**
* This transformer a JSON-LD structure into a {@link VerifiableCredential}. In so far it is not different from other transformers.
* However, this transformer is <strong>not</strong> intended to be used at the API level, because it <strong>MUST</strong>
* receive its input (i.e. the {@link JsonObject}) exactly as it was generated by the credential issuer, because otherwise the proof
* won't compute anymore. That means, the JSON-LD structure <strong>must not</strong> be expanded or compacted or modified in any
* way before passing it to the transformer!
* <p/>
* To that end, the transformer will first keep an exact copy of the input, and then perform the expansion, and ultimately
* the transformation.
* Transforms a JSON-LD structure into a {@link VerifiableCredential}.
* Note that keeping a raw form of the JSON-LD for verification purposes is highly recommended.
*/
public class JsonObjectToVerifiableCredentialTransformer extends AbstractJsonLdTransformer<JsonObject, VerifiableCredential> {
private final ObjectMapper mapper;
private final JsonLd jsonLd;

public JsonObjectToVerifiableCredentialTransformer(ObjectMapper jsonLdMapper, JsonLd jsonLd) {
public JsonObjectToVerifiableCredentialTransformer() {
super(JsonObject.class, VerifiableCredential.class);
this.mapper = jsonLdMapper;
this.jsonLd = jsonLd;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class JsonObjectToVerifiableCredentialTransformerTest {

@BeforeEach
void setUp() throws URISyntaxException {
transformer = new JsonObjectToVerifiableCredentialTransformer(OBJECT_MAPPER, jsonLdService);
transformer = new JsonObjectToVerifiableCredentialTransformer();
var registry = new TypeTransformerRegistryImpl();
registry.register(new JsonObjectToCredentialSubjectTransformer());
registry.register(new JsonObjectToCredentialStatusTransformer());
Expand All @@ -54,7 +54,6 @@ void setUp() throws URISyntaxException {

context = spy(new TransformerContextImpl(registry));
jsonLdService.registerCachedDocument("https://www.w3.org/ns/credentials/v2", Thread.currentThread().getContextClassLoader().getResource("document/credentials.v2.jsonld").toURI());
jsonLdService.registerCachedDocument("https://www.w3.org/ns/credentials/examples/v2", Thread.currentThread().getContextClassLoader().getResource("document/example.jsonld").toURI());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package org.eclipse.edc.iam.identitytrust.transform.to;

import org.eclipse.edc.jsonld.TitaniumJsonLd;
import org.eclipse.edc.jsonld.util.JacksonJsonLd;
import org.eclipse.edc.transform.spi.TransformerContext;
import org.junit.jupiter.api.BeforeEach;

Expand All @@ -27,6 +25,6 @@ class JsonObjectToVerifiablePresentationTransformerTest {

@BeforeEach
void setup() {
transformer = new JsonObjectToVerifiableCredentialTransformer(JacksonJsonLd.createObjectMapper(), new TitaniumJsonLd(mock()));
transformer = new JsonObjectToVerifiableCredentialTransformer();
}
}

0 comments on commit 2e85a84

Please sign in to comment.