@wireapp/core 46.24.1 → 46.24.2

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 (48) hide show
  1. package/lib/Account.d.ts +8 -7
  2. package/lib/Account.d.ts.map +1 -1
  3. package/lib/Account.js +23 -21
  4. package/lib/client/ClientService.js +1 -1
  5. package/lib/conversation/ConversationService/ConversationService.d.ts +8 -12
  6. package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
  7. package/lib/conversation/ConversationService/ConversationService.js +13 -11
  8. package/lib/conversation/ConversationService/ConversationService.test.js +11 -5
  9. package/lib/messagingProtocols/common.types.d.ts +0 -9
  10. package/lib/messagingProtocols/common.types.d.ts.map +1 -1
  11. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIService.types.d.ts +2 -2
  12. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIService.types.d.ts.map +1 -1
  13. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIService.types.js +1 -2
  14. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.d.ts.map +1 -1
  15. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.js +5 -6
  16. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.test.js +15 -20
  17. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.d.ts +3 -9
  18. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.d.ts.map +1 -1
  19. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.js +12 -30
  20. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.d.ts.map +1 -1
  21. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.js +2 -7
  22. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.test.js +34 -0
  23. package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.test.js +2 -2
  24. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts +31 -16
  25. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts.map +1 -1
  26. package/lib/messagingProtocols/mls/MLSService/MLSService.js +171 -74
  27. package/lib/messagingProtocols/mls/MLSService/MLSService.test.js +151 -93
  28. package/lib/messagingProtocols/mls/types.d.ts +8 -0
  29. package/lib/messagingProtocols/mls/types.d.ts.map +1 -1
  30. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts +13 -4
  31. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts.map +1 -1
  32. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.js +62 -79
  33. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts +2 -0
  34. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts.map +1 -1
  35. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts +3 -5
  36. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts.map +1 -1
  37. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.js +14 -14
  38. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts.map +1 -1
  39. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.js +1 -3
  40. package/lib/messagingProtocols/proteus/ProteusService/WithMockedGenerics.test.js +0 -3
  41. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.test.js +0 -3
  42. package/lib/secretStore/secretKeyGenerator.d.ts +0 -1
  43. package/lib/secretStore/secretKeyGenerator.d.ts.map +1 -1
  44. package/lib/secretStore/secretKeyGenerator.js +1 -3
  45. package/package.json +5 -5
  46. package/lib/test/StoreHelper.d.ts +0 -2
  47. package/lib/test/StoreHelper.d.ts.map +0 -1
  48. package/lib/test/StoreHelper.js +0 -27
@@ -40,100 +40,57 @@ const coreCryptoLogger = {
40
40
  logFunctions[level].call(logger, { message, context });
41
41
  },
42
42
  };
