@bedrock/vc-delivery 7.0.2 → 7.1.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.
- package/lib/helpers.js +25 -0
- package/lib/index.js +4 -5
- package/lib/oid4/oid4vp.js +13 -11
- package/lib/vcapi.js +12 -7
- package/package.json +3 -4
package/lib/helpers.js
CHANGED
|
@@ -28,6 +28,31 @@ const JWT_FORMAT_ALIASES = new Set([
|
|
|
28
28
|
'jwt_vc_json'
|
|
29
29
|
]);
|
|
30
30
|
|
|
31
|
+
export function buildPresentationFromResults({
|
|
32
|
+
presentation, verifyResult
|
|
33
|
+
}) {
|
|
34
|
+
// build VP w/all envelopes removed (if any)
|
|
35
|
+
const vp = {
|
|
36
|
+
...(verifyResult?.presentationResult?.presentation ?? presentation)
|
|
37
|
+
};
|
|
38
|
+
let credentials = vp.verifiableCredential;
|
|
39
|
+
const {credentialResults} = verifyResult;
|
|
40
|
+
if(credentials && credentialResults) {
|
|
41
|
+
if(!Array.isArray(credentials)) {
|
|
42
|
+
credentials = [credentials];
|
|
43
|
+
}
|
|
44
|
+
const hasEnvelopedVC = credentials.some(
|
|
45
|
+
vc => vc.type === 'EnvelopedVerifiableCredential');
|
|
46
|
+
if(!hasEnvelopedVC) {
|
|
47
|
+
// no enveloped VCs to update, return early
|
|
48
|
+
return vp;
|
|
49
|
+
}
|
|
50
|
+
// walk credential results and produce unenveloped output
|
|
51
|
+
vp.verifiableCredential = credentialResults.map(r => r.credential);
|
|
52
|
+
}
|
|
53
|
+
return vp;
|
|
54
|
+
}
|
|
55
|
+
|
|
31
56
|
export async function evaluateTemplate({
|
|
32
57
|
workflow, exchange, typedTemplate, variables
|
|
33
58
|
} = {}) {
|
package/lib/index.js
CHANGED
|
@@ -1,12 +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 workflowSchemas from '../schemas/bedrock-vc-workflow.js';
|
|
6
6
|
import {createService, schemas} from '@bedrock/service-core';
|
|
7
7
|
import {addRoutes} from './http.js';
|
|
8
8
|
import {initializeServiceAgent} from '@bedrock/service-agent';
|
|
9
|
-
import {klona} from 'klona';
|
|
10
9
|
import {MAX_ISSUER_INSTANCES} from './constants.js';
|
|
11
10
|
import {parseLocalId} from './helpers.js';
|
|
12
11
|
import '@bedrock/express';
|
|
@@ -24,8 +23,8 @@ bedrock.events.on('bedrock.init', async () => {
|
|
|
24
23
|
|
|
25
24
|
async function _initService({serviceType, routePrefix}) {
|
|
26
25
|
// add customizations to config validators...
|
|
27
|
-
const createConfigBody =
|
|
28
|
-
const updateConfigBody =
|
|
26
|
+
const createConfigBody = structuredClone(schemas.createConfigBody);
|
|
27
|
+
const updateConfigBody = structuredClone(schemas.updateConfigBody);
|
|
29
28
|
const schemasToUpdate = [createConfigBody, updateConfigBody];
|
|
30
29
|
const {
|
|
31
30
|
credentialTemplates, steps, initialStep, issuerInstances
|
|
@@ -37,7 +36,7 @@ async function _initService({serviceType, routePrefix}) {
|
|
|
37
36
|
schema.properties.initialStep = initialStep;
|
|
38
37
|
schema.properties.issuerInstances = issuerInstances;
|
|
39
38
|
// allow zcaps by custom reference ID
|
|
40
|
-
schema.properties.zcaps =
|
|
39
|
+
schema.properties.zcaps = structuredClone(schemas.zcaps);
|
|
41
40
|
// max of 4 basic zcaps + max issuer instances
|
|
42
41
|
schema.properties.zcaps.maxProperties = 4 + MAX_ISSUER_INSTANCES;
|
|
43
42
|
schema.properties.zcaps.additionalProperties = schemas.delegatedZcap;
|
package/lib/oid4/oid4vp.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
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
|
-
evaluateTemplate, unenvelopePresentation,
|
|
7
|
+
buildPresentationFromResults, evaluateTemplate, unenvelopePresentation,
|
|
8
|
+
validateStep
|
|
8
9
|
} from '../helpers.js';
|
|
9
10
|
import {
|
|
10
11
|
presentationSubmission as presentationSubmissionSchema,
|
|
11
12
|
verifiablePresentation as verifiablePresentationSchema
|
|
12
13
|
} from '../../schemas/bedrock-vc-workflow.js';
|
|
13
14
|
import {compile} from '@bedrock/validation';
|
|
14
|
-
import {klona} from 'klona';
|
|
15
15
|
import {logger} from '../logger.js';
|
|
16
16
|
import {oid4vp} from '@digitalbazaar/oid4-client';
|
|
17
17
|
import {verify} from '../verify.js';
|
|
@@ -102,7 +102,8 @@ export async function getAuthorizationRequest({req}) {
|
|
|
102
102
|
authorizationRequest.client_id_scheme = 'redirect_uri';
|
|
103
103
|
}
|
|
104
104
|
if(client_metadata) {
|
|
105
|
-
authorizationRequest.client_metadata =
|
|
105
|
+
authorizationRequest.client_metadata = structuredClone(
|
|
106
|
+
client_metadata);
|
|
106
107
|
} else if(client_metadata_uri) {
|
|
107
108
|
authorizationRequest.client_metadata_uri = client_metadata_uri;
|
|
108
109
|
} else {
|
|
@@ -207,24 +208,25 @@ export async function processAuthorizationResponse({req}) {
|
|
|
207
208
|
if(!exchange.variables.results) {
|
|
208
209
|
exchange.variables.results = {};
|
|
209
210
|
}
|
|
210
|
-
const
|
|
211
|
+
const stepResult = {
|
|
211
212
|
// common use case of DID Authentication; provide `did` for ease
|
|
212
213
|
// of use in template
|
|
213
214
|
did: verificationMethod?.controller || null,
|
|
214
215
|
verificationMethod,
|
|
215
|
-
verifiablePresentation:
|
|
216
|
+
verifiablePresentation: buildPresentationFromResults({
|
|
217
|
+
presentation,
|
|
218
|
+
verifyResult
|
|
219
|
+
}),
|
|
216
220
|
openId: {
|
|
217
221
|
authorizationRequest,
|
|
218
222
|
presentationSubmission
|
|
219
223
|
}
|
|
220
224
|
};
|
|
221
225
|
if(envelope) {
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
results.verifiablePresentation = verifyResult
|
|
225
|
-
.presentationResult.presentation;
|
|
226
|
+
// include enveloped VP in step result
|
|
227
|
+
stepResult.envelopedPresentation = presentation;
|
|
226
228
|
}
|
|
227
|
-
exchange.variables.results[currentStep] =
|
|
229
|
+
exchange.variables.results[currentStep] = stepResult;
|
|
228
230
|
try {
|
|
229
231
|
exchange.sequence++;
|
|
230
232
|
|
package/lib/vcapi.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Copyright (c) 2018-
|
|
2
|
+
* Copyright (c) 2018-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 {createChallenge as _createChallenge, verify} from './verify.js';
|
|
7
7
|
import {
|
|
8
|
-
evaluateTemplate, generateRandom,
|
|
8
|
+
buildPresentationFromResults, evaluateTemplate, generateRandom,
|
|
9
|
+
unenvelopePresentation, validateStep
|
|
9
10
|
} from './helpers.js';
|
|
10
11
|
import {exportJWK, generateKeyPair, importJWK} from 'jose';
|
|
11
12
|
import {compile} from '@bedrock/validation';
|
|
12
13
|
import {issue} from './issue.js';
|
|
13
|
-
import {klona} from 'klona';
|
|
14
14
|
import {logger} from './logger.js';
|
|
15
15
|
|
|
16
16
|
const {util: {BedrockError}} = bedrock;
|
|
@@ -140,7 +140,7 @@ export async function processExchange({req, res, workflow, exchangeRecord}) {
|
|
|
140
140
|
|
|
141
141
|
// if no presentation was received in the body...
|
|
142
142
|
if(!receivedPresentation) {
|
|
143
|
-
const verifiablePresentationRequest =
|
|
143
|
+
const verifiablePresentationRequest = structuredClone(
|
|
144
144
|
step.verifiablePresentationRequest);
|
|
145
145
|
if(createChallenge) {
|
|
146
146
|
/* Note: When creating a challenge, the initial step always
|
|
@@ -194,7 +194,7 @@ export async function processExchange({req, res, workflow, exchangeRecord}) {
|
|
|
194
194
|
// verify the received VP
|
|
195
195
|
const expectedChallenge = isInitialStep ? exchange.id : undefined;
|
|
196
196
|
const {allowUnprotectedPresentation = false} = step;
|
|
197
|
-
const
|
|
197
|
+
const verifyResult = await verify({
|
|
198
198
|
workflow,
|
|
199
199
|
verifiablePresentationRequest: step.verifiablePresentationRequest,
|
|
200
200
|
presentation: receivedPresentation,
|
|
@@ -206,14 +206,19 @@ export async function processExchange({req, res, workflow, exchangeRecord}) {
|
|
|
206
206
|
if(!exchange.variables.results) {
|
|
207
207
|
exchange.variables.results = {};
|
|
208
208
|
}
|
|
209
|
-
|
|
209
|
+
const {verificationMethod} = verifyResult;
|
|
210
|
+
const result = {
|
|
210
211
|
// common use case of DID Authentication; provide `did` for ease
|
|
211
212
|
// of use in templates and consistency with OID4VCI which only
|
|
212
213
|
// receives `did` not verification method nor VP
|
|
213
214
|
did: verificationMethod?.controller || null,
|
|
214
215
|
verificationMethod,
|
|
215
|
-
verifiablePresentation:
|
|
216
|
+
verifiablePresentation: buildPresentationFromResults({
|
|
217
|
+
presentation: receivedPresentation,
|
|
218
|
+
verifyResult
|
|
219
|
+
})
|
|
216
220
|
};
|
|
221
|
+
exchange.variables.results[currentStep] = result;
|
|
217
222
|
|
|
218
223
|
// clear received presentation as it has been processed
|
|
219
224
|
receivedPresentation = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrock/vc-delivery",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Bedrock Verifiable Credential Delivery",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -40,14 +40,13 @@
|
|
|
40
40
|
"@digitalbazaar/ed25519-signature-2020": "^5.4.0",
|
|
41
41
|
"@digitalbazaar/ezcap": "^4.1.0",
|
|
42
42
|
"@digitalbazaar/oid4-client": "^4.3.0",
|
|
43
|
-
"@digitalbazaar/vc": "^7.
|
|
43
|
+
"@digitalbazaar/vc": "^7.2.0",
|
|
44
44
|
"assert-plus": "^1.0.0",
|
|
45
45
|
"bnid": "^3.0.0",
|
|
46
46
|
"body-parser": "^1.20.3",
|
|
47
47
|
"cors": "^2.8.5",
|
|
48
48
|
"jose": "^5.10.0",
|
|
49
49
|
"jsonata": "^2.0.6",
|
|
50
|
-
"klona": "^2.0.6",
|
|
51
50
|
"serialize-error": "^12.0.0"
|
|
52
51
|
},
|
|
53
52
|
"peerDependencies": {
|
|
@@ -72,6 +71,6 @@
|
|
|
72
71
|
"eslint-plugin-unicorn": "^56.0.1"
|
|
73
72
|
},
|
|
74
73
|
"engines": {
|
|
75
|
-
"node": ">=
|
|
74
|
+
"node": ">=20"
|
|
76
75
|
}
|
|
77
76
|
}
|