-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrost_node.py
61 lines (52 loc) · 1.75 KB
/
frost_node.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
import frost
class FrostUser:
def __init__(self, id: int, n: int, t: int): # n --> users , t --> threshold
self.id = id
self.t = t
self.params = frost.Parameters(n, t)
self.user = frost.Participant(self.params, self.id)
self.user.verify_proof_of_secret_key()
def round1(self, parties_list: list[bytes]):
self.other_participants = [
frost.Participant.load(p, self.t) for p in parties_list
]
self.user_state = frost.DistributedKeyGenerationR1(
self.params, self.user, self.other_participants
)
self.user_their_secret_shares = self.user_state.their_secret_shares()
def round2(self, their_secret_shares: list[list[int]]):
self.user_my_secret_shares = [
bytes(dict(secret_shares)[self.id]) for secret_shares in their_secret_shares
]
self.user_state = self.user_state.to_round_two(
self.id, self.user_my_secret_shares
)
(
self.user_group_key,
self.user_secret_key,
self.user_public_key,
) = self.user_state.finish(self.user)
def generate_commitments(
self,
):
(
self.user_public_comshares,
self.user_secret_comshares,
) = frost.generate_commitment_share_lists(self.id, 1)
def will_sign(
self,
):
return True
def sign(self, msg_hash, signers):
self.user_partial = frost.sign(
self.id,
self.user_secret_key,
msg_hash,
self.user_group_key,
self.user_secret_comshares,
0,
signers,
)
return self.user_partial
def encode(self):
return bytes(self.user.encode(self.t))