diff --git a/waku/bridge/public_waku_api.go b/waku/bridge/public_waku_api.go index 42d88c39d..65f05658a 100644 --- a/waku/bridge/public_waku_api.go +++ b/waku/bridge/public_waku_api.go @@ -94,18 +94,5 @@ func (w *GethPublicWakuAPIWrapper) GetFilterMessages(id string) ([]*wakutypes.Me // Post posts a message on the network. // returns the hash of the message in case of success. func (w *GethPublicWakuAPIWrapper) Post(ctx context.Context, req wakutypes.NewMessage) ([]byte, error) { - msg := wakuv1.NewMessage{ - SymKeyID: req.SymKeyID, - PublicKey: req.PublicKey, - Sig: req.SigID, // Sig is really a SigID - TTL: req.TTL, - Topic: wakuv1common.TopicType(req.Topic), - Payload: req.Payload, - Padding: req.Padding, - PowTime: req.PowTime, - PowTarget: req.PowTarget, - TargetPeer: req.TargetPeer, - Ephemeral: req.Ephemeral, - } - return w.api.Post(ctx, msg) + return w.api.Post(ctx, req) } diff --git a/waku/bridge/public_wakuv2_api.go b/waku/bridge/public_wakuv2_api.go index b531fef70..81d07629e 100644 --- a/waku/bridge/public_wakuv2_api.go +++ b/waku/bridge/public_wakuv2_api.go @@ -91,17 +91,5 @@ func (w *gethPublicWakuV2APIWrapper) GetFilterMessages(id string) ([]*wakutypes. // Post posts a message on the network. // returns the hash of the message in case of success. func (w *gethPublicWakuV2APIWrapper) Post(ctx context.Context, req wakutypes.NewMessage) ([]byte, error) { - msg := wakuv2.NewMessage{ - SymKeyID: req.SymKeyID, - PublicKey: req.PublicKey, - Sig: req.SigID, // Sig is really a SigID - PubsubTopic: req.PubsubTopic, - ContentTopic: wakucommon.TopicType(req.Topic), - Payload: req.Payload, - Padding: req.Padding, - TargetPeer: req.TargetPeer, - Ephemeral: req.Ephemeral, - Priority: req.Priority, - } - return w.api.Post(ctx, msg) + return w.api.Post(ctx, req) } diff --git a/wakuv1/api.go b/wakuv1/api.go index f1ee08525..1dd64f799 100644 --- a/wakuv1/api.go +++ b/wakuv1/api.go @@ -29,6 +29,7 @@ import ( "go.uber.org/zap" "github.com/status-im/status-go/logutils" + "github.com/status-im/status-go/waku/types" "github.com/status-im/status-go/wakuv1/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -209,24 +210,9 @@ func (api *PublicWakuAPI) CancelLightClient(ctx context.Context) bool { return !api.w.LightClientMode() } -// NewMessage represents a new waku message that is posted through the RPC. -type NewMessage struct { - SymKeyID string `json:"symKeyID"` - PublicKey []byte `json:"pubKey"` - Sig string `json:"sig"` - TTL uint32 `json:"ttl"` - Topic common.TopicType `json:"topic"` - Payload []byte `json:"payload"` - Padding []byte `json:"padding"` - PowTime uint32 `json:"powTime"` - PowTarget float64 `json:"powTarget"` - TargetPeer string `json:"targetPeer"` - Ephemeral bool `json:"ephemeral"` -} - // Post posts a message on the Waku network. // returns the hash of the message in case of success. -func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Bytes, error) { +func (api *PublicWakuAPI) Post(ctx context.Context, req types.NewMessage) (hexutil.Bytes, error) { var ( symKeyGiven = len(req.SymKeyID) > 0 pubKeyGiven = len(req.PublicKey) > 0 @@ -244,12 +230,12 @@ func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Byt Padding: req.Padding, WorkTime: req.PowTime, PoW: req.PowTarget, - Topic: req.Topic, + Topic: common.TopicType(req.Topic), } // Set key that is used to sign the message - if len(req.Sig) > 0 { - if params.Src, err = api.w.GetPrivateKey(req.Sig); err != nil { + if len(req.SigID) > 0 { + if params.Src, err = api.w.GetPrivateKey(req.SigID); err != nil { return nil, err } } diff --git a/wakuv2/api.go b/wakuv2/api.go index 09ea54ae0..6a35a76a6 100644 --- a/wakuv2/api.go +++ b/wakuv2/api.go @@ -32,6 +32,7 @@ import ( "github.com/waku-org/go-waku/waku/v2/protocol/pb" "github.com/status-im/status-go/logutils" + "github.com/status-im/status-go/waku/types" "github.com/status-im/status-go/wakuv2/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -173,23 +174,9 @@ func (api *PublicWakuAPI) BloomFilter() []byte { return nil } -// NewMessage represents a new waku message that is posted through the RPC. -type NewMessage struct { - SymKeyID string `json:"symKeyID"` - PublicKey []byte `json:"pubKey"` - Sig string `json:"sig"` - PubsubTopic string `json:"pubsubTopic"` - ContentTopic common.TopicType `json:"topic"` - Payload []byte `json:"payload"` - Padding []byte `json:"padding"` - TargetPeer string `json:"targetPeer"` - Ephemeral bool `json:"ephemeral"` - Priority *int `json:"priority"` -} - // Post posts a message on the Waku network. // returns the hash of the message in case of success. -func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Bytes, error) { +func (api *PublicWakuAPI) Post(ctx context.Context, req types.NewMessage) (hexutil.Bytes, error) { var ( symKeyGiven = len(req.SymKeyID) > 0 pubKeyGiven = len(req.PublicKey) > 0 @@ -204,19 +191,21 @@ func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Byt var keyInfo *payload.KeyInfo = new(payload.KeyInfo) // Set key that is used to sign the message - if len(req.Sig) > 0 { - privKey, err := api.w.GetPrivateKey(req.Sig) + if len(req.SigID) > 0 { + privKey, err := api.w.GetPrivateKey(req.SigID) if err != nil { return nil, err } keyInfo.PrivKey = privKey } + contentTopic := common.TopicType(req.Topic) + // Set symmetric key that is used to encrypt the message if symKeyGiven { keyInfo.Kind = payload.Symmetric - if req.ContentTopic == (common.TopicType{}) { // topics are mandatory with symmetric encryption + if contentTopic == (common.TopicType{}) { // topics are mandatory with symmetric encryption return nil, ErrNoTopics } if keyInfo.SymKey, err = api.w.GetSymKey(req.SymKeyID); err != nil { @@ -252,7 +241,7 @@ func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Byt wakuMsg := &pb.WakuMessage{ Payload: payload, Version: &version, - ContentTopic: req.ContentTopic.ContentTopic(), + ContentTopic: contentTopic.ContentTopic(), Timestamp: proto.Int64(api.w.timestamp()), Meta: []byte{}, // TODO: empty for now. Once we use Waku Archive v2, we should deprecate the timestamp and use an ULID here Ephemeral: &req.Ephemeral,