From 6a48b78d5a45ccf031677a968adf6016e3a66a27 Mon Sep 17 00:00:00 2001 From: AlexNi245 Date: Fri, 20 Sep 2024 10:15:04 +0200 Subject: [PATCH] replace encryptedMessageHash with messageHash --- packages/backend/src/storage.test.ts | 2 +- .../src/persistence/messages/createMessage.test.ts | 4 ++-- .../persistence/messages/deleteExpiredMessages.test.ts | 6 +++--- .../src/persistence/messages/syncAcknowledge.test.ts | 10 ++++------ .../src/persistence/messages/syncAcknowledge.ts | 2 +- packages/lib/messaging/src/Envelop.test.ts | 2 +- packages/lib/messaging/src/Envelop.ts | 8 +++++--- packages/lib/messaging/src/MessageProxy.test.ts | 4 ++-- packages/lib/messaging/src/ProxyEnvelop.test.ts | 4 ++-- .../lib/storage/src/new/chunkStorage/testHelper.ts | 2 +- .../storage/src/new/cloudStorage/getCloudStorage.ts | 7 +++---- .../src/components/DeleteMessage/DeleteMessage.tsx | 2 +- .../src/components/EmojiModal/EmojiModal.tsx | 3 +-- .../src/components/Message/Message.tsx | 2 +- .../src/components/Message/MessageReactions.tsx | 2 +- .../src/components/Message/ReplyMessagePreview.tsx | 3 +-- .../src/components/MessageAction/MessageAction.tsx | 9 ++++----- .../src/components/SendMessage/onSubmitMessage.ts | 4 ++-- .../src/hooks/messages/receipt/ReceiptDispatcher.ts | 4 ++-- .../messages/renderer/messageTypes/renderDelete.ts | 2 +- .../messages/renderer/messageTypes/renderDuplicates.ts | 4 ++-- .../hooks/messages/renderer/messageTypes/renderEdit.ts | 2 +- .../messages/renderer/messageTypes/renderReactions.ts | 2 +- .../messages/renderer/messageTypes/renderReadOpened.ts | 2 +- .../renderer/messageTypes/renderReadReceived.ts | 2 +- .../messages/renderer/messageTypes/renderReply.ts | 2 +- .../src/hooks/messages/renderer/renderMessage.ts | 1 - .../sources/handleMessagesFromDeliveryService.ts | 3 +-- .../messages/sources/handleMessagesFromWebSocket.ts | 4 ++-- .../src/hooks/messages/useMessage.test.tsx | 6 +++--- .../messenger-widget/src/hooks/messages/useMessage.tsx | 8 ++++---- test-data/encrypted-envelops.test.ts | 4 ++-- 32 files changed, 58 insertions(+), 64 deletions(-) diff --git a/packages/backend/src/storage.test.ts b/packages/backend/src/storage.test.ts index 42c128aec..a4cbe7a9a 100644 --- a/packages/backend/src/storage.test.ts +++ b/packages/backend/src/storage.test.ts @@ -1007,7 +1007,7 @@ describe('Storage', () => { .send({ encryptedEnvelopContainer: JSON.stringify(envelop1), encryptedContactName: sha256(receiver.account.ensName), - messageId: envelop1.metadata.encryptedMessageHash, + messageId: envelop1.metadata.messageHash, createdAt: 1, isHalted: true, }); diff --git a/packages/delivery-service/src/persistence/messages/createMessage.test.ts b/packages/delivery-service/src/persistence/messages/createMessage.test.ts index 3c9d43556..997fe2ee6 100644 --- a/packages/delivery-service/src/persistence/messages/createMessage.test.ts +++ b/packages/delivery-service/src/persistence/messages/createMessage.test.ts @@ -36,7 +36,7 @@ describe('Create Message', () => { metadata: { deliveryInformation: '', signature: '', - encryptedMessageHash: '', + messageHash: '', version: '', encryptionScheme: 'x25519-chacha20-poly1305', }, @@ -64,7 +64,7 @@ describe('Create Message', () => { deliveryInstruction: '', }, signature: '', - encryptedMessageHash: '', + messageHash: '', version: '', encryptionScheme: 'x25519-chacha20-poly1305', }, diff --git a/packages/delivery-service/src/persistence/messages/deleteExpiredMessages.test.ts b/packages/delivery-service/src/persistence/messages/deleteExpiredMessages.test.ts index 71371ea7f..3b72bd2d9 100644 --- a/packages/delivery-service/src/persistence/messages/deleteExpiredMessages.test.ts +++ b/packages/delivery-service/src/persistence/messages/deleteExpiredMessages.test.ts @@ -29,7 +29,7 @@ describe('Delete Expired messages', () => { metadata: { deliveryInformation: '', signature: '', - encryptedMessageHash: '', + messageHash: '', version: '', encryptionScheme: 'x25519-chacha20-poly1305', }, @@ -44,7 +44,7 @@ describe('Delete Expired messages', () => { metadata: { deliveryInformation: '', signature: '', - encryptedMessageHash: '', + messageHash: '', version: '', encryptionScheme: 'x25519-chacha20-poly1305', }, @@ -60,7 +60,7 @@ describe('Delete Expired messages', () => { metadata: { deliveryInformation: '', signature: '', - encryptedMessageHash: '', + messageHash: '', version: '', encryptionScheme: 'x25519-chacha20-poly1305', }, diff --git a/packages/delivery-service/src/persistence/messages/syncAcknowledge.test.ts b/packages/delivery-service/src/persistence/messages/syncAcknowledge.test.ts index d317d9ff8..55699d00e 100644 --- a/packages/delivery-service/src/persistence/messages/syncAcknowledge.test.ts +++ b/packages/delivery-service/src/persistence/messages/syncAcknowledge.test.ts @@ -36,7 +36,7 @@ describe('Sync Acknowledge', () => { from: SENDER_ADDRESS, }, signature: '', - encryptedMessageHash: '0x123', + messageHash: '0x123', version: '', encryptionScheme: 'x25519-chacha20-poly1305', }, @@ -49,7 +49,7 @@ describe('Sync Acknowledge', () => { from: SENDER_ADDRESS, }, signature: '', - encryptedMessageHash: '0x456', + messageHash: '0x456', version: '', encryptionScheme: 'x25519-chacha20-poly1305', }, @@ -84,9 +84,7 @@ describe('Sync Acknowledge', () => { ); expect(afterSyncAcknowledge.length).toBe(1); - expect(afterSyncAcknowledge[0].metadata.encryptedMessageHash).toBe( - '0x456', - ); + expect(afterSyncAcknowledge[0].metadata.messageHash).toBe('0x456'); }); it('returns false if message is not found', async () => { const envelop1: EncryptionEnvelop = { @@ -97,7 +95,7 @@ describe('Sync Acknowledge', () => { from: SENDER_ADDRESS, }, signature: '', - encryptedMessageHash: '0x123', + messageHash: '0x123', version: '', encryptionScheme: 'x25519-chacha20-poly1305', }, diff --git a/packages/delivery-service/src/persistence/messages/syncAcknowledge.ts b/packages/delivery-service/src/persistence/messages/syncAcknowledge.ts index be740eb2b..2df6648d1 100644 --- a/packages/delivery-service/src/persistence/messages/syncAcknowledge.ts +++ b/packages/delivery-service/src/persistence/messages/syncAcknowledge.ts @@ -22,7 +22,7 @@ export function syncAcknowledge(redis: Redis) { //find the message with the given hash const message = messages.find( - (m) => m.metadata.encryptedMessageHash === messageHash, + (m) => m.metadata.messageHash === messageHash, ); //return if the message is not found diff --git a/packages/lib/messaging/src/Envelop.test.ts b/packages/lib/messaging/src/Envelop.test.ts index b5f48d3c9..e9f795583 100644 --- a/packages/lib/messaging/src/Envelop.test.ts +++ b/packages/lib/messaging/src/Envelop.test.ts @@ -141,7 +141,7 @@ describe('Envelope', () => { from: '', to: '', }, - encryptedMessageHash: + messageHash: '0xc3428898a18e2cdb914e7eec870e45348c7f401d094968408524b787b43451d0', version: 'v1', signature: diff --git a/packages/lib/messaging/src/Envelop.ts b/packages/lib/messaging/src/Envelop.ts index 1818ef44a..46fc629f9 100644 --- a/packages/lib/messaging/src/Envelop.ts +++ b/packages/lib/messaging/src/Envelop.ts @@ -20,7 +20,7 @@ export interface EnvelopeMetadata { version: string; encryptionScheme?: string; deliveryInformation: string | DeliveryInformation; - encryptedMessageHash: string; + messageHash: string; signature: string; } @@ -141,7 +141,7 @@ export async function buildEnvelop( /** * Builds the {@see EnvelopMetadata} for the message * and encrypts the {@see DeliveryInformation} using the deliveryServiceEncryptionPubKey - * the encryptedMessageHash field is mendatory to establish a link between the message and metadata + * the messageHash field is mendatory to establish a link between the message and metadata */ const envelopeMetadata: Omit = { encryptionScheme: 'x25519-chacha20-poly1305', @@ -151,7 +151,9 @@ export async function buildEnvelop( stringify(deliveryInformation), ), ), - encryptedMessageHash: sha256(stringify(encryptedMessage)), + //Even though the fields name is messageHash we hash the message to be able to find message duplicates + //For examples messages comming from the same DS + messageHash: sha256(stringify(message)), version: 'v1', }; diff --git a/packages/lib/messaging/src/MessageProxy.test.ts b/packages/lib/messaging/src/MessageProxy.test.ts index 0e7ab9ad3..1a0446f89 100644 --- a/packages/lib/messaging/src/MessageProxy.test.ts +++ b/packages/lib/messaging/src/MessageProxy.test.ts @@ -17,7 +17,7 @@ const proxyEnvelop = { encryptionEnvelop: { metadata: { deliveryInformation: stringify(encryptedPayloadMock), - encryptedMessageHash: + messageHash: '0xdac53d80a308eb9a48caca48719aada24a32f1cede2f4368817aa63b1375a09f', encryptionScheme: 'x25519-chacha20-poly1305', signature: @@ -31,7 +31,7 @@ const proxyEnvelop = { encryptionEnvelop: { metadata: { deliveryInformation: stringify(encryptedPayloadMock), - encryptedMessageHash: + messageHash: '0xdac53d80a308eb9a48caca48719aada24a32f1cede2f4368817aa63b1375a09f', encryptionScheme: 'x25519-chacha20-poly1305', signature: diff --git a/packages/lib/messaging/src/ProxyEnvelop.test.ts b/packages/lib/messaging/src/ProxyEnvelop.test.ts index 8f6ac5db7..c39f4a0f3 100644 --- a/packages/lib/messaging/src/ProxyEnvelop.test.ts +++ b/packages/lib/messaging/src/ProxyEnvelop.test.ts @@ -118,13 +118,13 @@ describe('ProxyEnvelope', () => { delete proxyEnvelop.encryptionEnvelops[0].encryptionEnvelop.metadata .signature; delete proxyEnvelop.encryptionEnvelops[0].encryptionEnvelop.metadata - .encryptedMessageHash; + .messageHash; delete proxyEnvelop.encryptionEnvelops[1].encryptionEnvelop.metadata .deliveryInformation; delete proxyEnvelop.encryptionEnvelops[1].encryptionEnvelop.metadata .signature; delete proxyEnvelop.encryptionEnvelops[1].encryptionEnvelop.metadata - .encryptedMessageHash; + .messageHash; expect(proxyEnvelop).toStrictEqual({ encryptionEnvelops: [ diff --git a/packages/lib/storage/src/new/chunkStorage/testHelper.ts b/packages/lib/storage/src/new/chunkStorage/testHelper.ts index 60a77ae98..1f988378e 100644 --- a/packages/lib/storage/src/new/chunkStorage/testHelper.ts +++ b/packages/lib/storage/src/new/chunkStorage/testHelper.ts @@ -33,7 +33,7 @@ export function makeEnvelop( to: '', deliveryInstruction: '', }, - encryptedMessageHash: '', + messageHash: '', version: '', encryptionScheme: '', signature: '', diff --git a/packages/lib/storage/src/new/cloudStorage/getCloudStorage.ts b/packages/lib/storage/src/new/cloudStorage/getCloudStorage.ts index ff7c0fde6..619d785e7 100644 --- a/packages/lib/storage/src/new/cloudStorage/getCloudStorage.ts +++ b/packages/lib/storage/src/new/cloudStorage/getCloudStorage.ts @@ -147,8 +147,7 @@ export const getCloudStorage = ( await backendConnector.addMessage( ensName, encryptedContactName, - envelop.envelop.metadata?.encryptedMessageHash! ?? - envelop.envelop.id, + envelop.envelop.metadata?.messageHash! ?? envelop.envelop.id, createdAt, encryptedEnvelopContainer, isHalted, @@ -178,7 +177,7 @@ export const getCloudStorage = ( createdAt, messageId: storageEnvelopContainer.envelop.metadata - ?.encryptedMessageHash! ?? + ?.messageHash! ?? storageEnvelopContainer.envelop.id, isHalted: false, }; @@ -215,7 +214,7 @@ export const getCloudStorage = ( encryptedEnvelopContainer, messageId: storageEnvelopContainer.envelop.metadata - ?.encryptedMessageHash!, + ?.messageHash!, createdAt, isHalted: false, }; diff --git a/packages/messenger-widget/src/components/DeleteMessage/DeleteMessage.tsx b/packages/messenger-widget/src/components/DeleteMessage/DeleteMessage.tsx index 8554153e5..e2854dd8c 100644 --- a/packages/messenger-widget/src/components/DeleteMessage/DeleteMessage.tsx +++ b/packages/messenger-widget/src/components/DeleteMessage/DeleteMessage.tsx @@ -32,7 +32,7 @@ export default function DeleteMessage() { } const messageHash = - messageView.messageData?.envelop.metadata?.encryptedMessageHash; + messageView.messageData?.envelop.metadata?.messageHash; setMessageView(resetMessageView); diff --git a/packages/messenger-widget/src/components/EmojiModal/EmojiModal.tsx b/packages/messenger-widget/src/components/EmojiModal/EmojiModal.tsx index 0bb216673..963e28df3 100644 --- a/packages/messenger-widget/src/components/EmojiModal/EmojiModal.tsx +++ b/packages/messenger-widget/src/components/EmojiModal/EmojiModal.tsx @@ -76,8 +76,7 @@ export function EmojiModal(props: EmojiProps) { messageData: undefined, }); - const referenceMessageHash = - props.envelop.metadata?.encryptedMessageHash; + const referenceMessageHash = props.envelop.metadata?.messageHash; // react to the message const messageData = await createReactionMessage( diff --git a/packages/messenger-widget/src/components/Message/Message.tsx b/packages/messenger-widget/src/components/Message/Message.tsx index 6481909fa..45d635daa 100644 --- a/packages/messenger-widget/src/components/Message/Message.tsx +++ b/packages/messenger-widget/src/components/Message/Message.tsx @@ -19,7 +19,7 @@ export function Message(props: MessageProps) { return ( scrollToMessage( - props.replyToMessageEnvelop?.metadata - ?.encryptedMessageHash!, + props.replyToMessageEnvelop?.metadata?.messageHash!, ) } > diff --git a/packages/messenger-widget/src/components/MessageAction/MessageAction.tsx b/packages/messenger-widget/src/components/MessageAction/MessageAction.tsx index 2a24d8ee8..3c62b4c7a 100644 --- a/packages/messenger-widget/src/components/MessageAction/MessageAction.tsx +++ b/packages/messenger-widget/src/components/MessageAction/MessageAction.tsx @@ -75,8 +75,7 @@ export function MessageAction(props: MessageProps) { messageData: undefined, }); - const referenceMessageHash = - props.envelop.metadata?.encryptedMessageHash; + const referenceMessageHash = props.envelop.metadata?.messageHash; // react to the message const messageData = await createReactionMessage( @@ -157,7 +156,7 @@ export function MessageAction(props: MessageProps) { (props.message || (props.envelop.message.attachments && props.envelop.message.attachments.length > 0)) && - props.envelop.metadata?.encryptedMessageHash && + props.envelop.metadata?.messageHash && (!props.hideFunction || !props.hideFunction.split(',').includes('edit')) && (
0)) && - props.envelop.metadata?.encryptedMessageHash && ( + props.envelop.metadata?.messageHash && (
{ .map((message) => { if ( toBeDeletedByMessageHash.includes( - message.envelop.metadata?.encryptedMessageHash, + message.envelop.metadata?.messageHash, ) ) { return { diff --git a/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderDuplicates.ts b/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderDuplicates.ts index 16179f645..769050c93 100644 --- a/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderDuplicates.ts +++ b/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderDuplicates.ts @@ -7,8 +7,8 @@ export const renderDuplicates = (messages: MessageModel[]) => { index === self.findIndex( (t) => - t.envelop.metadata?.encryptedMessageHash === - message.envelop.metadata?.encryptedMessageHash, + t.envelop.metadata?.messageHash === + message.envelop.metadata?.messageHash, ), ); }; diff --git a/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderEdit.ts b/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderEdit.ts index 4b118e1a9..4df174d69 100644 --- a/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderEdit.ts +++ b/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderEdit.ts @@ -32,7 +32,7 @@ export const renderEdit = (_messages: MessageModel[]) => { while (currentMsg.envelop.message.metadata.type === 'EDIT') { const originalMsg = messages.find( (m, i) => - m.envelop.metadata?.encryptedMessageHash === + m.envelop.metadata?.messageHash === currentMsg.envelop.message.metadata.referenceMessageHash, ); if (!originalMsg) { diff --git a/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReactions.ts b/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReactions.ts index cb54f878c..d6f7c4646 100644 --- a/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReactions.ts +++ b/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReactions.ts @@ -16,7 +16,7 @@ export const renderReactions = (messages: MessageModel[]) => { .filter( (reaction) => reaction.message.metadata.referenceMessageHash === - message.envelop.metadata?.encryptedMessageHash, + message.envelop.metadata?.messageHash, ) //Filter duplicates, we only want to display a reaction once //I.e if there are ten messages from type ❤️ we only want to display one ❤️ diff --git a/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReadOpened.ts b/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReadOpened.ts index 7409a2cc0..c729c204e 100644 --- a/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReadOpened.ts +++ b/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReadOpened.ts @@ -15,7 +15,7 @@ export const renderReadOpened = (messages: MessageModel[]) => { const openedMsg = readOpenedMsgs.find( (m) => m.envelop.message.metadata.referenceMessageHash === - message.envelop.metadata?.encryptedMessageHash, + message.envelop.metadata?.messageHash, ); return { ...message, diff --git a/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReadReceived.ts b/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReadReceived.ts index 1a0b4c79c..9d9f81d4a 100644 --- a/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReadReceived.ts +++ b/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReadReceived.ts @@ -15,7 +15,7 @@ export const renderReadReceived = (messages: MessageModel[]) => { const receivedMsg = readReceivedMsgs.find( (m) => m.envelop.message.metadata.referenceMessageHash === - message.envelop.metadata?.encryptedMessageHash, + message.envelop.metadata?.messageHash, ); return { ...message, diff --git a/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReply.ts b/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReply.ts index 443b164a1..6ce8b3305 100644 --- a/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReply.ts +++ b/packages/messenger-widget/src/hooks/messages/renderer/messageTypes/renderReply.ts @@ -6,7 +6,7 @@ export const renderReply = (messages: MessageModel[]) => { //TODO we've to figure out how to get a message from a different chunk (Alex) const replyToMessageEnvelop = messages.find( (m) => - m.envelop.metadata?.encryptedMessageHash === + m.envelop.metadata?.messageHash === message.envelop.message.metadata.referenceMessageHash, ); return { diff --git a/packages/messenger-widget/src/hooks/messages/renderer/renderMessage.ts b/packages/messenger-widget/src/hooks/messages/renderer/renderMessage.ts index 9f011e667..96b3966f3 100644 --- a/packages/messenger-widget/src/hooks/messages/renderer/renderMessage.ts +++ b/packages/messenger-widget/src/hooks/messages/renderer/renderMessage.ts @@ -19,7 +19,6 @@ export const renderMessage = (messages: MessageModel[]) => { const withDeletes = renderDelete(withReadOpened); const withReactions = renderReactions(withDeletes); const withReply = renderReply(withReactions); - const withReplyC = renderReply(withReactions); const withoutEdited = renderEdit(withReply); //Sort the messages by timestamp DESC to show them in the right order diff --git a/packages/messenger-widget/src/hooks/messages/sources/handleMessagesFromDeliveryService.ts b/packages/messenger-widget/src/hooks/messages/sources/handleMessagesFromDeliveryService.ts index 42d584398..1c9003f84 100644 --- a/packages/messenger-widget/src/hooks/messages/sources/handleMessagesFromDeliveryService.ts +++ b/packages/messenger-widget/src/hooks/messages/sources/handleMessagesFromDeliveryService.ts @@ -147,8 +147,7 @@ export const handleMessagesFromDeliveryService = async ( //Here we use the TLD name because the delivery service uses the TLD name to identify the contact //We cannot just use teh messageId because redis prevents us from finding messages by ID contactAddress: conversation.tldName, - messageHash: - message.envelop.metadata?.encryptedMessageHash!, + messageHash: message.envelop.metadata?.messageHash!, }), ); //sync acknowledgements with the delivery serviceƒƒ diff --git a/packages/messenger-widget/src/hooks/messages/sources/handleMessagesFromWebSocket.ts b/packages/messenger-widget/src/hooks/messages/sources/handleMessagesFromWebSocket.ts index 9b0f67001..a067f9a31 100644 --- a/packages/messenger-widget/src/hooks/messages/sources/handleMessagesFromWebSocket.ts +++ b/packages/messenger-widget/src/hooks/messages/sources/handleMessagesFromWebSocket.ts @@ -63,8 +63,8 @@ export const handleMessagesFromWebSocket = async ( if ( prev[contact]?.find( (m) => - m.envelop.metadata?.encryptedMessageHash === - messageModel.envelop.metadata?.encryptedMessageHash, + m.envelop.metadata?.messageHash === + messageModel.envelop.metadata?.messageHash, ) ) { return prev; diff --git a/packages/messenger-widget/src/hooks/messages/useMessage.test.tsx b/packages/messenger-widget/src/hooks/messages/useMessage.test.tsx index dc07a014a..e97806b25 100644 --- a/packages/messenger-widget/src/hooks/messages/useMessage.test.tsx +++ b/packages/messenger-widget/src/hooks/messages/useMessage.test.tsx @@ -742,15 +742,15 @@ describe('useMessage hook test cases', () => { [ { contactAddress: sender.account.ensName, - messageHash: message1.metadata.encryptedMessageHash, + messageHash: message1.metadata.messageHash, }, { contactAddress: sender.account.ensName, - messageHash: message2.metadata.encryptedMessageHash, + messageHash: message2.metadata.messageHash, }, { contactAddress: sender.account.ensName, - messageHash: message3.metadata.encryptedMessageHash, + messageHash: message3.metadata.messageHash, }, ], ); diff --git a/packages/messenger-widget/src/hooks/messages/useMessage.tsx b/packages/messenger-widget/src/hooks/messages/useMessage.tsx index c173c633b..63e007c93 100644 --- a/packages/messenger-widget/src/hooks/messages/useMessage.tsx +++ b/packages/messenger-widget/src/hooks/messages/useMessage.tsx @@ -325,7 +325,7 @@ export const useMessage = () => { deliveryInformation: '', //Because storing a message is always an internal process we dont need to sign it. The signature is only needed for the delivery service signature: '', - encryptedMessageHash: sha256(stringify(message)), + messageHash: sha256(stringify(message)), version: 'v1', }, }, @@ -489,15 +489,15 @@ export const useMessage = () => { newMessages //filter duplicates .filter((message, index, self) => { - if (!message.envelop.metadata?.encryptedMessageHash) { + if (!message.envelop.metadata?.messageHash) { return true; } return ( index === self.findIndex( (m) => - m.envelop.metadata?.encryptedMessageHash === - message.envelop.metadata?.encryptedMessageHash, + m.envelop.metadata?.messageHash === + message.envelop.metadata?.messageHash, ) ); }); diff --git a/test-data/encrypted-envelops.test.ts b/test-data/encrypted-envelops.test.ts index 8c54f248a..e2b907d89 100644 --- a/test-data/encrypted-envelops.test.ts +++ b/test-data/encrypted-envelops.test.ts @@ -8,7 +8,7 @@ export const testData = { deliveryInformation: '{"ciphertext":"mSTXIS7LCebwZgxz+XtqtB3bobDQpfnh6jah3ciJ+H87c0D4HIQtumCmRssGhSAoMOG0MkYIYEeFw976MgvJNmyxMB4B60hL3z2F9fm+uNyhENlPhO+6ol8VVXSS8SiQObvqhnSk4p8Gqi5nF1lYZGz5c9+TSm9rccePxzyMzHHmI8r7+qs94JGB9FhKUxxW3rsMcfIAoq+SoAXp8flGTpwqSgK72u/7skb/LhyDwdMoIjYk5cu0I4+xEAw1VqllhsllbGmB5zAVHLrhDKaBH2lclMXgbN7ovQLLepfYpRZFE94AuuZowa/CQ3kHwbqTBtR8xYjDKkU7VpcpQTsWcLCBRdT8rBx9PL469JJ/viF4xOuDcHEMT9GrDVwbWOVgN52X/+7X2dk5Z0lQw9Q+ZsruL501Yo/fFMfFzNjtfe3GyMKEtU0mwMBYN4VTXZAh6ziPNf2lqv0O4QYTW2XcNhYNw1BLuCXiI5OHF0CPMHgaNP70RuCmGBs3Orml2wfNrGkxGVDMLWubbSmqNmmZjWflqLyXdlc79yZgkEtPq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+5yXHe6WrCuQ+5SEB259HmGNJPI6U4apU4kMfa/EZ9GaAfBHG","nonce":"0x5f564ab2e955e921e131621e","ephemPublicKey":"yhl5dtz+xbvMczZtysmFiQ5Mi30cJcitqiz33cIAPy4="}', signature: '', - encryptedMessageHash: '', + messageHash: '', version: '', encryptionScheme: 'x25519-chacha20-poly1305', }, @@ -19,7 +19,7 @@ export const testData = { deliveryInformation: '{"ciphertext":"TR8l/5eOwKzsrED5+pUzVHhXtqnsmpZ71kBsONzcnb5XGnBUtMH+TX5lfgKcNVTIgdji6QXVjy1MPMQgOMfLoQEGGZ4Z7+oTVNwdOztjOEDJ0oETTtpj/ZNZ57PXdNj2g82CA3cTU/V1USSHTTxuDNsvvFhr+WYnlL/NewZMAVmSgKgdIEEgp6RIm+eUAVuZlqUHDZu/BSc9WRKyznaXL48ziR0cKhV8rIo5cBve2C5FTRO1fsIPPYc57c+8iSTvON5stjIV0WbCQjOuCoO6L66+1RsaROCW1IFyZfPOcI2K3KfGuxIJISAtle4XWKFcGmpEuLwZIgudqh6eLXD/bfP3MSTGsJBMSWHjesHqqvokldA9n1REo6DzR3SG8EaLQCWFGIKXVhVkjyNBoyRituY8iVrWxCcx4wrL5PbsurOOhiS2Rd6YZQMiyVMm7pjnnAB4oRF3fHhTwMIUg5GwlQhybMpTOJ3db11kCZYAM+LiTX4JHG8B78xOjWDLq5S0IT43jxE0q9Dn/WklN3xCB7YrX4HMLkz/qXBg02A6n54SL4S+6F43I87B5wKVOTzT+WzUcSnXAxFsn1oqgN1YhyVy8J3GHUEQoe6GeFtyv2sCXExEPeoOuHc0gVnbmz5m3dErT5a9CJxlGRLO89y2vLRaOtAG9Ax64zSle3uXPwnKYhQODMhbaTw1LjenM3ABMzDyW2VOp1rGZO3xlf/rX3cfoNB9xjjpyrfLalmdgf93tW4Zw/frefiJAas8lNSit0xly1wrfUrD81+ppx+yk4crmVi7PvRlDyXzfa8qkIxp5MEjdNYjdu3adVryqYi72/ztp9zniQVLx0iy6q1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qDsxe4a5LrrEqUTiKvcdfugLNWT94aj+8k4eijKlPuMJ1H1nfqgbit0F9h9EpiH3gYDO/El5lDE85Uiil7c6b7qIWILSv5vsVMvmRZjWgdF85L5I+OrIH4918qPhONDIswBQPwHFcbyAuNqpUagY3xN6DcGCPNqfOSaQlEfHaHxQbCkgvJkghl1Qm3GuKcvDKd6X3nWK4kA9NHNWX//02CgDYki70f/uRS/x2uk9wV6+33Cq27X0xzmH0MT0o8eI3cbQAIcLwJR030qfmPNs6fWMMNJFPuzHaEXTesKCUhHhbfTdf1M3zZPRXxU7F8Yv9IytfWZ35fxAbdIkgYmA+EtVBNHaNB75C479fkyOTBmHq5JkV4mPFZ61kwb+eMy9h/NC+5bhL1APrQdOWNSCmBmddLnuejTmEAlynF3ZUNPL6g8h6ktFNVDbXuPQtjIdRXZmlY/ruZRMhqDdAJ+BzDYXogeyGiJM9o4HPnpU3tO1yKcQdFcKoKPLifHIKbelV6UPHaiA8fFeMDwGwFsT045GWeMp/0fvrK5ZeuqGl+SCLfgyN9IS4Li2Ntjue9X4ChOyfbMnR54IpGQ97KGRjmvKtD80qd6wHWbY8MRGkrp7Elqdc9c1o1Q1sF0Sx4x0Am1wneqZc2kkL7xVSHaXHKN44sM1E6qpDzFBxIMgm4IiuBY1Tf7xEbJReX5B9LvYEvunjouuzPQ1qbtbRLcagRfZoimIpxAsE0nth6wYmSZshr9jGEmWIo4mEC9u6DcjN3VACPc7Rvk0gcl5Dssf61ph7EVQ+SND6KF9KOklyfJEcMwNyVvOrizWVaj5o","nonce":"0x55d8d963b4712d3b74a1c3f7","ephemPublicKey":"JswCtQ84+mfSYSE8+MzzUsjYG4aSZIBZIvA0IIvUGn4="}', signature: '', - encryptedMessageHash: '', + messageHash: '', version: '', encryptionScheme: 'x25519-chacha20-poly1305', },