@wireapp/core 27.6.0 → 28.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,22 @@
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
+ # [28.0.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@27.6.0...@wireapp/core@28.0.0) (2022-07-01)
7
+
8
+
9
+ ### Features
10
+
11
+ * Use mls config object ([#4307](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4307)) ([3d510d0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/3d510d0e041a3d049282e6a312ffa880d9bafd89))
12
+
13
+
14
+ ### BREAKING CHANGES
15
+
16
+ * the enableMLS flag has been removed in favor of a config object. If the config object is set, then MLS will be activated
17
+
18
+
19
+
20
+
21
+
6
22
  # [27.6.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@27.5.0...@wireapp/core@27.6.0) (2022-06-30)
7
23
 
8
24
 
package/package.json CHANGED
@@ -73,6 +73,6 @@
73
73
  "test:project": "yarn dist && yarn test",
74
74
  "test:node": "nyc jasmine --config=jasmine.json"
75
75
  },
76
- "version": "27.6.0",
77
- "gitHead": "8bc302af20f400f4c0cb3e15edfcaebb4494f1d0"
76
+ "version": "28.0.0",
77
+ "gitHead": "89c2a626f3f385edea215a96640c2805972a161a"
78
78
  }
@@ -59,13 +59,22 @@ declare type SecretCrypto<T> = {
59
59
  encrypt: (value: Uint8Array) => Promise<T>;
60
60
  decrypt: (payload: T) => Promise<Uint8Array>;
61
61
  };
62
- interface AccountOptions<T> {
63
- /** Used to store info in the database (will create a inMemory engine if returns undefined) */
64
- createStore?: CreateStoreFn;
65
- /** encrypt/decrypt function pair that will be called before storing/fetching secrets in the secrets database.
62
+ interface MLSConfig<T = any> {
63
+ /**
64
+ * encrypt/decrypt function pair that will be called before storing/fetching secrets in the secrets database.
66
65
  * If not provided will use the built in encryption mechanism
67
66
  */
68
67
  secretsCrypto?: SecretCrypto<T>;
68
+ /**
69
+ * path on the public server to the core crypto wasm file.
70
+ * This file will be downloaded lazily when corecrypto is needed.
71
+ * It, thus, needs to know where, on the server, the file can be found
72
+ */
73
+ coreCrypoWasmFilePath: string;
74
+ }
75
+ interface AccountOptions<T> {
76
+ /** Used to store info in the database (will create a inMemory engine if returns undefined) */
77
+ createStore?: CreateStoreFn;
69
78
  /** Number of prekeys to generate when creating a new device (defaults to 2)
70
79
  * Prekeys are Diffie-Hellmann public keys which allow offline initiation of a secure Proteus session between two devices.
71
80
  * Having a high value will:
@@ -76,16 +85,18 @@ interface AccountOptions<T> {
76
85
  * - 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
77
86
  */
78
87
  nbPrekeys?: number;
79
- enableMLS?: boolean;
88
+ /**
89
+ * Config for MLS devices. Will not load corecrypt or create MLS devices if undefined
90
+ */
91
+ mlsConfig?: MLSConfig<T>;
80
92
  }
