Skip to content

Commit

Permalink
replace encryptedMessageHash with messageHash
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNi245 committed Sep 20, 2024
1 parent d4afd02 commit 6a48b78
Show file tree
Hide file tree
Showing 32 changed files with 58 additions and 64 deletions.
2 changes: 1 addition & 1 deletion packages/backend/src/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Create Message', () => {
metadata: {
deliveryInformation: '',
signature: '',
encryptedMessageHash: '',
messageHash: '',
version: '',
encryptionScheme: 'x25519-chacha20-poly1305',
},
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('Create Message', () => {
deliveryInstruction: '',
},
signature: '',
encryptedMessageHash: '',
messageHash: '',
version: '',
encryptionScheme: 'x25519-chacha20-poly1305',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Delete Expired messages', () => {
metadata: {
deliveryInformation: '',
signature: '',
encryptedMessageHash: '',
messageHash: '',
version: '',
encryptionScheme: 'x25519-chacha20-poly1305',
},
Expand All @@ -44,7 +44,7 @@ describe('Delete Expired messages', () => {
metadata: {
deliveryInformation: '',
signature: '',
encryptedMessageHash: '',
messageHash: '',
version: '',
encryptionScheme: 'x25519-chacha20-poly1305',
},
Expand All @@ -60,7 +60,7 @@ describe('Delete Expired messages', () => {
metadata: {
deliveryInformation: '',
signature: '',
encryptedMessageHash: '',
messageHash: '',
version: '',
encryptionScheme: 'x25519-chacha20-poly1305',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Sync Acknowledge', () => {
from: SENDER_ADDRESS,
},
signature: '',
encryptedMessageHash: '0x123',
messageHash: '0x123',
version: '',
encryptionScheme: 'x25519-chacha20-poly1305',
},
Expand All @@ -49,7 +49,7 @@ describe('Sync Acknowledge', () => {
from: SENDER_ADDRESS,
},
signature: '',
encryptedMessageHash: '0x456',
messageHash: '0x456',
version: '',
encryptionScheme: 'x25519-chacha20-poly1305',
},
Expand Down Expand Up @@ -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 = {
Expand All @@ -97,7 +95,7 @@ describe('Sync Acknowledge', () => {
from: SENDER_ADDRESS,
},
signature: '',
encryptedMessageHash: '0x123',
messageHash: '0x123',
version: '',
encryptionScheme: 'x25519-chacha20-poly1305',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/messaging/src/Envelop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('Envelope', () => {
from: '',
to: '',
},
encryptedMessageHash:
messageHash:
'0xc3428898a18e2cdb914e7eec870e45348c7f401d094968408524b787b43451d0',
version: 'v1',
signature:
Expand Down
8 changes: 5 additions & 3 deletions packages/lib/messaging/src/Envelop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface EnvelopeMetadata {
version: string;
encryptionScheme?: string;
deliveryInformation: string | DeliveryInformation;
encryptedMessageHash: string;
messageHash: string;
signature: string;
}

Expand Down Expand Up @@ -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<EnvelopeMetadata, 'signature'> = {
encryptionScheme: 'x25519-chacha20-poly1305',
Expand All @@ -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',
};

Expand Down
4 changes: 2 additions & 2 deletions packages/lib/messaging/src/MessageProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const proxyEnvelop = {
encryptionEnvelop: {
metadata: {
deliveryInformation: stringify(encryptedPayloadMock),
encryptedMessageHash:
messageHash:
'0xdac53d80a308eb9a48caca48719aada24a32f1cede2f4368817aa63b1375a09f',
encryptionScheme: 'x25519-chacha20-poly1305',
signature:
Expand All @@ -31,7 +31,7 @@ const proxyEnvelop = {
encryptionEnvelop: {
metadata: {
deliveryInformation: stringify(encryptedPayloadMock),
encryptedMessageHash:
messageHash:
'0xdac53d80a308eb9a48caca48719aada24a32f1cede2f4368817aa63b1375a09f',
encryptionScheme: 'x25519-chacha20-poly1305',
signature:
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/messaging/src/ProxyEnvelop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/storage/src/new/chunkStorage/testHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function makeEnvelop(
to: '',
deliveryInstruction: '',
},
encryptedMessageHash: '',
messageHash: '',
version: '',
encryptionScheme: '',
signature: '',
Expand Down
7 changes: 3 additions & 4 deletions packages/lib/storage/src/new/cloudStorage/getCloudStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -178,7 +177,7 @@ export const getCloudStorage = (
createdAt,
messageId:
storageEnvelopContainer.envelop.metadata
?.encryptedMessageHash! ??
?.messageHash! ??
storageEnvelopContainer.envelop.id,
isHalted: false,
};
Expand Down Expand Up @@ -215,7 +214,7 @@ export const getCloudStorage = (
encryptedEnvelopContainer,
messageId:
storageEnvelopContainer.envelop.metadata
?.encryptedMessageHash!,
?.messageHash!,
createdAt,
isHalted: false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function DeleteMessage() {
}

const messageHash =
messageView.messageData?.envelop.metadata?.encryptedMessageHash;
messageView.messageData?.envelop.metadata?.messageHash;

setMessageView(resetMessageView);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function Message(props: MessageProps) {

return (
<span
id={props.envelop.metadata?.encryptedMessageHash}
id={props.envelop.metadata?.messageHash}
className={'text-primary-color d-grid msg'.concat(
' ',
props.ownMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function MessageReactions(props: MessageProps) {
throw Error('no contact selected');
}

const messageHash = deleteEmojiData.metadata?.encryptedMessageHash;
const messageHash = deleteEmojiData.metadata?.messageHash;

setMessageView({
actionType: MessageActionType.NONE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export function ReplyMessagePreview(props: MessageProps) {
)}
onClick={() =>
scrollToMessage(
props.replyToMessageEnvelop?.metadata
?.encryptedMessageHash!,
props.replyToMessageEnvelop?.metadata?.messageHash!,
)
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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')) && (
<div
Expand All @@ -171,7 +170,7 @@ export function MessageAction(props: MessageProps) {
)}

{props.ownMessage &&
props.envelop.metadata?.encryptedMessageHash &&
props.envelop.metadata?.messageHash &&
(!props.hideFunction ||
!props.hideFunction.split(',').includes('delete')) && (
<div
Expand Down Expand Up @@ -225,7 +224,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 && (
<div
data-testid="reply-msg"
className="d-flex align-items-center justify-content-start"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const onSubmitMessage = async (
}
if (messageView.actionType === MessageActionType.REPLY) {
const referenceMessageHash =
messageView.messageData?.envelop.metadata?.encryptedMessageHash;
messageView.messageData?.envelop.metadata?.messageHash;

const messageData = await createReplyMessage(
selectedContact?.contactDetails.account.ensName!,
Expand Down Expand Up @@ -67,7 +67,7 @@ export const onSubmitMessage = async (
}
if (messageView.actionType === MessageActionType.EDIT) {
const referenceMessageHash =
messageView.messageData?.envelop.metadata?.encryptedMessageHash;
messageView.messageData?.envelop.metadata?.messageHash;

// reply to the original message
const messageData = await createEditMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class ReceiptDispatcher {
this.account!.ensName,
'READ_OPENED',
this.profileKeys?.signingKeyPair.privateKey!,
messageModel.envelop.metadata?.encryptedMessageHash as string,
messageModel.envelop.metadata?.messageHash as string,
);

//add the message to dispatch it via useMessage hook
Expand All @@ -47,7 +47,7 @@ export class ReceiptDispatcher {
this.account!.ensName,
'READ_RECEIVED',
this.profileKeys?.signingKeyPair.privateKey!,
messageModel.envelop.metadata?.encryptedMessageHash as string,
messageModel.envelop.metadata?.messageHash as string,
);

//add the message to dispatch it via useMessage hook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const renderDelete = (messages: MessageModel[]) => {
.map((message) => {
if (
toBeDeletedByMessageHash.includes(
message.envelop.metadata?.encryptedMessageHash,
message.envelop.metadata?.messageHash,
)
) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ❤️
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 6a48b78

Please sign in to comment.