@wireapp/core 41.0.0 → 41.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.
@@ -89,5 +89,17 @@ export declare class ConversationService {
89
89
  wipeMLSConversation(groupId: string): Promise<void>;
90
90
  private matchesEpoch;
91
91
  handleEpochMismatch(): Promise<void>;
92
+ /**
93
+ * Will try registering mls 1:1 conversation adding the other user.
94
+ * If it fails and the conversation is already established, it will try joining via external commit instead.
95
+ *
96
+ * @param mlsConversation - mls 1:1 conversation
97
+ * @param selfUser - user and client ids of the self user
98
+ * @param otherUserId - id of the other user
99
+ */
100
+ readonly establishMLS1to1Conversation: (groupId: string, selfUser: {
101
+ user: QualifiedId;
102
+ client: string;
103
+ }, otherUserId: QualifiedId) => Promise<void>;
92
104
  }
93
105
  //# sourceMappingURL=ConversationService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConversationService.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,YAAY,EACZ,2BAA2B,EAC3B,WAAW,EACX,eAAe,EACf,oBAAoB,EAEpB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAC,4BAA4B,EAAC,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAIvD,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAI9C,OAAO,EAAC,cAAc,EAAE,aAAa,EAAE,oBAAoB,EAAE,UAAU,EAAC,MAAM,6BAA6B,CAAC;AAE5G,OAAO,EAAC,YAAY,EAAuB,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAEzF,OAAO,EAAC,UAAU,EAAuB,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAkC,cAAc,EAAC,MAAM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AAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAIlD,YAAY;IAYb,mBAAmB;CA2BjC"}
1
+ {"version":3,"file":"ConversationService.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,YAAY,EACZ,2BAA2B,EAC3B,WAAW,EACX,eAAe,EACf,oBAAoB,EAEpB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAC,4BAA4B,EAAC,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAIvD,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAI9C,OAAO,EAAC,cAAc,EAAE,aAAa,EAAE,oBAAoB,EAAE,UAAU,EAAC,MAAM,6BAA6B,CAAC;AAE5G,OAAO,EAAC,YAAY,EAAuB,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAEzF,OAAO,EAAC,UAAU,EAAuB,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAkC,cAAc,EAAC,MAAM,kCAAkC,CAAC;AACjG,OAAO,EACL,mCAAmC,EACnC,wBAAwB,EACzB,MAAM,sEAAsE,CAAC;AAG9E,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAGtC,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;IAN/B,SAAgB,YAAY,EAAE,YAAY,CAAC;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgD;gBAGpD,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,cAAc,EAC9B,WAAW,CAAC,wBAAY;IAK3C,IAAI,UAAU,IAAI,UAAU,CAK3B;IAED;;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I,CAAC;IAaT,yBAAyB,CAC9B,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,2BAA2B,GAAG,MAAM,GACrD,OAAO,CAAC,IAAI,CAAC;IAMhB;;;;OAIG;IAEH;;;OAGG;IACU,qBAAqB,CAChC,gBAAgB,EAAE,eAAe,EACjC,UAAU,EAAE,WAAW,EACvB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,aAAa,CAAC;YAqCX,cAAc;IAiC5B;;;;;;OAMG;IACU,yBAAyB,CAAC,EACrC,cAAc,EACd,OAAO,EACP,cAAc,GACf,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC;IAkBvC,8BAA8B,CAAC,EAC1C,OAAO,EACP,cAAc,EACd,gBAAgB,GACjB,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC;IAoBhC,oBAAoB,CAAC,cAAc,EAAE,WAAW;IAI7D;;;;;OAKG;IACU,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAmBvD,4BAA4B,CAAC,OAAO,EAAE,MAAM;IAI5C,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAIlD,YAAY;IAYb,mBAAmB;IA4BhC;;;;;;;OAOG;IACH,SAAgB,4BAA4B,YACjC,MAAM,YACL;QAAC,IAAI,EAAE,WAAW,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,eAChC,WAAW,KACvB,QAAQ,IAAI,CAAC,CA0Bd;CACH"}
@@ -41,6 +41,33 @@ class ConversationService {
41
41
  this.proteusService = proteusService;
42
42
  this._mlsService = _mlsService;
43
43
  this.logger = (0, logdown_1.default)('@wireapp/core/ConversationService');
44
+ /**
45
+ * Will try registering mls 1:1 conversation adding the other user.
46
+ * If it fails and the conversation is already established, it will try joining via external commit instead.
47
+ *
48
+ * @param mlsConversation - mls 1:1 conversation
49
+ * @param selfUser - user and client ids of the self user
50
+ * @param otherUserId - id of the other user
51
+ */
52
+ this.establishMLS1to1Conversation = async (groupId, selfUser, otherUserId) => {
53
+ try {
54
+ await this.mlsService.registerConversation(groupId, [otherUserId, selfUser.user], selfUser);
55
+ }
56
+ catch (error) {
57
+ this.logger.info(`Could not register MLS group with id ${groupId}.`);
58
+ const mlsConversation = await this.apiClient.api.conversation.getMLS1to1Conversation(otherUserId);
59
+ if (mlsConversation.epoch > 0) {
60
+ this.logger.info(`Conversation (id ${mlsConversation.qualified_id.id}) is already established, joining via external commit`);
61
+ // If its already established, we join with external commit
62
+ await this.joinByExternalCommit(mlsConversation.qualified_id);
63
+ return;
64
+ }
65
+ this.logger.info(`Conversation (id ${mlsConversation.qualified_id.id}) is not established, retrying to establish it`);
66
+ // If conversation is not established, we can wipe it and try to establish it again
67
+ await this.wipeMLSConversation(groupId);
68
+ return this.establishMLS1to1Conversation(groupId, selfUser, otherUserId);
69
+ }
70
+ };
44
71
  this.messageTimer = new conversation_2.MessageTimer();
45
72
  }
