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
/
caller.py
executable file
·73 lines (59 loc) · 1.74 KB
/
caller.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
#!/bin/python
import socketio
import sys
import coov_api
import vc_util
import eoskey
import random
import threading
if len(sys.argv) != 2:
print(f"{sys.argv[0]} <responder session code>")
exit()
if not vc_util.did_valid(sys.argv[1]):
print("Invaild session code")
exit()
key_pub = eoskey.eos_keygen()[1]
key_nonce = eoskey.eos_keygen()[1]
url, servernum, responder_session_id = vc_util.diduri_split(sys.argv[1])
sio = socketio.Client()
def timeout():
sio.disconnect()
print("No response from other")
resp_timeout = threading.Timer(5, timeout)
def send_data(to, data):
sio.emit('send', {
'to': f'{servernum}/'+to,
'data': data
})
@sio.on('send')
def on_msg(data):
try:
did_data = vc_util.vc_verify(data['data']['vp'])
assert vc_util.did_strip(did_data['nonce']) == key_nonce
for vc in did_data['vp']['verifiableCredential']:
vc_json = vc_util.vc_verify(vc, check_issuer=coov_api.KDCA_DID, check_subject=did_data['iss'])
for k, v in vc_json['vc']['credentialSubject'].items():
print(f'{k}: {v}')
send_data(
responder_session_id,
{
'from': sio.get_sid(),
'result': 'success',
'successCode': f'{random.randrange(100):02d}'
}
)
sio.sleep(0.01)
except:
print(sys.exc_info()[2])
finally:
resp_timeout.cancel()
sio.disconnect()
sio.connect(f'https://{url.replace("wss", f"wss-{servernum}")}', transports="websocket")
send_data(
responder_session_id,
{
'from': sio.get_sid(),
'verifierDid': vc_util.did_append(key_pub),
'challenge': vc_util.did_append(key_nonce)
})
resp_timeout.start()