@wireapp/core 27.3.7 → 27.4.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,36 @@
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
+ # [27.4.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@27.3.9...@wireapp/core@27.4.0) (2022-06-17)
7
+
8
+
9
+ ### Features
10
+
11
+ * **core:** Create MLS capable devices ([#4287](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4287)) ([8c9c0ca](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/8c9c0ca1c540370aa2fc386407695318f4047f0a))
12
+
13
+
14
+
15
+
16
+
17
+ ## [27.3.9](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@27.3.8...@wireapp/core@27.3.9) (2022-06-15)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **core:** Make sure access token is valid before connecting to websocket ([#4293](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4293)) ([1ef45a5](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/1ef45a5a60a086d4ebe0a512813d4677e7b99ded))
23
+
24
+
25
+
26
+
27
+
28
+ ## [27.3.8](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@27.3.7...@wireapp/core@27.3.8) (2022-06-15)
29
+
30
+ **Note:** Version bump only for package @wireapp/core
31
+
32
+
33
+
34
+
35
+
6
36
  ## [27.3.7](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@27.3.6...@wireapp/core@27.3.7) (2022-06-14)
7
37
 
8
38
  **Note:** Version bump only for package @wireapp/core
package/package.json CHANGED
@@ -3,9 +3,11 @@
3
3
  "./src/main/cryptography/AssetCryptography/crypto.node": "./src/main/cryptography/AssetCryptography/crypto.browser.js"
4
4
  },
5
5
  "dependencies": {
6
+ "@open-wc/webpack-import-meta-loader": "0.4.7",
7
+ "@otak/core-crypto": "0.2.0-beta-3",
6
8
  "@types/long": "4.0.1",
7
9
  "@types/node": "~14",
8
- "@wireapp/api-client": "19.6.2",
10
+ "@wireapp/api-client": "19.6.4",
9
11
  "@wireapp/cryptobox": "12.8.0",
10
12
  "bazinga64": "5.10.0",
11
13
  "hash.js": "1.1.7",
@@ -69,6 +71,6 @@
69
71
  "test:project": "yarn dist && yarn test",
70
72
  "test:node": "nyc jasmine --config=jasmine.json"
71
73
  },
72
- "version": "27.3.7",
73
- "gitHead": "d9b71b067cf68fb1fbb2c619f413bcd884bc090c"
74
+ "version": "27.4.0",
75
+ "gitHead": "18a1691d5401d6f3b9fbd279213fd4a30fea7845"
74
76
  }
@@ -68,6 +68,7 @@ interface AccountOptions {
68
68
  * - make it likely that all prekeys get consumed while the device is offline and the last resort prekey will be used to create new session
69
69
  */
70
70
  nbPrekeys?: number;
71
+ enableMLS?: boolean;
71
72
  }
