@@ -26,6 +26,9 @@ import (
26
26
"github.com/bnb-chain/tss-lib/v2/ecdsa/keygen"
27
27
"github.com/bnb-chain/tss-lib/v2/ecdsa/signing"
28
28
"github.com/bnb-chain/tss-lib/v2/tss"
29
+ "github.com/btcsuite/btcd/btcec/v2"
30
+ s256k1 "github.com/btcsuite/btcd/btcec/v2"
31
+ "github.com/decred/dcrd/dcrec/secp256k1/v4"
29
32
"github.com/golang/protobuf/proto"
30
33
"github.com/golang/protobuf/ptypes/any"
31
34
)
@@ -106,14 +109,20 @@ type party struct {
106
109
in chan tss.Message
107
110
shareData * keygen.LocalPartySaveData
108
111
closeChan chan struct {}
112
+ curve elliptic.Curve
109
113
}
110
114
111
- func NewParty (id uint16 , logger Logger ) * party {
115
+ func NewParty (id uint16 , curve elliptic.Curve , logger Logger ) * party {
116
+ if curve == nil {
117
+ curve = s256k1 .S256 ()
118
+ }
119
+
112
120
return & party {
113
121
logger : logger ,
114
122
id : tss .NewPartyID (fmt .Sprintf ("%d" , id ), "" , big .NewInt (int64 (id ))),
115
123
out : make (chan tss.Message , 1000 ),
116
124
in : make (chan tss.Message , 1000 ),
125
+ curve : curve ,
117
126
}
118
127
}
119
128
@@ -190,7 +199,17 @@ func (p *party) ThresholdPK() ([]byte, error) {
190
199
if err != nil {
191
200
return nil , err
192
201
}
193
- return x509 .MarshalPKIXPublicKey (pk )
202
+
203
+ switch p .curve .Params ().Name {
204
+ case string (tss .Secp256k1 ):
205
+ xFieldVal , yFieldVal := new (secp256k1.FieldVal ), new (secp256k1.FieldVal )
206
+ xFieldVal .SetByteSlice (pk .X .Bytes ())
207
+ yFieldVal .SetByteSlice (pk .Y .Bytes ())
208
+ btcecPubKey := btcec .NewPublicKey (xFieldVal , yFieldVal )
209
+ return btcecPubKey .SerializeCompressed (), nil
210
+ default :
211
+ return x509 .MarshalPKIXPublicKey (pk )
212
+ }
194
213
}
195
214
196
215
func (p * party ) SetShareData (shareData []byte ) error {
@@ -199,9 +218,9 @@ func (p *party) SetShareData(shareData []byte) error {
199
218
if err != nil {
200
219
return fmt .Errorf ("failed deserializing shares: %w" , err )
201
220
}
202
- localSaveData .ECDSAPub .SetCurve (elliptic . P256 () )
221
+ localSaveData .ECDSAPub .SetCurve (p . curve )
203
222
for _ , xj := range localSaveData .BigXj {
204
- xj .SetCurve (elliptic . P256 () )
223
+ xj .SetCurve (p . curve )
205
224
}
206
225
p .shareData = & localSaveData
207
226
return nil
@@ -210,7 +229,7 @@ func (p *party) SetShareData(shareData []byte) error {
210
229
func (p * party ) Init (parties []uint16 , threshold int , sendMsg func (msg []byte , isBroadcast bool , to uint16 )) {
211
230
partyIDs := partyIDsFromNumbers (parties )
212
231
ctx := tss .NewPeerContext (partyIDs )
213
- p .params = tss .NewParameters (elliptic . P256 () , ctx , p .id , len (parties ), threshold )
232
+ p .params = tss .NewParameters (p . curve , ctx , p .id , len (parties ), threshold )
214
233
p .id .Index = p .locatePartyIndex (p .id )
215
234
p .sendMsg = sendMsg
216
235
p .closeChan = make (chan struct {})
@@ -237,7 +256,7 @@ func (p *party) Sign(ctx context.Context, msgHash []byte) ([]byte, error) {
237
256
238
257
end := make (chan * common.SignatureData , 1 )
239
258
240
- msgToSign := hashToInt (msgHash , elliptic . P256 () )
259
+ msgToSign := hashToInt (msgHash , p . curve )
241
260
party := signing .NewLocalParty (msgToSign , p .params , * p .shareData , p .out , end )
242
261
243
262
var endWG sync.WaitGroup
0 commit comments