-
Notifications
You must be signed in to change notification settings - Fork 0
/
finalize.go
executable file
·78 lines (65 loc) · 2 KB
/
finalize.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
// 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 signing
import (
"errors"
"fmt"
"math/big"
"github.com/agl/ed25519/edwards25519"
"github.com/decred/dcrd/dcrec/edwards/v2"
"github.com/sodiumlabs/tss-lib/common"
"github.com/sodiumlabs/tss-lib/tss"
)
func (round *finalization) Start() *tss.Error {
if round.started {
return round.WrapError(errors.New("round already started"))
}
round.number = 4
round.started = true
round.resetOK()
sumS := round.temp.si
for j := range round.Parties().IDs() {
round.ok[j] = true
if j == round.PartyID().Index {
continue
}
r3msg := round.temp.signRound3Messages[j].Content().(*SignRound3Message)
sjBytes := bigIntToEncodedBytes(r3msg.UnmarshalS())
var tmpSumS [32]byte
edwards25519.ScMulAdd(&tmpSumS, sumS, bigIntToEncodedBytes(big.NewInt(1)), sjBytes)
sumS = &tmpSumS
}
s := encodedBytesToBigInt(sumS)
// save the signature for final output
signature := new(common.ECSignature)
signature.Signature = append(bigIntToEncodedBytes(round.temp.r)[:], sumS[:]...)
signature.R = round.temp.r.Bytes()
signature.S = s.Bytes()
signature.M = round.temp.m.Bytes()
round.data.Signature = signature
pk := edwards.PublicKey{
Curve: tss.EC("eddsa"),
X: round.key.EDDSAPub.X(),
Y: round.key.EDDSAPub.Y(),
}
ok := edwards.Verify(&pk, round.temp.m.Bytes(), round.temp.r, s)
if !ok {
return round.WrapError(fmt.Errorf("signature verification failed"))
}
round.end <- round.data
return nil
}
func (round *finalization) CanAccept(msg tss.ParsedMessage) bool {
// not expecting any incoming messages in this round
return false
}
func (round *finalization) Update() (bool, *tss.Error) {
// not expecting any incoming messages in this round
return false, nil
}
func (round *finalization) NextRound() tss.Round {
return nil // finished!
}