@wireapp/core 40.5.3-draft-20-cc.3 → 40.5.3-draft-20-cc.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 (143) hide show
  1. package/lib/Account.d.ts +9 -7
  2. package/lib/Account.d.ts.map +1 -1
  3. package/lib/Account.js +32 -35
  4. package/lib/CoreError.js +1 -1
  5. package/lib/broadcast/BroadcastService.d.ts +2 -11
  6. package/lib/broadcast/BroadcastService.d.ts.map +1 -1
  7. package/lib/broadcast/BroadcastService.js +5 -39
  8. package/lib/client/ClientDatabaseRepository.d.ts +5 -5
  9. package/lib/client/ClientDatabaseRepository.d.ts.map +1 -1
  10. package/lib/client/ClientDatabaseRepository.js +10 -17
  11. package/lib/client/ClientService.d.ts +5 -1
  12. package/lib/client/ClientService.d.ts.map +1 -1
  13. package/lib/client/ClientService.js +11 -9
  14. package/lib/connection/ConnectionService.d.ts +2 -2
  15. package/lib/connection/ConnectionService.d.ts.map +1 -1
  16. package/lib/connection/ConnectionService.js +2 -2
  17. package/lib/conversation/AssetTransferState.js +1 -1
  18. package/lib/conversation/ConversationService/ConversationService.d.ts +12 -5
  19. package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
  20. package/lib/conversation/ConversationService/ConversationService.js +26 -11
  21. package/lib/conversation/ConversationService/ConversationService.test.js +1 -1
  22. package/lib/conversation/ConversationService/ConversationService.types.d.ts +12 -11
  23. package/lib/conversation/ConversationService/ConversationService.types.d.ts.map +1 -1
  24. package/lib/conversation/ConversationService/ConversationService.types.js +1 -1
  25. package/lib/conversation/ConversationService/Utility/getConversationQualifiedMembers.d.ts +1 -1
  26. package/lib/conversation/ConversationService/Utility/getConversationQualifiedMembers.d.ts.map +1 -1
  27. package/lib/conversation/GenericMessageType.js +1 -1
  28. package/lib/conversation/ReactionType.d.ts +1 -4
  29. package/lib/conversation/ReactionType.d.ts.map +1 -1
  30. package/lib/conversation/ReactionType.js +0 -6
  31. package/lib/conversation/message/Message.types.js +1 -1
  32. package/lib/conversation/message/MessageBuilder.d.ts +1 -1
  33. package/lib/conversation/message/MessageBuilder.d.ts.map +1 -1
  34. package/lib/conversation/message/MessageBuilder.js +2 -2
  35. package/lib/conversation/message/MessageService.d.ts +6 -31
  36. package/lib/conversation/message/MessageService.d.ts.map +1 -1
  37. package/lib/conversation/message/MessageService.js +19 -162
  38. package/lib/conversation/message/MessageService.test.js +151 -141
  39. package/lib/conversation/message/PayloadBundle.js +1 -1
  40. package/lib/conversation/message/UserClientsUtil.d.ts +14 -10
  41. package/lib/conversation/message/UserClientsUtil.d.ts.map +1 -1
  42. package/lib/conversation/message/UserClientsUtil.js +21 -11
  43. package/lib/conversation/message/UserClientsUtils.test.js +5 -9
  44. package/lib/messagingProtocols/mls/EventHandler/EventHandler.d.ts +1 -1
  45. package/lib/messagingProtocols/mls/EventHandler/EventHandler.d.ts.map +1 -1
  46. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.d.ts +1 -1
  47. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.d.ts.map +1 -1
  48. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.js +7 -2
  49. package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.d.ts.map +1 -1
  50. package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.js +2 -0
  51. package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.test.js +3 -1
  52. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts +20 -8
  53. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts.map +1 -1
  54. package/lib/messagingProtocols/mls/MLSService/MLSService.js +81 -40
  55. package/lib/messagingProtocols/mls/MLSService/MLSService.test.js +9 -0
  56. package/lib/messagingProtocols/mls/MLSService/commitBundleUtil.d.ts +1 -1
  57. package/lib/messagingProtocols/mls/MLSService/commitBundleUtil.d.ts.map +1 -1
  58. package/lib/messagingProtocols/mls/MLSService/commitBundleUtil.js +5 -5
  59. package/lib/messagingProtocols/mls/MLSService/commitBundleUtil.test.js +3 -3
  60. package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.d.ts +13 -0
  61. package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.d.ts.map +1 -0
  62. package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.js +67 -0
  63. package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.test.d.ts +2 -0
  64. package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.test.d.ts.map +1 -0
  65. package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.test.js +72 -0
  66. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts +10 -5
  67. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts.map +1 -1
  68. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.js +33 -11
  69. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.d.ts +2 -3
  70. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.d.ts.map +1 -1
  71. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.js +8 -9
  72. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.d.ts +4 -9
  73. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.d.ts.map +1 -1
  74. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.js +10 -24
  75. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.test.js +2 -10
  76. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.d.ts +1 -2
  77. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.d.ts.map +1 -1
  78. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.js +3 -3
  79. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts +2 -2
  80. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts.map +1 -1
  81. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.d.ts +1 -1
  82. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.d.ts.map +1 -1
  83. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.js +2 -2
  84. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts +14 -7
  85. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts.map +1 -1
  86. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.js +31 -35
  87. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts +1 -1
  88. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts.map +1 -1
  89. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.js +2 -3
  90. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.test.js +109 -89
  91. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.types.d.ts +6 -9
  92. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.types.d.ts.map +1 -1
  93. package/lib/messagingProtocols/proteus/Utility/Recipients.d.ts +4 -10
  94. package/lib/messagingProtocols/proteus/Utility/Recipients.d.ts.map +1 -1
  95. package/lib/messagingProtocols/proteus/Utility/Recipients.js +16 -16
  96. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts +15 -10
  97. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts.map +1 -1
  98. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.js +80 -92
  99. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.test.js +70 -54
  100. package/lib/messagingProtocols/proteus/Utility/getGenericMessageParams.d.ts +5 -14
  101. package/lib/messagingProtocols/proteus/Utility/getGenericMessageParams.d.ts.map +1 -1
  102. package/lib/messagingProtocols/proteus/Utility/getGenericMessageParams.js +3 -35
  103. package/lib/messagingProtocols/proteus/Utility/isClearFromMismatch.d.ts +2 -2
  104. package/lib/messagingProtocols/proteus/Utility/isClearFromMismatch.d.ts.map +1 -1
  105. package/lib/notification/NotificationDatabaseRepository.js +1 -1
  106. package/lib/notification/Notifications.types.js +1 -1
  107. package/lib/user/UserService.d.ts +6 -17
  108. package/lib/user/UserService.d.ts.map +1 -1
  109. package/lib/user/UserService.js +2 -47
  110. package/lib/util/TaskScheduler/TaskScheduler.d.ts +4 -1
  111. package/lib/util/TaskScheduler/TaskScheduler.d.ts.map +1 -1
  112. package/lib/util/TaskScheduler/TaskScheduler.js +24 -3
  113. package/lib/util/TaskScheduler/TaskScheduler.store.d.ts +7 -0
  114. package/lib/util/TaskScheduler/TaskScheduler.store.d.ts.map +1 -0
  115. package/lib/util/TaskScheduler/TaskScheduler.store.js +34 -0
  116. package/lib/util/TypePredicateUtil.d.ts +0 -1
  117. package/lib/util/TypePredicateUtil.d.ts.map +1 -1
  118. package/lib/util/TypePredicateUtil.js +1 -2
  119. package/package.json +3 -3
  120. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/index.d.ts +0 -2
  121. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/index.d.ts.map +0 -1
  122. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/index.js +0 -35
  123. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.d.ts +0 -11
  124. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.d.ts.map +0 -1
  125. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.js +0 -50
  126. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.test.d.ts +0 -2
  127. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.test.d.ts.map +0 -1
  128. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.test.js +0 -39
  129. package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.d.ts +0 -4
  130. package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.d.ts.map +0 -1
  131. package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.js +0 -35
  132. package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.test.d.ts +0 -2
  133. package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.test.d.ts.map +0 -1
  134. package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.test.js +0 -35
  135. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.d.ts +0 -25
  136. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.d.ts.map +0 -1
  137. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.js +0 -93
  138. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.test.d.ts +0 -2
  139. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.test.d.ts.map +0 -1
  140. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.test.js +0 -66
  141. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/index.d.ts +0 -2
  142. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/index.d.ts.map +0 -1
  143. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/index.js +0 -35
