forked from tw-mosip/verify-credential-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify.js
42 lines (29 loc) · 1.12 KB
/
verify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const vcjs = require('@digitalcredentials/vc');
const {readFile, getProofPurpose, getSuite, documentLoader} = require("./utils");
const jsonld = require("@digitalcredentials/jsonld");
async function verify(){
console.log("\n\n ************ Verification Initiated ************ \n")
let vcFilePath = "VC/vc.json";
if(process.argv.length > 1){
vcFilePath = process.argv[1];
}
const verifiableCredential = readFile(vcFilePath);
const result = await verifyCredential(verifiableCredential);
if(!result.verified){
throw new Error("Verification Failed");
}
console.log("\nVerify Credential Response => ", JSON.stringify(result, null, 4));
console.log("\n\n ************ Verification Completed ************ \n\n")
}
async function verifyCredential(verifiableCredential){
const purpose = getProofPurpose(verifiableCredential);
const suite = await getSuite(verifiableCredential);
const vcjsOptions = {
purpose,
suite,
credential: verifiableCredential,
documentLoader: await documentLoader,
};
return await vcjs.verifyCredential(vcjsOptions);
}
module.exports = {verifyCredential, verify}