81
93
  export declare class Account<T = unknown> extends EventEmitter {
82
94
  private readonly apiClient;
83
95
  private readonly logger;
84
96
  private readonly createStore;
85
97
  private storeEngine?;
86
- private readonly secretsCrypto?;
87
98
  private readonly nbPrekeys;
88
- private readonly enableMLS;
99
+ private readonly mlsConfig?;
89
100
  private coreCryptoClient?;
90
101
  static readonly TOPIC: typeof TOPIC;
91
102
  service?: {
@@ -108,7 +119,7 @@ export declare class Account<T = unknown> extends EventEmitter {
108
119
  * @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
109
120
  * @param accountOptions
110
121
  */
111
- constructor(apiClient?: APIClient, { createStore, nbPrekeys, secretsCrypto, enableMLS }?: AccountOptions<T>);
122
+ constructor(apiClient?: APIClient, { createStore, nbPrekeys, mlsConfig }?: AccountOptions<T>);
112
123
  private persistCookie;
113
124
  get clientId(): string;
114
125
  get userId(): string;
@@ -86,14 +86,13 @@ class Account extends events_1.EventEmitter {
86
86
  * @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
87
87
  * @param accountOptions
88
88
  */
89
- constructor(apiClient = new api_client_1.APIClient(), { createStore = () => undefined, nbPrekeys = 2, secretsCrypto, enableMLS = false } = {}) {
89
+ constructor(apiClient = new api_client_1.APIClient(), { createStore = () => undefined, nbPrekeys = 2, mlsConfig } = {}) {
90
90
  super();
91
91
  this.apiClient = apiClient;
92
92
  this.backendFeatures = this.apiClient.backendFeatures;
93
- this.secretsCrypto = secretsCrypto;
93
+ this.mlsConfig = this.mlsConfig;
94
94
  this.nbPrekeys = nbPrekeys;
95
95
  this.createStore = createStore;
96
- this.enableMLS = enableMLS;
97
96
  apiClient.on(api_client_1.APIClient.TOPIC.COOKIE_REFRESH, async (cookie) => {
98
97
  if (cookie && this.storeEngine) {
99
98
  try {
@@ -260,17 +259,17 @@ class Account extends events_1.EventEmitter {
260
259
  const loadedClient = await this.service.client.getLocalClient();
261
260
  await this.apiClient.api.client.getClient(loadedClient.id);
262
261
  this.apiClient.context.clientId = loadedClient.id;
263
- if (this.enableMLS) {
264
- this.coreCryptoClient = await this.createMLSClient(loadedClient, this.apiClient.context);
262
+ if (this.mlsConfig) {
263
+ this.coreCryptoClient = await this.createMLSClient(loadedClient, this.apiClient.context, this.mlsConfig);
265
264
  }
266
265
  return loadedClient;
267
266
  }
268
- async createMLSClient(client, context) {
267
+ async createMLSClient(client, context, mlsConfig) {
269
268
  const coreCryptoKeyId = 'corecrypto-key';
270
269
  const { CoreCrypto } = await Promise.resolve().then(() => __importStar(require('@otak/core-crypto')));
271
270
  const dbName = `secrets-${this.generateDbName(context)}`;
272
- const secretStore = this.secretsCrypto
273
- ? await (0, encryptedStore_1.createCustomEncryptedStore)(dbName, this.secretsCrypto)
271
+ const secretStore = mlsConfig.secretsCrypto
272
+ ? await (0, encryptedStore_1.createCustomEncryptedStore)(dbName, mlsConfig.secretsCrypto)
274
273
  : await (0, encryptedStore_1.createEncryptedStore)(dbName);
275
274
  let key = await secretStore.getsecretValue(coreCryptoKeyId);
276
275
  if (!key) {
@@ -288,10 +287,10 @@ class Account extends events_1.EventEmitter {
288
287
  if (!this.service) {
289
288
  throw new Error('Services are not set.');
290
289
  }
291
- this.logger.info(`Creating new client {mls: ${!!this.enableMLS}}`);
290
+ this.logger.info(`Creating new client {mls: ${!!this.mlsConfig}}`);
292
291
  const registeredClient = await this.service.client.register(loginData, clientInfo, entropyData);
293
- if (this.enableMLS) {
294
- this.coreCryptoClient = await this.createMLSClient(registeredClient, this.apiClient.context);
292
+ if (this.mlsConfig) {
293
+ this.coreCryptoClient = await this.createMLSClient(registeredClient, this.apiClient.context, this.mlsConfig);
295
294
  await this.service.client.uploadMLSPublicKeys(this.coreCryptoClient.clientPublicKey(), registeredClient.id);
296
295
  await this.service.client.uploadMLSKeyPackages(this.coreCryptoClient.clientKeypackages(this.nbPrekeys), registeredClient.id);
297
296
  }