@digitalbazaar/oid4-client 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/oid4vp.js +31 -6
- package/package.json +1 -1
package/lib/oid4vp.js
CHANGED
|
@@ -296,7 +296,9 @@ export async function toVpr({
|
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
// converts a VPR to partial "authorization request"
|
|
299
|
-
export function fromVpr({
|
|
299
|
+
export function fromVpr({
|
|
300
|
+
verifiablePresentationRequest, strict = false, prefixJwtVcPath = false
|
|
301
|
+
} = {}) {
|
|
300
302
|
try {
|
|
301
303
|
let {query} = verifiablePresentationRequest;
|
|
302
304
|
if(!Array.isArray(query)) {
|
|
@@ -322,7 +324,10 @@ export function fromVpr({verifiablePresentationRequest, strict = false} = {}) {
|
|
|
322
324
|
response_type: 'vp_token',
|
|
323
325
|
presentation_definition: {
|
|
324
326
|
id: uuid(),
|
|
325
|
-
input_descriptors: credentialQuery.map(_fromQueryByExampleQuery
|
|
327
|
+
input_descriptors: credentialQuery.map(q => _fromQueryByExampleQuery({
|
|
328
|
+
credentialQuery: q,
|
|
329
|
+
prefixJwtVcPath
|
|
330
|
+
}))
|
|
326
331
|
},
|
|
327
332
|
response_mode: 'direct_post'
|
|
328
333
|
};
|
|
@@ -557,7 +562,8 @@ function _matchesInputDescriptor({
|
|
|
557
562
|
return true;
|
|
558
563
|
}
|
|
559
564
|
|
|
560
|
-
|
|
565
|
+
// exported for testing purposes only
|
|
566
|
+
export function _fromQueryByExampleQuery({credentialQuery, prefixJwtVcPath}) {
|
|
561
567
|
const fields = [];
|
|
562
568
|
const inputDescriptor = {
|
|
563
569
|
id: uuid(),
|
|
@@ -592,8 +598,15 @@ function _fromQueryByExampleQuery(credentialQuery) {
|
|
|
592
598
|
filter.type = 'string',
|
|
593
599
|
filter.const = value;
|
|
594
600
|
}
|
|
601
|
+
const fieldsPath = [JSONPath.toPathString(path)];
|
|
602
|
+
// include 'vc' path for queries against JWT payloads instead of VCs
|
|
603
|
+
if(prefixJwtVcPath) {
|
|
604
|
+
const vcPath = [...path];
|
|
605
|
+
vcPath.splice(1, 0, 'vc');
|
|
606
|
+
fieldsPath.push(JSONPath.toPathString(vcPath));
|
|
607
|
+
}
|
|
595
608
|
fields.push({
|
|
596
|
-
path:
|
|
609
|
+
path: fieldsPath,
|
|
597
610
|
filter
|
|
598
611
|
});
|
|
599
612
|
|
|
@@ -730,7 +743,13 @@ function _adjustErroneousPaths(paths) {
|
|
|
730
743
|
// JWT-secured VC, such that only actual VC paths remain
|
|
731
744
|
const removed = paths.filter(p => !_isPresentationSubmissionPath(p));
|
|
732
745
|
return removed.map(p => {
|
|
733
|
-
|
|
746
|
+
if(_isJWTPath(p)) {
|
|
747
|
+
return '$' + p.slice('$.vc'.length);
|
|
748
|
+
}
|
|
749
|
+
if(_isSquareJWTPath(p)) {
|
|
750
|
+
return '$' + p.slice('$[\'vc\']'.length);
|
|
751
|
+
}
|
|
752
|
+
return p;
|
|
734
753
|
});
|
|
735
754
|
}
|
|
736
755
|
|
|
@@ -789,9 +808,15 @@ function _get(sp, name) {
|
|
|
789
808
|
}
|
|
790
809
|
|
|
791
810
|
function _isPresentationSubmissionPath(path) {
|
|
792
|
-
return path.startsWith('$.verifiableCredential[') ||
|
|
811
|
+
return path.startsWith('$.verifiableCredential[') ||
|
|
812
|
+
path.startsWith('$.vp.') ||
|
|
813
|
+
path.startsWith('$[\'verifiableCredential') || path.startsWith('$[\'vp');
|
|
793
814
|
}
|
|
794
815
|
|
|
795
816
|
function _isJWTPath(path) {
|
|
796
817
|
return path.startsWith('$.vc.');
|
|
797
818
|
}
|
|
819
|
+
|
|
820
|
+
function _isSquareJWTPath(path) {
|
|
821
|
+
return path.startsWith('$[\'vc\']');
|
|
822
|
+
}
|