fix: merge credential contexts into VP @context to preserve custom claims #894
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #893
Problem
When generating Verifiable Presentations (VPs), custom claims from embedded credentials (e.g.,
holderIdentifierfrom Tractus-X contexts) were being dropped during JSON-LD compaction. This occurred because:@contextarray only included hardcoded base contexts:https://www.w3.org/2018/credentials/v1https://identity.foundation/presentation-exchange/submission/v1PresentationApiController.createPresentation()(line 140), the JSON-LD processor dropped terms undefined in the available contextsSolution
This PR implements context merging in
LdpPresentationGeneratorto extract and merge@contextvalues from all embedded credentials with the VP's base contexts.Key Changes:
extractContextsFromCredentials()method to extract contexts from all credentialsmergeContexts()method to combine base and credential contexts without duplicatesgeneratePresentation()to use merged contexts when building the VPExample:
Before:
{ "@context": [ "https://www.w3.org/2018/credentials/v1", "https://identity.foundation/presentation-exchange/submission/v1" ], "verifiableCredential": [...] }After:
{ "@context": [ "https://www.w3.org/2018/credentials/v1", "https://identity.foundation/presentation-exchange/submission/v1", "https://w3id.org/tractusx-trust/v0.8" // ✅ Merged from credential ], "verifiableCredential": [...] }Testing
tractusx.v08.json,custom.v1.json)identity-hub-corepass ✅Files Changed
core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/core/services/verifiablepresentation/generators/LdpPresentationGenerator.javacore/identity-hub-core/src/test/java/org/eclipse/edc/identityhub/core/services/verifiablepresentation/generators/LdpPresentationGeneratorTest.javacore/identity-hub-core/src/test/resources/tractusx.v08.json(new)core/identity-hub-core/src/test/resources/custom.v1.json(new)Checklist
Branch:
fix/893-merge-credential-contexts-vpCommit:
39833797Ready for review 🚀