@wireapp/core 20.7.2 → 22.0.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/CHANGELOG.md CHANGED
@@ -3,6 +3,61 @@
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.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)
7
+
8
+
9
+ ### Features
10
+
11
+ * **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))
12
+
13
+
14
+ ### BREAKING CHANGES
15
+
16
+ * **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
17
+
18
+
19
+
20
+
21
+
22
+ ## [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)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **core:** Use Uint8Array in place of Buffer ([#4214](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4214)) ([d9c8692](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/d9c869291e60325411070b87f71d8803561bde49))
28
+
29
+
30
+
31
+
32
+
33
+ ## [21.0.1](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@21.0.0...@wireapp/core@21.0.1) (2022-01-18)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * **core:** Improve types for setAvailability ([26da881](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/26da88113adf9eaba987ad22265df758231e5dc1))
39
+ * **core:** Improve types for setAvailability ([dcbada4](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/dcbada4e353296e17307baeac8d4b775158a1436))
40
+
41
+
42
+
43
+
44
+
45
+ # [21.0.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@20.7.2...@wireapp/core@21.0.0) (2022-01-18)
46
+
47
+
48
+ ### Features
49
+
50
+ * **core:** Send availability status only to directly connected members ([#4213](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4213)) ([73bad2f](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/73bad2fb8f75a473b686fa9273b1c03774afd5c7))
51
+
52
+
53
+ ### BREAKING CHANGES
54
+
55
+ * **core:** the setAvailability of the user service will by default now only send to directly connected users. To send to absolutely all the users in the team call `setAvailability` with the `{sendAll: true}` option
56
+
57
+
58
+
59
+
60
+
6
61
  ## [20.7.2](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@20.7.1...@wireapp/core@20.7.2) (2022-01-12)
7
62
 
8
63
  **Note:** Version bump only for package @wireapp/core
package/package.json CHANGED
@@ -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": "20.7.2",
73
- "gitHead": "57da347406b301aa1d3ea80ab6b53c9740a645ff"
72
+ "version": "22.0.0",
73
+ "gitHead": "6f85fe1a8bc2dfe0ef0db6dfe094916aa00dc1f7"
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);
@@ -8,6 +8,13 @@ export declare class BroadcastService {
8
8
  private readonly cryptographyService;
9
9
  private readonly messageService;
10
10
  constructor(apiClient: APIClient, cryptographyService: CryptographyService);
11
- getPreKeyBundlesFromTeam(teamId: string, skipOwnClients?: boolean): Promise<UserPreKeyBundleMap>;
11
+ /**
12
+ * Will create a key bundle for all the users of the team
13
+ *
14
+ * @param teamId
15
+ * @param skipOwnClients=false
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
+ */
18
+ getPreKeyBundlesFromTeam(teamId: string, skipOwnClients?: boolean, onlyDirectConnections?: boolean): Promise<UserPreKeyBundleMap>;
12
19
  broadcastGenericMessage(genericMessage: GenericMessage, recipients: UserPreKeyBundleMap | UserClients, sendAsProtobuf?: boolean): Promise<ClientMismatch>;
13
20
  }
@@ -27,9 +27,20 @@ class BroadcastService {
27
27
  this.cryptographyService = cryptographyService;
28
28
  this.messageService = new MessageService_1.MessageService(this.apiClient, this.cryptographyService);
29
29
  }
30
- async getPreKeyBundlesFromTeam(teamId, skipOwnClients = false) {
31
- const { members: teamMembers } = await this.apiClient.teams.member.api.getAllMembers(teamId);
32
- let members = teamMembers.map(member => ({ id: member.user }));
30
+ /**
31
+ * Will create a key bundle for all the users of the team
32
+ *
33
+ * @param teamId
34
+ * @param skipOwnClients=false
35
+ * @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
36
+ */
37
+ async getPreKeyBundlesFromTeam(teamId, skipOwnClients = false, onlyDirectConnections = false) {
38
+ const teamMembers = onlyDirectConnections
39
+ ? (await this.apiClient.conversation.api.getConversations()).conversations
40
+ .map(({ members }) => members.others.map(user => user.id).concat(members.self.id))
41
+ .flat()
42
+ : (await this.apiClient.teams.member.api.getAllMembers(teamId)).members.map(({ user }) => user);
43
+ let members = Array.from(new Set(teamMembers)).map(member => ({ id: member }));
33
44
  if (skipOwnClients) {
34
45
  const selfUser = await this.apiClient.self.api.getSelf();
35
46
  members = members.filter(member => member.id !== selfUser.id);
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { APIClient } from '@wireapp/api-client';
3
2
  import { MessageSendingStatus, Conversation, DefaultConversationRoleName, MutedStatus, QualifiedUserClients, UserClients, ClientMismatch } from '@wireapp/api-client/src/conversation';
4
3
  import type { ConversationMemberLeaveEvent } from '@wireapp/api-client/src/event';
@@ -61,10 +60,13 @@ export interface MessageSendingCallbacks {
61
60
  }
62
61
  export declare class ConversationService {
63
62
  private readonly apiClient;
63
+ private readonly config;
64
64
  readonly messageTimer: MessageTimer;
65
65
  private readonly messageService;
66
66
  private selfConversationId?;
67
- constructor(apiClient: APIClient, cryptographyService: CryptographyService);
67
+ constructor(apiClient: APIClient, cryptographyService: CryptographyService, config: {
68
+ useQualifiedIds?: boolean;
69
+ });
68
70
  private createEphemeral;
69
71
  private getConversationQualifiedMembers;
70
72
  /**
@@ -150,7 +152,7 @@ export declare class ConversationService {
150
152
  createConversation(name: string, otherUserIds?: string | string[]): Promise<Conversation>;
151
153
  getConversations(conversationId: string): Promise<Conversation>;
152
154
  getConversations(conversationIds?: string[]): Promise<Conversation[]>;
153
- getAsset({ assetId, assetToken, otrKey, sha256 }: RemoteData): Promise<Buffer>;
155
+ getAsset({ assetId, assetToken, otrKey, sha256 }: RemoteData): Promise<Uint8Array>;
154
156
  getUnencryptedAsset(assetId: string, assetToken?: string): Promise<ArrayBuffer>;
155
157
  addUser<T extends string | string[] | QualifiedId | QualifiedId[]>(conversationId: string, userIds: T): Promise<T>;
156
158
  removeUser(conversationId: string, userId: string): Promise<string>;
@@ -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
  }
@@ -633,9 +635,9 @@ class ConversationService {
633
635
  const request = this.apiClient.asset.api.getAssetV3(assetId, assetToken);
634
636
  const encryptedBuffer = (await request.response).buffer;
635
637
  return (0, AssetCryptography_1.decryptAsset)({
636
- cipherText: Buffer.from(encryptedBuffer),
637
- keyBytes: Buffer.from(otrKey),
638
- sha256: Buffer.from(sha256),
638
+ cipherText: new Uint8Array(encryptedBuffer),
639
+ keyBytes: otrKey,
640
+ sha256: sha256,
639
641
  });
640
642
  }
641
643
  async getUnencryptedAsset(assetId, assetToken) {
@@ -1,9 +1,8 @@
1
- /// <reference types="node" />
2
1
  export interface EncryptedAsset {
3
- cipherText: Buffer;
4
- keyBytes: Buffer;
2
+ cipherText: Uint8Array;
3
+ keyBytes: Uint8Array;
5
4
  /** The SHA-256 sum of `cipherText` */
6
- sha256: Buffer;
5
+ sha256: Uint8Array;
7
6
  }
8
7
  export interface EncryptedAssetUploaded extends EncryptedAsset {
9
8
  key: string;
@@ -23,22 +23,22 @@ const cryptoLib = window.crypto;
23
23
  exports.crypto = {
24
24
  async digest(cipherText) {
25
25
  const checksum = await cryptoLib.subtle.digest('SHA-256', cipherText);
26
- return Buffer.from(checksum);
26
+ return new Uint8Array(checksum);
27
27
  },
28
28
  async decrypt(cipherText, keyBytes) {
29
29
  const key = await cryptoLib.subtle.importKey('raw', keyBytes, 'AES-CBC', false, ['decrypt']);
30
30
  const initializationVector = cipherText.slice(0, 16);
31
31
  const assetCipherText = cipherText.slice(16);
32
32
  const decipher = await cryptoLib.subtle.decrypt({ iv: initializationVector, name: 'AES-CBC' }, key, assetCipherText);
33
- return Buffer.from(decipher);
33
+ return new Uint8Array(decipher);
34
34
  },
35
35
  getRandomValues(size) {
36
- return Buffer.from(cryptoLib.getRandomValues(new Uint8Array(size)));
36
+ return cryptoLib.getRandomValues(new Uint8Array(size));
37
37
  },
38
38
  async encrypt(plainText, keyBytes, initializationVector) {
39
39
  const key = await cryptoLib.subtle.importKey('raw', keyBytes, 'AES-CBC', true, ['encrypt']);
40
40
  return {
41
- key: Buffer.from(await cryptoLib.subtle.exportKey('raw', key)),
41
+ key: new Uint8Array(await cryptoLib.subtle.exportKey('raw', key)),
42
42
  cipher: await cryptoLib.subtle.encrypt({ iv: initializationVector, name: 'AES-CBC' }, key, plainText),
43
43
  };
44
44
  },
@@ -1,9 +1,8 @@
1
- /// <reference types="node" />
2
1
  import { CipherOptions } from '@wireapp/api-client/src/asset';
3
2
  import type { EncryptedAsset } from './EncryptedAsset';
4
3
  interface EncryptOptions extends CipherOptions {
5
- plainText: Buffer | Uint8Array;
4
+ plainText: Uint8Array;
6
5
  }
7
- export declare const decryptAsset: ({ cipherText, keyBytes, sha256: referenceSha256, }: EncryptedAsset) => Promise<Buffer>;
6
+ export declare const decryptAsset: ({ cipherText, keyBytes, sha256: referenceSha256, }: EncryptedAsset) => Promise<Uint8Array>;
8
7
  export declare const encryptAsset: ({ plainText, algorithm }: EncryptOptions) => Promise<EncryptedAsset>;
9
8
  export {};
@@ -44,7 +44,7 @@ const encryptAsset = async ({ plainText, algorithm = 'AES-256-CBC' }) => {
44
44
  ivCipherText.set(new Uint8Array(cipher), initializationVector.byteLength);
45
45
  const sha256 = await crypto_node_1.crypto.digest(ivCipherText);
46
46
  return {
47
- cipherText: Buffer.from(ivCipherText.buffer),
47
+ cipherText: ivCipherText,
48
48
  keyBytes: key,
49
49
  sha256,
50
50
  };
@@ -1,10 +1,9 @@
1
- /// <reference types="node" />
2
1
  export interface Crypto {
3
- digest(cipherText: Buffer | Uint8Array): Promise<Buffer>;
4
- decrypt(cipherText: Buffer | Uint8Array, keyBytes: Buffer): Promise<Buffer>;
5
- getRandomValues(size: number): Buffer;
6
- encrypt(plainText: Buffer | Uint8Array, keyBytes: Buffer, initializationVector: Buffer, algorithm: string): Promise<{
7
- key: Buffer;
8
- cipher: Buffer;
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;
9
8
  }>;
10
9
  }
@@ -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}`;
@@ -147,9 +146,8 @@ class CryptographyService {
147
146
  this.logger.log(`Deleted session ID "${sessionId}".`);
148
147
  }
149
148
  async decodeGenericMessage(otrMessage, source) {
150
- var _a;
151
149
  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;
150
+ const domain = this.config.useQualifiedIds ? qualified_from.domain : null;
153
151
  const sessionId = CryptographyService.constructSessionId(from, sender, domain);
154
152
  const decryptedMessage = await this.decrypt(sessionId, cipherText);
155
153
  const genericMessage = protocol_messaging_1.GenericMessage.decode(decryptedMessage);
@@ -11,5 +11,15 @@ export declare class UserService {
11
11
  constructor(apiClient: APIClient, broadcastService: BroadcastService, conversationService: ConversationService, connectionService: ConnectionService);
12
12
  getUser(userId: string | QualifiedId): Promise<User>;
13
13
  getUsers(userIds: string[] | QualifiedId[]): Promise<User[]>;
14
- setAvailability(teamId: string, type: AvailabilityType, sendAsProtobuf?: boolean): Promise<void>;
14
+ /**
15
+ * Sends a availability update to members of the same team
16
+ * @param teamId
17
+ * @param type
18
+ * @param options.sendAll=false will broadcast the message to all the members of the team (instead of just direct connections). Should be avoided in a big team
19
+ * @param options.sendAsProtobuf=false
20
+ */
21
+ setAvailability(teamId: string, type: AvailabilityType, { sendAll, sendAsProtobuf }?: {
22
+ sendAll?: boolean | undefined;
23
+ sendAsProtobuf?: boolean | undefined;
24
+ }): Promise<void>;
15
25
  }
@@ -44,9 +44,16 @@ class UserService {
44
44
  ? this.apiClient.user.api.postListUsers({ qualified_ids: userIds })
45
45
  : this.apiClient.user.api.getUsers({ ids: userIds });
46
46
  }
47
- async setAvailability(teamId, type, sendAsProtobuf) {
47
+ /**
48
+ * Sends a availability update to members of the same team
49
+ * @param teamId
50
+ * @param type
51
+ * @param options.sendAll=false will broadcast the message to all the members of the team (instead of just direct connections). Should be avoided in a big team
52
+ * @param options.sendAsProtobuf=false
53
+ */
54
+ async setAvailability(teamId, type, { sendAll = false, sendAsProtobuf = false } = {}) {
48
55
  // Get pre-key bundles for members of your own team
49
- const preKeyBundlesFromTeam = await this.broadcastService.getPreKeyBundlesFromTeam(teamId);
56
+ const preKeyBundlesFromTeam = await this.broadcastService.getPreKeyBundlesFromTeam(teamId, false, !sendAll);
50
57
  // Get pre-key bundles for all of your other 1:1 connections
51
58
  const connections = await this.connectionService.getConnections();
52
59
  const acceptedConnections = connections.filter(connection => connection.status === connection_1.ConnectionStatus.ACCEPTED);