This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
responder.py
executable file
·83 lines (67 loc) · 1.81 KB
/
responder.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/python
import socketio
import time
import vc_util
import configparser
import sys
import os
QR_CODE = True
if not os.path.isfile('coov.ini'):
print('Cannot find config file')
exit()
config = configparser.ConfigParser()
config.read('coov.ini')
if len(sys.argv) != 3:
print(f"{sys.argv[0]} <credential type> <comma-separated vc types>")
print("Available credential types: user, vaccine")
print(f"Available VC types: {', '.join(config['VC'])}")
exit()
key_priv = config['Key']['private']
vp_type = sys.argv[1]
assert vp_type in ['user', 'vaccine']
vc_list = sys.argv[2].split(',')
vc = []
for vc_type in vc_list:
vc.append(config['VC'][vc_type.lower()])
has_dob = True if 'dob' in vc_list else None
has_name = True if 'name' in vc_list else None
sio = socketio.Client()
@sio.on('send')
def on_msg(data):
if res := data['data'].get('result'):
if res == 'success':
print("Verify success")
sio.disconnect()
else:
print("Request received")
vp = vc_util.makevp(
key_priv,
[data['data']['verifierDid']],
data['data']['challenge'],
vc
)
send_data(
data['data']['from'],
{
'from': sio.get_sid(),
'vp': vp,
'user': {'dob': has_dob, 'name': has_name},
'type':vp_type,
'hasPassport': False
}
)
def send_data(to, data):
sio.emit('send', {
'to': to,
'data': data
})
@sio.event
def connect():
sid_uri = f'did:infra:vp:wss.coov.io/{sio.get_sid()}'
if QR_CODE:
import qrcode
qr = qrcode.QRCode()
qr.add_data(sid_uri)
qr.print_ascii()
print(sid_uri)
sio.connect('https://wss.coov.io/', transports='websocket')