@wireapp/core 40.5.0 → 40.5.2-1
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/lib/Account.d.ts +7 -9
- package/lib/Account.d.ts.map +1 -1
- package/lib/Account.js +35 -32
- package/lib/CoreError.js +1 -1
- package/lib/broadcast/BroadcastService.d.ts +11 -2
- package/lib/broadcast/BroadcastService.d.ts.map +1 -1
- package/lib/broadcast/BroadcastService.js +39 -5
- package/lib/client/ClientDatabaseRepository.d.ts +5 -5
- package/lib/client/ClientDatabaseRepository.d.ts.map +1 -1
- package/lib/client/ClientDatabaseRepository.js +17 -10
- package/lib/client/ClientService.d.ts +1 -5
- package/lib/client/ClientService.d.ts.map +1 -1
- package/lib/client/ClientService.js +9 -11
- package/lib/connection/ConnectionService.d.ts +2 -2
- package/lib/connection/ConnectionService.d.ts.map +1 -1
- package/lib/connection/ConnectionService.js +2 -2
- package/lib/conversation/AssetTransferState.js +1 -1
- package/lib/conversation/ConversationService/ConversationService.d.ts +4 -11
- package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
- package/lib/conversation/ConversationService/ConversationService.js +5 -23
- package/lib/conversation/ConversationService/ConversationService.test.js +1 -1
- package/lib/conversation/ConversationService/ConversationService.types.d.ts +11 -12
- package/lib/conversation/ConversationService/ConversationService.types.d.ts.map +1 -1
- package/lib/conversation/ConversationService/ConversationService.types.js +1 -1
- package/lib/conversation/ConversationService/Utility/getConversationQualifiedMembers.d.ts +1 -1
- package/lib/conversation/ConversationService/Utility/getConversationQualifiedMembers.d.ts.map +1 -1
- package/lib/conversation/GenericMessageType.js +1 -1
- package/lib/conversation/ReactionType.d.ts +4 -1
- package/lib/conversation/ReactionType.d.ts.map +1 -1
- package/lib/conversation/ReactionType.js +6 -0
- package/lib/conversation/message/Message.types.js +1 -1
- package/lib/conversation/message/MessageBuilder.d.ts +1 -1
- package/lib/conversation/message/MessageBuilder.d.ts.map +1 -1
- package/lib/conversation/message/MessageBuilder.js +2 -2
- package/lib/conversation/message/MessageService.d.ts +31 -6
- package/lib/conversation/message/MessageService.d.ts.map +1 -1
- package/lib/conversation/message/MessageService.js +162 -19
- package/lib/conversation/message/MessageService.test.js +141 -151
- package/lib/conversation/message/PayloadBundle.js +1 -1
- package/lib/conversation/message/UserClientsUtil.d.ts +10 -14
- package/lib/conversation/message/UserClientsUtil.d.ts.map +1 -1
- package/lib/conversation/message/UserClientsUtil.js +11 -21
- package/lib/conversation/message/UserClientsUtils.test.js +9 -5
- package/lib/messagingProtocols/mls/EventHandler/EventHandler.d.ts +1 -1
- package/lib/messagingProtocols/mls/EventHandler/EventHandler.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.d.ts +1 -1
- package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.js +2 -7
- package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.js +0 -2
- package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.test.js +1 -3
- package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts +8 -19
- package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts.map +1 -1
- package/lib/messagingProtocols/mls/MLSService/MLSService.js +37 -79
- package/lib/messagingProtocols/mls/MLSService/MLSService.test.js +0 -9
- package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/index.d.ts +2 -0
- package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/index.d.ts.map +1 -0
- package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/index.js +35 -0
- package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.d.ts +11 -0
- package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.d.ts.map +1 -0
- package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.js +50 -0
- package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.test.d.ts +2 -0
- package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.test.d.ts.map +1 -0
- package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.test.js +39 -0
- package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.d.ts +4 -0
- package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.d.ts.map +1 -0
- package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.js +35 -0
- package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.test.d.ts +2 -0
- package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.test.d.ts.map +1 -0
- package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.test.js +35 -0
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts +5 -10
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.js +11 -33
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.d.ts +3 -2
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.js +9 -8
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.d.ts +9 -4
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.js +24 -10
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.test.js +10 -2
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.d.ts +2 -1
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.js +3 -3
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts +2 -2
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.d.ts +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.js +2 -2
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts +7 -14
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.js +35 -31
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.js +3 -2
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.test.js +89 -109
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.types.d.ts +9 -6
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.types.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.d.ts +25 -0
- package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.js +93 -0
- package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.test.d.ts +2 -0
- package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.test.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.test.js +66 -0
- package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/index.d.ts +2 -0
- package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/index.d.ts.map +1 -0
- package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/index.js +35 -0
- package/lib/messagingProtocols/proteus/Utility/Recipients.d.ts +10 -4
- package/lib/messagingProtocols/proteus/Utility/Recipients.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/Utility/Recipients.js +16 -16
- package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts +10 -15
- package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.js +92 -80
- package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.test.js +54 -70
- package/lib/messagingProtocols/proteus/Utility/getGenericMessageParams.d.ts +14 -5
- package/lib/messagingProtocols/proteus/Utility/getGenericMessageParams.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/Utility/getGenericMessageParams.js +35 -3
- package/lib/messagingProtocols/proteus/Utility/isClearFromMismatch.d.ts +2 -2
- package/lib/messagingProtocols/proteus/Utility/isClearFromMismatch.d.ts.map +1 -1
- package/lib/notification/NotificationDatabaseRepository.js +1 -1
- package/lib/notification/Notifications.types.js +1 -1
- package/lib/user/UserService.d.ts +17 -6
- package/lib/user/UserService.d.ts.map +1 -1
- package/lib/user/UserService.js +47 -2
- package/lib/util/TaskScheduler/TaskScheduler.d.ts +1 -4
- package/lib/util/TaskScheduler/TaskScheduler.d.ts.map +1 -1
- package/lib/util/TaskScheduler/TaskScheduler.js +3 -24
- package/lib/util/TypePredicateUtil.d.ts +1 -0
- package/lib/util/TypePredicateUtil.d.ts.map +1 -1
- package/lib/util/TypePredicateUtil.js +2 -1
- package/package.json +8 -8
- package/LICENSE +0 -674
- package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.d.ts +0 -13
- package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.d.ts.map +0 -1
- package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.js +0 -67
- package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.test.d.ts +0 -2
- package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.test.d.ts.map +0 -1
- package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.test.js +0 -72
- package/lib/util/TaskScheduler/TaskScheduler.store.d.ts +0 -7
- package/lib/util/TaskScheduler/TaskScheduler.store.d.ts.map +0 -1
- package/lib/util/TaskScheduler/TaskScheduler.store.js +0 -34
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/Utility/PreKeyBundle/index.ts"],"names":[],"mappings":"AAmBA,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Wire
|
|
4
|
+
* Copyright (C) 2022 Wire Swiss GmbH
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU General Public License
|
|
17
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
27
|
+
}) : (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
}));
|
|
31
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
32
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
__exportStar(require("./PreKeyBundle"), exports);
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { APIClient } from '@wireapp/api-client/lib/APIClient';
|
|
2
|
-
import { QualifiedUserClients } from '@wireapp/api-client/lib/conversation';
|
|
3
|
-
import { QualifiedId } from '@wireapp/api-client/lib/user';
|
|
2
|
+
import { QualifiedUserClients, UserClients } from '@wireapp/api-client/lib/conversation';
|
|
3
|
+
import { QualifiedId, QualifiedUserPreKeyBundleMap, UserPreKeyBundleMap } 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
|
|
10
|
-
|
|
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 };
|
|
11
17
|
//# 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;
|
|
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"}
|
|
@@ -18,26 +18,26 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.getRecipientsForConversation = void 0;
|
|
21
|
+
exports.getRecipientsForConversation = exports.getQualifiedRecipientsForConversation = void 0;
|
|
22
|
+
const PreKeyBundle_1 = require("./PreKeyBundle/PreKeyBundle");
|
|
22
23
|
const getConversationQualifiedMembers_1 = require("../../../conversation/ConversationService/Utility/getConversationQualifiedMembers");
|
|
23
|
-
const UserClientsUtil_1 = require("../../../conversation/message/UserClientsUtil");
|
|
24
24
|
const util_1 = require("../../../util");
|
|
25
|
-
|
|
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
|
-
}
|
|
32
|
-
const getRecipientsForConversation = async ({ apiClient, conversationId, userIds, }) => {
|
|
25
|
+
const getQualifiedRecipientsForConversation = async ({ apiClient, conversationId, userIds, }) => {
|
|
33
26
|
if ((0, util_1.isQualifiedUserClients)(userIds)) {
|
|
34
27
|
return userIds;
|
|
35
28
|
}
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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;
|
|
33
|
+
const getRecipientsForConversation = async ({ apiClient, conversationId, userIds, }) => {
|
|
34
|
+
if ((0, util_1.isUserClients)(userIds)) {
|
|
35
|
+
return userIds;
|
|
36
|
+
}
|
|
37
|
+
return (0, PreKeyBundle_1.getPreKeyBundleMap)({
|
|
38
|
+
apiClient: apiClient,
|
|
39
|
+
conversationId,
|
|
40
|
+
userIds,
|
|
41
|
+
});
|
|
42
42
|
};
|
|
43
43
|
exports.getRecipientsForConversation = getRecipientsForConversation;
|
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import { PreKey } from '@wireapp/api-client/lib/auth';
|
|
2
|
-
import {
|
|
3
|
-
import { QualifiedId,
|
|
2
|
+
import { UserClients } from '@wireapp/api-client/lib/conversation';
|
|
3
|
+
import { QualifiedId, UserPreKeyBundleMap } 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: QualifiedId;
|
|
8
|
+
userId: string | QualifiedId;
|
|
9
9
|
clientId: string;
|
|
10
|
+
useQualifiedIds: boolean;
|
|
10
11
|
domain?: string;
|
|
11
12
|
}
|
|
12
|
-
|
|
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;
|
|
13
|
+
declare const constructSessionId: ({ userId, clientId, useQualifiedIds, domain }: ConstructSessionIdParams) => string;
|
|
21
14
|
/**
|
|
22
15
|
* Will make sure the session is available in cryptoClient
|
|
23
16
|
* @param sessionId the session to init
|
|
@@ -31,7 +24,8 @@ declare const initSession: ({ userId, clientId, initialPrekey }: {
|
|
|
31
24
|
cryptoClient: CryptoClient;
|
|
32
25
|
}) => Promise<string>;
|
|
33
26
|
interface GetSessionsAndClientsFromRecipientsProps {
|
|
34
|
-
recipients:
|
|
27
|
+
recipients: UserClients | UserPreKeyBundleMap;
|
|
28
|
+
domain?: string;
|
|
35
29
|
apiClient: APIClient;
|
|
36
30
|
cryptoClient: CryptoClient;
|
|
37
31
|
logger?: Logger;
|
|
@@ -39,14 +33,15 @@ interface GetSessionsAndClientsFromRecipientsProps {
|
|
|
39
33
|
/**
|
|
40
34
|
* Will make sure all the sessions need to encrypt for those user/clients pair are set
|
|
41
35
|
*/
|
|
42
|
-
declare const initSessions: ({ recipients, apiClient, cryptoClient, logger, }: GetSessionsAndClientsFromRecipientsProps) => Promise<
|
|
36
|
+
declare const initSessions: ({ recipients, domain, apiClient, cryptoClient, logger, }: GetSessionsAndClientsFromRecipientsProps) => Promise<string[]>;
|
|
43
37
|
interface DeleteSessionParams {
|
|
44
38
|
userId: QualifiedId;
|
|
45
39
|
clientId: string;
|
|
46
40
|
cryptoClient: CryptoClient;
|
|
41
|
+
useQualifiedIds: boolean;
|
|
47
42
|
}
|
|
48
43
|
declare function deleteSession(params: DeleteSessionParams): Promise<void>;
|
|
49
|
-
type EncryptedPayloads<T> = Record<string, Record<string,
|
|
44
|
+
type EncryptedPayloads<T> = Record<string, Record<string, T>>;
|
|
50
45
|
/**
|
|
51
46
|
* creates an encrypted payload that can be sent to backend from a bunch of sessionIds/encrypted payload
|
|
52
47
|
*/
|
|
@@ -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,
|
|
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"}
|
|
@@ -21,10 +21,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
exports.buildEncryptedPayloads = exports.deleteSession = exports.initSessions = exports.initSession = exports.constructSessionId = void 0;
|
|
22
22
|
const bazinga64_1 = require("bazinga64");
|
|
23
23
|
const UserClientsUtil_1 = require("../../../../conversation/message/UserClientsUtil");
|
|
24
|
-
const constructSessionId = ({ userId, clientId }) => {
|
|
25
|
-
const
|
|
24
|
+
const constructSessionId = ({ userId, clientId, useQualifiedIds, domain }) => {
|
|
25
|
+
const id = typeof userId === 'string' ? userId : userId.id;
|
|
26
|
+
const baseDomain = typeof userId === 'string' ? domain : userId.domain;
|
|
26
27
|
const baseId = `${id}@${clientId}`;
|
|
27
|
-
return
|
|
28
|
+
return baseDomain && useQualifiedIds ? `${baseDomain}@${baseId}` : baseId;
|
|
28
29
|
};
|
|
29
30
|
exports.constructSessionId = constructSessionId;
|
|
30
31
|
const isSessionId = (object) => {
|
|
@@ -42,16 +43,55 @@ const parseSessionId = (sessionId) => {
|
|
|
42
43
|
}
|
|
43
44
|
return match.groups;
|
|
44
45
|
};
|
|
46
|
+
const createLegacySessions = async ({ userClients, apiClient, cryptoClient, logger, }) => {
|
|
47
|
+
const preKeyBundleMap = await apiClient.api.user.postMultiPreKeyBundles(userClients);
|
|
48
|
+
const sessions = await createSessionsFromPreKeys({
|
|
49
|
+
preKeyBundleMap,
|
|
50
|
+
useQualifiedIds: false,
|
|
51
|
+
cryptoClient,
|
|
52
|
+
logger,
|
|
53
|
+
});
|
|
54
|
+
return sessions;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Create sessions for the qualified clients.
|
|
58
|
+
* @param {userClientMap} map of domain to (map of user IDs to client IDs)
|
|
59
|
+
*/
|
|
60
|
+
const createQualifiedSessions = async ({ userClientMap, domain, apiClient, cryptoClient, logger, }) => {
|
|
61
|
+
const prekeyBundleMap = await apiClient.api.user.postQualifiedMultiPreKeyBundles({ [domain]: userClientMap });
|
|
62
|
+
const sessions = [];
|
|
63
|
+
for (const domain in prekeyBundleMap) {
|
|
64
|
+
const domainUsers = prekeyBundleMap[domain];
|
|
65
|
+
const domainSessions = await createSessionsFromPreKeys({
|
|
66
|
+
preKeyBundleMap: domainUsers,
|
|
67
|
+
domain,
|
|
68
|
+
useQualifiedIds: true,
|
|
69
|
+
cryptoClient,
|
|
70
|
+
logger,
|
|
71
|
+
});
|
|
72
|
+
sessions.push(...domainSessions);
|
|
73
|
+
}
|
|
74
|
+
return sessions;
|
|
75
|
+
};
|
|
45
76
|
/**
|
|
46
77
|
* Will make sure the session is available in cryptoClient
|
|
47
78
|
* @param sessionId the session to init
|
|
48
79
|
*/
|
|
49
80
|
const initSession = async ({ userId, clientId, initialPrekey }, { cryptoClient, apiClient }) => {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
81
|
+
const sessionId = constructSessionId({ userId, clientId, useQualifiedIds: !!userId.domain });
|
|
82
|
+
const sessionExists = await cryptoClient.sessionExists(sessionId);
|
|
83
|
+
if (sessionExists) {
|
|
84
|
+
return sessionId;
|
|
85
|
+
}
|
|
86
|
+
if (initialPrekey) {
|
|
87
|
+
const prekeyBuffer = bazinga64_1.Decoder.fromBase64(initialPrekey.key).asBytes;
|
|
88
|
+
await cryptoClient.sessionFromPrekey(sessionId, prekeyBuffer);
|
|
89
|
+
await cryptoClient.saveSession(sessionId);
|
|
90
|
+
return sessionId;
|
|
91
|
+
}
|
|
92
|
+
const sessions = await initSessions({
|
|
93
|
+
recipients: { [userId.id]: [clientId] },
|
|
94
|
+
domain: userId.domain,
|
|
55
95
|
apiClient,
|
|
56
96
|
cryptoClient,
|
|
57
97
|
});
|
|
@@ -60,67 +100,51 @@ const initSession = async ({ userId, clientId, initialPrekey }, { cryptoClient,
|
|
|
60
100
|
exports.initSession = initSession;
|
|
61
101
|
/**
|
|
62
102
|
* Create sessions for legacy/qualified clients (umberella function).
|
|
103
|
+
* Will call createQualifiedSessions or createLegacySessions based on passed userClientMap.
|
|
63
104
|
* @param {userClientMap} map of domain to (map of user IDs to client IDs) or map of user IDs containg the lists of clients
|
|
64
105
|
*/
|
|
65
|
-
const createSessions = async ({
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
106
|
+
const createSessions = async ({ userClientMap, domain, apiClient, cryptoClient, logger, }) => {
|
|
107
|
+
if (domain) {
|
|
108
|
+
return await createQualifiedSessions({ userClientMap, domain, apiClient, cryptoClient, logger });
|
|
109
|
+
}
|
|
110
|
+
return await createLegacySessions({
|
|
111
|
+
userClients: userClientMap,
|
|
112
|
+
apiClient,
|
|
69
113
|
cryptoClient,
|
|
114
|
+
logger,
|
|
70
115
|
});
|
|
71
|
-
return Object.assign(Object.assign({}, result), { failed: (failed === null || failed === void 0 ? void 0 : failed.length) ? failed : undefined });
|
|
72
116
|
};
|
|
73
117
|
/**
|
|
74
118
|
* Will make sure all the sessions need to encrypt for those user/clients pair are set
|
|
75
119
|
*/
|
|
76
|
-
const initSessions = async ({ recipients, apiClient, cryptoClient, logger, }) => {
|
|
77
|
-
|
|
78
|
-
const missingClients = {};
|
|
79
|
-
const missingClientsWithPrekeys = {};
|
|
120
|
+
const initSessions = async ({ recipients, domain = '', apiClient, cryptoClient, logger, }) => {
|
|
121
|
+
const missingUserClients = {};
|
|
80
122
|
const existingSessions = [];
|
|
81
|
-
const users = (0, UserClientsUtil_1.
|
|
123
|
+
const users = (0, UserClientsUtil_1.flattenUserClients)(recipients, domain);
|
|
82
124
|
for (const user of users) {
|
|
83
125
|
const { userId, data } = user;
|
|
84
126
|
const clients = Array.isArray(data) ? data : Object.keys(data);
|
|
85
127
|
for (const clientId of clients) {
|
|
86
|
-
const sessionId = constructSessionId({ userId, clientId });
|
|
128
|
+
const sessionId = constructSessionId({ userId, clientId, useQualifiedIds: !!domain });
|
|
87
129
|
if (await cryptoClient.sessionExists(sessionId)) {
|
|
88
130
|
existingSessions.push(sessionId);
|
|
89
131
|
continue;
|
|
90
132
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
domainMissingWithPrekey[userId.id] = (_b = domainMissingWithPrekey[userId.id]) !== null && _b !== void 0 ? _b : {};
|
|
94
|
-
domainMissingWithPrekey[userId.id][clientId] = data[clientId];
|
|
95
|
-
missingClientsWithPrekeys[userId.domain] = domainMissingWithPrekey;
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
const domainMissing = (_c = missingClients[userId.domain]) !== null && _c !== void 0 ? _c : {};
|
|
99
|
-
domainMissing[userId.id] = domainMissing[userId.id] || [];
|
|
100
|
-
domainMissing[userId.id].push(clientId);
|
|
101
|
-
missingClients[userId.domain] = domainMissing;
|
|
133
|
+
missingUserClients[userId.id] = missingUserClients[userId.id] || [];
|
|
134
|
+
missingUserClients[userId.id].push(clientId);
|
|
102
135
|
}
|
|
103
136
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
logger,
|
|
116
|
-
})
|
|
117
|
-
: { sessions: [], failed: undefined, unknowns: undefined };
|
|
118
|
-
const allUnknowns = Object.assign(Object.assign({}, prekeyUnknows), unknowns);
|
|
119
|
-
return {
|
|
120
|
-
sessions: [...existingSessions, ...prekeyCreated, ...created],
|
|
121
|
-
failed,
|
|
122
|
-
unknowns: Object.keys(allUnknowns).length > 0 ? allUnknowns : undefined,
|
|
123
|
-
};
|
|
137
|
+
if (Object.keys(missingUserClients).length === 0) {
|
|
138
|
+
return existingSessions;
|
|
139
|
+
}
|
|
140
|
+
const newSessions = await createSessions({
|
|
141
|
+
userClientMap: missingUserClients,
|
|
142
|
+
domain,
|
|
143
|
+
apiClient,
|
|
144
|
+
cryptoClient,
|
|
145
|
+
logger,
|
|
146
|
+
});
|
|
147
|
+
return [...existingSessions, ...newSessions];
|
|
124
148
|
};
|
|
125
149
|
exports.initSessions = initSessions;
|
|
126
150
|
async function deleteSession(params) {
|
|
@@ -128,46 +152,34 @@ async function deleteSession(params) {
|
|
|
128
152
|
await params.cryptoClient.deleteSession(sessionId);
|
|
129
153
|
}
|
|
130
154
|
exports.deleteSession = deleteSession;
|
|
131
|
-
const createSessionsFromPreKeys = async ({
|
|
132
|
-
var _a, _b;
|
|
155
|
+
const createSessionsFromPreKeys = async ({ preKeyBundleMap, domain = '', useQualifiedIds, cryptoClient, logger, }) => {
|
|
133
156
|
const sessions = [];
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
for (const
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const domainUnknowns = (_a = unknowns[domain]) !== null && _a !== void 0 ? _a : {};
|
|
143
|
-
domainUnknowns[userId] = (_b = domainUnknowns[userId]) !== null && _b !== void 0 ? _b : [];
|
|
144
|
-
domainUnknowns[userId].push(clientId);
|
|
145
|
-
unknowns[domain] = domainUnknowns;
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
const prekeyBuffer = bazinga64_1.Decoder.fromBase64(prekey.key).asBytes;
|
|
149
|
-
await cryptoClient.sessionFromPrekey(sessionId, prekeyBuffer);
|
|
150
|
-
await cryptoClient.saveSession(sessionId);
|
|
151
|
-
sessions.push(sessionId);
|
|
157
|
+
for (const userId in preKeyBundleMap) {
|
|
158
|
+
const userClients = preKeyBundleMap[userId];
|
|
159
|
+
for (const clientId in userClients) {
|
|
160
|
+
const sessionId = constructSessionId({ userId, clientId, domain, useQualifiedIds });
|
|
161
|
+
const prekey = userClients[clientId];
|
|
162
|
+
if (!prekey) {
|
|
163
|
+
logger === null || logger === void 0 ? void 0 : logger.warn(`A prekey for client ${clientId} of user ${userId}${domain ? ` on domain ${domain}` : ''} was not found, session won't be created.`);
|
|
164
|
+
continue;
|
|
152
165
|
}
|
|
166
|
+
const prekeyBuffer = bazinga64_1.Decoder.fromBase64(prekey.key).asBytes;
|
|
167
|
+
await cryptoClient.sessionFromPrekey(sessionId, prekeyBuffer);
|
|
168
|
+
await cryptoClient.saveSession(sessionId);
|
|
169
|
+
sessions.push(sessionId);
|
|
153
170
|
}
|
|
154
171
|
}
|
|
155
|
-
return
|
|
172
|
+
return sessions;
|
|
156
173
|
};
|
|
157
174
|
/**
|
|
158
175
|
* creates an encrypted payload that can be sent to backend from a bunch of sessionIds/encrypted payload
|
|
159
176
|
*/
|
|
160
177
|
const buildEncryptedPayloads = (payloads) => {
|
|
161
178
|
return [...payloads].reduce((acc, [sessionId, payload]) => {
|
|
162
|
-
var _a
|
|
163
|
-
const { userId,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
const domainPayloads = (_a = acc[domain]) !== null && _a !== void 0 ? _a : {};
|
|
168
|
-
domainPayloads[userId] = (_b = domainPayloads[userId]) !== null && _b !== void 0 ? _b : {};
|
|
169
|
-
domainPayloads[userId][clientId] = payload;
|
|
170
|
-
acc[domain] = domainPayloads;
|
|
179
|
+
var _a;
|
|
180
|
+
const { userId, clientId } = parseSessionId(sessionId);
|
|
181
|
+
acc[userId] = (_a = acc[userId]) !== null && _a !== void 0 ? _a : {};
|
|
182
|
+
acc[userId][clientId] = payload;
|
|
171
183
|
return acc;
|
|
172
184
|
}, {});
|
|
173
185
|
};
|
|
@@ -20,29 +20,16 @@
|
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
const api_client_1 = require("@wireapp/api-client");
|
|
22
22
|
const SessionHandler_1 = require("./SessionHandler");
|
|
23
|
-
function generatePrekeys(
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
domainUsers[userId] = clientIds.reduce((acc, clientId, index) => {
|
|
34
|
-
const payload = clientId.startsWith('deleted:')
|
|
35
|
-
? null
|
|
36
|
-
: {
|
|
37
|
-
id: index,
|
|
38
|
-
key: 'pQABARn//wKhAFggJ1Fbpg5l6wnzKOJE+vXpRnkqUYhIvVnR5lNXEbO2o/0DoQChAFggHxZvgvtDktY/vqBcpjjo6rQnXvcNQhfwmy8AJQJKlD0E9g==',
|
|
39
|
-
};
|
|
40
|
-
return Object.assign(Object.assign({}, acc), { [clientId]: payload });
|
|
41
|
-
}, {});
|
|
42
|
-
prekeys[domain] = domainUsers;
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
return Promise.resolve({ qualified_user_client_prekeys: prekeys, failed_to_list: failed });
|
|
23
|
+
function generatePrekeys(userId, clientIds) {
|
|
24
|
+
const clients = clientIds.reduce((prekeys, clientId, index) => {
|
|
25
|
+
return Object.assign(Object.assign({}, prekeys), { [clientId]: {
|
|
26
|
+
id: index,
|
|
27
|
+
key: 'pQABARn//wKhAFggJ1Fbpg5l6wnzKOJE+vXpRnkqUYhIvVnR5lNXEbO2o/0DoQChAFggHxZvgvtDktY/vqBcpjjo6rQnXvcNQhfwmy8AJQJKlD0E9g==',
|
|
28
|
+
} });
|
|
29
|
+
}, {});
|
|
30
|
+
return {
|
|
31
|
+
[userId.id]: Object.assign({}, clients),
|
|
32
|
+
};
|
|
46
33
|
}
|
|
47
34
|
describe('SessionHandler', () => {
|
|
48
35
|
const cryptoClient = {
|
|
@@ -53,19 +40,27 @@ describe('SessionHandler', () => {
|
|
|
53
40
|
deleteSession: jest.fn(),
|
|
54
41
|
};
|
|
55
42
|
const apiClient = new api_client_1.APIClient({ urls: api_client_1.APIClient.BACKEND.STAGING });
|
|
56
|
-
beforeAll(() => {
|
|
57
|
-
jest.spyOn(apiClient.api.user, 'postMultiPreKeyBundles').mockImplementation(generatePrekeys);
|
|
58
|
-
});
|
|
59
43
|
describe('constructSessionId', () => {
|
|
60
44
|
describe('constructs a session ID', () => {
|
|
61
45
|
it('without a domain', () => {
|
|
62
|
-
const sessionId = (0, SessionHandler_1.constructSessionId)({ userId:
|
|
46
|
+
const sessionId = (0, SessionHandler_1.constructSessionId)({ userId: 'user-id', clientId: 'client-id', useQualifiedIds: true });
|
|
63
47
|
expect(sessionId).toBe('user-id@client-id');
|
|
64
48
|
});
|
|
65
49
|
it('with a domain', () => {
|
|
66
50
|
const sessionId = (0, SessionHandler_1.constructSessionId)({
|
|
67
|
-
userId:
|
|
51
|
+
userId: 'user-id',
|
|
68
52
|
clientId: 'client-id',
|
|
53
|
+
domain: 'domain',
|
|
54
|
+
useQualifiedIds: true,
|
|
55
|
+
});
|
|
56
|
+
expect(sessionId).toBe('domain@user-id@client-id');
|
|
57
|
+
});
|
|
58
|
+
it('with a domain and useQualifiedIds', () => {
|
|
59
|
+
const sessionId = (0, SessionHandler_1.constructSessionId)({
|
|
60
|
+
userId: 'user-id',
|
|
61
|
+
clientId: 'client-id',
|
|
62
|
+
domain: 'domain',
|
|
63
|
+
useQualifiedIds: true,
|
|
69
64
|
});
|
|
70
65
|
expect(sessionId).toBe('domain@user-id@client-id');
|
|
71
66
|
});
|
|
@@ -73,6 +68,15 @@ describe('SessionHandler', () => {
|
|
|
73
68
|
const sessionId = (0, SessionHandler_1.constructSessionId)({
|
|
74
69
|
userId: { id: 'user-id', domain: 'domain' },
|
|
75
70
|
clientId: 'client-id',
|
|
71
|
+
useQualifiedIds: true,
|
|
72
|
+
});
|
|
73
|
+
expect(sessionId).toBe('domain@user-id@client-id');
|
|
74
|
+
});
|
|
75
|
+
it('with a qualified ID and useQualifiedIds', () => {
|
|
76
|
+
const sessionId = (0, SessionHandler_1.constructSessionId)({
|
|
77
|
+
userId: { id: 'user-id', domain: 'domain' },
|
|
78
|
+
clientId: 'client-id',
|
|
79
|
+
useQualifiedIds: true,
|
|
76
80
|
});
|
|
77
81
|
expect(sessionId).toBe('domain@user-id@client-id');
|
|
78
82
|
});
|
|
@@ -88,9 +92,27 @@ describe('SessionHandler', () => {
|
|
|
88
92
|
const userId = { id: 'user1', domain: 'domain' };
|
|
89
93
|
const clientId = 'client1';
|
|
90
94
|
jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(false);
|
|
95
|
+
jest
|
|
96
|
+
.spyOn(apiClient.api.user, 'postQualifiedMultiPreKeyBundles')
|
|
97
|
+
.mockResolvedValue({ domain: generatePrekeys(userId, [clientId]) });
|
|
98
|
+
const sessionId = (0, SessionHandler_1.constructSessionId)({
|
|
99
|
+
userId,
|
|
100
|
+
clientId,
|
|
101
|
+
useQualifiedIds: true,
|
|
102
|
+
});
|
|
103
|
+
await (0, SessionHandler_1.initSession)({ userId, clientId }, { apiClient, cryptoClient });
|
|
104
|
+
expect(cryptoClient.sessionFromPrekey).toHaveBeenCalledWith(sessionId, expect.any(Object));
|
|
105
|
+
});
|
|
106
|
+
it('indicates the consumer if a session could not be created', async () => {
|
|
107
|
+
const userId = { id: 'user1', domain: 'domain' };
|
|
108
|
+
const clientId = 'client1';
|
|
109
|
+
jest
|
|
110
|
+
.spyOn(apiClient.api.user, 'postQualifiedMultiPreKeyBundles')
|
|
111
|
+
.mockResolvedValue({ domain: generatePrekeys(userId, [clientId]) });
|
|
91
112
|
const sessionId = (0, SessionHandler_1.constructSessionId)({
|
|
92
113
|
userId,
|
|
93
114
|
clientId,
|
|
115
|
+
useQualifiedIds: true,
|
|
94
116
|
});
|
|
95
117
|
await (0, SessionHandler_1.initSession)({ userId, clientId }, { apiClient, cryptoClient });
|
|
96
118
|
expect(cryptoClient.sessionFromPrekey).toHaveBeenCalledWith(sessionId, expect.any(Object));
|
|
@@ -106,57 +128,19 @@ describe('SessionHandler', () => {
|
|
|
106
128
|
'missing-user1': ['client1'],
|
|
107
129
|
'missing-user2': ['client1', 'client2'],
|
|
108
130
|
};
|
|
131
|
+
jest.spyOn(apiClient.api.user, 'postQualifiedMultiPreKeyBundles').mockResolvedValue({});
|
|
132
|
+
jest.spyOn(apiClient.api.user, 'postMultiPreKeyBundles').mockResolvedValue(Object.assign(Object.assign({}, generatePrekeys({ id: 'missing-user1', domain: '' }, ['client1'])), generatePrekeys({ id: 'missing-user2', domain: '' }, ['client1', 'client2'])));
|
|
109
133
|
jest
|
|
110
134
|
.spyOn(cryptoClient, 'sessionExists')
|
|
111
135
|
.mockImplementation(sessionId => Promise.resolve(sessionId.includes('missing')));
|
|
112
136
|
const sessionFromPrekeySpy = jest.spyOn(cryptoClient, 'sessionFromPrekey');
|
|
113
|
-
const
|
|
114
|
-
recipients:
|
|
137
|
+
const sessions = await (0, SessionHandler_1.initSessions)({
|
|
138
|
+
recipients: Object.assign(Object.assign({}, existingUserClients), missingUserClients),
|
|
115
139
|
apiClient,
|
|
116
140
|
cryptoClient,
|
|
117
141
|
});
|
|
118
142
|
expect(sessionFromPrekeySpy).toHaveBeenCalledTimes(3);
|
|
119
143
|
expect(sessions).toHaveLength(6);
|
|
120
144
|
});
|
|
121
|
-
it('returns the list of deleted clients (clients with null prekeys)', async () => {
|
|
122
|
-
const userClients = {
|
|
123
|
-
'existing-user1': ['client1', 'deleted:client2'],
|
|
124
|
-
};
|
|
125
|
-
const { sessions, unknowns } = await (0, SessionHandler_1.initSessions)({
|
|
126
|
-
recipients: { domain: userClients },
|
|
127
|
-
apiClient,
|
|
128
|
-
cryptoClient,
|
|
129
|
-
});
|
|
130
|
-
expect(sessions).toEqual(['domain@existing-user1@client1']);
|
|
131
|
-
expect(unknowns).toEqual({ domain: { 'existing-user1': ['deleted:client2'] } });
|
|
132
|
-
});
|
|
133
|
-
it('initializes sessions across multiple domains', async () => {
|
|
134
|
-
const userClients = {
|
|
135
|
-
domain1: { 'existing-user1': ['client11'] },
|
|
136
|
-
domain2: { 'existing-user2': ['client21'] },
|
|
137
|
-
};
|
|
138
|
-
jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(true);
|
|
139
|
-
const { sessions, unknowns } = await (0, SessionHandler_1.initSessions)({
|
|
140
|
-
recipients: userClients,
|
|
141
|
-
apiClient,
|
|
142
|
-
cryptoClient,
|
|
143
|
-
});
|
|
144
|
-
expect(sessions).toEqual(['domain1@existing-user1@client11', 'domain2@existing-user2@client21']);
|
|
145
|
-
expect(unknowns).toBeUndefined();
|
|
146
|
-
});
|
|
147
|
-
it('returns failed session creation', async () => {
|
|
148
|
-
const recipients = {
|
|
149
|
-
domain1: { 'existing-user1': ['client1'] },
|
|
150
|
-
'offline:domain': { user2: ['client12'] },
|
|
151
|
-
};
|
|
152
|
-
jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(false);
|
|
153
|
-
const { sessions, failed } = await (0, SessionHandler_1.initSessions)({
|
|
154
|
-
recipients,
|
|
155
|
-
apiClient,
|
|
156
|
-
cryptoClient,
|
|
157
|
-
});
|
|
158
|
-
expect(sessions).toEqual(['domain1@existing-user1@client1']);
|
|
159
|
-
expect(failed).toEqual([{ id: 'user2', domain: 'offline:domain' }]);
|
|
160
|
-
});
|
|
161
145
|
});
|
|
162
146
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { APIClient } from '@wireapp/api-client/lib/APIClient';
|
|
2
|
-
import { QualifiedUserClients } from '@wireapp/api-client/lib/conversation';
|
|
3
|
-
import { QualifiedId, QualifiedUserPreKeyBundleMap } from '@wireapp/api-client/lib/user';
|
|
2
|
+
import { QualifiedUserClients, UserClients } from '@wireapp/api-client/lib/conversation';
|
|
3
|
+
import { QualifiedId, QualifiedUserPreKeyBundleMap, UserPreKeyBundleMap } from '@wireapp/api-client/lib/user';
|
|
4
4
|
import { GenericMessage } from '@wireapp/protocol-messaging';
|
|
5
5
|
import { MessageSendingOptions } from '../../../conversation';
|
|
6
|
-
export type
|
|
6
|
+
export type FederatedMessageParams = {
|
|
7
|
+
federated: true;
|
|
7
8
|
sendingClientId: string;
|
|
8
9
|
recipients: QualifiedUserClients | QualifiedUserPreKeyBundleMap;
|
|
9
10
|
plainText: Uint8Array;
|
|
@@ -13,14 +14,22 @@ export type MessageParams = {
|
|
|
13
14
|
reportMissing: boolean | QualifiedId[] | undefined;
|
|
14
15
|
};
|
|
15
16
|
};
|
|
17
|
+
export type MessageParams = Omit<FederatedMessageParams, 'recipients' | 'options' | 'federated'> & {
|
|
18
|
+
federated: false;
|
|
19
|
+
recipients: UserClients | UserPreKeyBundleMap;
|
|
20
|
+
options: Omit<FederatedMessageParams['options'], 'reportMissing'> & {
|
|
21
|
+
reportMissing: boolean | string[] | undefined;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
16
24
|
interface GetGenericMessageParamsParams {
|
|
17
25
|
sendingClientId: string;
|
|
18
26
|
conversationId: QualifiedId;
|
|
19
27
|
genericMessage: GenericMessage;
|
|
20
28
|
options: MessageSendingOptions;
|
|
29
|
+
useQualifiedIds: boolean;
|
|
21
30
|
apiClient: APIClient;
|
|
22
31
|
}
|
|
23
|
-
type GetGenericMessageParamsReturnType = Promise<MessageParams>;
|
|
24
|
-
declare const getGenericMessageParams: ({ sendingClientId, conversationId, genericMessage, options: { targetMode, userIds, nativePush }, apiClient, }: GetGenericMessageParamsParams) => GetGenericMessageParamsReturnType;
|
|
32
|
+
type GetGenericMessageParamsReturnType = Promise<MessageParams | FederatedMessageParams>;
|
|
33
|
+
declare const getGenericMessageParams: ({ sendingClientId, conversationId, genericMessage, options: { targetMode, userIds, nativePush }, useQualifiedIds, apiClient, }: GetGenericMessageParamsParams) => GetGenericMessageParamsReturnType;
|
|
25
34
|
export { getGenericMessageParams };
|
|
26
35
|
//# sourceMappingURL=getGenericMessageParams.d.ts.map
|