-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ParticipantIdentity): implements the ID extractor for the summar…
…y credential + E2E test
- Loading branch information
Showing
44 changed files
with
1,091 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
implementation(libs.edc.spi.core) | ||
implementation(libs.edc.spi.jsonld) | ||
} |
74 changes: 74 additions & 0 deletions
74
core/json-ld-core/src/main/java/org/eclipse/tractusx/edc/jsonld/JsonLdExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.tractusx.edc.jsonld; | ||
|
||
import org.eclipse.edc.jsonld.spi.JsonLd; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Inject; | ||
import org.eclipse.edc.spi.monitor.Monitor; | ||
import org.eclipse.edc.spi.result.Result; | ||
import org.eclipse.edc.spi.system.ServiceExtension; | ||
import org.eclipse.edc.spi.system.ServiceExtensionContext; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Map; | ||
|
||
import static java.lang.String.format; | ||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; | ||
|
||
public class JsonLdExtension implements ServiceExtension { | ||
|
||
private static final String PREFIX = "document" + File.separator; | ||
private static final Map<String, String> FILES = Map.of( | ||
"https://www.w3.org/2018/credentials/v1", PREFIX + "credential-v1.jsonld", | ||
"https://w3id.org/2023/catenax/credentials/summary/v1", PREFIX + "summary-vc-context-v1.jsonld"); | ||
@Inject | ||
private JsonLd jsonLdService; | ||
|
||
@Inject | ||
private Monitor monitor; | ||
|
||
@Override | ||
public void initialize(ServiceExtensionContext context) { | ||
FILES.entrySet().stream().map(this::mapToFile) | ||
.forEach(result -> result.onSuccess(entry -> jsonLdService.registerCachedDocument(entry.getKey(), entry.getValue())) | ||
.onFailure(failure -> monitor.warning("Failed to register cached json-ld document: " + failure.getFailureDetail()))); | ||
} | ||
|
||
private Result<Map.Entry<String, File>> mapToFile(Map.Entry<String, String> fileEntry) { | ||
return getResourceFile(fileEntry.getValue()) | ||
.map(file1 -> Map.entry(fileEntry.getKey(), file1)); | ||
} | ||
|
||
@NotNull | ||
private Result<File> getResourceFile(String name) { | ||
try (var stream = getClass().getClassLoader().getResourceAsStream(name)) { | ||
if (stream == null) { | ||
return Result.failure(format("Cannot find resource %s", name)); | ||
} | ||
|
||
var filename = Path.of(name).getFileName().toString(); | ||
var parts = filename.split("\\."); | ||
var tempFile = Files.createTempFile(parts[0], "." + parts[1]); | ||
Files.copy(stream, tempFile, REPLACE_EXISTING); | ||
return Result.success(tempFile.toFile()); | ||
} catch (Exception e) { | ||
return Result.failure(format("Cannot read resource %s: ", name)); | ||
} | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...-ld-core/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# | ||
# Copyright (c) 2023 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Apache License, Version 2.0 which is available at | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Contributors: | ||
# Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
# | ||
# | ||
|
||
org.eclipse.tractusx.edc.jsonld.JsonLdExtension |
237 changes: 237 additions & 0 deletions
237
core/json-ld-core/src/main/resources/document/credential-v1.jsonld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,237 @@ | ||
{ | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"id": "@id", | ||
"type": "@type", | ||
|
||
"VerifiableCredential": { | ||
"@id": "https://www.w3.org/2018/credentials#VerifiableCredential", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"id": "@id", | ||
"type": "@type", | ||
|
||
"cred": "https://www.w3.org/2018/credentials#", | ||
"sec": "https://w3id.org/security#", | ||
"xsd": "http://www.w3.org/2001/XMLSchema#", | ||
|
||
"credentialSchema": { | ||
"@id": "cred:credentialSchema", | ||
"@type": "@id", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"id": "@id", | ||
"type": "@type", | ||
|
||
"cred": "https://www.w3.org/2018/credentials#", | ||
|
||
"JsonSchemaValidator2018": "cred:JsonSchemaValidator2018" | ||
} | ||
}, | ||
"credentialStatus": {"@id": "cred:credentialStatus", "@type": "@id"}, | ||
"credentialSubject": {"@id": "cred:credentialSubject", "@type": "@id"}, | ||
"evidence": {"@id": "cred:evidence", "@type": "@id"}, | ||
"expirationDate": {"@id": "cred:expirationDate", "@type": "xsd:dateTime"}, | ||
"holder": {"@id": "cred:holder", "@type": "@id"}, | ||
"issued": {"@id": "cred:issued", "@type": "xsd:dateTime"}, | ||
"issuer": {"@id": "cred:issuer", "@type": "@id"}, | ||
"issuanceDate": {"@id": "cred:issuanceDate", "@type": "xsd:dateTime"}, | ||
"proof": {"@id": "sec:proof", "@type": "@id", "@container": "@graph"}, | ||
"refreshService": { | ||
"@id": "cred:refreshService", | ||
"@type": "@id", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"id": "@id", | ||
"type": "@type", | ||
|
||
"cred": "https://www.w3.org/2018/credentials#", | ||
|
||
"ManualRefreshService2018": "cred:ManualRefreshService2018" | ||
} | ||
}, | ||
"termsOfUse": {"@id": "cred:termsOfUse", "@type": "@id"}, | ||
"validFrom": {"@id": "cred:validFrom", "@type": "xsd:dateTime"}, | ||
"validUntil": {"@id": "cred:validUntil", "@type": "xsd:dateTime"} | ||
} | ||
}, | ||
|
||
"VerifiablePresentation": { | ||
"@id": "https://www.w3.org/2018/credentials#VerifiablePresentation", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"id": "@id", | ||
"type": "@type", | ||
|
||
"cred": "https://www.w3.org/2018/credentials#", | ||
"sec": "https://w3id.org/security#", | ||
|
||
"holder": {"@id": "cred:holder", "@type": "@id"}, | ||
"proof": {"@id": "sec:proof", "@type": "@id", "@container": "@graph"}, | ||
"verifiableCredential": {"@id": "cred:verifiableCredential", "@type": "@id", "@container": "@graph"} | ||
} | ||
}, | ||
|
||
"EcdsaSecp256k1Signature2019": { | ||
"@id": "https://w3id.org/security#EcdsaSecp256k1Signature2019", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"id": "@id", | ||
"type": "@type", | ||
|
||
"sec": "https://w3id.org/security#", | ||
"xsd": "http://www.w3.org/2001/XMLSchema#", | ||
|
||
"challenge": "sec:challenge", | ||
"created": {"@id": "http://purl.org/dc/terms/created", "@type": "xsd:dateTime"}, | ||
"domain": "sec:domain", | ||
"expires": {"@id": "sec:expiration", "@type": "xsd:dateTime"}, | ||
"jws": "sec:jws", | ||
"nonce": "sec:nonce", | ||
"proofPurpose": { | ||
"@id": "sec:proofPurpose", | ||
"@type": "@vocab", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"id": "@id", | ||
"type": "@type", | ||
|
||
"sec": "https://w3id.org/security#", | ||
|
||
"assertionMethod": {"@id": "sec:assertionMethod", "@type": "@id", "@container": "@set"}, | ||
"authentication": {"@id": "sec:authenticationMethod", "@type": "@id", "@container": "@set"} | ||
} | ||
}, | ||
"proofValue": "sec:proofValue", | ||
"verificationMethod": {"@id": "sec:verificationMethod", "@type": "@id"} | ||
} | ||
}, | ||
|
||
"EcdsaSecp256r1Signature2019": { | ||
"@id": "https://w3id.org/security#EcdsaSecp256r1Signature2019", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"id": "@id", | ||
"type": "@type", | ||
|
||
"sec": "https://w3id.org/security#", | ||
"xsd": "http://www.w3.org/2001/XMLSchema#", | ||
|
||
"challenge": "sec:challenge", | ||
"created": {"@id": "http://purl.org/dc/terms/created", "@type": "xsd:dateTime"}, | ||
"domain": "sec:domain", | ||
"expires": {"@id": "sec:expiration", "@type": "xsd:dateTime"}, | ||
"jws": "sec:jws", | ||
"nonce": "sec:nonce", | ||
"proofPurpose": { | ||
"@id": "sec:proofPurpose", | ||
"@type": "@vocab", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"id": "@id", | ||
"type": "@type", | ||
|
||
"sec": "https://w3id.org/security#", | ||
|
||
"assertionMethod": {"@id": "sec:assertionMethod", "@type": "@id", "@container": "@set"}, | ||
"authentication": {"@id": "sec:authenticationMethod", "@type": "@id", "@container": "@set"} | ||
} | ||
}, | ||
"proofValue": "sec:proofValue", | ||
"verificationMethod": {"@id": "sec:verificationMethod", "@type": "@id"} | ||
} | ||
}, | ||
|
||
"Ed25519Signature2018": { | ||
"@id": "https://w3id.org/security#Ed25519Signature2018", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"id": "@id", | ||
"type": "@type", | ||
|
||
"sec": "https://w3id.org/security#", | ||
"xsd": "http://www.w3.org/2001/XMLSchema#", | ||
|
||
"challenge": "sec:challenge", | ||
"created": {"@id": "http://purl.org/dc/terms/created", "@type": "xsd:dateTime"}, | ||
"domain": "sec:domain", | ||
"expires": {"@id": "sec:expiration", "@type": "xsd:dateTime"}, | ||
"jws": "sec:jws", | ||
"nonce": "sec:nonce", | ||
"proofPurpose": { | ||
"@id": "sec:proofPurpose", | ||
"@type": "@vocab", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"id": "@id", | ||
"type": "@type", | ||
|
||
"sec": "https://w3id.org/security#", | ||
|
||
"assertionMethod": {"@id": "sec:assertionMethod", "@type": "@id", "@container": "@set"}, | ||
"authentication": {"@id": "sec:authenticationMethod", "@type": "@id", "@container": "@set"} | ||
} | ||
}, | ||
"proofValue": "sec:proofValue", | ||
"verificationMethod": {"@id": "sec:verificationMethod", "@type": "@id"} | ||
} | ||
}, | ||
|
||
"RsaSignature2018": { | ||
"@id": "https://w3id.org/security#RsaSignature2018", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"challenge": "sec:challenge", | ||
"created": {"@id": "http://purl.org/dc/terms/created", "@type": "xsd:dateTime"}, | ||
"domain": "sec:domain", | ||
"expires": {"@id": "sec:expiration", "@type": "xsd:dateTime"}, | ||
"jws": "sec:jws", | ||
"nonce": "sec:nonce", | ||
"proofPurpose": { | ||
"@id": "sec:proofPurpose", | ||
"@type": "@vocab", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
|
||
"id": "@id", | ||
"type": "@type", | ||
|
||
"sec": "https://w3id.org/security#", | ||
|
||
"assertionMethod": {"@id": "sec:assertionMethod", "@type": "@id", "@container": "@set"}, | ||
"authentication": {"@id": "sec:authenticationMethod", "@type": "@id", "@container": "@set"} | ||
} | ||
}, | ||
"proofValue": "sec:proofValue", | ||
"verificationMethod": {"@id": "sec:verificationMethod", "@type": "@id"} | ||
} | ||
}, | ||
|
||
"proof": {"@id": "https://w3id.org/security#proof", "@type": "@id", "@container": "@graph"} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
core/json-ld-core/src/main/resources/document/summary-vc-context-v1.jsonld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
"summary": "https://w3id.org/2023/catenax/credentials/summary/", | ||
"id": "@id", | ||
"type": "@type", | ||
"SummaryCredential": { | ||
"@context": [ | ||
"https://www.w3.org/2018/credentials/v1" | ||
], | ||
"@id": "summary:SummaryCredential" | ||
}, | ||
"holderIdentifier": { | ||
"@id": "summary:holderIdentifier" | ||
}, | ||
"items": { | ||
"@id": "summary:items", | ||
"@type": "https://schema.org/Text" | ||
}, | ||
"contract-template": { | ||
"@id": "summary:contract-template", | ||
"@type": "https://schema.org/Text" | ||
} | ||
} | ||
} |
Oops, something went wrong.