@bedrock/vc-delivery 7.0.2 → 7.1.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 +25 -0
- package/lib/oid4/oid4vp.js +11 -9
- package/lib/vcapi.js +11 -5
- package/package.json +2 -2
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/oid4/oid4vp.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
|
-
evaluateTemplate, unenvelopePresentation,
|
|
7
|
+
buildPresentationFromResults, evaluateTemplate, unenvelopePresentation,
|
|
8
|
+
validateStep
|
|
8
9
|
} from '../helpers.js';
|
|
9
10
|
import {
|
|
10
11
|
presentationSubmission as presentationSubmissionSchema,
|
|
@@ -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,11 +1,12 @@
|
|
|
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';
|
|
@@ -194,7 +195,7 @@ export async function processExchange({req, res, workflow, exchangeRecord}) {
|
|
|
194
195
|
// verify the received VP
|
|
195
196
|
const expectedChallenge = isInitialStep ? exchange.id : undefined;
|
|
196
197
|
const {allowUnprotectedPresentation = false} = step;
|
|
197
|
-
const
|
|
198
|
+
const verifyResult = await verify({
|
|
198
199
|
workflow,
|
|
199
200
|
verifiablePresentationRequest: step.verifiablePresentationRequest,
|
|
200
201
|
presentation: receivedPresentation,
|
|
@@ -206,14 +207,19 @@ export async function processExchange({req, res, workflow, exchangeRecord}) {
|
|
|
206
207
|
if(!exchange.variables.results) {
|
|
207
208
|
exchange.variables.results = {};
|
|
208
209
|
}
|
|
209
|
-
|
|
210
|
+
const {verificationMethod} = verifyResult;
|
|
211
|
+
const result = {
|
|
210
212
|
// common use case of DID Authentication; provide `did` for ease
|
|
211
213
|
// of use in templates and consistency with OID4VCI which only
|
|
212
214
|
// receives `did` not verification method nor VP
|
|
213
215
|
did: verificationMethod?.controller || null,
|
|
214
216
|
verificationMethod,
|
|
215
|
-
verifiablePresentation:
|
|
217
|
+
verifiablePresentation: buildPresentationFromResults({
|
|
218
|
+
presentation: receivedPresentation,
|
|
219
|
+
verifyResult
|
|
220
|
+
})
|
|
216
221
|
};
|
|
222
|
+
exchange.variables.results[currentStep] = result;
|
|
217
223
|
|
|
218
224
|
// clear received presentation as it has been processed
|
|
219
225
|
receivedPresentation = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrock/vc-delivery",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Bedrock Verifiable Credential Delivery",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
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",
|