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

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 (53) hide show
  1. package/lib/Account.d.ts +5 -8
  2. package/lib/Account.d.ts.map +1 -1
  3. package/lib/Account.js +321 -141
  4. package/lib/Account.test.js +9 -9
  5. package/lib/conversation/AssetService/AssetService.test.js +3 -3
  6. package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
  7. package/lib/conversation/ConversationService/ConversationService.js +1 -1
  8. package/lib/conversation/ConversationService/ConversationService.test.js +9 -6
  9. package/lib/conversation/SubconversationService/SubconversationService.d.ts +1 -9
  10. package/lib/conversation/SubconversationService/SubconversationService.d.ts.map +1 -1
  11. package/lib/conversation/SubconversationService/SubconversationService.js +1 -37
  12. package/lib/conversation/SubconversationService/SubconversationService.test.js +5 -6
  13. package/lib/conversation/message/MessageBuilder.js +2 -2
  14. package/lib/conversation/message/MessageService.test.js +3 -3
  15. package/lib/index.d.ts +0 -1
  16. package/lib/index.d.ts.map +1 -1
  17. package/lib/index.js +1 -3
  18. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/AcmeService.d.ts +1 -1
  19. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/schema.d.ts +2 -2
  20. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.d.ts.map +1 -1
  21. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.js +31 -8
  22. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.test.js +4 -56
  23. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.d.ts +2 -2
  24. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.d.ts.map +1 -1
  25. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.js +6 -3
  26. package/lib/messagingProtocols/mls/E2EIdentityService/Helper/index.d.ts +2 -4
  27. package/lib/messagingProtocols/mls/E2EIdentityService/Helper/index.d.ts.map +1 -1
  28. package/lib/messagingProtocols/mls/E2EIdentityService/Helper/index.js +2 -24
  29. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/OidcChallenge.d.ts +1 -1
  30. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts +9 -43
  31. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts.map +1 -1
  32. package/lib/messagingProtocols/mls/MLSService/MLSService.guards.d.ts +4 -0
  33. package/lib/messagingProtocols/mls/MLSService/MLSService.guards.d.ts.map +1 -0
  34. package/lib/messagingProtocols/mls/MLSService/{ClientMLSError.js → MLSService.guards.js} +7 -12
  35. package/lib/messagingProtocols/mls/MLSService/MLSService.js +41 -90
  36. package/lib/messagingProtocols/mls/MLSService/MLSService.test.js +10 -109
  37. package/lib/messagingProtocols/mls/MLSService/MLSService.types.d.ts +15 -1
  38. package/lib/messagingProtocols/mls/MLSService/MLSService.types.d.ts.map +1 -1
  39. package/lib/messagingProtocols/mls/MLSService/index.d.ts +0 -1
  40. package/lib/messagingProtocols/mls/MLSService/index.d.ts.map +1 -1
  41. package/lib/messagingProtocols/mls/MLSService/index.js +0 -1
  42. package/lib/messagingProtocols/mls/types.d.ts +3 -0
  43. package/lib/messagingProtocols/mls/types.d.ts.map +1 -1
  44. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts.map +1 -1
  45. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.js +1 -0
  46. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts +4 -7
  47. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts.map +1 -1
  48. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts +1 -1
  49. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts.map +1 -1
  50. package/lib/test/PayloadHelper.js +2 -2
  51. package/package.json +3 -3
  52. package/lib/messagingProtocols/mls/MLSService/ClientMLSError.d.ts +0 -8
  53. package/lib/messagingProtocols/mls/MLSService/ClientMLSError.d.ts.map +0 -1
package/lib/Account.js CHANGED
@@ -1,4 +1,22 @@
1
- "use strict";
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
+
2
20
  /*
3
21
  * Wire
4
22
  * Copyright (C) 2018 Wire Swiss GmbH
@@ -17,92 +35,150 @@
17
35
  * along with this program. If not, see http://www.gnu.org/licenses/.
18
36
  *
19
37
  */
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 });
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 });
54
128
  exports.Account = exports.ConnectionState = exports.EVENTS = void 0;
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;
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;
89
165
  (function (EVENTS) {
90
166
  /**
91
167
  * event triggered when a message from an unknown client is received.
92
168
  * An unknown client is a client we don't yet have a session with
93
169
  */
94
- EVENTS["NEW_SESSION"] = "new_session";
170
+ EVENTS['NEW_SESSION'] = 'new_session';
95
171
  })(EVENTS || (exports.EVENTS = EVENTS = {}));
