@wireapp/core 31.1.3 → 31.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -9
- package/src/main/Account.d.ts +214 -0
- package/src/main/Account.js +463 -0
- package/src/main/CoreError.d.ts +9 -0
- package/src/main/CoreError.js +26 -0
- package/src/main/account/AccountService.d.ts +7 -0
- package/src/main/account/AccountService.js +33 -0
- package/src/main/account/AccountService.js.map +1 -0
- package/src/main/account/index.d.ts +1 -0
- package/src/main/account/index.js +36 -0
- package/src/main/account/index.js.map +1 -0
- package/src/main/auth/LoginSanitizer.d.ts +5 -0
- package/src/main/auth/LoginSanitizer.js +41 -0
- package/src/main/auth/index.d.ts +1 -0
- package/src/main/auth/index.js +36 -0
- package/src/main/broadcast/AvailabilityType.d.ts +2 -0
- package/src/main/broadcast/AvailabilityType.js +21 -0
- package/src/main/broadcast/BroadcastService.d.ts +24 -0
- package/src/main/broadcast/BroadcastService.js +74 -0
- package/src/main/broadcast/index.d.ts +2 -0
- package/src/main/broadcast/index.js +37 -0
- package/src/main/client/ClientBackendRepository.d.ts +11 -0
- package/src/main/client/ClientBackendRepository.js +43 -0
- package/src/main/client/ClientDatabaseRepository.d.ts +27 -0
- package/src/main/client/ClientDatabaseRepository.js +85 -0
- package/src/main/client/ClientInfo.d.ts +8 -0
- package/src/main/client/ClientInfo.js +21 -0
- package/src/main/client/ClientService.d.ts +40 -0
- package/src/main/client/ClientService.js +103 -0
- package/src/main/client/index.d.ts +4 -0
- package/src/main/client/index.js +39 -0
- package/src/main/connection/ConnectionService.d.ts +11 -0
- package/src/main/connection/ConnectionService.js +45 -0
- package/src/main/connection/index.d.ts +1 -0
- package/src/main/connection/index.js +36 -0
- package/src/main/conversation/AbortReason.d.ts +2 -0
- package/src/main/conversation/AbortReason.js +21 -0
- package/src/main/conversation/AssetService/AssetService.d.ts +62 -0
- package/src/main/conversation/AssetService/AssetService.js +88 -0
- package/src/main/conversation/AssetService/index.d.ts +1 -0
- package/src/main/conversation/AssetService/index.js +36 -0
- package/src/main/conversation/AssetTransferState.d.ts +4 -0
- package/src/main/conversation/AssetTransferState.js +27 -0
- package/src/main/conversation/ClientActionType.d.ts +1 -0
- package/src/main/conversation/ClientActionType.js +24 -0
- package/src/main/conversation/ConversationMapper/ConversationMapper.d.ts +6 -0
- package/src/main/conversation/ConversationMapper/ConversationMapper.js +57 -0
- package/src/main/conversation/ConversationMapper/index.d.ts +1 -0
- package/src/main/conversation/ConversationMapper/index.js +36 -0
- package/src/main/conversation/ConversationService/ConversationService.d.ts +149 -0
- package/src/main/conversation/ConversationService/ConversationService.js +584 -0
- package/src/main/conversation/ConversationService/ConversationService.types.d.ts +110 -0
- package/src/main/conversation/ConversationService/ConversationService.types.js +28 -0
- package/src/main/conversation/ConversationService/index.d.ts +2 -0
- package/src/main/conversation/ConversationService/index.js +37 -0
- package/src/main/conversation/ConversationService/messageGenerator.d.ts +9 -0
- package/src/main/conversation/ConversationService/messageGenerator.js +313 -0
- package/src/main/conversation/GenericMessageType.d.ts +25 -0
- package/src/main/conversation/GenericMessageType.js +49 -0
- package/src/main/conversation/MessageTimer/MessageTimer.d.ts +10 -0
- package/src/main/conversation/MessageTimer/MessageTimer.js +54 -0
- package/src/main/conversation/MessageTimer/index.d.ts +1 -0
- package/src/main/conversation/MessageTimer/index.js +36 -0
- package/src/main/conversation/ReactionType.d.ts +4 -0
- package/src/main/conversation/ReactionType.js +27 -0
- package/src/main/conversation/content/AssetContent.d.ts +42 -0
- package/src/main/conversation/content/AssetContent.js +21 -0
- package/src/main/conversation/content/ButtonActionConfirmationContent.d.ts +2 -0
- package/src/main/conversation/content/ButtonActionConfirmationContent.js +21 -0
- package/src/main/conversation/content/ButtonActionContent.d.ts +2 -0
- package/src/main/conversation/content/ButtonActionContent.js +21 -0
- package/src/main/conversation/content/CallingContent.d.ts +1 -0
- package/src/main/conversation/content/CallingContent.js +21 -0
- package/src/main/conversation/content/ClearedContent.d.ts +2 -0
- package/src/main/conversation/content/ClearedContent.js +21 -0
- package/src/main/conversation/content/ClientActionContent.d.ts +2 -0
- package/src/main/conversation/content/ClientActionContent.js +21 -0
- package/src/main/conversation/content/ClientAddContent.d.ts +4 -0
- package/src/main/conversation/content/ClientAddContent.js +21 -0
- package/src/main/conversation/content/ClientRemoveContent.d.ts +6 -0
- package/src/main/conversation/content/ClientRemoveContent.js +21 -0
- package/src/main/conversation/content/CompositeContent.d.ts +2 -0
- package/src/main/conversation/content/CompositeContent.js +21 -0
- package/src/main/conversation/content/ConfirmationContent.d.ts +2 -0
- package/src/main/conversation/content/ConfirmationContent.js +21 -0
- package/src/main/conversation/content/ContentType.d.ts +21 -0
- package/src/main/conversation/content/ContentType.js +94 -0
- package/src/main/conversation/content/ConversationContent.d.ts +3 -0
- package/src/main/conversation/content/ConversationContent.js +21 -0
- package/src/main/conversation/content/DeletedContent.d.ts +2 -0
- package/src/main/conversation/content/DeletedContent.js +21 -0
- package/src/main/conversation/content/EditedTextContent.d.ts +11 -0
- package/src/main/conversation/content/EditedTextContent.js +21 -0
- package/src/main/conversation/content/FileContent.d.ts +13 -0
- package/src/main/conversation/content/FileContent.js +21 -0
- package/src/main/conversation/content/HiddenContent.d.ts +2 -0
- package/src/main/conversation/content/HiddenContent.js +21 -0
- package/src/main/conversation/content/ImageContent.d.ts +7 -0
- package/src/main/conversation/content/ImageContent.js +21 -0
- package/src/main/conversation/content/KnockContent.d.ts +2 -0
- package/src/main/conversation/content/KnockContent.js +21 -0
- package/src/main/conversation/content/LinkPreviewContent.d.ts +10 -0
- package/src/main/conversation/content/LinkPreviewContent.js +21 -0
- package/src/main/conversation/content/LocationContent.d.ts +9 -0
- package/src/main/conversation/content/LocationContent.js +21 -0
- package/src/main/conversation/content/MentionContent.d.ts +2 -0
- package/src/main/conversation/content/MentionContent.js +21 -0
- package/src/main/conversation/content/QuoteContent.d.ts +7 -0
- package/src/main/conversation/content/QuoteContent.js +21 -0
- package/src/main/conversation/content/ReactionContent.d.ts +7 -0
- package/src/main/conversation/content/ReactionContent.js +21 -0
- package/src/main/conversation/content/TextContent.d.ts +9 -0
- package/src/main/conversation/content/TextContent.js +21 -0
- package/src/main/conversation/content/TweetContent.d.ts +2 -0
- package/src/main/conversation/content/TweetContent.js +21 -0
- package/src/main/conversation/content/index.d.ts +28 -0
- package/src/main/conversation/content/index.js +76 -0
- package/src/main/conversation/index.d.ts +9 -0
- package/src/main/conversation/index.js +44 -0
- package/src/main/conversation/message/CompositeContentBuilder.d.ts +14 -0
- package/src/main/conversation/message/CompositeContentBuilder.js +54 -0
- package/src/main/conversation/message/Message.d.ts +4 -0
- package/src/main/conversation/message/Message.js +21 -0
- package/src/main/conversation/message/MessageBuilder.d.ts +96 -0
- package/src/main/conversation/message/MessageBuilder.js +125 -0
- package/src/main/conversation/message/MessageService.d.ts +67 -0
- package/src/main/conversation/message/MessageService.js +293 -0
- package/src/main/conversation/message/MessageToProtoMapper.d.ts +7 -0
- package/src/main/conversation/message/MessageToProtoMapper.js +99 -0
- package/src/main/conversation/message/OtrMessage.d.ts +80 -0
- package/src/main/conversation/message/OtrMessage.js +21 -0
- package/src/main/conversation/message/PayloadBundle.d.ts +76 -0
- package/src/main/conversation/message/PayloadBundle.js +81 -0
- package/src/main/conversation/message/TeamMessage.d.ts +31 -0
- package/src/main/conversation/message/TeamMessage.js +21 -0
- package/src/main/conversation/message/TextContentBuilder.d.ts +13 -0
- package/src/main/conversation/message/TextContentBuilder.js +75 -0
- package/src/main/conversation/message/UserClientsUtil.d.ts +22 -0
- package/src/main/conversation/message/UserClientsUtil.js +38 -0
- package/src/main/conversation/message/UserMessage.d.ts +43 -0
- package/src/main/conversation/message/UserMessage.js +21 -0
- package/src/main/conversation/message/messageSender.d.ts +4 -0
- package/src/main/conversation/message/messageSender.js +36 -0
- package/src/main/cryptography/AssetCryptography/EncryptedAsset.d.ts +11 -0
- package/src/main/cryptography/AssetCryptography/EncryptedAsset.js +21 -0
- package/src/main/cryptography/AssetCryptography/crypto.browser.d.ts +2 -0
- package/src/main/cryptography/AssetCryptography/crypto.browser.js +46 -0
- package/src/main/cryptography/AssetCryptography/crypto.node.d.ts +2 -0
- package/src/main/cryptography/AssetCryptography/crypto.node.js +72 -0
- package/src/main/cryptography/AssetCryptography/index.d.ts +8 -0
- package/src/main/cryptography/AssetCryptography/index.js +53 -0
- package/src/main/cryptography/AssetCryptography/interfaces.d.ts +9 -0
- package/src/main/cryptography/AssetCryptography/interfaces.js +21 -0
- package/src/main/cryptography/CryptographyDatabaseRepository.d.ts +16 -0
- package/src/main/cryptography/CryptographyDatabaseRepository.js +44 -0
- package/src/main/cryptography/CryptographyService.d.ts +52 -0
- package/src/main/cryptography/CryptographyService.js +205 -0
- package/src/main/cryptography/GenericMessageMapper.d.ts +6 -0
- package/src/main/cryptography/GenericMessageMapper.js +160 -0
- package/src/main/cryptography/MessageHashService.d.ts +16 -0
- package/src/main/cryptography/MessageHashService.js +118 -0
- package/src/main/cryptography/SessionPayloadBundle.d.ts +4 -0
- package/src/main/cryptography/SessionPayloadBundle.js +21 -0
- package/src/main/cryptography/index.d.ts +4 -0
- package/src/main/cryptography/index.js +39 -0
- package/src/main/giphy/GiphyService.d.ts +9 -0
- package/src/main/giphy/GiphyService.js +37 -0
- package/src/main/giphy/index.d.ts +1 -0
- package/src/main/giphy/index.js +36 -0
- package/src/main/index.d.ts +17 -0
- package/src/main/index.js +59 -0
- package/src/main/linkPreview/LinkPreviewService.d.ts +7 -0
- package/src/main/linkPreview/LinkPreviewService.js +52 -0
- package/src/main/linkPreview/index.d.ts +1 -0
- package/src/main/linkPreview/index.js +36 -0
- package/src/main/mls/MLSService/MLSService.d.ts +39 -0
- package/src/main/mls/MLSService/MLSService.js +181 -0
- package/src/main/mls/index.d.ts +1 -0
- package/src/main/mls/index.js +36 -0
- package/src/main/mls/keyMaterialUpdatesStore/index.d.ts +1 -0
- package/src/main/mls/keyMaterialUpdatesStore/index.js +36 -0
- package/src/main/mls/keyMaterialUpdatesStore/keyMaterialUpdatesStore.d.ts +9 -0
- package/src/main/mls/keyMaterialUpdatesStore/keyMaterialUpdatesStore.js +51 -0
- package/src/main/mls/keyPackagesStatusStore/keyPackagesStatusStore.d.ts +7 -0
- package/src/main/mls/keyPackagesStatusStore/keyPackagesStatusStore.js +42 -0
- package/src/main/mls/types.d.ts +33 -0
- package/src/main/mls/types.js +21 -0
- package/src/main/notification/NotificationBackendRepository.d.ts +11 -0
- package/src/main/notification/NotificationBackendRepository.js +34 -0
- package/src/main/notification/NotificationDatabaseRepository.d.ts +42 -0
- package/src/main/notification/NotificationDatabaseRepository.js +97 -0
- package/src/main/notification/NotificationService.d.ts +129 -0
- package/src/main/notification/NotificationService.js +501 -0
- package/src/main/notification/index.d.ts +1 -0
- package/src/main/notification/index.js +36 -0
- package/src/main/notification/types.d.ts +16 -0
- package/src/main/notification/types.js +21 -0
- package/src/main/self/SelfService.d.ts +13 -0
- package/src/main/self/SelfService.js +55 -0
- package/src/main/self/index.d.ts +1 -0
- package/src/main/self/index.js +36 -0
- package/src/main/team/TeamService.d.ts +15 -0
- package/src/main/team/TeamService.js +55 -0
- package/src/main/team/index.d.ts +1 -0
- package/src/main/team/index.js +36 -0
- package/src/main/test/CryptographyHelper.d.ts +4 -0
- package/src/main/test/CryptographyHelper.js +69 -0
- package/src/main/test/PayloadHelper.d.ts +3 -0
- package/src/main/test/PayloadHelper.js +66 -0
- package/src/main/user/UserMapper.d.ts +5 -0
- package/src/main/user/UserMapper.js +88 -0
- package/src/main/user/UserService.d.ts +25 -0
- package/src/main/user/UserService.js +81 -0
- package/src/main/user/index.d.ts +1 -0
- package/src/main/user/index.js +36 -0
- package/src/main/util/LowPrecisionTaskScheduler/LowPrecisionTaskScheduler.d.ts +21 -0
- package/src/main/util/LowPrecisionTaskScheduler/LowPrecisionTaskScheduler.js +62 -0
- package/src/main/util/TaskScheduler/TaskScheduler.d.ts +10 -0
- package/src/main/util/TaskScheduler/TaskScheduler.js +70 -0
- package/src/main/util/TypePredicateUtil.d.ts +7 -0
- package/src/main/util/TypePredicateUtil.js +55 -0
- package/src/main/util/encryptedStore.d.ts +45 -0
- package/src/main/util/encryptedStore.js +116 -0
- package/src/main/util/fullyQualifiedClientIdUtils.d.ts +13 -0
- package/src/main/util/fullyQualifiedClientIdUtils.js +42 -0
- package/src/main/util/index.d.ts +1 -0
- package/src/main/util/index.js +36 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CipherOptions } from '@wireapp/api-client/src/asset';
|
|
2
|
+
import { EncryptedAsset } from './EncryptedAsset';
|
|
3
|
+
interface EncryptOptions extends CipherOptions {
|
|
4
|
+
plainText: Uint8Array;
|
|
5
|
+
}
|
|
6
|
+
export declare const decryptAsset: ({ cipherText, keyBytes, sha256, }: EncryptedAsset) => Promise<Uint8Array>;
|
|
7
|
+
export declare const encryptAsset: ({ plainText, algorithm }: EncryptOptions) => Promise<EncryptedAsset>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Wire
|
|
4
|
+
* Copyright (C) 2021 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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.encryptAsset = exports.decryptAsset = void 0;
|
|
22
|
+
const crypto_node_1 = require("./crypto.node");
|
|
23
|
+
const isEqual = (a, b) => {
|
|
24
|
+
const arrayA = new Uint32Array(a);
|
|
25
|
+
const arrayB = new Uint32Array(b);
|
|
26
|
+
const hasSameLength = arrayA.length === arrayB.length;
|
|
27
|
+
const hasSameValues = arrayA.every((value, index) => value === arrayB[index]);
|
|
28
|
+
return hasSameLength && hasSameValues;
|
|
29
|
+
};
|
|
30
|
+
const decryptAsset = async ({ cipherText, keyBytes, sha256: referenceSha256, }) => {
|
|
31
|
+
const computedSha256 = await crypto_node_1.crypto.digest(cipherText);
|
|
32
|
+
if (!isEqual(computedSha256, referenceSha256)) {
|
|
33
|
+
throw new Error('Encrypted asset does not match its SHA-256 hash');
|
|
34
|
+
}
|
|
35
|
+
return crypto_node_1.crypto.decrypt(cipherText, keyBytes);
|
|
36
|
+
};
|
|
37
|
+
exports.decryptAsset = decryptAsset;
|
|
38
|
+
const encryptAsset = async ({ plainText, algorithm = 'AES-256-CBC' }) => {
|
|
39
|
+
const initializationVector = crypto_node_1.crypto.getRandomValues(16);
|
|
40
|
+
const rawKeyBytes = crypto_node_1.crypto.getRandomValues(32);
|
|
41
|
+
const { key, cipher } = await crypto_node_1.crypto.encrypt(plainText, rawKeyBytes, initializationVector, algorithm);
|
|
42
|
+
const ivCipherText = new Uint8Array(cipher.byteLength + initializationVector.byteLength);
|
|
43
|
+
ivCipherText.set(initializationVector, 0);
|
|
44
|
+
ivCipherText.set(new Uint8Array(cipher), initializationVector.byteLength);
|
|
45
|
+
const sha256 = await crypto_node_1.crypto.digest(ivCipherText);
|
|
46
|
+
return {
|
|
47
|
+
cipherText: ivCipherText,
|
|
48
|
+
keyBytes: key,
|
|
49
|
+
sha256,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
exports.encryptAsset = encryptAsset;
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface Crypto {
|
|
2
|
+
digest(cipherText: Uint8Array): Promise<Uint8Array>;
|
|
3
|
+
decrypt(cipherText: Uint8Array, keyBytes: Uint8Array): Promise<Uint8Array>;
|
|
4
|
+
getRandomValues(size: number): Uint8Array;
|
|
5
|
+
encrypt(plainText: Uint8Array, keyBytes: Uint8Array, initializationVector: Uint8Array, algorithm: string): Promise<{
|
|
6
|
+
key: Uint8Array;
|
|
7
|
+
cipher: Uint8Array | ArrayBuffer;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Wire
|
|
4
|
+
* Copyright (C) 2021 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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
//# sourceMappingURL=interfaces.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CRUDEngine } from '@wireapp/store-engine';
|
|
2
|
+
export declare enum DatabaseStores {
|
|
3
|
+
AMPLIFY = "amplify",
|
|
4
|
+
CLIENTS = "clients",
|
|
5
|
+
KEYS = "keys",
|
|
6
|
+
PRE_KEYS = "prekeys",
|
|
7
|
+
SESSIONS = "sessions",
|
|
8
|
+
GROUP_IDS = "group_ids",
|
|
9
|
+
PENDING_PROPOSALS = "pending_proposals"
|
|
10
|
+
}
|
|
11
|
+
export declare class CryptographyDatabaseRepository {
|
|
12
|
+
private readonly storeEngine;
|
|
13
|
+
static readonly STORES: typeof DatabaseStores;
|
|
14
|
+
constructor(storeEngine: CRUDEngine);
|
|
15
|
+
deleteStores(): Promise<boolean[]>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Wire
|
|
4
|
+
* Copyright (C) 2018 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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.CryptographyDatabaseRepository = exports.DatabaseStores = void 0;
|
|
22
|
+
var DatabaseStores;
|
|
23
|
+
(function (DatabaseStores) {
|
|
24
|
+
DatabaseStores["AMPLIFY"] = "amplify";
|
|
25
|
+
DatabaseStores["CLIENTS"] = "clients";
|
|
26
|
+
DatabaseStores["KEYS"] = "keys";
|
|
27
|
+
DatabaseStores["PRE_KEYS"] = "prekeys";
|
|
28
|
+
DatabaseStores["SESSIONS"] = "sessions";
|
|
29
|
+
DatabaseStores["GROUP_IDS"] = "group_ids";
|
|
30
|
+
DatabaseStores["PENDING_PROPOSALS"] = "pending_proposals";
|
|
31
|
+
})(DatabaseStores = exports.DatabaseStores || (exports.DatabaseStores = {}));
|
|
32
|
+
class CryptographyDatabaseRepository {
|
|
33
|
+
constructor(storeEngine) {
|
|
34
|
+
this.storeEngine = storeEngine;
|
|
35
|
+
}
|
|
36
|
+
deleteStores() {
|
|
37
|
+
return Promise.all(
|
|
38
|
+
//make sure we use enum's lowercase values, not uppercase keys
|
|
39
|
+
Object.values(CryptographyDatabaseRepository.STORES).map(store => this.storeEngine.deleteAll(store)));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.CryptographyDatabaseRepository = CryptographyDatabaseRepository;
|
|
43
|
+
CryptographyDatabaseRepository.STORES = DatabaseStores;
|
|
44
|
+
//# sourceMappingURL=CryptographyDatabaseRepository.js.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { APIClient } from '@wireapp/api-client';
|
|
2
|
+
import { PreKey as SerializedPreKey } from '@wireapp/api-client/src/auth/';
|
|
3
|
+
import { RegisteredClient } from '@wireapp/api-client/src/client/';
|
|
4
|
+
import { OTRRecipients, QualifiedOTRRecipients, QualifiedUserClients, UserClients } from '@wireapp/api-client/src/conversation/';
|
|
5
|
+
import { ConversationOtrMessageAddEvent } from '@wireapp/api-client/src/event';
|
|
6
|
+
import { QualifiedId, QualifiedUserPreKeyBundleMap, UserPreKeyBundleMap } from '@wireapp/api-client/src/user/';
|
|
7
|
+
import { Cryptobox } from '@wireapp/cryptobox';
|
|
8
|
+
import { GenericMessage } from '@wireapp/protocol-messaging';
|
|
9
|
+
import { CRUDEngine } from '@wireapp/store-engine';
|
|
10
|
+
import { PayloadBundle, PayloadBundleSource } from '../conversation';
|
|
11
|
+
export declare type DecryptionError = {
|
|
12
|
+
code: number;
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
15
|
+
export interface MetaClient extends RegisteredClient {
|
|
16
|
+
meta: {
|
|
17
|
+
is_verified?: boolean;
|
|
18
|
+
primary_key: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare class CryptographyService {
|
|
22
|
+
readonly apiClient: APIClient;
|
|
23
|
+
private readonly storeEngine;
|
|
24
|
+
private readonly config;
|
|
25
|
+
private readonly logger;
|
|
26
|
+
cryptobox: Cryptobox;
|
|
27
|
+
private readonly database;
|
|
28
|
+
constructor(apiClient: APIClient, storeEngine: CRUDEngine, config: {
|
|
29
|
+
useQualifiedIds: boolean;
|
|
30
|
+
nbPrekeys: number;
|
|
31
|
+
});
|
|
32
|
+
constructSessionId(userId: string | QualifiedId, clientId: string, domain?: string): string;
|
|
33
|
+
static convertArrayRecipientsToBase64(recipients: OTRRecipients<Uint8Array>): OTRRecipients<string>;
|
|
34
|
+
static convertBase64RecipientsToArray(recipients: OTRRecipients<string>): OTRRecipients<Uint8Array>;
|
|
35
|
+
createCryptobox(entropyData?: Uint8Array): Promise<SerializedPreKey[]>;
|
|
36
|
+
decrypt(sessionId: string, encodedCiphertext: string): Promise<Uint8Array>;
|
|
37
|
+
encryptQualified(plainText: Uint8Array, preKeyBundles: QualifiedUserPreKeyBundleMap | QualifiedUserClients): Promise<{
|
|
38
|
+
missing: QualifiedUserClients;
|
|
39
|
+
encrypted: QualifiedOTRRecipients;
|
|
40
|
+
}>;
|
|
41
|
+
encrypt(plainText: Uint8Array, users: UserPreKeyBundleMap | UserClients, domain?: string): Promise<{
|
|
42
|
+
missing: UserClients;
|
|
43
|
+
encrypted: OTRRecipients<Uint8Array>;
|
|
44
|
+
}>;
|
|
45
|
+
private encryptPayloadForSession;
|
|
46
|
+
initCryptobox(): Promise<void>;
|
|
47
|
+
deleteCryptographyStores(): Promise<boolean[]>;
|
|
48
|
+
resetSession(sessionId: string): Promise<void>;
|
|
49
|
+
decryptMessage(otrMessage: ConversationOtrMessageAddEvent): Promise<GenericMessage>;
|
|
50
|
+
mapGenericMessage(otrMessage: ConversationOtrMessageAddEvent, genericMessage: GenericMessage, source: PayloadBundleSource): PayloadBundle;
|
|
51
|
+
private generateDecryptionError;
|
|
52
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Wire
|
|
4
|
+
* Copyright (C) 2018 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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
21
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.CryptographyService = void 0;
|
|
25
|
+
const cryptobox_1 = require("@wireapp/cryptobox");
|
|
26
|
+
const proteus_1 = require("@wireapp/proteus");
|
|
27
|
+
const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
28
|
+
const bazinga64_1 = require("bazinga64");
|
|
29
|
+
const logdown_1 = __importDefault(require("logdown"));
|
|
30
|
+
const conversation_1 = require("../conversation");
|
|
31
|
+
const util_1 = require("../util");
|
|
32
|
+
const CryptographyDatabaseRepository_1 = require("./CryptographyDatabaseRepository");
|
|
33
|
+
const GenericMessageMapper_1 = require("./GenericMessageMapper");
|
|
34
|
+
class CryptographyService {
|
|
35
|
+
constructor(apiClient, storeEngine, config) {
|
|
36
|
+
this.apiClient = apiClient;
|
|
37
|
+
this.storeEngine = storeEngine;
|
|
38
|
+
this.config = config;
|
|
39
|
+
this.cryptobox = new cryptobox_1.Cryptobox(this.storeEngine, config.nbPrekeys);
|
|
40
|
+
this.database = new CryptographyDatabaseRepository_1.CryptographyDatabaseRepository(this.storeEngine);
|
|
41
|
+
this.logger = (0, logdown_1.default)('@wireapp/core/cryptography/CryptographyService', {
|
|
42
|
+
logger: console,
|
|
43
|
+
markdown: false,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
constructSessionId(userId, clientId, domain) {
|
|
47
|
+
const { id, domain: baseDomain } = typeof userId === 'string' ? { id: userId, domain } : userId;
|
|
48
|
+
const baseId = `${id}@${clientId}`;
|
|
49
|
+
return baseDomain && this.config.useQualifiedIds ? `${baseDomain}@${baseId}` : baseId;
|
|
50
|
+
}
|
|
51
|
+
static convertArrayRecipientsToBase64(recipients) {
|
|
52
|
+
return Object.fromEntries(Object.entries(recipients).map(([userId, otrClientMap]) => {
|
|
53
|
+
const otrClientMapWithBase64 = Object.fromEntries(Object.entries(otrClientMap).map(([clientId, payload]) => {
|
|
54
|
+
return [clientId, bazinga64_1.Encoder.toBase64(payload).asString];
|
|
55
|
+
}));
|
|
56
|
+
return [userId, otrClientMapWithBase64];
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
static convertBase64RecipientsToArray(recipients) {
|
|
60
|
+
return Object.fromEntries(Object.entries(recipients).map(([userId, otrClientMap]) => {
|
|
61
|
+
const otrClientMapWithUint8Array = Object.fromEntries(Object.entries(otrClientMap).map(([clientId, payload]) => {
|
|
62
|
+
return [clientId, bazinga64_1.Decoder.fromBase64(payload).asBytes];
|
|
63
|
+
}));
|
|
64
|
+
return [userId, otrClientMapWithUint8Array];
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
async createCryptobox(entropyData) {
|
|
68
|
+
const initialPreKeys = await this.cryptobox.create(entropyData);
|
|
69
|
+
return initialPreKeys
|
|
70
|
+
.map(preKey => {
|
|
71
|
+
const preKeyJson = this.cryptobox.serialize_prekey(preKey);
|
|
72
|
+
if (preKeyJson.id !== proteus_1.keys.PreKey.MAX_PREKEY_ID) {
|
|
73
|
+
return preKeyJson;
|
|
74
|
+
}
|
|
75
|
+
return { id: -1, key: '' };
|
|
76
|
+
})
|
|
77
|
+
.filter(serializedPreKey => serializedPreKey.key);
|
|
78
|
+
}
|
|
79
|
+
decrypt(sessionId, encodedCiphertext) {
|
|
80
|
+
this.logger.log(`Decrypting message for session ID "${sessionId}"`);
|
|
81
|
+
const messageBytes = bazinga64_1.Decoder.fromBase64(encodedCiphertext).asBytes;
|
|
82
|
+
return this.cryptobox.decrypt(sessionId, messageBytes.buffer);
|
|
83
|
+
}
|
|
84
|
+
async encryptQualified(plainText, preKeyBundles) {
|
|
85
|
+
const qualifiedOTRRecipients = {};
|
|
86
|
+
const missing = {};
|
|
87
|
+
for (const [domain, preKeyBundleMap] of Object.entries(preKeyBundles)) {
|
|
88
|
+
const result = await this.encrypt(plainText, preKeyBundleMap, domain);
|
|
89
|
+
qualifiedOTRRecipients[domain] = result.encrypted;
|
|
90
|
+
missing[domain] = result.missing;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
encrypted: qualifiedOTRRecipients,
|
|
94
|
+
missing,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
async encrypt(plainText, users, domain) {
|
|
98
|
+
var _a;
|
|
99
|
+
const encrypted = {};
|
|
100
|
+
const missing = {};
|
|
101
|
+
for (const userId in users) {
|
|
102
|
+
const clientIds = (0, util_1.isUserClients)(users)
|
|
103
|
+
? users[userId]
|
|
104
|
+
: Object.keys(users[userId])
|
|
105
|
+
// We filter out clients that have `null` prekey
|
|
106
|
+
.filter(clientId => !!users[userId][clientId]);
|
|
107
|
+
for (const clientId of clientIds) {
|
|
108
|
+
const base64PreKey = (0, util_1.isUserClients)(users) ? undefined : (_a = users[userId][clientId]) === null || _a === void 0 ? void 0 : _a.key;
|
|
109
|
+
const sessionId = this.constructSessionId(userId, clientId, domain);
|
|
110
|
+
const result = await this.encryptPayloadForSession(sessionId, plainText, base64PreKey);
|
|
111
|
+
if (result) {
|
|
112
|
+
encrypted[userId] || (encrypted[userId] = {});
|
|
113
|
+
encrypted[userId][clientId] = result.encryptedPayload;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
missing[userId] || (missing[userId] = []);
|
|
117
|
+
missing[userId].push(clientId);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return { encrypted, missing };
|
|
122
|
+
}
|
|
123
|
+
async encryptPayloadForSession(sessionId, plainText, base64EncodedPreKey) {
|
|
124
|
+
this.logger.log(`Encrypting payload for session ID "${sessionId}"`);
|
|
125
|
+
let encryptedPayload;
|
|
126
|
+
try {
|
|
127
|
+
const decodedPreKeyBundle = base64EncodedPreKey
|
|
128
|
+
? bazinga64_1.Decoder.fromBase64(base64EncodedPreKey).asBytes.buffer
|
|
129
|
+
: undefined;
|
|
130
|
+
const payloadAsArrayBuffer = await this.cryptobox.encrypt(sessionId, plainText, decodedPreKeyBundle);
|
|
131
|
+
encryptedPayload = new Uint8Array(payloadAsArrayBuffer);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
const notFoundErrorCode = 2;
|
|
135
|
+
if (error.code === notFoundErrorCode) {
|
|
136
|
+
// If the session is not in the database, we just return undefined. Later on there will be a mismatch and the session will be created
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
this.logger.error(`Could not encrypt payload: ${error.message}`);
|
|
140
|
+
encryptedPayload = new Uint8Array(Buffer.from('💣', 'utf-8'));
|
|
141
|
+
}
|
|
142
|
+
return { encryptedPayload, sessionId };
|
|
143
|
+
}
|
|
144
|
+
async initCryptobox() {
|
|
145
|
+
await this.cryptobox.load();
|
|
146
|
+
}
|
|
147
|
+
deleteCryptographyStores() {
|
|
148
|
+
return this.database.deleteStores();
|
|
149
|
+
}
|
|
150
|
+
async resetSession(sessionId) {
|
|
151
|
+
await this.cryptobox.session_delete(sessionId);
|
|
152
|
+
this.logger.log(`Deleted session ID "${sessionId}".`);
|
|
153
|
+
}
|
|
154
|
+
async decryptMessage(otrMessage) {
|
|
155
|
+
const { from, qualified_from, data: { sender, text: cipherText }, } = otrMessage;
|
|
156
|
+
const sessionId = this.constructSessionId(from, sender, qualified_from === null || qualified_from === void 0 ? void 0 : qualified_from.domain);
|
|
157
|
+
try {
|
|
158
|
+
const decryptedMessage = await this.decrypt(sessionId, cipherText);
|
|
159
|
+
return protocol_messaging_1.GenericMessage.decode(decryptedMessage);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
throw this.generateDecryptionError(otrMessage, error);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
mapGenericMessage(otrMessage, genericMessage, source) {
|
|
166
|
+
if (genericMessage.content === conversation_1.GenericMessageType.EPHEMERAL) {
|
|
167
|
+
const unwrappedMessage = GenericMessageMapper_1.GenericMessageMapper.mapGenericMessage(genericMessage.ephemeral, otrMessage, source);
|
|
168
|
+
unwrappedMessage.id = genericMessage.messageId;
|
|
169
|
+
if (genericMessage.ephemeral) {
|
|
170
|
+
const expireAfterMillis = genericMessage.ephemeral.expireAfterMillis;
|
|
171
|
+
unwrappedMessage.messageTimer =
|
|
172
|
+
typeof expireAfterMillis === 'number' ? expireAfterMillis : expireAfterMillis.toNumber();
|
|
173
|
+
}
|
|
174
|
+
return unwrappedMessage;
|
|
175
|
+
}
|
|
176
|
+
return GenericMessageMapper_1.GenericMessageMapper.mapGenericMessage(genericMessage, otrMessage, source);
|
|
177
|
+
}
|
|
178
|
+
generateDecryptionError(event, error) {
|
|
179
|
+
var _a;
|
|
180
|
+
const errorCode = (_a = error.code) !== null && _a !== void 0 ? _a : 999;
|
|
181
|
+
let message = 'Unknown decryption error';
|
|
182
|
+
const { data: eventData, from: remoteUserId, time: formattedTime } = event;
|
|
183
|
+
const remoteClientId = eventData.sender;
|
|
184
|
+
const isDuplicateMessage = error instanceof proteus_1.errors.DecryptError.DuplicateMessage;
|
|
185
|
+
const isOutdatedMessage = error instanceof proteus_1.errors.DecryptError.OutdatedMessage;
|
|
186
|
+
// We don't need to show these message errors to the user
|
|
187
|
+
if (isDuplicateMessage || isOutdatedMessage) {
|
|
188
|
+
message = `Message from user ID "${remoteUserId}" at "${formattedTime}" will not be handled because it is outdated or a duplicate.`;
|
|
189
|
+
}
|
|
190
|
+
const isInvalidMessage = error instanceof proteus_1.errors.DecryptError.InvalidMessage;
|
|
191
|
+
const isInvalidSignature = error instanceof proteus_1.errors.DecryptError.InvalidSignature;
|
|
192
|
+
const isRemoteIdentityChanged = error instanceof proteus_1.errors.DecryptError.RemoteIdentityChanged;
|
|
193
|
+
// Session is broken, let's see what's really causing it...
|
|
194
|
+
if (isInvalidMessage || isInvalidSignature) {
|
|
195
|
+
message = `Session with user '${remoteUserId}' (${remoteClientId}) is broken.\nReset the session for possible fix.`;
|
|
196
|
+
}
|
|
197
|
+
else if (isRemoteIdentityChanged) {
|
|
198
|
+
message = `Remote identity of client '${remoteClientId}' from user '${remoteUserId}' changed`;
|
|
199
|
+
}
|
|
200
|
+
this.logger.warn(`Failed to decrypt event from client '${remoteClientId}' of user '${remoteUserId}' (${formattedTime}).\nError Code: '${errorCode}'\nError Message: ${error.message}`, error);
|
|
201
|
+
return { code: errorCode, message };
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
exports.CryptographyService = CryptographyService;
|
|
205
|
+
//# sourceMappingURL=CryptographyService.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ConversationOtrMessageAddEvent } from '@wireapp/api-client/src/event/';
|
|
2
|
+
import { PayloadBundle, PayloadBundleSource } from '../conversation';
|
|
3
|
+
export declare class GenericMessageMapper {
|
|
4
|
+
private static readonly logger;
|
|
5
|
+
static mapGenericMessage(genericMessage: any, event: ConversationOtrMessageAddEvent, source: PayloadBundleSource): PayloadBundle;
|
|
6
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Wire
|
|
4
|
+
* Copyright (C) 2019 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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
21
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
|
+
};
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.GenericMessageMapper = void 0;
|
|
25
|
+
const logdown_1 = __importDefault(require("logdown"));
|
|
26
|
+
const conversation_1 = require("../conversation");
|
|
27
|
+
class GenericMessageMapper {
|
|
28
|
+
// TODO: Turn "any" into a specific type (or collection of types) and make the return type more specific based on the
|
|
29
|
+
// "genericMessage" input parameter.
|
|
30
|
+
static mapGenericMessage(genericMessage, event, source) {
|
|
31
|
+
const baseMessage = {
|
|
32
|
+
conversation: event.conversation,
|
|
33
|
+
qualifiedConversation: event.qualified_conversation,
|
|
34
|
+
qualifiedFrom: event.qualified_from,
|
|
35
|
+
fromClientId: event.data.sender,
|
|
36
|
+
from: event.from,
|
|
37
|
+
state: conversation_1.PayloadBundleState.INCOMING,
|
|
38
|
+
timestamp: new Date(event.time).getTime(),
|
|
39
|
+
id: genericMessage.messageId,
|
|
40
|
+
messageTimer: 0,
|
|
41
|
+
source,
|
|
42
|
+
};
|
|
43
|
+
switch (genericMessage.content) {
|
|
44
|
+
case conversation_1.GenericMessageType.TEXT: {
|
|
45
|
+
const { content: text, expectsReadConfirmation, legalHoldStatus, linkPreview: linkPreviews, mentions, quote, } = genericMessage[conversation_1.GenericMessageType.TEXT];
|
|
46
|
+
const content = { expectsReadConfirmation, legalHoldStatus, text };
|
|
47
|
+
if (linkPreviews === null || linkPreviews === void 0 ? void 0 : linkPreviews.length) {
|
|
48
|
+
content.linkPreviews = linkPreviews;
|
|
49
|
+
}
|
|
50
|
+
if (mentions === null || mentions === void 0 ? void 0 : mentions.length) {
|
|
51
|
+
content.mentions = mentions;
|
|
52
|
+
}
|
|
53
|
+
if (quote) {
|
|
54
|
+
content.quote = quote;
|
|
55
|
+
}
|
|
56
|
+
if (typeof legalHoldStatus !== 'undefined') {
|
|
57
|
+
content.legalHoldStatus = legalHoldStatus;
|
|
58
|
+
}
|
|
59
|
+
return Object.assign(Object.assign({}, baseMessage), { content, type: conversation_1.PayloadBundleType.TEXT });
|
|
60
|
+
}
|
|
61
|
+
case conversation_1.GenericMessageType.BUTTON_ACTION: {
|
|
62
|
+
return Object.assign(Object.assign({}, baseMessage), { content: genericMessage.buttonAction, type: conversation_1.PayloadBundleType.BUTTON_ACTION });
|
|
63
|
+
}
|
|
64
|
+
case conversation_1.GenericMessageType.CALLING: {
|
|
65
|
+
return Object.assign(Object.assign({}, baseMessage), { content: genericMessage.calling.content, type: conversation_1.PayloadBundleType.CALL });
|
|
66
|
+
}
|
|
67
|
+
case conversation_1.GenericMessageType.CONFIRMATION: {
|
|
68
|
+
const { firstMessageId, moreMessageIds, type } = genericMessage[conversation_1.GenericMessageType.CONFIRMATION];
|
|
69
|
+
const content = { firstMessageId, moreMessageIds, type };
|
|
70
|
+
return Object.assign(Object.assign({}, baseMessage), { content, type: conversation_1.PayloadBundleType.CONFIRMATION });
|
|
71
|
+
}
|
|
72
|
+
case conversation_1.GenericMessageType.CLEARED: {
|
|
73
|
+
const content = genericMessage[conversation_1.GenericMessageType.CLEARED];
|
|
74
|
+
return Object.assign(Object.assign({}, baseMessage), { content, type: conversation_1.PayloadBundleType.CONVERSATION_CLEAR });
|
|
75
|
+
}
|
|
76
|
+
case conversation_1.GenericMessageType.DELETED: {
|
|
77
|
+
const originalMessageId = genericMessage[conversation_1.GenericMessageType.DELETED].messageId;
|
|
78
|
+
const content = { messageId: originalMessageId };
|
|
79
|
+
return Object.assign(Object.assign({}, baseMessage), { content, type: conversation_1.PayloadBundleType.MESSAGE_DELETE });
|
|
80
|
+
}
|
|
81
|
+
case conversation_1.GenericMessageType.EDITED: {
|
|
82
|
+
const { expectsReadConfirmation, text: { content: editedText, legalHoldStatus, linkPreview: editedLinkPreviews, mentions: editedMentions, quote: editedQuote, }, replacingMessageId, } = genericMessage[conversation_1.GenericMessageType.EDITED];
|
|
83
|
+
const content = {
|
|
84
|
+
expectsReadConfirmation,
|
|
85
|
+
legalHoldStatus,
|
|
86
|
+
originalMessageId: replacingMessageId,
|
|
87
|
+
text: editedText,
|
|
88
|
+
};
|
|
89
|
+
if (editedLinkPreviews === null || editedLinkPreviews === void 0 ? void 0 : editedLinkPreviews.length) {
|
|
90
|
+
content.linkPreviews = editedLinkPreviews;
|
|
91
|
+
}
|
|
92
|
+
if (editedMentions === null || editedMentions === void 0 ? void 0 : editedMentions.length) {
|
|
93
|
+
content.mentions = editedMentions;
|
|
94
|
+
}
|
|
95
|
+
if (editedQuote) {
|
|
96
|
+
content.quote = editedQuote;
|
|
97
|
+
}
|
|
98
|
+
return Object.assign(Object.assign({}, baseMessage), { content, type: conversation_1.PayloadBundleType.MESSAGE_EDIT });
|
|
99
|
+
}
|
|
100
|
+
case conversation_1.GenericMessageType.HIDDEN: {
|
|
101
|
+
const { conversationId, messageId } = genericMessage[conversation_1.GenericMessageType.HIDDEN];
|
|
102
|
+
const content = {
|
|
103
|
+
conversationId,
|
|
104
|
+
messageId,
|
|
105
|
+
};
|
|
106
|
+
return Object.assign(Object.assign({}, baseMessage), { content, type: conversation_1.PayloadBundleType.MESSAGE_HIDE });
|
|
107
|
+
}
|
|
108
|
+
case conversation_1.GenericMessageType.KNOCK: {
|
|
109
|
+
const { expectsReadConfirmation, legalHoldStatus } = genericMessage[conversation_1.GenericMessageType.KNOCK];
|
|
110
|
+
const content = { expectsReadConfirmation, hotKnock: false, legalHoldStatus };
|
|
111
|
+
return Object.assign(Object.assign({}, baseMessage), { content, type: conversation_1.PayloadBundleType.PING });
|
|
112
|
+
}
|
|
113
|
+
case conversation_1.GenericMessageType.LOCATION: {
|
|
114
|
+
const { expectsReadConfirmation, latitude, legalHoldStatus, longitude, name, zoom } = genericMessage[conversation_1.GenericMessageType.LOCATION];
|
|
115
|
+
const content = {
|
|
116
|
+
expectsReadConfirmation,
|
|
117
|
+
latitude,
|
|
118
|
+
legalHoldStatus,
|
|
119
|
+
longitude,
|
|
120
|
+
name,
|
|
121
|
+
zoom,
|
|
122
|
+
};
|
|
123
|
+
return Object.assign(Object.assign({}, baseMessage), { content, type: conversation_1.PayloadBundleType.LOCATION });
|
|
124
|
+
}
|
|
125
|
+
case conversation_1.GenericMessageType.ASSET: {
|
|
126
|
+
const { expectsReadConfirmation, legalHoldStatus, notUploaded, original, preview, status, uploaded } = genericMessage[conversation_1.GenericMessageType.ASSET];
|
|
127
|
+
const isImage = !!(uploaded === null || uploaded === void 0 ? void 0 : uploaded.assetId) && !!(original === null || original === void 0 ? void 0 : original.image);
|
|
128
|
+
const content = {
|
|
129
|
+
abortReason: notUploaded,
|
|
130
|
+
expectsReadConfirmation,
|
|
131
|
+
legalHoldStatus,
|
|
132
|
+
original,
|
|
133
|
+
preview,
|
|
134
|
+
status,
|
|
135
|
+
uploaded,
|
|
136
|
+
};
|
|
137
|
+
return Object.assign(Object.assign({}, baseMessage), { content, type: isImage ? conversation_1.PayloadBundleType.ASSET_IMAGE : conversation_1.PayloadBundleType.ASSET });
|
|
138
|
+
}
|
|
139
|
+
case conversation_1.GenericMessageType.REACTION: {
|
|
140
|
+
const { emoji, legalHoldStatus, messageId } = genericMessage[conversation_1.GenericMessageType.REACTION];
|
|
141
|
+
const content = {
|
|
142
|
+
legalHoldStatus,
|
|
143
|
+
originalMessageId: messageId,
|
|
144
|
+
type: emoji,
|
|
145
|
+
};
|
|
146
|
+
return Object.assign(Object.assign({}, baseMessage), { content, type: conversation_1.PayloadBundleType.REACTION });
|
|
147
|
+
}
|
|
148
|
+
default: {
|
|
149
|
+
this.logger.warn(`Unhandled event type "${genericMessage.content}": ${JSON.stringify(genericMessage)}`);
|
|
150
|
+
return Object.assign(Object.assign({}, baseMessage), { content: genericMessage.content, type: conversation_1.PayloadBundleType.UNKNOWN });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.GenericMessageMapper = GenericMessageMapper;
|
|
156
|
+
GenericMessageMapper.logger = (0, logdown_1.default)('@wireapp/core/cryptography/GenericMessageMapper', {
|
|
157
|
+
logger: console,
|
|
158
|
+
markdown: false,
|
|
159
|
+
});
|
|
160
|
+
//# sourceMappingURL=GenericMessageMapper.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AssetContent, LocationContent, TextContent } from '../conversation/content';
|
|
3
|
+
export declare type AvailableMessageContent = AssetContent | LocationContent | TextContent;
|
|
4
|
+
export declare class MessageHashService {
|
|
5
|
+
private readonly messageContent;
|
|
6
|
+
private readonly timestamp;
|
|
7
|
+
constructor(messageContent: AvailableMessageContent, timestamp?: number);
|
|
8
|
+
private createSha256Hash;
|
|
9
|
+
private convertToUtf16BE;
|
|
10
|
+
private getAssetBytes;
|
|
11
|
+
private getTimestampBuffer;
|
|
12
|
+
private getLocationBytes;
|
|
13
|
+
private getTextBytes;
|
|
14
|
+
private getBytes;
|
|
15
|
+
getHash(): Buffer;
|
|
16
|
+
}
|