Skip to content

fix(core): add customContexts to default context#2599

Open
lotharking wants to merge 4 commits intoopenwallet-foundation:mainfrom
lotharking:fix/w3c-credentials-custom-contexts
Open

fix(core): add customContexts to default context#2599
lotharking wants to merge 4 commits intoopenwallet-foundation:mainfrom
lotharking:fix/w3c-credentials-custom-contexts

Conversation

@lotharking
Copy link
Copy Markdown
Contributor

Previously, adding a custom document loader required implementing a completely new class. This often caused confusion and introduced unnecessary complexity, especially when only a single additional requirement was needed. By adding a complementary custom document loader, users can add new contexts for specific scenarios.

Signed-off-by: andres vallecilla <andresfelipe083195@hotmail.com>
@lotharking lotharking requested a review from a team as a code owner December 17, 2025 23:26
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Dec 17, 2025

⚠️ No Changeset found

Latest commit: 2a2682e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown
Contributor

@TimoGlastra TimoGlastra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you provide a custom document loader? Then the customContexts does not really have effect right?

Should we make this a parameter to the default document loader, e.g.

documenLoader: defaultDocumentLoader(additionalContexts)

So it's more clear that this is an extension to the default document loader?

Or we should change the behavior maybe, that if a custom context is defined it will ALWAYS use that first, otherwise it will fallback to the document loader. That way the custom contexts are always used

@lotharking
Copy link
Copy Markdown
Contributor Author

With this implementation, we can reuse the default document loader and create a customized by extending it with additional context.
For example, a helper factory can wrap defaultDocumentLoader and inject custom context while preserving the default behavior.

export const createCustomDocumentLoader =
  (customContexts: Record<string, unknown> = {}) =>
  (agentContext: AgentContext): DocumentLoader => {
    const coreLoader = defaultDocumentLoader(agentContext, customContexts)
    return coreLoader
  }
export const CRED_EXAM_V2 = JSON.parse('{"@context":{"@vocab":"https://www.w3.org/ns/credentials/examples#"}}')
export const customContext = {
  'https://www.w3.org/ns/credentials/examples/v2': CRED_EXAM_V2,
}

const agentOptions = getAgentOptions(
  'W3cCredentialsApi',
  {},
  {},
  {
    w3cCredentials: new W3cCredentialsModule({
      documentLoader: createCustomDocumentLoader(customContext),
    }),
  }
)

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.

2 participants