/
round_2.go
71 lines (58 loc) · 1.7 KB
/
round_2.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
// 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"
errors2 "github.com/pkg/errors"
"github.com/holynull/tss-wasm-lib/crypto/schnorr"
"github.com/holynull/tss-wasm-lib/tss"
)
func (round *round2) Start() *tss.Error {
if round.started {
return round.WrapError(errors.New("round already started"))
}
round.number = 2
round.started = true
round.resetOK()
i := round.PartyID().Index
// 1. store r1 message pieces
for j, msg := range round.temp.signRound1Messages {
r1msg := msg.Content().(*SignRound1Message)
round.temp.cjs[j] = r1msg.UnmarshalCommitment()
}
// 2. compute Schnorr prove
pir, err := schnorr.NewZKProof(round.temp.ri, round.temp.pointRi)
if err != nil {
return round.WrapError(errors2.Wrapf(err, "NewZKProof(ri, pointRi)"))
}
// 3. BROADCAST de-commitments of Shamir poly*G and Schnorr prove
r2msg2 := NewSignRound2Message(round.PartyID(), round.temp.deCommit, pir)
round.temp.signRound2Messages[i] = r2msg2
round.out <- r2msg2
return nil
}
func (round *round2) CanAccept(msg tss.ParsedMessage) bool {
if _, ok := msg.Content().(*SignRound2Message); ok {
return msg.IsBroadcast()
}
return false
}
func (round *round2) Update() (bool, *tss.Error) {
for j, msg := range round.temp.signRound2Messages {
if round.ok[j] {
continue
}
if msg == nil || !round.CanAccept(msg) {
return false, nil
}
round.ok[j] = true
}
return true, nil
}
func (round *round2) NextRound() tss.Round {
round.started = false
return &round3{round}
}