diff --git a/protocol/message.go b/protocol/message.go index c0241234e57..dacec67123c 100644 --- a/protocol/message.go +++ b/protocol/message.go @@ -92,7 +92,7 @@ type Message struct { // Replace indicates that this is a replacement of a message // that has been updated - Replace string `json:"replace"` + Replace string `json:"replace,omitEmpty"` SigPubKey *ecdsa.PublicKey `json:"-"` } @@ -128,7 +128,7 @@ func (m *Message) MarshalJSON() ([]byte, error) { ChatId string `json:"chatId"` LocalChatID string `json:"localChatId"` Clock uint64 `json:"clock"` - Replace string `json:"replace"` + Replace string `json:"replace,omitEmpty"` ResponseTo string `json:"responseTo"` EnsName string `json:"ensName"` Sticker *protobuf.StickerMessage `json:"sticker"` diff --git a/protocol/message_handler.go b/protocol/message_handler.go index d9d8db9a614..d04873c3c1a 100644 --- a/protocol/message_handler.go +++ b/protocol/message_handler.go @@ -479,6 +479,40 @@ func (m *MessageHandler) HandleDeclineRequestAddressForTransaction(messageState return m.handleCommandMessage(messageState, oldMessage) } +func (m *MessageHandler) HandleDeclineRequestTransaction(messageState *ReceivedMessageState, command protobuf.DeclineRequestTransaction) error { + err := ValidateReceivedDeclineRequestTransaction(&command) + if err != nil { + return err + } + oldMessage, err := m.persistence.MessageByID(command.Id) + if err != nil { + return err + } + if oldMessage == nil { + return errors.New("message not found") + } + + if oldMessage.LocalChatID != messageState.CurrentMessageState.Contact.ID { + return errors.New("From must match") + } + + if oldMessage.OutgoingStatus == "" { + return errors.New("Initial message must originate from us") + } + + if oldMessage.CommandParameters.CommandState != CommandStateRequestTransaction { + return errors.New("Wrong state for command") + } + + oldMessage.Clock = command.Clock + oldMessage.Timestamp = messageState.CurrentMessageState.WhisperTimestamp + oldMessage.Text = "Transaction request declined" + oldMessage.Replace = command.Id + oldMessage.CommandParameters.CommandState = CommandStateRequestTransactionDeclined + + return m.handleCommandMessage(messageState, oldMessage) +} + func (m *MessageHandler) matchMessage(message *Message, chats map[string]*Chat) (*Chat, error) { if message.SigPubKey == nil { m.logger.Error("public key can't be empty") diff --git a/protocol/message_validator.go b/protocol/message_validator.go index 93ed54e8191..712be1e0ced 100644 --- a/protocol/message_validator.go +++ b/protocol/message_validator.go @@ -109,6 +109,18 @@ func ValidateReceivedDeclineRequestAddressForTransaction(message *protobuf.Decli return nil } +func ValidateReceivedDeclineRequestTransaction(message *protobuf.DeclineRequestTransaction) error { + if message.Clock == 0 { + return errors.New("Clock can't be 0") + } + + if len(message.Id) == 0 { + return errors.New("MessageID can't be empty") + } + + return nil +} + func ValidateReceivedChatMessage(message *protobuf.ChatMessage) error { if message.Clock == 0 { return errors.New("Clock can't be 0") diff --git a/protocol/message_validator_test.go b/protocol/message_validator_test.go index 6a27f851191..f48e2eee19e 100644 --- a/protocol/message_validator_test.go +++ b/protocol/message_validator_test.go @@ -261,25 +261,6 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() { ContentType: protobuf.ChatMessage_STICKER, }, }, - { - Name: "Invalid sticker message without Pack", - Valid: false, - Message: protobuf.ChatMessage{ - ChatId: "a", - Text: "valid", - Clock: 2, - Timestamp: 3, - ResponseTo: "", - EnsName: "", - Payload: &protobuf.ChatMessage_Sticker{ - Sticker: &protobuf.StickerMessage{ - Hash: "some-hash", - }, - }, - MessageType: protobuf.ChatMessage_ONE_TO_ONE, - ContentType: protobuf.ChatMessage_STICKER, - }, - }, { Name: "Invalid sticker message without Hash", Valid: false, diff --git a/protocol/messenger.go b/protocol/messenger.go index 7f1657cf339..e5a4d5ad1fe 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -1123,11 +1123,9 @@ func (m *Messenger) hasPairedDevices() bool { // sendToPairedDevices will check if we have any paired devices and send to them if necessary func (m *Messenger) sendToPairedDevices(ctx context.Context, payload []byte, messageType protobuf.ApplicationMetadataMessage_Type) error { - m.logger.Info("PAIRED") hasPairedDevices := m.hasPairedDevices() // We send a message to any paired device if hasPairedDevices { - m.logger.Info("hAH PAIRED") _, err := m.processor.SendPrivateRaw(ctx, &m.identity.PublicKey, payload, messageType) if err != nil { return err @@ -1703,6 +1701,15 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte continue } + case protobuf.DeclineRequestTransaction: + command := msg.ParsedMessage.(protobuf.DeclineRequestTransaction) + logger.Debug("Handling DeclineRequestTransaction") + err = m.handler.HandleDeclineRequestTransaction(messageState, command) + if err != nil { + logger.Warn("failed to handle DeclineRequestTransaction", zap.Error(err)) + continue + } + case protobuf.RequestTransaction: command := msg.ParsedMessage.(protobuf.RequestTransaction) logger.Debug("Handling RequestTransaction") @@ -2169,6 +2176,87 @@ func (m *Messenger) AcceptRequestAddressForTransaction(ctx context.Context, mess return &response, m.saveChat(chat) } +func (m *Messenger) DeclineRequestTransaction(ctx context.Context, messageID string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + message, err := m.MessageByID(messageID) + if err != nil { + return nil, err + } + + if message == nil { + return nil, errors.New("message not found") + } + + chatID := message.LocalChatID + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.Timestamp = timestamp + message.Text = "Transaction request declined" + message.OutgoingStatus = OutgoingStatusSending + message.Replace = messageID + + err = m.persistence.HideMessage(messageID) + if err != nil { + return nil, err + } + + request := &protobuf.DeclineRequestTransaction{ + Clock: message.Clock, + Id: messageID, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + + newMessageID, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_TRANSACTION, + ResendAutomatically: true, + }) + + if err != nil { + return nil, err + } + + message.ID = types.EncodeHex(newMessageID) + message.CommandParameters.CommandState = CommandStateRequestTransactionDeclined + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + func (m *Messenger) DeclineRequestAddressForTransaction(ctx context.Context, messageID string) (*MessengerResponse, error) { m.mutex.Lock() defer m.mutex.Unlock() diff --git a/protocol/messenger_test.go b/protocol/messenger_test.go index a22406fb244..9cfe63d985c 100644 --- a/protocol/messenger_test.go +++ b/protocol/messenger_test.go @@ -63,6 +63,14 @@ func (n *testNode) NewENSVerifier(_ *zap.Logger) enstypes.ENSVerifier { panic("not implemented") } +func (n *testNode) AddPeer(_ string) error { + panic("not implemented") +} + +func (n *testNode) RemovePeer(_ string) error { + panic("not implemented") +} + func (n *testNode) GetWhisper(_ interface{}) (types.Whisper, error) { return n.shh, nil } @@ -702,89 +710,6 @@ func (s *MessengerSuite) TestRetrieveTheirPrivateChatNonExisting() { s.Require().True(actualChat.Active) } -// Test retrieve paired message -func (s *MessengerSuite) TestRetrieveOurPairedMessage() { - pairedMessenger := s.newMessengerWithKey(s.shh, s.privateKey) - chat := CreateOneToOneChat("XXX", &s.privateKey.PublicKey) - err := pairedMessenger.SaveChat(&chat) - s.NoError(err) - - inputMessage := buildTestMessage(chat) - - // Send a message so we now of the installation - sendResponse, err := pairedMessenger.SendChatMessage(context.Background(), inputMessage) - s.NoError(err) - s.Require().Len(sendResponse.Messages, 1) - - sentMessage := sendResponse.Messages[0] - - // Wait for the message to reach its destination - - var response *MessengerResponse - err = tt.RetryWithBackOff(func() error { - var err error - response, err = s.m.RetrieveAll() - if err == nil && len(response.Messages) == 0 { - err = errors.New("no messages") - } - return err - }) - s.Require().NoError(err) - // Check message is received - s.Require().Len(response.Messages, 1) - - actualChat := response.Chats[0] - // It does not update the unviewed message count - s.Require().Equal(uint(0), actualChat.UnviewedMessagesCount) - // It updates the last message clock value - s.Require().Equal(sentMessage.Clock, actualChat.LastClockValue) - // It sets the last message - s.Require().NotNil(actualChat.LastMessage) - - // Get installations - installations := s.m.Installations() - s.Require().Len(installations, 2) - - // Enable installations - err = s.m.EnableInstallation(installations[0].ID) - s.Require().NoError(err) - err = s.m.EnableInstallation(installations[1].ID) - s.Require().NoError(err) - - // We create new one to one chat - key, err := crypto.GenerateKey() - s.Require().NoError(err) - chat = CreateOneToOneChat("new-chat", &key.PublicKey) - err = s.m.SaveChat(&chat) - s.NoError(err) - - inputMessage = buildTestMessage(chat) - _, err = s.m.SendChatMessage(context.Background(), inputMessage) - s.NoError(err) - - // Wait for the message to reach its destination - err = tt.RetryWithBackOff(func() error { - var err error - response, err = pairedMessenger.RetrieveAll() - if err == nil && len(response.Messages) == 0 { - err = errors.New("no messages") - } - return err - }) - s.Require().NoError(err) - - // Check message is received - s.Require().Len(response.Messages, 1) - - message := response.Messages[0] - - // The chatID is the same chatID as the received one - s.Require().Equal(message.LocalChatID, chat.ID) - - // Sets the outgoing status - s.Equal(message.OutgoingStatus, OutgoingStatusSent) -} - // Test receiving a message on an non-existing public chat func (s *MessengerSuite) TestRetrieveTheirPublicChatNonExisting() { theirMessenger := s.newMessenger(s.shh) @@ -1543,7 +1468,9 @@ func (s *MessengerSuite) TestDeclineRequestAddressForTransaction() { err := s.m.SaveChat(&chat) s.Require().NoError(err) - response, err := s.m.RequestAddressForTransaction(context.Background(), theirPkString, value, contract) + myAddress := crypto.PubkeyToAddress(s.m.identity.PublicKey) + + response, err := s.m.RequestAddressForTransaction(context.Background(), theirPkString, myAddress.Hex(), value, contract) s.Require().NoError(err) s.Require().NotNil(response) s.Require().Len(response.Chats, 1) @@ -1823,11 +1750,13 @@ func (s *MessengerSuite) TestAcceptRequestAddressForTransaction() { theirMessenger := s.newMessenger(s.shh) theirPkString := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey)) + myAddress := crypto.PubkeyToAddress(s.m.identity.PublicKey) + chat := CreateOneToOneChat(theirPkString, &theirMessenger.identity.PublicKey) err := s.m.SaveChat(&chat) s.Require().NoError(err) - response, err := s.m.RequestAddressForTransaction(context.Background(), theirPkString, value, contract) + response, err := s.m.RequestAddressForTransaction(context.Background(), theirPkString, myAddress.Hex(), value, contract) s.Require().NoError(err) s.Require().NotNil(response) s.Require().Len(response.Chats, 1) @@ -1910,6 +1839,99 @@ func (s *MessengerSuite) TestAcceptRequestAddressForTransaction() { s.Require().Equal(initialCommandID, receiverMessage.Replace) } +func (s *MessengerSuite) TestDeclineRequestTransaction() { + value := "2000" + contract := "0x314159265dd8dbb310642f98f50c066173c1259b" + receiverAddress := crypto.PubkeyToAddress(s.m.identity.PublicKey) + receiverAddressString := strings.ToLower(receiverAddress.Hex()) + theirMessenger := s.newMessenger(s.shh) + theirPkString := types.EncodeHex(crypto.FromECDSAPub(&theirMessenger.identity.PublicKey)) + + chat := CreateOneToOneChat(theirPkString, &theirMessenger.identity.PublicKey) + err := s.m.SaveChat(&chat) + s.Require().NoError(err) + + response, err := s.m.RequestTransaction(context.Background(), theirPkString, value, contract, receiverAddressString) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + senderMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, senderMessage.ContentType) + initialCommandID := senderMessage.ID + + s.Require().Equal("Request transaction", senderMessage.Text) + s.Require().NotNil(senderMessage.CommandParameters) + s.Require().Equal(value, senderMessage.CommandParameters.Value) + s.Require().Equal(contract, senderMessage.CommandParameters.Contract) + s.Require().Equal(receiverAddressString, senderMessage.CommandParameters.Address) + s.Require().Equal(initialCommandID, senderMessage.CommandParameters.ID) + s.Require().Equal(CommandStateRequestTransaction, senderMessage.CommandParameters.CommandState) + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = theirMessenger.RetrieveAll() + if err == nil && len(response.Messages) == 0 { + err = errors.New("no messages") + } + return err + }) + s.Require().NoError(err) + + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + receiverMessage := response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, receiverMessage.ContentType) + s.Require().Equal("Request transaction", receiverMessage.Text) + s.Require().NotNil(receiverMessage.CommandParameters) + s.Require().Equal(value, receiverMessage.CommandParameters.Value) + s.Require().Equal(contract, receiverMessage.CommandParameters.Contract) + s.Require().Equal(receiverAddressString, receiverMessage.CommandParameters.Address) + s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID) + s.Require().Equal(CommandStateRequestTransaction, receiverMessage.CommandParameters.CommandState) + + response, err = theirMessenger.DeclineRequestTransaction(context.Background(), initialCommandID) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + senderMessage = response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, senderMessage.ContentType) + + s.Require().Equal("Transaction request declined", senderMessage.Text) + s.Require().Equal(initialCommandID, senderMessage.CommandParameters.ID) + s.Require().Equal(receiverMessage.ID, senderMessage.Replace) + s.Require().Equal(CommandStateRequestTransactionDeclined, senderMessage.CommandParameters.CommandState) + + // Wait for the message to reach its destination + err = tt.RetryWithBackOff(func() error { + var err error + response, err = s.m.RetrieveAll() + if err == nil && len(response.Messages) == 0 { + err = errors.New("no messages") + } + return err + }) + s.Require().NoError(err) + + s.Require().NotNil(response) + s.Require().Len(response.Chats, 1) + s.Require().Len(response.Messages, 1) + + receiverMessage = response.Messages[0] + s.Require().Equal(protobuf.ChatMessage_TRANSACTION_COMMAND, receiverMessage.ContentType) + + s.Require().Equal("Transaction request declined", receiverMessage.Text) + s.Require().Equal(initialCommandID, receiverMessage.CommandParameters.ID) + s.Require().Equal(initialCommandID, receiverMessage.Replace) + s.Require().Equal(CommandStateRequestTransactionDeclined, receiverMessage.CommandParameters.CommandState) +} + func (s *MessengerSuite) TestRequestTransaction() { value := "2000" contract := "0x314159265dd8dbb310642f98f50c066173c1259b" @@ -2097,7 +2119,7 @@ func (s *MessengerSuite) TestMessageJSON() { From: "from-field", } - expectedJSON := `{"id":"test-1","whisperTimestamp":0,"from":"from-field","alias":"alias","identicon":"","seen":false,"quotedMessage":null,"rtl":false,"parsedText":null,"lineCount":0,"text":"test-1","chatId":"remote-chat-id","localChatId":"local-chat-id","clock":1,"responseTo":"","ensName":"","sticker":null,"commandParameters":null,"timestamp":0,"contentType":0,"messageType":0}` + expectedJSON := `{"id":"test-1","whisperTimestamp":0,"from":"from-field","alias":"alias","identicon":"","seen":false,"quotedMessage":null,"rtl":false,"parsedText":null,"lineCount":0,"text":"test-1","chatId":"remote-chat-id","localChatId":"local-chat-id","clock":1,"replace":"","responseTo":"","ensName":"","sticker":null,"commandParameters":null,"timestamp":0,"contentType":0,"messageType":0}` messageJSON, err := json.Marshal(message) s.Require().NoError(err) diff --git a/protocol/migrations/migrations.go b/protocol/migrations/migrations.go index e49f15fd13c..597b517f4bc 100644 --- a/protocol/migrations/migrations.go +++ b/protocol/migrations/migrations.go @@ -86,7 +86,7 @@ func _000001_initDownDbSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "000001_init.down.db.sql", size: 65, mode: os.FileMode(0644), modTime: time.Unix(1576661250, 0)} + info := bindataFileInfo{name: "000001_init.down.db.sql", size: 65, mode: os.FileMode(0644), modTime: time.Unix(1577718673, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x5e, 0xbb, 0x3f, 0x1, 0x75, 0x19, 0x70, 0x86, 0xa7, 0x34, 0x40, 0x17, 0x34, 0x3e, 0x18, 0x51, 0x79, 0xd4, 0x22, 0xad, 0x8f, 0x80, 0xcc, 0xa6, 0xcc, 0x6, 0x2b, 0x62, 0x2, 0x47, 0xba, 0xf9}} return a, nil } @@ -106,7 +106,7 @@ func _000001_initUpDbSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "000001_init.up.db.sql", size: 2693, mode: os.FileMode(0644), modTime: time.Unix(1577712858, 0)} + info := bindataFileInfo{name: "000001_init.up.db.sql", size: 2693, mode: os.FileMode(0644), modTime: time.Unix(1577718868, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x34, 0x9f, 0x6, 0x64, 0xcf, 0x97, 0xbe, 0xa8, 0xa2, 0x2f, 0xda, 0xc5, 0x9d, 0x26, 0x3, 0x65, 0x98, 0x8a, 0x7a, 0x6a, 0xc3, 0xd, 0x3f, 0x25, 0xfe, 0x4c, 0x5, 0xdb, 0x98, 0xa9, 0xf9, 0xf}} return a, nil } diff --git a/protocol/protobuf/application_metadata_message.pb.go b/protocol/protobuf/application_metadata_message.pb.go index 60fa3020de0..b166e283ff5 100644 --- a/protocol/protobuf/application_metadata_message.pb.go +++ b/protocol/protobuf/application_metadata_message.pb.go @@ -34,9 +34,10 @@ const ( ApplicationMetadataMessage_DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION ApplicationMetadataMessage_Type = 8 ApplicationMetadataMessage_REQUEST_TRANSACTION ApplicationMetadataMessage_Type = 9 ApplicationMetadataMessage_SEND_TRANSACTION ApplicationMetadataMessage_Type = 10 - ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT ApplicationMetadataMessage_Type = 11 - ApplicationMetadataMessage_SYNC_INSTALLATION_ACCOUNT ApplicationMetadataMessage_Type = 12 - ApplicationMetadataMessage_SYNC_INSTALLATION_PUBLIC_CHAT ApplicationMetadataMessage_Type = 13 + ApplicationMetadataMessage_DECLINE_REQUEST_TRANSACTION ApplicationMetadataMessage_Type = 11 + ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT ApplicationMetadataMessage_Type = 12 + ApplicationMetadataMessage_SYNC_INSTALLATION_ACCOUNT ApplicationMetadataMessage_Type = 13 + ApplicationMetadataMessage_SYNC_INSTALLATION_PUBLIC_CHAT ApplicationMetadataMessage_Type = 14 ) var ApplicationMetadataMessage_Type_name = map[int32]string{ @@ -51,9 +52,10 @@ var ApplicationMetadataMessage_Type_name = map[int32]string{ 8: "DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION", 9: "REQUEST_TRANSACTION", 10: "SEND_TRANSACTION", - 11: "SYNC_INSTALLATION_CONTACT", - 12: "SYNC_INSTALLATION_ACCOUNT", - 13: "SYNC_INSTALLATION_PUBLIC_CHAT", + 11: "DECLINE_REQUEST_TRANSACTION", + 12: "SYNC_INSTALLATION_CONTACT", + 13: "SYNC_INSTALLATION_ACCOUNT", + 14: "SYNC_INSTALLATION_PUBLIC_CHAT", } var ApplicationMetadataMessage_Type_value = map[string]int32{ @@ -68,9 +70,10 @@ var ApplicationMetadataMessage_Type_value = map[string]int32{ "DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION": 8, "REQUEST_TRANSACTION": 9, "SEND_TRANSACTION": 10, - "SYNC_INSTALLATION_CONTACT": 11, - "SYNC_INSTALLATION_ACCOUNT": 12, - "SYNC_INSTALLATION_PUBLIC_CHAT": 13, + "DECLINE_REQUEST_TRANSACTION": 11, + "SYNC_INSTALLATION_CONTACT": 12, + "SYNC_INSTALLATION_ACCOUNT": 13, + "SYNC_INSTALLATION_PUBLIC_CHAT": 14, } func (x ApplicationMetadataMessage_Type) String() string { @@ -147,28 +150,29 @@ func init() { func init() { proto.RegisterFile("application_metadata_message.proto", fileDescriptor_ad09a6406fcf24c7) } var fileDescriptor_ad09a6406fcf24c7 = []byte{ - // 367 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0x51, 0x8f, 0xd2, 0x40, - 0x10, 0xc7, 0xed, 0x51, 0x8f, 0xbb, 0x39, 0xbc, 0xac, 0xa3, 0xc6, 0x6a, 0xbc, 0x88, 0x98, 0x28, - 0x6a, 0xd2, 0x07, 0x7d, 0xf6, 0x61, 0xd9, 0xae, 0xd2, 0xd8, 0x6e, 0xeb, 0xee, 0x36, 0xc6, 0xa7, - 0xcd, 0x22, 0x95, 0x90, 0x00, 0x6d, 0xa0, 0x3c, 0xf0, 0x3d, 0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, 0x84, - 0x42, 0x69, 0x1a, 0x45, 0x54, 0x87, 0x89, 0x20, 0x6e, 0x8d, 0xd5, 0x57, 0xc1, 0x0e, 0xf1, 0x6d, - 0x7c, 0x0e, 0x4f, 0x25, 0xff, 0x9c, 0x71, 0xa5, 0x0d, 0x0d, 0x02, 0xc9, 0x95, 0x32, 0x1f, 0x12, - 0x69, 0xb4, 0xa4, 0x42, 0x51, 0xd6, 0x48, 0xe7, 0xf8, 0x1a, 0x5e, 0x50, 0xc6, 0x78, 0xaa, 0xcd, - 0x29, 0xb7, 0x8d, 0x6f, 0xe0, 0x65, 0xc0, 0x59, 0x14, 0x0a, 0x7e, 0x52, 0xbe, 0xc0, 0x87, 0x70, - 0x6f, 0x27, 0xfd, 0x1d, 0x5c, 0xe2, 0x7d, 0x20, 0x8a, 0x8b, 0xe0, 0x80, 0x42, 0xbd, 0xf9, 0xd1, - 0x0e, 0x66, 0x7b, 0x1f, 0x72, 0xf5, 0xef, 0x98, 0x32, 0x96, 0x64, 0x42, 0x93, 0x0e, 0x3e, 0x83, - 0x9b, 0xe3, 0x38, 0xcd, 0x06, 0x51, 0xc8, 0x4c, 0x7d, 0x76, 0x72, 0x67, 0x74, 0xde, 0x7c, 0xe3, - 0xbb, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x9c, 0x40, 0xd5, 0x34, 0x63, 0x02, 0x00, 0x00, + // 377 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0xcf, 0x8e, 0xd3, 0x30, + 0x10, 0xc6, 0xc9, 0x36, 0x6c, 0x77, 0x67, 0x4b, 0x65, 0x06, 0x10, 0xe1, 0xcf, 0x6a, 0x97, 0x22, + 0xc1, 0x02, 0x52, 0x0e, 0x70, 0xe6, 0xe0, 0x75, 0x0c, 0x1b, 0x91, 0x38, 0xc1, 0x76, 0x84, 0x38, + 0x59, 0x2e, 0x0d, 0x55, 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0x1f, 0xc0, 0xdd, 0x94, 0x86, + 0xd2, 0x84, 0x42, 0x69, 0x1a, 0x45, 0x54, 0x87, 0x89, 0x20, 0x6e, 0x2d, 0xab, 0xaf, 0x82, 0xed, + 0xca, 0xb7, 0xf1, 0x39, 0x5c, 0x48, 0xfe, 0x39, 0xe3, 0x4a, 0x1b, 0x1a, 0x04, 0x92, 0x2b, 0x65, + 0x3e, 0x24, 0xd2, 0x68, 0x49, 0x85, 0xa2, 0xac, 0x81, 0x8e, 0xf1, 0x35, 0xbc, 0xa0, 0x8c, 0xf1, + 0x54, 0x9b, 0x43, 0x6c, 0x1b, 0xdf, 0xc0, 0xcb, 0x80, 0xb3, 0x28, 0x14, 0xfc, 0x20, 0x7c, 0x82, + 0x0f, 0xe1, 0xde, 0x1a, 0xda, 0x36, 0x4e, 0xf1, 0x3e, 0x10, 0xc5, 0x45, 0xb0, 0xa3, 0x02, 0x5e, + 0xc0, 0x93, 0xbf, 0xff, 0xde, 0x06, 0xce, 0xea, 0xd5, 0xec, 0x0d, 0x69, 0x56, 0x0b, 0x24, 0x9d, + 0x7f, 0xdb, 0x94, 0xb1, 0x24, 0x13, 0x9a, 0xdc, 0xc1, 0x67, 0x70, 0xbe, 0x6f, 0xa7, 0xd9, 0x75, + 0x14, 0x32, 0x53, 0xdf, 0x85, 0x74, 0xfb, 0xc7, 0xcd, 0x9d, 0xdf, 0xfd, 0x0a, 0x00, 0x00, 0xff, + 0xff, 0xb7, 0x6c, 0xd6, 0xba, 0x84, 0x02, 0x00, 0x00, } diff --git a/protocol/protobuf/application_metadata_message.proto b/protocol/protobuf/application_metadata_message.proto index 99a188eae4c..dae1d78be47 100644 --- a/protocol/protobuf/application_metadata_message.proto +++ b/protocol/protobuf/application_metadata_message.proto @@ -23,8 +23,9 @@ message ApplicationMetadataMessage { DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION = 8; REQUEST_TRANSACTION = 9; SEND_TRANSACTION = 10; - SYNC_INSTALLATION_CONTACT = 11; - SYNC_INSTALLATION_ACCOUNT = 12; - SYNC_INSTALLATION_PUBLIC_CHAT = 13; + DECLINE_REQUEST_TRANSACTION = 11; + SYNC_INSTALLATION_CONTACT = 12; + SYNC_INSTALLATION_ACCOUNT = 13; + SYNC_INSTALLATION_PUBLIC_CHAT = 14; } } diff --git a/protocol/protobuf/command.pb.go b/protocol/protobuf/command.pb.go index 8fbec22c566..c2a95993847 100644 --- a/protocol/protobuf/command.pb.go +++ b/protocol/protobuf/command.pb.go @@ -177,6 +177,53 @@ func (m *DeclineRequestAddressForTransaction) GetId() string { return "" } +type DeclineRequestTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeclineRequestTransaction) Reset() { *m = DeclineRequestTransaction{} } +func (m *DeclineRequestTransaction) String() string { return proto.CompactTextString(m) } +func (*DeclineRequestTransaction) ProtoMessage() {} +func (*DeclineRequestTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{3} +} + +func (m *DeclineRequestTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeclineRequestTransaction.Unmarshal(m, b) +} +func (m *DeclineRequestTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeclineRequestTransaction.Marshal(b, m, deterministic) +} +func (m *DeclineRequestTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeclineRequestTransaction.Merge(m, src) +} +func (m *DeclineRequestTransaction) XXX_Size() int { + return xxx_messageInfo_DeclineRequestTransaction.Size(m) +} +func (m *DeclineRequestTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_DeclineRequestTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_DeclineRequestTransaction proto.InternalMessageInfo + +func (m *DeclineRequestTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *DeclineRequestTransaction) GetId() string { + if m != nil { + return m.Id + } + return "" +} + type RequestTransaction struct { Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` @@ -191,7 +238,7 @@ func (m *RequestTransaction) Reset() { *m = RequestTransaction{} } func (m *RequestTransaction) String() string { return proto.CompactTextString(m) } func (*RequestTransaction) ProtoMessage() {} func (*RequestTransaction) Descriptor() ([]byte, []int) { - return fileDescriptor_213c0bb044472049, []int{3} + return fileDescriptor_213c0bb044472049, []int{4} } func (m *RequestTransaction) XXX_Unmarshal(b []byte) error { @@ -254,7 +301,7 @@ func (m *SendTransaction) Reset() { *m = SendTransaction{} } func (m *SendTransaction) String() string { return proto.CompactTextString(m) } func (*SendTransaction) ProtoMessage() {} func (*SendTransaction) Descriptor() ([]byte, []int) { - return fileDescriptor_213c0bb044472049, []int{4} + return fileDescriptor_213c0bb044472049, []int{5} } func (m *SendTransaction) XXX_Unmarshal(b []byte) error { @@ -307,6 +354,7 @@ func init() { proto.RegisterType((*RequestAddressForTransaction)(nil), "protobuf.RequestAddressForTransaction") proto.RegisterType((*AcceptRequestAddressForTransaction)(nil), "protobuf.AcceptRequestAddressForTransaction") proto.RegisterType((*DeclineRequestAddressForTransaction)(nil), "protobuf.DeclineRequestAddressForTransaction") + proto.RegisterType((*DeclineRequestTransaction)(nil), "protobuf.DeclineRequestTransaction") proto.RegisterType((*RequestTransaction)(nil), "protobuf.RequestTransaction") proto.RegisterType((*SendTransaction)(nil), "protobuf.SendTransaction") } @@ -314,21 +362,22 @@ func init() { func init() { proto.RegisterFile("command.proto", fileDescriptor_213c0bb044472049) } var fileDescriptor_213c0bb044472049 = []byte{ - // 252 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4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xdb, 0x54, 0xaf, 0x09, 0x4c, 0xee, 0xd9, 0x99, 0xbf, 0x0f, 0x73, 0x01, 0x27, 0xd2, 0x85, - 0x1e, 0x0b, 0x8c, 0x45, 0x8b, 0x9d, 0xf4, 0xfc, 0x5b, 0x8c, 0x85, 0x9a, 0xc2, 0x38, 0xda, 0x27, - 0x87, 0x52, 0x05, 0xae, 0x1b, 0x1c, 0xe6, 0x9d, 0xb1, 0xdc, 0xaf, 0xff, 0xc7, 0xd5, 0x5b, 0x00, - 0x00, 0x00, 0xff, 0xff, 0x76, 0x92, 0x96, 0x32, 0x37, 0x02, 0x00, 0x00, + // 257 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x92, 0x41, 0x4b, 0x03, 0x31, + 0x10, 0x85, 0xd9, 0x6d, 0xd5, 0x76, 0x50, 0x2b, 0xc1, 0xc3, 0x2a, 0x3d, 0x94, 0x78, 0xa9, 0x17, + 0x2f, 0xfe, 0x82, 0x05, 0x11, 0xc1, 0xdb, 0xea, 0x5d, 0xa6, 0x93, 0xa9, 0x1b, 0xdc, 0x26, 0x35, + 0xc9, 0xf6, 0xec, 0x4f, 0x17, 0xb3, 0xab, 0xdb, 0x0a, 0x82, 0xab, 0xa7, 0xf0, 0x5e, 0x78, 0xf3, + 0x65, 0x1e, 0x81, 0x23, 0xb2, 0xab, 0x15, 0x1a, 0x75, 0xb5, 0x76, 0x36, 0x58, 0x31, 0x8a, 0xc7, + 0xa2, 0x5e, 0xca, 0x25, 0x4c, 0x0b, 0x7e, 0xad, 0xd9, 0x87, 0x5c, 0x29, 0xc7, 0xde, 0xdf, 0x5a, + 0xf7, 0xe8, 0xd0, 0x78, 0xa4, 0xa0, 0xad, 0x11, 0xa7, 0xb0, 0x47, 0x95, 0xa5, 0x97, 0x2c, 0x99, + 0x25, 0xf3, 0x61, 0xd1, 0x88, 0x0f, 0x77, 0x83, 0x55, 0xcd, 0x59, 0x3a, 0x4b, 0xe6, 0xe3, 0xa2, + 0x11, 0xe2, 0x1c, 0x46, 0x64, 0x4d, 0x70, 0x48, 0x21, 0x1b, 0xc4, 0x8b, 0x2f, 0x2d, 0x15, 0xc8, + 0x9c, 0x88, 0xd7, 0xe1, 0x0f, 0xb4, 0x63, 0x48, 0xb5, 0x6a, 0x51, 0xa9, 0x56, 0x22, 0x83, 0x03, + 0x6c, 0xe2, 0x2d, 0xe6, 0x53, 0xca, 0x7b, 0xb8, 0xb8, 0x61, 0xaa, 0xb4, 0xe1, 0xff, 0x63, 0x64, + 0x0e, 0x67, 0xbb, 0xc3, 0xfa, 0x8f, 0xd8, 0x80, 0xf8, 0x75, 0x76, 0x6b, 0xab, 0x74, 0x67, 0xab, + 0xae, 0xed, 0xc1, 0x4f, 0x6d, 0x0f, 0xbf, 0xb5, 0xfd, 0x96, 0xc0, 0xe4, 0x81, 0x8d, 0xea, 0xdf, + 0xed, 0x25, 0x9c, 0x84, 0x2e, 0xf4, 0x54, 0xa2, 0x2f, 0x5b, 0xec, 0x64, 0xcb, 0xbf, 0x43, 0x5f, + 0x8a, 0x29, 0x8c, 0xbd, 0x7e, 0x36, 0x18, 0x6a, 0xc7, 0xf1, 0x05, 0x87, 0x45, 0x67, 0x2c, 0xf6, + 0xe3, 0x17, 0xbb, 0x7e, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x13, 0xdb, 0x87, 0x02, 0x7a, 0x02, 0x00, + 0x00, } diff --git a/protocol/protobuf/command.proto b/protocol/protobuf/command.proto index 9089898f222..195e9035d93 100644 --- a/protocol/protobuf/command.proto +++ b/protocol/protobuf/command.proto @@ -19,6 +19,11 @@ message DeclineRequestAddressForTransaction { string id = 2; } +message DeclineRequestTransaction { + uint64 clock = 1; + string id = 2; +} + message RequestTransaction { uint64 clock = 1; string address = 2; diff --git a/protocol/transaction_validator.go b/protocol/transaction_validator.go index 3a3d91e5ae8..0517163b8ec 100644 --- a/protocol/transaction_validator.go +++ b/protocol/transaction_validator.go @@ -73,7 +73,10 @@ func (t *TransactionValidator) verifyTransactionSignature(from *ecdsa.PublicKey, signatureMaterial := append(publicKeyBytes, hashBytes...) t.logger.Info("signature material", zap.Binary("material", signatureMaterial)) - extractedAddress, err := crypto.EcRecover(context.Background(), signatureMaterial, signature) + // We take a copy as EcRecover modifies the byte slice + signatureCopy := make([]byte, len(signature)) + copy(signatureCopy, signature) + extractedAddress, err := crypto.EcRecover(context.Background(), signatureMaterial, signatureCopy) if err != nil { return err } diff --git a/protocol/v1/status_message.go b/protocol/v1/status_message.go index 5bc506c2343..db34a825106 100644 --- a/protocol/v1/status_message.go +++ b/protocol/v1/status_message.go @@ -225,6 +225,17 @@ func (m *StatusMessage) HandleApplication() 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 } diff --git a/services/shhext/api.go b/services/shhext/api.go index 7d3ea531bd1..e084c7f9c51 100644 --- a/services/shhext/api.go +++ b/services/shhext/api.go @@ -707,6 +707,10 @@ func (api *PublicAPI) DeclineRequestAddressForTransaction(ctx context.Context, m return api.service.messenger.DeclineRequestAddressForTransaction(ctx, messageID) } +func (api *PublicAPI) DeclineRequestTransaction(ctx context.Context, messageID string) (*protocol.MessengerResponse, error) { + return api.service.messenger.DeclineRequestTransaction(ctx, messageID) +} + func (api *PublicAPI) AcceptRequestAddressForTransaction(ctx context.Context, messageID, address string) (*protocol.MessengerResponse, error) { return api.service.messenger.AcceptRequestAddressForTransaction(ctx, messageID, address) } diff --git a/vendor/github.com/status-im/status-go/protocol/message.go b/vendor/github.com/status-im/status-go/protocol/message.go index c0241234e57..dacec67123c 100644 --- a/vendor/github.com/status-im/status-go/protocol/message.go +++ b/vendor/github.com/status-im/status-go/protocol/message.go @@ -92,7 +92,7 @@ type Message struct { // Replace indicates that this is a replacement of a message // that has been updated - Replace string `json:"replace"` + Replace string `json:"replace,omitEmpty"` SigPubKey *ecdsa.PublicKey `json:"-"` } @@ -128,7 +128,7 @@ func (m *Message) MarshalJSON() ([]byte, error) { ChatId string `json:"chatId"` LocalChatID string `json:"localChatId"` Clock uint64 `json:"clock"` - Replace string `json:"replace"` + Replace string `json:"replace,omitEmpty"` ResponseTo string `json:"responseTo"` EnsName string `json:"ensName"` Sticker *protobuf.StickerMessage `json:"sticker"` diff --git a/vendor/github.com/status-im/status-go/protocol/message_handler.go b/vendor/github.com/status-im/status-go/protocol/message_handler.go index d9d8db9a614..d04873c3c1a 100644 --- a/vendor/github.com/status-im/status-go/protocol/message_handler.go +++ b/vendor/github.com/status-im/status-go/protocol/message_handler.go @@ -479,6 +479,40 @@ func (m *MessageHandler) HandleDeclineRequestAddressForTransaction(messageState return m.handleCommandMessage(messageState, oldMessage) } +func (m *MessageHandler) HandleDeclineRequestTransaction(messageState *ReceivedMessageState, command protobuf.DeclineRequestTransaction) error { + err := ValidateReceivedDeclineRequestTransaction(&command) + if err != nil { + return err + } + oldMessage, err := m.persistence.MessageByID(command.Id) + if err != nil { + return err + } + if oldMessage == nil { + return errors.New("message not found") + } + + if oldMessage.LocalChatID != messageState.CurrentMessageState.Contact.ID { + return errors.New("From must match") + } + + if oldMessage.OutgoingStatus == "" { + return errors.New("Initial message must originate from us") + } + + if oldMessage.CommandParameters.CommandState != CommandStateRequestTransaction { + return errors.New("Wrong state for command") + } + + oldMessage.Clock = command.Clock + oldMessage.Timestamp = messageState.CurrentMessageState.WhisperTimestamp + oldMessage.Text = "Transaction request declined" + oldMessage.Replace = command.Id + oldMessage.CommandParameters.CommandState = CommandStateRequestTransactionDeclined + + return m.handleCommandMessage(messageState, oldMessage) +} + func (m *MessageHandler) matchMessage(message *Message, chats map[string]*Chat) (*Chat, error) { if message.SigPubKey == nil { m.logger.Error("public key can't be empty") diff --git a/vendor/github.com/status-im/status-go/protocol/message_validator.go b/vendor/github.com/status-im/status-go/protocol/message_validator.go index 93ed54e8191..712be1e0ced 100644 --- a/vendor/github.com/status-im/status-go/protocol/message_validator.go +++ b/vendor/github.com/status-im/status-go/protocol/message_validator.go @@ -109,6 +109,18 @@ func ValidateReceivedDeclineRequestAddressForTransaction(message *protobuf.Decli return nil } +func ValidateReceivedDeclineRequestTransaction(message *protobuf.DeclineRequestTransaction) error { + if message.Clock == 0 { + return errors.New("Clock can't be 0") + } + + if len(message.Id) == 0 { + return errors.New("MessageID can't be empty") + } + + return nil +} + func ValidateReceivedChatMessage(message *protobuf.ChatMessage) error { if message.Clock == 0 { return errors.New("Clock can't be 0") diff --git a/vendor/github.com/status-im/status-go/protocol/messenger.go b/vendor/github.com/status-im/status-go/protocol/messenger.go index 7f1657cf339..e5a4d5ad1fe 100644 --- a/vendor/github.com/status-im/status-go/protocol/messenger.go +++ b/vendor/github.com/status-im/status-go/protocol/messenger.go @@ -1123,11 +1123,9 @@ func (m *Messenger) hasPairedDevices() bool { // sendToPairedDevices will check if we have any paired devices and send to them if necessary func (m *Messenger) sendToPairedDevices(ctx context.Context, payload []byte, messageType protobuf.ApplicationMetadataMessage_Type) error { - m.logger.Info("PAIRED") hasPairedDevices := m.hasPairedDevices() // We send a message to any paired device if hasPairedDevices { - m.logger.Info("hAH PAIRED") _, err := m.processor.SendPrivateRaw(ctx, &m.identity.PublicKey, payload, messageType) if err != nil { return err @@ -1703,6 +1701,15 @@ func (m *Messenger) handleRetrievedMessages(chatWithMessages map[transport.Filte continue } + case protobuf.DeclineRequestTransaction: + command := msg.ParsedMessage.(protobuf.DeclineRequestTransaction) + logger.Debug("Handling DeclineRequestTransaction") + err = m.handler.HandleDeclineRequestTransaction(messageState, command) + if err != nil { + logger.Warn("failed to handle DeclineRequestTransaction", zap.Error(err)) + continue + } + case protobuf.RequestTransaction: command := msg.ParsedMessage.(protobuf.RequestTransaction) logger.Debug("Handling RequestTransaction") @@ -2169,6 +2176,87 @@ func (m *Messenger) AcceptRequestAddressForTransaction(ctx context.Context, mess return &response, m.saveChat(chat) } +func (m *Messenger) DeclineRequestTransaction(ctx context.Context, messageID string) (*MessengerResponse, error) { + m.mutex.Lock() + defer m.mutex.Unlock() + + var response MessengerResponse + + message, err := m.MessageByID(messageID) + if err != nil { + return nil, err + } + + if message == nil { + return nil, errors.New("message not found") + } + + chatID := message.LocalChatID + + // A valid added chat is required. + chat, ok := m.allChats[chatID] + if !ok { + return nil, errors.New("Chat not found") + } + if chat.ChatType != ChatTypeOneToOne { + return nil, errors.New("Need to be a one-to-one chat") + } + + clock, timestamp := chat.NextClockAndTimestamp() + message.Clock = clock + message.Timestamp = timestamp + message.Text = "Transaction request declined" + message.OutgoingStatus = OutgoingStatusSending + message.Replace = messageID + + err = m.persistence.HideMessage(messageID) + if err != nil { + return nil, err + } + + request := &protobuf.DeclineRequestTransaction{ + Clock: message.Clock, + Id: messageID, + } + encodedMessage, err := proto.Marshal(request) + if err != nil { + return nil, err + } + + newMessageID, err := m.dispatchMessage(ctx, &RawMessage{ + LocalChatID: chat.ID, + Payload: encodedMessage, + MessageType: protobuf.ApplicationMetadataMessage_DECLINE_REQUEST_TRANSACTION, + ResendAutomatically: true, + }) + + if err != nil { + return nil, err + } + + message.ID = types.EncodeHex(newMessageID) + message.CommandParameters.CommandState = CommandStateRequestTransactionDeclined + + err = message.PrepareContent() + if err != nil { + return nil, err + } + + err = chat.UpdateFromMessage(message) + if err != nil { + return nil, err + } + + err = m.persistence.SaveMessagesLegacy([]*Message{message}) + if err != nil { + return nil, err + } + + response.Chats = []*Chat{chat} + response.Messages = []*Message{message} + return &response, m.saveChat(chat) +} + func (m *Messenger) DeclineRequestAddressForTransaction(ctx context.Context, messageID string) (*MessengerResponse, error) { m.mutex.Lock() defer m.mutex.Unlock() diff --git a/vendor/github.com/status-im/status-go/protocol/migrations/migrations.go b/vendor/github.com/status-im/status-go/protocol/migrations/migrations.go index e49f15fd13c..597b517f4bc 100644 --- a/vendor/github.com/status-im/status-go/protocol/migrations/migrations.go +++ b/vendor/github.com/status-im/status-go/protocol/migrations/migrations.go @@ -86,7 +86,7 @@ func _000001_initDownDbSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "000001_init.down.db.sql", size: 65, mode: os.FileMode(0644), modTime: time.Unix(1576661250, 0)} + info := bindataFileInfo{name: "000001_init.down.db.sql", size: 65, mode: os.FileMode(0644), modTime: time.Unix(1577718673, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x5e, 0xbb, 0x3f, 0x1, 0x75, 0x19, 0x70, 0x86, 0xa7, 0x34, 0x40, 0x17, 0x34, 0x3e, 0x18, 0x51, 0x79, 0xd4, 0x22, 0xad, 0x8f, 0x80, 0xcc, 0xa6, 0xcc, 0x6, 0x2b, 0x62, 0x2, 0x47, 0xba, 0xf9}} return a, nil } @@ -106,7 +106,7 @@ func _000001_initUpDbSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "000001_init.up.db.sql", size: 2693, mode: os.FileMode(0644), modTime: time.Unix(1577712858, 0)} + info := bindataFileInfo{name: "000001_init.up.db.sql", size: 2693, mode: os.FileMode(0644), modTime: time.Unix(1577718868, 0)} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x34, 0x9f, 0x6, 0x64, 0xcf, 0x97, 0xbe, 0xa8, 0xa2, 0x2f, 0xda, 0xc5, 0x9d, 0x26, 0x3, 0x65, 0x98, 0x8a, 0x7a, 0x6a, 0xc3, 0xd, 0x3f, 0x25, 0xfe, 0x4c, 0x5, 0xdb, 0x98, 0xa9, 0xf9, 0xf}} return a, nil } diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.pb.go b/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.pb.go index 60fa3020de0..b166e283ff5 100644 --- a/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.pb.go +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.pb.go @@ -34,9 +34,10 @@ const ( ApplicationMetadataMessage_DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION ApplicationMetadataMessage_Type = 8 ApplicationMetadataMessage_REQUEST_TRANSACTION ApplicationMetadataMessage_Type = 9 ApplicationMetadataMessage_SEND_TRANSACTION ApplicationMetadataMessage_Type = 10 - ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT ApplicationMetadataMessage_Type = 11 - ApplicationMetadataMessage_SYNC_INSTALLATION_ACCOUNT ApplicationMetadataMessage_Type = 12 - ApplicationMetadataMessage_SYNC_INSTALLATION_PUBLIC_CHAT ApplicationMetadataMessage_Type = 13 + ApplicationMetadataMessage_DECLINE_REQUEST_TRANSACTION ApplicationMetadataMessage_Type = 11 + ApplicationMetadataMessage_SYNC_INSTALLATION_CONTACT ApplicationMetadataMessage_Type = 12 + ApplicationMetadataMessage_SYNC_INSTALLATION_ACCOUNT ApplicationMetadataMessage_Type = 13 + ApplicationMetadataMessage_SYNC_INSTALLATION_PUBLIC_CHAT ApplicationMetadataMessage_Type = 14 ) var ApplicationMetadataMessage_Type_name = map[int32]string{ @@ -51,9 +52,10 @@ var ApplicationMetadataMessage_Type_name = map[int32]string{ 8: "DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION", 9: "REQUEST_TRANSACTION", 10: "SEND_TRANSACTION", - 11: "SYNC_INSTALLATION_CONTACT", - 12: "SYNC_INSTALLATION_ACCOUNT", - 13: "SYNC_INSTALLATION_PUBLIC_CHAT", + 11: "DECLINE_REQUEST_TRANSACTION", + 12: "SYNC_INSTALLATION_CONTACT", + 13: "SYNC_INSTALLATION_ACCOUNT", + 14: "SYNC_INSTALLATION_PUBLIC_CHAT", } var ApplicationMetadataMessage_Type_value = map[string]int32{ @@ -68,9 +70,10 @@ var ApplicationMetadataMessage_Type_value = map[string]int32{ "DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION": 8, "REQUEST_TRANSACTION": 9, "SEND_TRANSACTION": 10, - "SYNC_INSTALLATION_CONTACT": 11, - "SYNC_INSTALLATION_ACCOUNT": 12, - "SYNC_INSTALLATION_PUBLIC_CHAT": 13, + "DECLINE_REQUEST_TRANSACTION": 11, + "SYNC_INSTALLATION_CONTACT": 12, + "SYNC_INSTALLATION_ACCOUNT": 13, + "SYNC_INSTALLATION_PUBLIC_CHAT": 14, } func (x ApplicationMetadataMessage_Type) String() string { @@ -147,28 +150,29 @@ func init() { func init() { proto.RegisterFile("application_metadata_message.proto", fileDescriptor_ad09a6406fcf24c7) } var fileDescriptor_ad09a6406fcf24c7 = []byte{ - // 367 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0x51, 0x8f, 0xd2, 0x40, - 0x10, 0xc7, 0xed, 0x51, 0x8f, 0xbb, 0x39, 0xbc, 0xac, 0xa3, 0xc6, 0x6a, 0xbc, 0x88, 0x98, 0x28, - 0x6a, 0xd2, 0x07, 0x7d, 0xf6, 0x61, 0xd9, 0xae, 0xd2, 0xd8, 0x6e, 0xeb, 0xee, 0x36, 0xc6, 0xa7, - 0xcd, 0x22, 0x95, 0x90, 0x00, 0x6d, 0xa0, 0x3c, 0xf0, 0x3d, 0xfc, 0x14, 0x7e, 0x4a, 0xd3, 0x0a, - 0x22, 0x41, 0xc3, 0xd3, 0x66, 0x7e, 0xff, 0xdf, 0x64, 0x32, 0xb3, 0xd0, 0xb3, 0x65, 0x39, 0x9b, - 0x7e, 0xb3, 0xd5, 0xb4, 0x58, 0x98, 0x79, 0x5e, 0xd9, 0xb1, 0xad, 0xac, 0x99, 0xe7, 0xab, 0x95, - 0x9d, 0xe4, 0x7e, 0xb9, 0x2c, 0xaa, 0x02, 0x2f, 0x9a, 0x67, 0xb4, 0xfe, 0xde, 0xfb, 0xe9, 0xc2, - 0x63, 0xba, 0x6f, 0x88, 0xb7, 0x7e, 0xfc, 0x5b, 0xc7, 0x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, 0x70, - 0x6f, 0x27, 0xfd, 0x1d, 0x5c, 0xe2, 0x7d, 0x20, 0x8a, 0x8b, 0xe0, 0x80, 0x42, 0xbd, 0xf9, 0xd1, - 0x0e, 0x66, 0x7b, 0x1f, 0x72, 0xf5, 0xef, 0x98, 0x32, 0x96, 0x64, 0x42, 0x93, 0x0e, 0x3e, 0x83, - 0x9b, 0xe3, 0x38, 0xcd, 0x06, 0x51, 0xc8, 0x4c, 0x7d, 0x76, 0x72, 0x67, 0x74, 0xde, 0x7c, 0xe3, - 0xbb, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x9c, 0x40, 0xd5, 0x34, 0x63, 0x02, 0x00, 0x00, + // 377 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0xcf, 0x8e, 0xd3, 0x30, + 0x10, 0xc6, 0xc9, 0x36, 0x6c, 0x77, 0x67, 0x4b, 0x65, 0x06, 0x10, 0xe1, 0xcf, 0x6a, 0x97, 0x22, + 0xc1, 0x02, 0x52, 0x0e, 0x70, 0xe6, 0xe0, 0x75, 0x0c, 0x1b, 0x91, 0x38, 0xc1, 0x76, 0x84, 0x38, + 0x59, 0x2e, 0x0d, 0x55, 0xa5, 0xb6, 0x89, 0xda, 0xf4, 0xd0, 0x07, 0xe3, 0x29, 0x78, 0x29, 0x94, + 0xd0, 0xd2, 0x96, 0x82, 0x7a, 0xb2, 0xe6, 0xfb, 0x7e, 0x9f, 0x47, 0x33, 0x03, 0x3d, 0x5b, 0x96, + 0xe3, 0xd1, 0x37, 0x5b, 0x8d, 0x8a, 0xa9, 0x99, 0xe4, 0x95, 0x1d, 0xd8, 0xca, 0x9a, 0x49, 0x3e, + 0x9f, 0xdb, 0x61, 0xee, 0x97, 0xb3, 0xa2, 0x2a, 0xf0, 0xa4, 0x79, 0xfa, 0x8b, 0xef, 0xbd, 0x9f, + 0x2e, 0x3c, 0xa6, 0x9b, 0x40, 0xbc, 0xe2, 0xe3, 0xdf, 0x38, 0x3e, 0x85, 0xd3, 0xf9, 0x68, 0x38, + 0xb5, 0xd5, 0x62, 0x96, 0x7b, 0xce, 0xa5, 0x73, 0xd5, 0x91, 0x1b, 0x01, 0x3d, 0x68, 0x97, 0x76, + 0x39, 0x2e, 0xec, 0xc0, 0x3b, 0x6a, 0xbc, 0x75, 0x89, 0xef, 0xc1, 0xad, 0x96, 0x65, 0xee, 0xb5, + 0x2e, 0x9d, 0xab, 0xee, 0xdb, 0x57, 0xfe, 0xba, 0x9f, 0xff, 0xff, 0x5e, 0xbe, 0x5e, 0x96, 0xb9, + 0x6c, 0x62, 0xbd, 0x1f, 0x2d, 0x70, 0xeb, 0x12, 0xcf, 0xa0, 0x9d, 0x89, 0x4f, 0x22, 0xf9, 0x22, + 0xc8, 0x2d, 0x24, 0xd0, 0x61, 0x37, 0x54, 0x9b, 0x98, 0x2b, 0x45, 0x3f, 0x72, 0xe2, 0x20, 0x42, + 0x97, 0x25, 0x42, 0x53, 0xa6, 0x4d, 0x96, 0x06, 0x54, 0x73, 0x72, 0x84, 0xe7, 0xf0, 0x28, 0xe6, + 0xf1, 0x35, 0x97, 0xea, 0x26, 0x4c, 0x57, 0xf2, 0x9f, 0x48, 0x0b, 0x1f, 0xc0, 0xdd, 0x94, 0x86, + 0xd2, 0x84, 0x42, 0x69, 0x1a, 0x45, 0x54, 0x87, 0x89, 0x20, 0x6e, 0x2d, 0xab, 0xaf, 0x82, 0xed, + 0xca, 0xb7, 0xf1, 0x39, 0x5c, 0x48, 0xfe, 0x39, 0xe3, 0x4a, 0x1b, 0x1a, 0x04, 0x92, 0x2b, 0x65, + 0x3e, 0x24, 0xd2, 0x68, 0x49, 0x85, 0xa2, 0xac, 0x81, 0x8e, 0xf1, 0x35, 0xbc, 0xa0, 0x8c, 0xf1, + 0x54, 0x9b, 0x43, 0x6c, 0x1b, 0xdf, 0xc0, 0xcb, 0x80, 0xb3, 0x28, 0x14, 0xfc, 0x20, 0x7c, 0x82, + 0x0f, 0xe1, 0xde, 0x1a, 0xda, 0x36, 0x4e, 0xf1, 0x3e, 0x10, 0xc5, 0x45, 0xb0, 0xa3, 0x02, 0x5e, + 0xc0, 0x93, 0xbf, 0xff, 0xde, 0x06, 0xce, 0xea, 0xd5, 0xec, 0x0d, 0x69, 0x56, 0x0b, 0x24, 0x9d, + 0x7f, 0xdb, 0x94, 0xb1, 0x24, 0x13, 0x9a, 0xdc, 0xc1, 0x67, 0x70, 0xbe, 0x6f, 0xa7, 0xd9, 0x75, + 0x14, 0x32, 0x53, 0xdf, 0x85, 0x74, 0xfb, 0xc7, 0xcd, 0x9d, 0xdf, 0xfd, 0x0a, 0x00, 0x00, 0xff, + 0xff, 0xb7, 0x6c, 0xd6, 0xba, 0x84, 0x02, 0x00, 0x00, } diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.proto b/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.proto index 99a188eae4c..dae1d78be47 100644 --- a/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.proto +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/application_metadata_message.proto @@ -23,8 +23,9 @@ message ApplicationMetadataMessage { DECLINE_REQUEST_ADDRESS_FOR_TRANSACTION = 8; REQUEST_TRANSACTION = 9; SEND_TRANSACTION = 10; - SYNC_INSTALLATION_CONTACT = 11; - SYNC_INSTALLATION_ACCOUNT = 12; - SYNC_INSTALLATION_PUBLIC_CHAT = 13; + DECLINE_REQUEST_TRANSACTION = 11; + SYNC_INSTALLATION_CONTACT = 12; + SYNC_INSTALLATION_ACCOUNT = 13; + SYNC_INSTALLATION_PUBLIC_CHAT = 14; } } diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/command.pb.go b/vendor/github.com/status-im/status-go/protocol/protobuf/command.pb.go index 8fbec22c566..c2a95993847 100644 --- a/vendor/github.com/status-im/status-go/protocol/protobuf/command.pb.go +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/command.pb.go @@ -177,6 +177,53 @@ func (m *DeclineRequestAddressForTransaction) GetId() string { return "" } +type DeclineRequestTransaction struct { + Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *DeclineRequestTransaction) Reset() { *m = DeclineRequestTransaction{} } +func (m *DeclineRequestTransaction) String() string { return proto.CompactTextString(m) } +func (*DeclineRequestTransaction) ProtoMessage() {} +func (*DeclineRequestTransaction) Descriptor() ([]byte, []int) { + return fileDescriptor_213c0bb044472049, []int{3} +} + +func (m *DeclineRequestTransaction) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DeclineRequestTransaction.Unmarshal(m, b) +} +func (m *DeclineRequestTransaction) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DeclineRequestTransaction.Marshal(b, m, deterministic) +} +func (m *DeclineRequestTransaction) XXX_Merge(src proto.Message) { + xxx_messageInfo_DeclineRequestTransaction.Merge(m, src) +} +func (m *DeclineRequestTransaction) XXX_Size() int { + return xxx_messageInfo_DeclineRequestTransaction.Size(m) +} +func (m *DeclineRequestTransaction) XXX_DiscardUnknown() { + xxx_messageInfo_DeclineRequestTransaction.DiscardUnknown(m) +} + +var xxx_messageInfo_DeclineRequestTransaction proto.InternalMessageInfo + +func (m *DeclineRequestTransaction) GetClock() uint64 { + if m != nil { + return m.Clock + } + return 0 +} + +func (m *DeclineRequestTransaction) GetId() string { + if m != nil { + return m.Id + } + return "" +} + type RequestTransaction struct { Clock uint64 `protobuf:"varint,1,opt,name=clock,proto3" json:"clock,omitempty"` Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"` @@ -191,7 +238,7 @@ func (m *RequestTransaction) Reset() { *m = RequestTransaction{} } func (m *RequestTransaction) String() string { return proto.CompactTextString(m) } func (*RequestTransaction) ProtoMessage() {} func (*RequestTransaction) Descriptor() ([]byte, []int) { - return fileDescriptor_213c0bb044472049, []int{3} + return fileDescriptor_213c0bb044472049, []int{4} } func (m *RequestTransaction) XXX_Unmarshal(b []byte) error { @@ -254,7 +301,7 @@ func (m *SendTransaction) Reset() { *m = SendTransaction{} } func (m *SendTransaction) String() string { return proto.CompactTextString(m) } func (*SendTransaction) ProtoMessage() {} func (*SendTransaction) Descriptor() ([]byte, []int) { - return fileDescriptor_213c0bb044472049, []int{4} + return fileDescriptor_213c0bb044472049, []int{5} } func (m *SendTransaction) XXX_Unmarshal(b []byte) error { @@ -307,6 +354,7 @@ func init() { proto.RegisterType((*RequestAddressForTransaction)(nil), "protobuf.RequestAddressForTransaction") proto.RegisterType((*AcceptRequestAddressForTransaction)(nil), "protobuf.AcceptRequestAddressForTransaction") proto.RegisterType((*DeclineRequestAddressForTransaction)(nil), "protobuf.DeclineRequestAddressForTransaction") + proto.RegisterType((*DeclineRequestTransaction)(nil), "protobuf.DeclineRequestTransaction") proto.RegisterType((*RequestTransaction)(nil), "protobuf.RequestTransaction") proto.RegisterType((*SendTransaction)(nil), "protobuf.SendTransaction") } @@ -314,21 +362,22 @@ func init() { func init() { proto.RegisterFile("command.proto", fileDescriptor_213c0bb044472049) } var fileDescriptor_213c0bb044472049 = []byte{ - // 252 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x92, 0x41, 0x4b, 0xc3, 0x40, - 0x10, 0x85, 0x49, 0x5a, 0xb5, 0x1d, 0xd4, 0xca, 0xe2, 0x21, 0x48, 0x0f, 0x65, 0xbd, 0xd4, 0x8b, - 0x17, 0x7f, 0x41, 0x41, 0x44, 0xf0, 0x16, 0xbd, 0xcb, 0x74, 0x76, 0x6a, 0x16, 0xd3, 0xdd, 0xba, - 0x3b, 0xe9, 0xd9, 0x9f, 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af, 0xff, 0xc7, 0xd5, 0x5b, 0x00, - 0x00, 0x00, 0xff, 0xff, 0x76, 0x92, 0x96, 0x32, 0x37, 0x02, 0x00, 0x00, + // 257 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x92, 0x41, 0x4b, 0x03, 0x31, + 0x10, 0x85, 0xd9, 0x6d, 0xd5, 0x76, 0x50, 0x2b, 0xc1, 0xc3, 0x2a, 0x3d, 0x94, 0x78, 0xa9, 0x17, + 0x2f, 0xfe, 0x82, 0x05, 0x11, 0xc1, 0xdb, 0xea, 0x5d, 0xa6, 0x93, 0xa9, 0x1b, 0xdc, 0x26, 0x35, + 0xc9, 0xf6, 0xec, 0x4f, 0x17, 0xb3, 0xab, 0xdb, 0x0a, 0x82, 0xab, 0xa7, 0xf0, 0x5e, 0x78, 0xf3, + 0x65, 0x1e, 0x81, 0x23, 0xb2, 0xab, 0x15, 0x1a, 0x75, 0xb5, 0x76, 0x36, 0x58, 0x31, 0x8a, 0xc7, + 0xa2, 0x5e, 0xca, 0x25, 0x4c, 0x0b, 0x7e, 0xad, 0xd9, 0x87, 0x5c, 0x29, 0xc7, 0xde, 0xdf, 0x5a, + 0xf7, 0xe8, 0xd0, 0x78, 0xa4, 0xa0, 0xad, 0x11, 0xa7, 0xb0, 0x47, 0x95, 0xa5, 0x97, 0x2c, 0x99, + 0x25, 0xf3, 0x61, 0xd1, 0x88, 0x0f, 0x77, 0x83, 0x55, 0xcd, 0x59, 0x3a, 0x4b, 0xe6, 0xe3, 0xa2, + 0x11, 0xe2, 0x1c, 0x46, 0x64, 0x4d, 0x70, 0x48, 0x21, 0x1b, 0xc4, 0x8b, 0x2f, 0x2d, 0x15, 0xc8, + 0x9c, 0x88, 0xd7, 0xe1, 0x0f, 0xb4, 0x63, 0x48, 0xb5, 0x6a, 0x51, 0xa9, 0x56, 0x22, 0x83, 0x03, + 0x6c, 0xe2, 0x2d, 0xe6, 0x53, 0xca, 0x7b, 0xb8, 0xb8, 0x61, 0xaa, 0xb4, 0xe1, 0xff, 0x63, 0x64, + 0x0e, 0x67, 0xbb, 0xc3, 0xfa, 0x8f, 0xd8, 0x80, 0xf8, 0x75, 0x76, 0x6b, 0xab, 0x74, 0x67, 0xab, + 0xae, 0xed, 0xc1, 0x4f, 0x6d, 0x0f, 0xbf, 0xb5, 0xfd, 0x96, 0xc0, 0xe4, 0x81, 0x8d, 0xea, 0xdf, + 0xed, 0x25, 0x9c, 0x84, 0x2e, 0xf4, 0x54, 0xa2, 0x2f, 0x5b, 0xec, 0x64, 0xcb, 0xbf, 0x43, 0x5f, + 0x8a, 0x29, 0x8c, 0xbd, 0x7e, 0x36, 0x18, 0x6a, 0xc7, 0xf1, 0x05, 0x87, 0x45, 0x67, 0x2c, 0xf6, + 0xe3, 0x17, 0xbb, 0x7e, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x13, 0xdb, 0x87, 0x02, 0x7a, 0x02, 0x00, + 0x00, } diff --git a/vendor/github.com/status-im/status-go/protocol/protobuf/command.proto b/vendor/github.com/status-im/status-go/protocol/protobuf/command.proto index 9089898f222..195e9035d93 100644 --- a/vendor/github.com/status-im/status-go/protocol/protobuf/command.proto +++ b/vendor/github.com/status-im/status-go/protocol/protobuf/command.proto @@ -19,6 +19,11 @@ message DeclineRequestAddressForTransaction { string id = 2; } +message DeclineRequestTransaction { + uint64 clock = 1; + string id = 2; +} + message RequestTransaction { uint64 clock = 1; string address = 2; diff --git a/vendor/github.com/status-im/status-go/protocol/transaction_validator.go b/vendor/github.com/status-im/status-go/protocol/transaction_validator.go index 3a3d91e5ae8..0517163b8ec 100644 --- a/vendor/github.com/status-im/status-go/protocol/transaction_validator.go +++ b/vendor/github.com/status-im/status-go/protocol/transaction_validator.go @@ -73,7 +73,10 @@ func (t *TransactionValidator) verifyTransactionSignature(from *ecdsa.PublicKey, signatureMaterial := append(publicKeyBytes, hashBytes...) t.logger.Info("signature material", zap.Binary("material", signatureMaterial)) - extractedAddress, err := crypto.EcRecover(context.Background(), signatureMaterial, signature) + // We take a copy as EcRecover modifies the byte slice + signatureCopy := make([]byte, len(signature)) + copy(signatureCopy, signature) + extractedAddress, err := crypto.EcRecover(context.Background(), signatureMaterial, signatureCopy) if err != nil { return err } diff --git a/vendor/github.com/status-im/status-go/protocol/v1/status_message.go b/vendor/github.com/status-im/status-go/protocol/v1/status_message.go index 5bc506c2343..db34a825106 100644 --- a/vendor/github.com/status-im/status-go/protocol/v1/status_message.go +++ b/vendor/github.com/status-im/status-go/protocol/v1/status_message.go @@ -225,6 +225,17 @@ func (m *StatusMessage) HandleApplication() 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 }