use pub key to gen chat message id

This commit is contained in:
Felicio Mununga 2022-06-08 17:09:36 +02:00
parent d4c597fa0f
commit 6252736ad2
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
2 changed files with 13 additions and 9 deletions

View File

@ -1,3 +1,5 @@
import { recoverPublicKeyFromMetadata } from '~/src/utils/recover-public-key-from-metadata'
import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message' import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message'
import { ChatMessage } from '../../../protos/chat-message' import { ChatMessage } from '../../../protos/chat-message'
import { ProtocolMessage } from '../../../protos/protocol-message' import { ProtocolMessage } from '../../../protos/protocol-message'
@ -46,12 +48,13 @@ export function handleChannelChatMessage(
return return
} }
const publicKey = recoverPublicKeyFromMetadata(decodedMetadata)
const decodedPayload = ChatMessage.decode(messageToDecode) const decodedPayload = ChatMessage.decode(messageToDecode)
const messageId = payloadToId( // fixme?: handle decodedProtocol.encryptedMessage
decodedProtocol.publicMessage, const messageId = payloadToId(decodedProtocol.publicMessage, publicKey)
wakuMessage.signaturePublicKey
)
const channelId = getChannelId(decodedPayload.chatId) const channelId = getChannelId(decodedPayload.chatId)
const message = mapChatMessage(decodedPayload, { messageId, channelId }) const message = mapChatMessage(decodedPayload, { messageId, channelId })

View File

@ -2,6 +2,8 @@
// todo?: rename to handle-message // todo?: rename to handle-message
import { bytesToHex } from 'ethereum-cryptography/utils' import { bytesToHex } from 'ethereum-cryptography/utils'
import { recoverPublicKeyFromMetadata } from '~/src/utils/recover-public-key-from-metadata'
import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message' import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message'
import { import {
ChatMessage, ChatMessage,
@ -61,17 +63,16 @@ export function handleChannelChatMessage(
// break // break
// } // }
const publicKey = recoverPublicKeyFromMetadata(decodedMetadata)
// todo: merge and process other types of messages // todo: merge and process other types of messages
// TODO?: ignore messages which are messageType !== COMMUNITY_CHAT // TODO?: ignore messages which are messageType !== COMMUNITY_CHAT
switch (decodedMetadata.type) { switch (decodedMetadata.type) {
case ApplicationMetadataMessage.Type.TYPE_CHAT_MESSAGE: { case ApplicationMetadataMessage.Type.TYPE_CHAT_MESSAGE: {
const decodedPayload = ChatMessage.decode(messageToDecode) const decodedPayload = ChatMessage.decode(messageToDecode)
const messageId = payloadToId( // fixme?: handle decodedProtocol.encryptedMessage
decodedProtocol.publicMessage, const messageId = payloadToId(decodedProtocol.publicMessage, publicKey)
// fixme!: replace for recoverPublicKeyFromMetadata
wakuMessage.signaturePublicKey
)
const channelId = getChannelId(decodedPayload.chatId) const channelId = getChannelId(decodedPayload.chatId)
const _messages = messages[channelId] || [] const _messages = messages[channelId] || []