@digitalbazaar/oid4-client 3.4.0 → 3.4.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.
Files changed (2) hide show
  1. package/lib/OID4Client.js +29 -2
  2. package/package.json +1 -1
package/lib/OID4Client.js CHANGED
@@ -121,8 +121,17 @@ export class OID4Client {
121
121
  }
122
122
  break;
123
123
  } catch(cause) {
124
+ // presentation is required to continue issuance
125
+ if(_isPresentationRequired(cause)) {
126
+ const {data: details} = cause;
127
+ const error = new Error('Presentation is required.', {cause});
128
+ error.name = 'NotAllowedError';
129
+ error.details = details;
130
+ throw error;
131
+ }
132
+
124
133
  if(!_isMissingProofError(cause)) {
125
- // non-specific error case
134
+ // other non-specific error case
126
135
  throw cause;
127
136
  }
128
137
 
@@ -335,7 +344,7 @@ function _isMissingProofError(error) {
335
344
  Cache-Control: no-store
336
345
 
337
346
  {
338
- "error": "invalid_or_missing_proof" // or "invalid_proof"
347
+ "error": "invalid_or_missing_proof", // or "invalid_proof"
339
348
  "error_description":
340
349
  "Credential issuer requires proof element in Credential Request"
341
350
  "c_nonce": "8YE9hCnyV2",
@@ -349,6 +358,24 @@ function _isMissingProofError(error) {
349
358
  errorType === 'invalid_or_missing_proof');
350
359
  }
351
360
 
361
+ function _isPresentationRequired(error) {
362
+ /* If OID4VP is required, delivery server sends, e.g.:
363
+
364
+ HTTP/1.1 400 Bad Request
365
+ Content-Type: application/json
366
+ Cache-Control: no-store
367
+
368
+ {
369
+ "error": "presentation_required",
370
+ "error_description":
371
+ "Credential issuer requires presentation before Credential Request"
372
+ "authorization_request": {...}
373
+ }
374
+ */
375
+ const errorType = error.data?.error;
376
+ return error.status === 400 && errorType === 'presentation_required';
377
+ }
378
+
352
379
  function _createCredentialRequestFromId({id, issuerConfig}) {
353
380
  const {credentials_supported: supported = []} = issuerConfig;
354
381
  const meta = supported.find(d => d.id === id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalbazaar/oid4-client",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "An OID4 (VC + VP) client",
5
5
  "homepage": "https://github.com/digitalbazaar/oid4-client",
6
6
  "author": {