7
7
package signing
8
8
9
9
import (
10
+ "bytes"
10
11
"crypto/ecdsa"
11
12
"fmt"
12
13
"runtime"
@@ -40,6 +41,10 @@ const (
40
41
victimPartySimulatingAbort = 1
41
42
)
42
43
44
+ var (
45
+ msg = big .NewInt (42 )
46
+ )
47
+
43
48
func setUp (level string ) {
44
49
if err := log .SetLogLevel ("tss-lib" , level ); err != nil {
45
50
panic (err )
@@ -77,7 +82,7 @@ func TestE2EConcurrent(t *testing.T) {
77
82
params , _ := tss .NewParameters (tss .S256 (), p2pCtx , signPIDs [i ], len (signPIDs ), threshold )
78
83
79
84
keyDerivationDelta := big .NewInt (0 )
80
- P_ , errP := NewLocalParty (big . NewInt ( 42 ) , params , keys [i ], keyDerivationDelta , outCh , endCh , sessionId )
85
+ P_ , errP := NewLocalParty (msg , params , keys [i ], keyDerivationDelta , outCh , endCh , sessionId )
81
86
if errP != nil {
82
87
t .Errorf ("error %v" , errP )
83
88
t .FailNow ()
@@ -123,7 +128,7 @@ signing:
123
128
// P = ...... with dtemp
124
129
// P.start
125
130
126
- case <- endCh :
131
+ case end := <- endCh :
127
132
atomic .AddInt32 (& ended , 1 )
128
133
if atomic .LoadInt32 (& ended ) == int32 (len (signPIDs )) {
129
134
t .Logf ("Done. Received signature data from %d participants" , ended )
@@ -148,7 +153,24 @@ signing:
148
153
X : pkX ,
149
154
Y : pkY ,
150
155
}
151
- ok := ecdsa .Verify (& pk , big .NewInt (42 ).Bytes (), R .X (), sumS )
156
+
157
+ r , s , v := end .R , end .S , end .SignatureRecovery
158
+ sig := make ([]byte , 65 )
159
+ copy (sig [32 - len (r ):32 ], r )
160
+ copy (sig [64 - len (s ):64 ], s )
161
+ sig [64 ] = v [0 ] & 0x01
162
+
163
+ expPub := keys [0 ].ECDSAPub .ToBtcecPubKey ().SerializeUncompressed ()
164
+
165
+ gotPub , err2 := crypto .Ecrecover (msg .Bytes (), sig )
166
+ if ! assert .NoError (t , err2 ) {
167
+ return
168
+ }
169
+ if ! bytes .Equal (expPub , gotPub ) {
170
+ t .Fatalf ("recovered key did not match the expected one" )
171
+ }
172
+
173
+ ok := ecdsa .Verify (& pk , msg .Bytes (), R .X (), sumS )
152
174
assert .True (t , ok , "ecdsa verify must pass" )
153
175
t .Log ("ECDSA signing test done." )
154
176
// END ECDSA verify
@@ -200,7 +222,7 @@ func TestE2EWithHDKeyDerivation(t *testing.T) {
200
222
for i := 0 ; i < len (signPIDs ); i ++ {
201
223
params , _ := tss .NewParameters (tss .S256 (), p2pCtx , signPIDs [i ], len (signPIDs ), threshold )
202
224
203
- P_ , _ := NewLocalParty (big . NewInt ( 42 ) , params , keys [i ], keyDerivationDelta , outCh , endCh , sessionId )
225
+ P_ , _ := NewLocalParty (msg , params , keys [i ], keyDerivationDelta , outCh , endCh , sessionId )
204
226
P := P_ .(* LocalParty )
205
227
parties = append (parties , P )
206
228
go func (P * LocalParty ) {
@@ -260,7 +282,7 @@ signing:
260
282
X : pkX ,
261
283
Y : pkY ,
262
284
}
263
- ok := ecdsa .Verify (& pk , big . NewInt ( 42 ) .Bytes (), R .X (), sumS )
285
+ ok := ecdsa .Verify (& pk , msg .Bytes (), R .X (), sumS )
264
286
assert .True (t , ok , "ecdsa verify must pass" )
265
287
t .Log ("ECDSA signing test done." )
266
288
// END ECDSA verify
@@ -396,7 +418,7 @@ func TestAbortIdentification(t *testing.T) {
396
418
params , _ := tss .NewParameters (tss .S256 (), p2pCtx , signPIDs [i ], len (signPIDs ), threshold )
397
419
398
420
keyDerivationDelta := big .NewInt (0 )
399
- P_ , _ := NewLocalParty (big . NewInt ( 42 ) , params , keys [i ], keyDerivationDelta , outCh , endCh , sessionId )
421
+ P_ , _ := NewLocalParty (msg , params , keys [i ], keyDerivationDelta , outCh , endCh , sessionId )
400
422
P := P_ .(* LocalParty )
401
423
parties = append (parties , P )
402
424
go func (P * LocalParty ) {
@@ -653,7 +675,7 @@ func TestTooManyParties(t *testing.T) {
653
675
654
676
var err error
655
677
var void keygen.LocalPartySaveData
656
- _ , err = NewLocalParty (big . NewInt ( 42 ) , params , void , big .NewInt (0 ), nil , nil , sessionId )
678
+ _ , err = NewLocalParty (msg , params , void , big .NewInt (0 ), nil , nil , sessionId )
657
679
if ! assert .Error (t , err ) {
658
680
t .FailNow ()
659
681
return
0 commit comments