@bedrock/vc-verifier 13.0.1 → 14.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/http.js +64 -15
- package/package.json +3 -2
package/lib/http.js
CHANGED
|
@@ -16,6 +16,7 @@ import {checkStatus} from './status.js';
|
|
|
16
16
|
import cors from 'cors';
|
|
17
17
|
import {createDocumentLoader} from './documentLoader.js';
|
|
18
18
|
import {createSuites} from './suites.js';
|
|
19
|
+
import {serializeError} from 'serialize-error';
|
|
19
20
|
import {createValidateMiddleware as validate} from '@bedrock/validation';
|
|
20
21
|
|
|
21
22
|
const {util: {BedrockError}} = bedrock;
|
|
@@ -93,6 +94,29 @@ export async function addRoutes({app, service} = {}) {
|
|
|
93
94
|
checkStatus: checks.includes('credentialStatus') ?
|
|
94
95
|
checkStatus : () => ({verified: true})
|
|
95
96
|
});
|
|
97
|
+
// if proof should have been checked but wasn't due to an error,
|
|
98
|
+
// try to run the check again using the VC's issuance date
|
|
99
|
+
if(checks.includes('proof') &&
|
|
100
|
+
result.error && !result.proof && result.results[0] &&
|
|
101
|
+
typeof credential.issuanceDate === 'string') {
|
|
102
|
+
const proofResult = await vc.verifyCredential({
|
|
103
|
+
credential,
|
|
104
|
+
documentLoader,
|
|
105
|
+
suite,
|
|
106
|
+
now: new Date(credential.issuanceDate),
|
|
107
|
+
// only check credential status when option is set
|
|
108
|
+
checkStatus: checks.includes('credentialStatus') ?
|
|
109
|
+
checkStatus : () => ({verified: true})
|
|
110
|
+
});
|
|
111
|
+
if(proofResult.verified) {
|
|
112
|
+
// overlay original (failed) results on top of proof results
|
|
113
|
+
result.results[0] = {
|
|
114
|
+
...proofResult.results[0],
|
|
115
|
+
...result.results[0],
|
|
116
|
+
proofVerified: true
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
96
120
|
response = _createResponse({credential, result, checks});
|
|
97
121
|
} catch(e) {
|
|
98
122
|
response = _createResponse({error: e});
|
|
@@ -152,14 +176,18 @@ export async function addRoutes({app, service} = {}) {
|
|
|
152
176
|
_validateChecks({checks});
|
|
153
177
|
const unsignedPresentation = !checks.includes('proof');
|
|
154
178
|
|
|
155
|
-
//
|
|
156
|
-
// should be checked
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
179
|
+
// allow for `checks` to indicate whether or not the challenge
|
|
180
|
+
// should be checked
|
|
181
|
+
let challengeUses;
|
|
182
|
+
if(checks.includes('challenge')) {
|
|
183
|
+
// first, check the challenge
|
|
184
|
+
const result = await verifyChallenge(
|
|
185
|
+
{challenge, verifierId: config.id});
|
|
186
|
+
const {verified, error} = result;
|
|
187
|
+
if(!verified) {
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
({uses: challengeUses} = result);
|
|
163
191
|
}
|
|
164
192
|
|
|
165
193
|
const verifyOptions = {
|
|
@@ -218,11 +246,22 @@ function _createResponse({credential, result, challengeUses, error, checks}) {
|
|
|
218
246
|
const results = result.results ||
|
|
219
247
|
(result.presentationResult && result.presentationResult.results);
|
|
220
248
|
if(results && results.length > 0) {
|
|
249
|
+
for(const r of results) {
|
|
250
|
+
// ensure error is serializable
|
|
251
|
+
if(r.error) {
|
|
252
|
+
r.error = _serializeError({error: r.error});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
221
255
|
const [{proof}] = results;
|
|
222
|
-
(
|
|
256
|
+
if(proof) {
|
|
257
|
+
({verificationMethod} = proof);
|
|
258
|
+
}
|
|
223
259
|
}
|
|
224
260
|
|
|
225
|
-
if(
|
|
261
|
+
if(result.error) {
|
|
262
|
+
// ensure error is serializable
|
|
263
|
+
error = result.error = _serializeError({error: result.error});
|
|
264
|
+
} else {
|
|
226
265
|
// try to get error from credential results
|
|
227
266
|
const firstCredentialResult = (result.presentationResult &&
|
|
228
267
|
result.credentialResults && result.credentialResults[0]) ||
|
|
@@ -245,11 +284,8 @@ function _createResponse({credential, result, challengeUses, error, checks}) {
|
|
|
245
284
|
error = firstCredentialResult.error;
|
|
246
285
|
}
|
|
247
286
|
error = error || {message: 'Verification error.'};
|
|
248
|
-
|
|
249
|
-
error =
|
|
250
|
-
if(!error.message) {
|
|
251
|
-
error.message = 'Verification error.';
|
|
252
|
-
}
|
|
287
|
+
// ensure error is serializable
|
|
288
|
+
error = _serializeError({error});
|
|
253
289
|
}
|
|
254
290
|
|
|
255
291
|
let message = error.message;
|
|
@@ -270,3 +306,16 @@ function _createResponse({credential, result, challengeUses, error, checks}) {
|
|
|
270
306
|
}
|
|
271
307
|
return response;
|
|
272
308
|
}
|
|
309
|
+
|
|
310
|
+
function _serializeError({error}) {
|
|
311
|
+
// ensure error is serializable; do not include stack
|
|
312
|
+
error = serializeError(error);
|
|
313
|
+
if(!error.name || error.name === 'Error') {
|
|
314
|
+
error.name = 'VerificationError';
|
|
315
|
+
}
|
|
316
|
+
if(!error.message) {
|
|
317
|
+
error.message = 'Verification error.';
|
|
318
|
+
}
|
|
319
|
+
delete error.stack;
|
|
320
|
+
return error;
|
|
321
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrock/vc-verifier",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Bedrock VC Verifier",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"assert-plus": "^1.0.0",
|
|
36
36
|
"bnid": "^3.0.0",
|
|
37
37
|
"body-parser": "^1.20.0",
|
|
38
|
-
"cors": "^2.8.5"
|
|
38
|
+
"cors": "^2.8.5",
|
|
39
|
+
"serialize-error": "^11.0.0"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
42
|
"@bedrock/core": "^6.0.1",
|