@wireapp/core 46.24.4 → 46.25.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.
Files changed (51) hide show
  1. package/lib/Account.d.ts +7 -8
  2. package/lib/Account.d.ts.map +1 -1
  3. package/lib/Account.js +17 -23
  4. package/lib/client/ClientService.js +1 -1
  5. package/lib/conversation/ConversationService/ConversationService.d.ts +12 -8
  6. package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
  7. package/lib/conversation/ConversationService/ConversationService.js +11 -13
  8. package/lib/conversation/ConversationService/ConversationService.test.js +5 -11
  9. package/lib/messagingProtocols/common.types.d.ts +9 -0
  10. package/lib/messagingProtocols/common.types.d.ts.map +1 -1
  11. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIService.types.d.ts +2 -2
  12. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIService.types.d.ts.map +1 -1
  13. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIService.types.js +2 -1
  14. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.d.ts.map +1 -1
  15. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.js +6 -5
  16. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.test.js +20 -15
  17. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.d.ts +9 -3
  18. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.d.ts.map +1 -1
  19. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.js +30 -12
  20. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.d.ts.map +1 -1
  21. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.js +7 -2
  22. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.test.js +0 -34
  23. package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.test.js +2 -2
  24. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts +16 -31
  25. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts.map +1 -1
  26. package/lib/messagingProtocols/mls/MLSService/MLSService.js +74 -171
  27. package/lib/messagingProtocols/mls/MLSService/MLSService.test.js +93 -151
  28. package/lib/messagingProtocols/mls/types.d.ts +0 -8
  29. package/lib/messagingProtocols/mls/types.d.ts.map +1 -1
  30. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts +4 -13
  31. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts.map +1 -1
  32. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.js +79 -62
  33. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts +0 -2
  34. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts.map +1 -1
  35. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts +5 -3
  36. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts.map +1 -1
  37. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.js +14 -14
  38. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts.map +1 -1
  39. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.js +3 -1
  40. package/lib/messagingProtocols/proteus/ProteusService/WithMockedGenerics.test.js +3 -0
  41. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.test.js +3 -0
  42. package/lib/secretStore/secretKeyGenerator.d.ts +1 -0
  43. package/lib/secretStore/secretKeyGenerator.d.ts.map +1 -1
  44. package/lib/secretStore/secretKeyGenerator.js +3 -1
  45. package/lib/team/TeamService.d.ts +5 -2
  46. package/lib/team/TeamService.d.ts.map +1 -1
  47. package/lib/team/TeamService.js +12 -2
  48. package/lib/test/StoreHelper.d.ts +2 -0
  49. package/lib/test/StoreHelper.d.ts.map +1 -0
  50. package/lib/test/StoreHelper.js +27 -0
  51. package/package.json +6 -6
@@ -19,16 +19,12 @@
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.MLSService = exports.MLSServiceEvents = exports.optionalToUint8Array = void 0;
22
- const http_1 = require("@wireapp/api-client/lib/http");
23
- const TimeUtil_1 = require("@wireapp/commons/lib/util/TimeUtil");
24
22
  const bazinga64_1 = require("bazinga64");
25
23
  const commons_1 = require("@wireapp/commons");
26
24
  const core_crypto_1 = require("@wireapp/core-crypto");
27
- const priority_queue_1 = require("@wireapp/priority-queue");
28
25
  const ClientMLSError_1 = require("./ClientMLSError");
29
26
  const CoreCryptoMLSError_1 = require("./CoreCryptoMLSError");
30
27
  const conversation_1 = require("../../../conversation");
31
- const messageSender_1 = require("../../../conversation/message/messageSender");
32
28
  const fullyQualifiedClientIdUtils_1 = require("../../../util/fullyQualifiedClientIdUtils");
33
29
  const numberToHex_1 = require("../../../util/numberToHex");
34
30
  const TaskScheduler_1 = require("../../../util/TaskScheduler");
@@ -52,6 +48,7 @@ var MLSServiceEvents;
52
48
  MLSServiceEvents["NEW_EPOCH"] = "newEpoch";
