prefix signed data with libp2p-pubsub:

This commit is contained in:
vyzo 2018-08-28 11:43:29 +03:00
parent 777c68fe0e
commit 9fa8f64fd3
1 changed files with 10 additions and 0 deletions

10
sign.go
View File

@ -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...)
}