@digitalbazaar/oid4-client 5.5.0 → 5.6.1

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.
@@ -7,6 +7,7 @@ import {JSONPath} from 'jsonpath-plus';
7
7
  import jsonpointer from 'json-pointer';
8
8
 
9
9
  const VALUE_TYPES = new Set(['string', 'number', 'boolean']);
10
+ const SUPPORTED_JWT_ALGS = ['EdDSA', 'Ed25519', 'ES256', 'ES384'];
10
11
 
11
12
  export function presentationDefinitionToVprGroups({
12
13
  presentation_definition, strict = false
@@ -42,27 +43,45 @@ export function vprGroupsToPresentationDefinition({
42
43
  input_descriptors
43
44
  };
44
45
 
46
+ // if there is more than one group, create submission requirements that will
47
+ // be populated for each group
48
+ let defaultGroupId;
49
+ let submission_requirements;
50
+ if(groupMap.size > 1) {
51
+ defaultGroupId = crypto.randomUUID();
52
+ submission_requirements = [];
53
+ }
54
+
55
+ let acceptsVpJwt = false;
56
+ let acceptsVcJwt = false;
57
+
58
+ const ldpVpProofTypes = new Set();
59
+ const ldpVcProofTypes = new Set();
45
60
  // note: same group ID is logical "AND" and different group ID is "OR"
46
- const groups = [...groupMap.values()];
47
- for(const queries of groups) {
48
- // only `QueryByExample` is convertible
49
- const queryByExamples = queries.get('QueryByExample');
50
- if(!queryByExamples) {
51
- continue;
61
+ for(const [groupId, queries] of groupMap.entries()) {
62
+ // add to submission_requirements if present
63
+ if(submission_requirements) {
64
+ submission_requirements.push({
65
+ rule: 'pick',
66
+ count: 1,
67
+ from: groupId ?? defaultGroupId
68
+ });
52
69
  }
53
70
 
71
+ const queryByExamples = queries.get('QueryByExample');
72
+
54
73
  // for each `QueryByExample`, add another input descriptor (for every
55
74
  // "credentialQuery" within it
56
75
  for(const queryByExample of queryByExamples) {
57
76
  // should only be one `credentialQuery` but handle each one as a new
58
- // set of input descriptors
77
+ // input descriptor
59
78
  const all = Array.isArray(queryByExample.credentialQuery) ?
60
79
  queryByExample.credentialQuery : [queryByExample.credentialQuery];
61
80
  for(const credentialQuery of all) {
62
81
  const inputDescriptor = _fromQueryByExampleQuery({
63
82
  credentialQuery, prefixJwtVcPath
64
83
  });
65
- input_descriptors.push(inputDescriptor);
84
+
66
85
  const {acceptedEnvelopes, acceptedCryptosuites} = credentialQuery;
67
86
  const shouldAddFormat = acceptedEnvelopes || acceptedCryptosuites;
68
87
  if(shouldAddFormat && !inputDescriptor.format) {
@@ -70,18 +89,74 @@ export function vprGroupsToPresentationDefinition({
70
89
  }
71
90
  if(acceptedEnvelopes?.includes('application/jwt')) {
72
91
  inputDescriptor.format.jwt_vc_json = {
73
- alg: ['EdDSA', 'Ed25519', 'ES256', 'ES384']
92
+ alg: SUPPORTED_JWT_ALGS
74
93
  };
94
+ acceptsVcJwt = true;
75
95
  }
76
96
  if(acceptedCryptosuites) {
97
+ const cryptosuites = acceptedCryptosuites
98
+ .map(({cryptosuite}) => cryptosuite);
77
99
  inputDescriptor.format.ldp_vc = {
78
- proof_type: acceptedCryptosuites.map(({cryptosuite}) => cryptosuite)
100
+ proof_type: cryptosuites
79
101
  };
102
+ for(const cryptosuite of cryptosuites) {
103
+ ldpVcProofTypes.add(cryptosuite);
104
+ }
105
+ }
106
+
107
+ if(submission_requirements) {
108
+ inputDescriptor.group = [submission_requirements.at(-1).from];
109
+ }
110
+
111
+ input_descriptors.push(inputDescriptor);
112
+ }
113
+ }
114
+
115
+ const didAuthentications = queries.get('DIDAuthentication');
116
+ for(const didAuthentication of didAuthentications) {
117
+ const {acceptedEnvelopes, acceptedCryptosuites} = didAuthentication;
118
+
119
+ if(acceptedEnvelopes?.includes('application/jwt')) {
120
+ acceptsVpJwt = true;
121
+ }
122
+ if(acceptedCryptosuites) {
123
+ const cryptosuites = acceptedCryptosuites
124
+ .map(({cryptosuite}) => cryptosuite);
125
+ for(const cryptosuite of cryptosuites) {
126
+ ldpVpProofTypes.add(cryptosuite);
80
127
  }
81
128
  }
82
129
  }
83
130
  }
84
131
 
132
+ // add `submission_requirements` if
133
+ if(submission_requirements) {
134
+ presentationDefinition.submission_requirements = submission_requirements;
135
+ }
136
+
137
+ const shouldAddFormat = acceptsVcJwt || acceptsVpJwt ||
138
+ ldpVcProofTypes.size > 0 || ldpVpProofTypes.size > 0;
139
+ if(shouldAddFormat && !presentationDefinition.format) {
140
+ presentationDefinition.format = {};
141
+ }
142
+
143
+ if(acceptsVcJwt) {
144
+ presentationDefinition.format.jwt_vc_json = {alg: SUPPORTED_JWT_ALGS};
145
+ }
146
+ if(acceptsVpJwt) {
147
+ presentationDefinition.format.jwt_vp = {alg: SUPPORTED_JWT_ALGS};
148
+ presentationDefinition.format.jwt_vp_json = {alg: SUPPORTED_JWT_ALGS};
149
+ }
150
+
151
+ if(ldpVcProofTypes.size > 0) {
152
+ const proof_type = [...ldpVcProofTypes];
153
+ presentationDefinition.format.ldp_vc = {proof_type};
154
+ }
155
+ if(ldpVpProofTypes.size > 0) {
156
+ const proof_type = [...ldpVpProofTypes];
157
+ presentationDefinition.format.ldp_vp = {proof_type};
158
+ }
159
+
85
160
  return presentationDefinition;
86
161
  }
87
162
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalbazaar/oid4-client",
3
- "version": "5.5.0",
3
+ "version": "5.6.1",
4
4
  "description": "An OID4 (VC + VP) client",
5
5
  "homepage": "https://github.com/digitalbazaar/oid4-client",
6
6
  "author": {