Remove signature pack to hex string

This commit is contained in:
ChronosX88 2020-11-18 22:14:56 +04:00
parent 1164f7968b
commit d1a1922ded
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
5 changed files with 9 additions and 26 deletions

View File

@ -1,8 +1,6 @@
package consensus
import (
"encoding/hex"
"github.com/Secured-Finance/dione/models"
"github.com/Secured-Finance/dione/sigs"
"github.com/Secured-Finance/dione/types"
@ -31,7 +29,7 @@ func (cp *CommitPool) CreateCommit(prepareMsg *models.Message, privateKey []byte
if err != nil {
return nil, err
}
consensusMsg.Signature = hex.EncodeToString(signature.Data)
consensusMsg.Signature = signature.Data
message.Payload = consensusMsg
return &message, nil
}
@ -49,11 +47,7 @@ func (cp *CommitPool) IsExistingCommit(commitMsg *models.Message) bool {
func (cp *CommitPool) IsValidCommit(commit *models.Message) bool {
consensusMsg := commit.Payload
buf, err := hex.DecodeString(consensusMsg.Signature)
if err != nil {
return false
}
err = sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: buf}, commit.From, []byte(consensusMsg.Data))
err := sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: consensusMsg.Signature}, commit.From, []byte(consensusMsg.Data))
if err != nil {
return false
}

View File

@ -1,11 +1,10 @@
package consensus
import (
"encoding/hex"
"github.com/Secured-Finance/dione/models"
"github.com/Secured-Finance/dione/sigs"
"github.com/Secured-Finance/dione/types"
"github.com/sirupsen/logrus"
)
type PrePreparePool struct {
@ -30,7 +29,7 @@ func (pp *PrePreparePool) CreatePrePrepare(consensusID, data string, requestID s
if err != nil {
return nil, err
}
consensusMsg.Signature = hex.EncodeToString(signature.Data)
consensusMsg.Signature = signature.Data
message.Payload = consensusMsg
return &message, nil
}
@ -49,12 +48,9 @@ func (ppp *PrePreparePool) IsExistingPrePrepare(prepareMsg *models.Message) bool
func (ppp *PrePreparePool) IsValidPrePrepare(prePrepare *models.Message) bool {
// TODO here we need to do validation of tx itself
consensusMsg := prePrepare.Payload
buf, err := hex.DecodeString(consensusMsg.Signature)
if err != nil {
return false
}
err = sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: buf}, prePrepare.From, []byte(consensusMsg.Data))
err := sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: consensusMsg.Signature}, prePrepare.From, []byte(consensusMsg.Data))
if err != nil {
logrus.Errorf("unable to verify signature: %v", err)
return false
}
return true

View File

@ -1,8 +1,6 @@
package consensus
import (
"encoding/hex"
"github.com/Secured-Finance/dione/models"
"github.com/Secured-Finance/dione/sigs"
"github.com/Secured-Finance/dione/types"
@ -32,7 +30,7 @@ func (pp *PreparePool) CreatePrepare(prePrepareMsg *models.Message, privateKey [
if err != nil {
return nil, err
}
consensusMsg.Signature = hex.EncodeToString(signature.Data)
consensusMsg.Signature = signature.Data
message.Payload = consensusMsg
return &message, nil
}
@ -50,11 +48,7 @@ func (pp *PreparePool) IsExistingPrepare(prepareMsg *models.Message) bool {
func (pp *PreparePool) IsValidPrepare(prepare *models.Message) bool {
consensusMsg := prepare.Payload
buf, err := hex.DecodeString(consensusMsg.Signature)
if err != nil {
return false
}
err = sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: buf}, prepare.From, []byte(consensusMsg.Data))
err := sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: consensusMsg.Signature}, prepare.From, []byte(consensusMsg.Data))
if err != nil {
return false
}

View File

@ -16,7 +16,7 @@ const (
type ConsensusMessage struct {
ConsensusID string
Signature string
Signature []byte
RequestID string
CallbackAddress string
Data string

View File

@ -74,7 +74,6 @@ func (psr *PubSubRouter) handleMessage(p *pubsub.Message) {
}
// We can receive our own messages when sending to the topic. So we should drop them.
if senderPeerID == psr.node.ID() {
logrus.Debug("Drop message because it came from the current node - a bug (or feature) in the pubsub system")
return
}
var message models.Message