diff --git a/core/lib/verifiable-presentation-lib/src/main/java/org/eclipse/edc/identithub/verifiablepresentation/PresentationCreatorRegistryImpl.java b/core/lib/verifiable-presentation-lib/src/main/java/org/eclipse/edc/identithub/verifiablepresentation/PresentationCreatorRegistryImpl.java index d2e48dc12..a9081596a 100644 --- a/core/lib/verifiable-presentation-lib/src/main/java/org/eclipse/edc/identithub/verifiablepresentation/PresentationCreatorRegistryImpl.java +++ b/core/lib/verifiable-presentation-lib/src/main/java/org/eclipse/edc/identithub/verifiablepresentation/PresentationCreatorRegistryImpl.java @@ -32,6 +32,7 @@ import java.util.Map; import static java.util.Optional.ofNullable; +import static org.eclipse.edc.identithub.verifiablepresentation.generators.PresentationGeneratorConstants.CONTROLLER_ADDITIONAL_DATA; public class PresentationCreatorRegistryImpl implements PresentationCreatorRegistry { @@ -73,7 +74,9 @@ public T createPresentation(String participantContextId, List new EdcException(f.getFailureDetail())); + var additionalDataWithController = new HashMap<>(additionalData); + additionalDataWithController.put(CONTROLLER_ADDITIONAL_DATA, did); - return (T) creator.generatePresentation(credentials, keyPair.getPrivateKeyAlias(), keyPair.getKeyId(), did, additionalData); + return (T) creator.generatePresentation(credentials, keyPair.getPrivateKeyAlias(), keyPair.getKeyId(), did, additionalDataWithController); } } diff --git a/core/lib/verifiable-presentation-lib/src/main/java/org/eclipse/edc/identithub/verifiablepresentation/VerifiablePresentationServiceImpl.java b/core/lib/verifiable-presentation-lib/src/main/java/org/eclipse/edc/identithub/verifiablepresentation/VerifiablePresentationServiceImpl.java index e03eb4bc2..dba1e9524 100644 --- a/core/lib/verifiable-presentation-lib/src/main/java/org/eclipse/edc/identithub/verifiablepresentation/VerifiablePresentationServiceImpl.java +++ b/core/lib/verifiable-presentation-lib/src/main/java/org/eclipse/edc/identithub/verifiablepresentation/VerifiablePresentationServiceImpl.java @@ -37,7 +37,6 @@ import static org.eclipse.edc.iam.verifiablecredentials.spi.VcConstants.VERIFIABLE_PRESENTATION_TYPE; import static org.eclipse.edc.iam.verifiablecredentials.spi.model.CredentialFormat.JSON_LD; import static org.eclipse.edc.identithub.verifiablepresentation.generators.LdpPresentationGenerator.TYPE_ADDITIONAL_DATA; -import static org.eclipse.edc.identithub.verifiablepresentation.generators.PresentationGeneratorConstants.CONTROLLER_ADDITIONAL_DATA; public class VerifiablePresentationServiceImpl implements VerifiablePresentationService { private final CredentialFormat defaultFormatVp; @@ -81,15 +80,13 @@ public Result createPresentation(String participant var additionalDataJwt = new HashMap(); ofNullable(audience).ifPresent(aud -> additionalDataJwt.put(AUDIENCE, audience)); - additionalDataJwt.put(CONTROLLER_ADDITIONAL_DATA, participantContextId); if (defaultFormatVp == JSON_LD) { // LDP-VPs cannot contain JWT VCs if (!ldpVcs.isEmpty()) { // todo: once we support PresentationDefinition, the types list could be dynamic JsonObject ldpVp = registry.createPresentation(participantContextId, ldpVcs, JSON_LD, Map.of( - TYPE_ADDITIONAL_DATA, List.of(VERIFIABLE_PRESENTATION_TYPE), - CONTROLLER_ADDITIONAL_DATA, participantContextId)); + TYPE_ADDITIONAL_DATA, List.of(VERIFIABLE_PRESENTATION_TYPE))); vpToken.add(ldpVp); } diff --git a/core/lib/verifiable-presentation-lib/src/test/java/org/eclipse/edc/identithub/verifiablepresentation/VerifiablePresentationServiceImplTest.java b/core/lib/verifiable-presentation-lib/src/test/java/org/eclipse/edc/identithub/verifiablepresentation/VerifiablePresentationServiceImplTest.java index d0ec46ab6..dc01ce208 100644 --- a/core/lib/verifiable-presentation-lib/src/test/java/org/eclipse/edc/identithub/verifiablepresentation/VerifiablePresentationServiceImplTest.java +++ b/core/lib/verifiable-presentation-lib/src/test/java/org/eclipse/edc/identithub/verifiablepresentation/VerifiablePresentationServiceImplTest.java @@ -81,7 +81,7 @@ void generate_defaultFormatLdp_containsOnlyLdpVc() { eq(TEST_PARTICIPANT_CONTEXT_ID), argThat(argument -> argument.size() == 2), eq(JSON_LD), - argThat(additional -> TEST_PARTICIPANT_CONTEXT_ID.equals(additional.get("controller")))); + argThat(additional -> additional.get("types") instanceof List typesList && typesList.contains("VerifiablePresentation"))); } @Test @@ -113,8 +113,7 @@ void generate_defaultFormatLdp_onlyJwtVcs() { eq(TEST_PARTICIPANT_CONTEXT_ID), argThat(argument -> argument.size() == 2), eq(JWT), - argThat(additional -> TEST_PARTICIPANT_CONTEXT_ID.equals(additional.get("controller")) && - TEST_AUDIENCE.equals(additional.get(JwtRegisteredClaimNames.AUDIENCE))) + argThat(additional -> TEST_AUDIENCE.equals(additional.get(JwtRegisteredClaimNames.AUDIENCE))) ); verify(registry, never()).createPresentation(eq(TEST_PARTICIPANT_CONTEXT_ID), any(), eq(JSON_LD), any()); verify(monitor).warning(eq("The VP was requested in JSON_LD format, but the request yielded 2 JWT-VCs, which cannot be transported in a LDP-VP. A second VP will be returned, containing JWT-VCs"));