@bedrock/vc-delivery 7.2.0 → 7.3.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/helpers.js +23 -0
- package/lib/oid4/oid4vci.js +6 -3
- package/lib/oid4/oid4vp.js +8 -3
- package/lib/vcapi.js +7 -2
- package/package.json +2 -1
- package/schemas/bedrock-vc-workflow.js +12 -1
package/lib/helpers.js
CHANGED
|
@@ -5,8 +5,10 @@ import * as bedrock from '@bedrock/core';
|
|
|
5
5
|
import * as vcjwt from './vcjwt.js';
|
|
6
6
|
import {decodeId, generateId} from 'bnid';
|
|
7
7
|
import {Ed25519Signature2020} from '@digitalbazaar/ed25519-signature-2020';
|
|
8
|
+
import {httpClient} from '@digitalbazaar/http-client';
|
|
8
9
|
import {httpsAgent} from '@bedrock/https-agent';
|
|
9
10
|
import jsonata from 'jsonata';
|
|
11
|
+
import {logger} from './logger.js';
|
|
10
12
|
import {serializeError} from 'serialize-error';
|
|
11
13
|
import {serviceAgents} from '@bedrock/service-agent';
|
|
12
14
|
import {ZcapClient} from '@digitalbazaar/ezcap';
|
|
@@ -53,6 +55,27 @@ export function buildPresentationFromResults({
|
|
|
53
55
|
return vp;
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
export function emitExchangeUpdated({workflow, exchange, step}) {
|
|
59
|
+
if(!step?.callback?.url) {
|
|
60
|
+
// no-op when there is no callback to notify
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const {url} = step.callback;
|
|
65
|
+
const exchangeId = `${workflow.id}/exchanges/${exchange.id}`;
|
|
66
|
+
httpClient.post(url, {
|
|
67
|
+
agent: httpsAgent,
|
|
68
|
+
json: {
|
|
69
|
+
event: {
|
|
70
|
+
data: {exchangeId}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}).catch(
|
|
74
|
+
error => logger.error(
|
|
75
|
+
'Could not send "exchangeUpdated" push notification: ' +
|
|
76
|
+
error.message, {error}));
|
|
77
|
+
}
|
|
78
|
+
|
|
56
79
|
export async function evaluateTemplate({
|
|
57
80
|
workflow, exchange, typedTemplate, variables
|
|
58
81
|
} = {}) {
|
package/lib/oid4/oid4vci.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Copyright (c) 2022-
|
|
2
|
+
* Copyright (c) 2022-2025 Digital Bazaar, Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
4
|
import * as bedrock from '@bedrock/core';
|
|
5
5
|
import * as exchanges from '../exchanges.js';
|
|
6
6
|
import {
|
|
7
|
-
deepEqual,
|
|
7
|
+
deepEqual, emitExchangeUpdated,
|
|
8
|
+
evaluateTemplate, getWorkflowIssuerInstances, validateStep
|
|
8
9
|
} from '../helpers.js';
|
|
9
10
|
import {importJWK, SignJWT} from 'jose';
|
|
10
11
|
import {checkAccessToken} from '@bedrock/oauth2-verifier';
|
|
@@ -397,6 +398,7 @@ function _normalizeCredentialDefinitionTypes({credentialRequests}) {
|
|
|
397
398
|
async function _processExchange({
|
|
398
399
|
req, res, workflow, exchangeRecord, isBatchRequest
|
|
399
400
|
}) {
|
|
401
|
+
let step;
|
|
400
402
|
const {id: workflowId} = workflow;
|
|
401
403
|
const {exchange, meta} = exchangeRecord;
|
|
402
404
|
let {updated: lastUpdated} = meta;
|
|
@@ -428,7 +430,6 @@ async function _processExchange({
|
|
|
428
430
|
});
|
|
429
431
|
|
|
430
432
|
// process exchange step if present
|
|
431
|
-
let step;
|
|
432
433
|
const currentStep = exchange.step;
|
|
433
434
|
if(currentStep) {
|
|
434
435
|
step = workflow.steps[exchange.step];
|
|
@@ -494,6 +495,7 @@ async function _processExchange({
|
|
|
494
495
|
try {
|
|
495
496
|
exchange.sequence++;
|
|
496
497
|
await exchanges.complete({workflowId, exchange});
|
|
498
|
+
emitExchangeUpdated({workflow, exchange, step});
|
|
497
499
|
lastUpdated = Date.now();
|
|
498
500
|
} catch(e) {
|
|
499
501
|
exchange.sequence--;
|
|
@@ -516,6 +518,7 @@ async function _processExchange({
|
|
|
516
518
|
exchanges.setLastError({workflowId, exchange: copy, lastUpdated})
|
|
517
519
|
.catch(error => logger.error(
|
|
518
520
|
'Could not set last exchange error: ' + error.message, {error}));
|
|
521
|
+
emitExchangeUpdated({workflow, exchange, step});
|
|
519
522
|
throw e;
|
|
520
523
|
}
|
|
521
524
|
}
|
package/lib/oid4/oid4vp.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
import * as bedrock from '@bedrock/core';
|
|
5
5
|
import * as exchanges from '../exchanges.js';
|
|
6
6
|
import {
|
|
7
|
-
buildPresentationFromResults,
|
|
7
|
+
buildPresentationFromResults, emitExchangeUpdated,
|
|
8
|
+
evaluateTemplate, unenvelopePresentation,
|
|
8
9
|
validateStep
|
|
9
10
|
} from '../helpers.js';
|
|
10
11
|
import {
|
|
@@ -141,6 +142,7 @@ export async function getAuthorizationRequest({req}) {
|
|
|
141
142
|
try {
|
|
142
143
|
exchange.sequence++;
|
|
143
144
|
await exchanges.update({workflowId: workflow.id, exchange});
|
|
145
|
+
emitExchangeUpdated({workflow, exchange, step});
|
|
144
146
|
} catch(e) {
|
|
145
147
|
exchange.sequence--;
|
|
146
148
|
if(e.name !== 'InvalidStateError') {
|
|
@@ -168,11 +170,12 @@ export async function processAuthorizationResponse({req}) {
|
|
|
168
170
|
const exchangeRecord = await req.getExchange();
|
|
169
171
|
let {exchange} = exchangeRecord;
|
|
170
172
|
let {meta: {updated: lastUpdated}} = exchangeRecord;
|
|
173
|
+
let step;
|
|
171
174
|
try {
|
|
172
175
|
// get authorization request and updated exchange associated with exchange
|
|
173
176
|
const arRequest = await getAuthorizationRequest({req});
|
|
174
|
-
const {authorizationRequest
|
|
175
|
-
({exchange} = arRequest);
|
|
177
|
+
const {authorizationRequest} = arRequest;
|
|
178
|
+
({exchange, step} = arRequest);
|
|
176
179
|
|
|
177
180
|
// FIXME: check the VP against the presentation submission if requested
|
|
178
181
|
// FIXME: check the VP against "trustedIssuer" in VPR, if provided
|
|
@@ -250,6 +253,7 @@ export async function processAuthorizationResponse({req}) {
|
|
|
250
253
|
exchange.state = 'complete';
|
|
251
254
|
await exchanges.complete({workflowId: workflow.id, exchange});
|
|
252
255
|
}
|
|
256
|
+
emitExchangeUpdated({workflow, exchange, step});
|
|
253
257
|
lastUpdated = Date.now();
|
|
254
258
|
} catch(e) {
|
|
255
259
|
exchange.sequence--;
|
|
@@ -277,6 +281,7 @@ export async function processAuthorizationResponse({req}) {
|
|
|
277
281
|
exchanges.setLastError({workflowId, exchange: copy, lastUpdated})
|
|
278
282
|
.catch(error => logger.error(
|
|
279
283
|
'Could not set last exchange error: ' + error.message, {error}));
|
|
284
|
+
emitExchangeUpdated({workflow, exchange, step});
|
|
280
285
|
throw e;
|
|
281
286
|
}
|
|
282
287
|
}
|
package/lib/vcapi.js
CHANGED
|
@@ -5,7 +5,8 @@ import * as bedrock from '@bedrock/core';
|
|
|
5
5
|
import * as exchanges from './exchanges.js';
|
|
6
6
|
import {createChallenge as _createChallenge, verify} from './verify.js';
|
|
7
7
|
import {
|
|
8
|
-
buildPresentationFromResults,
|
|
8
|
+
buildPresentationFromResults, emitExchangeUpdated,
|
|
9
|
+
evaluateTemplate, generateRandom,
|
|
9
10
|
unenvelopePresentation, validateStep
|
|
10
11
|
} from './helpers.js';
|
|
11
12
|
import {exportJWK, generateKeyPair, importJWK} from 'jose';
|
|
@@ -93,6 +94,8 @@ export async function createExchange({workflow, exchange}) {
|
|
|
93
94
|
export async function processExchange({req, res, workflow, exchangeRecord}) {
|
|
94
95
|
const {exchange, meta} = exchangeRecord;
|
|
95
96
|
let {updated: lastUpdated} = meta;
|
|
97
|
+
let step;
|
|
98
|
+
|
|
96
99
|
try {
|
|
97
100
|
// get any `verifiablePresentation` from the body...
|
|
98
101
|
let receivedPresentation = req?.body?.verifiablePresentation;
|
|
@@ -100,7 +103,6 @@ export async function processExchange({req, res, workflow, exchangeRecord}) {
|
|
|
100
103
|
// process exchange step(s)
|
|
101
104
|
let i = 0;
|
|
102
105
|
let currentStep = exchange.step;
|
|
103
|
-
let step;
|
|
104
106
|
while(true) {
|
|
105
107
|
if(i++ > MAXIMUM_STEPS) {
|
|
106
108
|
throw new BedrockError('Maximum steps exceeded.', {
|
|
@@ -255,6 +257,7 @@ export async function processExchange({req, res, workflow, exchangeRecord}) {
|
|
|
255
257
|
try {
|
|
256
258
|
exchange.sequence++;
|
|
257
259
|
await exchanges.update({workflowId: workflow.id, exchange});
|
|
260
|
+
emitExchangeUpdated({workflow, exchange, step});
|
|
258
261
|
lastUpdated = Date.now();
|
|
259
262
|
} catch(e) {
|
|
260
263
|
exchange.sequence--;
|
|
@@ -279,6 +282,7 @@ export async function processExchange({req, res, workflow, exchangeRecord}) {
|
|
|
279
282
|
try {
|
|
280
283
|
exchange.sequence++;
|
|
281
284
|
await exchanges.complete({workflowId: workflow.id, exchange});
|
|
285
|
+
emitExchangeUpdated({workflow, exchange, step});
|
|
282
286
|
} catch(e) {
|
|
283
287
|
exchange.sequence--;
|
|
284
288
|
throw e;
|
|
@@ -311,6 +315,7 @@ export async function processExchange({req, res, workflow, exchangeRecord}) {
|
|
|
311
315
|
exchanges.setLastError({workflowId, exchange: copy, lastUpdated})
|
|
312
316
|
.catch(error => logger.error(
|
|
313
317
|
'Could not set last exchange error: ' + error.message, {error}));
|
|
318
|
+
emitExchangeUpdated({workflow, exchange, step});
|
|
314
319
|
throw e;
|
|
315
320
|
}
|
|
316
321
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrock/vc-delivery",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Bedrock Verifiable Credential Delivery",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"@digitalbazaar/ed25519-multikey": "^1.3.1",
|
|
40
40
|
"@digitalbazaar/ed25519-signature-2020": "^5.4.0",
|
|
41
41
|
"@digitalbazaar/ezcap": "^4.1.0",
|
|
42
|
+
"@digitalbazaar/http-client": "^4.2.0",
|
|
42
43
|
"@digitalbazaar/oid4-client": "^4.3.0",
|
|
43
44
|
"@digitalbazaar/vc": "^7.2.0",
|
|
44
45
|
"assert-plus": "^1.0.0",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Copyright (c) 2022-
|
|
2
|
+
* Copyright (c) 2022-2025 Digital Bazaar, Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
4
|
import {MAX_ISSUER_INSTANCES} from '../lib/constants.js';
|
|
5
5
|
import {schemas} from '@bedrock/validation';
|
|
@@ -381,6 +381,7 @@ const step = {
|
|
|
381
381
|
not: {
|
|
382
382
|
required: [
|
|
383
383
|
'allowUnprotectedPresentation',
|
|
384
|
+
'callback',
|
|
384
385
|
'createChallenge',
|
|
385
386
|
'issueRequests',
|
|
386
387
|
'jwtDidProofRequest',
|
|
@@ -400,6 +401,16 @@ const step = {
|
|
|
400
401
|
allowUnprotectedPresentation: {
|
|
401
402
|
type: 'boolean'
|
|
402
403
|
},
|
|
404
|
+
callback: {
|
|
405
|
+
type: 'object',
|
|
406
|
+
required: ['url'],
|
|
407
|
+
additionalProperties: false,
|
|
408
|
+
properties: {
|
|
409
|
+
url: {
|
|
410
|
+
type: 'string'
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
},
|
|
403
414
|
createChallenge: {
|
|
404
415
|
type: 'boolean'
|
|
405
416
|
},
|