From 10c2e20910bfea028b17923d509199ef4b88d1aa Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 26 May 2023 11:18:00 -0400 Subject: [PATCH] fix: signatures --- waku/v2/protocol/relay/validators.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/waku/v2/protocol/relay/validators.go b/waku/v2/protocol/relay/validators.go index c6bcac67..a3dd1c55 100644 --- a/waku/v2/protocol/relay/validators.go +++ b/waku/v2/protocol/relay/validators.go @@ -1,7 +1,6 @@ package relay import ( - "bytes" "context" "crypto/ecdsa" "crypto/elliptic" @@ -56,6 +55,7 @@ func withinTimeWindow(t timesource.Timesource, msg *pb.WakuMessage) bool { type validatorFn = func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool func validatorFnBuilder(t timesource.Timesource, topic string, publicKey *ecdsa.PublicKey) (validatorFn, error) { + publicKeyBytes := crypto.FromECDSAPub(publicKey) return func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool { msg := new(pb.WakuMessage) err := proto.Unmarshal(message.Data, msg) @@ -70,12 +70,7 @@ func validatorFnBuilder(t timesource.Timesource, topic string, publicKey *ecdsa. msgHash := MsgHash(topic, msg) signature := msg.Meta - msgPubKey, err := crypto.SigToPub(msgHash, signature) - if err != nil { - return false - } - - return bytes.Equal(crypto.FromECDSAPub(msgPubKey), crypto.FromECDSAPub(publicKey)) + return secp256k1.VerifySignature(publicKeyBytes, msgHash, signature) }, nil } @@ -106,6 +101,6 @@ func SignMessage(privKey *ecdsa.PrivateKey, msg *pb.WakuMessage, pubsubTopic str return err } - msg.Meta = sign + msg.Meta = sign[0:64] // Remove V return nil }