-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
39 lines (33 loc) · 1.17 KB
/
functions.py
File metadata and controls
39 lines (33 loc) · 1.17 KB
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
def createCert(a):
a[3] = str(a[3])
ar = "+".join(a)
ar_hash = sha256(ar.encode()).hexdigest()
newuser = ({
"name": a[0],
"Matric No": a[1],
"Course": a[2],
"Year": a[3],
"Hash": ar_hash
})
db.insert_one(newuser)
Mktree.encryptRecord(ar)
img = Image.open('Cert_template.png')
qr = qrcode.QRCode(box_size=2)
qr.add_data([str(ar_hash), Mktree.get_commitment().decode("utf-8")], optimize=0)
qr.make()
test = qr.make_image(fill_color="black", back_color="white").convert('RGB')
img.paste(test, (330, 460))
I1 = ImageDraw.Draw(img)
font = ImageFont.truetype('font.ttf', 30)
I1.text((288, 156), a[0], font=font, fill=(0, 0, 0))
I1.text((288, 246), a[1], font=font, fill=(0, 0, 0))
I1.text((268, 326), a[2], font=font, fill=(0, 0, 0))
I1.text((348, 416), a[3], font=font, fill=(0, 0, 0))
img.save('uploads/certs/' + a[0] + '.png')
def validateCert(roothash, certhash):
loaded_tree = MerkleTree.loadFromFile(roothash)
challenge = {
'checksum' : certhash
}
merkle_proof = loaded_tree.merkleProof(challenge)
validateProof(merkle_proof)