@digitalbazaar/oid4-client 3.4.0 → 3.5.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/OID4Client.js +29 -2
- package/lib/oid4vp.js +3 -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/lib/oid4vp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
|
|
2
|
+
* Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
4
|
import {assert, assertOptional, fetchJSON} from './util.js';
|
|
5
5
|
import {decodeJwt} from 'jose';
|
|
@@ -159,6 +159,7 @@ export async function sendAuthorizationResponse({
|
|
|
159
159
|
verifiablePresentation,
|
|
160
160
|
presentationSubmission,
|
|
161
161
|
authorizationRequest,
|
|
162
|
+
vpToken,
|
|
162
163
|
agent
|
|
163
164
|
} = {}) {
|
|
164
165
|
try {
|
|
@@ -174,7 +175,7 @@ export async function sendAuthorizationResponse({
|
|
|
174
175
|
|
|
175
176
|
// send VP and presentation submission to complete exchange
|
|
176
177
|
const body = new URLSearchParams();
|
|
177
|
-
body.set('vp_token', JSON.stringify(verifiablePresentation));
|
|
178
|
+
body.set('vp_token', vpToken ?? JSON.stringify(verifiablePresentation));
|
|
178
179
|
body.set('presentation_submission', JSON.stringify(presentationSubmission));
|
|
179
180
|
const response = await httpClient.post(authorizationRequest.response_uri, {
|
|
180
181
|
agent, body, headers: {accept: 'application/json'},
|