Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix 1174.1 #1176

Merged
merged 18 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/dm3-backend",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ export const addMessageBatch =
account.id,
encryptedContactName,
);

const uniqueMessageBatch = messageBatch.filter(
(message, index, self) =>
index ===
self.findIndex((m) => m.messageId === message.messageId),
);

//store each message in the db
const createMessagePromises = messageBatch.map(
const createMessagePromises = uniqueMessageBatch.map(
({
messageId,
createdAt,
Expand Down
71 changes: 70 additions & 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 Expand Up @@ -1146,6 +1146,75 @@ describe('Storage', () => {
expect(body[0].contact).toEqual(sha256(receiver.account.ensName));
expect(body.length).toBe(1);

const { status: getMessagesStatus, body: messages } = await request(
app,
)
.get(
`/new/bob.eth/getMessages/${sha256(
receiver.account.ensName,
)}`,
)
.set({
authorization: 'Bearer ' + token,
})
.send();

expect(getMessagesStatus).toBe(200);
expect(messages.length).toBe(2);
expect(
JSON.parse(JSON.parse(messages[0]).encryptedEnvelopContainer),
).toStrictEqual(envelop);
});
it('if batch contains duplicates it only creates the message once', async () => {
const messageFactory = MockMessageFactory(
sender,
receiver,
deliveryService,
);
const envelop = await messageFactory.createEncryptedEnvelop(
'Hello1',
);
const { status } = await request(app)
.post(`/new/bob.eth/addMessageBatch`)
.set({
authorization: 'Bearer ' + token,
})
.send({
encryptedContactName: sha256(receiver.account.ensName),
messageBatch: [
{
encryptedEnvelopContainer: JSON.stringify(envelop),
messageId: '123',
createdAt: 1,
isHalted: false,
},
{
encryptedEnvelopContainer: JSON.stringify(envelop),
messageId: '123',
createdAt: 1,
isHalted: false,
},
{
encryptedEnvelopContainer: JSON.stringify(envelop),
messageId: '456',
createdAt: 2,
isHalted: false,
},
],
});
expect(status).toBe(200);

const { body } = await request(app)
.get(`/new/bob.eth/getConversations`)
.set({
authorization: 'Bearer ' + token,
})
.send();

expect(status).toBe(200);
expect(body[0].contact).toEqual(sha256(receiver.account.ensName));
expect(body.length).toBe(1);

const { status: getMessagesStatus, body: messages } = await request(
app,
)
Expand Down
2 changes: 1 addition & 1 deletion packages/billboard-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/dm3-billboard-client",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"private": true,
"main": "dist/index.js",
"types": "dist/ined.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/billboard-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/dm3-billboard-widget",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/delivery-service/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/delivery-service",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"dependencies": {
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/integration-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/dm3-integration-tests",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"dependencies": {
"@dm3-org/dm3-lib-delivery": "workspace:^",
"@dm3-org/dm3-lib-messaging": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/billboard-api/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/dm3-lib-billboard-client-api",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/crypto/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/dm3-lib-crypto",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"main": "dist/index.js",
"module": "dist-backend/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/delivery-api/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/dm3-lib-delivery-api",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/delivery/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/dm3-lib-delivery",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"main": "dist/index.js",
"module": "dist-backend/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/messaging/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/dm3-lib-messaging",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"main": "dist/index.js",
"module": "dist-backend/index.js",
"types": "dist/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions packages/lib/messaging/src/Envelop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ describe('Envelope', () => {
from: '',
to: '',
},
encryptedMessageHash:
'0xc3428898a18e2cdb914e7eec870e45348c7f401d094968408524b787b43451d0',
messageHash:
'0xf2f8e4e1301481b3d7f11127adc11f5f4cf5faa8261296501d7726206ba35a85',
version: 'v1',
signature:
'kKfGVNdGuZf5TrWa6ctQAuHwZQ8fSH36D4Hz+pxYA2UPNMNVZvWPwRmDjKEHMf3iWm8v/yh3BW7fwwk8ns4+AA==',
'sHQCkcuocwB7E9iy2hzyvl45020vFNgDfEV/dAKaMal98svGl7Gk8h0vcXxmhNwZt+rJ0j+Bc6sgpoeiIBjBCQ==',
},
});
});
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/offchain-resolver-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dm3-org/dm3-lib-offchain-resolver-api",
"version": "1.6.0",
"version": "1.6.1",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/profile/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/dm3-lib-profile",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"main": "dist/index.js",
"module": "dist-backend/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/server-side/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/dm3-lib-server-side",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"main": "dist/index.js",
"module": "dist-backend/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@dm3-org/dm3-lib-shared",
"license": "BSD-2-Clause",
"version": "1.6.0",
"version": "1.6.1",
"main": "dist/index.js",
"module": "dist-backend/index.js",
"types": "dist/index.d.ts",
Expand Down
Loading
Loading