46
73
  get mlsService() {
@@ -56,6 +56,8 @@ const mockedMLSService = {
56
56
  commitPendingProposals: () => Promise.resolve(),
57
57
  getEpoch: () => Promise.resolve(),
58
58
  joinByExternalCommit: jest.fn(),
59
+ registerConversation: jest.fn(),
60
+ wipeConversation: jest.fn(),
59
61
  };
60
62
  const mockedProteusService = {
61
63
  encryptGenericMessage: () => Promise.resolve(),
@@ -186,6 +188,55 @@ describe('ConversationService', () => {
186
188
  expect(conversationService.joinByExternalCommit).not.toHaveBeenCalled();
187
189
  });
188
190
  });
191
+ describe('establishMLS1to1Conversation', () => {
192
+ it('successfully register an MLS group if it did not exist before', async () => {
193
+ const [conversationService, { mlsService }] = buildConversationService();
194
+ const mockGroupId = 'mock-group-id';
195
+ const selfUser = { user: { id: 'self-user-id', domain: 'staging.zinfra.io' }, client: 'self-user-client-id' };
196
+ const otherUserId = { id: 'other-user-id', domain: 'staging.zinfra.io' };
197
+ await conversationService.establishMLS1to1Conversation(mockGroupId, selfUser, otherUserId);
198
+ expect(mlsService.registerConversation).toHaveBeenCalledTimes(1);
199
+ expect(mlsService.registerConversation).toHaveBeenCalledWith(mockGroupId, [otherUserId, selfUser.user], selfUser);
200
+ expect(mlsService.joinByExternalCommit).not.toHaveBeenCalled();
201
+ expect(mlsService.wipeConversation).not.toHaveBeenCalled();
202
+ });
203
+ it('joins with external commit if epoch number is higher than 0', async () => {
204
+ const [conversationService, { apiClient, mlsService }] = buildConversationService();
205
+ const mockConversationId = { id: 'mock-conversation-id', domain: 'staging.zinfra.io' };
206
+ const mockGroupId = 'mock-group-id';
207
+ const selfUser = { user: { id: 'self-user-id', domain: 'staging.zinfra.io' }, client: 'self-user-client-id' };
208
+ const otherUserId = { id: 'other-user-id', domain: 'staging.zinfra.io' };
209
+ jest.spyOn(mlsService, 'registerConversation').mockRejectedValueOnce(undefined);
210
+ jest.spyOn(apiClient.api.conversation, 'getMLS1to1Conversation').mockResolvedValueOnce({
211
+ qualified_id: mockConversationId,
212
+ protocol: conversation_1.ConversationProtocol.MLS,
213
+ epoch: 1,
214
+ group_id: mockGroupId,
215
+ });
216
+ await conversationService.establishMLS1to1Conversation(mockGroupId, selfUser, otherUserId);
217
+ expect(mlsService.registerConversation).toHaveBeenCalledTimes(1);
218
+ expect(mlsService.registerConversation).toHaveBeenCalledWith(mockGroupId, [otherUserId, selfUser.user], selfUser);
219
+ expect(conversationService.joinByExternalCommit).toHaveBeenCalledWith(mockConversationId);
220
+ });
221
+ it('retries to register mls group if epoch number is equal 0', async () => {
222
+ const [conversationService, { apiClient, mlsService }] = buildConversationService();
223
+ const mockConversationId = { id: 'mock-conversation-id', domain: 'staging.zinfra.io' };
224
+ const mockGroupId = 'mock-group-id';
225
+ const selfUser = { user: { id: 'self-user-id', domain: 'staging.zinfra.io' }, client: 'self-user-client-id' };
226
+ const otherUserId = { id: 'other-user-id', domain: 'staging.zinfra.io' };
227
+ jest.spyOn(mlsService, 'registerConversation').mockRejectedValueOnce(undefined);
228
+ jest.spyOn(apiClient.api.conversation, 'getMLS1to1Conversation').mockResolvedValueOnce({
229
+ qualified_id: mockConversationId,
230
+ protocol: conversation_1.ConversationProtocol.MLS,
231
+ epoch: 0,
232
+ group_id: mockGroupId,
233
+ });
234
+ await conversationService.establishMLS1to1Conversation(mockGroupId, selfUser, otherUserId);
235
+ expect(mlsService.registerConversation).toHaveBeenCalledWith(mockGroupId, [otherUserId, selfUser.user], selfUser);
236
+ expect(mlsService.wipeConversation).toHaveBeenCalledWith(mockGroupId);
237
+ expect(mlsService.registerConversation).toHaveBeenCalledTimes(2);
238
+ });
239
+ });
189
240
  describe('fetchAllParticipantsClients', () => {
190
241
  it('gives the members and clients of a federated conversation', async () => {
191
242
  const [conversationService, { apiClient }] = buildConversationService();
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "./lib/cryptography/AssetCryptography/crypto.node": "./lib/cryptography/AssetCryptography/crypto.browser.js"
12
12
  },
13
13
  "dependencies": {
14
- "@wireapp/api-client": "^25.0.0",
14
+ "@wireapp/api-client": "^25.1.0",
15
15
  "@wireapp/commons": "^5.1.0",
16
16
  "@wireapp/core-crypto": "1.0.0-rc.6",
17
17
  "@wireapp/cryptobox": "12.8.0",
@@ -60,6 +60,6 @@
60
60
  "test:coverage": "jest --coverage",
61
61
  "watch": "tsc --watch"
62
62
  },
63
- "version": "41.0.0",
64
- "gitHead": "7d3f425539e2e8a549fa813c1b6d5d19598475d8"
63
+ "version": "41.1.0",
64
+ "gitHead": "b88ae7c76cc5ed141344814dd0012cdaf47a8af2"
65
65
  }