@bedrock/vc-delivery 5.3.4 → 5.4.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.
Files changed (2) hide show
  1. package/lib/oid4/http.js +37 -23
  2. package/package.json +1 -1
package/lib/oid4/http.js CHANGED
@@ -62,8 +62,17 @@ export async function createRoutes({
62
62
  authorizationResponse: `${openIdRoute}/client/authorization/response`
63
63
  };
64
64
 
65
- // urlencoded body parser (extended=true for rich JSON-like representation)
66
- const urlencoded = bodyParser.urlencoded({extended: true});
65
+ // urlencoded body parser
66
+ const urlencodedSmall = bodyParser.urlencoded({
67
+ // (extended=true for rich JSON-like representation)
68
+ extended: true
69
+ });
70
+ const urlencodedLarge = bodyParser.urlencoded({
71
+ // (extended=true for rich JSON-like representation)
72
+ extended: true,
73
+ // allow larger payloads
74
+ limit: '10MB'
75
+ });
67
76
 
68
77
  /* Note: The well-known metadata paths for the OID4VCI spec have been
69
78
  specified in at least two different ways over time, including
@@ -142,7 +151,7 @@ export async function createRoutes({
142
151
  app.post(
143
152
  routes.token,
144
153
  cors(),
145
- urlencoded,
154
+ urlencodedSmall,
146
155
  validate({bodySchema: openIdTokenBody}),
147
156
  getConfigMiddleware,
148
157
  getExchange,
@@ -194,28 +203,33 @@ export async function createRoutes({
194
203
  return;
195
204
  }
196
205
 
197
- /* Note: The `/credential` route only supports sending a single VC;
198
- assume here that this workflow is configured for a single VC and an
199
- error code would have been sent to the client to use the batch
200
- endpoint if there was more than one VC to deliver. */
201
- const {response, format} = result;
202
- const {verifiablePresentation: {verifiableCredential: [vc]}} = response;
206
+ // send VC(s)
207
+ const {
208
+ response: {verifiablePresentation: {verifiableCredential}},
209
+ format
210
+ } = result;
211
+ // FIXME: "format" doesn't seem to be in the spec anymore (draft 14+)...
212
+ const credentials = verifiableCredential.map(vc => {
213
+ // parse any enveloped VC
214
+ let credential;
215
+ if(vc.type === 'EnvelopedVerifiableCredential' &&
216
+ vc.id?.startsWith('data:application/jwt,')) {
217
+ credential = vc.id.slice('data:application/jwt,'.length);
218
+ } else {
219
+ credential = vc;
220
+ }
221
+ return credential;
222
+ });
203
223
 
204
- // parse any enveloped VC
205
- let credential;
206
- if(vc.type === 'EnvelopedVerifiableCredential' &&
207
- vc.id?.startsWith('data:application/jwt,')) {
208
- credential = vc.id.slice('data:application/jwt,'.length);
209
- } else {
210
- credential = vc;
211
- }
224
+ /* Note: The `/credential` route only supports sending VCs of the same
225
+ type, but there can be more than one of them. The above `isBatchRequest`
226
+ check will ensure that the workflow used here only allows a single
227
+ credential request, indicating a single type. */
212
228
 
213
229
  // send OID4VCI response
214
- res.json({
215
- // FIXME: this doesn't seem to be in the spec anymore (draft 14+)...
216
- format,
217
- credential
218
- });
230
+ const response = credentials.length === 1 ?
231
+ {format, credential: credentials[0]} : {format, credentials};
232
+ res.json(response);
219
233
  }));
220
234
 
221
235
  // a credential delivery server endpoint
@@ -316,7 +330,7 @@ export async function createRoutes({
316
330
  app.post(
317
331
  routes.authorizationResponse,
318
332
  cors(),
319
- urlencoded,
333
+ urlencodedLarge,
320
334
  validate({bodySchema: openIdAuthorizationResponseBody()}),
321
335
  getConfigMiddleware,
322
336
  getExchange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrock/vc-delivery",
3
- "version": "5.3.4",
3
+ "version": "5.4.0",
4
4
  "type": "module",
5
5
  "description": "Bedrock Verifiable Credential Delivery",
6
6
  "main": "./lib/index.js",