prefix signed data with libp2p-pubsub:
This commit is contained in:
parent
777c68fe0e
commit
9fa8f64fd3
10
sign.go
10
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...)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue