@wireapp/core 32.0.7 → 32.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -43,13 +43,14 @@
43
43
  "jest": "29.0.3",
44
44
  "jest-babel": "1.0.1",
45
45
  "jest-jasmine2": "29.0.3",
46
+ "jest-websocket-mock": "2.4.0",
46
47
  "karma": "6.4.1",
47
48
  "karma-chrome-launcher": "3.1.1",
48
49
  "karma-jasmine": "4.0.2",
49
50
  "karma-jasmine-diff-reporter": "2.0.1",
50
51
  "karma-sourcemap-loader": "0.3.8",
51
52
  "karma-spec-reporter": "0.0.34",
52
- "mock-socket": "9.0.3",
53
+ "mock-socket": "9.1.5",
53
54
  "nock": "13.1.1",
54
55
  "nyc": "15.1.0",
55
56
  "rimraf": "3.0.2",
@@ -81,6 +82,6 @@
81
82
  "test": "jest",
82
83
  "watch": "tsc ---watch"
83
84
  },
84
- "version": "32.0.7",
85
- "gitHead": "b8b83908d9516f9dc79e8e7591c0401618956caf"
85
+ "version": "32.1.0",
86
+ "gitHead": "33dcd430a801f27e7267f6d9d3dbaf4cd0869003"
86
87
  }
@@ -211,7 +211,7 @@ export declare class Account<T = any> extends EventEmitter {
211
211
  * When set will not decrypt and not store the last notification ID. This is useful if you only want to subscribe to unencrypted backend events
212
212
  */
213
213
  dryRun?: boolean;
214
- }): Promise<() => void>;
214
+ }): () => void;
215
215
  private generateDbName;
216
216
  private generateSecretsDbName;
217
217
  private initEngine;
