-
Notifications
You must be signed in to change notification settings - Fork 3
/
encode_resource_in_qr_code.py
39 lines (31 loc) · 1.15 KB
/
encode_resource_in_qr_code.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
import argparse
import json
import time
import secrets
import utils
def main():
parser = argparse.ArgumentParser(description='Encodes a vc')
parser.add_argument('private_keyset_file', help='Private keyset file')
parser.add_argument('issuer', help='Issuer')
parser.add_argument('input_file', help='Sample VC fixture file')
parser.add_argument('output_file', help='Output file')
args = parser.parse_args()
(kid, private_signing_key) = utils.load_private_key_from_file(
args.private_keyset_file,
'sig',
'ES256'
)
with open(args.input_file, 'r') as input_file:
payload = json.load(input_file)
##since we're using a static file to form the payload
## it needs to be modified a bit
now = int(time.time())
payload['iss'] = args.issuer
payload['nbf'] = now
vc_jws = utils.encode_vc(payload, private_signing_key, kid)
numeric_encoded_payload = utils.encode_to_numeric(vc_jws)
qr_img = utils.create_shc_qr_code(numeric_encoded_payload)
with open(args.output_file, 'wb') as outfile:
qr_img.save(outfile)
if __name__ == "__main__":
main()