Skip to content

Commit

Permalink
prefix signed data with libp2p-pubsub:
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Aug 28, 2018
1 parent 117e0f2 commit 6bfec03
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
peer "github.com/libp2p/go-libp2p-peer"
)

const SignPrefix = "libp2p-pubsub:"

func verifyMessageSignature(m *pb.Message) error {
pubk, err := messagePubKey(m)
if err != nil {
Expand All @@ -26,6 +28,8 @@ func verifyMessageSignature(m *pb.Message) error {
return err
}

bytes = withSignPrefix(bytes)

valid, err := pubk.Verify(bytes, m.Signature)
if err != nil {
return err
Expand Down Expand Up @@ -73,6 +77,8 @@ func signMessage(key crypto.PrivKey, m *pb.Message) error {
return err
}

bytes = withSignPrefix(bytes)

sig, err := key.Sign(bytes)
if err != nil {
return err
Expand All @@ -89,3 +95,7 @@ func signMessage(key crypto.PrivKey, m *pb.Message) error {
}
return nil
}

func withSignPrefix(bytes []byte) []byte {
return append([]byte(SignPrefix), bytes...)
}

0 comments on commit 6bfec03

Please sign in to comment.