43
- const getKey = async (generateSecretKey, keyName, keySize) => {
44
- return await generateSecretKey(keyName, keySize);
45
- };
46
- const migrateOnceAndGetKey = async (generateSecretKey, coreCryptoDbName) => {
47
- const coreCryptoNewKeyId = 'corecrypto-key-v2';
43
+ async function buildClient(storeEngine, { wasmFilePath, generateSecretKey, nbPrekeys, onNewPrekeys }) {
44
+ let key;
45
+ const coreCryptoDbName = `corecrypto-${storeEngine.storeName}`;
48
46
  const coreCryptoKeyId = 'corecrypto-key';
49
- // We retrieve the old key if it exists or generate a new one
50
- const keyOld = await getKey(generateSecretKey, coreCryptoKeyId, 16);
51
- // We retrieve the new key if it exists or generate a new one
52
- const keyNew = await getKey(generateSecretKey, coreCryptoNewKeyId, 32);
53
- // If we dont retreive any key, we throw an error
54
- // This should not happen since we generate a new key if it does not exist
55
- if (!keyNew || !keyOld) {
56
- throw new Error('Key not found and could not be generated');
57
- }
58
- /**
59
- * If the old key is freshly generated we dont need to migrate and return the new key
60
- * If the old key exists and the new key is freshly generated, we need to migrate and then return the new key (This should only happen once !!!!)
61
- * If the old key exists and the new key exists we return the new key
62
- */
63
- if (!keyOld.freshlyGenerated && keyNew.freshlyGenerated) {
64
- // Create the new key in the format used by coreCrypto
65
- const databaseKey = new core_crypto_1.DatabaseKey(keyNew.key);
66
- // Run the migration
67
- await (0, core_crypto_1.migrateDatabaseKeyTypeToBytes)(coreCryptoDbName, bazinga64_1.Encoder.toBase64(keyOld.key).asString, databaseKey);
68
- // delete the old key, it will be freshly generated in the next call and ensure we dont run the migration again
69
- await keyOld.deleteKey();
70
- }
71
- return {
72
- key: new core_crypto_1.DatabaseKey(keyNew.key),
73
- deleteKey: keyNew.deleteKey,
74
- };
75
- };
76
- async function buildClient(storeEngine, { generateSecretKey, nbPrekeys, onNewPrekeys }, { wasmFilePath }) {
77
- return (
78
- // We need to initialize the coreCrypto package with the path to the wasm file
79
- // before we can use it. This is a one time operation and should be done
80
- // before we create the CoreCrypto instance.
81
- (0, core_crypto_1.initWasmModule)(wasmFilePath)
82
- .then(async (output) => {
83
- logger.log('info', 'CoreCrypto initialized', { output });
84
- const coreCryptoDbName = `corecrypto-${storeEngine.storeName}`;
85
- // New key format used by coreCrypto
86
- let key;
87
- try {
88
- key = await migrateOnceAndGetKey(generateSecretKey, coreCryptoDbName);
47
+ try {
48
+ key = await generateSecretKey(coreCryptoKeyId);
49
+ }
50
+ catch (error) {
51
+ if (error instanceof secretKeyGenerator_1.CorruptedKeyError) {
52
+ // If we are dealing with a corrupted key, we wipe the key and the coreCrypto DB to start fresh
53
+ await (0, idb_1.deleteDB)(coreCryptoDbName);
54
+ key = await generateSecretKey(coreCryptoKeyId);
89
55
  }
90
- catch (error) {
91
- if (error instanceof secretKeyGenerator_1.CorruptedKeyError) {
92
- // If we are dealing with a corrupted key, we wipe the key and the coreCrypto DB to start fresh
93
- await (0, idb_1.deleteDB)(coreCryptoDbName);
94
- key = await migrateOnceAndGetKey(generateSecretKey, coreCryptoDbName);
95
- }
96
- else {
97
- throw error;
98
- }
56
+ else {
57
+ throw error;
99
58
  }
100
- const coreCrypto = await core_crypto_1.CoreCrypto.deferredInit({
101
- databaseName: coreCryptoDbName,
102
- key: key.key,
103
- });
104
- (0, core_crypto_1.setLogger)(coreCryptoLogger);
105
- (0, core_crypto_1.setMaxLogLevel)(core_crypto_1.CoreCryptoLogLevel.Info);
106
- return new CoreCryptoWrapper(coreCrypto, { nbPrekeys, onNewPrekeys, onWipe: key.deleteKey });
107
- })
108
- // if the coreCrypto initialization fails, can not use the crypto client and throw an error
109
- .catch(error => {
110
- logger.error('error', 'CoreCrypto initialization failed', { error });
111
- throw error;
112
- }));
59
+ }
60
+ const coreCrypto = await core_crypto_1.CoreCrypto.deferredInit({
61
+ databaseName: coreCryptoDbName,
62
+ key: bazinga64_1.Encoder.toBase64(key.key).asString,
63
+ wasmFilePath,
64
+ });
65
+ (0, core_crypto_1.setLogger)(coreCryptoLogger);
66
+ (0, core_crypto_1.setMaxLogLevel)(core_crypto_1.CoreCryptoLogLevel.Info);
67
+ return new CoreCryptoWrapper(coreCrypto, { nbPrekeys, onNewPrekeys, onWipe: key.deleteKey });
113
68
  }
114
69
  class CoreCryptoWrapper {
115
70
  coreCrypto;
71
+ config;
116
72
  prekeyTracker;
117
73
  version;
118
74
  constructor(coreCrypto, config) {
119
75
  this.coreCrypto = coreCrypto;
120
- this.version = (0, core_crypto_1.version)();
76
+ this.config = config;
77
+ this.version = core_crypto_1.CoreCrypto.version();
121
78
  this.prekeyTracker = new PrekeysTracker_1.PrekeyTracker(this, config);
122
79
  }
123
80
  getNativeClient() {
124
81
  return this.coreCrypto;
125
82
  }
126
83
  encrypt(sessions, plainText) {
127
- return this.coreCrypto.transaction(cx => cx.proteusEncryptBatched(sessions, plainText));
84
+ return this.coreCrypto.proteusEncryptBatched(sessions, plainText);
128
85
  }
129
86
  decrypt(sessionId, message) {
130
- return this.coreCrypto.transaction(cx => cx.proteusDecrypt(sessionId, message));
87
+ return this.coreCrypto.proteusDecrypt(sessionId, message);
131
88
  }
132
89
  init(nbInitialPrekeys) {
133
90
  if (nbInitialPrekeys) {
134
91
  this.prekeyTracker.setInitialState(nbInitialPrekeys);
135
92
  }
136
- return this.coreCrypto.transaction(cx => cx.proteusInit());
93
+ return this.coreCrypto.proteusInit();
137
94
  }
138
95
  async create(nbPrekeys, entropy) {
139
96
  if (entropy) {
@@ -144,7 +101,7 @@ class CoreCryptoWrapper {
144
101
  for (let id = 0; id < nbPrekeys; id++) {
145
102
  prekeys.push(await this.newPrekey());
146
103
  }
147
- const lastPrekeyBytes = await this.coreCrypto.transaction(cx => cx.proteusLastResortPrekey());
104
+ const lastPrekeyBytes = await this.coreCrypto.proteusLastResortPrekey();
148
105
  const lastPrekey = bazinga64_1.Encoder.toBase64(lastPrekeyBytes).asString;
149
106
  const lastPrekeyId = core_crypto_1.CoreCrypto.proteusLastResortPrekeyId();
150
107
  return {
@@ -160,25 +117,25 @@ class CoreCryptoWrapper {
160
117
  }
161
118
  async sessionFromMessage(sessionId, message) {
162
119
  await this.consumePrekey(); // we need to mark a prekey as consumed since if we create a session from a message, it means the sender has consumed one of our prekeys
163
- return this.coreCrypto.transaction(cx => cx.proteusSessionFromMessage(sessionId, message));
120
+ return this.coreCrypto.proteusSessionFromMessage(sessionId, message);
164
121
  }
165
122
  sessionFromPrekey(sessionId, prekey) {
166
- return this.coreCrypto.transaction(cx => cx.proteusSessionFromPrekey(sessionId, prekey));
123
+ return this.coreCrypto.proteusSessionFromPrekey(sessionId, prekey);
167
124
  }
168
125
  sessionExists(sessionId) {
169
126
  return this.coreCrypto.proteusSessionExists(sessionId);
170
127
  }
171
128
  saveSession(sessionId) {
172
- return this.coreCrypto.transaction(cx => cx.proteusSessionSave(sessionId));
129
+ return this.coreCrypto.proteusSessionSave(sessionId);
173
130
  }
174
131
  deleteSession(sessionId) {
175
- return this.coreCrypto.transaction(cx => cx.proteusSessionDelete(sessionId));
132
+ return this.coreCrypto.proteusSessionDelete(sessionId);
176
133
  }
177
134
  consumePrekey() {
178
135
  return this.prekeyTracker.consumePrekey();
179
136
  }
180
137
  async newPrekey() {
181
- const { id, pkb } = await this.coreCrypto.transaction(cx => cx.proteusNewPrekeyAuto());
138
+ const { id, pkb } = await this.coreCrypto.proteusNewPrekeyAuto();
182
139
  return { id, key: bazinga64_1.Encoder.toBase64(pkb).asString };
183
140
  }
184
141
  async debugBreakSession(sessionId) {
@@ -188,10 +145,36 @@ class CoreCryptoWrapper {
188
145
  200, 16, 166, 184, 70, 21, 81, 43, 80, 21, 231, 182, 142, 51, 220, 131, 162, 11, 255, 162, 74, 78, 162, 95, 156,
189
146
  131, 48, 203, 5, 77, 122, 4, 246,
190
147
  ];
191
- await this.coreCrypto.transaction(cx => cx.proteusSessionFromPrekey(sessionId, Uint8Array.from(fakePrekey)));
148
+ await this.coreCrypto.proteusSessionFromPrekey(sessionId, Uint8Array.from(fakePrekey));
149
+ }
150
+ async debugResetIdentity() {
151
+ await this.coreCrypto.wipe();
192
152
  }
193
153
  async migrateFromCryptobox(dbName) {
194
- return this.coreCrypto.transaction(cx => cx.proteusCryptoboxMigrate(dbName));
154
+ return this.coreCrypto.proteusCryptoboxMigrate(dbName);
155
+ }
156
+ /**
157
+ * Will call the callback once corecrypto is ready.
158
+ * @param callback - Function to be called once corecrypto is ready.
159
+ * @see https://github.com/wireapp/wire-web-packages/pull/4972
160
+ */
161
+ onReady(callback) {
162
+ if (!this.coreCrypto.isLocked()) {
163
+ return callback();
164
+ }
165
+ return new Promise(resolve => {
166
+ const intervalId = setInterval(async () => {
167
+ if (!this.coreCrypto.isLocked()) {
168
+ clearInterval(intervalId);
169
+ await callback();
170
+ return resolve();
171
+ }
172
+ }, 100);
173
+ });
174
+ }
175
+ async wipe() {
176
+ await this.config.onWipe();
177
+ await this.onReady(() => this.coreCrypto.wipe());
195
178
  }
196
179
  }
197
180
  exports.CoreCryptoWrapper = CoreCryptoWrapper;
@@ -30,9 +30,11 @@ export interface CryptoClient<T = unknown> {
30
30
  deleteSession(sessionId: string): Promise<void>;
31
31
  newPrekey(): Promise<PreKey>;
32
32
  debugBreakSession(sessionId: string): void;
33
+ debugResetIdentity(): Promise<void>;
33
34
  /**
34
35
  * Will migrate the database from a different client type
35
36
  */
36
37
  migrateFromCryptobox?(dbName: string): Promise<void>;
38
+ wipe(): Promise<void>;
37
39
  }
38
40
  //# sourceMappingURL=CryptoClient.types.d.ts.map
@@ -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,oBAAY,gBAA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C;IAC7B,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C;;OAEG;IACH,oBAAoB,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtD"}
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,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,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"}
@@ -20,13 +20,11 @@ export declare class ProteusService {
20
20
  private readonly apiClient;
21
21
  private readonly cryptoClient;
22
22
  private readonly config;
23
- private readonly storeEngine;
24
23
  private readonly messageService;
25
24
  private readonly logger;
26
- private readonly dbName;
27
- constructor(apiClient: APIClient, cryptoClient: CryptoClient, config: ProteusServiceConfig, storeEngine: CRUDEngine);
25
+ constructor(apiClient: APIClient, cryptoClient: CryptoClient, config: ProteusServiceConfig);
28
26
  handleOtrMessageAddEvent(event: ConversationOtrMessageAddEvent): Promise<HandledEventPayload>;
29
- initClient(context: Context): Promise<void>;
27
+ initClient(storeEngine: CRUDEngine, context: Context): Promise<void>;
30
28
  createClient(entropy?: Uint8Array): Promise<import("./CryptoClient").InitialPrekeys>;
31
29
  /**
32
30
  * Get the fingerprint of the local client.
@@ -52,6 +50,6 @@ export declare class ProteusService {
52
50
  consumePrekey(): Promise<void>;
53
51
  deleteSession(userId: QualifiedId, clientId: string): Promise<void>;
54
52
  encrypt(plainText: Uint8Array, recipients: QualifiedUserPreKeyBundleMap | QualifiedUserClients): Promise<EncryptionResult>;
55
- wipe(): Promise<void>;
53
+ wipe(storeEngine?: CRUDEngine): Promise<void>;
56
54
  }
57
55
  //# sourceMappingURL=ProteusService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ProteusService.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAGL,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAC,8BAA8B,EAAC,MAAM,+BAA+B,CAAC;AAClF,OAAO,KAAK,EAAC,WAAW,EAAE,4BAA4B,EAAC,MAAM,8BAA8B,CAAC;AAG5F,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAI5C,OAAO,KAAK,EACV,mCAAmC,EACnC,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EAEL,iCAAiC,EAEjC,UAAU,EACV,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAY1D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,wEAAwE;IACxE,QAAQ,EAAE,sBAAsB,CAAC;IACjC,wEAAwE;IACxE,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,sGAAsG;IACtG,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;CAC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AAC,IAAI,CAAC;IAI9B,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM;IAQ7C,OAAO,CAClB,SAAS,EAAE,UAAU,EACrB,UAAU,EAAE,4BAA4B,GAAG,oBAAoB,GAC9D,OAAO,CAAC,gBAAgB,CAAC;IAiBtB,IAAI;CAGX"}
1
+ {"version":3,"file":"ProteusService.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAGL,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAC,8BAA8B,EAAC,MAAM,+BAA+B,CAAC;AAClF,OAAO,KAAK,EAAC,WAAW,EAAE,4BAA4B,EAAC,MAAM,8BAA8B,CAAC;AAG5F,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAI5C,OAAO,KAAK,EACV,mCAAmC,EACnC,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EAEL,iCAAiC,EAEjC,UAAU,EACV,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAY1D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,wEAAwE;IACxE,QAAQ,EAAE,sBAAsB,CAAC;IACjC,wEAAwE;IACxE,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,sGAAsG;IACtG,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC;AAEF,qBAAa,cAAc;IAKvB,OAAO,CAAC,QAAQ,CAA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B,GAAG,oBAAoB,GAC9D,OAAO,CAAC,gBAAgB,CAAC;IAiBtB,IAAI,CAAC,WAAW,CAAC,EAAE,UAAU;CAMpC"}
@@ -37,17 +37,13 @@ class ProteusService {
37
37
  apiClient;
38
38
  cryptoClient;
39
39
  config;
40
- storeEngine;
41
40
  messageService;
42
41
  logger = commons_1.LogFactory.getLogger('@wireapp/core/ProteusService');
43
- dbName;
44
- constructor(apiClient, cryptoClient, config, storeEngine) {
42
+ constructor(apiClient, cryptoClient, config) {
45
43
  this.apiClient = apiClient;
46
44
  this.cryptoClient = cryptoClient;
47
45
  this.config = config;
48
- this.storeEngine = storeEngine;
49
46
  this.messageService = new MessageService_1.MessageService(this.apiClient, this);
50
- this.dbName = storeEngine.storeName;
51
47
  }
52
48
  async handleOtrMessageAddEvent(event) {
53
49
  return (0, events_1.handleOtrMessageAdd)({
@@ -55,22 +51,23 @@ class ProteusService {
55
51
  proteusService: this,
56
52
  });
57
53
  }
58
- async initClient(context) {
54
+ async initClient(storeEngine, context) {
55
+ const dbName = storeEngine.storeName;
59
56
  if (context.domain) {
60
57
  // We want sessions to be fully qualified from now on
61
- if (!cryptoMigrationStateStore_1.cryptoMigrationStore.qualifiedSessions.isReady(this.dbName)) {
58
+ if (!cryptoMigrationStateStore_1.cryptoMigrationStore.qualifiedSessions.isReady(dbName)) {
62
59
  this.logger.info(`Migrating existing session ids to qualified ids.`);
63
- await (0, sessionIdMigrator_1.migrateToQualifiedSessionIds)(this.storeEngine, context.domain);
64
- cryptoMigrationStateStore_1.cryptoMigrationStore.qualifiedSessions.markAsReady(this.dbName);
60
+ await (0, sessionIdMigrator_1.migrateToQualifiedSessionIds)(storeEngine, context.domain);
61
+ cryptoMigrationStateStore_1.cryptoMigrationStore.qualifiedSessions.markAsReady(dbName);
65
62
  this.logger.info(`Successfully migrated session ids to qualified ids.`);
66
63
  }
67
64
  }
68
- if (!cryptoMigrationStateStore_1.cryptoMigrationStore.coreCrypto.isReady(this.dbName) && this.cryptoClient.migrateFromCryptobox) {
65
+ if (!cryptoMigrationStateStore_1.cryptoMigrationStore.coreCrypto.isReady(dbName) && this.cryptoClient.migrateFromCryptobox) {
69
66
  this.logger.info(`Migrating from cryptobox to corecrypto.`);
70
67
  try {
71
68
  const startTime = Date.now();
72
- await this.cryptoClient.migrateFromCryptobox(this.dbName);
73
- cryptoMigrationStateStore_1.cryptoMigrationStore.coreCrypto.markAsReady(this.dbName);
69
+ await this.cryptoClient.migrateFromCryptobox(dbName);
70
+ cryptoMigrationStateStore_1.cryptoMigrationStore.coreCrypto.markAsReady(dbName);
74
71
  this.logger.info(`Successfully migrated from cryptobox to corecrypto (took ${Date.now() - startTime}ms).`);
75
72
  }
76
73
  catch (error) {
@@ -274,8 +271,11 @@ class ProteusService {
274
271
  failed,
275
272
  };
276
273
  }
277
- async wipe() {
278
- await (0, identityClearer_1.deleteIdentity)(this.storeEngine);
274
+ async wipe(storeEngine) {
275
+ if (storeEngine) {
276
+ await (0, identityClearer_1.deleteIdentity)(storeEngine);
277
+ }
278
+ return this.cryptoClient.wipe();
279
279
  }
280
280
  }
281
281
  exports.ProteusService = ProteusService;
@@ -1 +1 @@
1
- {"version":3,"file":"ProteusService.mocks.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.mocks.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAKhD,eAAO,MAAM,mBAAmB,QAAa,OAAO,CAClD,CAAC,cAAc,EAAE;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,YAAY,CAAA;CAAC,CAAC,CAwBrE,CAAC"}
1
+ {"version":3,"file":"ProteusService.mocks.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.mocks.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAIhD,eAAO,MAAM,mBAAmB,QAAa,OAAO,CAClD,CAAC,cAAc,EAAE;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,YAAY,CAAA;CAAC,CAAC,CAgBrE,CAAC"}
@@ -24,7 +24,6 @@ const api_client_1 = require("@wireapp/api-client");
24
24
  const CoreCryptoWrapper_1 = require("./CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper");
25
25
  const ProteusService_1 = require("./ProteusService");
26
26
  const PayloadHelper_1 = require("../../../test/PayloadHelper");
27
- const StoreHelper_1 = require("../../../test/StoreHelper");
28
27
  const buildProteusService = async () => {
29
28
  const apiClient = new api_client_1.APIClient({ urls: api_client_1.APIClient.BACKEND.STAGING });
30
29
  apiClient.context = {
@@ -33,10 +32,9 @@ const buildProteusService = async () => {
33
32
  clientId: (0, PayloadHelper_1.getUUID)(),
34
33
  };
35
34
  const cryptoClient = new CoreCryptoWrapper_1.CoreCryptoWrapper({}, {});
36
- const storeEngine = await (0, StoreHelper_1.createMemoryEngine)('proteus-service-test');
37
35
  const proteusService = new ProteusService_1.ProteusService(apiClient, cryptoClient, {
38
36
  nbPrekeys: 0,
39
- }, storeEngine);
37
+ });
40
38
  return [proteusService, { apiClient, cryptoClient }];
41
39
  };
42
40
  exports.buildProteusService = buildProteusService;
@@ -72,9 +72,6 @@ const prepareProteusService = async () => {
72
72
  .mockImplementation(data => Promise.resolve(data));
73
73
  return proteusService;
74
74
  };
75
- afterAll(() => {
76
- jest.clearAllTimers();
77
- });
78
75
  describe('sendGenericMessage', () => {
79
76
  describe('targetted messages', () => {
80
77
  it(`indicates when sending was canceled`, async () => {
@@ -59,9 +59,6 @@ describe('SessionHandler', () => {
59
59
  beforeAll(() => {
60
60
  jest.spyOn(apiClient.api.user, 'postMultiPreKeyBundles').mockImplementation(generatePrekeys);
61
61
  });
62
- afterAll(() => {
63
- jest.clearAllTimers();
64
- });
65
62
  describe('constructSessionId', () => {
66
63
  describe('constructs a session ID', () => {
67
64
  it('without a domain', () => {
@@ -4,7 +4,6 @@ export declare class CorruptedKeyError extends Error {
4
4
  export type GeneratedKey = {
5
5
  key: Uint8Array;
6
6
  deleteKey: () => Promise<void>;
7
- freshlyGenerated: boolean;
8
7
  };
9
8
  /**
10
9
  * Will generate (or retrieve) a secret key from the database.
@@ -1 +1 @@
1
- {"version":3,"file":"secretKeyGenerator.d.ts","sourceRoot":"","sources":["../../src/secretStore/secretKeyGenerator.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,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;IAC/B,gBAAgB,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,KAAK,EACL,OAAY,EACZ,SAAS,GACV,EAAE;IACD,wGAAwG;IACxG,KAAK,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,SAAS,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;CAChC,GAAG,OAAO,CAAC,YAAY,CAAC,CAgCxB"}
1
+ {"version":3,"file":"secretKeyGenerator.d.ts","sourceRoot":"","sources":["../../src/secretStore/secretKeyGenerator.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,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,SAAS,GACV,EAAE;IACD,wGAAwG;IACxG,KAAK,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sDAAsD;IACtD,SAAS,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;CAChC,GAAG,OAAO,CAAC,YAAY,CAAC,CA8BxB"}
@@ -27,7 +27,6 @@ exports.CorruptedKeyError = CorruptedKeyError;
27
27
  * Will generate (or retrieve) a secret key from the database.
28
28
  */
29
29
  async function generateSecretKey({ keyId, keySize = 16, secretsDb, }) {
30
- let freshlyGenerated = false;
31
30
  try {
32
31
  let key;
33
32
  try {
@@ -49,9 +48,8 @@ async function generateSecretKey({ keyId, keySize = 16, secretsDb, }) {
49
48
  }, true, ['encrypt', 'decrypt']);
50
49
  key = new Uint8Array(await crypto.subtle.exportKey('raw', key));
51
50
  await secretsDb.saveSecretValue(keyId, key);
52
- freshlyGenerated = true;
53
51
  }
54
- return { key, deleteKey: () => secretsDb.deleteSecretValue(keyId), freshlyGenerated };
52
+ return { key, deleteKey: () => secretsDb.deleteSecretValue(keyId) };
55
53
  }
56
54
  catch (error) {
57
55
  throw error;
package/package.json CHANGED
@@ -13,14 +13,14 @@
13
13
  "dependencies": {
14
14
  "@wireapp/api-client": "^27.57.0",
15
15
  "@wireapp/commons": "^5.4.2",
16
- "@wireapp/core-crypto": "7.0.1",
16
+ "@wireapp/core-crypto": "3.1.1",
17
17
  "@wireapp/cryptobox": "12.8.0",
18
18
  "@wireapp/priority-queue": "^2.1.11",
19
19
  "@wireapp/promise-queue": "^2.3.12",
20
20
  "@wireapp/protocol-messaging": "1.52.0",
21
- "@wireapp/store-engine": "^5.1.11",
21
+ "@wireapp/store-engine": "5.1.11",
22
22
  "axios": "1.7.9",
23
- "bazinga64": "^6.4.0",
23
+ "bazinga64": "^6.4.1",
24
24
  "deepmerge-ts": "6.0.0",
25
25
  "hash.js": "1.1.7",
26
26
  "http-status-codes": "2.3.0",
@@ -61,6 +61,6 @@
61
61
  "test:coverage": "jest --coverage",
62
62
  "watch": "tsc --watch"
63
63
  },
64
- "version": "46.24.1",
65
- "gitHead": "345051e009d4d297268c1f2648ea763a6250fe1e"
64
+ "version": "46.24.2",
65
+ "gitHead": "6b39b5fb13dedc1b923d12f00ddce7376fd935d1"
66
66
  }
@@ -1,2 +0,0 @@
1
- export declare function createMemoryEngine(storeName?: string): Promise<any>;
2
- //# sourceMappingURL=StoreHelper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StoreHelper.d.ts","sourceRoot":"","sources":["../../src/test/StoreHelper.ts"],"names":[],"mappings":"AAqBA,wBAAsB,kBAAkB,CAAC,SAAS,SAAuB,gBAIxE"}
@@ -1,27 +0,0 @@
1
- "use strict";
2
- /*
3
- * Wire
4
- * Copyright (C) 2022 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
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.createMemoryEngine = createMemoryEngine;
22
- const { MemoryEngine } = require('@wireapp/store-engine');
23
- async function createMemoryEngine(storeName = `temp-${Date.now()}`) {
24
- const engine = new MemoryEngine();
25
- await engine.init(storeName);
26
- return engine;
27
- }