@bedrock/vc-delivery 7.1.1 → 7.2.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 +30 -0
- package/lib/oid4/oid4vp.js +7 -1
- package/lib/vcapi.js +7 -1
- package/lib/verify.js +27 -12
- package/package.json +1 -1
- package/schemas/bedrock-vc-workflow.js +22 -0
package/lib/helpers.js
CHANGED
|
@@ -188,6 +188,36 @@ export function deepEqual(obj1, obj2) {
|
|
|
188
188
|
return true;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
export function createVerifyOptions({
|
|
192
|
+
verifyPresentationOptions,
|
|
193
|
+
expectedChallenge,
|
|
194
|
+
verifiablePresentationRequest,
|
|
195
|
+
presentation,
|
|
196
|
+
domain,
|
|
197
|
+
checks
|
|
198
|
+
}) {
|
|
199
|
+
// start with `verifyPresentationOptions`, then overwrite as needed
|
|
200
|
+
const options = {...verifyPresentationOptions};
|
|
201
|
+
|
|
202
|
+
// update `checks` with anything additional from `verifyPresentationOptions`
|
|
203
|
+
const checkSet = new Set(checks);
|
|
204
|
+
if(verifyPresentationOptions.checks) {
|
|
205
|
+
Object.entries(verifyPresentationOptions.checks)
|
|
206
|
+
.forEach(([check, enabled]) => enabled && checkSet.add(check));
|
|
207
|
+
}
|
|
208
|
+
options.checks = [...checkSet];
|
|
209
|
+
|
|
210
|
+
// update `challenge`
|
|
211
|
+
options.challenge = expectedChallenge ??
|
|
212
|
+
verifiablePresentationRequest.challenge ??
|
|
213
|
+
presentation?.proof?.challenge;
|
|
214
|
+
|
|
215
|
+
// update `domain`
|
|
216
|
+
options.domain = domain;
|
|
217
|
+
|
|
218
|
+
return options;
|
|
219
|
+
}
|
|
220
|
+
|
|
191
221
|
export function stripStacktrace(error) {
|
|
192
222
|
// serialize error and allow-list specific properties
|
|
193
223
|
const serialized = serializeError(error);
|
package/lib/oid4/oid4vp.js
CHANGED
|
@@ -193,9 +193,15 @@ export async function processAuthorizationResponse({req}) {
|
|
|
193
193
|
// verify the received VP
|
|
194
194
|
const {verifiablePresentationRequest} = await oid4vp.toVpr(
|
|
195
195
|
{authorizationRequest});
|
|
196
|
-
const {
|
|
196
|
+
const {
|
|
197
|
+
allowUnprotectedPresentation = false,
|
|
198
|
+
verifyPresentationOptions = {},
|
|
199
|
+
verifyPresentationResultSchema
|
|
200
|
+
} = step;
|
|
197
201
|
const verifyResult = await verify({
|
|
198
202
|
workflow,
|
|
203
|
+
verifyPresentationOptions,
|
|
204
|
+
verifyPresentationResultSchema,
|
|
199
205
|
verifiablePresentationRequest,
|
|
200
206
|
presentation,
|
|
201
207
|
allowUnprotectedPresentation,
|
package/lib/vcapi.js
CHANGED
|
@@ -193,9 +193,15 @@ export async function processExchange({req, res, workflow, exchangeRecord}) {
|
|
|
193
193
|
|
|
194
194
|
// verify the received VP
|
|
195
195
|
const expectedChallenge = isInitialStep ? exchange.id : undefined;
|
|
196
|
-
const {
|
|
196
|
+
const {
|
|
197
|
+
allowUnprotectedPresentation = false,
|
|
198
|
+
verifyPresentationOptions = {},
|
|
199
|
+
verifyPresentationResultSchema
|
|
200
|
+
} = step;
|
|
197
201
|
const verifyResult = await verify({
|
|
198
202
|
workflow,
|
|
203
|
+
verifyPresentationOptions,
|
|
204
|
+
verifyPresentationResultSchema,
|
|
199
205
|
verifiablePresentationRequest: step.verifiablePresentationRequest,
|
|
200
206
|
presentation: receivedPresentation,
|
|
201
207
|
allowUnprotectedPresentation,
|
package/lib/verify.js
CHANGED
|
@@ -4,8 +4,13 @@
|
|
|
4
4
|
import * as bedrock from '@bedrock/core';
|
|
5
5
|
import * as EcdsaMultikey from '@digitalbazaar/ecdsa-multikey';
|
|
6
6
|
import * as Ed25519Multikey from '@digitalbazaar/ed25519-multikey';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
createVerifyOptions,
|
|
9
|
+
getZcapClient,
|
|
10
|
+
stripStacktrace
|
|
11
|
+
} from './helpers.js';
|
|
8
12
|
import {importJWK, jwtVerify} from 'jose';
|
|
13
|
+
import {compile} from '@bedrock/validation';
|
|
9
14
|
import {didIo} from '@bedrock/did-io';
|
|
10
15
|
|
|
11
16
|
const {util: {BedrockError}} = bedrock;
|
|
@@ -25,8 +30,9 @@ export async function createChallenge({workflow} = {}) {
|
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
export async function verify({
|
|
28
|
-
workflow,
|
|
29
|
-
allowUnprotectedPresentation = false, expectedChallenge
|
|
33
|
+
workflow, verifyPresentationOptions, verifiablePresentationRequest,
|
|
34
|
+
presentation, allowUnprotectedPresentation = false, expectedChallenge,
|
|
35
|
+
verifyPresentationResultSchema
|
|
30
36
|
} = {}) {
|
|
31
37
|
// create zcap client for verifying
|
|
32
38
|
const {zcapClient, zcaps} = await getZcapClient({workflow});
|
|
@@ -46,17 +52,18 @@ export async function verify({
|
|
|
46
52
|
new URL(workflow.id).origin;
|
|
47
53
|
let result;
|
|
48
54
|
try {
|
|
55
|
+
const options = createVerifyOptions({
|
|
56
|
+
verifyPresentationOptions,
|
|
57
|
+
expectedChallenge,
|
|
58
|
+
verifiablePresentationRequest,
|
|
59
|
+
presentation,
|
|
60
|
+
domain,
|
|
61
|
+
checks
|
|
62
|
+
});
|
|
49
63
|
result = await zcapClient.write({
|
|
50
64
|
capability,
|
|
51
65
|
json: {
|
|
52
|
-
options
|
|
53
|
-
// FIXME: support multi-proof presentations?
|
|
54
|
-
challenge: expectedChallenge ??
|
|
55
|
-
verifiablePresentationRequest.challenge ??
|
|
56
|
-
presentation?.proof?.challenge,
|
|
57
|
-
domain,
|
|
58
|
-
checks
|
|
59
|
-
},
|
|
66
|
+
options,
|
|
60
67
|
verifiablePresentation: presentation
|
|
61
68
|
}
|
|
62
69
|
});
|
|
@@ -120,7 +127,15 @@ export async function verify({
|
|
|
120
127
|
const verificationMethod = presentationResult?.results[0]
|
|
121
128
|
.verificationMethod ?? null;
|
|
122
129
|
|
|
123
|
-
//
|
|
130
|
+
// validate against the verify presentation result schema, if applicable
|
|
131
|
+
if(verifyPresentationResultSchema) {
|
|
132
|
+
const {jsonSchema: schema} = verifyPresentationResultSchema;
|
|
133
|
+
const validate = compile({schema});
|
|
134
|
+
const {valid, error} = validate(result.data);
|
|
135
|
+
if(!valid) {
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
124
139
|
|
|
125
140
|
return {
|
|
126
141
|
verified,
|
package/package.json
CHANGED
|
@@ -486,6 +486,28 @@ const step = {
|
|
|
486
486
|
stepTemplate: typedTemplate,
|
|
487
487
|
verifiablePresentationRequest: {
|
|
488
488
|
type: 'object'
|
|
489
|
+
},
|
|
490
|
+
verifyPresentationOptions: {
|
|
491
|
+
type: 'object',
|
|
492
|
+
properties: {
|
|
493
|
+
checks: {
|
|
494
|
+
type: 'object'
|
|
495
|
+
}
|
|
496
|
+
},
|
|
497
|
+
additionalProperties: true
|
|
498
|
+
},
|
|
499
|
+
verifyPresentationResultSchema: {
|
|
500
|
+
type: 'object',
|
|
501
|
+
required: ['type', 'jsonSchema'],
|
|
502
|
+
additionalProperties: false,
|
|
503
|
+
properties: {
|
|
504
|
+
type: {
|
|
505
|
+
type: 'string'
|
|
506
|
+
},
|
|
507
|
+
jsonSchema: {
|
|
508
|
+
type: 'object'
|
|
509
|
+
}
|
|
510
|
+
}
|
|
489
511
|
}
|
|
490
512
|
}
|
|
491
513
|
};
|