@wireapp/core 42.26.2 → 43.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.
Files changed (35) hide show
  1. package/lib/Account.d.ts +5 -5
  2. package/lib/Account.d.ts.map +1 -1
  3. package/lib/Account.js +38 -21
  4. package/lib/messagingProtocols/mls/types.d.ts +5 -8
  5. package/lib/messagingProtocols/mls/types.d.ts.map +1 -1
  6. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts +5 -4
  7. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts.map +1 -1
  8. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.js +6 -13
  9. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts +4 -0
  10. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts.map +1 -1
  11. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.js +6 -0
  12. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/index.d.ts +0 -1
  13. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/index.d.ts.map +1 -1
  14. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/index.js +0 -1
  15. package/lib/{messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper → secretStore}/encryptedStore.d.ts +3 -2
  16. package/lib/secretStore/encryptedStore.d.ts.map +1 -0
  17. package/lib/{messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper → secretStore}/encryptedStore.js +8 -3
  18. package/lib/secretStore/encryptedStore.test.node.d.ts.map +1 -0
  19. package/lib/{messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper → secretStore}/encryptedStore.test.node.js +2 -2
  20. package/lib/secretStore/secretKeyGenerator.d.ts +21 -0
  21. package/lib/secretStore/secretKeyGenerator.d.ts.map +1 -0
  22. package/lib/{messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper → secretStore}/secretKeyGenerator.js +11 -8
  23. package/lib/secretStore/secretKeyGenerator.test.d.ts.map +1 -0
  24. package/lib/{messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper → secretStore}/secretKeyGenerator.test.js +11 -7
  25. package/package.json +2 -2
  26. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/encryptedStore.d.ts.map +0 -1
  27. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/encryptedStore.test.node.d.ts.map +0 -1
  28. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/secretKeyGenerator.d.ts +0 -13
  29. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/secretKeyGenerator.d.ts.map +0 -1
  30. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/secretKeyGenerator.test.d.ts.map +0 -1
  31. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.d.ts +0 -22
  32. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.d.ts.map +0 -1
  33. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.js +0 -64
  34. /package/lib/{messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper → secretStore}/encryptedStore.test.node.d.ts +0 -0
  35. /package/lib/{messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper → secretStore}/secretKeyGenerator.test.d.ts +0 -0
package/lib/Account.d.ts CHANGED
@@ -14,7 +14,7 @@ import { GiphyService } from './giphy/';
14
14
  import { LinkPreviewService } from './linkPreview';
15
15
  import { MLSService } from './messagingProtocols/mls';
16
16
  import { AcmeChallenge, E2EIServiceExternal } from './messagingProtocols/mls/E2EIdentityService';
17
- import { CoreCallbacks, CryptoProtocolConfig } from './messagingProtocols/mls/types';
17
+ import { CoreCallbacks, CoreCryptoConfig } from './messagingProtocols/mls/types';
18
18
  import { NewClient, ProteusService } from './messagingProtocols/proteus';
19
19
  import { HandledEventPayload, NotificationService, NotificationSource } from './notification/';
20
20
  import { SelfService } from './self/';
@@ -54,9 +54,9 @@ interface AccountOptions {
54
54
  */
55
55
  nbPrekeys?: number;
56
56
  /**
57
- * Config for MLS and proteus devices. Will fallback to the old proteus logic if not provided
57
+ * Config for MLS and proteus devices. Will fallback to the old cryptobox logic if not provided
58
58
  */
59
- cryptoProtocolConfig?: CryptoProtocolConfig;
59
+ coreCryptoConfig?: CoreCryptoConfig;
60
60
  }
