Skip to content

Commit

Permalink
fix: use controller did when passing additionalData
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas committed Jul 24, 2024
1 parent c444f67 commit 0378c49
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -73,7 +74,9 @@ public <T> T createPresentation(String participantContextId, List<VerifiableCred
.map(ParticipantContext::getDid)
.orElseThrow(f -> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,15 +80,13 @@ public Result<PresentationResponseMessage> createPresentation(String participant

var additionalDataJwt = new HashMap<String, Object>();
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit 0378c49

Please sign in to comment.