@@ -1,7 +1,7 @@
1
1
  import { APIClient } from '@wireapp/api-client';
2
2
  import { CryptoClient } from './CryptoClient';
3
3
  import { ProteusService } from './ProteusService';
4
- export declare const buildProteusService: (federated?: boolean) => Promise<[ProteusService, {
4
+ export declare const buildProteusService: () => Promise<[ProteusService, {
5
5
  apiClient: APIClient;
6
6
  cryptoClient: CryptoClient;
7
7
  }]>;
@@ -1 +1 @@
1
- {"version":3,"file":"ProteusService.mocks.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.mocks.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAIhD,eAAO,MAAM,mBAAmB;eAEQ,SAAS;kBAAgB,YAAY;GAgB5E,CAAC"}
1
+ {"version":3,"file":"ProteusService.mocks.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.mocks.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAIhD,eAAO,MAAM,mBAAmB;eACD,SAAS;kBAAgB,YAAY;GAgBnE,CAAC"}
@@ -24,17 +24,16 @@ const api_client_1 = require("@wireapp/api-client");
24
24
  const CoreCryptoWrapper_1 = require("./CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper");
25
25
  const ProteusService_1 = require("./ProteusService");
26
26
  const PayloadHelper_1 = require("../../../test/PayloadHelper");
27
- const buildProteusService = async (federated = false) => {
27
+ const buildProteusService = async () => {
28
28
  const apiClient = new api_client_1.APIClient({ urls: api_client_1.APIClient.BACKEND.STAGING });
29
29
  apiClient.context = {
30
30
  clientType: client_1.ClientType.NONE,
31
31
  userId: (0, PayloadHelper_1.getUUID)(),
32
32
  clientId: (0, PayloadHelper_1.getUUID)(),
33
33
  };
34
- const cryptoClient = new CoreCryptoWrapper_1.CoreCryptoWrapper({}, {}, {});
34
+ const cryptoClient = new CoreCryptoWrapper_1.CoreCryptoWrapper({}, {});
35
35
  const proteusService = new ProteusService_1.ProteusService(apiClient, cryptoClient, {
36
36
  nbPrekeys: 0,
37
- useQualifiedIds: federated,
38
37
  });
39
38
  return [proteusService, { apiClient, cryptoClient }];
40
39
  };
@@ -64,11 +64,11 @@ jest.mock('./CryptoClient/CoreCryptoWrapper/PrekeysTracker', () => {
64
64
  });
65
65
  jest.mock('../Utility/Recipients', () => (Object.assign(Object.assign({}, jest.requireActual('../Utility/Recipients')), { getRecipientsForConversation: jest.fn(), getQualifiedRecipientsForConversation: jest.fn() })));
66
66
  const MockedRecipients = Recipients;
67
- const prepareDataForEncryption = async (useQualifiedIds = true) => {
68
- const [proteusService, { cryptoClient, apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)(useQualifiedIds);
67
+ const prepareDataForEncryption = async () => {
68
+ const [proteusService, { cryptoClient, apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
69
69
  const domain = 'staging.zinfra.io';
70
70
  //user 1
71
- const firstUserId = 'bc0c99f1-49a5-4ad2-889a-62885af37088';
71
+ const firstUserId = { id: 'bc0c99f1-49a5-4ad2-889a-62885af37088', domain };
72
72
  //user 1 clients
73
73
  const firstClientId = 'be67218b77d02d30';
74
74
  const secondClientId = 'ae87218e77d02d30';
@@ -76,25 +76,19 @@ const prepareDataForEncryption = async (useQualifiedIds = true) => {
76
76
  const firstClientSessionId = (0, SessionHandler_1.constructSessionId)({
77
77
  userId: firstUserId,
78
78
  clientId: firstClientId,
79
- useQualifiedIds,
80
- domain: useQualifiedIds ? domain : undefined,
81
79
  });
82
80
  const firstClientSession2Id = (0, SessionHandler_1.constructSessionId)({
83
81
  userId: firstUserId,
84
82
  clientId: secondClientId,
85
- useQualifiedIds,
86
- domain: useQualifiedIds ? domain : undefined,
87
83
  });
88
84
  //user 2
89
- const secondUserId = 'cd0c88f1-49a5-4ar2-889a-62885af37069';
85
+ const secondUserId = { id: 'cd0c88f1-49a5-4ar2-889a-62885af37069', domain };
90
86
  //user 2 client
91
87
  const thirdClientId = 'ce67218b77d02d69';
92
88
  //user 2 sessions
93
89
  const secondClientSessionId = (0, SessionHandler_1.constructSessionId)({
94
90
  userId: secondUserId,
95
91
  clientId: thirdClientId,
96
- useQualifiedIds,
97
- domain: useQualifiedIds ? domain : undefined,
98
92
  });
99
93
  //message sent by a user
100
94
  const message = 'Hello';
@@ -134,12 +128,14 @@ describe('ProteusService', () => {
134
128
  const expectedFingerprint = 'fingerprint-client1';
135
129
  const userId = { id: 'user1', domain: 'domain.com' };
136
130
  const clientId = 'client1';
137
- jest.spyOn(apiClient.api.user, 'postQualifiedMultiPreKeyBundles').mockResolvedValue({
138
- [userId.domain]: {
139
- [userId.id]: {
140
- [clientId]: {
141
- id: 123,
142
- key: 'pQABARhIAqEAWCCaJpFa9c626ORmjj1aV6OnOYgmTjfoiE3ynOfNfGAOmgOhAKEAWCD60VMzRrLfO+1GSjgyhnVp2N7L58DM+eeJhZJi1tBLfQT2',
131
+ jest.spyOn(apiClient.api.user, 'postMultiPreKeyBundles').mockResolvedValue({
132
+ qualified_user_client_prekeys: {
133
+ [userId.domain]: {
134
+ [userId.id]: {
135
+ [clientId]: {
136
+ id: 123,
137
+ key: 'pQABARhIAqEAWCCaJpFa9c626ORmjj1aV6OnOYgmTjfoiE3ynOfNfGAOmgOhAKEAWCD60VMzRrLfO+1GSjgyhnVp2N7L58DM+eeJhZJi1tBLfQT2',
138
+ },
143
139
  },
144
140
  },
145
141
  },
@@ -154,9 +150,9 @@ describe('ProteusService', () => {
154
150
  it('create a session from given prekey if session does not exists', async () => {
155
151
  const [proteusService, { apiClient, cryptoClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
156
152
  const expectedFingerprint = 'fingerprint-client1';
157
- const getPrekeyMock = jest.spyOn(apiClient.api.user, 'getClientPreKey');
153
+ const getPrekeysSpy = jest.spyOn(apiClient.api.user, 'postMultiPreKeyBundles');
158
154
  jest.spyOn(cryptoClient, 'getRemoteFingerprint').mockResolvedValue(expectedFingerprint);
159
- jest.spyOn(cryptoClient, 'sessionFromPrekey').mockResolvedValue(undefined);
155
+ const saveSessionSpy = jest.spyOn(cryptoClient, 'sessionFromPrekey').mockResolvedValue(undefined);
160
156
  jest.spyOn(cryptoClient, 'saveSession').mockResolvedValue(undefined);
161
157
  jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(false);
162
158
  const userId = { id: 'user1', domain: 'domain.com' };
@@ -165,7 +161,8 @@ describe('ProteusService', () => {
165
161
  key: 'pQABARhIAqEAWCCaJpFa9c626ORmjj1aV6OnOYgmTjfoiE3ynOfNfGAOmgOhAKEAWCD60VMzRrLfO+1GSjgyhnVp2N7L58DM+eeJhZJi1tBLfQT2',
166
162
  id: 123,
167
163
  });
168
- expect(getPrekeyMock).not.toHaveBeenCalled();
164
+ expect(saveSessionSpy).toHaveBeenCalled();
165
+ expect(getPrekeysSpy).not.toHaveBeenCalled();
169
166
  expect(result).toBe(expectedFingerprint);
170
167
  });
171
168
  it('returns the fingerprint from existing session', async () => {
@@ -220,83 +217,64 @@ describe('ProteusService', () => {
220
217
  });
221
218
  describe('"encrypt"', () => {
222
219
  it('returns encrypted payload', async () => {
223
- const { services, data: { firstUser, encryptedMessageBuffer, messageBuffer }, } = await prepareDataForEncryption(false);
220
+ const { services, data: { firstUser, encryptedMessageBuffer, messageBuffer, domain }, } = await prepareDataForEncryption();
224
221
  const userClients = {
225
- [firstUser.id]: [firstUser.clients.first, firstUser.clients.second],
226
- };
227
- const encryptedPayload = new Map([
228
- [firstUser.sessions.first, encryptedMessageBuffer],
229
- [firstUser.sessions.second, encryptedMessageBuffer],
230
- ]);
231
- jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(true);
232
- jest.spyOn(services.cryptoClient, 'encrypt').mockImplementationOnce(() => Promise.resolve(encryptedPayload));
233
- const encrypted = await services.proteusService.encrypt(messageBuffer, userClients);
234
- expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second], messageBuffer);
235
- expect(encrypted).toEqual({
236
- [firstUser.id]: {
237
- [firstUser.clients.first]: encryptedMessageBuffer,
238
- [firstUser.clients.second]: encryptedMessageBuffer,
222
+ [domain]: {
223
+ [firstUser.id.id]: [firstUser.clients.first, firstUser.clients.second],
239
224
  },
240
- });
241
- });
242
- it('returns encrypted payload for multiple users', async () => {
243
- const { services, data: { firstUser, secondUser, encryptedMessageBuffer, messageBuffer }, } = await prepareDataForEncryption(false);
244
- const userClients = {
245
- [firstUser.id]: [firstUser.clients.first, firstUser.clients.second],
246
- [secondUser.id]: [secondUser.clients.first],
247
225
  };
248
226
  const encryptedPayload = new Map([
249
227
  [firstUser.sessions.first, encryptedMessageBuffer],
250
228
  [firstUser.sessions.second, encryptedMessageBuffer],
251
- [secondUser.sessions.first, encryptedMessageBuffer],
252
229
  ]);
253
230
  jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(true);
254
231
  jest.spyOn(services.cryptoClient, 'encrypt').mockResolvedValueOnce(encryptedPayload);
255
- const encrypted = await services.proteusService.encrypt(messageBuffer, userClients);
256
- expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second, secondUser.sessions.first], messageBuffer);
257
- expect(encrypted).toEqual({
258
- [firstUser.id]: {
259
- [firstUser.clients.first]: encryptedMessageBuffer,
260
- [firstUser.clients.second]: encryptedMessageBuffer,
261
- },
262
- [secondUser.id]: {
263
- [secondUser.clients.first]: encryptedMessageBuffer,
232
+ const { payloads } = await services.proteusService.encrypt(messageBuffer, userClients);
233
+ expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second], messageBuffer);
234
+ expect(payloads).toEqual({
235
+ [domain]: {
236
+ [firstUser.id.id]: {
237
+ [firstUser.clients.first]: encryptedMessageBuffer,
238
+ [firstUser.clients.second]: encryptedMessageBuffer,
239
+ },
264
240
  },
265
241
  });
266
242
  });
267
- });
268
- describe('"encryptQualified"', () => {
269
- it('returns encrypted payload', async () => {
270
- const { services, data: { firstUser, encryptedMessageBuffer, messageBuffer, domain }, } = await prepareDataForEncryption();
243
+ it('returns missing clients and encrypted payload for multiple users', async () => {
244
+ const { services, data: { firstUser, secondUser, encryptedMessageBuffer, messageBuffer, domain }, } = await prepareDataForEncryption();
271
245
  const userClients = {
272
246
  [domain]: {
273
- [firstUser.id]: [firstUser.clients.first, firstUser.clients.second],
247
+ [firstUser.id.id]: [firstUser.clients.first, firstUser.clients.second],
248
+ [secondUser.id.id]: [secondUser.clients.first],
274
249
  },
275
250
  };
276
251
  const encryptedPayload = new Map([
277
252
  [firstUser.sessions.first, encryptedMessageBuffer],
278
253
  [firstUser.sessions.second, encryptedMessageBuffer],
254
+ [secondUser.sessions.first, encryptedMessageBuffer],
279
255
  ]);
280
256
  jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(true);
281
257
  jest.spyOn(services.cryptoClient, 'encrypt').mockResolvedValueOnce(encryptedPayload);
282
- const encrypted = await services.proteusService.encryptQualified(messageBuffer, userClients);
283
- // console.log({encrypted, missing});
284
- expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second], messageBuffer);
285
- expect(encrypted).toEqual({
258
+ const { payloads } = await services.proteusService.encrypt(messageBuffer, userClients);
259
+ expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second, secondUser.sessions.first], messageBuffer);
260
+ expect(payloads).toEqual({
286
261
  [domain]: {
287
- [firstUser.id]: {
262
+ [firstUser.id.id]: {
288
263
  [firstUser.clients.first]: encryptedMessageBuffer,
289
264
  [firstUser.clients.second]: encryptedMessageBuffer,
290
265
  },
266
+ [secondUser.id.id]: {
267
+ [secondUser.clients.first]: encryptedMessageBuffer,
268
+ },
291
269
  },
292
270
  });
293
271
  });
294
- it('returns missing clients and encrypted payload for multiple users', async () => {
272
+ it('returns the unknown clients that are deleted on backend', async () => {
295
273
  const { services, data: { firstUser, secondUser, encryptedMessageBuffer, messageBuffer, domain }, } = await prepareDataForEncryption();
296
274
  const userClients = {
297
275
  [domain]: {
298
- [firstUser.id]: [firstUser.clients.first, firstUser.clients.second],
299
- [secondUser.id]: [secondUser.clients.first],
276
+ [firstUser.id.id]: [firstUser.clients.first, firstUser.clients.second],
277
+ [secondUser.id.id]: [secondUser.clients.first],
300
278
  },
301
279
  };
302
280
  const encryptedPayload = new Map([
@@ -304,17 +282,43 @@ describe('ProteusService', () => {
304
282
  [firstUser.sessions.second, encryptedMessageBuffer],
305
283
  [secondUser.sessions.first, encryptedMessageBuffer],
306
284
  ]);
307
- jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(true);
285
+ jest.spyOn(services.apiClient.api.user, 'postMultiPreKeyBundles').mockResolvedValue({
286
+ qualified_user_client_prekeys: {
287
+ [domain]: {
288
+ [firstUser.id.id]: {
289
+ [firstUser.clients.first]: null,
290
+ [firstUser.clients.second]: {
291
+ id: 123,
292
+ key: 'pQABARhIAqEAWCCaJpFa9c626ORmjj1aV6OnOYgmTjfoiE3ynOfNfGAOmgOhAKEAWCD60VMzRrLfO+1GSjgyhnVp2N7L58DM+eeJhZJi1tBLfQT2',
293
+ },
294
+ },
295
+ [secondUser.id.id]: {
296
+ [secondUser.clients.first]: {
297
+ id: 123,
298
+ key: 'pQABARhIAqEAWCCaJpFa9c626ORmjj1aV6OnOYgmTjfoiE3ynOfNfGAOmgOhAKEAWCD60VMzRrLfO+1GSjgyhnVp2N7L58DM+eeJhZJi1tBLfQT2',
299
+ },
300
+ },
301
+ },
302
+ },
303
+ });
304
+ jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(false);
308
305
  jest.spyOn(services.cryptoClient, 'encrypt').mockResolvedValueOnce(encryptedPayload);
309
- const encrypted = await services.proteusService.encryptQualified(messageBuffer, userClients);
310
- expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second, secondUser.sessions.first], messageBuffer);
311
- expect(encrypted).toEqual({
306
+ jest.spyOn(services.cryptoClient, 'sessionFromPrekey').mockResolvedValue();
307
+ jest.spyOn(services.cryptoClient, 'saveSession').mockResolvedValue();
308
+ const { payloads, unknowns } = await services.proteusService.encrypt(messageBuffer, userClients);
309
+ expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.second, secondUser.sessions.first], messageBuffer);
310
+ expect(unknowns).toEqual({
311
+ [domain]: {
312
+ [firstUser.id.id]: [firstUser.clients.first],
313
+ },
314
+ });
315
+ expect(payloads).toEqual({
312
316
  [domain]: {
313
- [firstUser.id]: {
317
+ [firstUser.id.id]: {
314
318
  [firstUser.clients.first]: encryptedMessageBuffer,
315
319
  [firstUser.clients.second]: encryptedMessageBuffer,
316
320
  },
317
- [secondUser.id]: {
321
+ [secondUser.id.id]: {
318
322
  [secondUser.clients.first]: encryptedMessageBuffer,
319
323
  },
320
324
  },
@@ -344,7 +348,13 @@ describe('ProteusService', () => {
344
348
  expect(errorMessage).toContain('no userIds are given');
345
349
  }
346
350
  });
347
- [{ user1: ['client1'], user2: ['client11', 'client12'] }, ['user1', 'user2']].forEach(recipients => {
351
+ [
352
+ { domain: { user1: ['client1'], user2: ['client11', 'client12'] } },
353
+ [
354
+ { domain: 'domain', id: 'user1' },
355
+ { domain: 'domain', id: 'user2' },
356
+ ],
357
+ ].forEach(recipients => {
348
358
  it(`forwards the list of users to report (${JSON.stringify(recipients)})`, async () => {
349
359
  const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)();
350
360
  MockedRecipients.getRecipientsForConversation.mockResolvedValue({});
@@ -356,7 +366,12 @@ describe('ProteusService', () => {
356
366
  userIds: recipients,
357
367
  conversationId: { id: 'conv1', domain: '' },
358
368
  });
359
- expect(proteusService['messageService'].sendMessage).toHaveBeenCalledWith(expect.any(String), expect.any(Object), expect.any(Uint8Array), expect.objectContaining({ reportMissing: ['user1', 'user2'] }));
369
+ expect(proteusService['messageService'].sendMessage).toHaveBeenCalledWith(expect.any(String), expect.any(Object), expect.any(Uint8Array), expect.objectContaining({
370
+ reportMissing: [
371
+ { domain: 'domain', id: 'user1' },
372
+ { domain: 'domain', id: 'user2' },
373
+ ],
374
+ }));
360
375
  });
361
376
  });
362
377
  [
@@ -368,9 +383,9 @@ describe('ProteusService', () => {
368
383
  ],
369
384
  ].forEach(recipients => {
370
385
  it(`forwards the list of users to report for federated message (${JSON.stringify(recipients)})`, async () => {
371
- const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)(true);
372
- MockedRecipients.getQualifiedRecipientsForConversation.mockResolvedValue({});
373
- jest.spyOn(proteusService['messageService'], 'sendFederatedMessage').mockResolvedValue({});
386
+ const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)();
387
+ MockedRecipients.getRecipientsForConversation.mockResolvedValue({});
388
+ jest.spyOn(proteusService['messageService'], 'sendMessage').mockResolvedValue({});
374
389
  await proteusService.sendMessage({
375
390
  protocol: conversation_1.ConversationProtocol.PROTEUS,
376
391
  conversationId: { id: 'conv1', domain: 'domain1' },
@@ -378,7 +393,7 @@ describe('ProteusService', () => {
378
393
  targetMode: conversation_2.MessageTargetMode.USERS,
379
394
  userIds: recipients,
380
395
  });
381
- expect(proteusService['messageService'].sendFederatedMessage).toHaveBeenCalledWith(expect.any(String), expect.any(Object), expect.any(Uint8Array), expect.objectContaining({
396
+ expect(proteusService['messageService'].sendMessage).toHaveBeenCalledWith(expect.any(String), expect.any(Object), expect.any(Uint8Array), expect.objectContaining({
382
397
  reportMissing: [
383
398
  { id: 'user1', domain: 'domain1' },
384
399
  { id: 'user2', domain: 'domain1' },
@@ -387,9 +402,15 @@ describe('ProteusService', () => {
387
402
  }));
388
403
  });
389
404
  });
390
- [{ user1: ['client1'], user2: ['client11', 'client12'] }, ['user1', 'user2']].forEach(recipients => {
405
+ [
406
+ { domain: { user1: ['client1'], user2: ['client11', 'client12'] } },
407
+ [
408
+ { domain: 'domain', id: 'user1' },
409
+ { domain: 'domain', id: 'user2' },
410
+ ],
411
+ ].forEach(recipients => {
391
412
  it(`ignores all missing user/client pair if targetMode is USER_CLIENTS`, async () => {
392
- const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)(false);
413
+ const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)();
393
414
  MockedRecipients.getRecipientsForConversation.mockReturnValue(Promise.resolve({}));
394
415
  jest.spyOn(proteusService['messageService'], 'sendMessage').mockReturnValue(Promise.resolve({}));
395
416
  await proteusService.sendMessage({
@@ -411,11 +432,9 @@ describe('ProteusService', () => {
411
432
  ],
412
433
  ].forEach(recipients => {
413
434
  it(`ignores all missing user/client pair if targetMode is USER_CLIENTS on federated env`, async () => {
414
- const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)(true);
415
- MockedRecipients.getQualifiedRecipientsForConversation.mockResolvedValue({});
416
- jest
417
- .spyOn(proteusService['messageService'], 'sendFederatedMessage')
418
- .mockReturnValue(Promise.resolve({}));
435
+ const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)();
436
+ MockedRecipients.getRecipientsForConversation.mockResolvedValue({});
437
+ jest.spyOn(proteusService['messageService'], 'sendMessage').mockReturnValue(Promise.resolve({}));
419
438
  await proteusService.sendMessage({
420
439
  protocol: conversation_1.ConversationProtocol.PROTEUS,
421
440
  conversationId: { id: 'conv1', domain: 'domain1' },
@@ -423,19 +442,20 @@ describe('ProteusService', () => {
423
442
  targetMode: conversation_2.MessageTargetMode.USERS_CLIENTS,
424
443
  userIds: recipients,
425
444
  });
426
- expect(proteusService['messageService'].sendFederatedMessage).toHaveBeenCalledWith(expect.any(String), expect.any(Object), expect.any(Uint8Array), expect.objectContaining({
445
+ expect(proteusService['messageService'].sendMessage).toHaveBeenCalledWith(expect.any(String), expect.any(Object), expect.any(Uint8Array), expect.objectContaining({
427
446
  reportMissing: false,
428
447
  }));
429
448
  });
430
449
  });
431
- it(`returns the recipients that could not receive the message`, async () => {
432
- const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)(true);
450
+ it(`returns the recipients that will receive the message later`, async () => {
451
+ var _a;
452
+ const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)();
433
453
  const recipients = {
434
454
  domain1: { user1: ['client1'], user2: ['client11', 'client12'] },
435
455
  domain2: { user3: ['client3'] },
436
456
  };
437
- MockedRecipients.getQualifiedRecipientsForConversation.mockResolvedValue({});
438
- jest.spyOn(proteusService['messageService'], 'sendFederatedMessage').mockResolvedValue({
457
+ MockedRecipients.getRecipientsForConversation.mockResolvedValue({});
458
+ jest.spyOn(proteusService['messageService'], 'sendMessage').mockResolvedValue({
439
459
  missing: {},
440
460
  redundant: {},
441
461
  failed_to_send: { domain2: recipients.domain2 },
@@ -450,7 +470,7 @@ describe('ProteusService', () => {
450
470
  userIds: recipients,
451
471
  });
452
472
  expect(result.state).toBe(conversation_2.MessageSendingState.OUTGOING_SENT);
453
- expect(result.failedToSend).toEqual({ domain2: recipients.domain2 });
473
+ expect((_a = result.failedToSend) === null || _a === void 0 ? void 0 : _a.queued).toEqual({ domain2: recipients.domain2 });
454
474
  });
455
475
  });
456
476
  });
@@ -1,4 +1,4 @@
1
- import { UserClients, QualifiedUserClients, ClientMismatch, MessageSendingStatus, ConversationProtocol, NewConversation } from '@wireapp/api-client/lib/conversation';
1
+ import { QualifiedUserClients, MessageSendingStatus, ConversationProtocol, NewConversation } from '@wireapp/api-client/lib/conversation';
2
2
  import { QualifiedId } from '@wireapp/api-client/lib/user';
3
3
  import { AddUsersParams, MessageSendingOptions, SendCommonParams } from '../../../conversation';
4
4
  export interface NewClient {
@@ -6,21 +6,18 @@ export interface NewClient {
6
6
  userId: QualifiedId;
7
7
  }
8
8
  export type ProteusServiceConfig = {
9
- useQualifiedIds: boolean;
10
9
  onNewClient?: (client: NewClient) => void;
11
10
  nbPrekeys: number;
12
11
  };
13
12
  export type SendProteusMessageParams = SendCommonParams & MessageSendingOptions & {
14
13
  conversationId: QualifiedId;
15
14
  /**
16
- * Can be either a QualifiedId[], string[], UserClients or QualfiedUserClients. The type has some effect on the behavior of the method. (Needed only for Proteus)
17
- * When given a QualifiedId[] or string[] the method will fetch the freshest list of devices for those users (since they are not given by the consumer). As a consequence no ClientMismatch error will trigger and we will ignore missing clients when sending
18
- * When given a QualifiedUserClients or UserClients the method will only send to the clients listed in the userIds. This could lead to ClientMismatch (since the given list of devices might not be the freshest one and new clients could have been created)
19
- * When given a QualifiedId[] or QualifiedUserClients the method will send the message through the federated API endpoint
20
- * When given a string[] or UserClients the method will send the message through the old API endpoint
15
+ * Can be either a QualifiedId[] or QualfiedUserClients. The type has some effect on the behavior of the method. (Needed only for Proteus)
16
+ * When given a QualifiedId[] the method will fetch the freshest list of devices for those users (since they are not given by the consumer). As a consequence no ClientMismatch error will trigger and we will ignore missing clients when sending
17
+ * When given a QualifiedUserClients the method will only send to the clients listed in the userIds. This could lead to ClientMismatch (since the given list of devices might not be the freshest one and new clients could have been created)
21
18
  */
22
- userIds?: string[] | QualifiedId[] | UserClients | QualifiedUserClients;
23
- onClientMismatch?: (status: ClientMismatch | MessageSendingStatus, wasSent: boolean) => void | boolean | Promise<boolean>;
19
+ userIds?: QualifiedId[] | QualifiedUserClients;
20
+ onClientMismatch?: (status: MessageSendingStatus, wasSent: boolean) => void | boolean | Promise<boolean>;
24
21
  protocol: ConversationProtocol.PROTEUS;
25
22
  };
26
23
  export type CreateProteusConversationParams = {
@@ -1 +1 @@
1
- {"version":3,"file":"ProteusService.types.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.types.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAC,cAAc,EAAE,qBAAqB,EAAE,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAE9F,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,WAAW,CAAC;CACrB;AACD,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1C,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,gBAAgB,GACrD,qBAAqB,GAAG;IACtB,cAAc,EAAE,WAAW,CAAC;IAE5B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,GAAG,WAAW,GAAG,oBAAoB,CAAC;IACxE,gBAAgB,CAAC,EAAE,CACjB,MAAM,EAAE,cAAc,GAAG,oBAAoB,EAC7C,OAAO,EAAE,OAAO,KACb,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC;CACxC,CAAC;AAEJ,MAAM,MAAM,+BAA+B,GAAG;IAC5C,gBAAgB,EAAE,eAAe,GAAG,MAAM,CAAC;IAC3C,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC"}
1
+ {"version":3,"file":"ProteusService.types.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.types.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAC,cAAc,EAAE,qBAAqB,EAAE,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAE9F,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,WAAW,CAAC;CACrB;AACD,MAAM,MAAM,oBAAoB,GAAG;IACjC,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1C,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,gBAAgB,GACrD,qBAAqB,GAAG;IACtB,cAAc,EAAE,WAAW,CAAC;IAE5B;;;;OAIG;IACH,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,oBAAoB,CAAC;IAC/C,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACzG,QAAQ,EAAE,oBAAoB,CAAC,OAAO,CAAC;CACxC,CAAC;AAEJ,MAAM,MAAM,+BAA+B,GAAG;IAC5C,gBAAgB,EAAE,eAAe,GAAG,MAAM,CAAC;IAC3C,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC"}
@@ -1,17 +1,11 @@
1
1
  import { APIClient } from '@wireapp/api-client/lib/APIClient';
2
- import { QualifiedUserClients, UserClients } from '@wireapp/api-client/lib/conversation';
3
- import { QualifiedId, QualifiedUserPreKeyBundleMap, UserPreKeyBundleMap } from '@wireapp/api-client/lib/user';
2
+ import { QualifiedUserClients } from '@wireapp/api-client/lib/conversation';
3
+ import { QualifiedId } from '@wireapp/api-client/lib/user';
4
4
  interface GetRecipientsForConversationQualifiedParams {
5
5
  apiClient: APIClient;
6
6
  conversationId: QualifiedId;
7
7
  userIds?: QualifiedId[] | QualifiedUserClients;
8
8
  }
9
- declare const getQualifiedRecipientsForConversation: ({ apiClient, conversationId, userIds, }: GetRecipientsForConversationQualifiedParams) => Promise<QualifiedUserClients | QualifiedUserPreKeyBundleMap>;
10
- interface GetRecipientsForConversationParams {
11
- apiClient: APIClient;
12
- conversationId: QualifiedId;
13
- userIds?: string[] | UserClients;
14
- }
15
- declare const getRecipientsForConversation: ({ apiClient, conversationId, userIds, }: GetRecipientsForConversationParams) => Promise<UserClients | UserPreKeyBundleMap>;
16
- export { getQualifiedRecipientsForConversation, getRecipientsForConversation };
9
+ declare const getRecipientsForConversation: ({ apiClient, conversationId, userIds, }: GetRecipientsForConversationQualifiedParams) => Promise<QualifiedUserClients>;
10
+ export { getRecipientsForConversation };
17
11
  //# sourceMappingURL=Recipients.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Recipients.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/Utility/Recipients.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAC,oBAAoB,EAAE,WAAW,EAAC,MAAM,sCAAsC,CAAC;AACvF,OAAO,EAAC,WAAW,EAAE,4BAA4B,EAAE,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAO5G,UAAU,2CAA2C;IACnD,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,EAAE,WAAW,CAAC;IAC5B,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,oBAAoB,CAAC;CAChD;AAED,QAAA,MAAM,qCAAqC,4CAIxC,2CAA2C,KAAG,QAAQ,oBAAoB,GAAG,4BAA4B,CAO3G,CAAC;AAEF,UAAU,kCAAkC;IAC1C,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,EAAE,WAAW,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC;CAClC;AACD,QAAA,MAAM,4BAA4B,4CAI/B,kCAAkC,KAAG,QAAQ,WAAW,GAAG,mBAAmB,CAShF,CAAC;AAEF,OAAO,EAAC,qCAAqC,EAAE,4BAA4B,EAAC,CAAC"}
1
+ {"version":3,"file":"Recipients.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/Utility/Recipients.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAE5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAczD,UAAU,2CAA2C;IACnD,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,EAAE,WAAW,CAAC;IAC5B,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,oBAAoB,CAAC;CAChD;AAED,QAAA,MAAM,4BAA4B,4CAI/B,2CAA2C,KAAG,QAAQ,oBAAoB,CAW5E,CAAC;AAEF,OAAO,EAAC,4BAA4B,EAAC,CAAC"}
@@ -18,26 +18,26 @@
18
18
  *
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.getRecipientsForConversation = exports.getQualifiedRecipientsForConversation = void 0;
22
- const PreKeyBundle_1 = require("./PreKeyBundle/PreKeyBundle");
21
+ exports.getRecipientsForConversation = void 0;
23
22
  const getConversationQualifiedMembers_1 = require("../../../conversation/ConversationService/Utility/getConversationQualifiedMembers");
23
+ const UserClientsUtil_1 = require("../../../conversation/message/UserClientsUtil");
24
24
  const util_1 = require("../../../util");
25
- const getQualifiedRecipientsForConversation = async ({ apiClient, conversationId, userIds, }) => {
26
- if ((0, util_1.isQualifiedUserClients)(userIds)) {
27
- return userIds;
28
- }
29
- const recipientIds = userIds || (await (0, getConversationQualifiedMembers_1.getConversationQualifiedMembers)({ apiClient: apiClient, conversationId }));
30
- return (0, PreKeyBundle_1.getQualifiedPreKeyBundle)({ apiClient, userIds: recipientIds });
31
- };
32
- exports.getQualifiedRecipientsForConversation = getQualifiedRecipientsForConversation;
25
+ function toQualifiedUserClients(publicClients) {
26
+ const userList = (0, UserClientsUtil_1.flattenUserMap)(publicClients).map(({ userId, data: clientInfo }) => ({
27
+ userId,
28
+ data: clientInfo.map(client => client.id),
29
+ }));
30
+ return (0, UserClientsUtil_1.nestUsersList)(userList);
31
+ }
33
32
  const getRecipientsForConversation = async ({ apiClient, conversationId, userIds, }) => {
34
- if ((0, util_1.isUserClients)(userIds)) {
33
+ if ((0, util_1.isQualifiedUserClients)(userIds)) {
35
34
  return userIds;
36
35
  }
37
- return (0, PreKeyBundle_1.getPreKeyBundleMap)({
38
- apiClient: apiClient,
39
- conversationId,
40
- userIds,
41
- });
36
+ const hasTargetUsers = userIds && Object.keys(userIds).length > 0;
37
+ const recipientIds = hasTargetUsers
38
+ ? userIds
39
+ : await (0, getConversationQualifiedMembers_1.getConversationQualifiedMembers)({ apiClient: apiClient, conversationId });
40
+ const allClients = await apiClient.api.user.postListClients({ qualified_users: recipientIds });
41
+ return toQualifiedUserClients(allClients.qualified_user_map);
42
42
  };
43
43
  exports.getRecipientsForConversation = getRecipientsForConversation;
@@ -1,16 +1,23 @@
1
1
  import { PreKey } from '@wireapp/api-client/lib/auth';
2
- import { UserClients } from '@wireapp/api-client/lib/conversation';
3
- import { QualifiedId, UserPreKeyBundleMap } from '@wireapp/api-client/lib/user';
2
+ import { QualifiedUserClients } from '@wireapp/api-client/lib/conversation';
3
+ import { QualifiedId, QualifiedUserPreKeyBundleMap } from '@wireapp/api-client/lib/user';
4
4
  import { Logger } from 'logdown';
5
5
  import { APIClient } from '@wireapp/api-client';
6
6
  import { CryptoClient } from '../../ProteusService/CryptoClient';
7
7
  interface ConstructSessionIdParams {
8
- userId: string | QualifiedId;
8
+ userId: QualifiedId;
9
9
  clientId: string;
10
- useQualifiedIds: boolean;
11
10
  domain?: string;
12
11
  }
13
- declare const constructSessionId: ({ userId, clientId, useQualifiedIds, domain }: ConstructSessionIdParams) => string;
12
+ type InitSessionsResult = {
13
+ /** valid sessions that either already existed or have been freshly created */
14
+ sessions: string[];
15
+ /** client that do we do not have sessions with and that do not have existence on backend (deleted clients) */
16
+ unknowns?: QualifiedUserClients;
17
+ /** clients for which we had problem fetch prekeys (federated server down) */
18
+ failed?: QualifiedId[];
19
+ };
20
+ declare const constructSessionId: ({ userId, clientId }: ConstructSessionIdParams) => string;
14
21
  /**
15
22
  * Will make sure the session is available in cryptoClient
16
23
  * @param sessionId the session to init
@@ -24,8 +31,7 @@ declare const initSession: ({ userId, clientId, initialPrekey }: {
24
31
  cryptoClient: CryptoClient;
25
32
  }) => Promise<string>;
26
33
  interface GetSessionsAndClientsFromRecipientsProps {
27
- recipients: UserClients | UserPreKeyBundleMap;
28
- domain?: string;
34
+ recipients: QualifiedUserClients | QualifiedUserPreKeyBundleMap;
29
35
  apiClient: APIClient;
30
36
  cryptoClient: CryptoClient;
31
37
  logger?: Logger;
@@ -33,15 +39,14 @@ interface GetSessionsAndClientsFromRecipientsProps {
33
39
  /**
34
40
  * Will make sure all the sessions need to encrypt for those user/clients pair are set
35
41
  */
36
- declare const initSessions: ({ recipients, domain, apiClient, cryptoClient, logger, }: GetSessionsAndClientsFromRecipientsProps) => Promise<string[]>;
42
+ declare const initSessions: ({ recipients, apiClient, cryptoClient, logger, }: GetSessionsAndClientsFromRecipientsProps) => Promise<InitSessionsResult>;
37
43
  interface DeleteSessionParams {
38
44
  userId: QualifiedId;
39
45
  clientId: string;
40
46
  cryptoClient: CryptoClient;
41
- useQualifiedIds: boolean;
42
47
  }
43
48
  declare function deleteSession(params: DeleteSessionParams): Promise<void>;
44
- type EncryptedPayloads<T> = Record<string, Record<string, T>>;
49
+ type EncryptedPayloads<T> = Record<string, Record<string, Record<string, T>>>;
45
50
  /**
46
51
  * creates an encrypted payload that can be sent to backend from a bunch of sessionIds/encrypted payload
47
52
  */
@@ -1 +1 @@
1
- {"version":3,"file":"SessionHandler.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAC,WAAW,EAAC,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAE9E,OAAO,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAK9C,OAAO,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAC;AAE/D,UAAU,wBAAwB;IAChC,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,QAAA,MAAM,kBAAkB,kDAAiD,wBAAwB,KAAG,MAKnG,CAAC;AAuFF;;;GAGG;AACH,QAAA,MAAM,WAAW;YAC6B,WAAW;cAAY,MAAM;;;eAClC,SAAS;kBAAgB,YAAY;MAC3E,QAAQ,MAAM,CAmBhB,CAAC;AAyBF,UAAU,wCAAwC;IAChD,UAAU,EAAE,WAAW,GAAG,mBAAmB,CAAC;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,QAAA,MAAM,YAAY,6DAMf,wCAAwC,KAAG,QAAQ,MAAM,EAAE,CAgC7D,CAAC;AAEF,UAAU,mBAAmB;IAC3B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;CAC1B;AACD,iBAAe,aAAa,CAAC,MAAM,EAAE,mBAAmB,iBAGvD;AA+CD,KAAK,iBAAiB,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D;;GAEG;AACH,QAAA,MAAM,sBAAsB,uDAO3B,CAAC;AAEF,OAAO,EAAC,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAC,CAAC"}
1
+ {"version":3,"file":"SessionHandler.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAE,4BAA4B,EAAC,MAAM,8BAA8B,CAAC;AAEvF,OAAO,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAK9C,OAAO,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAC;AAE/D,UAAU,wBAAwB;IAChC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,kBAAkB,GAAG;IACxB,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,8GAA8G;IAC9G,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,6EAA6E;IAC7E,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC;AAEF,QAAA,MAAM,kBAAkB,yBAAwB,wBAAwB,KAAG,MAI1E,CAAC;AA6BF;;;GAGG;AACH,QAAA,MAAM,WAAW;YAC6B,WAAW;cAAY,MAAM;;;eAClC,SAAS;kBAAgB,YAAY;MAC3E,QAAQ,MAAM,CAUhB,CAAC;AAqBF,UAAU,wCAAwC;IAChD,UAAU,EAAE,oBAAoB,GAAG,4BAA4B,CAAC;IAChE,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,QAAA,MAAM,YAAY,qDAKf,wCAAwC,KAAG,QAAQ,kBAAkB,CAwDvE,CAAC;AAEF,UAAU,mBAAmB;IAC3B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;CAC5B;AACD,iBAAe,aAAa,CAAC,MAAM,EAAE,mBAAmB,iBAGvD;AA4CD,KAAK,iBAAiB,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E;;GAEG;AACH,QAAA,MAAM,sBAAsB,uDAY3B,CAAC;AAEF,OAAO,EAAC,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAC,CAAC"}