2020-12-02 21:18:47 +00:00
|
|
|
package filecoin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"github.com/Secured-Finance/dione/consensus/validation"
|
|
|
|
rtypes "github.com/Secured-Finance/dione/rpc/types"
|
|
|
|
|
|
|
|
ftypes "github.com/Secured-Finance/dione/rpc/filecoin/types"
|
|
|
|
"github.com/Secured-Finance/dione/sigs"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ValidateGetTransaction(payload []byte) error {
|
|
|
|
var msg ftypes.SignedMessage
|
|
|
|
if err := msg.UnmarshalCBOR(bytes.NewReader(payload)); err != nil {
|
|
|
|
if err := msg.Message.UnmarshalCBOR(bytes.NewReader(payload)); err != nil {
|
2021-04-22 19:42:44 +00:00
|
|
|
return xerrors.Errorf("cannot unmarshal payload: %s", err.Error())
|
2020-12-02 21:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if msg.Type == ftypes.MessageTypeSecp256k1 {
|
2020-12-12 12:44:01 +00:00
|
|
|
if err := sigs.Verify(&msg.Signature, msg.Message.From.Bytes(), msg.Message.Cid().Bytes()); err != nil {
|
2020-12-02 21:18:47 +00:00
|
|
|
logrus.Errorf("Couldn't verify transaction %v", err)
|
|
|
|
return xerrors.Errorf("Couldn't verify transaction: %v")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
// TODO: BLS Signature verification
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
validation.RegisterValidation(rtypes.RPCTypeFilecoin, map[string]func([]byte) error{
|
|
|
|
"getTransaction": ValidateGetTransaction,
|
|
|
|
})
|
|
|
|
}
|