@wireapp/core 31.1.3 → 31.1.4

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 (227) hide show
  1. package/package.json +9 -8
  2. package/src/main/Account.d.ts +214 -0
  3. package/src/main/Account.js +463 -0
  4. package/src/main/CoreError.d.ts +9 -0
  5. package/src/main/CoreError.js +26 -0
  6. package/src/main/account/AccountService.d.ts +7 -0
  7. package/src/main/account/AccountService.js +33 -0
  8. package/src/main/account/AccountService.js.map +1 -0
  9. package/src/main/account/index.d.ts +1 -0
  10. package/src/main/account/index.js +36 -0
  11. package/src/main/account/index.js.map +1 -0
  12. package/src/main/auth/LoginSanitizer.d.ts +5 -0
  13. package/src/main/auth/LoginSanitizer.js +41 -0
  14. package/src/main/auth/index.d.ts +1 -0
  15. package/src/main/auth/index.js +36 -0
  16. package/src/main/broadcast/AvailabilityType.d.ts +2 -0
  17. package/src/main/broadcast/AvailabilityType.js +21 -0
  18. package/src/main/broadcast/BroadcastService.d.ts +24 -0
  19. package/src/main/broadcast/BroadcastService.js +74 -0
  20. package/src/main/broadcast/index.d.ts +2 -0
  21. package/src/main/broadcast/index.js +37 -0
  22. package/src/main/client/ClientBackendRepository.d.ts +11 -0
  23. package/src/main/client/ClientBackendRepository.js +43 -0
  24. package/src/main/client/ClientDatabaseRepository.d.ts +27 -0
  25. package/src/main/client/ClientDatabaseRepository.js +85 -0
  26. package/src/main/client/ClientInfo.d.ts +8 -0
  27. package/src/main/client/ClientInfo.js +21 -0
  28. package/src/main/client/ClientService.d.ts +40 -0
  29. package/src/main/client/ClientService.js +103 -0
  30. package/src/main/client/index.d.ts +4 -0
  31. package/src/main/client/index.js +39 -0
  32. package/src/main/connection/ConnectionService.d.ts +11 -0
  33. package/src/main/connection/ConnectionService.js +45 -0
  34. package/src/main/connection/index.d.ts +1 -0
  35. package/src/main/connection/index.js +36 -0
  36. package/src/main/conversation/AbortReason.d.ts +2 -0
  37. package/src/main/conversation/AbortReason.js +21 -0
  38. package/src/main/conversation/AssetService/AssetService.d.ts +62 -0
  39. package/src/main/conversation/AssetService/AssetService.js +88 -0
  40. package/src/main/conversation/AssetService/index.d.ts +1 -0
  41. package/src/main/conversation/AssetService/index.js +36 -0
  42. package/src/main/conversation/AssetTransferState.d.ts +4 -0
  43. package/src/main/conversation/AssetTransferState.js +27 -0
  44. package/src/main/conversation/ClientActionType.d.ts +1 -0
  45. package/src/main/conversation/ClientActionType.js +24 -0
  46. package/src/main/conversation/ConversationMapper/ConversationMapper.d.ts +6 -0
  47. package/src/main/conversation/ConversationMapper/ConversationMapper.js +57 -0
  48. package/src/main/conversation/ConversationMapper/index.d.ts +1 -0
  49. package/src/main/conversation/ConversationMapper/index.js +36 -0
  50. package/src/main/conversation/ConversationService/ConversationService.d.ts +149 -0
  51. package/src/main/conversation/ConversationService/ConversationService.js +584 -0
  52. package/src/main/conversation/ConversationService/ConversationService.types.d.ts +110 -0
  53. package/src/main/conversation/ConversationService/ConversationService.types.js +28 -0
  54. package/src/main/conversation/ConversationService/index.d.ts +2 -0
  55. package/src/main/conversation/ConversationService/index.js +37 -0
  56. package/src/main/conversation/ConversationService/messageGenerator.d.ts +9 -0
  57. package/src/main/conversation/ConversationService/messageGenerator.js +313 -0
  58. package/src/main/conversation/GenericMessageType.d.ts +25 -0
  59. package/src/main/conversation/GenericMessageType.js +49 -0
  60. package/src/main/conversation/MessageTimer/MessageTimer.d.ts +10 -0
  61. package/src/main/conversation/MessageTimer/MessageTimer.js +54 -0
  62. package/src/main/conversation/MessageTimer/index.d.ts +1 -0
  63. package/src/main/conversation/MessageTimer/index.js +36 -0
  64. package/src/main/conversation/ReactionType.d.ts +4 -0
  65. package/src/main/conversation/ReactionType.js +27 -0
  66. package/src/main/conversation/content/AssetContent.d.ts +42 -0
  67. package/src/main/conversation/content/AssetContent.js +21 -0
  68. package/src/main/conversation/content/ButtonActionConfirmationContent.d.ts +2 -0
  69. package/src/main/conversation/content/ButtonActionConfirmationContent.js +21 -0
  70. package/src/main/conversation/content/ButtonActionContent.d.ts +2 -0
  71. package/src/main/conversation/content/ButtonActionContent.js +21 -0
  72. package/src/main/conversation/content/CallingContent.d.ts +1 -0
  73. package/src/main/conversation/content/CallingContent.js +21 -0
  74. package/src/main/conversation/content/ClearedContent.d.ts +2 -0
  75. package/src/main/conversation/content/ClearedContent.js +21 -0
  76. package/src/main/conversation/content/ClientActionContent.d.ts +2 -0
  77. package/src/main/conversation/content/ClientActionContent.js +21 -0
  78. package/src/main/conversation/content/ClientAddContent.d.ts +4 -0
  79. package/src/main/conversation/content/ClientAddContent.js +21 -0
  80. package/src/main/conversation/content/ClientRemoveContent.d.ts +6 -0
  81. package/src/main/conversation/content/ClientRemoveContent.js +21 -0
  82. package/src/main/conversation/content/CompositeContent.d.ts +2 -0
  83. package/src/main/conversation/content/CompositeContent.js +21 -0
  84. package/src/main/conversation/content/ConfirmationContent.d.ts +2 -0
  85. package/src/main/conversation/content/ConfirmationContent.js +21 -0
  86. package/src/main/conversation/content/ContentType.d.ts +21 -0
  87. package/src/main/conversation/content/ContentType.js +94 -0
  88. package/src/main/conversation/content/ConversationContent.d.ts +3 -0
  89. package/src/main/conversation/content/ConversationContent.js +21 -0
  90. package/src/main/conversation/content/DeletedContent.d.ts +2 -0
  91. package/src/main/conversation/content/DeletedContent.js +21 -0
  92. package/src/main/conversation/content/EditedTextContent.d.ts +11 -0
  93. package/src/main/conversation/content/EditedTextContent.js +21 -0
  94. package/src/main/conversation/content/FileContent.d.ts +13 -0
  95. package/src/main/conversation/content/FileContent.js +21 -0
  96. package/src/main/conversation/content/HiddenContent.d.ts +2 -0
  97. package/src/main/conversation/content/HiddenContent.js +21 -0
  98. package/src/main/conversation/content/ImageContent.d.ts +7 -0
  99. package/src/main/conversation/content/ImageContent.js +21 -0
  100. package/src/main/conversation/content/KnockContent.d.ts +2 -0
  101. package/src/main/conversation/content/KnockContent.js +21 -0
  102. package/src/main/conversation/content/LinkPreviewContent.d.ts +10 -0
  103. package/src/main/conversation/content/LinkPreviewContent.js +21 -0
  104. package/src/main/conversation/content/LocationContent.d.ts +9 -0
  105. package/src/main/conversation/content/LocationContent.js +21 -0
  106. package/src/main/conversation/content/MentionContent.d.ts +2 -0
  107. package/src/main/conversation/content/MentionContent.js +21 -0
  108. package/src/main/conversation/content/QuoteContent.d.ts +7 -0
  109. package/src/main/conversation/content/QuoteContent.js +21 -0
  110. package/src/main/conversation/content/ReactionContent.d.ts +7 -0
  111. package/src/main/conversation/content/ReactionContent.js +21 -0
  112. package/src/main/conversation/content/TextContent.d.ts +9 -0
  113. package/src/main/conversation/content/TextContent.js +21 -0
  114. package/src/main/conversation/content/TweetContent.d.ts +2 -0
  115. package/src/main/conversation/content/TweetContent.js +21 -0
  116. package/src/main/conversation/content/index.d.ts +28 -0
  117. package/src/main/conversation/content/index.js +76 -0
  118. package/src/main/conversation/index.d.ts +9 -0
  119. package/src/main/conversation/index.js +44 -0
  120. package/src/main/conversation/message/CompositeContentBuilder.d.ts +14 -0
  121. package/src/main/conversation/message/CompositeContentBuilder.js +54 -0
  122. package/src/main/conversation/message/Message.d.ts +4 -0
  123. package/src/main/conversation/message/Message.js +21 -0
  124. package/src/main/conversation/message/MessageBuilder.d.ts +96 -0
  125. package/src/main/conversation/message/MessageBuilder.js +125 -0
  126. package/src/main/conversation/message/MessageService.d.ts +67 -0
  127. package/src/main/conversation/message/MessageService.js +293 -0
  128. package/src/main/conversation/message/MessageToProtoMapper.d.ts +7 -0
  129. package/src/main/conversation/message/MessageToProtoMapper.js +99 -0
  130. package/src/main/conversation/message/OtrMessage.d.ts +80 -0
  131. package/src/main/conversation/message/OtrMessage.js +21 -0
  132. package/src/main/conversation/message/PayloadBundle.d.ts +76 -0
  133. package/src/main/conversation/message/PayloadBundle.js +81 -0
  134. package/src/main/conversation/message/TeamMessage.d.ts +31 -0
  135. package/src/main/conversation/message/TeamMessage.js +21 -0
  136. package/src/main/conversation/message/TextContentBuilder.d.ts +13 -0
  137. package/src/main/conversation/message/TextContentBuilder.js +75 -0
  138. package/src/main/conversation/message/UserClientsUtil.d.ts +22 -0
  139. package/src/main/conversation/message/UserClientsUtil.js +38 -0
  140. package/src/main/conversation/message/UserMessage.d.ts +43 -0
  141. package/src/main/conversation/message/UserMessage.js +21 -0
  142. package/src/main/conversation/message/messageSender.d.ts +4 -0
  143. package/src/main/conversation/message/messageSender.js +36 -0
  144. package/src/main/cryptography/AssetCryptography/EncryptedAsset.d.ts +11 -0
  145. package/src/main/cryptography/AssetCryptography/EncryptedAsset.js +21 -0
  146. package/src/main/cryptography/AssetCryptography/crypto.browser.d.ts +2 -0
  147. package/src/main/cryptography/AssetCryptography/crypto.browser.js +46 -0
  148. package/src/main/cryptography/AssetCryptography/crypto.node.d.ts +2 -0
  149. package/src/main/cryptography/AssetCryptography/crypto.node.js +72 -0
  150. package/src/main/cryptography/AssetCryptography/index.d.ts +8 -0
  151. package/src/main/cryptography/AssetCryptography/index.js +53 -0
  152. package/src/main/cryptography/AssetCryptography/interfaces.d.ts +9 -0
  153. package/src/main/cryptography/AssetCryptography/interfaces.js +21 -0
  154. package/src/main/cryptography/CryptographyDatabaseRepository.d.ts +16 -0
  155. package/src/main/cryptography/CryptographyDatabaseRepository.js +44 -0
  156. package/src/main/cryptography/CryptographyService.d.ts +52 -0
  157. package/src/main/cryptography/CryptographyService.js +205 -0
  158. package/src/main/cryptography/GenericMessageMapper.d.ts +6 -0
  159. package/src/main/cryptography/GenericMessageMapper.js +160 -0
  160. package/src/main/cryptography/MessageHashService.d.ts +16 -0
  161. package/src/main/cryptography/MessageHashService.js +118 -0
  162. package/src/main/cryptography/SessionPayloadBundle.d.ts +4 -0
  163. package/src/main/cryptography/SessionPayloadBundle.js +21 -0
  164. package/src/main/cryptography/index.d.ts +4 -0
  165. package/src/main/cryptography/index.js +39 -0
  166. package/src/main/giphy/GiphyService.d.ts +9 -0
  167. package/src/main/giphy/GiphyService.js +37 -0
  168. package/src/main/giphy/index.d.ts +1 -0
  169. package/src/main/giphy/index.js +36 -0
  170. package/src/main/index.d.ts +17 -0
  171. package/src/main/index.js +59 -0
  172. package/src/main/linkPreview/LinkPreviewService.d.ts +7 -0
  173. package/src/main/linkPreview/LinkPreviewService.js +52 -0
  174. package/src/main/linkPreview/index.d.ts +1 -0
  175. package/src/main/linkPreview/index.js +36 -0
  176. package/src/main/mls/MLSService/MLSService.d.ts +39 -0
  177. package/src/main/mls/MLSService/MLSService.js +181 -0
  178. package/src/main/mls/index.d.ts +1 -0
  179. package/src/main/mls/index.js +36 -0
  180. package/src/main/mls/keyMaterialUpdatesStore/index.d.ts +1 -0
  181. package/src/main/mls/keyMaterialUpdatesStore/index.js +36 -0
  182. package/src/main/mls/keyMaterialUpdatesStore/keyMaterialUpdatesStore.d.ts +9 -0
  183. package/src/main/mls/keyMaterialUpdatesStore/keyMaterialUpdatesStore.js +51 -0
  184. package/src/main/mls/keyPackagesStatusStore/keyPackagesStatusStore.d.ts +7 -0
  185. package/src/main/mls/keyPackagesStatusStore/keyPackagesStatusStore.js +42 -0
  186. package/src/main/mls/types.d.ts +33 -0
  187. package/src/main/mls/types.js +21 -0
  188. package/src/main/notification/NotificationBackendRepository.d.ts +11 -0
  189. package/src/main/notification/NotificationBackendRepository.js +34 -0
  190. package/src/main/notification/NotificationDatabaseRepository.d.ts +42 -0
  191. package/src/main/notification/NotificationDatabaseRepository.js +97 -0
  192. package/src/main/notification/NotificationService.d.ts +129 -0
  193. package/src/main/notification/NotificationService.js +501 -0
  194. package/src/main/notification/index.d.ts +1 -0
  195. package/src/main/notification/index.js +36 -0
  196. package/src/main/notification/types.d.ts +16 -0
  197. package/src/main/notification/types.js +21 -0
  198. package/src/main/self/SelfService.d.ts +13 -0
  199. package/src/main/self/SelfService.js +55 -0
  200. package/src/main/self/index.d.ts +1 -0
  201. package/src/main/self/index.js +36 -0
  202. package/src/main/team/TeamService.d.ts +15 -0
  203. package/src/main/team/TeamService.js +55 -0
  204. package/src/main/team/index.d.ts +1 -0
  205. package/src/main/team/index.js +36 -0
  206. package/src/main/test/CryptographyHelper.d.ts +4 -0
  207. package/src/main/test/CryptographyHelper.js +69 -0
  208. package/src/main/test/PayloadHelper.d.ts +3 -0
  209. package/src/main/test/PayloadHelper.js +66 -0
  210. package/src/main/user/UserMapper.d.ts +5 -0
  211. package/src/main/user/UserMapper.js +88 -0
  212. package/src/main/user/UserService.d.ts +25 -0
  213. package/src/main/user/UserService.js +81 -0
  214. package/src/main/user/index.d.ts +1 -0
  215. package/src/main/user/index.js +36 -0
  216. package/src/main/util/LowPrecisionTaskScheduler/LowPrecisionTaskScheduler.d.ts +21 -0
  217. package/src/main/util/LowPrecisionTaskScheduler/LowPrecisionTaskScheduler.js +62 -0
  218. package/src/main/util/TaskScheduler/TaskScheduler.d.ts +10 -0
  219. package/src/main/util/TaskScheduler/TaskScheduler.js +70 -0
  220. package/src/main/util/TypePredicateUtil.d.ts +7 -0
  221. package/src/main/util/TypePredicateUtil.js +55 -0
  222. package/src/main/util/encryptedStore.d.ts +45 -0
  223. package/src/main/util/encryptedStore.js +116 -0
  224. package/src/main/util/fullyQualifiedClientIdUtils.d.ts +13 -0
  225. package/src/main/util/fullyQualifiedClientIdUtils.js +42 -0
  226. package/src/main/util/index.d.ts +1 -0
  227. package/src/main/util/index.js +36 -0
