This repository has been archived by the owner on Jun 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
signature_proposal_validation.go
84 lines (66 loc) · 2.11 KB
/
signature_proposal_validation.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
package requests
import (
"errors"
"fmt"
"github.com/lidofinance/dc4bc/fsm/config"
)
func (r *SignatureProposalParticipantsListRequest) Validate() error {
if len(r.Participants) < config.ParticipantsMinCount {
return fmt.Errorf("too few participants, minimum is {%d}", config.ParticipantsMinCount)
}
if r.SigningThreshold < config.SignatureProposalSigningThresholdMinCount {
return fmt.Errorf(
"{SigningThreshold} minimum count is {%d}",
config.SignatureProposalSigningThresholdMinCount,
)
}
if r.SigningThreshold > len(r.Participants) {
return errors.New("{SigningThreshold} cannot be higher than {ParticipantsCount}")
}
uniqueUsernames := make(map[string]bool)
for _, participant := range r.Participants {
if _, ok := uniqueUsernames[participant.Username]; ok {
return errors.New("{Username} must be unique")
}
uniqueUsernames[participant.Username] = true
}
for _, participant := range r.Participants {
if len(participant.Username) < config.UsernameMinLength {
return fmt.Errorf("{Username} minimum length is {%d}", config.UsernameMinLength)
}
if len(participant.Username) > config.UsernameMaxLength {
return fmt.Errorf("{Username} maximum length is {%d}", config.UsernameMaxLength)
}
if len(participant.PubKey) < config.ParticipantPubKeyMinLength {
return errors.New("{PubKey} too short")
}
if len(participant.DkgPubKey) < config.DkgPubKeyMinLength {
return errors.New("{DkgPubKey} too short")
}
}
if r.CreatedAt.IsZero() {
return errors.New("{CreatedAt} cannot be a nil")
}
return nil
}
func (r *SignatureProposalParticipantRequest) Validate() error {
if r.ParticipantId < 0 {
return errors.New("{ParticipantId} cannot be a negative number")
}
if r.CreatedAt.IsZero() {
return errors.New("{CreatedAt} cannot be a nil")
}
return nil
}
func (r *SignatureProposalConfirmationErrorRequest) Validate() error {
if r.ParticipantId < 0 {
return errors.New("{ParticipantId} cannot be a negative number")
}
if r.Error == nil {
return errors.New("{Error} cannot be a nil")
}
if r.CreatedAt.IsZero() {
return errors.New("{CreatedAt} is not set")
}
return nil
}