-
Notifications
You must be signed in to change notification settings - Fork 1
/
02_verify.ts
31 lines (25 loc) · 1.07 KB
/
02_verify.ts
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
import {
BbsBlsSignature2020
} from "@mattrglobal/jsonld-signatures-bbs";
import { verify, purposes } from "jsonld-signatures";
import config from './config.json';
import { documentLoader, cli } from './util';
import fsp from 'fs/promises';
import path from 'path';
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
const verifyDiploma = async (credentialConfig: any): Promise<void> => {
const signedDocument = JSON.parse(await fsp.readFile(path.resolve(__dirname, credentialConfig.path_refresh_signed), 'utf8'));
//Verify the proof
let verified = await verify(signedDocument, {
suite: new BbsBlsSignature2020(),
purpose: new purposes.AssertionProofPurpose(),
documentLoader,
});
if (verified.verified) {
console.log(`'${credentialConfig.description}' verified!`);
} else {
throw new Error(`Couldn't verify ${credentialConfig.description}`);
}
await fsp.writeFile(path.resolve(__dirname, credentialConfig.path_original_verified), JSON.stringify(verified, null, 2));
};
cli(config, verifyDiploma);