Skip to content

Conversation

@wahidulazam
Copy link

@wahidulazam wahidulazam commented Jan 8, 2026

Description

Fixes #893

Problem

When generating Verifiable Presentations (VPs), custom claims from embedded credentials (e.g., holderIdentifier from Tractus-X contexts) were being dropped during JSON-LD compaction. This occurred because:

  1. The VP's @context array only included hardcoded base contexts:
    • https://www.w3.org/2018/credentials/v1
    • https://identity.foundation/presentation-exchange/submission/v1
  2. Custom contexts from embedded credentials were not propagated to the VP
  3. When the VP was compacted in PresentationApiController.createPresentation() (line 140), the JSON-LD processor dropped terms undefined in the available contexts

Solution

This PR implements context merging in LdpPresentationGenerator to extract and merge @context values from all embedded credentials with the VP's base contexts.

Key Changes:

  • Added extractContextsFromCredentials() method to extract contexts from all credentials
  • Added mergeContexts() method to combine base and credential contexts without duplicates
  • Modified generatePresentation() to use merged contexts when building the VP
  • Handles both string and array context formats gracefully
  • Ensures proper ordering: W3C_CREDENTIALS_URL first, then PRESENTATION_EXCHANGE_URL, then credential contexts

Example:

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

  • Added 5 comprehensive test cases covering:
    • Custom context merging
    • Single context strings vs arrays
    • Multiple credentials with different contexts
    • Duplicate context avoidance
    • Missing contexts handling
  • Added test JSON-LD context files (tractusx.v08.json, custom.v1.json)
  • All 98 tests in identity-hub-core pass ✅
  • Full project build successful ✅
  • Checkstyle passed ✅

Files Changed

  • core/identity-hub-core/src/main/java/org/eclipse/edc/identityhub/core/services/verifiablepresentation/generators/LdpPresentationGenerator.java
  • core/identity-hub-core/src/test/java/org/eclipse/edc/identityhub/core/services/verifiablepresentation/generators/LdpPresentationGeneratorTest.java
  • core/identity-hub-core/src/test/resources/tractusx.v08.json (new)
  • core/identity-hub-core/src/test/resources/custom.v1.json (new)

Checklist

  • Code follows the project's style guidelines
  • Tests added for new functionality
  • All tests pass
  • Documentation updated where necessary
  • Commit message follows conventional commits format
  • Issue reference included in commit message

Branch: fix/893-merge-credential-contexts-vp
Commit: 39833797
Ready for review 🚀

…aims

When generating Verifiable Presentations, custom claims from credentials
were being dropped during JSON-LD compaction because the VP's @context
array only included hardcoded base contexts.

This fix extracts @context values from all embedded credentials and merges
them with the base VP contexts (W3C_CREDENTIALS_URL and PRESENTATION_EXCHANGE_URL),
ensuring custom terms are preserved during the compaction step in
PresentationApiController.

Changes:
- Add extractContextsFromCredentials() to extract contexts from all credentials
- Add mergeContexts() to combine base and credential contexts without duplicates
- Update generatePresentation() to use merged contexts when building VP
- Handle both string and array context formats gracefully
- Add comprehensive test coverage (5 new test cases)
- Add test JSON-LD context files for Tractus-X and custom contexts

All 98 tests in identity-hub-core pass.

Fixes eclipse-edc#893
@wahidulazam wahidulazam requested a review from a team as a code owner January 8, 2026 16:36
@wahidulazam wahidulazam closed this Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON-LD Compaction Drops Custom Claims in Verifiable Presentations

1 participant