Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Nov 14, 2023
1 parent 82f030f commit 6d9ec44
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 15 deletions.
2 changes: 2 additions & 0 deletions core/identity-hub-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ dependencies {
api(project(":spi:identity-hub-store-spi"))
implementation(libs.edc.core.connector) // for the CriterionToPredicateConverterImpl
implementation(libs.edc.spi.jsonld)
implementation(libs.edc.spi.jsonld)
implementation(libs.edc.ext.jsonld) // for the JSON-LD mapper
implementation(libs.edc.iatp.service) // JWT validator
implementation(libs.edc.core.crypto) // JWT verifier
implementation(libs.edc.jws2020)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,39 @@

package org.eclipse.edc.identityhub;

import com.apicatalog.ld.signature.SignatureSuite;
import org.eclipse.edc.identityhub.defaults.EdcScopeToCriterionTransformer;
import org.eclipse.edc.identityhub.defaults.InMemoryCredentialStore;
import org.eclipse.edc.identityhub.spi.ScopeToCriterionTransformer;
import org.eclipse.edc.identityhub.spi.generator.PresentationGenerator;
import org.eclipse.edc.identityhub.spi.model.IdentityHubConstants;
import org.eclipse.edc.identityhub.spi.store.CredentialStore;
import org.eclipse.edc.identitytrust.verification.SignatureSuiteRegistry;
import org.eclipse.edc.jsonld.util.JacksonJsonLd;
import org.eclipse.edc.runtime.metamodel.annotation.Extension;
import org.eclipse.edc.runtime.metamodel.annotation.Provider;
import org.eclipse.edc.security.signature.jws2020.JwsSignature2020Suite;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;

@Extension("Default Services Extension")
import java.util.Collection;
import java.util.Map;

import static org.eclipse.edc.identityhub.DefaultServicesExtension.NAME;

@Extension(NAME)
public class DefaultServicesExtension implements ServiceExtension {
@Provider(isDefault = true)
public CredentialStore createInMemStore() {
return new InMemoryCredentialStore();

public static final String NAME = "IdentityHub Default Services Extension";

@Override
public String name() {
return NAME;
}

@Provider(isDefault = true)
public PresentationGenerator createPresentationGenerator(ServiceExtensionContext context) {
context.getMonitor().warning(" #### Creating a default NOOP PresentationGenerator, that will always return 'null'!");
return (credentials, presentationDefinition) -> null;
public CredentialStore createInMemStore() {
return new InMemoryCredentialStore();

}

@Provider(isDefault = true)
Expand All @@ -45,4 +56,25 @@ public ScopeToCriterionTransformer createScopeTransformer(ServiceExtensionContex
return new EdcScopeToCriterionTransformer();
}

@Provider(isDefault = true)
public SignatureSuiteRegistry createSignatureSuiteRegistry() {
return new SignatureSuiteRegistry() {
private final Map<String, SignatureSuite> registry = Map.of(IdentityHubConstants.JWS_2020_SIGNATURE_SUITE, new JwsSignature2020Suite(JacksonJsonLd.createObjectMapper()));

@Override
public void register(String w3cIdentifier, SignatureSuite suite) {

}

@Override
public SignatureSuite getForId(String w3cIdentifier) {
return registry.get(w3cIdentifier);
}

@Override
public Collection<SignatureSuite> getAllSuites() {
return registry.values();
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.edc.identityhub.spi.ScopeToCriterionTransformer;
import org.eclipse.edc.identityhub.spi.generator.PresentationCreatorRegistry;
import org.eclipse.edc.identityhub.spi.generator.PresentationGenerator;
import org.eclipse.edc.identityhub.spi.model.IdentityHubConstants;
import org.eclipse.edc.identityhub.spi.resolution.CredentialQueryResolver;
import org.eclipse.edc.identityhub.spi.store.CredentialStore;
import org.eclipse.edc.identityhub.spi.verification.AccessTokenVerifier;
Expand All @@ -44,6 +45,7 @@
import java.net.URISyntaxException;
import java.time.Clock;

import static org.eclipse.edc.identityhub.core.CoreServicesExtension.NAME;
import static org.eclipse.edc.identityhub.spi.model.IdentityHubConstants.DID_CONTEXT_URL;
import static org.eclipse.edc.identityhub.spi.model.IdentityHubConstants.IATP_CONTEXT_URL;
import static org.eclipse.edc.identityhub.spi.model.IdentityHubConstants.JWS_2020_URL;
Expand All @@ -53,19 +55,22 @@
/**
* This extension provides core services for the IdentityHub that are not intended to be user-replaceable.
*/
@Extension(value = "Core Services extension")
@Extension(value = NAME)
public class CoreServicesExtension implements ServiceExtension {

public static final String NAME = "IdentityHub Core Services Extension";
@Setting(value = "Configure this IdentityHub's DID", required = true)
public static final String OWN_DID_PROPERTY = "edc.ih.iam.id";
public static final String PRESENTATION_EXCHANGE_V_1_JSON = "presentation-exchange.v1.json";
public static final String PRESENTATION_QUERY_V_08_JSON = "presentation-query.v08.json";
public static final String DID_JSON = "did.json";
public static final String JWS_2020_JSON = "jws2020.json";
public static final String CREDENTIALS_V_1_JSON = "credentials.v1.json";
private final String defaultSuite = "JsonWebSignature2020";
private final String defaultSuite = IdentityHubConstants.JWS_2020_SIGNATURE_SUITE;
private PresentationCreatorRegistryImpl presentationCreatorRegistry;
private JwtVerifier jwtVerifier;
private JwtValidator jwtValidator;

@Inject
private DidResolverRegistry didResolverRegistry;
@Inject
Expand All @@ -82,7 +87,11 @@ public class CoreServicesExtension implements ServiceExtension {
private Clock clock;
@Inject
private SignatureSuiteRegistry signatureSuiteRegistry;
private PresentationCreatorRegistryImpl presentationCreatorRegistry;

@Override
public String name() {
return NAME;
}

@Override
public void initialize(ServiceExtensionContext context) {
Expand Down Expand Up @@ -122,7 +131,7 @@ public PresentationCreatorRegistry presentationCreatorRegistry(ServiceExtensionC
presentationCreatorRegistry = new PresentationCreatorRegistryImpl();
presentationCreatorRegistry.addCreator(new JwtPresentationCreator(privateKeyResolver, clock, getOwnDid(context)), CredentialFormat.JWT);

var ldpIssuer = LdpIssuer.Builder.newInstance().jsonLd(jsonLd).build();
var ldpIssuer = LdpIssuer.Builder.newInstance().jsonLd(jsonLd).monitor(context.getMonitor()).build();
presentationCreatorRegistry.addCreator(new LdpPresentationCreator(privateKeyResolver, getOwnDid(context), signatureSuiteRegistry, defaultSuite, ldpIssuer, null),
CredentialFormat.JSON_LD);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.nimbusds.jose.jwk.OctetKeyPair;
import com.nimbusds.jose.jwk.gen.OctetKeyPairGenerator;
import org.eclipse.edc.iam.did.spi.key.PrivateKeyWrapper;
import org.eclipse.edc.identityhub.spi.model.IdentityHubConstants;
import org.eclipse.edc.identitytrust.model.CredentialFormat;
import org.eclipse.edc.identitytrust.model.VerifiableCredentialContainer;
import org.eclipse.edc.identitytrust.verification.SignatureSuiteRegistry;
Expand Down Expand Up @@ -56,7 +57,6 @@

class LdpPresentationCreatorTest extends PresentationCreatorTest {

public static final String JSON_WEB_SIGNATURE_2020 = "JsonWebSignature2020";
private final PrivateKeyResolver resolverMock = mock();
private final Map<String, Object> types = Map.of("types", List.of("VerifiablePresentation", "SomeOtherPresentationType"));
private LdpPresentationCreator creator;
Expand All @@ -66,12 +66,12 @@ void setup() throws URISyntaxException {
var vpSigningKey = createKey(KEY_ID);
when(resolverMock.resolvePrivateKey(eq(KEY_ID), any())).thenReturn(new OctetKeyPairWrapper(vpSigningKey));
var signatureSuiteRegistryMock = mock(SignatureSuiteRegistry.class);
when(signatureSuiteRegistryMock.getForId(JSON_WEB_SIGNATURE_2020)).thenReturn(new JwsSignature2020Suite(new ObjectMapper()));
when(signatureSuiteRegistryMock.getForId(IdentityHubConstants.JWS_2020_SIGNATURE_SUITE)).thenReturn(new JwsSignature2020Suite(new ObjectMapper()));
var ldpIssuer = LdpIssuer.Builder.newInstance()
.jsonLd(initializeJsonLd())
.monitor(mock())
.build();
creator = new LdpPresentationCreator(resolverMock, "did:web:test-issuer", signatureSuiteRegistryMock, JSON_WEB_SIGNATURE_2020, ldpIssuer,
creator = new LdpPresentationCreator(resolverMock, "did:web:test-issuer", signatureSuiteRegistryMock, IdentityHubConstants.JWS_2020_SIGNATURE_SUITE, ldpIssuer,
JacksonJsonLd.createObjectMapper());
}

Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ edc-identity-did-crypto = { module = "org.eclipse.edc:identity-did-crypto", vers
edc-identity-did-core = { module = "org.eclipse.edc:identity-did-core", version.ref = "edc" }
edc-identity-did-web = { module = "org.eclipse.edc:identity-did-web", version.ref = "edc" }
edc-iatp-service = { module = "org.eclipse.edc:identity-trust-service", version.ref = "edc" }
edc-iatp-core = { module = "org.eclipse.edc:identity-trust-core", version.ref = "edc" }
edc-vc-jwt = { module = "org.eclipse.edc:jwt-verifiable-credentials", version.ref = "edc" }
edc-vc-ldp = { module = "org.eclipse.edc:ldp-verifiable-credentials", version.ref = "edc" }
edc-ext-http = { module = "org.eclipse.edc:http", version.ref = "edc" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public interface IdentityHubConstants {
String VERIFIABLE_PRESENTATION_TYPE = "VerifiablePresentation";
String JWS_2020_URL = "https://w3id.org/security/suites/jws-2020/v1";
String DID_CONTEXT_URL = "https://www.w3.org/ns/did/v1";
String JWS_2020_SIGNATURE_SUITE = "JsonWebSignature2020";
String ED25519_SIGNATURE_SUITE = "Ed25519Signature2020"; // not used right now
}

0 comments on commit 6d9ec44

Please sign in to comment.