-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify.ts
45 lines (40 loc) · 1.13 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { NextApiRequest, NextApiResponse } from "next";
import MyInfoVcVerifier from "@/lib/myinfo-vc-verifier";
interface VerifyVcApiRequest extends NextApiRequest {
body: {
vcData: string; // Verifiable Credential data in format of JSON string
};
}
type VerifyVCResponseData = {
error?: string;
verificationResult?: any;
};
export default async function handler(
req: VerifyVcApiRequest,
res: NextApiResponse<VerifyVCResponseData>
) {
if (req.method !== "POST") {
res.status(405).send({
error: "Method Not Allowed",
});
return;
}
try {
const vcData = JSON.parse(req.body.vcData);
// Verify Verifiable Credential
console.log("Verifying Corporate Verifiable Credential...");
const verificationResult = await MyInfoVcVerifier.verify(vcData);
console.log(
"Corporate Verifiable Credential verification result:",
verificationResult
);
res.status(200).send({
verificationResult: verificationResult,
});
} catch (_e) {
let error = _e as Error;
res.status(500).send({
error: error.message,
});
}
}