2019-11-21 16:19:22 +00:00
|
|
|
package protocol
|
2019-07-26 07:17:29 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
"encoding/json"
|
2019-07-26 07:17:29 +00:00
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
"github.com/jinzhu/copier"
|
2019-09-26 07:01:17 +00:00
|
|
|
"github.com/pkg/errors"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2019-11-21 16:19:22 +00:00
|
|
|
"github.com/status-im/status-go/protocol/datasync"
|
|
|
|
"github.com/status-im/status-go/protocol/encryption"
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
2019-07-26 07:17:29 +00:00
|
|
|
)
|
|
|
|
|
2019-11-06 16:23:11 +00:00
|
|
|
type StatusMessageT int
|
|
|
|
|
2019-07-26 07:17:29 +00:00
|
|
|
// StatusMessage is any Status Protocol message.
|
|
|
|
type StatusMessage struct {
|
2019-09-26 07:01:17 +00:00
|
|
|
// TransportMessage is the parsed message received from the transport layer, i.e the input
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
TransportMessage *types.Message `json:"transportMessage"`
|
2019-12-02 15:34:05 +00:00
|
|
|
// Type is the type of application message contained
|
|
|
|
Type protobuf.ApplicationMetadataMessage_Type `json:"-"`
|
2019-07-26 07:17:29 +00:00
|
|
|
// ParsedMessage is the parsed message by the application layer, i.e the output
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
ParsedMessage interface{} `json:"-"`
|
2019-07-26 07:17:29 +00:00
|
|
|
|
|
|
|
// TransportPayload is the payload as received from the transport layer
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
TransportPayload []byte `json:"-"`
|
2019-07-26 07:17:29 +00:00
|
|
|
// DecryptedPayload is the payload after having been processed by the encryption layer
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
DecryptedPayload []byte `json:"decryptedPayload"`
|
2019-07-26 07:17:29 +00:00
|
|
|
|
|
|
|
// ID is the canonical ID of the message
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
ID types.HexBytes `json:"id"`
|
2019-07-26 07:17:29 +00:00
|
|
|
// Hash is the transport layer hash
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
Hash []byte `json:"-"`
|
2019-07-26 07:17:29 +00:00
|
|
|
|
|
|
|
// TransportLayerSigPubKey contains the public key provided by the transport layer
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
TransportLayerSigPubKey *ecdsa.PublicKey `json:"-"`
|
2019-07-26 07:17:29 +00:00
|
|
|
// ApplicationMetadataLayerPubKey contains the public key provided by the application metadata layer
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
ApplicationMetadataLayerSigPubKey *ecdsa.PublicKey `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Temporary JSON marshaling for those messages that are not yet processed
|
|
|
|
// by the go code
|
|
|
|
func (m *StatusMessage) MarshalJSON() ([]byte, error) {
|
|
|
|
item := struct {
|
|
|
|
ID types.HexBytes `json:"id"`
|
|
|
|
Payload string `json:"payload"`
|
|
|
|
From types.HexBytes `json:"from"`
|
|
|
|
Timestamp uint32 `json:"timestamp"`
|
|
|
|
}{
|
|
|
|
ID: m.ID,
|
|
|
|
Payload: string(m.DecryptedPayload),
|
|
|
|
Timestamp: m.TransportMessage.Timestamp,
|
|
|
|
From: m.TransportMessage.Sig,
|
|
|
|
}
|
|
|
|
return json.Marshal(item)
|
2019-07-26 07:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SigPubKey returns the most important signature, from the application layer to transport
|
2019-11-23 17:57:05 +00:00
|
|
|
func (m *StatusMessage) SigPubKey() *ecdsa.PublicKey {
|
|
|
|
if m.ApplicationMetadataLayerSigPubKey != nil {
|
|
|
|
return m.ApplicationMetadataLayerSigPubKey
|
2019-07-26 07:17:29 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
return m.TransportLayerSigPubKey
|
2019-07-26 07:17:29 +00:00
|
|
|
}
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
func (m *StatusMessage) Clone() (*StatusMessage, error) {
|
2019-07-26 07:17:29 +00:00
|
|
|
copy := &StatusMessage{}
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
err := copier.Copy(©, m)
|
2019-07-26 07:17:29 +00:00
|
|
|
return copy, err
|
|
|
|
}
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
func (m *StatusMessage) HandleTransport(shhMessage *types.Message) error {
|
2019-07-26 07:17:29 +00:00
|
|
|
publicKey, err := crypto.UnmarshalPubkey(shhMessage.Sig)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to get signature")
|
|
|
|
}
|
|
|
|
|
|
|
|
m.TransportMessage = shhMessage
|
|
|
|
m.Hash = shhMessage.Hash
|
|
|
|
m.TransportLayerSigPubKey = publicKey
|
|
|
|
m.TransportPayload = shhMessage.Payload
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *StatusMessage) HandleEncryption(myKey *ecdsa.PrivateKey, senderKey *ecdsa.PublicKey, enc *encryption.Protocol) error {
|
|
|
|
// As we handle non-encrypted messages, we make sure that DecryptPayload
|
|
|
|
// is set regardless of whether this step is successful
|
|
|
|
m.DecryptedPayload = m.TransportPayload
|
|
|
|
|
|
|
|
var protocolMessage encryption.ProtocolMessage
|
|
|
|
err := proto.Unmarshal(m.TransportPayload, &protocolMessage)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to unmarshal ProtocolMessage")
|
|
|
|
}
|
|
|
|
|
|
|
|
payload, err := enc.HandleMessage(
|
|
|
|
myKey,
|
|
|
|
senderKey,
|
|
|
|
&protocolMessage,
|
|
|
|
m.Hash,
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "failed to handle Encryption message")
|
|
|
|
}
|
|
|
|
|
|
|
|
m.DecryptedPayload = payload
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-09-02 09:29:06 +00:00
|
|
|
// HandleDatasync processes StatusMessage through data sync layer.
|
|
|
|
// This is optional and DataSync might be nil. In such a case,
|
|
|
|
// only one payload will be returned equal to DecryptedPayload.
|
2019-07-26 07:17:29 +00:00
|
|
|
func (m *StatusMessage) HandleDatasync(datasync *datasync.DataSync) ([]*StatusMessage, error) {
|
|
|
|
var statusMessages []*StatusMessage
|
2019-09-02 09:29:06 +00:00
|
|
|
|
2019-07-26 07:17:29 +00:00
|
|
|
payloads := datasync.Handle(
|
|
|
|
m.SigPubKey(),
|
|
|
|
m.DecryptedPayload,
|
|
|
|
)
|
2019-09-02 09:29:06 +00:00
|
|
|
|
2019-07-26 07:17:29 +00:00
|
|
|
for _, payload := range payloads {
|
|
|
|
message, err := m.Clone()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
message.DecryptedPayload = payload
|
|
|
|
statusMessages = append(statusMessages, message)
|
|
|
|
}
|
|
|
|
return statusMessages, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *StatusMessage) HandleApplicationMetadata() error {
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
message, err := protobuf.Unmarshal(m.DecryptedPayload)
|
2019-07-26 07:17:29 +00:00
|
|
|
if err != nil {
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
return err
|
2019-07-26 07:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
recoveredKey, err := message.RecoverKey()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
m.ApplicationMetadataLayerSigPubKey = recoveredKey
|
2019-08-27 12:04:15 +00:00
|
|
|
// Calculate ID using the wrapped record
|
|
|
|
m.ID = MessageID(recoveredKey, m.DecryptedPayload)
|
2019-07-26 07:17:29 +00:00
|
|
|
m.DecryptedPayload = message.Payload
|
2019-12-02 15:34:05 +00:00
|
|
|
m.Type = message.Type
|
2019-07-26 07:17:29 +00:00
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *StatusMessage) HandleApplication() error {
|
2019-12-02 15:34:05 +00:00
|
|
|
switch m.Type {
|
|
|
|
case protobuf.ApplicationMetadataMessage_CHAT_MESSAGE:
|
|
|
|
var message protobuf.ChatMessage
|
Move to protobuf for Message type (#1706)
* Use a single Message type `v1/message.go` and `message.go` are the same now, and they embed `protobuf.ChatMessage`
* Use `SendChatMessage` for sending chat messages, this is basically the old `Send` but a bit more flexible so we can send different message types (stickers,commands), and not just text.
* Remove dedup from services/shhext. Because now we process in status-protocol, dedup makes less sense, as those messages are going to be processed anyway, so removing for now, we can re-evaluate if bringing it to status-go or not.
* Change the various retrieveX method to a single one:
`RetrieveAll` will be processing those messages that it can process (Currently only `Message`), and return the rest in `RawMessages` (still transit). The format for the response is:
`Chats`: -> The chats updated by receiving the message
`Messages`: -> The messages retrieved (already matched to a chat)
`Contacts`: -> The contacts updated by the messages
`RawMessages` -> Anything else that can't be parsed, eventually as we move everything to status-protocol-go this will go away.
2019-12-05 16:25:34 +00:00
|
|
|
|
2019-12-02 15:34:05 +00:00
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode ChatMessage: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
2019-07-26 07:17:29 +00:00
|
|
|
|
2019-12-02 15:34:05 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case protobuf.ApplicationMetadataMessage_MEMBERSHIP_UPDATE_MESSAGE:
|
|
|
|
var message protobuf.MembershipUpdateMessage
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode MembershipUpdateMessage: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-01-10 18:59:01 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_ACCEPT_REQUEST_ADDRESS_FOR_TRANSACTION:
|
|
|
|
var message protobuf.AcceptRequestAddressForTransaction
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode AcceptRequestAddressForTransaction: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case protobuf.ApplicationMetadataMessage_SEND_TRANSACTION:
|
|
|
|
var message protobuf.SendTransaction
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode SendTransaction: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_REQUEST_TRANSACTION:
|
|
|
|
var message protobuf.RequestTransaction
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode RequestTransaction: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2019-12-02 15:34:05 +00:00
|
|
|
|
2020-01-10 18:59:01 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION:
|
|
|
|
var message protobuf.DeclineRequestAddressForTransaction
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode DeclineRequestAddressForTransaction: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_TRANSACTION:
|
|
|
|
var message protobuf.DeclineRequestTransaction
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode DeclineRequestTransaction: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_REQUEST_ADDRESS_FOR_TRANSACTION:
|
|
|
|
var message protobuf.RequestAddressForTransaction
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode RequestAddressForTransaction: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_CONTACT_UPDATE:
|
|
|
|
var message protobuf.ContactUpdate
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode ContactUpdate: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION:
|
|
|
|
var message protobuf.SyncInstallation
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode SyncInstallation: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT:
|
|
|
|
var message protobuf.SyncInstallationContact
|
|
|
|
log.Printf("Sync installation contact")
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode SyncInstallationContact: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_PUBLIC_CHAT:
|
|
|
|
var message protobuf.SyncInstallationPublicChat
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode SyncInstallationPublicChat: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case protobuf.ApplicationMetadataMessage_SYNC_INSTALLATION_ACCOUNT:
|
|
|
|
var message protobuf.SyncInstallationAccount
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode SyncInstallationAccount: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case protobuf.ApplicationMetadataMessage_PAIR_INSTALLATION:
|
|
|
|
var message protobuf.PairInstallation
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode PairInstallation: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-07-03 08:26:35 +00:00
|
|
|
case protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_REGISTRATION:
|
|
|
|
// This message is a bit different as it's encrypted, so we pass it straight through
|
|
|
|
|
|
|
|
m.ParsedMessage = m.DecryptedPayload
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_CONTACT_CODE_ADVERTISEMENT:
|
|
|
|
var message protobuf.ContactCodeAdvertisement
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode ContactCodeAdvertisement: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_REQUEST:
|
|
|
|
var message protobuf.PushNotificationRequest
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode PushNotificationRequest: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
case protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_REGISTRATION_RESPONSE:
|
|
|
|
var message protobuf.PushNotificationRegistrationResponse
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode PushNotificationRegistrationResponse: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_QUERY:
|
|
|
|
var message protobuf.PushNotificationQuery
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode PushNotificationQuery: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_QUERY_RESPONSE:
|
|
|
|
var message protobuf.PushNotificationQueryResponse
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode PushNotificationQueryResponse: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
case protobuf.ApplicationMetadataMessage_PUSH_NOTIFICATION_RESPONSE:
|
|
|
|
var message protobuf.PushNotificationResponse
|
|
|
|
err := proto.Unmarshal(m.DecryptedPayload, &message)
|
|
|
|
if err != nil {
|
|
|
|
m.ParsedMessage = nil
|
|
|
|
log.Printf("[message::DecodeMessage] could not decode PushNotificationResponse: %#x, err: %v", m.Hash, err.Error())
|
|
|
|
} else {
|
|
|
|
m.ParsedMessage = message
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-10 18:59:01 +00:00
|
|
|
}
|
2019-07-26 07:17:29 +00:00
|
|
|
return nil
|
|
|
|
}
|