diff --git a/sign.go b/sign.go index a234d499..1bd04ab8 100644 --- a/sign.go +++ b/sign.go @@ -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 { @@ -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 @@ -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 @@ -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...) +}