-
Notifications
You must be signed in to change notification settings - Fork 0
/
verifier.py
62 lines (47 loc) · 1.86 KB
/
verifier.py
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
import asyncio
import json
import didkit
import fileoper
import transferor
class Verifier:
''' Verify a verification credential or a verification presentation. '''
def __init__(self, keyfile):
with open(keyfile, "r", encoding="utf-8") as f:
self.key = f.readline()
f.close()
self.did = didkit.key_to_did("key", self.key)
def verify_vc_file(self, filename):
with open(filename, "r", encoding="utf-8") as f:
jo = json.load(f)
f.close()
jostr = json.dumps(jo)
asyncio.run(self.verify_content(jostr))
async def verify_content(self, content: str):
result = await didkit.verify_credential(content, json.dumps({}))
print(result)
def verify_vp_file(self, filename):
''' Verify a credential presentation. If no error, start a transfer operation. '''
print(f"Verifing {filename}...")
with open(filename, "r", encoding="utf-8") as f:
jo = json.load(f)
f.close()
jostr = json.dumps(jo)
asyncio.run(self.verify_vp_content(jostr))
async def verify_vp_content(self, content: str):
''' Using didkit method to verify VP '''
result = await didkit.verify_presentation(content, json.dumps({}))
resobj = json.loads(result)
if len(resobj["errors"]) == 0:
do_transfer(content)
else:
print("Verification failed!")
def do_transfer(content: str):
runner = transferor.Transferor()
runner.run(content)
def main():
actor = Verifier("user2.key")
#actor.verify_vp_file("../User/req1.json")
#actor.verify_vp_file("../User/reqwithtrans.json")
actor.verify_vp_file("../User/trans0901signed_vp.json")
if __name__ == "__main__":
main()