Skip to content

Commit

Permalink
Add PD-generation test for VPR w/both "accepted" methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Oct 1, 2024
1 parent bba0c08 commit 4d37cc4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/oid4vp.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,11 @@ function _matchesInputDescriptor({
// exported for testing purposes only
export function _fromQueryByExampleQuery({credentialQuery, prefixJwtVcPath}) {
// determine `prefixJwtVcPath` default:
// if `credentialQuery` does NOT specify any `acceptedCryptosuites` but it
// does specify `acceptedEnvelopes: ['application/jwt']`, then default
// `prefixJwtVcPath` to `true`
// if `credentialQuery` specifies `acceptedEnvelopes: ['application/jwt']`,
// then default `prefixJwtVcPath` to `true`
if(prefixJwtVcPath === undefined &&
!credentialQuery.acceptedCryptosuites?.length > 0 &&
(credentialQuery.acceptedEnvelopes?.length === 1 &&
credentialQuery.acceptedEnvelopes?.[0] === 'application/jwt')) {
(Array.isArray(credentialQuery.acceptedEnvelopes) &&
credentialQuery.acceptedEnvelopes.includes?.('application/jwt'))) {
prefixJwtVcPath = true;
}

Expand Down
29 changes: 29 additions & 0 deletions tests/unit/oid4vp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,34 @@ describe('OID4VP', () => {
'$[\'vc\'][\'type\']'
]);
});

it('auto-detect to include "vc" w/both "accepted" methods', async () => {
const presentation_definition = _fromQueryByExampleQuery({
credentialQuery: {
reason: 'Please present your Driver\'s License to complete the ' +
'verification process.',
example: {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://w3id.org/vdl/v1',
'https://w3id.org/vdl/aamva/v1'
],
type: [
'Iso18013DriversLicenseCredential'
]
},
acceptedCryptosuites: ['bbs-2023'],
acceptedEnvelopes: ['application/jwt']
}
});
expect(presentation_definition.constraints.fields[0].path).to.eql([
'$[\'@context\']',
'$[\'vc\'][\'@context\']'
]);
expect(presentation_definition.constraints.fields[1].path).to.eql([
'$[\'type\']',
'$[\'vc\'][\'type\']'
]);
});
});
});

0 comments on commit 4d37cc4

Please sign in to comment.