mirror of
https://github.com/status-im/go-waku.git
synced 2025-02-05 10:23:32 +00:00
revert: "refactor: use an address instead of public key for the node setup"
This reverts commit 38a9fc4b19ba9eae64f8f8da0388e2a9b06cf72f.
This commit is contained in:
parent
a5abfa8710
commit
189b2ed120
@ -1,20 +1,24 @@
|
|||||||
package cliutils
|
package cliutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/ecdsa"
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProtectedTopic struct {
|
type ProtectedTopic struct {
|
||||||
Topic string
|
Topic string
|
||||||
Address common.Address
|
PublicKey *ecdsa.PublicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p ProtectedTopic) String() string {
|
func (p ProtectedTopic) String() string {
|
||||||
return fmt.Sprintf("%s:%s", p.Topic, p.Address.String())
|
pubKBytes := crypto.FromECDSAPub(p.PublicKey)
|
||||||
|
return fmt.Sprintf("%s:%s", p.Topic, hex.EncodeToString(pubKBytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProtectedTopicSlice struct {
|
type ProtectedTopicSlice struct {
|
||||||
@ -27,13 +31,13 @@ func (k *ProtectedTopicSlice) Set(value string) error {
|
|||||||
return errors.New("expected topic_name:hex_encoded_public_key")
|
return errors.New("expected topic_name:hex_encoded_public_key")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !common.IsHexAddress(protectedTopicParts[1]) {
|
pubk, err := crypto.UnmarshalPubkey(common.FromHex(protectedTopicParts[1]))
|
||||||
return errors.New("invalid address format")
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
*k.Values = append(*k.Values, ProtectedTopic{
|
*k.Values = append(*k.Values, ProtectedTopic{
|
||||||
Topic: protectedTopicParts[0],
|
Topic: protectedTopicParts[0],
|
||||||
Address: common.HexToAddress(protectedTopicParts[1]),
|
PublicKey: pubk,
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -316,7 +316,7 @@ func Execute(options Options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, protectedTopic := range options.Relay.ProtectedTopics {
|
for _, protectedTopic := range options.Relay.ProtectedTopics {
|
||||||
err := wakuNode.Relay().AddSignedTopicValidator(protectedTopic.Topic, protectedTopic.Address)
|
err := wakuNode.Relay().AddSignedTopicValidator(protectedTopic.Topic, protectedTopic.PublicKey)
|
||||||
failOnErr(err, "Error adding signed topic validator")
|
failOnErr(err, "Error adding signed topic validator")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"crypto/elliptic"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"encoding/hex"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
||||||
|
|
||||||
@ -55,7 +56,8 @@ func withinTimeWindow(t timesource.Timesource, msg *pb.WakuMessage) bool {
|
|||||||
|
|
||||||
type validatorFn = func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool
|
type validatorFn = func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool
|
||||||
|
|
||||||
func validatorFnBuilder(t timesource.Timesource, address common.Address) (validatorFn, error) {
|
func validatorFnBuilder(t timesource.Timesource, publicKey *ecdsa.PublicKey) (validatorFn, error) {
|
||||||
|
address := crypto.PubkeyToAddress(*publicKey)
|
||||||
topic := protocol.NewNamedShardingPubsubTopic(address.String() + "/proto").String()
|
topic := protocol.NewNamedShardingPubsubTopic(address.String() + "/proto").String()
|
||||||
return func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool {
|
return func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool {
|
||||||
msg := new(pb.WakuMessage)
|
msg := new(pb.WakuMessage)
|
||||||
@ -82,10 +84,10 @@ func validatorFnBuilder(t timesource.Timesource, address common.Address) (valida
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WakuRelay) AddSignedTopicValidator(topic string, address common.Address) error {
|
func (w *WakuRelay) AddSignedTopicValidator(topic string, publicKey *ecdsa.PublicKey) error {
|
||||||
w.log.Info("adding validator to signed topic", zap.String("topic", topic), zap.String("address", address.String()))
|
w.log.Info("adding validator to signed topic", zap.String("topic", topic), zap.String("publicKey", hex.EncodeToString(elliptic.Marshal(publicKey.Curve, publicKey.X, publicKey.Y))))
|
||||||
|
|
||||||
fn, err := validatorFnBuilder(w.timesource, address)
|
fn, err := validatorFnBuilder(w.timesource, publicKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -60,13 +60,11 @@ func TestMsgHash(t *testing.T) {
|
|||||||
|
|
||||||
msgData, _ := proto.Marshal(msg)
|
msgData, _ := proto.Marshal(msg)
|
||||||
|
|
||||||
address := crypto.PubkeyToAddress(prvKey.PublicKey)
|
|
||||||
|
|
||||||
//expectedMessageHash, _ := hex.DecodeString("662F8C20A335F170BD60ABC1F02AD66F0C6A6EE285DA2A53C95259E7937C0AE9")
|
//expectedMessageHash, _ := hex.DecodeString("662F8C20A335F170BD60ABC1F02AD66F0C6A6EE285DA2A53C95259E7937C0AE9")
|
||||||
//messageHash := MsgHash(pubsubTopic, msg)
|
//messageHash := MsgHash(pubsubTopic, msg)
|
||||||
//require.True(t, bytes.Equal(expectedMessageHash, messageHash))
|
//require.True(t, bytes.Equal(expectedMessageHash, messageHash))
|
||||||
|
|
||||||
myValidator, err := validatorFnBuilder(NewFakeTimesource(timestamp), address)
|
myValidator, err := validatorFnBuilder(NewFakeTimesource(timestamp), &prvKey.PublicKey)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
result := myValidator(context.Background(), "", &pubsub.Message{
|
result := myValidator(context.Background(), "", &pubsub.Message{
|
||||||
Message: &pubsub_pb.Message{
|
Message: &pubsub_pb.Message{
|
||||||
@ -77,7 +75,7 @@ func TestMsgHash(t *testing.T) {
|
|||||||
|
|
||||||
// Exceed 5m window in both directions
|
// Exceed 5m window in both directions
|
||||||
now5m1sInPast := timestamp.Add(-5 * time.Minute).Add(-1 * time.Second)
|
now5m1sInPast := timestamp.Add(-5 * time.Minute).Add(-1 * time.Second)
|
||||||
myValidator, err = validatorFnBuilder(NewFakeTimesource(now5m1sInPast), address)
|
myValidator, err = validatorFnBuilder(NewFakeTimesource(now5m1sInPast), &prvKey.PublicKey)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
result = myValidator(context.Background(), "", &pubsub.Message{
|
result = myValidator(context.Background(), "", &pubsub.Message{
|
||||||
Message: &pubsub_pb.Message{
|
Message: &pubsub_pb.Message{
|
||||||
@ -87,7 +85,7 @@ func TestMsgHash(t *testing.T) {
|
|||||||
require.False(t, result)
|
require.False(t, result)
|
||||||
|
|
||||||
now5m1sInFuture := timestamp.Add(5 * time.Minute).Add(1 * time.Second)
|
now5m1sInFuture := timestamp.Add(5 * time.Minute).Add(1 * time.Second)
|
||||||
myValidator, err = validatorFnBuilder(NewFakeTimesource(now5m1sInFuture), address)
|
myValidator, err = validatorFnBuilder(NewFakeTimesource(now5m1sInFuture), &prvKey.PublicKey)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
result = myValidator(context.Background(), "", &pubsub.Message{
|
result = myValidator(context.Background(), "", &pubsub.Message{
|
||||||
Message: &pubsub_pb.Message{
|
Message: &pubsub_pb.Message{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user