@wireapp/core 21.0.2 → 22.1.2

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/CHANGELOG.md CHANGED
@@ -3,6 +3,52 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [22.1.2](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@22.1.1...@wireapp/core@22.1.2) (2022-02-01)
7
+
8
+ **Note:** Version bump only for package @wireapp/core
9
+
10
+
11
+
12
+
13
+
14
+ ## [22.1.1](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@22.1.0...@wireapp/core@22.1.1) (2022-02-01)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **core:** Do not try to encrypt for clients without prekeys ([#4220](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4220)) ([1adea26](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/1adea2652de6fd7833a3f1ae99b488f2d25e9817))
20
+
21
+
22
+
23
+
24
+
25
+ # [22.1.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@22.0.0...@wireapp/core@22.1.0) (2022-02-01)
26
+
27
+
28
+ ### Features
29
+
30
+ * **core:** Enable mismatch hook into broadcast messages ([#4219](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4219)) ([55d8aad](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/55d8aad4519d708af7ed67a6a591d3f6ccd7f55a))
31
+
32
+
33
+
34
+
35
+
36
+ # [22.0.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@21.0.2...@wireapp/core@22.0.0) (2022-01-31)
37
+
38
+
39
+ ### Features
40
+
41
+ * **core:** Remove the need to give a domain to use qualified Ids ([#4217](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4217)) ([8ce58ea](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/8ce58eae8dcf86f66baccab3acfca7e3ba472e3c))
42
+
43
+
44
+ ### BREAKING CHANGES
45
+
46
+ * **core:** If you were using the Account with a federationDomain, you need to replace federationDomain: 'the.domain' to useQualifiedIds: true. The domain will be found automatically by the core
47
+
48
+
49
+
50
+
51
+
6
52
  ## [21.0.2](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@21.0.1...@wireapp/core@21.0.2) (2022-01-19)
7
53
 
8
54
 
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "dependencies": {
6
6
  "@types/long": "4.0.1",
7
7
  "@types/node": "~14",
8
- "@wireapp/api-client": "16.6.0",
8
+ "@wireapp/api-client": "16.7.0",
9
9
  "@wireapp/cryptobox": "12.7.1",
10
10
  "bazinga64": "5.10.0",
11
11
  "hash.js": "1.1.7",
@@ -69,6 +69,6 @@
69
69
  "test:project": "yarn dist && yarn test",
70
70
  "test:node": "nyc jasmine --config=jasmine.json"
71
71
  },
72
- "version": "21.0.2",
73
- "gitHead": "9838da9b1a1dcb702154c73c28a15e53fc35af9f"
72
+ "version": "22.1.2",
73
+ "gitHead": "c1934516b62e0a6a8e85cb48908b4df8cfb752e8"
74
74
  }
@@ -54,10 +54,11 @@ export interface Account {
54
54
  }
55
55
  export declare type StoreEngineProvider = (storeName: string) => Promise<CRUDEngine>;
56
56
  declare type AccountConfig = {
57
- federationDomain?: string;
57
+ /** If set to true, will use fully qualified ids and federated endpoints */
58
+ useQualifiedIds?: boolean;
58
59
  };
59
60
  export declare class Account extends EventEmitter {
60
- private readonly config?;
61
+ private readonly config;
61
62
  private readonly apiClient;
62
63
  private readonly logger;
63
64
  private readonly storeEngineProvider;
@@ -81,9 +82,8 @@ export declare class Account extends EventEmitter {
81
82
  /**
82
83
  * @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
83
84
  * @param storeEngineProvider Used to store info in the database (will create a inMemory engine if undefined)
84
- * @param config.federationDomain If using a federated backend this will set the default domain for qualified ids. Do not set if using a regular backend
85
85
  */
86
- constructor(apiClient?: APIClient, storeEngineProvider?: StoreEngineProvider, config?: AccountConfig | undefined);
86
+ constructor(apiClient?: APIClient, storeEngineProvider?: StoreEngineProvider, config?: AccountConfig);
87
87
  private persistCookie;
88
88
  get clientId(): string;
89
89
  get userId(): string;
@@ -71,9 +71,8 @@ class Account extends events_1.EventEmitter {
71
71
  /**
72
72
  * @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
73
73
  * @param storeEngineProvider Used to store info in the database (will create a inMemory engine if undefined)
74
- * @param config.federationDomain If using a federated backend this will set the default domain for qualified ids. Do not set if using a regular backend
75
74
  */
76
- constructor(apiClient = new api_client_1.APIClient(), storeEngineProvider, config) {
75
+ constructor(apiClient = new api_client_1.APIClient(), storeEngineProvider, config = {}) {
77
76
  super();
78
77
  this.config = config;
79
78
  this.handlePayload = async (payload) => {
@@ -157,7 +156,7 @@ class Account extends events_1.EventEmitter {
157
156
  const connectionService = new connection_1.ConnectionService(this.apiClient);
158
157
  const giphyService = new giphy_1.GiphyService(this.apiClient);
159
158
  const linkPreviewService = new linkPreview_1.LinkPreviewService(assetService);
160
- const conversationService = new conversation_1.ConversationService(this.apiClient, cryptographyService);
159
+ const conversationService = new conversation_1.ConversationService(this.apiClient, cryptographyService, this.config);
161
160
  const notificationService = new notification_1.NotificationService(this.apiClient, cryptographyService, storeEngine);
162
161
  const selfService = new self_1.SelfService(this.apiClient);
163
162
  const teamService = new team_1.TeamService(this.apiClient);
@@ -16,5 +16,5 @@ export declare class BroadcastService {
16
16
  * @param onlyDirectConnections=false Will generate a bundle only for directly connected users (users the self user has conversation with). Allows avoiding broadcasting messages to too many people
17
17
  */
18
18
  getPreKeyBundlesFromTeam(teamId: string, skipOwnClients?: boolean, onlyDirectConnections?: boolean): Promise<UserPreKeyBundleMap>;
19
- broadcastGenericMessage(genericMessage: GenericMessage, recipients: UserPreKeyBundleMap | UserClients, sendAsProtobuf?: boolean): Promise<ClientMismatch>;
19
+ broadcastGenericMessage(genericMessage: GenericMessage, recipients: UserPreKeyBundleMap | UserClients, sendAsProtobuf?: boolean, onClientMismatch?: (mismatch: ClientMismatch) => void | boolean | Promise<boolean>): Promise<ClientMismatch>;
20
20
  }
@@ -54,11 +54,12 @@ class BroadcastService {
54
54
  return bundleMap;
55
55
  }, {});
56
56
  }
57
- async broadcastGenericMessage(genericMessage, recipients, sendAsProtobuf) {
57
+ async broadcastGenericMessage(genericMessage, recipients, sendAsProtobuf, onClientMismatch) {
58
58
  const plainTextArray = protocol_messaging_1.GenericMessage.encode(genericMessage).finish();
59
59
  return this.messageService.sendMessage(this.apiClient.validatedClientId, recipients, plainTextArray, {
60
60
  sendAsProtobuf,
61
61
  reportMissing: Object.keys(recipients),
62
+ onClientMismatch,
62
63
  });
63
64
  }
64
65
  }
@@ -60,10 +60,13 @@ export interface MessageSendingCallbacks {
60
60
  }
61
61
  export declare class ConversationService {
62
62
  private readonly apiClient;
63
+ private readonly config;
63
64
  readonly messageTimer: MessageTimer;
64
65
  private readonly messageService;
65
66
  private selfConversationId?;
66
- constructor(apiClient: APIClient, cryptographyService: CryptographyService);
67
+ constructor(apiClient: APIClient, cryptographyService: CryptographyService, config: {
68
+ useQualifiedIds?: boolean;
69
+ });
67
70
  private createEphemeral;
68
71
  private getConversationQualifiedMembers;
69
72
  /**
@@ -35,8 +35,9 @@ var MessageTargetMode;
35
35
  MessageTargetMode[MessageTargetMode["USERS_CLIENTS"] = 2] = "USERS_CLIENTS";
36
36
  })(MessageTargetMode = exports.MessageTargetMode || (exports.MessageTargetMode = {}));
37
37
  class ConversationService {
38
- constructor(apiClient, cryptographyService) {
38
+ constructor(apiClient, cryptographyService, config) {
39
39
  this.apiClient = apiClient;
40
+ this.config = config;
40
41
  this.messageTimer = new conversation_2.MessageTimer();
41
42
  this.messageService = new MessageService_1.MessageService(this.apiClient, cryptographyService);
42
43
  }
@@ -138,7 +139,8 @@ class ConversationService {
138
139
  if (!this.selfConversationId) {
139
140
  const { userId } = this.apiClient.context;
140
141
  const { qualified_id, id } = await this.apiClient.conversation.api.getConversation(userId);
141
- this.selfConversationId = qualified_id || { id, domain: '' };
142
+ const domain = this.config.useQualifiedIds ? qualified_id.domain : '';
143
+ this.selfConversationId = { id, domain };
142
144
  }
143
145
  return this.selfConversationId;
144
146
  }
@@ -13,17 +13,16 @@ export interface MetaClient extends RegisteredClient {
13
13
  primary_key: string;
14
14
  };
15
15
  }
16
- declare type CryptographyServiceOptions = {
17
- federationDomain?: string;
18
- };
19
16
  export declare class CryptographyService {
20
17
  readonly apiClient: APIClient;
21
18
  private readonly storeEngine;
22
- private readonly options?;
19
+ private readonly config;
23
20
  private readonly logger;
24
21
  cryptobox: Cryptobox;
25
22
  private readonly database;
26
- constructor(apiClient: APIClient, storeEngine: CRUDEngine, options?: CryptographyServiceOptions | undefined);
23
+ constructor(apiClient: APIClient, storeEngine: CRUDEngine, config?: {
24
+ useQualifiedIds?: boolean;
25
+ });
27
26
  static constructSessionId(userId: string, clientId: string, domain: string | null): string;
28
27
  static convertArrayRecipientsToBase64(recipients: OTRRecipients<Uint8Array>): OTRRecipients<string>;
29
28
  static convertBase64RecipientsToArray(recipients: OTRRecipients<string>): OTRRecipients<Uint8Array>;
@@ -43,4 +42,3 @@ export declare class CryptographyService {
43
42
  resetSession(sessionId: string): Promise<void>;
44
43
  decodeGenericMessage(otrMessage: ConversationOtrMessageAddEvent, source: PayloadBundleSource): Promise<PayloadBundle>;
45
44
  }
46
- export {};
@@ -32,17 +32,16 @@ const util_1 = require("../util");
32
32
  const CryptographyDatabaseRepository_1 = require("./CryptographyDatabaseRepository");
33
33
  const GenericMessageMapper_1 = require("./GenericMessageMapper");
34
34
  class CryptographyService {
35
- constructor(apiClient, storeEngine, options) {
35
+ constructor(apiClient, storeEngine, config = {}) {
36
36
  this.apiClient = apiClient;
37
37
  this.storeEngine = storeEngine;
38
- this.options = options;
38
+ this.config = config;
39
39
  this.cryptobox = new cryptobox_1.Cryptobox(this.storeEngine);
40
40
  this.database = new CryptographyDatabaseRepository_1.CryptographyDatabaseRepository(this.storeEngine);
41
41
  this.logger = (0, logdown_1.default)('@wireapp/core/cryptography/CryptographyService', {
42
42
  logger: console,
43
43
  markdown: false,
44
44
  });
45
- this.options = options;
46
45
  }
47
46
  static constructSessionId(userId, clientId, domain) {
48
47
  const baseId = `${userId}@${clientId}`;
@@ -95,12 +94,17 @@ class CryptographyService {
95
94
  };
96
95
  }
97
96
  async encrypt(plainText, users, domain) {
97
+ var _a;
98
98
  const encrypted = {};
99
99
  const missing = {};
100
100
  for (const userId in users) {
101
- const clientIds = (0, util_1.isUserClients)(users) ? users[userId] : Object.keys(users[userId]);
101
+ const clientIds = (0, util_1.isUserClients)(users)
102
+ ? users[userId]
103
+ : Object.keys(users[userId])
104
+ // We filter out clients that have `null` prekey
105
+ .filter(clientId => !!users[userId][clientId]);
102
106
  for (const clientId of clientIds) {
103
- const base64PreKey = (0, util_1.isUserClients)(users) ? undefined : users[userId][clientId].key;
107
+ const base64PreKey = (0, util_1.isUserClients)(users) ? undefined : (_a = users[userId][clientId]) === null || _a === void 0 ? void 0 : _a.key;
104
108
  const sessionId = CryptographyService.constructSessionId(userId, clientId, domain || null);
105
109
  const result = await this.encryptPayloadForSession(sessionId, plainText, base64PreKey);
106
110
  if (result) {
@@ -147,9 +151,8 @@ class CryptographyService {
147
151
  this.logger.log(`Deleted session ID "${sessionId}".`);
148
152
  }
149
153
  async decodeGenericMessage(otrMessage, source) {
150
- var _a;
151
154
  const { from, qualified_from, data: { sender, text: cipherText }, } = otrMessage;
152
- const domain = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.federationDomain) ? (qualified_from === null || qualified_from === void 0 ? void 0 : qualified_from.domain) || this.options.federationDomain : null;
155
+ const domain = this.config.useQualifiedIds ? qualified_from.domain : null;
153
156
  const sessionId = CryptographyService.constructSessionId(from, sender, domain);
154
157
  const decryptedMessage = await this.decrypt(sessionId, cipherText);
155
158
  const genericMessage = protocol_messaging_1.GenericMessage.decode(decryptedMessage);