-
Notifications
You must be signed in to change notification settings - Fork 2
fix/sdjwt import over oid4vc #529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ab9c2fe
feat: support importing decoded SD-JWT VC payloads
maycon-mello af3d813
feat: honor issuer-advertised format in OID4VCI credential acquisition
maycon-mello 23e053a
fix: lint formatting in OID4VCI tests
maycon-mello 6f1f592
fix: address PR review feedback for SD-JWT and OID4VCI
maycon-mello b83124f
fix: match offered credential id in legacy array-shaped supported list
maycon-mello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| export function resolveOfferedCredentialConfig(client) { | ||
| const supported = client.getCredentialsSupported(); | ||
| const offerIds = | ||
| client.credentialOffer?.credential_offer?.credential_configuration_ids ?? | ||
| client.credentialOffer?.credential_configuration_ids ?? | ||
| []; | ||
|
|
||
| if (Array.isArray(supported)) { | ||
| const matchedLegacy = supported.find( | ||
| entry => entry?.id && offerIds.includes(entry.id), | ||
| ); | ||
| return matchedLegacy ?? supported[0]; | ||
| } | ||
|
|
||
| const matched = offerIds.map(id => supported[id]).find(Boolean); | ||
| return matched ?? Object.values(supported)[0]; | ||
| } | ||
|
|
||
| const KNOWN_FORMATS = new Set([ | ||
| 'vc+sd-jwt', | ||
| 'dc+sd-jwt', | ||
| 'ldp_vc', | ||
| 'jwt_vc_json', | ||
| 'jwt_vc_json-ld', | ||
| 'jwt_vc', | ||
| ]); | ||
|
|
||
| export function resolveFormatAndType(config) { | ||
| const scopeSegments = config.scope?.split(':') ?? []; | ||
| const scopeTail = scopeSegments.slice(-1)[0]; | ||
| const scopePrefix = scopeSegments.length > 1 ? scopeSegments[0] : undefined; | ||
| const definitionType = config.credential_definition?.type?.slice(-1)[0]; | ||
|
|
||
| const format = | ||
| config.format ?? | ||
| (scopePrefix && KNOWN_FORMATS.has(scopePrefix) ? scopePrefix : 'ldp_vc'); | ||
|
|
||
| const credentialTypes = | ||
| format === 'vc+sd-jwt' || format === 'dc+sd-jwt' | ||
| ? config.vct | ||
| : definitionType ?? scopeTail; | ||
|
|
||
| return {format, credentialTypes}; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| import {resolveOfferedCredentialConfig, resolveFormatAndType} from './oid4vci'; | ||
|
|
||
| function makeClient({supported, offerIds}) { | ||
| return { | ||
| getCredentialsSupported: () => supported, | ||
| credentialOffer: offerIds | ||
| ? {credential_offer: {credential_configuration_ids: offerIds}} | ||
| : undefined, | ||
| }; | ||
| } | ||
|
|
||
| describe('OID4VCI offer resolution', () => { | ||
| describe('resolveOfferedCredentialConfig', () => { | ||
| it('returns the entry matching the offered configuration id', () => { | ||
| const supported = { | ||
| 'ldp_vc:MyCredential': {format: 'vc+sd-jwt', vct: 'MyCredential'}, | ||
| 'ldp_vc:OtherCredential': {format: 'ldp_vc'}, | ||
| }; | ||
| const client = makeClient({ | ||
| supported, | ||
| offerIds: ['ldp_vc:MyCredential'], | ||
| }); | ||
|
|
||
| expect(resolveOfferedCredentialConfig(client)).toBe( | ||
| supported['ldp_vc:MyCredential'], | ||
| ); | ||
| }); | ||
|
|
||
| it('falls back to the first record entry when the offer id does not match', () => { | ||
| const supported = { | ||
| 'ldp_vc:A': {format: 'ldp_vc'}, | ||
| 'ldp_vc:B': {format: 'vc+sd-jwt'}, | ||
| }; | ||
| const client = makeClient({supported, offerIds: ['nonexistent']}); | ||
|
|
||
| expect(resolveOfferedCredentialConfig(client)).toBe( | ||
| supported['ldp_vc:A'], | ||
| ); | ||
| }); | ||
|
|
||
| it('handles array-shaped credentialsSupported by returning the first entry', () => { | ||
| const supported = [ | ||
| {format: 'vc+sd-jwt', vct: 'MyCredential'}, | ||
| {format: 'ldp_vc'}, | ||
| ]; | ||
| const client = makeClient({supported, offerIds: []}); | ||
|
|
||
| expect(resolveOfferedCredentialConfig(client)).toBe(supported[0]); | ||
| }); | ||
|
|
||
| it('matches an array-shaped entry by id when the offer provides one', () => { | ||
| const supported = [ | ||
| {id: 'ldp_vc:A', format: 'ldp_vc'}, | ||
| {id: 'sdjwt:B', format: 'vc+sd-jwt', vct: 'B'}, | ||
| ]; | ||
| const client = makeClient({supported, offerIds: ['sdjwt:B']}); | ||
|
|
||
| expect(resolveOfferedCredentialConfig(client)).toBe(supported[1]); | ||
| }); | ||
|
|
||
| it('falls back to the first array entry when no offered id matches', () => { | ||
| const supported = [ | ||
| {id: 'ldp_vc:A', format: 'ldp_vc'}, | ||
| {id: 'sdjwt:B', format: 'vc+sd-jwt'}, | ||
| ]; | ||
| const client = makeClient({supported, offerIds: ['nonexistent']}); | ||
|
|
||
| expect(resolveOfferedCredentialConfig(client)).toBe(supported[0]); | ||
| }); | ||
|
|
||
| it('reads offer ids from credentialOffer.credential_configuration_ids when not nested', () => { | ||
| const supported = { | ||
| 'ldp_vc:Wanted': {format: 'vc+sd-jwt', vct: 'Wanted'}, | ||
| 'ldp_vc:Other': {format: 'ldp_vc'}, | ||
| }; | ||
| const client = { | ||
| getCredentialsSupported: () => supported, | ||
| credentialOffer: {credential_configuration_ids: ['ldp_vc:Wanted']}, | ||
| }; | ||
|
|
||
| expect(resolveOfferedCredentialConfig(client)).toBe( | ||
| supported['ldp_vc:Wanted'], | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('resolveFormatAndType', () => { | ||
| it('returns vct as credentialTypes for vc+sd-jwt', () => { | ||
| const result = resolveFormatAndType({ | ||
| format: 'vc+sd-jwt', | ||
| vct: 'MyCredential', | ||
| scope: 'ldp_vc:MyCredential', | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| format: 'vc+sd-jwt', | ||
| credentialTypes: 'MyCredential', | ||
| }); | ||
| }); | ||
|
|
||
| it('returns the last credential_definition.type entry for ldp_vc', () => { | ||
| const result = resolveFormatAndType({ | ||
| format: 'ldp_vc', | ||
| credential_definition: { | ||
| type: ['VerifiableCredential', 'UniversityDegreeCredential'], | ||
| }, | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| format: 'ldp_vc', | ||
| credentialTypes: 'UniversityDegreeCredential', | ||
| }); | ||
| }); | ||
|
|
||
| it('falls back to the scope suffix when credential_definition is missing', () => { | ||
| const result = resolveFormatAndType({ | ||
| format: 'ldp_vc', | ||
| scope: 'ldp_vc:LegacyCredential', | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| format: 'ldp_vc', | ||
| credentialTypes: 'LegacyCredential', | ||
| }); | ||
| }); | ||
|
|
||
| it('returns undefined credentialTypes when nothing identifies the type', () => { | ||
| const result = resolveFormatAndType({format: 'jwt_vc_json'}); | ||
|
|
||
| expect(result).toEqual({ | ||
| format: 'jwt_vc_json', | ||
| credentialTypes: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| it('derives format from a known scope prefix when format is missing', () => { | ||
| const result = resolveFormatAndType({ | ||
| scope: 'vc+sd-jwt:MyCredential', | ||
| vct: 'MyCredential', | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| format: 'vc+sd-jwt', | ||
| credentialTypes: 'MyCredential', | ||
| }); | ||
| }); | ||
|
|
||
| it('defaults to ldp_vc when format and a recognizable scope prefix are missing', () => { | ||
| const result = resolveFormatAndType({ | ||
| scope: 'MyCredential', | ||
| credential_definition: { | ||
| type: ['VerifiableCredential', 'MyCredential'], | ||
| }, | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| format: 'ldp_vc', | ||
| credentialTypes: 'MyCredential', | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.