-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.go
executable file
·125 lines (107 loc) · 2.95 KB
/
messages.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
// 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 (
"math/big"
"github.com/sodiumlabs/tss-lib/common"
"github.com/sodiumlabs/tss-lib/crypto"
cmt "github.com/sodiumlabs/tss-lib/crypto/commitments"
"github.com/sodiumlabs/tss-lib/crypto/zkp"
"github.com/sodiumlabs/tss-lib/tss"
)
// These messages were generated from Protocol Buffers definitions into eddsa-signing.pb.go
var (
// Ensure that signing messages implement ValidateBasic
_ = []tss.MessageContent{
(*SignRound1Message)(nil),
(*SignRound2Message)(nil),
(*SignRound3Message)(nil),
}
)
// ----- //
func NewSignRound1Message(
from *tss.PartyID,
commitment cmt.HashCommitment,
) tss.ParsedMessage {
meta := tss.MessageRouting{
From: from,
IsBroadcast: true,
}
content := &SignRound1Message{
Commitment: commitment.Bytes(),
}
msg := tss.NewMessageWrapper(meta, content)
return tss.NewMessage(meta, content, msg)
}
func (m *SignRound1Message) ValidateBasic() bool {
return m.Commitment != nil &&
common.NonEmptyBytes(m.GetCommitment())
}
func (m *SignRound1Message) UnmarshalCommitment() *big.Int {
return new(big.Int).SetBytes(m.GetCommitment())
}
// ----- //
func NewSignRound2Message(
from *tss.PartyID,
deCommitment cmt.HashDeCommitment,
proof *zkp.DLogProof,
) tss.ParsedMessage {
meta := tss.MessageRouting{
From: from,
IsBroadcast: true,
}
dcBzs := common.BigIntsToBytes(deCommitment)
content := &SignRound2Message{
DeCommitment: dcBzs,
ProofAlpha: proof.Alpha.ToProtobufPoint(),
ProofT: proof.T.Bytes(),
}
msg := tss.NewMessageWrapper(meta, content)
return tss.NewMessage(meta, content, msg)
}
func (m *SignRound2Message) ValidateBasic() bool {
return m != nil &&
m.ProofAlpha != nil &&
common.NonEmptyMultiBytes(m.DeCommitment, 3) &&
m.ProofAlpha.ValidateBasic() &&
common.NonEmptyBytes(m.ProofT)
}
func (m *SignRound2Message) UnmarshalDeCommitment() []*big.Int {
deComBzs := m.GetDeCommitment()
return cmt.NewHashDeCommitmentFromBytes(deComBzs)
}
func (m *SignRound2Message) UnmarshalZKProof() (*zkp.DLogProof, error) {
point, err := crypto.NewECPointFromProtobuf("eddsa", m.GetProofAlpha())
if err != nil {
return nil, err
}
return &zkp.DLogProof{
Alpha: point,
T: new(big.Int).SetBytes(m.GetProofT()),
}, nil
}
// ----- //
func NewSignRound3Message(
from *tss.PartyID,
si *big.Int,
) tss.ParsedMessage {
meta := tss.MessageRouting{
From: from,
IsBroadcast: true,
}
content := &SignRound3Message{
S: si.Bytes(),
}
msg := tss.NewMessageWrapper(meta, content)
return tss.NewMessage(meta, content, msg)
}
func (m *SignRound3Message) ValidateBasic() bool {
return m != nil &&
common.NonEmptyBytes(m.S)
}
func (m *SignRound3Message) UnmarshalS() *big.Int {
return new(big.Int).SetBytes(m.S)
}