72
73
  export declare class Account extends EventEmitter {
73
74
  private readonly apiClient;
@@ -75,6 +76,8 @@ export declare class Account extends EventEmitter {
75
76
  private readonly createStore;
76
77
  private storeEngine?;
77
78
  private readonly nbPrekeys;
79
+ private readonly enableMLS;
80
+ private coreCryptoClient?;
78
81
  static readonly TOPIC: typeof TOPIC;
79
82
  service?: {
80
83
  account: AccountService;
@@ -96,7 +99,7 @@ export declare class Account extends EventEmitter {
96
99
  * @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
97
100
  * @param storeEngineProvider
98
101
  */
99
- constructor(apiClient?: APIClient, { createStore, nbPrekeys }?: AccountOptions);
102
+ constructor(apiClient?: APIClient, { createStore, nbPrekeys, enableMLS }?: AccountOptions);
100
103
  private persistCookie;
101
104
  get clientId(): string;
102
105
  get userId(): string;
@@ -140,6 +143,7 @@ export declare class Account extends EventEmitter {
140
143
  }>;
141
144
  initServices(context: Context): Promise<void>;
142
145
  loadAndValidateLocalClient(): Promise<RegisteredClient>;
146
+ private createMLSClient;
143
147
  private registerClient;
144
148
  private resetContext;
145
149
  logout(): Promise<void>;
@@ -84,12 +84,13 @@ class Account extends events_1.EventEmitter {
84
84
  * @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
85
85
  * @param storeEngineProvider
86
86
  */
87
- constructor(apiClient = new api_client_1.APIClient(), { createStore = () => undefined, nbPrekeys = 2 } = {}) {
87
+ constructor(apiClient = new api_client_1.APIClient(), { createStore = () => undefined, nbPrekeys = 2, enableMLS = false } = {}) {
88
88
  super();
89
89
  this.apiClient = apiClient;
90
90
  this.backendFeatures = this.apiClient.backendFeatures;
91
91
  this.nbPrekeys = nbPrekeys;
92
92
  this.createStore = createStore;
93
+ this.enableMLS = enableMLS;
93
94
  apiClient.on(api_client_1.APIClient.TOPIC.COOKIE_REFRESH, async (cookie) => {
94
95
  if (cookie && this.storeEngine) {
95
96
  try {
@@ -256,17 +257,36 @@ class Account extends events_1.EventEmitter {
256
257
  const loadedClient = await this.service.client.getLocalClient();
257
258
  await this.apiClient.api.client.getClient(loadedClient.id);
258
259
  this.apiClient.context.clientId = loadedClient.id;
260
+ if (this.enableMLS) {
261
+ this.coreCryptoClient = await this.createMLSClient(loadedClient);
262
+ }
259
263
  return loadedClient;
260
264
  }
265
+ async createMLSClient(client) {
266
+ const { CoreCrypto } = await Promise.resolve().then(() => __importStar(require('@otak/core-crypto')));
267
+ const { userId, domain } = this.apiClient.context;
268
+ return CoreCrypto.init({
269
+ path: 'path/to/database',
270
+ key: 'a root identity key (i.e. enclaved encryption key for this device)',
271
+ clientId: `${userId}:${client.id}@${domain}`,
272
+ });
273
+ }
261
274
  async registerClient(loginData, clientInfo = coreDefaultClient, entropyData) {
262
275
  if (!this.service) {
263
276
  throw new Error('Services are not set.');
264
277
  }
278
+ this.logger.info(`Creating new client {mls: ${!!this.enableMLS}}`);
265
279
  const registeredClient = await this.service.client.register(loginData, clientInfo, entropyData);
280
+ if (this.enableMLS) {
281
+ this.coreCryptoClient = await this.createMLSClient(registeredClient);
282
+ await this.service.client.uploadMLSPublicKeys(this.coreCryptoClient.clientPublicKey(), registeredClient.id);
283
+ await this.service.client.uploadMLSKeyPackages(this.coreCryptoClient.clientKeypackages(this.nbPrekeys), registeredClient.id);
284
+ }
266
285
  this.apiClient.context.clientId = registeredClient.id;
267
- this.logger.log('Client is created');
286
+ this.logger.info('Client is created');
268
287
  await this.service.notification.initializeNotificationStream();
269
288
  await this.service.client.synchronizeClients();
289
+ await this.service.cryptography.initCryptobox();
270
290
  return { isNewClient: true, localClient: registeredClient };
271
291
  }
272
292
  resetContext() {
@@ -341,9 +361,8 @@ class Account extends events_1.EventEmitter {
341
361
  };
342
362
  await this.apiClient.connect(onBeforeConnect);
343
363
  return () => {
364
+ this.apiClient.transport.ws.removeAllListeners();
344
365
  this.apiClient.disconnect();
345
- this.apiClient.transport.ws.removeAllListeners(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE);
346
- this.apiClient.transport.ws.removeListener(tcp_1.WebSocketClient.TOPIC.ON_STATE_CHANGE, onConnectionStateChanged);
347
366
  };
348
367
  }
349
368
  async initEngine(context) {
@@ -37,4 +37,12 @@ export declare class ClientService {
37
37
  createLocalClient(client: RegisteredClient, domain?: string): Promise<MetaClient>;
38
38
  synchronizeClients(): Promise<MetaClient[]>;
39
39
  register(loginData: LoginData, clientInfo: ClientInfo, entropyData?: Uint8Array): Promise<RegisteredClient>;
40
+ /**
41
+ * Will make the given client mls capable (generate and upload key packages)
42
+ *
43
+ * @param mlsClient Intance of the coreCrypto that represents the mls client
44
+ * @param clientId The id of the client
45
+ */
46
+ uploadMLSPublicKeys(publicKey: Uint8Array, clientId: string): Promise<void>;
47
+ uploadMLSKeyPackages(keypackages: Uint8Array[], clientId: string): Promise<void>;
40
48
  }
@@ -21,6 +21,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.ClientService = void 0;
22
22
  const client_1 = require("@wireapp/api-client/src/client/");
23
23
  const _1 = require("./");
24
+ const bazinga64_1 = require("bazinga64");
24
25
  class ClientService {
25
26
  constructor(apiClient, storeEngine, cryptographyService) {
26
27
  this.apiClient = apiClient;
@@ -96,9 +97,22 @@ class ClientService {
96
97
  };
97
98
  const client = await this.backend.postClient(newClient);
98
99
  await this.createLocalClient(client, this.apiClient.context.domain);
99
- await this.cryptographyService.initCryptobox();
100
100
  return client;
101
101
  }
102
+ /**
103
+ * Will make the given client mls capable (generate and upload key packages)
104
+ *
105
+ * @param mlsClient Intance of the coreCrypto that represents the mls client
106
+ * @param clientId The id of the client
107
+ */
108
+ async uploadMLSPublicKeys(publicKey, clientId) {
109
+ return this.backend.putClient(clientId, {
110
+ mls_public_keys: { ed25519: btoa(bazinga64_1.Converter.arrayBufferViewToBaselineString(publicKey)) },
111
+ });
112
+ }
113
+ async uploadMLSKeyPackages(keypackages, clientId) {
114
+ return this.backend.uploadMLSKeyPackages(clientId, keypackages.map(keypackage => btoa(bazinga64_1.Converter.arrayBufferViewToBaselineString(keypackage))));
115
+ }
102
116
  }
103
117
  exports.ClientService = ClientService;
104
118
  //# sourceMappingURL=ClientService.js.map