-
Notifications
You must be signed in to change notification settings - Fork 0
/
DIDStampVCVerifier.ts
78 lines (58 loc) · 3.11 KB
/
DIDStampVCVerifier.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// import { createCredential } from "../utils/didkitSign"
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { ethers } from "hardhat";
import DIDKitSignedCredential from "../mocks/DIDKitSignedCredential.json";
import {
AttestationStation,
AttestationStation__factory,
DIDStampVcVerifier,
DIDStampVcVerifier__factory,
} from "../src/types";
import { DocumentStruct } from "../types";
import { normalizeDIDCredential } from "../utils/normalizeDIDCredential";
const domainName = "Passport";
describe("DIDStampVCVerifier", function () {
let signer: SignerWithAddress;
let submitter: SignerWithAddress;
let didStampVCVerifier: DIDStampVcVerifier;
beforeEach(async function () {
const signers = await ethers.getSigners();
signer = signers[0];
submitter = signers[1];
});
it("should verify a didkit issued VC using the DIDStampVcVerifier smart contract", async function () {
const atteststationStation = <AttestationStation__factory>await ethers.getContractFactory("AttestationStation");
const attestationStation = <AttestationStation>await atteststationStation.connect(signer).deploy();
await attestationStation.deployed();
const stampVcVerifierFactory = <DIDStampVcVerifier__factory>await ethers.getContractFactory("DIDStampVcVerifier");
didStampVCVerifier = <DIDStampVcVerifier>(
await stampVcVerifierFactory.connect(signer).deploy(domainName, signer.address, attestationStation.address)
);
await didStampVCVerifier.deployed();
const { v, r, s } = ethers.utils.splitSignature(DIDKitSignedCredential.proof.proofValue);
const normalizedDIDCredential = normalizeDIDCredential(DIDKitSignedCredential) as DocumentStruct;
await expect(await didStampVCVerifier.connect(submitter).verifyStampVc(normalizedDIDCredential, v, r, s)).to.emit(
didStampVCVerifier,
"Verified",
);
});
it("should call the make an attestation on the attestation contract if signature is valid", async function () {
const atteststationStation = <AttestationStation__factory>await ethers.getContractFactory("AttestationStation");
const attestationStation = <AttestationStation>await atteststationStation.connect(signer).deploy();
console.log(attestationStation.address, "attestationStation.address");
await attestationStation.deployed();
const stampVcVerifierFactory = <DIDStampVcVerifier__factory>await ethers.getContractFactory("DIDStampVcVerifier");
didStampVCVerifier = <DIDStampVcVerifier>(
await stampVcVerifierFactory.connect(signer).deploy(domainName, signer.address, attestationStation.address)
);
console.log(didStampVCVerifier.address, "didStampVCVerifier.address");
await didStampVCVerifier.deployed();
const { v, r, s } = ethers.utils.splitSignature(DIDKitSignedCredential.proof.proofValue);
const normalizedDIDCredential = normalizeDIDCredential(DIDKitSignedCredential) as DocumentStruct;
await expect(await didStampVCVerifier.connect(submitter).verifyStampVc(normalizedDIDCredential, v, r, s)).to.emit(
attestationStation,
"AttestationCreated",
);
});
});