@wireapp/core 46.1.0-hotfix-1.5 → 46.1.0-hotfix-1.7

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.
Files changed (55) hide show
  1. package/README.md +1 -1
  2. package/lib/Account.d.ts +8 -5
  3. package/lib/Account.d.ts.map +1 -1
  4. package/lib/Account.js +141 -321
  5. package/lib/Account.test.js +9 -9
  6. package/lib/conversation/AssetService/AssetService.test.js +3 -3
  7. package/lib/conversation/ConversationService/ConversationService.d.ts +1 -1
  8. package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
  9. package/lib/conversation/ConversationService/ConversationService.js +11 -5
  10. package/lib/conversation/ConversationService/ConversationService.test.js +6 -9
  11. package/lib/conversation/SubconversationService/SubconversationService.d.ts +1 -1
  12. package/lib/conversation/SubconversationService/SubconversationService.d.ts.map +1 -1
  13. package/lib/conversation/SubconversationService/SubconversationService.js +3 -1
  14. package/lib/conversation/SubconversationService/SubconversationService.test.js +6 -5
  15. package/lib/conversation/message/MessageBuilder.js +2 -2
  16. package/lib/conversation/message/MessageService.test.js +3 -3
  17. package/lib/index.d.ts +1 -0
  18. package/lib/index.d.ts.map +1 -1
  19. package/lib/index.js +3 -1
  20. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/AcmeService.d.ts +1 -1
  21. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/schema.d.ts +2 -2
  22. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.d.ts.map +1 -1
  23. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.js +8 -31
  24. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.test.js +56 -4
  25. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.d.ts +2 -2
  26. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.d.ts.map +1 -1
  27. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.js +3 -6
  28. package/lib/messagingProtocols/mls/E2EIdentityService/Helper/index.d.ts +4 -2
  29. package/lib/messagingProtocols/mls/E2EIdentityService/Helper/index.d.ts.map +1 -1
  30. package/lib/messagingProtocols/mls/E2EIdentityService/Helper/index.js +24 -2
  31. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/OidcChallenge.d.ts +1 -1
  32. package/lib/messagingProtocols/mls/MLSService/ClientMLSError.d.ts +8 -0
  33. package/lib/messagingProtocols/mls/MLSService/ClientMLSError.d.ts.map +1 -0
  34. package/lib/messagingProtocols/mls/MLSService/{MLSService.guards.js → ClientMLSError.js} +12 -7
  35. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts +45 -11
  36. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts.map +1 -1
  37. package/lib/messagingProtocols/mls/MLSService/MLSService.js +92 -42
  38. package/lib/messagingProtocols/mls/MLSService/MLSService.test.js +109 -10
  39. package/lib/messagingProtocols/mls/MLSService/MLSService.types.d.ts +1 -15
  40. package/lib/messagingProtocols/mls/MLSService/MLSService.types.d.ts.map +1 -1
  41. package/lib/messagingProtocols/mls/MLSService/index.d.ts +1 -0
  42. package/lib/messagingProtocols/mls/MLSService/index.d.ts.map +1 -1
  43. package/lib/messagingProtocols/mls/MLSService/index.js +1 -0
  44. package/lib/messagingProtocols/mls/types.d.ts +0 -3
  45. package/lib/messagingProtocols/mls/types.d.ts.map +1 -1
  46. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts.map +1 -1
  47. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.js +0 -1
  48. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts +7 -4
  49. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts.map +1 -1
  50. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts +1 -1
  51. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts.map +1 -1
  52. package/lib/test/PayloadHelper.js +2 -2
  53. package/package.json +3 -3
  54. package/lib/messagingProtocols/mls/MLSService/MLSService.guards.d.ts +0 -4
  55. package/lib/messagingProtocols/mls/MLSService/MLSService.guards.d.ts.map +0 -1
package/lib/Account.js CHANGED
@@ -1,22 +1,4 @@
1
- /*
2
- * Wire
3
- * Copyright (C) 2024 Wire Swiss GmbH
4
- *
5
- * This program is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program. If not, see http://www.gnu.org/licenses/.
17
- *
18
- */
19
-
1
+ "use strict";
20
2
  /*
21
3
  * Wire
22
4
  * Copyright (C) 2018 Wire Swiss GmbH
@@ -35,150 +17,92 @@
35
17
  * along with this program. If not, see http://www.gnu.org/licenses/.
36
18
  *
37
19
  */
