Skip to content

Commit 6a6e412

Browse files
Enhance certificate verification and error handling
1 parent 11c524e commit 6a6e412

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@project-sunbird/client-services",
3-
"version": "8.0.5",
3+
"version": "8.1.0",
44
"description": "Type definitions and models for Sunbird platform clients",
55
"main": "dist/index.js",
66
"module": "src/index.ts",

src/utilities/certificate/certificate-verifier.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export class CertificateVerifier {
2929
public async verifyData(signedJSON, publicKey): Promise<any>{
3030
this.publicKey = publicKey;
3131
try {
32+
// Ensure security context is in the document's @context array
33+
if (signedJSON['@context'] && Array.isArray(signedJSON['@context'])) {
34+
const securityContextV2 = 'https://w3id.org/security/v2';
35+
if (signedJSON['@context'].indexOf(securityContextV2) === -1) {
36+
signedJSON['@context'].push(securityContextV2);
37+
}
38+
}
39+
3240
const {AssertionProofPurpose} = jsigs.purposes;
3341
let result;
3442
const publicKey = {
@@ -63,7 +71,19 @@ export class CertificateVerifier {
6371
return result;
6472

6573
} catch (e) {
66-
throw new Error('Invalid data');
74+
// Improved error handling
75+
console.error('Certificate verification error:', e);
76+
const error = e as Error;
77+
console.error('Error details:', {
78+
message: error.message,
79+
stack: error.stack,
80+
name: error.name
81+
});
82+
// Preserve the original error if it's already a VerificationError
83+
if ((error as any).name === 'VerificationError' || (error as any).verified === false) {
84+
return e; // Return the error object as-is so caller can see details
85+
}
86+
throw new Error(`Invalid data: ${error.message || 'Unknown error'}`);
6787
}
6888
}
6989

@@ -72,6 +92,7 @@ export class CertificateVerifier {
7292
"did:india": this.publicKey,
7393
"https://example.com/i/india": this.publicKey,
7494
"https://w3id.org/security/v1": contexts.get("https://w3id.org/security/v1"),
95+
"https://w3id.org/security/v2": contexts.get("https://w3id.org/security/v2"), // Added v2
7596
'https://www.w3.org/2018/credentials#': credentialsv1,
7697
"https://www.w3.org/2018/credentials/v1": credentialsv1
7798

0 commit comments

Comments
 (0)