96
- var ConnectionState;
172
+ let ConnectionState;
97
173
  (function (ConnectionState) {
98
174
  /** The websocket is closed and notifications stream is not being processed */
99
- ConnectionState["CLOSED"] = "closed";
175
+ ConnectionState['CLOSED'] = 'closed';
100
176
  /** The websocket is being opened */
101
- ConnectionState["CONNECTING"] = "connecting";
177
+ ConnectionState['CONNECTING'] = 'connecting';
102
178
  /** The websocket is open but locked and notifications stream is being processed */
103
- ConnectionState["PROCESSING_NOTIFICATIONS"] = "processing_notifications";
179
+ ConnectionState['PROCESSING_NOTIFICATIONS'] = 'processing_notifications';
104
180
  /** The websocket is open and message will go through and notifications stream is fully processed */
105
- ConnectionState["LIVE"] = "live";
181
+ ConnectionState['LIVE'] = 'live';
106
182
  })(ConnectionState || (exports.ConnectionState = ConnectionState = {}));
107
183
  const coreDefaultClient = {
108
184
  classification: client_1.ClientClassification.DESKTOP,
@@ -118,36 +194,49 @@ class Account extends commons_1.TypedEventEmitter {
118
194
  super();
119
195
  this.options = options;
120
196
  this.groupIdFromConversationId = async (conversationId, subconversationId) => {
121
- var _a, _b;
197
+ let _a;
198
+ let _b;
122
199
  if (!subconversationId) {
123
- return (_a = this.coreCallbacks) === null || _a === void 0 ? void 0 : _a.groupIdFromConversationId(conversationId);
200
+ return (_a = this.coreCallbacks) === null || _a === void 0
201
+ ? void 0
202
+ : _a.groupIdFromConversationId(conversationId);
124
203
  }
125
- return (_b = this.service) === null || _b === void 0 ? void 0 : _b.subconversation.getSubconversationGroupId(conversationId, subconversationId);
204
+ return (_b = this.service) === null || _b === void 0
205
+ ? void 0
206
+ : _b.subconversation.getSubconversationGroupId(conversationId, subconversationId);
126
207
  };
127
208
  this.apiClient = apiClient;
128
209
  this.backendFeatures = this.apiClient.backendFeatures;
129
210
  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
+ };
130
218
  this.recurringTaskScheduler = new RecurringTaskScheduler_1.RecurringTaskScheduler({
131
- get: async (key) => {
132
- var _a;
219
+ get: async key => {
220
+ let _a;
133
221
  const task = await ((_a = this.db) === null || _a === void 0 ? void 0 : _a.get('recurringTasks', key));
134
222
  return task === null || task === void 0 ? void 0 : task.firingDate;
135
223
  },
136
224
  set: async (key, timestamp) => {
137
- var _a;
138
- await ((_a = this.db) === null || _a === void 0 ? void 0 : _a.put('recurringTasks', { key, firingDate: timestamp }, key));
225
+ let _a;
226
+ await ((_a = this.db) === null || _a === void 0
227
+ ? void 0
228
+ : _a.put('recurringTasks', { key, firingDate: timestamp }, key));
139
229
  },
140
- delete: async (key) => {
141
- var _a;
230
+ delete: async key => {
231
+ let _a;
142
232
  await ((_a = this.db) === null || _a === void 0 ? void 0 : _a.delete('recurringTasks', key));
143
233
  },
144
234
  });
145
- apiClient.on(api_client_1.APIClient.TOPIC.COOKIE_REFRESH, async (cookie) => {
235
+ apiClient.on(api_client_1.APIClient.TOPIC.COOKIE_REFRESH, async cookie => {
146
236
  if (cookie && this.storeEngine) {
147
237
  try {
148
238
  await this.persistCookie(this.storeEngine, cookie);
149
- }
150
- catch (error) {
239
+ } catch (error) {
151
240
  this.logger.error(`Failed to save cookie: ${error.message}`, error);
152
241
  }
153
242
  }
@@ -178,14 +267,27 @@ class Account extends commons_1.TypedEventEmitter {
178
267
  const entity = { expiration: cookie.expiration, zuid: cookie.zuid };
179
268
  return storeEngine.updateOrCreate(auth_1.AUTH_TABLE_NAME, auth_1.AUTH_COOKIE_KEY, entity);
180
269
  }
181
- async enrollE2EI({ displayName, handle, teamId, discoveryUrl, getOAuthToken, certificateTtl = 90 * (TimeUtil_1.TimeInMillis.DAY / 1000), }) {
182
- var _a, _b, _c, _d;
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;
183
281
  const context = this.apiClient.context;
184
- const domain = (_a = context === null || context === void 0 ? void 0 : context.domain) !== null && _a !== void 0 ? _a : '';
282
+ const domain =
283
+ (_a = context === null || context === void 0 ? void 0 : context.domain) !== null && _a !== void 0 ? _a : '';
185
284
  if (!this.currentClient) {
186
285
  throw new Error('Client has not been initialized - please login first');
187
286
  }
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)) {
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
+ ) {
189
291
  throw new Error('MLS not initialized, unable to enroll E2EI');
190
292
  }
191
293
  const user = {
@@ -195,7 +297,14 @@ class Account extends commons_1.TypedEventEmitter {
195
297
  teamId,
196
298
  id: this.userId,
197
299
  };
198
- return this.service.mls.enrollE2EI(discoveryUrl, user, this.currentClient, this.options.nbPrekeys, certificateTtl, getOAuthToken);
300
+ return this.service.mls.enrollE2EI(
301
+ discoveryUrl,
302
+ user,
303
+ this.currentClient,
304
+ this.options.nbPrekeys,
305
+ certificateTtl,
306
+ getOAuthToken,
307
+ );
199
308
  }
200
309
  get clientId() {
201
310
  return this.apiClient.validatedClientId;
@@ -240,9 +349,12 @@ class Account extends commons_1.TypedEventEmitter {
240
349
  /**
241
350
  * Will register a new client for the current user
242
351
  */
243
- async registerClient(loginData, clientInfo = coreDefaultClient,
244
- /** will add extra manual entropy to the client's identity being created */
245
- entropyData) {
352
+ async registerClient(
353
+ loginData,
354
+ clientInfo = coreDefaultClient,
355
+ /** will add extra manual entropy to the client's identity being created */
356
+ entropyData,
357
+ ) {
246
358
  if (!this.service || !this.apiClient.context || !this.storeEngine) {
247
359
  throw new Error('Services are not set or context not initialized.');
248
360
  }
@@ -256,7 +368,7 @@ class Account extends commons_1.TypedEventEmitter {
256
368
  return client;
257
369
  }
258
370
  getLocalClient() {
259
- var _a;
371
+ let _a;
260
372
  return (_a = this.service) === null || _a === void 0 ? void 0 : _a.client.loadClient();
261
373
  }
262
374
  /**
@@ -264,7 +376,7 @@ class Account extends commons_1.TypedEventEmitter {
264
376
  *
265
377
  * @returns The local existing client or undefined if the client does not exist or is not valid (non existing on backend)
266
378
  */
267
- async initClient(client, mlsConfig) {
379
+ async initClient(client, willEnrollE2ei = false) {
268
380
  if (!this.service || !this.apiClient.context || !this.storeEngine) {
269
381
  throw new Error('Services are not set.');
270
382
  }
@@ -272,9 +384,9 @@ class Account extends commons_1.TypedEventEmitter {
272
384
  // Call /access endpoint with client_id after client initialisation
273
385
  await this.apiClient.transport.http.associateClientWithSession(client.id);
274
386
  await this.service.proteus.initClient(this.storeEngine, this.apiClient.context);
275
- if (this.service.mls && mlsConfig) {
387
+ if (this.service.mls) {
276
388
  const { userId, domain = '' } = this.apiClient.context;
277
- await this.service.mls.initClient({ id: userId, domain }, client, mlsConfig);
389
+ await this.service.mls.initClient({ id: userId, domain }, client, willEnrollE2ei);
278
390
  // initialize schedulers for pending mls proposals once client is initialized
279
391
  await this.service.mls.initialisePendingProposalsTasks();
280
392
  // initialize scheduler for syncing key packages with backend
@@ -288,7 +400,7 @@ class Account extends commons_1.TypedEventEmitter {
288
400
  async buildCryptoClient(context, storeEngine, encryptedStore) {
289
401
  const baseConfig = {
290
402
  nbPrekeys: this.options.nbPrekeys,
291
- onNewPrekeys: async (prekeys) => {
403
+ onNewPrekeys: async prekeys => {
292
404
  this.logger.debug(`Received '${prekeys.length}' new PreKeys.`);
293
405
  await this.apiClient.api.client.putClient(context.clientId, { prekeys });
294
406
  this.logger.debug(`Successfully uploaded '${prekeys.length}' PreKeys.`);
@@ -296,11 +408,20 @@ class Account extends commons_1.TypedEventEmitter {
296
408
  };
297
409
  const coreCryptoConfig = this.coreCryptoConfig;
298
410
  if (coreCryptoConfig) {
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 }) }));
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
+ });
301
420
  return [CryptoClient_1.CryptoClientType.CORE_CRYPTO, client];
302
421
  }
303
- const { buildClient } = await Promise.resolve().then(() => __importStar(require('./messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper')));
422
+ const { buildClient } = await Promise.resolve().then(() =>
423
+ __importStar(require('./messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper')),
424
+ );
304
425
  const client = buildClient(storeEngine, baseConfig);
305
426
  return [CryptoClient_1.CryptoClientType.CRYPTOBOX, client];
306
427
  }
@@ -315,6 +436,7 @@ class Account extends commons_1.TypedEventEmitter {
315
436
  this.coreCallbacks = coreCallbacks;
316
437
  }
317
438
  async initServices(context) {
439
+ let _a;
318
440
  const encryptedStoreName = this.generateEncryptedDbName(context);
319
441
  this.encryptedDb = this.options.systemCrypto
320
442
  ? await (0, encryptedStore_1.createCustomEncryptedStore)(encryptedStoreName, this.options.systemCrypto)
@@ -332,16 +454,43 @@ class Account extends commons_1.TypedEventEmitter {
332
454
  nbPrekeys: this.options.nbPrekeys,
333
455
  });
334
456
  const clientService = new client_2.ClientService(this.apiClient, proteusService, this.storeEngine);
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);
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
+ );
338
472
  }
339
473
  const connectionService = new connection_1.ConnectionService(this.apiClient);
340
474
  const giphyService = new giphy_1.GiphyService(this.apiClient);
341
475
  const linkPreviewService = new linkPreview_1.LinkPreviewService(assetService);
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);
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
+ );
345
494
  const selfService = new self_1.SelfService(this.apiClient);
346
495
  const teamService = new team_1.TeamService(this.apiClient);
347
496
  const broadcastService = new broadcast_1.BroadcastService(this.apiClient, proteusService);
@@ -375,7 +524,8 @@ class Account extends commons_1.TypedEventEmitter {
375
524
  * @param clearData if set to `true` will completely wipe any database that was created by the Account
376
525
  */
377
526
  async logout(clearData = false) {
378
- var _a, _b;
527
+ let _a;
528
+ let _b;
379
529
  (_a = this.db) === null || _a === void 0 ? void 0 : _a.close();
380
530
  (_b = this.encryptedDb) === null || _b === void 0 ? void 0 : _b.close();
381
531
  if (clearData) {
@@ -388,20 +538,14 @@ class Account extends commons_1.TypedEventEmitter {
388
538
  * Will delete the identity of the current user
389
539
  */
390
540
  async wipe() {
391
- var _a, _b;
541
+ let _a;
542
+ let _b;
392
543
  await ((_a = this.service) === null || _a === void 0 ? void 0 : _a.proteus.wipe(this.storeEngine));
393
544
  if (this.db) {
394
545
  await (0, CoreDB_1.deleteDB)(this.db);
395
546
  }
396
547
  await ((_b = this.encryptedDb) === null || _b === void 0 ? void 0 : _b.wipe());
397
548
  }
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
- }
405
549
  /**
406
550
  * Will download and handle the notification stream since last stored notification id.
407
551
  * Once the notification stream has been handled from backend, will then connect to the websocket and start listening to incoming events
@@ -409,7 +553,13 @@ class Account extends commons_1.TypedEventEmitter {
409
553
  * @param callbacks callbacks that will be called to handle different events
410
554
  * @returns close a function that will disconnect from the websocket
411
555
  */
412
- listen({ onEvent = () => { }, onConnectionStateChanged = () => { }, onNotificationStreamProgress = () => { }, onMissedNotifications = () => { }, dryRun = false, } = {}) {
556
+ listen({
557
+ onEvent = () => { },
558
+ onConnectionStateChanged = () => { },
559
+ onNotificationStreamProgress = () => { },
560
+ onMissedNotifications = () => { },
561
+ dryRun = false,
562
+ } = {}) {
413
563
  if (!this.currentClient) {
414
564
  throw new Error('Client has not been initialized - please login first');
415
565
  }
@@ -417,7 +567,10 @@ class Account extends commons_1.TypedEventEmitter {
417
567
  const { event } = payload;
418
568
  switch (event === null || event === void 0 ? void 0 : event.type) {
419
569
  case event_1.CONVERSATION_EVENT.MESSAGE_TIMER_UPDATE: {
420
- const { data: { message_timer }, conversation, } = event;
570
+ const {
571
+ data: { message_timer },
572
+ conversation,
573
+ } = event;
421
574
  const expireAfterMillis = Number(message_timer);
422
575
  this.service.conversation.messageTimer.setConversationLevelTimer(conversation, expireAfterMillis);
423
576
  break;
@@ -426,31 +579,44 @@ class Account extends commons_1.TypedEventEmitter {
426
579
  await onEvent(payload, source);
427
580
  };
428
581
  const handleNotification = async (notification, source) => {
429
- var _a, e_1, _b, _c;
582
+ let _a;
583
+ let _b;
584
+ let _c;
585
+ let e_1;
430
586
  try {
431
587
  const messages = this.service.notification.handleNotification(notification, source, dryRun);
432
588
  try {
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) {
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
+ ) {
434
594
  _c = messages_1_1.value;
435
595
  _d = false;
436
596
  const message = _c;
437
597
  await handleEvent(message, source);
438
598
  }
439
- }
440
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
441
- finally {
599
+ } catch (e_1_1) {
600
+ e_1 = { error: e_1_1 };
601
+ } finally {
442
602
  try {
443
- if (!_d && !_a && (_b = messages_1.return)) await _b.call(messages_1);
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
+ }
444
610
  }
445
- finally { if (e_1) throw e_1.error; }
446
611
  }
447
- }
448
- catch (error) {
612
+ } catch (error) {
449
613
  this.logger.error(`Failed to handle notification ID "${notification.id}": ${error.message}`, error);
450
614
  }
451
615
  };
452
616
  this.apiClient.transport.ws.removeAllListeners(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE);
453
- this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE, notification => handleNotification(notification, notification_1.NotificationSource.WEBSOCKET));
617
+ this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE, notification =>
618
+ handleNotification(notification, notification_1.NotificationSource.WEBSOCKET),
619
+ );
454
620
  this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_STATE_CHANGE, wsState => {
455
621
  const mapping = {
456
622
  [ReconnectingWebsocket_1.WEBSOCKET_STATE.CLOSED]: ConnectionState.CLOSED,
@@ -461,23 +627,30 @@ class Account extends commons_1.TypedEventEmitter {
461
627
  onConnectionStateChanged(connectionState);
462
628
  }
463
629
  });
464
- const handleMissedNotifications = async (notificationId) => {
465
- if (this.hasMLSDevice) {
466
- (0, conversationRejoinQueue_1.queueConversationRejoin)('all-conversations', () => this.service.conversation.handleConversationsEpochMismatch());
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
+ );
467
636
  }
468
637
  return onMissedNotifications(notificationId);
469
638
  };
470
- const processNotificationStream = async (abortHandler) => {
639
+ const processNotificationStream = async abortHandler => {
471
640
  // Lock websocket in order to buffer any message that arrives while we handle the notification stream
472
641
  this.apiClient.transport.ws.lock();
473
642
  (0, messageSender_1.pauseMessageSending)();
474
643
  // We want to avoid triggering rejoins of out-of-sync MLS conversations while we are processing the notification stream
475
644
  (0, conversationRejoinQueue_1.pauseRejoiningMLSConversations)();
476
645
  onConnectionStateChanged(ConnectionState.PROCESSING_NOTIFICATIONS);
477
- const results = await this.service.notification.processNotificationStream(async (notification, source, progress) => {
478
- await handleNotification(notification, source);
479
- onNotificationStreamProgress(progress);
480
- }, handleMissedNotifications, abortHandler);
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
+ );
481
654
  this.logger.info(`Finished processing notifications ${JSON.stringify(results)}`, results);
482
655
  if (abortHandler.isAborted()) {
483
656
  this.logger.warn('Ending connection process as websocket was closed');
@@ -513,9 +686,16 @@ class Account extends commons_1.TypedEventEmitter {
513
686
  const dbName = this.generateDbName(context);
514
687
  this.logger.log(`Initialising store with name "${dbName}"...`);
515
688
  const openDb = async () => {
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));
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));
519
699
  if (initializedDb) {
520
700
  this.logger.info(`Initialized store with existing engine "${dbName}".`);
521
701
  return initializedDb;