-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate_master_dkg.py
74 lines (57 loc) · 1.98 KB
/
generate_master_dkg.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 18 14:30:49 2019
@author: jordip
"""
import sys
import hashlib
import consensus
import utils, logger
logger.setup_custom_logger('Consensus')
DKG_NUMBER_PARTICIPANTS = 100
#Make the random selection
random_no = utils.compress_random_no_to_int('0xfab206a4186845ff0f0192fd06be977971a7dedbf9c22173cc38d23625aac2a7', 16)
random_no_string = '0xfab206a4186845ff0f0192fd06be977971a7dedbf9c22173cc38d23625aac2a7'
#Load master addresses
#List all addresses at the moment in the chain
all_addresses = []
try:
all_addr = open('dataset/master-all-addrs-db-order.txt', 'r')
except Exception as e:
print e
sys.exit(1)
for line in all_addr:
all_addresses.append(line.rstrip('\n'))
all_addr.close()
#Randomly select participants from all the addresses
dkg_group = []
for i in range(DKG_NUMBER_PARTICIPANTS):
random_pos = random_no % len(all_addresses)
dkg_group.append(utils.normalize_address(all_addresses.pop(random_pos)))
random_no = utils.compress_random_no_to_int(hashlib.sha256(str(random_no)).hexdigest(), 16)
print "Selected the following addresses for the DKG:"
for elem in dkg_group:
print elem.encode('hex')
#Generate DKG shares
cons = consensus.Consensus(dkg_group, dkg_group, random_no_string, "0x00", 0, "0x00")
to_send = cons.new_dkg(dkg_group, dkg_group)
#Since we have given him all nodes, we can join the DKG shares directly
if cons.all_node_dkgs_finished():
print "Group key is: ", cons.get_current_group_key()
print "Now writing private keys in file"
else:
print "Fatal error, we own all nodes, DKG should be finished. Exiting"
sys.exit(1)
#Store private keys in file
try:
priv_keys = open('master-private-dkg-keys.txt', 'w')
except Exception as e:
print e
sys.exit(1)
for node in dkg_group:
oid = node
secretkey = cons.secretKeys[oid]
priv_keys.write(oid.encode('hex') + ' ' + secretkey + '\n')
priv_keys.close()
print "Done"