53
49
  MLSServiceEvents["MLS_CLIENT_MISMATCH"] = "mlsClientMismatch";
54
50
  MLSServiceEvents["NEW_CRL_DISTRIBUTION_POINTS"] = "newCrlDistributionPoints";
51
+ MLSServiceEvents["MLS_EVENT_DISTRIBUTED"] = "mlsEventDistributed";
55
52
  })(MLSServiceEvents || (exports.MLSServiceEvents = MLSServiceEvents = {}));
56
53
  class MLSService extends commons_1.TypedEventEmitter {
57
54
  apiClient;
@@ -62,18 +59,27 @@ class MLSService extends commons_1.TypedEventEmitter {
62
59
  _config;
63
60
  textEncoder = new TextEncoder();
64
61
  textDecoder = new TextDecoder();
65
- conflictBackoffQueue = new priority_queue_1.PriorityQueue({
66
- maxRetries: 10,
67
- retryDelay: 500,
68
- maxRetryDelay: TimeUtil_1.TimeInMillis.SECOND * 32,
69
- shouldRetry: error => error instanceof http_1.BackendError && error.code === http_1.StatusCode.CONFLICT,
70
- });
71
62
  constructor(apiClient, coreCryptoClient, coreDatabase, recurringTaskScheduler) {
72
63
  super();
73
64
  this.apiClient = apiClient;
74
65
  this.coreCryptoClient = coreCryptoClient;
75
66
  this.coreDatabase = coreDatabase;
76
67
  this.recurringTaskScheduler = recurringTaskScheduler;
68
+ const mlsTransport = {
69
+ sendCommitBundle: this._uploadCommitBundle,
70
+ // Info: This is not used for now, but we need to implement it to be able to use the mls transport
71
+ sendMessage: async () => {
72
+ return 'success';
73
+ },
74
+ };
75
+ const epochObserver = {
76
+ epochChanged: async (groupId, epoch) => {
77
+ const groupIdStr = bazinga64_1.Encoder.toBase64(groupId).asString;
78
+ this.emit(MLSServiceEvents.NEW_EPOCH, { epoch, groupId: groupIdStr });
79
+ },
80
+ };
81
+ void this.coreCryptoClient.registerEpochObserver(epochObserver);
82
+ void this.coreCryptoClient.provideTransport(mlsTransport);
77
83
  }
78
84
  /**
79
85
  * return true if the MLS service if configured and ready to be used
@@ -103,13 +109,7 @@ class MLSService extends commons_1.TypedEventEmitter {
103
109
  ...defaultConfig,
104
110
  ...filteredMLSConfig,
105
111
  };
106
- await this.coreCryptoClient.mlsInit((0, MLSId_1.generateMLSDeviceId)(userId, client.id), this.config.ciphersuites, this.config.nbKeyPackages);
107
- await this.coreCryptoClient.registerCallbacks({
108
- // All authorization/membership rules are enforced on backend
109
- clientIsExistingGroupUser: async () => true,
110
- authorize: async () => true,
111
- userAuthorize: async () => true,
112
- });
112
+ await this.coreCryptoClient.transaction(cx => cx.mlsInit((0, MLSId_1.generateMLSDeviceId)(userId, client.id), this.config.ciphersuites, this.config.nbKeyPackages));
113
113
  try {
114
114
  const ccClientSignature = await this.getCCClientSignatureString();
115
115
  const mlsDeviceStatus = (0, Helper_1.getMLSDeviceStatus)(client, this.config.defaultCiphersuite, ccClientSignature);
@@ -151,47 +151,25 @@ class MLSService extends commons_1.TypedEventEmitter {
151
151
  ? core_crypto_1.CredentialType.X509
152
152
  : core_crypto_1.CredentialType.Basic;
153
153
  }
154
- uploadCommitBundle = async (groupId, commitBundle, { isExternalCommit = false, regenerateCommitBundle } = {}) => {
154
+ _uploadCommitBundle = async ({ commit, groupInfo, welcome, }) => {
155
+ const bundlePayload = new Uint8Array([...commit, ...groupInfo.payload, ...(welcome || [])]);
155
156
  try {
156
- return await this._uploadCommitBundle(groupId, async () => commitBundle, isExternalCommit);
157
+ const response = await this.apiClient.api.conversation.postMlsCommitBundle(bundlePayload);
158
+ if (response.failed_to_send) {
159
+ this.logger.warn(`Failed to send commit bundle to backend`);
160
+ return 'retry';
161
+ }
162
+ const { events, time } = response;
163
+ this.emit(MLSServiceEvents.MLS_EVENT_DISTRIBUTED, { events, time });
164
+ return 'success';
157
165
  }
158
166
  catch (error) {
159
- if (error instanceof http_1.BackendError && error.code === http_1.StatusCode.CONFLICT && regenerateCommitBundle) {
160
- return this.conflictBackoffQueue.add(async () => this._uploadCommitBundle(groupId, regenerateCommitBundle, isExternalCommit));
161
- }
162
- throw error;
167
+ this.logger.error(`Failed to upload commit bundle`, error);
168
+ return {
169
+ abort: { reason: error instanceof Error ? error.message : 'unknown error' },
170
+ };
163
171
  }
164
172
  };
165
- _uploadCommitBundle = async (groupId, generateCommitBundle, isExternalCommit) => {
166
- const groupIdStr = bazinga64_1.Encoder.toBase64(groupId).asString;
167
- // We need to lock the incoming mls messages queue while we are uploading the commit bundle
168
- // it's possible that we will be sent some mls messages before we receive the response from backend and accept a commit locally.
169
- return (0, messageAdd_1.withLockedMLSMessagesQueue)(groupIdStr, async () => {
170
- const { commit, groupInfo, welcome } = await generateCommitBundle();
171
- const bundlePayload = new Uint8Array([...commit, ...groupInfo.payload, ...(welcome || [])]);
172
- try {
173
- const response = await this.apiClient.api.conversation.postMlsCommitBundle(bundlePayload);
174
- if (isExternalCommit) {
175
- await this.coreCryptoClient.mergePendingGroupFromExternalCommit(groupId);
176
- }
177
- else {
178
- await this.coreCryptoClient.commitAccepted(groupId);
179
- }
180
- const newEpoch = await this.getEpoch(groupId);
181
- this.emit(MLSServiceEvents.NEW_EPOCH, { epoch: newEpoch, groupId: groupIdStr });
182
- return response;
183
- }
184
- catch (error) {
185
- if (isExternalCommit) {
186
- await this.coreCryptoClient.clearPendingGroupFromExternalCommit(groupId);
187
- }
188
- else {
189
- await this.coreCryptoClient.clearPendingCommit(groupId);
190
- }
191
- throw error;
192
- }
193
- });
194
- };
195
173
  /**
196
174
  * Will add users to an existing MLS group and send a commit bundle to backend.
197
175
  * Cannot be called with an empty array of keys.
@@ -204,23 +182,8 @@ class MLSService extends commons_1.TypedEventEmitter {
204
182
  if (keyPackages.length < 1) {
205
183
  throw new Error('Empty list of keys provided to addUsersToExistingConversation');
206
184
  }
207
- // TODO: handle federation error when sending a commit bundle to backend like we do in ProteusService
208
- const response = await this.processCommitAction(groupIdBytes, async () => {
209
- const commitBundle = await this.coreCryptoClient.addClientsToConversation(groupIdBytes, keyPackages);
210
- this.dispatchNewCrlDistributionPoints(commitBundle);
211
- return commitBundle;
212
- });
213
- const failedUsers = response.failed;
214
- const failures = failedUsers
215
- ? [
216
- {
217
- users: failedUsers,
218
- backends: failedUsers.map(({ domain }) => domain),
219
- reason: conversation_1.AddUsersFailureReasons.UNREACHABLE_BACKENDS,
220
- },
221
- ]
222
- : [];
223
- return { ...response, failures };
185
+ const crlNewDistributionPoints = await this.coreCryptoClient.transaction(cx => cx.addClientsToConversation(groupIdBytes, keyPackages));
186
+ this.dispatchNewCrlDistributionPoints(crlNewDistributionPoints);
224
187
  }
225
188
  /**
226
189
  * Will return a list of client ids which are already in the group at core crypto level
@@ -302,90 +265,55 @@ class MLSService extends commons_1.TypedEventEmitter {
302
265
  const groupIdBytes = typeof groupId === 'string' ? bazinga64_1.Decoder.fromBase64(groupId).asBytes : groupId;
303
266
  return this.coreCryptoClient.conversationEpoch(groupIdBytes);
304
267
  }
305
- async newProposal(proposalType, args) {
306
- return this.coreCryptoClient.newProposal(proposalType, args);
307
- }
308
268
  async joinByExternalCommit(getGroupInfo) {
309
269
  const credentialType = await this.getCredentialType();
310
- const generateCommit = async () => {
311
- const groupInfo = await getGroupInfo();
312
- const joinRequest = await this.coreCryptoClient.joinByExternalCommit(groupInfo, credentialType);
313
- this.dispatchNewCrlDistributionPoints(joinRequest);
314
- const { conversationId, ...commitBundle } = joinRequest;
315
- return { groupId: conversationId, commitBundle };
316
- };
317
- const { commitBundle, groupId } = await generateCommit();
318
- const mlsResponse = await this.uploadCommitBundle(groupId, commitBundle, {
319
- isExternalCommit: true,
320
- regenerateCommitBundle: async () => (await generateCommit()).commitBundle,
321
- });
322
- if (mlsResponse) {
270
+ const groupInfo = await getGroupInfo();
271
+ const welcomeBundle = await this.coreCryptoClient.transaction(cx => cx.joinByExternalCommit(groupInfo, credentialType));
272
+ await this.dispatchNewCrlDistributionPoints(welcomeBundle.crlNewDistributionPoints);
273
+ if (welcomeBundle.id) {
323
274
  //after we've successfully joined via external commit, we schedule periodic key material renewal
324
- const groupIdStr = bazinga64_1.Encoder.toBase64(groupId).asString;
275
+ const groupIdStr = bazinga64_1.Encoder.toBase64(welcomeBundle.id).asString;
325
276
  await this.scheduleKeyMaterialRenewal(groupIdStr);
326
277
  }
327
- return mlsResponse;
328
278
  }
329
279
  async exportSecretKey(groupId, keyLength) {
330
280
  const groupIdBytes = bazinga64_1.Decoder.fromBase64(groupId).asBytes;
331
281
  const key = await this.coreCryptoClient.exportSecretKey(groupIdBytes, keyLength);
332
282
  return bazinga64_1.Encoder.toBase64(key).asString;
333
283
  }
334
- dispatchNewCrlDistributionPoints(payload) {
335
- const { crlNewDistributionPoints } = payload;
284
+ dispatchNewCrlDistributionPoints(crlNewDistributionPoints) {
336
285
  if (crlNewDistributionPoints && crlNewDistributionPoints.length > 0) {
337
286
  this.emit(MLSServiceEvents.NEW_CRL_DISTRIBUTION_POINTS, crlNewDistributionPoints);
338
287
  }
339
288
  }
340
289
  async processWelcomeMessage(welcomeMessage) {
341
- const welcomeBundle = await this.coreCryptoClient.processWelcomeMessage(welcomeMessage);
342
- this.dispatchNewCrlDistributionPoints(welcomeBundle);
290
+ const welcomeBundle = await this.coreCryptoClient.transaction(cx => cx.processWelcomeMessage(welcomeMessage));
291
+ this.dispatchNewCrlDistributionPoints(welcomeBundle.crlNewDistributionPoints);
343
292
  return welcomeBundle.id;
344
293
  }
345
294
  async decryptMessage(conversationId, payload) {
346
- return await this.coreCryptoClient.transaction(async (cx) => {
347
- try {
348
- const decryptedMessage = await cx.decryptMessage(conversationId, payload);
349
- this.dispatchNewCrlDistributionPoints(decryptedMessage);
350
- return decryptedMessage;
351
- }
352
- catch (error) {
353
- // According to CoreCrypto JS doc on .decryptMessage method, we should ignore some errors (corecrypto handle them internally)
354
- if ((0, CoreCryptoMLSError_1.shouldMLSDecryptionErrorBeIgnored)(error)) {
355
- return {
356
- hasEpochChanged: false,
357
- isActive: false,
358
- proposals: [],
359
- };
360
- }
361
- throw error;
295
+ try {
296
+ const decryptedMessage = await this.coreCryptoClient.transaction(cx => cx.decryptMessage(conversationId, payload));
297
+ this.dispatchNewCrlDistributionPoints(decryptedMessage.crlNewDistributionPoints);
298
+ return decryptedMessage;
299
+ }
300
+ catch (error) {
301
+ // According to CoreCrypto JS doc on .decryptMessage method, we should ignore some errors (corecrypto handle them internally)
302
+ if ((0, CoreCryptoMLSError_1.shouldMLSDecryptionErrorBeIgnored)(error)) {
303
+ return {
304
+ hasEpochChanged: false,
305
+ isActive: false,
306
+ };
362
307
  }
363
- });
308
+ return undefined;
309
+ }
364
310
  }
365
311
  async encryptMessage(conversationId, message) {
366
- return this.coreCryptoClient.encryptMessage(conversationId, message);
312
+ return this.coreCryptoClient.transaction(cx => cx.encryptMessage(conversationId, message));
367
313
  }
368
- /**
369
- * Will wrap a coreCrypto call that generates a CommitBundle and do all the necessary work so that commitbundle is handled the right way.
370
- * It does:
371
- * - commit the pending proposal
372
- * - then generates the commitBundle with the given function
373
- * - uploads the commitBundle to backend
374
- * - warns coreCrypto that the commit was successfully processed
375
- * @param groupId
376
- * @param generateCommit The function that will generate a coreCrypto CommitBundle
377
- */
378
- async processCommitAction(groupId, generateCommit) {
379
- const groupIdStr = bazinga64_1.Encoder.toBase64(groupId).asString;
380
- return (0, messageSender_1.sendMessage)(async () => {
381
- await this.commitPendingProposals(groupIdStr);
382
- const commitBundle = await generateCommit();
383
- return this.uploadCommitBundle(groupId, commitBundle, { regenerateCommitBundle: generateCommit });
384
- });
385
- }
386
- updateKeyingMaterial(groupId) {
314
+ async updateKeyingMaterial(groupId) {
387
315
  const groupIdBytes = bazinga64_1.Decoder.fromBase64(groupId).asBytes;
388
- return this.processCommitAction(groupIdBytes, () => this.coreCryptoClient.updateKeyingMaterial(groupIdBytes));
316
+ await this.coreCryptoClient.transaction(cx => cx.updateKeyingMaterial(groupIdBytes));
389
317
  }
390
318
  /**
391
319
  * Will create an empty conversation inside of coreCrypto.
@@ -413,7 +341,7 @@ class MLSService extends commons_1.TypedEventEmitter {
413
341
  ciphersuite: this.config.defaultCiphersuite,
414
342
  };
415
343
  const credentialType = await this.getCredentialType();
416
- return this.coreCryptoClient.createConversation(groupIdBytes, credentialType, configuration);
344
+ return this.coreCryptoClient.transaction(cx => cx.createConversation(groupIdBytes, credentialType, configuration));
417
345
  }
418
346
  /**
419
347
  * Will create a conversation inside of coreCrypto, add users to it or update the keying material if empty key packages list is provided.
@@ -437,19 +365,18 @@ class MLSService extends commons_1.TypedEventEmitter {
437
365
  }));
438
366
  if (keyPackages.length <= 0) {
439
367
  // If there are no clients to add, just update the keying material
440
- const response = await this.updateKeyingMaterial(groupId);
368
+ await this.updateKeyingMaterial(groupId);
441
369
  await this.scheduleKeyMaterialRenewal(groupId);
442
- return { ...response, failures: keysClaimingFailures };
370
+ return keysClaimingFailures;
443
371
  }
444
- const response = await this.addUsersToExistingConversation(groupId, keyPackages);
372
+ await this.addUsersToExistingConversation(groupId, keyPackages);
445
373
  // We schedule a periodic key material renewal
446
374
  await this.scheduleKeyMaterialRenewal(groupId);
447
375
  /**
448
376
  * @note If we can't fetch a user's key packages then we can not add them to mls conversation
449
377
  * so we're adding them to the list of failed users.
450
378
  */
451
- response.failures = [...keysClaimingFailures, ...response.failures];
452
- return response;
379
+ return keysClaimingFailures;
453
380
  }
454
381
  /**
455
382
  * Will create a 1:1 conversation inside of coreCrypto, try claiming key packages for user and (if succesfull) add them to the MLS group.
@@ -472,14 +399,10 @@ class MLSService extends commons_1.TypedEventEmitter {
472
399
  const { keyPackages: selfKeyPackages, failures: selfKeysClaimingFailures } = await this.getKeyPackagesPayload([
473
400
  { ...selfUser.user, skipOwnClientId: selfUser.client },
474
401
  ]);
475
- const response = await this.addUsersToExistingConversation(groupId, [
476
- ...otherUserKeyPackages,
477
- ...selfKeyPackages,
478
- ]);
402
+ await this.addUsersToExistingConversation(groupId, [...otherUserKeyPackages, ...selfKeyPackages]);
479
403
  // We schedule a periodic key material renewal
480
404
  await this.scheduleKeyMaterialRenewal(groupId);
481
- response.failures = [...otherUserKeysClaimingFailures, ...selfKeysClaimingFailures, ...response.failures];
482
- return response;
405
+ return [...otherUserKeysClaimingFailures, ...selfKeysClaimingFailures];
483
406
  }
484
407
  catch (error) {
485
408
  await this.wipeConversation(groupId);
@@ -525,7 +448,7 @@ class MLSService extends commons_1.TypedEventEmitter {
525
448
  */
526
449
  removeClientsFromConversation(groupId, clientIds) {
527
450
  const groupIdBytes = bazinga64_1.Decoder.fromBase64(groupId).asBytes;
528
- return this.processCommitAction(groupIdBytes, () => this.coreCryptoClient.removeClientsFromConversation(groupIdBytes, clientIds.map(id => this.textEncoder.encode(id))));
451
+ return this.coreCryptoClient.transaction(cx => cx.removeClientsFromConversation(groupIdBytes, clientIds.map(id => this.textEncoder.encode(id))));
529
452
  }
530
453
  /**
531
454
  * Will check if mls group exists in corecrypto.
@@ -546,11 +469,11 @@ class MLSService extends commons_1.TypedEventEmitter {
546
469
  }
547
470
  async clientValidKeypackagesCount() {
548
471
  const credentialType = await this.getCredentialType();
549
- return this.coreCryptoClient.clientValidKeypackagesCount(this.config.defaultCiphersuite, credentialType);
472
+ return this.coreCryptoClient.transaction(cx => cx.clientValidKeypackagesCount(this.config.defaultCiphersuite, credentialType));
550
473
  }
551
474
  async clientKeypackages(amountRequested) {
552
475
  const credentialType = await this.getCredentialType();
553
- return this.coreCryptoClient.clientKeypackages(this.config.defaultCiphersuite, credentialType, amountRequested);
476
+ return this.coreCryptoClient.transaction(cx => cx.clientKeypackages(this.config.defaultCiphersuite, credentialType, amountRequested));
554
477
  }
555
478
  /**
556
479
  * Will send an empty commit into a group (renew key material)
@@ -697,7 +620,7 @@ class MLSService extends commons_1.TypedEventEmitter {
697
620
  return;
698
621
  }
699
622
  const groupIdBytes = bazinga64_1.Decoder.fromBase64(groupId).asBytes;
700
- return this.coreCryptoClient.wipeConversation(groupIdBytes);
623
+ return this.coreCryptoClient.transaction(cx => cx.wipeConversation(groupIdBytes));
701
624
  }
702
625
  /**
703
626
  * If there are pending proposals, we need to either process them,
@@ -740,10 +663,7 @@ class MLSService extends commons_1.TypedEventEmitter {
740
663
  async commitPendingProposals(groupId, shouldRetry = true) {
741
664
  const groupIdBytes = bazinga64_1.Decoder.fromBase64(groupId).asBytes;
742
665
  try {
743
- const commitBundle = await this.coreCryptoClient.commitPendingProposals(groupIdBytes);
744
- if (commitBundle) {
745
- await this.uploadCommitBundle(groupIdBytes, commitBundle);
746
- }
666
+ await this.coreCryptoClient.transaction(cx => cx.commitPendingProposals(groupIdBytes));
747
667
  await this.cancelPendingProposalsTask(groupId);
748
668
  }
749
669
  catch (error) {
@@ -751,11 +671,6 @@ class MLSService extends commons_1.TypedEventEmitter {
751
671
  throw error;
752
672
  }
753
673
  this.logger.warn('Failed to commit proposals, clearing the pending commit and retrying', error);
754
- // If we failed to commit the proposals, we need to clear the pending commit and retry
755
- // this is to avoid a situation where we are stuck with pending proposals that we can't commit.
756
- // If there's nothing to clear the methods might throw an error, which we can ignore.
757
- await this.coreCryptoClient.clearPendingCommit(groupIdBytes).catch(() => undefined);
758
- await this.coreCryptoClient.clearPendingGroupFromExternalCommit(groupIdBytes).catch(() => undefined);
759
674
  return this.commitPendingProposals(groupId, false);
760
675
  }
761
676
  }
@@ -824,32 +739,20 @@ class MLSService extends commons_1.TypedEventEmitter {
824
739
  * @param oAuthIdToken The OAuth id token if the user is already authenticated
825
740
  * @returns AcmeChallenge if the user is not authenticated, true if the user is authenticated
826
741
  */
827
- async enrollE2EI(discoveryUrl, user, client, nbPrekeys, certificateTtl, getOAuthToken) {
742
+ async enrollE2EI(discoveryUrl, user, client, nbPrekeys, certificateTtl, getOAuthToken, getAllConversations) {
828
743
  const isCertificateRenewal = await this.coreCryptoClient.e2eiIsEnabled(this.config.defaultCiphersuite);
829
744
  const e2eiServiceInternal = new E2EIServiceInternal_1.E2EIServiceInternal(this.coreDatabase, this.coreCryptoClient, this.apiClient, certificateTtl, nbPrekeys, { user, clientId: client.id, discoveryUrl });
830
- const rotateBundle = await e2eiServiceInternal.generateCertificate(getOAuthToken, isCertificateRenewal, this.config.defaultCiphersuite);
831
- this.dispatchNewCrlDistributionPoints(rotateBundle);
745
+ const { keyPackages, newCrlDistributionPoints } = await e2eiServiceInternal.generateCertificate(getOAuthToken, isCertificateRenewal, getAllConversations, this.config.defaultCiphersuite);
746
+ this.dispatchNewCrlDistributionPoints(newCrlDistributionPoints);
832
747
  // upload the clients public keys
833
748
  if (!this.isInitializedMLSClient(client)) {
834
749
  // we only upload public keys for the initial certification process if the device is not already a registered MLS device.
835
750
  await this.uploadMLSPublicKeys(client);
836
751
  }
837
752
  // replace old key packages with new key packages with x509 certificate
838
- await this.replaceKeyPackages(client.id, rotateBundle.newKeyPackages);
753
+ await this.replaceKeyPackages(client.id, keyPackages);
839
754
  // Verify that we have enough key packages
840
755
  await this.verifyRemoteMLSKeyPackagesAmount(client.id);
841
- // Update keying material
842
- for (const [groupId, commitBundle] of rotateBundle.commits) {
843
- const groupIdAsBytes = bazinga64_1.Converter.hexStringToArrayBufferView(groupId);
844
- // manual copy of the commit bundle data because of a problem while cloning it
845
- const newCommitBundle = {
846
- commit: commitBundle.commit,
847
- // @ts-ignore
848
- groupInfo: commitBundle?.group_info || commitBundle.groupInfo,
849
- welcome: commitBundle?.welcome,
850
- };
851
- await this.uploadCommitBundle(groupIdAsBytes, newCommitBundle);
852
- }
853
756
  }
854
757
  }
855
758
  exports.MLSService = MLSService;