@wireapp/core 30.8.0 → 30.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [30.10.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@30.9.0...@wireapp/core@30.10.0) (2022-09-15)
7
+
8
+
9
+ ### Features
10
+
11
+ * Queue message sending [FS-882] ([#4392](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4392)) ([3b29dd0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/3b29dd012ebd41debcea3460c6e0fffa2da3646e))
12
+
13
+
14
+
15
+
16
+
17
+ # [30.9.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@30.8.0...@wireapp/core@30.9.0) (2022-09-15)
18
+
19
+
20
+ ### Features
21
+
22
+ * use localstorage for keys update date ([#4396](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4396)) ([cce74a3](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/cce74a3a8f403be8d658618a8684c397ab060df3))
23
+
24
+
25
+
26
+
27
+
6
28
  # [30.8.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@30.7.2...@wireapp/core@30.8.0) (2022-09-14)
7
29
 
8
30
 
package/package.json CHANGED
@@ -10,6 +10,7 @@
10
10
  "@wireapp/commons": "4.3.0",
11
11
  "@wireapp/core-crypto": "0.4.0",
12
12
  "@wireapp/cryptobox": "12.8.0",
13
+ "@wireapp/promise-queue": "1.1.1",
13
14
  "@wireapp/store-engine-dexie": "1.6.10",
14
15
  "bazinga64": "5.10.0",
15
16
  "hash.js": "1.1.7",
@@ -77,6 +78,6 @@
77
78
  "test:node": "nyc jasmine --config=jasmine.json",
78
79
  "watch": "tsc ---watch"
79
80
  },
80
- "version": "30.8.0",
81
- "gitHead": "908930586bdf08bdb150a1092084ab36f80fbb64"
81
+ "version": "30.10.0",
82
+ "gitHead": "4baf6f355f55532d2a59967ac81f72a81f36e25b"
82
83
  }
@@ -73,6 +73,7 @@ const linkPreview_1 = require("./linkPreview");
73
73
  const encryptedStore_1 = require("./util/encryptedStore");
74
74
  const bazinga64_1 = require("bazinga64");
75
75
  const mls_1 = require("./mls");
76
+ const messageSender_1 = require("./conversation/message/messageSender");
76
77
  var TOPIC;
77
78
  (function (TOPIC) {
78
79
  TOPIC["ERROR"] = "Account.TOPIC.ERROR";
@@ -402,6 +403,9 @@ class Account extends events_1.EventEmitter {
402
403
  }, onMissedNotifications, abortHandler);
403
404
  // We can now unlock the websocket and let the new messages being handled and decrypted
404
405
  this.apiClient.transport.ws.unlock();
406
+ // We need to wait for the notification stream to be fully handled before releasing the message sending queue.
407
+ // This is due to the nature of how message are encrypted, any change in mls epoch needs to happen before we start encrypting any kind of messages
408
+ (0, messageSender_1.resumeMessageSending)();
405
409
  onConnected();
406
410
  };
407
411
  await this.apiClient.connect(onBeforeConnect);
@@ -32,6 +32,7 @@ const ConversationService_types_1 = require("./ConversationService.types");
32
32
  const bazinga64_1 = require("bazinga64");
33
33
  const mapQualifiedUserClientIdsToFullyQualifiedClientIds_1 = require("../../util/mapQualifiedUserClientIdsToFullyQualifiedClientIds");
34
34
  const mls_1 = require("../../mls");
35
+ const messageSender_1 = require("../message/messageSender");
35
36
  class ConversationService {
36
37
  constructor(apiClient, cryptographyService, config, notificationService, mlsService) {
37
38
  this.apiClient = apiClient;
@@ -716,9 +717,9 @@ class ConversationService {
716
717
  // If the onStart call returns false, it means the consumer wants to cancel the message sending
717
718
  return Object.assign(Object.assign({}, payload), { state: conversation_2.PayloadBundleState.CANCELLED });
718
719
  }
719
- return isMLS(params)
720
+ return (0, messageSender_1.sendMessage)(() => isMLS(params)
720
721
  ? this.sendMLSMessage(params, genericMessage, content)
721
- : this.sendProteusMessage(params, genericMessage, content);
722
+ : this.sendProteusMessage(params, genericMessage, content));
722
723
  }
723
724
  sendTypingStart(conversationId) {
724
725
  return this.apiClient.api.conversation.postTyping(conversationId, { status: data_1.CONVERSATION_TYPING.STARTED });
@@ -916,16 +917,18 @@ class ConversationService {
916
917
  * @param epoch The current epoch of the local conversation
917
918
  */
918
919
  async sendExternalJoinProposal(conversationGroupId, epoch) {
919
- const groupIdDecodedFromBase64 = bazinga64_1.Decoder.fromBase64(conversationGroupId).asBytes;
920
- const externalProposal = await this.mlsService.newExternalProposal(0 /* Add */, {
921
- epoch,
922
- conversationId: groupIdDecodedFromBase64,
923
- });
924
- await this.apiClient.api.conversation.postMlsMessage(
925
- //@todo: it's temporary - we wait for core-crypto fix to return the actual Uint8Array instead of regular array
926
- (0, mls_1.optionalToUint8Array)(externalProposal));
927
- //We store the info when user was added (and key material was created), so we will know when to renew it
928
- await this.storeLastKeyMaterialUpdateDateWithCurrentTime(conversationGroupId);
920
+ return (0, messageSender_1.sendMessage)(async () => {
921
+ const groupIdDecodedFromBase64 = bazinga64_1.Decoder.fromBase64(conversationGroupId).asBytes;
922
+ const externalProposal = await this.mlsService.newExternalProposal(0 /* Add */, {
923
+ epoch,
924
+ conversationId: groupIdDecodedFromBase64,
925
+ });
926
+ await this.apiClient.api.conversation.postMlsMessage(
927
+ //@todo: it's temporary - we wait for core-crypto fix to return the actual Uint8Array instead of regular array
928
+ (0, mls_1.optionalToUint8Array)(externalProposal));
929
+ //We store the info when user was added (and key material was created), so we will know when to renew it
930
+ await this.storeLastKeyMaterialUpdateDateWithCurrentTime(conversationGroupId);
931
+ });
929
932
  }
930
933
  async isMLSConversationEstablished(conversationGroupId) {
931
934
  const groupIdDecodedFromBase64 = bazinga64_1.Decoder.fromBase64(conversationGroupId).asBytes;
@@ -0,0 +1,4 @@
1
+ import { Task } from '@wireapp/promise-queue';
2
+ export declare function sendMessage<T>(sendingFunction: Task<T>): Promise<T>;
3
+ export declare function resumeMessageSending(): void;
4
+ export declare function pauseMessageSending(): void;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /*
3
+ * Wire
4
+ * Copyright (C) 2022 Wire Swiss GmbH
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program. If not, see http://www.gnu.org/licenses/.
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.pauseMessageSending = exports.resumeMessageSending = exports.sendMessage = void 0;
22
+ const promise_queue_1 = require("@wireapp/promise-queue");
23
+ const sendingQueue = new promise_queue_1.PromiseQueue({ name: 'message-sender', paused: true });
24
+ function sendMessage(sendingFunction) {
25
+ return sendingQueue.push(sendingFunction);
26
+ }
27
+ exports.sendMessage = sendMessage;
28
+ function resumeMessageSending() {
29
+ sendingQueue.pause(false);
30
+ }
31
+ exports.resumeMessageSending = resumeMessageSending;
32
+ function pauseMessageSending() {
33
+ sendingQueue.pause(true);
34
+ }
35
+ exports.pauseMessageSending = pauseMessageSending;
36
+ //# sourceMappingURL=messageSender.js.map
@@ -6,8 +6,7 @@ export declare enum DatabaseStores {
6
6
  PRE_KEYS = "prekeys",
7
7
  SESSIONS = "sessions",
8
8
  GROUP_IDS = "group_ids",
9
- PENDING_PROPOSALS = "pending_proposals",
10
- LAST_KEY_MATERIAL_UPDATE_DATES = "last_key_material_update_dates"
9
+ PENDING_PROPOSALS = "pending_proposals"
11
10
  }
12
11
  export declare class CryptographyDatabaseRepository {
13
12
  private readonly storeEngine;
@@ -28,7 +28,6 @@ var DatabaseStores;
28
28
  DatabaseStores["SESSIONS"] = "sessions";
29
29
  DatabaseStores["GROUP_IDS"] = "group_ids";
30
30
  DatabaseStores["PENDING_PROPOSALS"] = "pending_proposals";
31
- DatabaseStores["LAST_KEY_MATERIAL_UPDATE_DATES"] = "last_key_material_update_dates";
32
31
  })(DatabaseStores = exports.DatabaseStores || (exports.DatabaseStores = {}));
33
32
  class CryptographyDatabaseRepository {
34
33
  constructor(storeEngine) {
@@ -20,6 +20,7 @@
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.MLSService = exports.optionalToUint8Array = void 0;
22
22
  const bazinga64_1 = require("bazinga64");
23
+ const messageSender_1 = require("../../conversation/message/messageSender");
23
24
  //@todo: this function is temporary, we wait for the update from core-crypto side
24
25
  //they are returning regular array instead of Uint8Array for commit and welcome messages
25
26
  const optionalToUint8Array = (array) => {
@@ -60,10 +61,12 @@ class MLSService {
60
61
  }
61
62
  return null;
62
63
  }
63
- async addUsersToExistingConversation(groupId, invitee) {
64
- const coreCryptoClient = this.getCoreCryptoClient();
65
- const memberAddedMessages = await coreCryptoClient.addClientsToConversation(groupId, invitee);
66
- return this.uploadCommitBundle(groupId, memberAddedMessages);
64
+ addUsersToExistingConversation(groupId, invitee) {
65
+ return (0, messageSender_1.sendMessage)(async () => {
66
+ const coreCryptoClient = this.getCoreCryptoClient();
67
+ const memberAddedMessages = await coreCryptoClient.addClientsToConversation(groupId, invitee);
68
+ return this.uploadCommitBundle(groupId, memberAddedMessages);
69
+ });
67
70
  }
68
71
  async getKeyPackagesPayload(qualifiedUsers) {
69
72
  /**
@@ -104,16 +107,20 @@ class MLSService {
104
107
  async encryptMessage(conversationId, message) {
105
108
  return this.getCoreCryptoClient().encryptMessage(conversationId, message);
106
109
  }
107
- async updateKeyingMaterial(conversationId) {
108
- const commitBundle = await this.getCoreCryptoClient().updateKeyingMaterial(conversationId);
109
- return this.uploadCommitBundle(conversationId, commitBundle);
110
+ updateKeyingMaterial(conversationId) {
111
+ return (0, messageSender_1.sendMessage)(async () => {
112
+ const commitBundle = await this.getCoreCryptoClient().updateKeyingMaterial(conversationId);
113
+ return this.uploadCommitBundle(conversationId, commitBundle);
114
+ });
110
115
  }
111
116
  async createConversation(conversationId, configuration) {
112
117
  return this.getCoreCryptoClient().createConversation(conversationId, configuration);
113
118
  }
114
- async removeClientsFromConversation(conversationId, clientIds) {
115
- const commitBundle = await this.getCoreCryptoClient().removeClientsFromConversation(conversationId, clientIds);
116
- return this.uploadCommitBundle(conversationId, commitBundle);
119
+ removeClientsFromConversation(conversationId, clientIds) {
120
+ return (0, messageSender_1.sendMessage)(async () => {
121
+ const commitBundle = await this.getCoreCryptoClient().removeClientsFromConversation(conversationId, clientIds);
122
+ return this.uploadCommitBundle(conversationId, commitBundle);
123
+ });
117
124
  }
118
125
  async commitPendingProposals(conversationId) {
119
126
  return this.getCoreCryptoClient().commitPendingProposals(conversationId);
@@ -0,0 +1 @@
1
+ export * from './keyMaterialUpdatesStore';
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ /*
3
+ * Wire
4
+ * Copyright (C) 2022 Wire Swiss GmbH
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program. If not, see http://www.gnu.org/licenses/.
18
+ *
19
+ */
20
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
23
+ }) : (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ o[k2] = m[k];
26
+ }));
27
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
28
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ __exportStar(require("./keyMaterialUpdatesStore"), exports);
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ import { CommonMLS, LastKeyMaterialUpdateParams } from '../../notification/types';
2
+ export interface KeyMaterialUpdatesStore {
3
+ [groupId: string]: LastKeyMaterialUpdateParams;
4
+ }
5
+ export declare const keyMaterialUpdatesStore: {
6
+ getAllUpdateDates: () => LastKeyMaterialUpdateParams[];
7
+ storeLastKeyMaterialUpdateDate: ({ groupId, previousUpdateDate }: LastKeyMaterialUpdateParams) => void;
8
+ deleteLastKeyMaterialUpdateDate: ({ groupId }: CommonMLS) => void;
9
+ };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /*
3
+ * Wire
4
+ * Copyright (C) 2022 Wire Swiss GmbH
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program. If not, see http://www.gnu.org/licenses/.
18
+ *
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.keyMaterialUpdatesStore = void 0;
22
+ const storageKey = 'keyMaterialUpdates';
23
+ const getUpdateDatesMap = () => {
24
+ const storedState = localStorage.getItem(storageKey);
25
+ if (!storedState) {
26
+ return {};
27
+ }
28
+ return JSON.parse(storedState);
29
+ };
30
+ const getAllUpdateDates = () => {
31
+ const storedStateMap = getUpdateDatesMap();
32
+ return Object.values(storedStateMap);
33
+ };
34
+ const storeLastKeyMaterialUpdateDate = ({ groupId, previousUpdateDate }) => {
35
+ const storedState = getUpdateDatesMap();
36
+ const newStoredState = Object.assign(Object.assign({}, storedState), { [groupId]: { groupId, previousUpdateDate } });
37
+ localStorage.setItem(storageKey, JSON.stringify(newStoredState));
38
+ };
39
+ const deleteLastKeyMaterialUpdateDate = ({ groupId }) => {
40
+ const storedState = getUpdateDatesMap();
41
+ if (storedState[groupId]) {
42
+ delete storedState[groupId];
43
+ }
44
+ localStorage.setItem(storageKey, JSON.stringify(storedState));
45
+ };
46
+ exports.keyMaterialUpdatesStore = {
47
+ getAllUpdateDates,
48
+ storeLastKeyMaterialUpdateDate,
49
+ deleteLastKeyMaterialUpdateDate,
50
+ };
51
+ //# sourceMappingURL=keyMaterialUpdatesStore.js.map
@@ -1,7 +1,7 @@
1
1
  import type { BackendEvent } from '@wireapp/api-client/src/event';
2
2
  import type { Notification } from '@wireapp/api-client/src/notification/';
3
3
  import type { CRUDEngine } from '@wireapp/store-engine';
4
- import { CommonMLS, CompoundGroupIdParams, LastKeyMaterialUpdateParams, StorePendingProposalsParams } from './types';
4
+ import { CommonMLS, CompoundGroupIdParams, StorePendingProposalsParams } from './types';
5
5
  export declare enum DatabaseStores {
6
6
  EVENTS = "events"
7
7
  }
@@ -42,25 +42,4 @@ export declare class NotificationDatabaseRepository {
42
42
  *
43
43
  */
44
44
  getStoredPendingProposals(): Promise<StorePendingProposalsParams[]>;
45
- /**
46
- * ## MLS only ##
47
- * Store groupIds with last key material update dates.
48
- *
49
- * @param {groupId} params.groupId - groupId of the mls conversation
50
- * @param {previousUpdateDate} params.previousUpdateDate - date of the previous key material update
51
- */
52
- storeLastKeyMaterialUpdateDate(params: LastKeyMaterialUpdateParams): Promise<boolean>;
53
- /**
54
- * ## MLS only ##
55
- * Delete stored entries for last key materials update dates.
56
- *
57
- * @param {groupId} groupId - of the mls conversation
58
- */
59
- deleteLastKeyMaterialUpdateDate({ groupId }: CommonMLS): Promise<boolean>;
60
- /**
61
- * ## MLS only ##
62
- * Get all stored entries for last key materials update dates.
63
- *
64
- */
65
- getStoredLastKeyMaterialUpdateDates(): Promise<LastKeyMaterialUpdateParams[]>;
66
45
  }
@@ -102,35 +102,6 @@ class NotificationDatabaseRepository {
102
102
  async getStoredPendingProposals() {
103
103
  return this.storeEngine.readAll(STORES.PENDING_PROPOSALS);
104
104
  }
105
- /**
106
- * ## MLS only ##
107
- * Store groupIds with last key material update dates.
108
- *
109
- * @param {groupId} params.groupId - groupId of the mls conversation
110
- * @param {previousUpdateDate} params.previousUpdateDate - date of the previous key material update
111
- */
112
- async storeLastKeyMaterialUpdateDate(params) {
113
- await this.storeEngine.updateOrCreate(STORES.LAST_KEY_MATERIAL_UPDATE_DATES, `${params.groupId}`, params);
114
- return true;
115
- }
116
- /**
117
- * ## MLS only ##
118
- * Delete stored entries for last key materials update dates.
119
- *
120
- * @param {groupId} groupId - of the mls conversation
121
- */
122
- async deleteLastKeyMaterialUpdateDate({ groupId }) {
123
- await this.storeEngine.delete(STORES.LAST_KEY_MATERIAL_UPDATE_DATES, `${groupId}`);
124
- return true;
125
- }
126
- /**
127
- * ## MLS only ##
128
- * Get all stored entries for last key materials update dates.
129
- *
130
- */
131
- async getStoredLastKeyMaterialUpdateDates() {
132
- return this.storeEngine.readAll(STORES.LAST_KEY_MATERIAL_UPDATE_DATES);
133
- }
134
105
  }
135
106
  exports.NotificationDatabaseRepository = NotificationDatabaseRepository;
136
107
  //# sourceMappingURL=NotificationDatabaseRepository.js.map
@@ -69,6 +69,7 @@ const bazinga64_1 = require("bazinga64");
69
69
  const TaskScheduler_1 = require("../util/TaskScheduler/TaskScheduler");
70
70
  const LowPrecisionTaskScheduler_1 = require("../util/LowPrecisionTaskScheduler/LowPrecisionTaskScheduler");
71
71
  const keyPackagesStatusStore_1 = require("../mls/keyPackagesStatusStore/keyPackagesStatusStore");
72
+ const keyMaterialUpdatesStore_1 = require("../mls/keyMaterialUpdatesStore");
72
73
  var TOPIC;
73
74
  (function (TOPIC) {
74
75
  TOPIC["NOTIFICATION_ERROR"] = "NotificationService.TOPIC.NOTIFICATION_ERROR";
@@ -407,7 +408,7 @@ class NotificationService extends events_1.EventEmitter {
407
408
  * @param {previousUpdateDate} params.previousUpdateDate - date of the previous key material update
408
409
  */
409
410
  async storeLastKeyMaterialUpdateDate(params) {
410
- await this.database.storeLastKeyMaterialUpdateDate(params);
411
+ keyMaterialUpdatesStore_1.keyMaterialUpdatesStore.storeLastKeyMaterialUpdateDate(params);
411
412
  await this.scheduleTaskToRenewKeyMaterial(params);
412
413
  }
413
414
  /**
@@ -420,7 +421,7 @@ class NotificationService extends events_1.EventEmitter {
420
421
  try {
421
422
  const groupConversationExists = await this.mlsService.conversationExists(bazinga64_1.Decoder.fromBase64(groupId).asBytes);
422
423
  if (!groupConversationExists) {
423
- await this.database.deleteLastKeyMaterialUpdateDate({ groupId });
424
+ keyMaterialUpdatesStore_1.keyMaterialUpdatesStore.deleteLastKeyMaterialUpdateDate({ groupId });
424
425
  return;
425
426
  }
426
427
  const groupIdDecodedFromBase64 = bazinga64_1.Decoder.fromBase64(groupId).asBytes;
@@ -457,7 +458,7 @@ class NotificationService extends events_1.EventEmitter {
457
458
  */
458
459
  async checkForKeyMaterialsUpdate() {
459
460
  try {
460
- const keyMaterialUpdateDates = await this.database.getStoredLastKeyMaterialUpdateDates();
461
+ const keyMaterialUpdateDates = keyMaterialUpdatesStore_1.keyMaterialUpdatesStore.getAllUpdateDates();
461
462
  keyMaterialUpdateDates.forEach(date => this.scheduleTaskToRenewKeyMaterial(date));
462
463
  }
463
464
  catch (error) {