@@ -0,0 +1,463 @@
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 __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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
32
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
33
+ }) : function(o, v) {
34
+ o["default"] = v;
35
+ });
36
+ var __importStar = (this && this.__importStar) || function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
43
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
44
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
45
+ var m = o[Symbol.asyncIterator], i;
46
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
47
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
48
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
49
+ };
50
+ var __importDefault = (this && this.__importDefault) || function (mod) {
51
+ return (mod && mod.__esModule) ? mod : { "default": mod };
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.Account = void 0;
55
+ const http_status_codes_1 = require("http-status-codes");
56
+ const api_client_1 = require("@wireapp/api-client");
57
+ const auth_1 = require("@wireapp/api-client/src/auth/");
58
+ const client_1 = require("@wireapp/api-client/src/client/");
59
+ const tcp_1 = require("@wireapp/api-client/src/tcp/");
60
+ const cryptobox = __importStar(require("@wireapp/cryptobox"));
61
+ const store_engine_1 = require("@wireapp/store-engine");
62
+ const events_1 = require("events");
63
+ const logdown_1 = __importDefault(require("logdown"));
64
+ const auth_2 = require("./auth/");
65
+ const broadcast_1 = require("./broadcast/");
66
+ const client_2 = require("./client/");
67
+ const connection_1 = require("./connection/");
68
+ const conversation_1 = require("./conversation/");
69
+ const cryptography_1 = require("./cryptography/");
70
+ const giphy_1 = require("./giphy/");
71
+ const notification_1 = require("./notification/");
72
+ const self_1 = require("./self/");
73
+ const team_1 = require("./team/");
74
+ const user_1 = require("./user/");
75
+ const account_1 = require("./account/");
76
+ const linkPreview_1 = require("./linkPreview");
77
+ const encryptedStore_1 = require("./util/encryptedStore");
78
+ const bazinga64_1 = require("bazinga64");
79
+ const mls_1 = require("./mls");
80
+ const messageSender_1 = require("./conversation/message/messageSender");
81
+ var TOPIC;
82
+ (function (TOPIC) {
83
+ TOPIC["ERROR"] = "Account.TOPIC.ERROR";
84
+ })(TOPIC || (TOPIC = {}));
85
+ const coreDefaultClient = {
86
+ classification: client_1.ClientClassification.DESKTOP,
87
+ cookieLabel: 'default',
88
+ model: '@wireapp/core',
89
+ };
90
+ class Account extends events_1.EventEmitter {
91
+ /**
92
+ * @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
93
+ * @param accountOptions
94
+ */
95
+ constructor(apiClient = new api_client_1.APIClient(), { createStore = () => undefined, nbPrekeys = 2, mlsConfig } = {}) {
96
+ super();
97
+ this.apiClient = apiClient;
98
+ this.backendFeatures = this.apiClient.backendFeatures;
99
+ this.mlsConfig = mlsConfig;
100
+ this.nbPrekeys = nbPrekeys;
101
+ this.createStore = createStore;
102
+ apiClient.on(api_client_1.APIClient.TOPIC.COOKIE_REFRESH, async (cookie) => {
103
+ if (cookie && this.storeEngine) {
104
+ try {
105
+ await this.persistCookie(this.storeEngine, cookie);
106
+ }
107
+ catch (error) {
108
+ this.logger.error(`Failed to save cookie: ${error.message}`, error);
109
+ }
110
+ }
111
+ });
112
+ this.logger = (0, logdown_1.default)('@wireapp/core/Account', {
113
+ logger: console,
114
+ markdown: false,
115
+ });
116
+ }
117
+ persistCookie(storeEngine, cookie) {
118
+ const entity = { expiration: cookie.expiration, zuid: cookie.zuid };
119
+ return storeEngine.updateOrCreate(auth_1.AUTH_TABLE_NAME, auth_1.AUTH_COOKIE_KEY, entity);
120
+ }
121
+ get clientId() {
122
+ return this.apiClient.validatedClientId;
123
+ }
124
+ get userId() {
125
+ return this.apiClient.validatedUserId;
126
+ }
127
+ /**
128
+ * Will register a new user to the backend
129
+ *
130
+ * @param registration The user's data
131
+ * @param clientType Type of client to create (temporary or permanent)
132
+ */
133
+ async register(registration, clientType) {
134
+ const context = await this.apiClient.register(registration, clientType);
135
+ await this.initServices(context);
136
+ return context;
137
+ }
138
+ /**
139
+ * Will init the core with an aleady existing client (both on backend and local)
140
+ * Will fail if local client cannot be found
141
+ *
142
+ * @param clientType The type of client the user is using (temporary or permanent)
143
+ * @param cookie The cookie to identify the user against backend (will use the browser's one if not given)
144
+ */
145
+ async init(clientType, cookie, initClient = true) {
146
+ var _a, _b, _c;
147
+ const context = await this.apiClient.init(clientType, cookie);
148
+ await this.initServices(context);
149
+ // Assumption: client gets only initialized once
150
+ if (initClient) {
151
+ await this.initClient({ clientType });
152
+ if (this.mlsConfig) {
153
+ // initialize schedulers for pending mls proposals once client is initialized
154
+ await ((_a = this.service) === null || _a === void 0 ? void 0 : _a.notification.checkExistingPendingProposals());
155
+ // initialize schedulers for renewing key materials
156
+ await ((_b = this.service) === null || _b === void 0 ? void 0 : _b.notification.checkForKeyMaterialsUpdate());
157
+ // initialize scheduler for syncing key packages with backend
158
+ await ((_c = this.service) === null || _c === void 0 ? void 0 : _c.notification.checkForKeyPackagesBackendSync());
159
+ }
160
+ }
161
+ return context;
162
+ }
163
+ /**
164
+ * Will log the user in with the given credential.
165
+ * Will also create the local client and store it in DB
166
+ *
167
+ * @param loginData The credentials of the user
168
+ * @param initClient Should the call also create the local client
169
+ * @param clientInfo Info about the client to create (name, type...)
170
+ */
171
+ async login(loginData, initClient = true, clientInfo = coreDefaultClient) {
172
+ this.resetContext();
173
+ auth_2.LoginSanitizer.removeNonPrintableCharacters(loginData);
174
+ const context = await this.apiClient.login(loginData);
175
+ await this.initServices(context);
176
+ if (initClient) {
177
+ await this.initClient(loginData, clientInfo);
178
+ }
179
+ return context;
180
+ }
181
+ /**
182
+ * Will try to get the load the local client from local DB.
183
+ * If clientInfo are provided, will also create the client on backend and DB
184
+ * If clientInfo are not provideo, the method will fail if local client cannot be found
185
+ *
186
+ * @param loginData User's credentials
187
+ * @param clientInfo Will allow creating the client if the local client cannot be found (else will fail if local client is not found)
188
+ * @param entropyData Additional entropy data
189
+ * @returns The local existing client or newly created client
190
+ */
191
+ async initClient(loginData, clientInfo, entropyData) {
192
+ var _a, _b;
193
+ if (!this.service) {
194
+ throw new Error('Services are not set.');
195
+ }
196
+ try {
197
+ const localClient = await this.loadAndValidateLocalClient(entropyData);
198
+ return { isNewClient: false, localClient };
199
+ }
200
+ catch (error) {
201
+ if (!clientInfo) {
202
+ // If no client info provided, the client should not be created
203
+ throw error;
204
+ }
205
+ // There was no client so we need to "create" and "register" a client
206
+ const notFoundInDatabase = error instanceof cryptobox.error.CryptoboxError ||
207
+ error.constructor.name === 'CryptoboxError' ||
208
+ error instanceof store_engine_1.error.RecordNotFoundError ||
209
+ error.constructor.name === store_engine_1.error.RecordNotFoundError.name;
210
+ const notFoundOnBackend = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === http_status_codes_1.StatusCodes.NOT_FOUND;
211
+ if (notFoundInDatabase) {
212
+ this.logger.log(`Could not find valid client in database "${(_b = this.storeEngine) === null || _b === void 0 ? void 0 : _b.storeName}".`);
213
+ return this.registerClient(loginData, clientInfo, entropyData);
214
+ }
215
+ if (notFoundOnBackend) {
216
+ this.logger.log('Could not find valid client on backend');
217
+ const client = await this.service.client.getLocalClient();
218
+ const shouldDeleteWholeDatabase = client.type === client_1.ClientType.TEMPORARY;
219
+ if (shouldDeleteWholeDatabase) {
220
+ this.logger.log('Last client was temporary - Deleting database');
221
+ if (this.storeEngine) {
222
+ await this.storeEngine.clearTables();
223
+ }
224
+ const context = await this.apiClient.init(loginData.clientType);
225
+ await this.initEngine(context);
226
+ return this.registerClient(loginData, clientInfo, entropyData);
227
+ }
228
+ this.logger.log('Last client was permanent - Deleting cryptography stores');
229
+ await this.service.cryptography.deleteCryptographyStores();
230
+ return this.registerClient(loginData, clientInfo, entropyData);
231
+ }
232
+ throw error;
233
+ }
234
+ }
235
+ /**
236
+ * In order to be able to send MLS messages, the core needs a few information from the consumer.
237
+ * Namely:
238
+ * - is the current user allowed to administrate a specific conversation
239
+ * - what is the groupId of a conversation
240
+ * @param mlsCallbacks
241
+ */
242
+ configureMLSCallbacks(mlsCallbacks) {
243
+ var _a;
244
+ (_a = this.service) === null || _a === void 0 ? void 0 : _a.mls.configureMLSCallbacks(mlsCallbacks);
245
+ }
246
+ async initServices(context) {
247
+ this.storeEngine = await this.initEngine(context);
248
+ const accountService = new account_1.AccountService(this.apiClient);
249
+ const assetService = new conversation_1.AssetService(this.apiClient);
250
+ const cryptographyService = new cryptography_1.CryptographyService(this.apiClient, this.storeEngine, {
251
+ // We want to encrypt with fully qualified session ids, only if the backend is federated with other backends
252
+ useQualifiedIds: this.backendFeatures.isFederated,
253
+ nbPrekeys: this.nbPrekeys,
254
+ });
255
+ const clientService = new client_2.ClientService(this.apiClient, this.storeEngine, cryptographyService);
256
+ const mlsService = new mls_1.MLSService(this.mlsConfig, this.apiClient, () => this.coreCryptoClient);
257
+ const connectionService = new connection_1.ConnectionService(this.apiClient);
258
+ const giphyService = new giphy_1.GiphyService(this.apiClient);
259
+ const linkPreviewService = new linkPreview_1.LinkPreviewService(assetService);
260
+ const notificationService = new notification_1.NotificationService(this.apiClient, cryptographyService, mlsService, this.storeEngine);
261
+ const conversationService = new conversation_1.ConversationService(this.apiClient, cryptographyService, {
262
+ // We can use qualified ids to send messages as long as the backend supports federated endpoints
263
+ useQualifiedIds: this.backendFeatures.federationEndpoints,
264
+ }, notificationService, mlsService);
265
+ const selfService = new self_1.SelfService(this.apiClient);
266
+ const teamService = new team_1.TeamService(this.apiClient);
267
+ const broadcastService = new broadcast_1.BroadcastService(this.apiClient, cryptographyService);
268
+ const userService = new user_1.UserService(this.apiClient, broadcastService, conversationService, connectionService);
269
+ this.service = {
270
+ mls: mlsService,
271
+ account: accountService,
272
+ asset: assetService,
273
+ broadcast: broadcastService,
274
+ client: clientService,
275
+ connection: connectionService,
276
+ conversation: conversationService,
277
+ cryptography: cryptographyService,
278
+ giphy: giphyService,
279
+ linkPreview: linkPreviewService,
280
+ notification: notificationService,
281
+ self: selfService,
282
+ team: teamService,
283
+ user: userService,
284
+ };
285
+ }
286
+ async loadAndValidateLocalClient(entropyData) {
287
+ await this.service.cryptography.initCryptobox();
288
+ const loadedClient = await this.service.client.getLocalClient();
289
+ await this.apiClient.api.client.getClient(loadedClient.id);
290
+ this.apiClient.context.clientId = loadedClient.id;
291
+ if (this.mlsConfig) {
292
+ this.coreCryptoClient = await this.createMLSClient(loadedClient, this.apiClient.context, this.mlsConfig, entropyData);
293
+ }
294
+ return loadedClient;
295
+ }
296
+ async createMLSClient(client, context, mlsConfig, entropyData) {
297
+ if (!this.service) {
298
+ throw new Error('Services are not set.');
299
+ }
300
+ const coreCryptoKeyId = 'corecrypto-key';
301
+ const { CoreCrypto } = await Promise.resolve().then(() => __importStar(require('@wireapp/core-crypto')));
302
+ const dbName = this.generateSecretsDbName(context);
303
+ const secretStore = mlsConfig.secretsCrypto
304
+ ? await (0, encryptedStore_1.createCustomEncryptedStore)(dbName, mlsConfig.secretsCrypto)
305
+ : await (0, encryptedStore_1.createEncryptedStore)(dbName);
306
+ let key = await secretStore.getsecretValue(coreCryptoKeyId);
307
+ let isNewMLSDevice = false;
308
+ if (!key) {
309
+ key = window.crypto.getRandomValues(new Uint8Array(16));
310
+ await secretStore.saveSecretValue(coreCryptoKeyId, key);
311
+ // Keeping track that this device is a new MLS device (but can be an old proteus device)
312
+ isNewMLSDevice = true;
313
+ }
314
+ const { userId, domain } = this.apiClient.context;
315
+ const mlsClient = await CoreCrypto.init({
316
+ databaseName: `corecrypto-${this.generateDbName(context)}`,
317
+ key: bazinga64_1.Encoder.toBase64(key).asString,
318
+ clientId: `${userId}:${client.id}@${domain}`,
319
+ wasmFilePath: mlsConfig.coreCrypoWasmFilePath,
320
+ entropySeed: entropyData,
321
+ });
322
+ if (isNewMLSDevice) {
323
+ // If the device is new, we need to upload keypackages and public key to the backend
324
+ await this.service.mls.uploadMLSPublicKeys(await mlsClient.clientPublicKey(), client.id);
325
+ await this.service.mls.uploadMLSKeyPackages(await mlsClient.clientKeypackages(this.nbPrekeys), client.id);
326
+ }
327
+ return mlsClient;
328
+ }
329
+ async registerClient(loginData, clientInfo = coreDefaultClient, entropyData) {
330
+ if (!this.service) {
331
+ throw new Error('Services are not set.');
332
+ }
333
+ this.logger.info(`Creating new client {mls: ${!!this.mlsConfig}}`);
334
+ const registeredClient = await this.service.client.register(loginData, clientInfo, entropyData);
335
+ if (this.mlsConfig) {
336
+ this.coreCryptoClient = await this.createMLSClient(registeredClient, this.apiClient.context, this.mlsConfig, entropyData);
337
+ }
338
+ this.apiClient.context.clientId = registeredClient.id;
339
+ this.logger.info('Client is created');
340
+ await this.service.notification.initializeNotificationStream();
341
+ await this.service.client.synchronizeClients();
342
+ await this.service.cryptography.initCryptobox();
343
+ return { isNewClient: true, localClient: registeredClient };
344
+ }
345
+ resetContext() {
346
+ delete this.apiClient.context;
347
+ delete this.service;
348
+ }
349
+ /**
350
+ * Will logout the current user
351
+ * @param clearData if set to `true` will completely wipe any database that was created by the Account
352
+ */
353
+ async logout(clearData = false) {
354
+ if (clearData && this.coreCryptoClient) {
355
+ await this.coreCryptoClient.wipe();
356
+ await (0, encryptedStore_1.deleteEncryptedStore)(this.generateSecretsDbName(this.apiClient.context));
357
+ }
358
+ await this.apiClient.logout();
359
+ this.resetContext();
360
+ }
361
+ /**
362
+ * Will download and handle the notification stream since last stored notification id.
363
+ * Once the notification stream has been handled from backend, will then connect to the websocket and start listening to incoming events
364
+ *
365
+ * @param callbacks callbacks that will be called to handle different events
366
+ * @returns close a function that will disconnect from the websocket
367
+ */
368
+ async listen({ onEvent = () => { }, onConnected = () => { }, onConnectionStateChanged = () => { }, onNotificationStreamProgress = () => { }, onMissedNotifications = () => { }, dryRun = false, } = {}) {
369
+ if (!this.apiClient.context) {
370
+ throw new Error('Context is not set - please login first');
371
+ }
372
+ const handleEvent = async (payload, source) => {
373
+ const { mappedEvent } = payload;
374
+ switch (mappedEvent === null || mappedEvent === void 0 ? void 0 : mappedEvent.type) {
375
+ case conversation_1.PayloadBundleType.TIMER_UPDATE: {
376
+ const { data: { message_timer }, conversation, } = payload.event;
377
+ const expireAfterMillis = Number(message_timer);
378
+ this.service.conversation.messageTimer.setConversationLevelTimer(conversation, expireAfterMillis);
379
+ break;
380
+ }
381
+ }
382
+ onEvent(payload, source);
383
+ if (mappedEvent) {
384
+ this.emit(mappedEvent.type, payload.mappedEvent);
385
+ }
386
+ };
387
+ const handleNotification = async (notification, source) => {
388
+ var e_1, _a;
389
+ try {
390
+ const messages = this.service.notification.handleNotification(notification, source, dryRun);
391
+ try {
392
+ for (var messages_1 = __asyncValues(messages), messages_1_1; messages_1_1 = await messages_1.next(), !messages_1_1.done;) {
393
+ const message = messages_1_1.value;
394
+ await handleEvent(message, source);
395
+ }
396
+ }
397
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
398
+ finally {
399
+ try {
400
+ if (messages_1_1 && !messages_1_1.done && (_a = messages_1.return)) await _a.call(messages_1);
401
+ }
402
+ finally { if (e_1) throw e_1.error; }
403
+ }
404
+ }
405
+ catch (error) {
406
+ this.logger.error(`Failed to handle notification ID "${notification.id}": ${error.message}`, error);
407
+ }
408
+ };
409
+ this.apiClient.transport.ws.removeAllListeners(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE);
410
+ this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE, notification => handleNotification(notification, conversation_1.PayloadBundleSource.WEBSOCKET));
411
+ this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_STATE_CHANGE, onConnectionStateChanged);
412
+ const onBeforeConnect = async (abortHandler) => {
413
+ // Lock websocket in order to buffer any message that arrives while we handle the notification stream
414
+ this.apiClient.transport.ws.lock();
415
+ await this.service.notification.handleNotificationStream(async (notification, source, progress) => {
416
+ await handleNotification(notification, source);
417
+ onNotificationStreamProgress(progress);
418
+ }, onMissedNotifications, abortHandler);
419
+ // We can now unlock the websocket and let the new messages being handled and decrypted
420
+ this.apiClient.transport.ws.unlock();
421
+ // We need to wait for the notification stream to be fully handled before releasing the message sending queue.
422
+ // This is due to the nature of how message are encrypted, any change in mls epoch needs to happen before we start encrypting any kind of messages
423
+ (0, messageSender_1.resumeMessageSending)();
424
+ onConnected();
425
+ };
426
+ await this.apiClient.connect(onBeforeConnect);
427
+ return () => {
428
+ this.apiClient.transport.ws.removeAllListeners();
429
+ this.apiClient.disconnect();
430
+ };
431
+ }
432
+ generateDbName(context) {
433
+ const clientType = context.clientType === client_1.ClientType.NONE ? '' : `@${context.clientType}`;
434
+ return `wire@${this.apiClient.config.urls.name}@${context.userId}${clientType}`;
435
+ }
436
+ generateSecretsDbName(context) {
437
+ return `secrets-${this.generateDbName(context)}`;
438
+ }
439
+ async initEngine(context) {
440
+ const dbName = this.generateDbName(context);
441
+ this.logger.log(`Initialising store with name "${dbName}"...`);
442
+ const openDb = async () => {
443
+ const initializedDb = await this.createStore(dbName, context);
444
+ if (initializedDb) {
445
+ this.logger.log(`Initialized store with existing engine "${dbName}".`);
446
+ return initializedDb;
447
+ }
448
+ this.logger.log(`Initialized store with new memory engine "${dbName}".`);
449
+ const memoryEngine = new store_engine_1.MemoryEngine();
450
+ await memoryEngine.init(dbName);
451
+ return memoryEngine;
452
+ };
453
+ const storeEngine = await openDb();
454
+ const cookie = auth_1.CookieStore.getCookie();
455
+ if (cookie) {
456
+ await this.persistCookie(storeEngine, cookie);
457
+ }
458
+ return storeEngine;
459
+ }
460
+ }
461
+ exports.Account = Account;
462
+ Account.TOPIC = TOPIC;
463
+ //# sourceMappingURL=Account.js.map
@@ -0,0 +1,9 @@
1
+ import { Notification } from '@wireapp/api-client/src/notification';
2
+ export declare enum CoreError {
3
+ NOTIFICATION_ERROR = "CoreError.NOTIFICATION_ERROR"
4
+ }
5
+ export interface NotificationError {
6
+ error: Error;
7
+ notification: Notification;
8
+ type: CoreError.NOTIFICATION_ERROR;
9
+ }
@@ -0,0 +1,26 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.CoreError = void 0;
22
+ var CoreError;
23
+ (function (CoreError) {
24
+ CoreError["NOTIFICATION_ERROR"] = "CoreError.NOTIFICATION_ERROR";
25
+ })(CoreError = exports.CoreError || (exports.CoreError = {}));
26
+ //# sourceMappingURL=CoreError.js.map
@@ -0,0 +1,7 @@
1
+ import { APIClient } from '@wireapp/api-client';
2
+ import { CallConfigData } from '@wireapp/api-client/src/account/CallConfigData';
3
+ export declare class AccountService {
4
+ private readonly apiClient;
5
+ constructor(apiClient: APIClient);
6
+ getCallConfig(): Promise<CallConfigData>;
7
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /*
3
+ * Wire
4
+ * Copyright (C) 2020 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.AccountService = void 0;
22
+ const commons_1 = require("@wireapp/commons");
23
+ class AccountService {
24
+ constructor(apiClient) {
25
+ this.apiClient = apiClient;
26
+ }
27
+ getCallConfig() {
28
+ const iceCandidateLimit = commons_1.Runtime.isFirefox() ? 3 : undefined;
29
+ return this.apiClient.api.account.getCallConfig(iceCandidateLimit);
30
+ }
31
+ }
32
+ exports.AccountService = AccountService;
33
+ //# sourceMappingURL=AccountService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountService.js","sourceRoot":"","sources":["AccountService.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAGH,8CAAyC;AAGzC,MAAa,cAAc;IACzB,YAA6B,SAAoB;QAApB,cAAS,GAAT,SAAS,CAAW;IAAG,CAAC;IAErD,aAAa;QACX,MAAM,iBAAiB,GAAG,iBAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9D,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC;IACrE,CAAC;CACF;AAPD,wCAOC"}
@@ -0,0 +1 @@
1
+ export * from './AccountService';
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /*
3
+ * Wire
4
+ * Copyright (C) 2020 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("./AccountService"), exports);
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;;;;;;;AAEH,mDAAiC"}
@@ -0,0 +1,5 @@
1
+ import { LoginData } from '@wireapp/api-client/src/auth/';
2
+ export declare class LoginSanitizer {
3
+ constructor();
4
+ static removeNonPrintableCharacters(loginData: LoginData): void;
5
+ }
@@ -0,0 +1,41 @@
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.LoginSanitizer = void 0;
22
+ class LoginSanitizer {
23
+ constructor() { }
24
+ static removeNonPrintableCharacters(loginData) {
25
+ const nonPrintableCharacters = /\s/gm;
26
+ if (loginData.email) {
27
+ loginData.email = loginData.email.replace(nonPrintableCharacters, '');
28
+ }
29
+ if (loginData.handle) {
30
+ loginData.handle = loginData.handle.replace(nonPrintableCharacters, '');
31
+ }
32
+ if (loginData.password) {
33
+ loginData.password = loginData.password.toString();
34
+ }
35
+ if (loginData.phone) {
36
+ loginData.phone = loginData.phone.toString().replace(nonPrintableCharacters, '');
37
+ }
38
+ }
39
+ }
40
+ exports.LoginSanitizer = LoginSanitizer;
41
+ //# sourceMappingURL=LoginSanitizer.js.map
@@ -0,0 +1 @@
1
+ export * from './LoginSanitizer';