61
61
  type InitOptions = {
62
62
  /** cookie used to identify the current user. Will use the browser cookie if not defined */
@@ -70,7 +70,7 @@ export declare class Account extends TypedEventEmitter<Events> {
70
70
  private readonly logger;
71
71
  private readonly createStore;
72
72
  private readonly nbPrekeys;
73
- private readonly cryptoProtocolConfig?;
73
+ private readonly coreCryptoConfig?;
74
74
  private readonly isMlsEnabled;
75
75
  /** this is the client the consumer is currently using. Will be set as soon as `initClient` is called and will be rest upon logout */
76
76
  private currentClient?;
@@ -101,7 +101,7 @@ export declare class Account extends TypedEventEmitter<Events> {
101
101
  * @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
102
102
  * @param accountOptions
103
103
  */
104
- constructor(apiClient?: APIClient, { createStore, nbPrekeys, cryptoProtocolConfig }?: AccountOptions);
104
+ constructor(apiClient?: APIClient, { createStore, nbPrekeys, coreCryptoConfig }?: AccountOptions);
105
105
  /**
106
106
  * Will set the APIClient to use a specific version of the API (by default uses version 0)
107
107
  * It will fetch the API Config and use the highest possible version
@@ -1 +1 @@
1
- {"version":3,"file":"Account.d.ts","sourceRoot":"","sources":["../src/Account.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,YAAY,EAGZ,OAAO,EACP,MAAM,EAEN,SAAS,EACV,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAu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,SAAS,CAAC;YAkClD,iBAAiB;IA2B/B;;;;;;OAMG;IACH,sBAAsB,CAAC,aAAa,EAAE,aAAa;IAItC,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAsE1D,OAAO,CAAC,YAAY;IAMpB;;;OAGG;IACU,MAAM,CAAC,SAAS,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAS9D;;OAEG;YACW,IAAI;IAOlB;;;;;;OAMG;IACI,MAAM,CAAC,EACZ,OAAkB,EAClB,wBAAmC,EACnC,4BAAuC,EACvC,qBAAgC,EAChC,MAAc,GACf,GAAE;QACD;;;;WAIG;QACH,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;QAE7E;;WAEG;QACH,4BAA4B,CAAC,EAAE,CAAC,EAAC,IAAI,EAAE,KAAK,EAAC,EAAE;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAC,KAAK,IAAI,CAAC;QAEtF;;WAEG;QACH,wBAAwB,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;QAE5D;;;;;;WAMG;QACH,qBAAqB,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;QAEzD;;WAEG;QACH,MAAM,CAAC,EAAE,OAAO,CAAC;KACb,GAAG,MAAM,IAAI;IA2FnB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,kBAAkB;YAIZ,UAAU;IAsBxB,OAAO,CAAC,yBAAyB,CAS/B;CACH"}
package/lib/Account.js CHANGED
@@ -17,6 +17,29 @@
17
17
  * along with this program. If not, see http://www.gnu.org/licenses/.
18
18
  *
19
19
  */
20
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ var desc = Object.getOwnPropertyDescriptor(m, k);
23
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
+ desc = { enumerable: true, get: function() { return m[k]; } };
25
+ }
26
+ Object.defineProperty(o, k2, desc);
27
+ }) : (function(o, m, k, k2) {
28
+ if (k2 === undefined) k2 = k;
29
+ o[k2] = m[k];
30
+ }));
31
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
32
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
33
+ }) : function(o, v) {
34
+ o["default"] = v;
35
+ });
36
+ var __importStar = (this && this.__importStar) || function (mod) {
37
+ if (mod && mod.__esModule) return mod;
38
+ var result = {};
39
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
40
+ __setModuleDefault(result, mod);
41
+ return result;
42
+ };
20
43
  var __asyncValues = (this && this.__asyncValues) || function (o) {
21
44
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
22
45
  var m = o[Symbol.asyncIterator], i;
@@ -53,7 +76,6 @@ const mls_1 = require("./messagingProtocols/mls");
53
76
  const E2EIdentityService_1 = require("./messagingProtocols/mls/E2EIdentityService");
54
77
  const proteus_1 = require("./messagingProtocols/proteus");
55
78
  const CryptoClient_1 = require("./messagingProtocols/proteus/ProteusService/CryptoClient");
56
- const cryptoMigrationStateStore_1 = require("./messagingProtocols/proteus/ProteusService/cryptoMigrationStateStore");
57
79
  const notification_1 = require("./notification/");
58
80
  const self_1 = require("./self/");
59
81
  const CoreDB_1 = require("./storage/CoreDB");
@@ -89,7 +111,7 @@ class Account extends commons_1.TypedEventEmitter {
89
111
  * @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
90
112
  * @param accountOptions
91
113
  */
92
- constructor(apiClient = new api_client_1.APIClient(), { createStore = () => undefined, nbPrekeys = 100, cryptoProtocolConfig } = {}) {
114
+ constructor(apiClient = new api_client_1.APIClient(), { createStore = () => undefined, nbPrekeys = 100, coreCryptoConfig } = {}) {
93
115
  super();
94
116
  this.groupIdFromConversationId = async (conversationId, subconversationId) => {
95
117
  var _a, _b;
@@ -100,9 +122,9 @@ class Account extends commons_1.TypedEventEmitter {
100
122
  };
101
123
  this.apiClient = apiClient;
102
124
  this.backendFeatures = this.apiClient.backendFeatures;
103
- this.cryptoProtocolConfig = cryptoProtocolConfig;
125
+ this.coreCryptoConfig = coreCryptoConfig;
104
126
  this.nbPrekeys = nbPrekeys;
105
- this.isMlsEnabled = async () => { var _a; return !!((_a = this.cryptoProtocolConfig) === null || _a === void 0 ? void 0 : _a.mls) && (await this.apiClient.supportsMLS()); };
127
+ this.isMlsEnabled = async () => { var _a; return !!((_a = this.coreCryptoConfig) === null || _a === void 0 ? void 0 : _a.mls) && (await this.apiClient.supportsMLS()); };
106
128
  this.createStore = createStore;
107
129
  this.recurringTaskScheduler = new RecurringTaskScheduler_1.RecurringTaskScheduler({
108
130
  get: async (key) => {
@@ -283,28 +305,23 @@ class Account extends commons_1.TypedEventEmitter {
283
305
  return validClient;
284
306
  }
285
307
  async buildCryptoClient(context, storeEngine) {
286
- var _a, _b, _c;
287
- /* There are 3 cases where we want to instantiate CoreCrypto:
288
- * 1. MLS is enabled
289
- * 2. The user has enabled CoreCrypto in the config
290
- * 3. The user has already used CoreCrypto in the past (cannot rollback to using cryptobox)
291
- */
292
- const clientType = (await this.isMlsEnabled()) ||
293
- !!((_a = this.cryptoProtocolConfig) === null || _a === void 0 ? void 0 : _a.useCoreCrypto) ||
294
- cryptoMigrationStateStore_1.cryptoMigrationStore.coreCrypto.isReady(storeEngine.storeName)
295
- ? CryptoClient_1.CryptoClientType.CORE_CRYPTO
296
- : CryptoClient_1.CryptoClientType.CRYPTOBOX;
297
- return (0, CryptoClient_1.buildCryptoClient)(clientType, {
298
- storeEngine,
308
+ const baseConfig = {
299
309
  nbPrekeys: this.nbPrekeys,
300
- coreCryptoWasmFilePath: (_b = this.cryptoProtocolConfig) === null || _b === void 0 ? void 0 : _b.coreCrypoWasmFilePath,
301
- systemCrypto: (_c = this.cryptoProtocolConfig) === null || _c === void 0 ? void 0 : _c.systemCrypto,
302
310
  onNewPrekeys: async (prekeys) => {
303
311
  this.logger.debug(`Received '${prekeys.length}' new PreKeys.`);
304
312
  await this.apiClient.api.client.putClient(context.clientId, { prekeys });
305
313
  this.logger.debug(`Successfully uploaded '${prekeys.length}' PreKeys.`);
306
314
  },
307
- });
315
+ };
316
+ const coreCryptoConfig = this.coreCryptoConfig;
317
+ if (coreCryptoConfig) {
318
+ const { buildClient } = await Promise.resolve().then(() => __importStar(require('./messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper')));
319
+ const client = await buildClient(storeEngine, Object.assign(Object.assign(Object.assign({}, baseConfig), coreCryptoConfig), { generateSecretKey: keyId => coreCryptoConfig.generateSecretKey(storeEngine.storeName, keyId, 16) }));
320
+ return [CryptoClient_1.CryptoClientType.CORE_CRYPTO, client];
321
+ }
322
+ const { buildClient } = await Promise.resolve().then(() => __importStar(require('./messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper')));
323
+ const client = await buildClient(storeEngine, baseConfig);
324
+ return [CryptoClient_1.CryptoClientType.CRYPTOBOX, client];
308
325
  }
309
326
  /**
310
327
  * In order to be able to send MLS messages, the core needs a few information from the consumer.
@@ -332,7 +349,7 @@ class Account extends commons_1.TypedEventEmitter {
332
349
  const clientService = new client_2.ClientService(this.apiClient, proteusService, this.storeEngine);
333
350
  if (clientType === CryptoClient_1.CryptoClientType.CORE_CRYPTO && (await this.isMlsEnabled())) {
334
351
  e2eIdentityService = new E2EIdentityService_1.E2EIServiceExternal(cryptoClient.getNativeClient(), clientService);
335
- mlsService = new mls_1.MLSService(this.apiClient, cryptoClient.getNativeClient(), this.db, this.recurringTaskScheduler, Object.assign({}, (_a = this.cryptoProtocolConfig) === null || _a === void 0 ? void 0 : _a.mls));
352
+ mlsService = new mls_1.MLSService(this.apiClient, cryptoClient.getNativeClient(), this.db, this.recurringTaskScheduler, Object.assign({}, (_a = this.coreCryptoConfig) === null || _a === void 0 ? void 0 : _a.mls));
336
353
  }
337
354
  const connectionService = new connection_1.ConnectionService(this.apiClient);
338
355
  const giphyService = new giphy_1.GiphyService(this.apiClient);
@@ -1,5 +1,6 @@
1
1
  import { QualifiedId } from '@wireapp/api-client/lib/user';
2
2
  import { MLSServiceConfig } from './MLSService/MLSService.types';
3
+ import { GeneratedKey } from '../../secretStore/secretKeyGenerator';
3
4
  export type ClientId = string;
4
5
  export type SecretCrypto = {
5
6
  encrypt: (value: Uint8Array) => Promise<Uint8Array>;
@@ -29,22 +30,18 @@ export type HandlePendingProposalsParams = {
29
30
  export type CommitPendingProposalsParams = {
30
31
  skipDelete?: boolean;
31
32
  } & CommonMLS;
32
- export interface CryptoProtocolConfig {
33
+ export interface CoreCryptoConfig {
33
34
  /**
34
- * encrypt/decrypt function pair that will be called before storing/fetching secrets in the secrets database.
35
- * If not provided will use the built in encryption mechanism
35
+ * function called to generate the secret key for CoreCrypto's database encryption
36
36
  */
37
- systemCrypto?: SecretCrypto;
38
- useCoreCrypto?: boolean;
37
+ generateSecretKey: (storeName: string, keyId: string, keySize: number) => Promise<GeneratedKey>;
39
38
  /**
40
39
  * path on the public server to the core crypto wasm file.
41
40
  * This file will be downloaded lazily when corecrypto is needed.
42
41
  * It, thus, needs to know where, on the server, the file can be found
43
42
  */
44
- coreCrypoWasmFilePath: string;
43
+ wasmFilePath: string;
45
44
  /** If set will create an MLS capable device from the current device */
46
45
  mls?: Partial<MLSServiceConfig>;
47
- /** if set to true, will use experimental proteus encryption/decryption library (core-crypto). If not set will fallback to the legacy proteus library (cryptobox) */
48
- proteus?: boolean;
49
46
  }
50
47
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/messagingProtocols/mls/types.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAEzD,OAAO,E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AO,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAEhG;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB,uEAAuE;IACvE,GAAG,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACjC"}
@@ -1,17 +1,18 @@
1
1
  import { PreKey } from '@wireapp/api-client/lib/auth';
2
2
  import { CoreCrypto } from '@wireapp/core-crypto';
3
3
  import type { CRUDEngine } from '@wireapp/store-engine';
4
- import { SecretCrypto } from '../../../../mls/types';
4
+ import { GeneratedKey } from '../../../../../secretStore/secretKeyGenerator';
5
5
  import { CryptoClient } from '../CryptoClient.types';
6
6
  type Config = {
7
- systemCrypto?: SecretCrypto;
7
+ generateSecretKey: (keyId: string) => Promise<GeneratedKey>;
8
8
  nbPrekeys: number;
9
9
  onNewPrekeys: (prekeys: PreKey[]) => void;
10
+ wasmFilePath: string;
10
11
  };
11
- type ClientConfig = Config & {
12
+ type ClientConfig = Omit<Config, 'generateSecretKey' | 'wasmFilePath'> & {
12
13
  onWipe: () => Promise<void>;
13
14
  };
14
- export declare function buildClient(storeEngine: CRUDEngine, coreCryptoWasmFilePath: string, { systemCrypto, nbPrekeys, onNewPrekeys }: Config): Promise<CoreCryptoWrapper>;
15
+ export declare function buildClient(storeEngine: CRUDEngine, { wasmFilePath, generateSecretKey, nbPrekeys, onNewPrekeys }: Config): Promise<CoreCryptoWrapper>;
15
16
  export declare class CoreCryptoWrapper implements CryptoClient {
16
17
  private readonly coreCrypto;
17
18
  private readonly config;
@@ -1 +1 @@
1
- {"version":3,"file":"CoreCryptoWrapper.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AAIpD,OAAO,EAAc,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,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E,UAAU;IAIvD,aAAa,CAAC,SAAS,EAAE,MAAM;IAI/B,WAAW,CAAC,SAAS,EAAE,MAAM;IAI7B,aAAa,CAAC,SAAS,EAAE,MAAM;IAI/B,aAAa;IAIP,SAAS;;;;IAKT,iBAAiB,CAAC,SAAS,EAAE,MAAM;IAUnC,kBAAkB;IAIlB,oBAAoB,CAAC,MAAM,EAAE,MAAM;IAIzC;;;;OAIG;IACH,OAAO,CAAC,OAAO;IAgBT,IAAI;CAIX"}
1
+ {"version":3,"file":"CoreCryptoWrapper.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AAIpD,OAAO,EAAc,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAItD,OAAO,EAAoB,YAAY,EAAC,MAAM,+CAA+C,CAAC;AAC9F,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAEnD,KAAK,MAAM,GAAG;IACZ,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC1C,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,KAAK,YAAY,GAAG,IAAI,CAAC,MAAM,EAAE,mBAAmB,GAAG,cAAc,CAAC,GAAG;IACvE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AAEF,wBAAsB,WAAW,CAC/B,WAAW,EAAE,UAAU,EACvB,EAAC,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAC,EAAE,MAAM,GACjE,OAAO,CAAC,iBAAiB,CAAC,CAsB5B;AAED,qBAAa,iBAAkB,YAAW,YAAY;IAIlD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;gBAG3B,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,YAAY;IAKvC,eAAe;IAIf,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,UAAU;IAIjD,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU;IAI9C,IAAI,CAAC,gBAAgB,CAAC,EAAE,MAAM;IAOxB,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU;;;;;;;IAqBpD,cAAc;IAId,oBAAoB,CAAC,SAAS,EAAE,MAAM;IAIhC,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU;IAK/D,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAIvD,aAAa,CAAC,SAAS,EAAE,MAAM;IAI/B,WAAW,CAAC,SAAS,EAAE,MAAM;IAI7B,aAAa,CAAC,SAAS,EAAE,MAAM;IAI/B,aAAa;IAIP,SAAS;;;;IAKT,iBAAiB,CAAC,SAAS,EAAE,MAAM;IAUnC,kBAAkB;IAIlB,oBAAoB,CAAC,MAAM,EAAE,MAAM;IAIzC;;;;OAIG;IACH,OAAO,CAAC,OAAO;IAgBT,IAAI;CAIX"}
@@ -23,26 +23,19 @@ const bazinga64_1 = require("bazinga64");
23
23
  const idb_1 = require("idb");
24
24
  const core_crypto_1 = require("@wireapp/core-crypto");
25
25
  const PrekeysTracker_1 = require("./PrekeysTracker");
26
- const secretKeyGenerator_1 = require("./secretKeyGenerator");
27
- async function buildClient(storeEngine, coreCryptoWasmFilePath, { systemCrypto, nbPrekeys, onNewPrekeys }) {
26
+ const secretKeyGenerator_1 = require("../../../../../secretStore/secretKeyGenerator");
27
+ async function buildClient(storeEngine, { wasmFilePath, generateSecretKey, nbPrekeys, onNewPrekeys }) {
28
28
  let key;
29
29
  const coreCryptoDbName = `corecrypto-${storeEngine.storeName}`;
30
- const secretKeysDbName = `secrets-${storeEngine.storeName}`;
30
+ const coreCryptoKeyId = 'corecrypto-key';
31
31
  try {
32
- key = await (0, secretKeyGenerator_1.generateSecretKey)({
33
- dbName: secretKeysDbName,
34
- systemCrypto,
35
- });
32
+ key = await generateSecretKey(coreCryptoKeyId);
36
33
  }
37
34
  catch (error) {
38
35
  if (error instanceof secretKeyGenerator_1.CorruptedKeyError) {
39
36
  // If we are dealing with a corrupted key, we wipe the key and the coreCrypto DB to start fresh
40
- await (0, idb_1.deleteDB)(secretKeysDbName);
41
37
  await (0, idb_1.deleteDB)(coreCryptoDbName);
42
- key = await (0, secretKeyGenerator_1.generateSecretKey)({
43
- dbName: secretKeysDbName,
44
- systemCrypto,
45
- });
38
+ key = await generateSecretKey(coreCryptoKeyId);
46
39
  }
47
40
  else {
48
41
  throw error;
@@ -51,7 +44,7 @@ async function buildClient(storeEngine, coreCryptoWasmFilePath, { systemCrypto,
51
44
  const coreCrypto = await core_crypto_1.CoreCrypto.deferredInit({
52
45
  databaseName: coreCryptoDbName,
53
46
  key: bazinga64_1.Encoder.toBase64(key.key).asString,
54
- wasmFilePath: coreCryptoWasmFilePath,
47
+ wasmFilePath,
55
48
  ciphersuites: [core_crypto_1.Ciphersuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519],
56
49
  });
57
50
  return new CoreCryptoWrapper(coreCrypto, { nbPrekeys, onNewPrekeys, onWipe: key.deleteKey });
@@ -3,6 +3,10 @@ export type InitialPrekeys = {
3
3
  prekeys: PreKey[];
4
4
  lastPrekey: PreKey;
5
5
  };
6
+ export declare enum CryptoClientType {
7
+ CORE_CRYPTO = 0,
8
+ CRYPTOBOX = 1
9
+ }
6
10
  export interface CryptoClient<T = unknown> {
7
11
  getNativeClient(): T;
8
12
  encrypt(sessions: string[], plainText: Uint8Array): Promise<Map<string, Uint8Array>>;
@@ -1 +1 @@
1
- {"version":3,"file":"CryptoClient.types.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AAEpD,MAAM,MAAM,cAAc,GAAG;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC,CAAC;AAErE,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,eAAe,IAAI,CAAC,CAAC;IACrB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IACrF,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAErE;;OAEG;IACH,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC;;OAEG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACzE,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACzD,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAChF,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnD,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC;;OAEG;IACH,oBAAoB,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB"}
1
+ {"version":3,"file":"CryptoClient.types.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AAEpD,MAAM,MAAM,cAAc,GAAG;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC,CAAC;AAErE,oBAAY,gBAAgB;IAC1B,WAAW,IAAA;IACX,SAAS,IAAA;CACV;AAED,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,eAAe,IAAI,CAAC,CAAC;IACrB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IACrF,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAErE;;OAEG;IACH,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC;;OAEG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACzE,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACzD,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAChF,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxE,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnD,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC;;OAEG;IACH,oBAAoB,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB"}
@@ -18,3 +18,9 @@
18
18
  *
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.CryptoClientType = void 0;
22
+ var CryptoClientType;
23
+ (function (CryptoClientType) {
24
+ CryptoClientType[CryptoClientType["CORE_CRYPTO"] = 0] = "CORE_CRYPTO";
25
+ CryptoClientType[CryptoClientType["CRYPTOBOX"] = 1] = "CRYPTOBOX";
26
+ })(CryptoClientType || (exports.CryptoClientType = CryptoClientType = {}));
@@ -1,3 +1,2 @@
1
- export * from './CryptoClient';
2
1
  export * from './CryptoClient.types';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/index.ts"],"names":[],"mappings":"AAmBA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/index.ts"],"names":[],"mappings":"AAmBA,cAAc,sBAAsB,CAAC"}
@@ -32,5 +32,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
32
32
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- __exportStar(require("./CryptoClient"), exports);
36
35
  __exportStar(require("./CryptoClient.types"), exports);
@@ -24,8 +24,9 @@ export declare class EncryptedStore<EncryptedPayload> {
24
24
  private readonly db;
25
25
  constructor(db: IDBPDatabase<EncryptedDB<EncryptedPayload>>, { encrypt, decrypt }: EncryptedStoreConfig<EncryptedPayload>);
26
26
  saveSecretValue(primaryKey: string, value: Uint8Array): Promise<void>;
27
- getsecretValue(primaryKey: string): Promise<Uint8Array | undefined>;
28
- close(): Promise<void>;
27
+ getSecretValue(primaryKey: string): Promise<Uint8Array | undefined>;
28
+ deleteSecretValue(primaryKey: string): Promise<void>;
29
+ close(): void;
29
30
  wipe(): Promise<void>;
30
31
  }
31
32
  /**
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryptedStore.d.ts","sourceRoot":"","sources":["../../src/secretStore/encryptedStore.ts"],"names":[],"mappings":"A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Ac,CAAC,uBAAuB,CAAC,CAAC,CAkB3G;AAED;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAAC,gBAAgB,EAC/D,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,GAC7C,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,CAQ3C"}
@@ -44,18 +44,23 @@ class EncryptedStore {
44
44
  const encrypted = await __classPrivateFieldGet(this, _EncryptedStore_encrypt, "f").call(this, value);
45
45
  await this.db.put('secrets', encrypted, primaryKey);
46
46
  }
47
- async getsecretValue(primaryKey) {
47
+ async getSecretValue(primaryKey) {
48
48
  const result = await this.db.get('secrets', primaryKey);
49
49
  if (!result) {
50
50
  return undefined;
51
51
  }
52
52
  return __classPrivateFieldGet(this, _EncryptedStore_decrypt, "f").call(this, result);
53
53
  }
54
- async close() {
54
+ async deleteSecretValue(primaryKey) {
55
+ const instance = await (0, idb_1.openDB)(this.db.name, this.db.version);
56
+ await instance.delete('secrets', primaryKey);
57
+ instance.close();
58
+ }
59
+ close() {
55
60
  this.db.close();
56
61
  }
57
62
  async wipe() {
58
- this.db.close();
63
+ this.close();
59
64
  await (0, idb_1.deleteDB)(this.db.name);
60
65
  }
61
66
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryptedStore.test.node.d.ts","sourceRoot":"","sources":["../../src/secretStore/encryptedStore.test.node.ts"],"names":[],"mappings":""}
@@ -25,7 +25,7 @@ describe('encryptedStore', () => {
25
25
  const store = await (0, encryptedStore_1.createEncryptedStore)('test');
26
26
  const value = Uint8Array.from([1, 2, 3]);
27
27
  await store.saveSecretValue('test', value);
28
- const result = await store.getsecretValue('test');
28
+ const result = await store.getSecretValue('test');
29
29
  expect(result).toEqual(value);
30
30
  });
31
31
  });
@@ -37,7 +37,7 @@ describe('encryptedStore', () => {
37
37
  });
38
38
  const value = Uint8Array.from([1, 2, 3]);
39
39
  await store.saveSecretValue('test', value);
40
- const result = await store.getsecretValue('test');
40
+ const result = await store.getSecretValue('test');
41
41
  expect(result).toEqual(value);
42
42
  });
43
43
  });
@@ -0,0 +1,21 @@
1
+ import { SecretCrypto } from '../messagingProtocols/mls/types';
2
+ export declare class CorruptedKeyError extends Error {
3
+ }
4
+ export type GeneratedKey = {
5
+ key: Uint8Array;
6
+ deleteKey: () => Promise<void>;
7
+ };
8
+ /**
9
+ * Will generate (or retrieve) a secret key from the database.
10
+ */
11
+ export declare function generateSecretKey({ keyId, keySize, dbName, systemCrypto: baseCrypto, }: {
12
+ /** the ID of the key to generate (if the ID already exists, then the generated key will be returned) */
13
+ keyId: string;
14
+ /** size of the key to generate */
15
+ keySize?: number;
16
+ /** name of the database that will hold the secrets */
17
+ dbName: string;
18
+ /** custom crypto primitives to use to encrypt the secret keys */
19
+ systemCrypto?: SecretCrypto;
20
+ }): Promise<GeneratedKey>;
21
+ //# sourceMappingURL=secretKeyGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secretKeyGenerator.d.ts","sourceRoot":"","sources":["../../src/secretStore/secretKeyGenerator.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAC,YAAY,EAAC,MAAM,iCAAiC,CAAC;AAI7D,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;AAE/C,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,UAAU,CAAC;IAChB,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,KAAK,EACL,OAAY,EACZ,MAAM,EACN,YAAY,EAAE,UAAU,GACzB,EAAE;IACD,wGAAwG;IACxG,KAAK,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,iEAAiE;IACjE,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,GAAG,OAAO,CAAC,YAAY,CAAC,CAwDxB"}
@@ -22,12 +22,13 @@ exports.generateSecretKey = exports.CorruptedKeyError = void 0;
22
22
  const bazinga64_1 = require("bazinga64");
23
23
  const encryptedStore_1 = require("./encryptedStore");
24
24
  const isBase64 = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/;
25
- const KEY_SIZE = 16;
26
25
  class CorruptedKeyError extends Error {
27
26
  }
28
27
  exports.CorruptedKeyError = CorruptedKeyError;
29
- async function generateSecretKey({ dbName, systemCrypto: baseCrypto, }) {
30
- const coreCryptoKeyId = 'corecrypto-key';
28
+ /**
29
+ * Will generate (or retrieve) a secret key from the database.
30
+ */
31
+ async function generateSecretKey({ keyId, keySize = 16, dbName, systemCrypto: baseCrypto, }) {
31
32
  const systemCrypto = baseCrypto
32
33
  ? {
33
34
  encrypt: (value) => {
@@ -59,21 +60,23 @@ async function generateSecretKey({ dbName, systemCrypto: baseCrypto, }) {
59
60
  try {
60
61
  let key;
61
62
  try {
62
- key = await secretsDb.getsecretValue(coreCryptoKeyId);
63
+ key = await secretsDb.getSecretValue(keyId);
63
64
  }
64
65
  catch (error) {
66
+ await secretsDb.deleteSecretValue(keyId);
65
67
  throw new CorruptedKeyError('Could not decrypt key');
66
68
  }
67
- if (key && key.length !== KEY_SIZE) {
69
+ if (key && key.length !== keySize) {
68
70
  // If the key size is not correct, we have a corrupted key in the DB. This is unrecoverable.
71
+ await secretsDb.deleteSecretValue(keyId);
69
72
  throw new CorruptedKeyError('Invalid key');
70
73
  }
71
74
  if (!key) {
72
- key = crypto.getRandomValues(new Uint8Array(KEY_SIZE));
73
- await secretsDb.saveSecretValue(coreCryptoKeyId, key);
75
+ key = crypto.getRandomValues(new Uint8Array(keySize));
76
+ await secretsDb.saveSecretValue(keyId, key);
74
77
  }
75
78
  await (secretsDb === null || secretsDb === void 0 ? void 0 : secretsDb.close());
76
- return { key, deleteKey: () => secretsDb.wipe() };
79
+ return { key, deleteKey: () => secretsDb.deleteSecretValue(keyId) };
77
80
  }
78
81
  catch (error) {
79
82
  await (secretsDb === null || secretsDb === void 0 ? void 0 : secretsDb.close());
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secretKeyGenerator.test.d.ts","sourceRoot":"","sources":["../../src/secretStore/secretKeyGenerator.test.ts"],"names":[],"mappings":""}
@@ -53,6 +53,7 @@ const systemCryptos = {
53
53
  },
54
54
  };
55
55
  const dbName = 'test';
56
+ const keyId = 'test-key';
56
57
  describe('SecretKeyGenerator', () => {
57
58
  beforeEach(async () => {
58
59
  return new Promise(resolve => {
@@ -65,21 +66,22 @@ describe('SecretKeyGenerator', () => {
65
66
  });
66
67
  });
67
68
  it('generates and store a secret key stored in indexeddb', async () => {
68
- const { key: secretKey } = await (0, secretKeyGenerator_1.generateSecretKey)({ dbName });
69
+ const { key: secretKey } = await (0, secretKeyGenerator_1.generateSecretKey)({ dbName, keyId });
69
70
  expect(secretKey).toBeDefined();
70
- const { key: secretKey2 } = await (0, secretKeyGenerator_1.generateSecretKey)({ dbName });
71
+ const { key: secretKey2 } = await (0, secretKeyGenerator_1.generateSecretKey)({ dbName, keyId });
71
72
  expect(secretKey).toEqual(secretKey2);
72
73
  });
73
74
  it.each(Object.entries(systemCryptos))('generates and store a secret key encrypted using system crypto (%s)', async (_name, systemCrypto) => {
74
75
  const { key } = await (0, secretKeyGenerator_1.generateSecretKey)({
75
76
  dbName,
76
77
  systemCrypto,
78
+ keyId,
77
79
  });
78
80
  expect(key).toBeDefined();
79
81
  expect(systemCrypto.encrypt).toHaveBeenCalled();
80
82
  expect(systemCrypto.decrypt).not.toHaveBeenCalled();
81
83
  // fetch stored key
82
- const { key: key2 } = await (0, secretKeyGenerator_1.generateSecretKey)({ dbName, systemCrypto: systemCrypto });
84
+ const { key: key2 } = await (0, secretKeyGenerator_1.generateSecretKey)({ dbName, systemCrypto: systemCrypto, keyId });
83
85
  expect(key2).toEqual(key);
84
86
  expect(systemCrypto.encrypt).toHaveBeenCalledTimes(1);
85
87
  expect(systemCrypto.decrypt).toHaveBeenCalledTimes(1);
@@ -91,28 +93,30 @@ describe('SecretKeyGenerator', () => {
91
93
  const { key } = await (0, secretKeyGenerator_1.generateSecretKey)({
92
94
  dbName,
93
95
  systemCrypto: crypto1,
96
+ keyId,
94
97
  });
95
98
  expect(key).toBeDefined();
96
99
  try {
97
- await (0, secretKeyGenerator_1.generateSecretKey)({ dbName, systemCrypto: crypto2 });
100
+ await (0, secretKeyGenerator_1.generateSecretKey)({ dbName, systemCrypto: crypto2, keyId });
98
101
  }
99
102
  catch (e) {
100
103
  expect(e).toBeInstanceOf(secretKeyGenerator_1.CorruptedKeyError);
101
104
  }
102
105
  });
103
106
  it('deletes the key from DB', async () => {
104
- const { key, deleteKey } = await (0, secretKeyGenerator_1.generateSecretKey)({ dbName });
107
+ const { key, deleteKey } = await (0, secretKeyGenerator_1.generateSecretKey)({ dbName, keyId });
105
108
  await deleteKey();
106
- const { key: secondKey } = await (0, secretKeyGenerator_1.generateSecretKey)({ dbName: 'test' });
109
+ const { key: secondKey } = await (0, secretKeyGenerator_1.generateSecretKey)({ dbName: 'test', keyId });
107
110
  expect(key).not.toEqual(secondKey);
108
111
  });
109
112
  it.each([['v01 > v1', systemCryptos.v01, systemCryptos.v1]])('is able to read a key that was generated with a previous system crypto (%s)', async (_name, crypto1, crypto2) => {
110
113
  const { key } = await (0, secretKeyGenerator_1.generateSecretKey)({
111
114
  dbName: 'test',
112
115
  systemCrypto: crypto1,
116
+ keyId,
113
117
  });
114
118
  expect(key).toBeDefined();
115
- const { key: key2 } = await (0, secretKeyGenerator_1.generateSecretKey)({ dbName: 'test', systemCrypto: crypto2 });
119
+ const { key: key2 } = await (0, secretKeyGenerator_1.generateSecretKey)({ dbName: 'test', systemCrypto: crypto2, keyId });
116
120
  expect(key2).toEqual(key);
117
121
  });
118
122
  });
package/package.json CHANGED
@@ -61,6 +61,6 @@
61
61
  "test:coverage": "jest --coverage",
62
62
  "watch": "tsc --watch"
63
63
  },
64
- "version": "42.26.2",
65
- "gitHead": "cf8237c2b4839d1b6680b30b79af3c2d350f1ed1"
64
+ "version": "43.0.0",
65
+ "gitHead": "0b73bccdc133167226b7d00994d8153575cbe097"
66
66
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryptedStore.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/encryptedStore.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,QAAQ,EAAE,YAAY,EAAmB,MAAM,KAAK,CAAC;AAE7D,UAAU,uBAAuB;IAC/B,EAAE,EAAE,UAAU,GAAG,WAAW,CAAC;IAC7B,KAAK,EAAE,UAAU,GAAG,WAAW,CAAC;CACjC;AACD,UAAU,WAAW,CAAC,gBAAgB,CAAE,SAAQ,QAAQ;IACtD,GAAG,EAAE;QACH,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,SAAS,CAAC;KAClB,CAAC;IACF,OAAO,EAAE;QACP,GAAG,EAAE,MAAM,CAAC;QACZ,KAAK,EAAE,gBAAgB,CAAC;KACzB,CAAC;CACH;AAED,KAAK,SAAS,CAAC,gBAAgB,IAAI,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;AACtF,KAAK,SAAS,CAAC,gBAAgB,IAAI,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAEpF,KAAK,oBAAoB,CAAC,gBAAgB,IAAI;IAC5C,OAAO,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACrC,OAAO,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC;CACtC,CAAC;AAEF,qBAAa,cAAc,CAAC,gBAAgB;;IAIxC,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,YAAY,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC,EAChE,EAAC,OAAO,EAAE,OAAO,EAAC,EAAE,oBAAoB,CAAC,gBAAgB,CAAC;IAMtD,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU;IAKrD,cAAc,CAAC,UAAU,EAAE,MAAM;IAQjC,KAAK;IAIL,IAAI;CAIX;AAuBD;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,uBAAuB,CAAC,CAAC,CAkB3G;AAED;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAAC,gBAAgB,EAC/D,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,GAC7C,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,CAQ3C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryptedStore.test.node.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/encryptedStore.test.node.ts"],"names":[],"mappings":""}
@@ -1,13 +0,0 @@
1
- import { SecretCrypto } from '../../../../mls/types';
2
- export declare class CorruptedKeyError extends Error {
3
- }
4
- type GeneratedKey = {
5
- key: Uint8Array;
6
- deleteKey: () => Promise<void>;
7
- };
8
- export declare function generateSecretKey({ dbName, systemCrypto: baseCrypto, }: {
9
- dbName: string;
10
- systemCrypto?: SecretCrypto;
11
- }): Promise<GeneratedKey>;
12
- export {};
13
- //# sourceMappingURL=secretKeyGenerator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"secretKeyGenerator.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/secretKeyGenerator.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAKnD,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;AAE/C,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,UAAU,CAAC;IAChB,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,EACtC,MAAM,EACN,YAAY,EAAE,UAAU,GACzB,EAAE;IACD,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,GAAG,OAAO,CAAC,YAAY,CAAC,CAwDxB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"secretKeyGenerator.test.d.ts","sourceRoot":"","sources":["../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/secretKeyGenerator.test.ts"],"names":[],"mappings":""}
@@ -1,22 +0,0 @@
1
- import { PreKey } from '@wireapp/api-client/lib/auth';
2
- import type { CRUDEngine } from '@wireapp/store-engine';
3
- import type { CoreCryptoWrapper } from './CoreCryptoWrapper/CoreCryptoWrapper';
4
- import type { CryptoboxWrapper } from './CryptoboxWrapper';
5
- import { SecretCrypto } from '../../../mls/types';
6
- export declare enum CryptoClientType {
7
- CORE_CRYPTO = 0,
8
- CRYPTOBOX = 1
9
- }
10
- export type CryptoClientDef = [CryptoClientType.CRYPTOBOX, CryptoboxWrapper] | [CryptoClientType.CORE_CRYPTO, CoreCryptoWrapper];
11
- type WrapConfig = {
12
- nbPrekeys: number;
13
- onNewPrekeys: (prekeys: PreKey[]) => void;
14
- };
15
- type InitConfig = WrapConfig & {
16
- storeEngine: CRUDEngine;
17
- systemCrypto?: SecretCrypto;
18
- coreCryptoWasmFilePath?: string;
19
- };
20
- export declare function buildCryptoClient(clientType: CryptoClientType, { storeEngine, nbPrekeys, systemCrypto, coreCryptoWasmFilePath, onNewPrekeys }: InitConfig): Promise<CryptoClientDef>;
21
- export {};
22
- //# sourceMappingURL=CryptoClient.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CryptoClient.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AAEpD,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEtD,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,uCAAuC,CAAC;AAC7E,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAEhD,oBAAY,gBAAgB;IAC1B,WAAW,IAAA;IACX,SAAS,IAAA;CACV;AAED,MAAM,MAAM,eAAe,GACvB,CAAC,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,CAAC,GAC9C,CAAC,gBAAgB,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;AAEtD,KAAK,UAAU,GAAG;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEF,KAAK,UAAU,GAAG,UAAU,GAAG;IAC7B,WAAW,EAAE,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC,CAAC;AAEF,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,gBAAgB,EAC5B,EAAC,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,sBAAsB,EAAE,YAAY,EAAC,EAAE,UAAU,GACvF,OAAO,CAAC,eAAe,CAAC,CAc1B"}
@@ -1,64 +0,0 @@
1
- "use strict";
2
- /*
3
- * Wire
4
- * Copyright (C) 2023 Wire Swiss GmbH
5
- *
6
- * This program is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see http://www.gnu.org/licenses/.
18
- *
19
- */
20
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- var desc = Object.getOwnPropertyDescriptor(m, k);
23
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
- desc = { enumerable: true, get: function() { return m[k]; } };
25
- }
26
- Object.defineProperty(o, k2, desc);
27
- }) : (function(o, m, k, k2) {
28
- if (k2 === undefined) k2 = k;
29
- o[k2] = m[k];
30
- }));
31
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
32
- Object.defineProperty(o, "default", { enumerable: true, value: v });
33
- }) : function(o, v) {
34
- o["default"] = v;
35
- });
36
- var __importStar = (this && this.__importStar) || function (mod) {
37
- if (mod && mod.__esModule) return mod;
38
- var result = {};
39
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
40
- __setModuleDefault(result, mod);
41
- return result;
42
- };
43
- Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.buildCryptoClient = exports.CryptoClientType = void 0;
45
- var CryptoClientType;
46
- (function (CryptoClientType) {
47
- CryptoClientType[CryptoClientType["CORE_CRYPTO"] = 0] = "CORE_CRYPTO";
48
- CryptoClientType[CryptoClientType["CRYPTOBOX"] = 1] = "CRYPTOBOX";
49
- })(CryptoClientType || (exports.CryptoClientType = CryptoClientType = {}));
50
- async function buildCryptoClient(clientType, { storeEngine, nbPrekeys, systemCrypto, coreCryptoWasmFilePath, onNewPrekeys }) {
51
- if (clientType === CryptoClientType.CORE_CRYPTO) {
52
- const { buildClient } = await Promise.resolve().then(() => __importStar(require('./CoreCryptoWrapper')));
53
- const client = await buildClient(storeEngine, coreCryptoWasmFilePath !== null && coreCryptoWasmFilePath !== void 0 ? coreCryptoWasmFilePath : '', {
54
- systemCrypto,
55
- nbPrekeys,
56
- onNewPrekeys,
57
- });
58
- return [CryptoClientType.CORE_CRYPTO, client];
59
- }
60
- const { buildClient } = await Promise.resolve().then(() => __importStar(require('./CryptoboxWrapper')));
61
- const client = await buildClient(storeEngine, { nbPrekeys, onNewPrekeys });
62
- return [CryptoClientType.CRYPTOBOX, client];
63
- }
64
- exports.buildCryptoClient = buildCryptoClient;