-
Notifications
You must be signed in to change notification settings - Fork 2
/
msg.go
55 lines (42 loc) · 1.21 KB
/
msg.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
package types
import (
ra "github.com/HermitMatrixNetwork/HermitMatrixNetwork/x/registration/remote_attestation"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const (
MaxCertificateSize = 20 * 1024
)
type PublicKey []byte
func (msg RaAuthenticate) Route() string {
return RouterKey
}
func (msg RaAuthenticate) Type() string {
return "node-auth"
}
func (msg RaAuthenticate) ValidateBasic() error {
if err := sdk.VerifyAddressFormat(msg.Sender); err != nil {
return err
}
if len(msg.Certificate) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "Authenticating certificate cannot be empty")
}
if len(msg.Certificate) > MaxCertificateSize {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "certificate length too large")
}
return validateCertificate(msg.Certificate)
}
func (msg RaAuthenticate) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
func (msg RaAuthenticate) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Sender}
}
func validateCertificate(cert ra.Certificate) error {
// todo: add public key verification
_, err := ra.VerifyRaCert(cert)
if err != nil {
return err
}
return nil
}