@wireapp/core 30.0.5 → 30.3.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,39 @@
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
+ # [30.3.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@30.2.0...@wireapp/core@30.3.0) (2022-09-07)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add ability to send external proposal (FS-689) ([#4376](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4376)) ([bf8e7dd](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/bf8e7ddd7ea4660c8a5b6eea93e27ec14485de6c))
12
+
13
+
14
+
15
+
16
+
17
+ # [30.2.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@30.1.0...@wireapp/core@30.2.0) (2022-09-07)
18
+
19
+
20
+ ### Features
21
+
22
+ * Also create MLS device when logging in with old proteus device ([#4378](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4378)) ([31cea5a](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/31cea5a31ac69ffb269f33458896d091de6c171f))
23
+
24
+
25
+
26
+
27
+
28
+ # [30.1.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@30.0.5...@wireapp/core@30.1.0) (2022-09-07)
29
+
30
+
31
+ ### Features
32
+
33
+ * Ability to clear database when logging out ([#4377](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4377)) ([e5f7a9c](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/e5f7a9c4f36a018d2bd13eca8a0d751cf7f9805c))
34
+
35
+
36
+
37
+
38
+
6
39
  ## [30.0.5](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@30.0.4...@wireapp/core@30.0.5) (2022-09-02)
7
40
 
8
41
  **Note:** Version bump only for package @wireapp/core
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "@otak/core-crypto": "0.3.0-es2017",
8
8
  "@types/long": "4.0.1",
9
9
  "@types/node": "~14",
10
- "@wireapp/api-client": "20.0.4",
10
+ "@wireapp/api-client": "20.1.0",
11
11
  "@wireapp/commons": "4.3.0",
12
12
  "@wireapp/cryptobox": "12.8.0",
13
13
  "@wireapp/store-engine-dexie": "1.6.10",
@@ -77,6 +77,6 @@
77
77
  "test:node": "nyc jasmine --config=jasmine.json",
78
78
  "watch": "tsc ---watch"
79
79
  },
80
- "version": "30.0.5",
81
- "gitHead": "a6993ee7b942cf5c4fe85dbb8cf742c546765a36"
80
+ "version": "30.3.0",
81
+ "gitHead": "0a4d4b6057006da93a731115ab02c9753b155127"
82
82
  }
@@ -166,7 +166,11 @@ export declare class Account<T = any> extends EventEmitter {
166
166
  private createMLSClient;
167
167
  private registerClient;
168
168
  private resetContext;
169
- logout(): Promise<void>;
169
+ /**
170
+ * Will logout the current user
171
+ * @param clearData if set to `true` will completely wipe any database that was created by the Account
172
+ */
173
+ logout(clearData?: boolean): Promise<void>;
170
174
  /**
171
175
  * Will download and handle the notification stream since last stored notification id.
172
176
  * Once the notification stream has been handled from backend, will then connect to the websocket and start listening to incoming events
@@ -210,6 +214,7 @@ export declare class Account<T = any> extends EventEmitter {
210
214
  dryRun?: boolean;
211
215
  }): Promise<() => void>;
212
216
  private generateDbName;
217
+ private generateSecretsDbName;
213
218
  private initEngine;
214
219
  }
215
220
  export {};
@@ -269,25 +269,37 @@ class Account extends events_1.EventEmitter {
269
269
  return loadedClient;
270
270
  }
271
271
  async createMLSClient(client, context, mlsConfig, entropyData) {
272
+ if (!this.service) {
273
+ throw new Error('Services are not set.');
274
+ }
272
275
  const coreCryptoKeyId = 'corecrypto-key';
273
276
  const { CoreCrypto } = await Promise.resolve().then(() => __importStar(require('@otak/core-crypto')));
274
- const dbName = `secrets-${this.generateDbName(context)}`;
277
+ const dbName = this.generateSecretsDbName(context);
275
278
  const secretStore = mlsConfig.secretsCrypto
276
279
  ? await (0, encryptedStore_1.createCustomEncryptedStore)(dbName, mlsConfig.secretsCrypto)
277
280
  : await (0, encryptedStore_1.createEncryptedStore)(dbName);
278
281
  let key = await secretStore.getsecretValue(coreCryptoKeyId);
282
+ let isNewMLSDevice = false;
279
283
  if (!key) {
280
284
  key = window.crypto.getRandomValues(new Uint8Array(16));
281
285
  await secretStore.saveSecretValue(coreCryptoKeyId, key);
286
+ // Keeping track that this device is a new MLS device (but can be an old proteus device)
287
+ isNewMLSDevice = true;
282
288
  }
283
289
  const { userId, domain } = this.apiClient.context;
284
- return CoreCrypto.init({
290
+ const mlsClient = await CoreCrypto.init({
285
291
  databaseName: `corecrypto-${this.generateDbName(context)}`,
286
292
  key: bazinga64_1.Encoder.toBase64(key).asString,
287
293
  clientId: `${userId}:${client.id}@${domain}`,
288
294
  wasmFilePath: mlsConfig.coreCrypoWasmFilePath,
289
295
  entropySeed: entropyData,
290
296
  });
297
+ if (isNewMLSDevice) {
298
+ // If the device is new, we need to upload keypackages and public key to the backend
299
+ await this.service.client.uploadMLSPublicKeys(await mlsClient.clientPublicKey(), client.id);
300
+ await this.service.client.uploadMLSKeyPackages(await mlsClient.clientKeypackages(this.nbPrekeys), client.id);
301
+ }
302
+ return mlsClient;
291
303
  }
292
304
  async registerClient(loginData, clientInfo = coreDefaultClient, entropyData) {
293
305
  if (!this.service) {
@@ -297,8 +309,6 @@ class Account extends events_1.EventEmitter {
297
309
  const registeredClient = await this.service.client.register(loginData, clientInfo, entropyData);
298
310
  if (this.mlsConfig) {
299
311
  this.coreCryptoClient = await this.createMLSClient(registeredClient, this.apiClient.context, this.mlsConfig, entropyData);
300
- await this.service.client.uploadMLSPublicKeys(await this.coreCryptoClient.clientPublicKey(), registeredClient.id);
301
- await this.service.client.uploadMLSKeyPackages(await this.coreCryptoClient.clientKeypackages(this.nbPrekeys), registeredClient.id);
302
312
  }
303
313
  this.apiClient.context.clientId = registeredClient.id;
304
314
  this.logger.info('Client is created');
@@ -311,7 +321,15 @@ class Account extends events_1.EventEmitter {
311
321
  delete this.apiClient.context;
312
322
  delete this.service;
313
323
  }
314
- async logout() {
324
+ /**
325
+ * Will logout the current user
326
+ * @param clearData if set to `true` will completely wipe any database that was created by the Account
327
+ */
328
+ async logout(clearData = false) {
329
+ if (clearData && this.coreCryptoClient) {
330
+ await this.coreCryptoClient.wipe();
331
+ await (0, encryptedStore_1.deleteEncryptedStore)(this.generateSecretsDbName(this.apiClient.context));
332
+ }
315
333
  await this.apiClient.logout();
316
334
  this.resetContext();
317
335
  }
@@ -387,6 +405,9 @@ class Account extends events_1.EventEmitter {
387
405
  const clientType = context.clientType === client_1.ClientType.NONE ? '' : `@${context.clientType}`;
388
406
  return `wire@${this.apiClient.config.urls.name}@${context.userId}${clientType}`;
389
407
  }
408
+ generateSecretsDbName(context) {
409
+ return `secrets-${this.generateDbName(context)}`;
410
+ }
390
411
  async initEngine(context) {
391
412
  const dbName = this.generateDbName(context);
392
413
  this.logger.log(`Initialising store with name "${dbName}"...`);
@@ -1,4 +1,4 @@
1
- import type { CoreCrypto } from '@otak/core-crypto';
1
+ import { CoreCrypto } from '@otak/core-crypto';
2
2
  import type { APIClient } from '@wireapp/api-client';
3
3
  import { MessageSendingStatus, Conversation, DefaultConversationRoleName, MutedStatus, NewConversation, QualifiedUserClients, UserClients, ClientMismatch } from '@wireapp/api-client/src/conversation';
4
4
  import type { ConversationMemberLeaveEvent } from '@wireapp/api-client/src/event';
@@ -157,4 +157,12 @@ export declare class ConversationService {
157
157
  addUsersToMLSConversation({ qualifiedUserIds, groupId, conversationId, }: Required<AddUsersParams>): Promise<MLSReturnType>;
158
158
  private sendCommitBundleRemovalMessages;
159
159
  removeUsersFromMLSConversation({ groupId, conversationId, qualifiedUserIds, }: RemoveUsersParams): Promise<MLSReturnType>;
160
+ /**
161
+ * Will send an external proposal for the current device to join a specific conversation.
162
+ * In order for the external proposal to be sent correctly, the underlying mls conversation needs to be in a non-established state
163
+ * @param conversationGroupId The conversation to join
164
+ * @param epoch The current epoch of the local conversation
165
+ */
166
+ sendExternalJoinProposal(conversationGroupId: string, epoch: number): Promise<void>;
167
+ isMLSConversationEstablished(conversationGroupId: string): Promise<boolean>;
160
168
  }
@@ -944,6 +944,28 @@ class ConversationService {
944
944
  conversation,
945
945
  };
946
946
  }
947
+ /**
948
+ * Will send an external proposal for the current device to join a specific conversation.
949
+ * In order for the external proposal to be sent correctly, the underlying mls conversation needs to be in a non-established state
950
+ * @param conversationGroupId The conversation to join
951
+ * @param epoch The current epoch of the local conversation
952
+ */
953
+ async sendExternalJoinProposal(conversationGroupId, epoch) {
954
+ const coreCryptoClient = this.coreCryptoClientProvider();
955
+ const groupIdDecodedFromBase64 = bazinga64_1.Decoder.fromBase64(conversationGroupId).asBytes;
956
+ const externalProposal = await coreCryptoClient.newExternalProposal(0 /* Add */, {
957
+ epoch,
958
+ conversationId: groupIdDecodedFromBase64,
959
+ });
960
+ await this.apiClient.api.conversation.postMlsMessage(
961
+ //@todo: it's temporary - we wait for core-crypto fix to return the actual Uint8Array instead of regular array
962
+ optionalToUint8Array(externalProposal));
963
+ }
964
+ async isMLSConversationEstablished(conversationGroupId) {
965
+ const coreCryptoClient = this.coreCryptoClientProvider();
966
+ const groupIdDecodedFromBase64 = bazinga64_1.Decoder.fromBase64(conversationGroupId).asBytes;
967
+ return coreCryptoClient.conversationExists(groupIdDecodedFromBase64);
968
+ }
947
969
  }
948
970
  exports.ConversationService = ConversationService;
949
971
  //# sourceMappingURL=ConversationService.js.map
@@ -41,4 +41,5 @@ export declare function createEncryptedStore(dbName: string): Promise<EncryptedS
41
41
  * @param config contains the encrypt and decrypt methods
42
42
  */
43
43
  export declare function createCustomEncryptedStore<EncryptedPayload>(dbName: string, config: EncryptedStoreConfig<EncryptedPayload>): Promise<EncryptedStore<EncryptedPayload>>;
44
+ export declare function deleteEncryptedStore(dbName: string): Promise<void>;
44
45
  export {};
@@ -30,7 +30,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
30
30
  };
31
31
  var _EncryptedStore_decrypt, _EncryptedStore_encrypt;
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.createCustomEncryptedStore = exports.createEncryptedStore = void 0;
33
+ exports.deleteEncryptedStore = exports.createCustomEncryptedStore = exports.createEncryptedStore = void 0;
34
34
  const idb_1 = require("idb");
35
35
  class EncryptedStore {
36
36
  constructor(db, { encrypt, decrypt }) {
@@ -109,4 +109,8 @@ async function createCustomEncryptedStore(dbName, config) {
109
109
  return new EncryptedStore(db, config);
110
110
  }
111
111
  exports.createCustomEncryptedStore = createCustomEncryptedStore;
112
+ async function deleteEncryptedStore(dbName) {
113
+ return (0, idb_1.deleteDB)(dbName);
114
+ }
115
+ exports.deleteEncryptedStore = deleteEncryptedStore;
112
116
  //# sourceMappingURL=encryptedStore.js.map