38
- const __createBinding =
39
- (this && this.__createBinding) ||
40
- (Object.create
41
- ? function (o, m, k, k2) {
42
- if (k2 === undefined) {
43
- k2 = k;
44
- }
45
- let desc = Object.getOwnPropertyDescriptor(m, k);
46
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
47
- desc = {
48
- enumerable: true,
49
- get: function () {
50
- return m[k];
51
- },
52
- };
53
- }
54
- Object.defineProperty(o, k2, desc);
55
- }
56
- : function (o, m, k, k2) {
57
- if (k2 === undefined) {
58
- k2 = k;
59
- }
60
- o[k2] = m[k];
61
- });
62
- const __setModuleDefault =
63
- (this && this.__setModuleDefault) ||
64
- (Object.create
65
- ? function (o, v) {
66
- Object.defineProperty(o, 'default', { enumerable: true, value: v });
67
- }
68
- : function (o, v) {
69
- o['default'] = v;
70
- });
71
- const __importStar =
72
- (this && this.__importStar) ||
73
- function (mod) {
74
- if (mod && mod.__esModule) {
75
- return mod;
76
- }
77
- const result = {};
78
- if (mod != null) {
79
- for (const k in mod) {
80
- if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k)) {
81
- __createBinding(result, mod, k);
82
- }
83
- }
84
- }
85
- __setModuleDefault(result, mod);
86
- return result;
87
- };
88
- const __asyncValues =
89
- (this && this.__asyncValues) ||
90
- function (o) {
91
- if (!Symbol.asyncIterator) {
92
- throw new TypeError('Symbol.asyncIterator is not defined.');
93
- }
94
- const m = o[Symbol.asyncIterator];
95
- let i;
96
- return m
97
- ? m.call(o)
98
- : ((o = typeof __values === 'function' ? __values(o) : o[Symbol.iterator]()),
99
- (i = {}),
100
- verb('next'),
101
- verb('throw'),
102
- verb('return'),
103
- (i[Symbol.asyncIterator] = function () {
104
- return this;
105
- }),
106
- i);
107
- function verb(n) {
108
- i[n] =
109
- o[n] &&
110
- function (v) {
111
- return new Promise((resolve, reject) => {
112
- (v = o[n](v)), settle(resolve, reject, v.done, v.value);
113
- });
114
- };
115
- }
116
- function settle(resolve, reject, d, v) {
117
- Promise.resolve(v).then(v => {
118
- resolve({ value: v, done: d });
119
- }, reject);
120
- }
121
- };
122
- const __importDefault =
123
- (this && this.__importDefault) ||
124
- function (mod) {
125
- return mod && mod.__esModule ? mod : { default: mod };
126
- };
127
- Object.defineProperty(exports, '__esModule', { value: true });
20
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ var desc = Object.getOwnPropertyDescriptor(m, k);
23
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
+ desc = { enumerable: true, get: function() { return m[k]; } };
25
+ }
26
+ Object.defineProperty(o, k2, desc);
27
+ }) : (function(o, m, k, k2) {
28
+ if (k2 === undefined) k2 = k;
29
+ o[k2] = m[k];
30
+ }));
31
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
32
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
33
+ }) : function(o, v) {
34
+ o["default"] = v;
35
+ });
36
+ var __importStar = (this && this.__importStar) || function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
43
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
44
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
45
+ var m = o[Symbol.asyncIterator], i;
46
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
47
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
48
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
49
+ };
50
+ var __importDefault = (this && this.__importDefault) || function (mod) {
51
+ return (mod && mod.__esModule) ? mod : { "default": mod };
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
128
54
  exports.Account = exports.ConnectionState = exports.EVENTS = void 0;
129
- const auth_1 = require('@wireapp/api-client/lib/auth');
130
- const client_1 = require('@wireapp/api-client/lib/client/');
131
- const event_1 = require('@wireapp/api-client/lib/event');
132
- const tcp_1 = require('@wireapp/api-client/lib/tcp/');
133
- const ReconnectingWebsocket_1 = require('@wireapp/api-client/lib/tcp/ReconnectingWebsocket');
134
- const TimeUtil_1 = require('@wireapp/commons/lib/util/TimeUtil');
135
-
136
- const logdown_1 = __importDefault(require('logdown'));
137
- const api_client_1 = require('@wireapp/api-client');
138
- const commons_1 = require('@wireapp/commons');
139
- const store_engine_1 = require('@wireapp/store-engine');
140
-
141
- const account_1 = require('./account/');
142
- const auth_2 = require('./auth/');
143
- const broadcast_1 = require('./broadcast/');
144
- const client_2 = require('./client/');
145
- const connection_1 = require('./connection/');
146
- const conversation_1 = require('./conversation/');
147
- const messageSender_1 = require('./conversation/message/messageSender');
148
- const SubconversationService_1 = require('./conversation/SubconversationService/SubconversationService');
149
- const giphy_1 = require('./giphy/');
150
- const linkPreview_1 = require('./linkPreview');
151
- const mls_1 = require('./messagingProtocols/mls');
152
- const conversationRejoinQueue_1 = require('./messagingProtocols/mls/conversationRejoinQueue');
153
- const E2EIdentityService_1 = require('./messagingProtocols/mls/E2EIdentityService');
154
- const proteus_1 = require('./messagingProtocols/proteus');
155
- const CryptoClient_1 = require('./messagingProtocols/proteus/ProteusService/CryptoClient');
156
- const notification_1 = require('./notification/');
157
- const encryptedStore_1 = require('./secretStore/encryptedStore');
158
- const secretKeyGenerator_1 = require('./secretStore/secretKeyGenerator');
159
- const self_1 = require('./self/');
160
- const CoreDB_1 = require('./storage/CoreDB');
161
- const team_1 = require('./team/');
162
- const user_1 = require('./user/');
163
- const RecurringTaskScheduler_1 = require('./util/RecurringTaskScheduler');
164
- let EVENTS;
55
+ const auth_1 = require("@wireapp/api-client/lib/auth");
56
+ const client_1 = require("@wireapp/api-client/lib/client/");
57
+ const event_1 = require("@wireapp/api-client/lib/event");
58
+ const tcp_1 = require("@wireapp/api-client/lib/tcp/");
59
+ const ReconnectingWebsocket_1 = require("@wireapp/api-client/lib/tcp/ReconnectingWebsocket");
60
+ const TimeUtil_1 = require("@wireapp/commons/lib/util/TimeUtil");
61
+ const logdown_1 = __importDefault(require("logdown"));
62
+ const api_client_1 = require("@wireapp/api-client");
63
+ const commons_1 = require("@wireapp/commons");
64
+ const store_engine_1 = require("@wireapp/store-engine");
65
+ const account_1 = require("./account/");
66
+ const auth_2 = require("./auth/");
67
+ const broadcast_1 = require("./broadcast/");
68
+ const client_2 = require("./client/");
69
+ const connection_1 = require("./connection/");
70
+ const conversation_1 = require("./conversation/");
71
+ const messageSender_1 = require("./conversation/message/messageSender");
72
+ const SubconversationService_1 = require("./conversation/SubconversationService/SubconversationService");
73
+ const giphy_1 = require("./giphy/");
74
+ const linkPreview_1 = require("./linkPreview");
75
+ const mls_1 = require("./messagingProtocols/mls");
76
+ const conversationRejoinQueue_1 = require("./messagingProtocols/mls/conversationRejoinQueue");
77
+ const E2EIdentityService_1 = require("./messagingProtocols/mls/E2EIdentityService");
78
+ const proteus_1 = require("./messagingProtocols/proteus");
79
+ const CryptoClient_1 = require("./messagingProtocols/proteus/ProteusService/CryptoClient");
80
+ const notification_1 = require("./notification/");
81
+ const encryptedStore_1 = require("./secretStore/encryptedStore");
82
+ const secretKeyGenerator_1 = require("./secretStore/secretKeyGenerator");
83
+ const self_1 = require("./self/");
84
+ const CoreDB_1 = require("./storage/CoreDB");
85
+ const team_1 = require("./team/");
86
+ const user_1 = require("./user/");
87
+ const RecurringTaskScheduler_1 = require("./util/RecurringTaskScheduler");
88
+ var EVENTS;
165
89
  (function (EVENTS) {
166
90
  /**
167
91
  * event triggered when a message from an unknown client is received.
168
92
  * An unknown client is a client we don't yet have a session with
169
93
  */
170
- EVENTS['NEW_SESSION'] = 'new_session';
94
+ EVENTS["NEW_SESSION"] = "new_session";
171
95
  })(EVENTS || (exports.EVENTS = EVENTS = {}));
172
- let ConnectionState;
96
+ var ConnectionState;
173
97
  (function (ConnectionState) {
174
98
  /** The websocket is closed and notifications stream is not being processed */
175
- ConnectionState['CLOSED'] = 'closed';
99
+ ConnectionState["CLOSED"] = "closed";
176
100
  /** The websocket is being opened */
177
- ConnectionState['CONNECTING'] = 'connecting';
101
+ ConnectionState["CONNECTING"] = "connecting";
178
102
  /** The websocket is open but locked and notifications stream is being processed */
179
- ConnectionState['PROCESSING_NOTIFICATIONS'] = 'processing_notifications';
103
+ ConnectionState["PROCESSING_NOTIFICATIONS"] = "processing_notifications";
180
104
  /** The websocket is open and message will go through and notifications stream is fully processed */
181
- ConnectionState['LIVE'] = 'live';
105
+ ConnectionState["LIVE"] = "live";
182
106
  })(ConnectionState || (exports.ConnectionState = ConnectionState = {}));
183
107
  const coreDefaultClient = {
184
108
  classification: client_1.ClientClassification.DESKTOP,
@@ -194,49 +118,36 @@ class Account extends commons_1.TypedEventEmitter {
194
118
  super();
195
119
  this.options = options;
196
120
  this.groupIdFromConversationId = async (conversationId, subconversationId) => {
197
- let _a;
198
- let _b;
121
+ var _a, _b;
199
122
  if (!subconversationId) {
200
- return (_a = this.coreCallbacks) === null || _a === void 0
201
- ? void 0
202
- : _a.groupIdFromConversationId(conversationId);
123
+ return (_a = this.coreCallbacks) === null || _a === void 0 ? void 0 : _a.groupIdFromConversationId(conversationId);
203
124
  }
204
- return (_b = this.service) === null || _b === void 0
205
- ? void 0
206
- : _b.subconversation.getSubconversationGroupId(conversationId, subconversationId);
125
+ return (_b = this.service) === null || _b === void 0 ? void 0 : _b.subconversation.getSubconversationGroupId(conversationId, subconversationId);
207
126
  };
208
127
  this.apiClient = apiClient;
209
128
  this.backendFeatures = this.apiClient.backendFeatures;
210
129
  this.coreCryptoConfig = options.coreCryptoConfig;
211
- this.isMlsEnabled = async () => {
212
- let _a;
213
- return (
214
- !!((_a = this.coreCryptoConfig) === null || _a === void 0 ? void 0 : _a.mls) &&
215
- (await this.apiClient.supportsMLS())
216
- );
217
- };
218
130
  this.recurringTaskScheduler = new RecurringTaskScheduler_1.RecurringTaskScheduler({
219
- get: async key => {
220
- let _a;
131
+ get: async (key) => {
132
+ var _a;
221
133
  const task = await ((_a = this.db) === null || _a === void 0 ? void 0 : _a.get('recurringTasks', key));
222
134
  return task === null || task === void 0 ? void 0 : task.firingDate;
223
135
  },
224
136
  set: async (key, timestamp) => {
225
- let _a;
226
- await ((_a = this.db) === null || _a === void 0
227
- ? void 0
228
- : _a.put('recurringTasks', { key, firingDate: timestamp }, key));
137
+ var _a;
138
+ await ((_a = this.db) === null || _a === void 0 ? void 0 : _a.put('recurringTasks', { key, firingDate: timestamp }, key));
229
139
  },
230
- delete: async key => {
231
- let _a;
140
+ delete: async (key) => {
141
+ var _a;
232
142
  await ((_a = this.db) === null || _a === void 0 ? void 0 : _a.delete('recurringTasks', key));
233
143
  },
234
144
  });
235
- apiClient.on(api_client_1.APIClient.TOPIC.COOKIE_REFRESH, async cookie => {
145
+ apiClient.on(api_client_1.APIClient.TOPIC.COOKIE_REFRESH, async (cookie) => {
236
146
  if (cookie && this.storeEngine) {
237
147
  try {
238
148
  await this.persistCookie(this.storeEngine, cookie);
239
- } catch (error) {
149
+ }
150
+ catch (error) {
240
151
  this.logger.error(`Failed to save cookie: ${error.message}`, error);
241
152
  }
242
153
  }
@@ -267,27 +178,14 @@ class Account extends commons_1.TypedEventEmitter {
267
178
  const entity = { expiration: cookie.expiration, zuid: cookie.zuid };
268
179
  return storeEngine.updateOrCreate(auth_1.AUTH_TABLE_NAME, auth_1.AUTH_COOKIE_KEY, entity);
269
180
  }
270
- async enrollE2EI({
271
- displayName,
272
- handle,
273
- teamId,
274
- discoveryUrl,
275
- getOAuthToken,
276
- certificateTtl = 90 * (TimeUtil_1.TimeInMillis.DAY / 1000),
277
- }) {
278
- let _a;
279
- let _b;
280
- let _c;
181
+ async enrollE2EI({ displayName, handle, teamId, discoveryUrl, getOAuthToken, certificateTtl = 90 * (TimeUtil_1.TimeInMillis.DAY / 1000), }) {
182
+ var _a, _b, _c, _d;
281
183
  const context = this.apiClient.context;
282
- const domain =
283
- (_a = context === null || context === void 0 ? void 0 : context.domain) !== null && _a !== void 0 ? _a : '';
184
+ const domain = (_a = context === null || context === void 0 ? void 0 : context.domain) !== null && _a !== void 0 ? _a : '';
284
185
  if (!this.currentClient) {
285
186
  throw new Error('Client has not been initialized - please login first');
286
187
  }
287
- if (
288
- !((_b = this.service) === null || _b === void 0 ? void 0 : _b.mls) ||
289
- !((_c = this.service) === null || _c === void 0 ? void 0 : _c.e2eIdentity)
290
- ) {
188
+ if (!((_c = (_b = this.service) === null || _b === void 0 ? void 0 : _b.mls) === null || _c === void 0 ? void 0 : _c.isEnabled) || !((_d = this.service) === null || _d === void 0 ? void 0 : _d.e2eIdentity)) {
291
189
  throw new Error('MLS not initialized, unable to enroll E2EI');
292
190
  }
293
191
  const user = {
@@ -297,14 +195,7 @@ class Account extends commons_1.TypedEventEmitter {
297
195
  teamId,
298
196
  id: this.userId,
299
197
  };
300
- return this.service.mls.enrollE2EI(
301
- discoveryUrl,
302
- user,
303
- this.currentClient,
304
- this.options.nbPrekeys,
305
- certificateTtl,
306
- getOAuthToken,
307
- );
198
+ return this.service.mls.enrollE2EI(discoveryUrl, user, this.currentClient, this.options.nbPrekeys, certificateTtl, getOAuthToken);
308
199
  }
309
200
  get clientId() {
310
201
  return this.apiClient.validatedClientId;
@@ -349,12 +240,9 @@ class Account extends commons_1.TypedEventEmitter {
349
240
  /**
350
241
  * Will register a new client for the current user
351
242
  */
352
- async registerClient(
353
- loginData,
354
- clientInfo = coreDefaultClient,
355
- /** will add extra manual entropy to the client's identity being created */
356
- entropyData,
357
- ) {
243
+ async registerClient(loginData, clientInfo = coreDefaultClient,
244
+ /** will add extra manual entropy to the client's identity being created */
245
+ entropyData) {
358
246
  if (!this.service || !this.apiClient.context || !this.storeEngine) {
359
247
  throw new Error('Services are not set or context not initialized.');
360
248
  }
@@ -368,7 +256,7 @@ class Account extends commons_1.TypedEventEmitter {
368
256
  return client;
369
257
  }
370
258
  getLocalClient() {
371
- let _a;
259
+ var _a;
372
260
  return (_a = this.service) === null || _a === void 0 ? void 0 : _a.client.loadClient();
373
261
  }
374
262
  /**
@@ -376,7 +264,7 @@ class Account extends commons_1.TypedEventEmitter {
376
264
  *
377
265
  * @returns The local existing client or undefined if the client does not exist or is not valid (non existing on backend)
378
266
  */
379
- async initClient(client, willEnrollE2ei = false) {
267
+ async initClient(client, mlsConfig) {
380
268
  if (!this.service || !this.apiClient.context || !this.storeEngine) {
381
269
  throw new Error('Services are not set.');
382
270
  }
@@ -384,9 +272,9 @@ class Account extends commons_1.TypedEventEmitter {
384
272
  // Call /access endpoint with client_id after client initialisation
385
273
  await this.apiClient.transport.http.associateClientWithSession(client.id);
386
274
  await this.service.proteus.initClient(this.storeEngine, this.apiClient.context);
387
- if (this.service.mls) {
275
+ if (this.service.mls && mlsConfig) {
388
276
  const { userId, domain = '' } = this.apiClient.context;
389
- await this.service.mls.initClient({ id: userId, domain }, client, willEnrollE2ei);
277
+ await this.service.mls.initClient({ id: userId, domain }, client, mlsConfig);
390
278
  // initialize schedulers for pending mls proposals once client is initialized
391
279
  await this.service.mls.initialisePendingProposalsTasks();
392
280
  // initialize scheduler for syncing key packages with backend
@@ -400,7 +288,7 @@ class Account extends commons_1.TypedEventEmitter {
400
288
  async buildCryptoClient(context, storeEngine, encryptedStore) {
401
289
  const baseConfig = {
402
290
  nbPrekeys: this.options.nbPrekeys,
403
- onNewPrekeys: async prekeys => {
291
+ onNewPrekeys: async (prekeys) => {
404
292
  this.logger.debug(`Received '${prekeys.length}' new PreKeys.`);
405
293
  await this.apiClient.api.client.putClient(context.clientId, { prekeys });
406
294
  this.logger.debug(`Successfully uploaded '${prekeys.length}' PreKeys.`);
@@ -408,20 +296,11 @@ class Account extends commons_1.TypedEventEmitter {
408
296
  };
409
297
  const coreCryptoConfig = this.coreCryptoConfig;
410
298
  if (coreCryptoConfig) {
411
- const { buildClient } = await Promise.resolve().then(() =>
412
- __importStar(require('./messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper')),
413
- );
414
- const client = await buildClient(storeEngine, {
415
- ...baseConfig,
416
- ...coreCryptoConfig,
417
- generateSecretKey: keyId =>
418
- (0, secretKeyGenerator_1.generateSecretKey)({ keyId, keySize: 16, secretsDb: encryptedStore }),
419
- });
299
+ const { buildClient } = await Promise.resolve().then(() => __importStar(require('./messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper')));
300
+ const client = await buildClient(storeEngine, Object.assign(Object.assign(Object.assign({}, baseConfig), coreCryptoConfig), { generateSecretKey: keyId => (0, secretKeyGenerator_1.generateSecretKey)({ keyId, keySize: 16, secretsDb: encryptedStore }) }));
420
301
  return [CryptoClient_1.CryptoClientType.CORE_CRYPTO, client];
421
302
  }
422
- const { buildClient } = await Promise.resolve().then(() =>
423
- __importStar(require('./messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper')),
424
- );
303
+ const { buildClient } = await Promise.resolve().then(() => __importStar(require('./messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper')));
425
304
  const client = buildClient(storeEngine, baseConfig);
426
305
  return [CryptoClient_1.CryptoClientType.CRYPTOBOX, client];
427
306
  }
@@ -436,7 +315,6 @@ class Account extends commons_1.TypedEventEmitter {
436
315
  this.coreCallbacks = coreCallbacks;
437
316
  }
438
317
  async initServices(context) {
439
- let _a;
440
318
  const encryptedStoreName = this.generateEncryptedDbName(context);
441
319
  this.encryptedDb = this.options.systemCrypto
442
320
  ? await (0, encryptedStore_1.createCustomEncryptedStore)(encryptedStoreName, this.options.systemCrypto)
@@ -454,43 +332,16 @@ class Account extends commons_1.TypedEventEmitter {
454
332
  nbPrekeys: this.options.nbPrekeys,
455
333
  });
456
334
  const clientService = new client_2.ClientService(this.apiClient, proteusService, this.storeEngine);
457
- if (clientType === CryptoClient_1.CryptoClientType.CORE_CRYPTO && (await this.isMlsEnabled())) {
458
- mlsService = new mls_1.MLSService(
459
- this.apiClient,
460
- cryptoClient.getNativeClient(),
461
- this.db,
462
- this.recurringTaskScheduler,
463
- { ...((_a = this.coreCryptoConfig) === null || _a === void 0 ? void 0 : _a.mls) },
464
- );
465
- e2eServiceExternal = new E2EIdentityService_1.E2EIServiceExternal(
466
- cryptoClient.getNativeClient(),
467
- this.db,
468
- this.recurringTaskScheduler,
469
- clientService,
470
- mlsService,
471
- );
335
+ if (clientType === CryptoClient_1.CryptoClientType.CORE_CRYPTO && (await this.apiClient.supportsMLS())) {
336
+ mlsService = new mls_1.MLSService(this.apiClient, cryptoClient.getNativeClient(), this.db, this.recurringTaskScheduler);
337
+ e2eServiceExternal = new E2EIdentityService_1.E2EIServiceExternal(cryptoClient.getNativeClient(), this.db, this.recurringTaskScheduler, clientService, mlsService);
472
338
  }
473
339
  const connectionService = new connection_1.ConnectionService(this.apiClient);
474
340
  const giphyService = new giphy_1.GiphyService(this.apiClient);
475
341
  const linkPreviewService = new linkPreview_1.LinkPreviewService(assetService);
476
- const subconversationService = new SubconversationService_1.SubconversationService(
477
- this.apiClient,
478
- this.db,
479
- mlsService,
480
- );
481
- const conversationService = new conversation_1.ConversationService(
482
- this.apiClient,
483
- proteusService,
484
- this.db,
485
- this.groupIdFromConversationId,
486
- subconversationService,
487
- mlsService,
488
- );
489
- const notificationService = new notification_1.NotificationService(
490
- this.apiClient,
491
- this.storeEngine,
492
- conversationService,
493
- );
342
+ const subconversationService = new SubconversationService_1.SubconversationService(this.apiClient, this.db, mlsService);
343
+ const conversationService = new conversation_1.ConversationService(this.apiClient, proteusService, this.db, this.groupIdFromConversationId, subconversationService, mlsService);
344
+ const notificationService = new notification_1.NotificationService(this.apiClient, this.storeEngine, conversationService);
494
345
  const selfService = new self_1.SelfService(this.apiClient);
495
346
  const teamService = new team_1.TeamService(this.apiClient);
496
347
  const broadcastService = new broadcast_1.BroadcastService(this.apiClient, proteusService);
@@ -524,8 +375,7 @@ class Account extends commons_1.TypedEventEmitter {
524
375
  * @param clearData if set to `true` will completely wipe any database that was created by the Account
525
376
  */
526
377
  async logout(clearData = false) {
527
- let _a;
528
- let _b;
378
+ var _a, _b;
529
379
  (_a = this.db) === null || _a === void 0 ? void 0 : _a.close();
530
380
  (_b = this.encryptedDb) === null || _b === void 0 ? void 0 : _b.close();
531
381
  if (clearData) {
@@ -538,14 +388,20 @@ class Account extends commons_1.TypedEventEmitter {
538
388
  * Will delete the identity of the current user
539
389
  */
540
390
  async wipe() {
541
- let _a;
542
- let _b;
391
+ var _a, _b;
543
392
  await ((_a = this.service) === null || _a === void 0 ? void 0 : _a.proteus.wipe(this.storeEngine));
544
393
  if (this.db) {
545
394
  await (0, CoreDB_1.deleteDB)(this.db);
546
395
  }
547
396
  await ((_b = this.encryptedDb) === null || _b === void 0 ? void 0 : _b.wipe());
548
397
  }
398
+ /**
399
+ * return true if the current user has a MLS device that is initialized and ready to use
400
+ */
401
+ get hasMLSDevice() {
402
+ var _a, _b;
403
+ return !!((_b = (_a = this.service) === null || _a === void 0 ? void 0 : _a.mls) === null || _b === void 0 ? void 0 : _b.isEnabled);
404
+ }
549
405
  /**
550
406
  * Will download and handle the notification stream since last stored notification id.
551
407
  * Once the notification stream has been handled from backend, will then connect to the websocket and start listening to incoming events
@@ -553,13 +409,7 @@ class Account extends commons_1.TypedEventEmitter {
553
409
  * @param callbacks callbacks that will be called to handle different events
554
410
  * @returns close a function that will disconnect from the websocket
555
411
  */
556
- listen({
557
- onEvent = () => { },
558
- onConnectionStateChanged = () => { },
559
- onNotificationStreamProgress = () => { },
560
- onMissedNotifications = () => { },
561
- dryRun = false,
562
- } = {}) {
412
+ listen({ onEvent = () => { }, onConnectionStateChanged = () => { }, onNotificationStreamProgress = () => { }, onMissedNotifications = () => { }, dryRun = false, } = {}) {
563
413
  if (!this.currentClient) {
564
414
  throw new Error('Client has not been initialized - please login first');
565
415
  }
@@ -567,10 +417,7 @@ class Account extends commons_1.TypedEventEmitter {
567
417
  const { event } = payload;
568
418
  switch (event === null || event === void 0 ? void 0 : event.type) {
569
419
  case event_1.CONVERSATION_EVENT.MESSAGE_TIMER_UPDATE: {
570
- const {
571
- data: { message_timer },
572
- conversation,
573
- } = event;
420
+ const { data: { message_timer }, conversation, } = event;
574
421
  const expireAfterMillis = Number(message_timer);
575
422
  this.service.conversation.messageTimer.setConversationLevelTimer(conversation, expireAfterMillis);
576
423
  break;
@@ -579,44 +426,31 @@ class Account extends commons_1.TypedEventEmitter {
579
426
  await onEvent(payload, source);
580
427
  };
581
428
  const handleNotification = async (notification, source) => {
582
- let _a;
583
- let _b;
584
- let _c;
585
- let e_1;
429
+ var _a, e_1, _b, _c;
586
430
  try {
587
431
  const messages = this.service.notification.handleNotification(notification, source, dryRun);
588
432
  try {
589
- for (
590
- var _d = true, messages_1 = __asyncValues(messages), messages_1_1;
591
- (messages_1_1 = await messages_1.next()), (_a = messages_1_1.done), !_a;
592
- _d = true
593
- ) {
433
+ for (var _d = true, messages_1 = __asyncValues(messages), messages_1_1; messages_1_1 = await messages_1.next(), _a = messages_1_1.done, !_a; _d = true) {
594
434
  _c = messages_1_1.value;
595
435
  _d = false;
596
436
  const message = _c;
597
437
  await handleEvent(message, source);
598
438
  }
599
- } catch (e_1_1) {
600
- e_1 = { error: e_1_1 };
601
- } finally {
439
+ }
440
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
441
+ finally {
602
442
  try {
603
- if (!_d && !_a && (_b = messages_1.return)) {
604
- await _b.call(messages_1);
605
- }
606
- } finally {
607
- if (e_1) {
608
- throw e_1.error;
609
- }
443
+ if (!_d && !_a && (_b = messages_1.return)) await _b.call(messages_1);
610
444
  }
445
+ finally { if (e_1) throw e_1.error; }
611
446
  }
612
- } catch (error) {
447
+ }
448
+ catch (error) {
613
449
  this.logger.error(`Failed to handle notification ID "${notification.id}": ${error.message}`, error);
614
450
  }
615
451
  };
616
452
  this.apiClient.transport.ws.removeAllListeners(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE);
617
- this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE, notification =>
618
- handleNotification(notification, notification_1.NotificationSource.WEBSOCKET),
619
- );
453
+ this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE, notification => handleNotification(notification, notification_1.NotificationSource.WEBSOCKET));
620
454
  this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_STATE_CHANGE, wsState => {
621
455
  const mapping = {
622
456
  [ReconnectingWebsocket_1.WEBSOCKET_STATE.CLOSED]: ConnectionState.CLOSED,
@@ -627,30 +461,23 @@ class Account extends commons_1.TypedEventEmitter {
627
461
  onConnectionStateChanged(connectionState);
628
462
  }
629
463
  });
630
- const handleMissedNotifications = async notificationId => {
631
- let _a;
632
- if ((_a = this.service) === null || _a === void 0 ? void 0 : _a.mls) {
633
- (0, conversationRejoinQueue_1.queueConversationRejoin)('all-conversations', () =>
634
- this.service.conversation.handleConversationsEpochMismatch(),
635
- );
464
+ const handleMissedNotifications = async (notificationId) => {
465
+ if (this.hasMLSDevice) {
466
+ (0, conversationRejoinQueue_1.queueConversationRejoin)('all-conversations', () => this.service.conversation.handleConversationsEpochMismatch());
636
467
  }
637
468
  return onMissedNotifications(notificationId);
638
469
  };
639
- const processNotificationStream = async abortHandler => {
470
+ const processNotificationStream = async (abortHandler) => {
640
471
  // Lock websocket in order to buffer any message that arrives while we handle the notification stream
641
472
  this.apiClient.transport.ws.lock();
642
473
  (0, messageSender_1.pauseMessageSending)();
643
474
  // We want to avoid triggering rejoins of out-of-sync MLS conversations while we are processing the notification stream
644
475
  (0, conversationRejoinQueue_1.pauseRejoiningMLSConversations)();
645
476
  onConnectionStateChanged(ConnectionState.PROCESSING_NOTIFICATIONS);
646
- const results = await this.service.notification.processNotificationStream(
647
- async (notification, source, progress) => {
648
- await handleNotification(notification, source);
649
- onNotificationStreamProgress(progress);
650
- },
651
- handleMissedNotifications,
652
- abortHandler,
653
- );
477
+ const results = await this.service.notification.processNotificationStream(async (notification, source, progress) => {
478
+ await handleNotification(notification, source);
479
+ onNotificationStreamProgress(progress);
480
+ }, handleMissedNotifications, abortHandler);
654
481
  this.logger.info(`Finished processing notifications ${JSON.stringify(results)}`, results);
655
482
  if (abortHandler.isAborted()) {
656
483
  this.logger.warn('Ending connection process as websocket was closed');
@@ -686,16 +513,9 @@ class Account extends commons_1.TypedEventEmitter {
686
513
  const dbName = this.generateDbName(context);
687
514
  this.logger.log(`Initialising store with name "${dbName}"...`);
688
515
  const openDb = async () => {
689
- let _a;
690
- let _b;
691
- const dbKey = await (0, secretKeyGenerator_1.generateSecretKey)({
692
- keyId: 'db-key',
693
- keySize: 32,
694
- secretsDb: encryptedStore,
695
- });
696
- const initializedDb = await ((_b = (_a = this.options).createStore) === null || _b === void 0
697
- ? void 0
698
- : _b.call(_a, dbName, dbKey.key));
516
+ var _a, _b;
517
+ const dbKey = await (0, secretKeyGenerator_1.generateSecretKey)({ keyId: 'db-key', keySize: 32, secretsDb: encryptedStore });
518
+ const initializedDb = await ((_b = (_a = this.options).createStore) === null || _b === void 0 ? void 0 : _b.call(_a, dbName, dbKey.key));
699
519
  if (initializedDb) {
700
520
  this.logger.info(`Initialized store with existing engine "${dbName}".`);
701
521
  return initializedDb;