Remove signature pack to hex string
This commit is contained in:
parent
1164f7968b
commit
d1a1922ded
@ -1,8 +1,6 @@
|
|||||||
package consensus
|
package consensus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
|
|
||||||
"github.com/Secured-Finance/dione/models"
|
"github.com/Secured-Finance/dione/models"
|
||||||
"github.com/Secured-Finance/dione/sigs"
|
"github.com/Secured-Finance/dione/sigs"
|
||||||
"github.com/Secured-Finance/dione/types"
|
"github.com/Secured-Finance/dione/types"
|
||||||
@ -31,7 +29,7 @@ func (cp *CommitPool) CreateCommit(prepareMsg *models.Message, privateKey []byte
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
consensusMsg.Signature = hex.EncodeToString(signature.Data)
|
consensusMsg.Signature = signature.Data
|
||||||
message.Payload = consensusMsg
|
message.Payload = consensusMsg
|
||||||
return &message, nil
|
return &message, nil
|
||||||
}
|
}
|
||||||
@ -49,11 +47,7 @@ func (cp *CommitPool) IsExistingCommit(commitMsg *models.Message) bool {
|
|||||||
|
|
||||||
func (cp *CommitPool) IsValidCommit(commit *models.Message) bool {
|
func (cp *CommitPool) IsValidCommit(commit *models.Message) bool {
|
||||||
consensusMsg := commit.Payload
|
consensusMsg := commit.Payload
|
||||||
buf, err := hex.DecodeString(consensusMsg.Signature)
|
err := sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: consensusMsg.Signature}, commit.From, []byte(consensusMsg.Data))
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
err = sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: buf}, commit.From, []byte(consensusMsg.Data))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package consensus
|
package consensus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
|
|
||||||
"github.com/Secured-Finance/dione/models"
|
"github.com/Secured-Finance/dione/models"
|
||||||
"github.com/Secured-Finance/dione/sigs"
|
"github.com/Secured-Finance/dione/sigs"
|
||||||
"github.com/Secured-Finance/dione/types"
|
"github.com/Secured-Finance/dione/types"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PrePreparePool struct {
|
type PrePreparePool struct {
|
||||||
@ -30,7 +29,7 @@ func (pp *PrePreparePool) CreatePrePrepare(consensusID, data string, requestID s
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
consensusMsg.Signature = hex.EncodeToString(signature.Data)
|
consensusMsg.Signature = signature.Data
|
||||||
message.Payload = consensusMsg
|
message.Payload = consensusMsg
|
||||||
return &message, nil
|
return &message, nil
|
||||||
}
|
}
|
||||||
@ -49,12 +48,9 @@ func (ppp *PrePreparePool) IsExistingPrePrepare(prepareMsg *models.Message) bool
|
|||||||
func (ppp *PrePreparePool) IsValidPrePrepare(prePrepare *models.Message) bool {
|
func (ppp *PrePreparePool) IsValidPrePrepare(prePrepare *models.Message) bool {
|
||||||
// TODO here we need to do validation of tx itself
|
// TODO here we need to do validation of tx itself
|
||||||
consensusMsg := prePrepare.Payload
|
consensusMsg := prePrepare.Payload
|
||||||
buf, err := hex.DecodeString(consensusMsg.Signature)
|
err := sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: consensusMsg.Signature}, prePrepare.From, []byte(consensusMsg.Data))
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
err = sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: buf}, prePrepare.From, []byte(consensusMsg.Data))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logrus.Errorf("unable to verify signature: %v", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package consensus
|
package consensus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
|
|
||||||
"github.com/Secured-Finance/dione/models"
|
"github.com/Secured-Finance/dione/models"
|
||||||
"github.com/Secured-Finance/dione/sigs"
|
"github.com/Secured-Finance/dione/sigs"
|
||||||
"github.com/Secured-Finance/dione/types"
|
"github.com/Secured-Finance/dione/types"
|
||||||
@ -32,7 +30,7 @@ func (pp *PreparePool) CreatePrepare(prePrepareMsg *models.Message, privateKey [
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
consensusMsg.Signature = hex.EncodeToString(signature.Data)
|
consensusMsg.Signature = signature.Data
|
||||||
message.Payload = consensusMsg
|
message.Payload = consensusMsg
|
||||||
return &message, nil
|
return &message, nil
|
||||||
}
|
}
|
||||||
@ -50,11 +48,7 @@ func (pp *PreparePool) IsExistingPrepare(prepareMsg *models.Message) bool {
|
|||||||
|
|
||||||
func (pp *PreparePool) IsValidPrepare(prepare *models.Message) bool {
|
func (pp *PreparePool) IsValidPrepare(prepare *models.Message) bool {
|
||||||
consensusMsg := prepare.Payload
|
consensusMsg := prepare.Payload
|
||||||
buf, err := hex.DecodeString(consensusMsg.Signature)
|
err := sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: consensusMsg.Signature}, prepare.From, []byte(consensusMsg.Data))
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
err = sigs.Verify(&types.Signature{Type: types.SigTypeEd25519, Data: buf}, prepare.From, []byte(consensusMsg.Data))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ const (
|
|||||||
|
|
||||||
type ConsensusMessage struct {
|
type ConsensusMessage struct {
|
||||||
ConsensusID string
|
ConsensusID string
|
||||||
Signature string
|
Signature []byte
|
||||||
RequestID string
|
RequestID string
|
||||||
CallbackAddress string
|
CallbackAddress string
|
||||||
Data string
|
Data string
|
||||||
|
@ -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.
|
// We can receive our own messages when sending to the topic. So we should drop them.
|
||||||
if senderPeerID == psr.node.ID() {
|
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
|
return
|
||||||
}
|
}
|
||||||
var message models.Message
|
var message models.Message
|
||||||
|
Loading…
Reference in New Issue
Block a user