Skip to content

Commit

Permalink
Make vc prefix optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianorwhatever authored and dlongley committed Nov 27, 2023
1 parent cd8e233 commit c3cedfe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
38 changes: 27 additions & 11 deletions lib/oid4vp.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export async function toVpr({
}

// converts a VPR to partial "authorization request"
export function fromVpr({verifiablePresentationRequest, strict = false} = {}) {
export function fromVpr({verifiablePresentationRequest, strict = false, prefixVC = false} = {}) {

Check failure on line 299 in lib/oid4vp.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

This line has a length of 97. Maximum allowed is 80
try {
let {query} = verifiablePresentationRequest;
if(!Array.isArray(query)) {
Expand All @@ -322,7 +322,10 @@ export function fromVpr({verifiablePresentationRequest, strict = false} = {}) {
response_type: 'vp_token',
presentation_definition: {
id: uuid(),
input_descriptors: credentialQuery.map(_fromQueryByExampleQuery)
input_descriptors: credentialQuery.map((q) => _fromQueryByExampleQuery({

Check failure on line 325 in lib/oid4vp.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

Unexpected parentheses around single function argument
credentialQuery: q,
prefixVC
}))
},
response_mode: 'direct_post'
};
Expand Down Expand Up @@ -558,7 +561,7 @@ function _matchesInputDescriptor({
}

// exported for testing purposes only
export function _fromQueryByExampleQuery(credentialQuery) {
export function _fromQueryByExampleQuery({credentialQuery, prefixVC}) {
const fields = [];
const inputDescriptor = {
id: uuid(),
Expand Down Expand Up @@ -593,13 +596,16 @@ export function _fromQueryByExampleQuery(credentialQuery) {
filter.type = 'string',
filter.const = value;
}
const vcPath = [...path];
vcPath.splice(1, 0, 'vc');
const fieldsPath = [JSONPath.toPathString(path)];
// Include 'vc' path for JWT purposes
if(prefixVC) {
const vcPath = [...path];
vcPath.splice(1, 0, 'vc');
fieldsPath.push(JSONPath.toPathString(vcPath));
}

fields.push({
path: [
JSONPath.toPathString(path),
JSONPath.toPathString(vcPath)
],
path: fieldsPath,
filter
});

Expand Down Expand Up @@ -736,7 +742,12 @@ function _adjustErroneousPaths(paths) {
// JWT-secured VC, such that only actual VC paths remain
const removed = paths.filter(p => !_isPresentationSubmissionPath(p));
return removed.map(p => {
return !_isJWTPath(p) ? p : '$' + p.slice('$.vc'.length);
if (_isJWTPath(p)) {

Check failure on line 745 in lib/oid4vp.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

Unexpected space(s) after "if"
return '$' + p.slice('$.vc'.length);
} else if (_isSquareJWTPath(p)) {

Check failure on line 747 in lib/oid4vp.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

Unexpected space(s) after "if"
return '$' + p.slice('$[\'vc\']'.length);
}
return p;
});
}

Expand Down Expand Up @@ -795,9 +806,14 @@ function _get(sp, name) {
}

function _isPresentationSubmissionPath(path) {
return path.startsWith('$.verifiableCredential[') || path.startsWith('$.vp.');
return path.startsWith('$.verifiableCredential[') || path.startsWith('$.vp.')
|| path.startsWith('$[\'verifiableCredential') || path.startsWith('$[\'vp');

Check failure on line 810 in lib/oid4vp.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

'||' should be placed at the end of the line
}

function _isJWTPath(path) {
return path.startsWith('$.vc.');
}

function _isSquareJWTPath(path) {
return path.startsWith('$[\'vc\']');
}

Check failure on line 819 in lib/oid4vp.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

Newline required at end of file but not found
27 changes: 15 additions & 12 deletions tests/unit/oid4vp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ describe('OID4VP', () => {
describe('constructor', () => {
it('should map a QueryByExample to a Presentation Definition', async () => {
const presentation_definition = _fromQueryByExampleQuery({
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'
]
}
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'
]
}
},
prefixVC: true
});
expect(presentation_definition.constraints.fields[0].path).to.eql([
'$[\'@context\']',
Expand Down

0 comments on commit c3cedfe

Please sign in to comment.