forked from bnb-chain/tss-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.go
147 lines (121 loc) · 3.54 KB
/
params.go
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright © 2019 Binance
//
// This file is part of Binance. The full Binance copyright notice, including
// terms governing use, modification, and redistribution, is contained in the
// file LICENSE at the root of the source code distribution tree.
package tss
import (
"crypto/elliptic"
"runtime"
"time"
)
type (
Parameters struct {
ec elliptic.Curve
partyID *PartyID
parties *PeerContext
partyCount int
threshold int
concurrency int
safePrimeGenTimeout time.Duration
}
ReSharingParameters struct {
*Parameters
newParties *PeerContext
newPartyCount int
newThreshold int
}
)
const (
defaultSafePrimeGenTimeout = 5 * time.Minute
)
// Exported, used in `tss` client
func NewParameters(ec elliptic.Curve, ctx *PeerContext, partyID *PartyID, partyCount, threshold int) *Parameters {
return &Parameters{
ec: ec,
parties: ctx,
partyID: partyID,
partyCount: partyCount,
threshold: threshold,
concurrency: runtime.GOMAXPROCS(0),
safePrimeGenTimeout: defaultSafePrimeGenTimeout,
}
}
func (params *Parameters) EC() elliptic.Curve {
return params.ec
}
func (params *Parameters) Parties() *PeerContext {
return params.parties
}
func (params *Parameters) PartyID() *PartyID {
return params.partyID
}
func (params *Parameters) PartyCount() int {
return params.partyCount
}
func (params *Parameters) Threshold() int {
return params.threshold
}
func (params *Parameters) Concurrency() int {
return params.concurrency
}
func (params *Parameters) SafePrimeGenTimeout() time.Duration {
return params.safePrimeGenTimeout
}
// The concurrency level must be >= 1.
func (params *Parameters) SetConcurrency(concurrency int) {
params.concurrency = concurrency
}
func (params *Parameters) SetSafePrimeGenTimeout(timeout time.Duration) {
params.safePrimeGenTimeout = timeout
}
// ----- //
// Exported, used in `tss` client
func NewReSharingParameters(ec elliptic.Curve, ctx, newCtx *PeerContext, partyID *PartyID, partyCount, threshold, newPartyCount, newThreshold int) *ReSharingParameters {
params := NewParameters(ec, ctx, partyID, partyCount, threshold)
return &ReSharingParameters{
Parameters: params,
newParties: newCtx,
newPartyCount: newPartyCount,
newThreshold: newThreshold,
}
}
func (rgParams *ReSharingParameters) OldParties() *PeerContext {
return rgParams.Parties() // wr use the original method for old parties
}
func (rgParams *ReSharingParameters) OldPartyCount() int {
return rgParams.partyCount
}
func (rgParams *ReSharingParameters) NewParties() *PeerContext {
return rgParams.newParties
}
func (rgParams *ReSharingParameters) NewPartyCount() int {
return rgParams.newPartyCount
}
func (rgParams *ReSharingParameters) NewThreshold() int {
return rgParams.newThreshold
}
func (rgParams *ReSharingParameters) OldAndNewParties() []*PartyID {
return append(rgParams.OldParties().IDs(), rgParams.NewParties().IDs()...)
}
func (rgParams *ReSharingParameters) OldAndNewPartyCount() int {
return rgParams.OldPartyCount() + rgParams.NewPartyCount()
}
func (rgParams *ReSharingParameters) IsOldCommittee() bool {
partyID := rgParams.partyID
for _, Pj := range rgParams.parties.IDs() {
if partyID.KeyInt().Cmp(Pj.KeyInt()) == 0 {
return true
}
}
return false
}
func (rgParams *ReSharingParameters) IsNewCommittee() bool {
partyID := rgParams.partyID
for _, Pj := range rgParams.newParties.IDs() {
if partyID.KeyInt().Cmp(Pj.KeyInt()) == 0 {
return true
}
}
return false
}