@@ -377,7 +377,7 @@ class Account extends events_1.EventEmitter {
377
377
  * @param callbacks callbacks that will be called to handle different events
378
378
  * @returns close a function that will disconnect from the websocket
379
379
  */
380
- async listen({ onEvent = () => { }, onConnectionStateChanged = () => { }, onNotificationStreamProgress = () => { }, onMissedNotifications = () => { }, dryRun = false, } = {}) {
380
+ listen({ onEvent = () => { }, onConnectionStateChanged = () => { }, onNotificationStreamProgress = () => { }, onMissedNotifications = () => { }, dryRun = false, } = {}) {
381
381
  if (!this.apiClient.context) {
382
382
  throw new Error('Context is not set - please login first');
383
383
  }
@@ -432,8 +432,8 @@ class Account extends events_1.EventEmitter {
432
432
  });
433
433
  const processNotificationStream = async (abortHandler) => {
434
434
  // Lock websocket in order to buffer any message that arrives while we handle the notification stream
435
- onConnectionStateChanged(ConnectionState.PROCESSING_NOTIFICATIONS);
436
435
  this.apiClient.transport.ws.lock();
436
+ onConnectionStateChanged(ConnectionState.PROCESSING_NOTIFICATIONS);
437
437
  const results = await this.service.notification.processNotificationStream(async (notification, source, progress) => {
438
438
  await handleNotification(notification, source);
439
439
  onNotificationStreamProgress(progress);
@@ -443,13 +443,13 @@ class Account extends events_1.EventEmitter {
443
443
  this.logger.warn('Ending connection process as websocket was closed');
444
444
  return;
445
445
  }
446
+ onConnectionStateChanged(ConnectionState.LIVE);
446
447
  // We can now unlock the websocket and let the new messages being handled and decrypted
447
448
  this.apiClient.transport.ws.unlock();
448
449
  // We need to wait for the notification stream to be fully handled before releasing the message sending queue.
449
450
  // This is due to the nature of how message are encrypted, any change in mls epoch needs to happen before we start encrypting any kind of messages
450
451
  this.logger.info(`Resuming message sending. ${(0, messageSender_1.getQueueLength)()} messages to be sent`);
451
452
  (0, messageSender_1.resumeMessageSending)();
452
- onConnectionStateChanged(ConnectionState.LIVE);
453
453
  };
454
454
  this.apiClient.connect(processNotificationStream);
455
455
  return () => {
@@ -14,6 +14,7 @@ export declare class MLSService {
14
14
  addUsersToExistingConversation(groupId: Uint8Array, invitee: Invitee[]): Promise<import("@wireapp/api-client/src/conversation").PostMlsMessageResponse | null>;
15
15
  configureMLSCallbacks({ groupIdFromConversationId, ...coreCryptoCallbacks }: MLSCallbacks): void;
16
16
  getKeyPackagesPayload(qualifiedUsers: QualifiedUsers[]): Promise<Invitee[]>;
17
+ getEpoch(groupId: Uint8Array): Promise<number>;
17
18
  newProposal(proposalType: ProposalType, args: ProposalArgs | AddProposalArgs | RemoveProposalArgs): Promise<import("@wireapp/core-crypto").ProposalBundle>;
18
19
  newExternalProposal(externalProposalType: ExternalProposalType, args: ExternalProposalArgs | ExternalRemoveProposalArgs): Promise<Uint8Array>;
19
20
  processWelcomeMessage(welcomeMessage: Uint8Array): Promise<ConversationId>;
@@ -112,6 +112,9 @@ class MLSService {
112
112
  }, []);
113
113
  return coreCryptoKeyPackagesPayload;
114
114
  }
115
+ getEpoch(groupId) {
116
+ return this.getCoreCryptoClient().conversationEpoch(groupId);
117
+ }
115
118
  async newProposal(proposalType, args) {
116
119
  return this.getCoreCryptoClient().newProposal(proposalType, args);
117
120
  }
@@ -62,6 +62,13 @@ export declare class NotificationService extends EventEmitter {
62
62
  private isOutdatedEvent;
63
63
  handleNotification(notification: Notification, source: PayloadBundleSource, dryRun?: boolean): AsyncGenerator<HandledEventPayload>;
64
64
  private cleanupPayloadBundle;
65
+ /**
66
+ * Will process one event
67
+ * @param event The backend event to process
68
+ * @param source The source of the event (websocket or notication stream)
69
+ * @param dryRun Will not try to decrypt if true
70
+ * @return the decrypted payload and the raw event. Returns `undefined` when the payload is a coreCrypto-only system message
71
+ */
65
72
  private handleEvent;
66
73
  /**
67
74
  * ## MLS only ##
@@ -198,7 +198,9 @@ class NotificationService extends events_1.EventEmitter {
198
198
  }
199
199
  try {
200
200
  const data = yield __await(this.handleEvent(event, source, dryRun));
201
- yield yield __await(Object.assign(Object.assign({}, data), { mappedEvent: data.mappedEvent ? this.cleanupPayloadBundle(data.mappedEvent) : undefined }));
201
+ if (typeof data !== 'undefined') {
202
+ yield yield __await(Object.assign(Object.assign({}, data), { mappedEvent: data.mappedEvent ? this.cleanupPayloadBundle(data.mappedEvent) : undefined }));
203
+ }
202
204
  }
203
205
  catch (error) {
204
206
  this.logger.error(`There was an error with notification ID "${notification.id}": ${error.message}`, error);
@@ -234,6 +236,13 @@ class NotificationService extends events_1.EventEmitter {
234
236
  return payload;
235
237
  }
236
238
  }
239
+ /**
240
+ * Will process one event
241
+ * @param event The backend event to process
242
+ * @param source The source of the event (websocket or notication stream)
243
+ * @param dryRun Will not try to decrypt if true
244
+ * @return the decrypted payload and the raw event. Returns `undefined` when the payload is a coreCrypto-only system message
245
+ */
237
246
  async handleEvent(event, source, dryRun = false) {
238
247
  var _a, _b;
239
248
  switch (event.type) {
@@ -251,8 +260,8 @@ class NotificationService extends events_1.EventEmitter {
251
260
  const encryptedData = bazinga64_1.Decoder.fromBase64(event.data).asBytes;
252
261
  const groupId = await this.getGroupIdFromConversationId((_a = event.qualified_conversation) !== null && _a !== void 0 ? _a : { id: event.conversation, domain: '' });
253
262
  const groupIdBytes = bazinga64_1.Decoder.fromBase64(groupId).asBytes;
254
- // Check if the message includes proposals
255
263
  const { proposals, commitDelay, message } = await this.mlsService.decryptMessage(groupIdBytes, encryptedData);
264
+ // Check if the message includes proposals
256
265
  if (typeof commitDelay === 'number' || proposals.length > 0) {
257
266
  // we are dealing with a proposal, add a task to process this proposal later on
258
267
  // Those proposals are stored inside of coreCrypto and will be handled after a timeout
@@ -262,10 +271,12 @@ class NotificationService extends events_1.EventEmitter {
262
271
  eventTime: event.time,
263
272
  });
264
273
  // This is not a text message, there is nothing more to do
265
- return { event };
274
+ return undefined;
266
275
  }
267
276
  if (!message) {
268
- throw new Error(`MLS message received from ${source} was empty`);
277
+ const newEpoch = await this.mlsService.getEpoch(groupIdBytes);
278
+ this.logger.log(`Received commit message for group "${groupId}". New epoch is "${newEpoch}"`);
279
+ return undefined;
269
280
  }
270
281
  const decryptedData = protocol_messaging_1.GenericMessage.decode(message);
271
282
  /**