@wireapp/core 40.5.3-draft-20-cc.3 → 40.5.3-draft-20-cc.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 (143) hide show
  1. package/lib/Account.d.ts +9 -7
  2. package/lib/Account.d.ts.map +1 -1
  3. package/lib/Account.js +32 -35
  4. package/lib/CoreError.js +1 -1
  5. package/lib/broadcast/BroadcastService.d.ts +2 -11
  6. package/lib/broadcast/BroadcastService.d.ts.map +1 -1
  7. package/lib/broadcast/BroadcastService.js +5 -39
  8. package/lib/client/ClientDatabaseRepository.d.ts +5 -5
  9. package/lib/client/ClientDatabaseRepository.d.ts.map +1 -1
  10. package/lib/client/ClientDatabaseRepository.js +10 -17
  11. package/lib/client/ClientService.d.ts +5 -1
  12. package/lib/client/ClientService.d.ts.map +1 -1
  13. package/lib/client/ClientService.js +11 -9
  14. package/lib/connection/ConnectionService.d.ts +2 -2
  15. package/lib/connection/ConnectionService.d.ts.map +1 -1
  16. package/lib/connection/ConnectionService.js +2 -2
  17. package/lib/conversation/AssetTransferState.js +1 -1
  18. package/lib/conversation/ConversationService/ConversationService.d.ts +12 -5
  19. package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
  20. package/lib/conversation/ConversationService/ConversationService.js +26 -11
  21. package/lib/conversation/ConversationService/ConversationService.test.js +1 -1
  22. package/lib/conversation/ConversationService/ConversationService.types.d.ts +12 -11
  23. package/lib/conversation/ConversationService/ConversationService.types.d.ts.map +1 -1
  24. package/lib/conversation/ConversationService/ConversationService.types.js +1 -1
  25. package/lib/conversation/ConversationService/Utility/getConversationQualifiedMembers.d.ts +1 -1
  26. package/lib/conversation/ConversationService/Utility/getConversationQualifiedMembers.d.ts.map +1 -1
  27. package/lib/conversation/GenericMessageType.js +1 -1
  28. package/lib/conversation/ReactionType.d.ts +1 -4
  29. package/lib/conversation/ReactionType.d.ts.map +1 -1
  30. package/lib/conversation/ReactionType.js +0 -6
  31. package/lib/conversation/message/Message.types.js +1 -1
  32. package/lib/conversation/message/MessageBuilder.d.ts +1 -1
  33. package/lib/conversation/message/MessageBuilder.d.ts.map +1 -1
  34. package/lib/conversation/message/MessageBuilder.js +2 -2
  35. package/lib/conversation/message/MessageService.d.ts +6 -31
  36. package/lib/conversation/message/MessageService.d.ts.map +1 -1
  37. package/lib/conversation/message/MessageService.js +19 -162
  38. package/lib/conversation/message/MessageService.test.js +151 -141
  39. package/lib/conversation/message/PayloadBundle.js +1 -1
  40. package/lib/conversation/message/UserClientsUtil.d.ts +14 -10
  41. package/lib/conversation/message/UserClientsUtil.d.ts.map +1 -1
  42. package/lib/conversation/message/UserClientsUtil.js +21 -11
  43. package/lib/conversation/message/UserClientsUtils.test.js +5 -9
  44. package/lib/messagingProtocols/mls/EventHandler/EventHandler.d.ts +1 -1
  45. package/lib/messagingProtocols/mls/EventHandler/EventHandler.d.ts.map +1 -1
  46. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.d.ts +1 -1
  47. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.d.ts.map +1 -1
  48. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.js +7 -2
  49. package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.d.ts.map +1 -1
  50. package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.js +2 -0
  51. package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.test.js +3 -1
  52. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts +20 -8
  53. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts.map +1 -1
  54. package/lib/messagingProtocols/mls/MLSService/MLSService.js +81 -40
  55. package/lib/messagingProtocols/mls/MLSService/MLSService.test.js +9 -0
  56. package/lib/messagingProtocols/mls/MLSService/commitBundleUtil.d.ts +1 -1
  57. package/lib/messagingProtocols/mls/MLSService/commitBundleUtil.d.ts.map +1 -1
  58. package/lib/messagingProtocols/mls/MLSService/commitBundleUtil.js +5 -5
  59. package/lib/messagingProtocols/mls/MLSService/commitBundleUtil.test.js +3 -3
  60. package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.d.ts +13 -0
  61. package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.d.ts.map +1 -0
  62. package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.js +67 -0
  63. package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.test.d.ts +2 -0
  64. package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.test.d.ts.map +1 -0
  65. package/lib/messagingProtocols/mls/MLSService/stores/subconversationGroupIdStore/subconversationGroupIdStore.test.js +72 -0
  66. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts +10 -5
  67. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.d.ts.map +1 -1
  68. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.js +33 -11
  69. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.d.ts +2 -3
  70. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.d.ts.map +1 -1
  71. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.js +8 -9
  72. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.d.ts +4 -9
  73. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.d.ts.map +1 -1
  74. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.js +10 -24
  75. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.test.js +2 -10
  76. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.d.ts +1 -2
  77. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.d.ts.map +1 -1
  78. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.js +3 -3
  79. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts +2 -2
  80. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoClient.types.d.ts.map +1 -1
  81. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.d.ts +1 -1
  82. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.d.ts.map +1 -1
  83. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.js +2 -2
  84. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts +14 -7
  85. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts.map +1 -1
  86. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.js +31 -35
  87. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts +1 -1
  88. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts.map +1 -1
  89. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.js +2 -3
  90. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.test.js +109 -89
  91. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.types.d.ts +6 -9
  92. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.types.d.ts.map +1 -1
  93. package/lib/messagingProtocols/proteus/Utility/Recipients.d.ts +4 -10
  94. package/lib/messagingProtocols/proteus/Utility/Recipients.d.ts.map +1 -1
  95. package/lib/messagingProtocols/proteus/Utility/Recipients.js +16 -16
  96. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts +15 -10
  97. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts.map +1 -1
  98. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.js +80 -92
  99. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.test.js +70 -54
  100. package/lib/messagingProtocols/proteus/Utility/getGenericMessageParams.d.ts +5 -14
  101. package/lib/messagingProtocols/proteus/Utility/getGenericMessageParams.d.ts.map +1 -1
  102. package/lib/messagingProtocols/proteus/Utility/getGenericMessageParams.js +3 -35
  103. package/lib/messagingProtocols/proteus/Utility/isClearFromMismatch.d.ts +2 -2
  104. package/lib/messagingProtocols/proteus/Utility/isClearFromMismatch.d.ts.map +1 -1
  105. package/lib/notification/NotificationDatabaseRepository.js +1 -1
  106. package/lib/notification/Notifications.types.js +1 -1
  107. package/lib/user/UserService.d.ts +6 -17
  108. package/lib/user/UserService.d.ts.map +1 -1
  109. package/lib/user/UserService.js +2 -47
  110. package/lib/util/TaskScheduler/TaskScheduler.d.ts +4 -1
  111. package/lib/util/TaskScheduler/TaskScheduler.d.ts.map +1 -1
  112. package/lib/util/TaskScheduler/TaskScheduler.js +24 -3
  113. package/lib/util/TaskScheduler/TaskScheduler.store.d.ts +7 -0
  114. package/lib/util/TaskScheduler/TaskScheduler.store.d.ts.map +1 -0
  115. package/lib/util/TaskScheduler/TaskScheduler.store.js +34 -0
  116. package/lib/util/TypePredicateUtil.d.ts +0 -1
  117. package/lib/util/TypePredicateUtil.d.ts.map +1 -1
  118. package/lib/util/TypePredicateUtil.js +1 -2
  119. package/package.json +3 -3
  120. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/index.d.ts +0 -2
  121. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/index.d.ts.map +0 -1
  122. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/index.js +0 -35
  123. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.d.ts +0 -11
  124. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.d.ts.map +0 -1
  125. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.js +0 -50
  126. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.test.d.ts +0 -2
  127. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.test.d.ts.map +0 -1
  128. package/lib/messagingProtocols/mls/MLSService/stores/keyMaterialUpdatesStore/keyMaterialUpdatesStore.test.js +0 -39
  129. package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.d.ts +0 -4
  130. package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.d.ts.map +0 -1
  131. package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.js +0 -35
  132. package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.test.d.ts +0 -2
  133. package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.test.d.ts.map +0 -1
  134. package/lib/messagingProtocols/mls/MLSService/subconversationGroupIdMapper.test.js +0 -35
  135. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.d.ts +0 -25
  136. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.d.ts.map +0 -1
  137. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.js +0 -93
  138. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.test.d.ts +0 -2
  139. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.test.d.ts.map +0 -1
  140. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/PreKeyBundle.test.js +0 -66
  141. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/index.d.ts +0 -2
  142. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/index.d.ts.map +0 -1
  143. package/lib/messagingProtocols/proteus/Utility/PreKeyBundle/index.js +0 -35
@@ -1,7 +1,6 @@
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 { CoreDatabase } from '../../../../../storage/CoreDB';
5
4
  import { SecretCrypto } from '../../../../mls/types';
6
5
  import { CryptoClient } from '../CryptoClient.types';
7
6
  type Config = {
@@ -12,16 +11,16 @@ type Config = {
12
11
  type ClientConfig = Config & {
13
12
  onWipe: () => Promise<void>;
14
13
  };
15
- export declare function buildClient(storeEngine: CRUDEngine, coreCryptoWasmFilePath: string, db: CoreDatabase, { systemCrypto, nbPrekeys, onNewPrekeys }: Config): Promise<CoreCryptoWrapper>;
14
+ export declare function buildClient(storeEngine: CRUDEngine, coreCryptoWasmFilePath: string, { systemCrypto, nbPrekeys, onNewPrekeys }: Config): Promise<CoreCryptoWrapper>;
16
15
  export declare class CoreCryptoWrapper implements CryptoClient {
17
16
  private readonly coreCrypto;
18
17
  private readonly config;
19
18
  private readonly prekeyTracker;
20
- constructor(coreCrypto: CoreCrypto, db: CoreDatabase, config: ClientConfig);
19
+ constructor(coreCrypto: CoreCrypto, config: ClientConfig);
21
20
  getNativeClient(): CoreCrypto;
22
21
  encrypt(sessions: string[], plainText: Uint8Array): Promise<Map<string, Uint8Array>>;
23
22
  decrypt(sessionId: string, message: Uint8Array): Promise<Uint8Array>;
24
- init(): Promise<void>;
23
+ init(nbInitialPrekeys?: number): Promise<void>;
25
24
  create(nbPrekeys: number, entropy?: Uint8Array): Promise<{
26
25
  prekeys: PreKey[];
27
26
  lastPrekey: {
@@ -37,13 +36,19 @@ export declare class CoreCryptoWrapper implements CryptoClient {
37
36
  saveSession(sessionId: string): Promise<void>;
38
37
  deleteSession(sessionId: string): Promise<void>;
39
38
  consumePrekey(): Promise<void>;
40
- newPrekey(id: number): Promise<{
39
+ newPrekey(): Promise<{
41
40
  id: number;
42
41
  key: string;
43
42
  }>;
44
43
  debugBreakSession(sessionId: string): Promise<void>;
45
44
  debugResetIdentity(): Promise<void>;
46
45
  migrateFromCryptobox(dbName: string): Promise<void>;
46
+ /**
47
+ * Will call the callback once corecrypto is ready.
48
+ * @param callback - Function to be called once corecrypto is ready.
49
+ * @see https://github.com/wireapp/wire-web-packages/pull/4972
50
+ */
51
+ private onReady;
47
52
  wipe(): Promise<void>;
48
53
  }
49
54
  export {};
@@ -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;AAChD,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAKtD,OAAO,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAEnD,KAAK,MAAM,GAAG;IACZ,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEF,KAAK,YAAY,GAAG,MAAM,GAAG;IAC3B,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AAEF,wBAAsB,WAAW,CAC/B,WAAW,EAAE,UAAU,EACvB,sBAAsB,EAAE,MAAM,EAC9B,EAAE,EAA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AAU;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"}
@@ -24,7 +24,7 @@ const idb_1 = require("idb");
24
24
  const core_crypto_1 = require("@wireapp/core-crypto");
25
25
  const PrekeysTracker_1 = require("./PrekeysTracker");
26
26
  const secretKeyGenerator_1 = require("./secretKeyGenerator");
27
- async function buildClient(storeEngine, coreCryptoWasmFilePath, db, { systemCrypto, nbPrekeys, onNewPrekeys }) {
27
+ async function buildClient(storeEngine, coreCryptoWasmFilePath, { systemCrypto, nbPrekeys, onNewPrekeys }) {
28
28
  let key;
29
29
  const coreCryptoDbName = `corecrypto-${storeEngine.storeName}`;
30
30
  const secretKeysDbName = `secrets-${storeEngine.storeName}`;
@@ -52,15 +52,16 @@ async function buildClient(storeEngine, coreCryptoWasmFilePath, db, { systemCryp
52
52
  databaseName: coreCryptoDbName,
53
53
  key: bazinga64_1.Encoder.toBase64(key.key).asString,
54
54
  wasmFilePath: coreCryptoWasmFilePath,
55
+ ciphersuites: [core_crypto_1.Ciphersuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519],
55
56
  });
56
- return new CoreCryptoWrapper(coreCrypto, db, { nbPrekeys, onNewPrekeys, onWipe: key.deleteKey });
57
+ return new CoreCryptoWrapper(coreCrypto, { nbPrekeys, onNewPrekeys, onWipe: key.deleteKey });
57
58
  }
58
59
  exports.buildClient = buildClient;
59
60
  class CoreCryptoWrapper {
60
- constructor(coreCrypto, db, config) {
61
+ constructor(coreCrypto, config) {
61
62
  this.coreCrypto = coreCrypto;
62
63
  this.config = config;
63
- this.prekeyTracker = new PrekeysTracker_1.PrekeyTracker(this, db, config);
64
+ this.prekeyTracker = new PrekeysTracker_1.PrekeyTracker(this, config);
64
65
  }
65
66
  getNativeClient() {
66
67
  return this.coreCrypto;
@@ -71,7 +72,10 @@ class CoreCryptoWrapper {
71
72
  decrypt(sessionId, message) {
72
73
  return this.coreCrypto.proteusDecrypt(sessionId, message);
73
74
  }
74
- init() {
75
+ init(nbInitialPrekeys) {
76
+ if (nbInitialPrekeys) {
77
+ this.prekeyTracker.setInitialState(nbInitialPrekeys);
78
+ }
75
79
  return this.coreCrypto.proteusInit();
76
80
  }
77
81
  async create(nbPrekeys, entropy) {
@@ -81,9 +85,8 @@ class CoreCryptoWrapper {
81
85
  await this.init();
82
86
  const prekeys = [];
83
87
  for (let id = 0; id < nbPrekeys; id++) {
84
- prekeys.push(await this.newPrekey(id));
88
+ prekeys.push(await this.newPrekey());
85
89
  }
86
- await this.prekeyTracker.setInitialState(prekeys.length);
87
90
  const lastPrekeyBytes = await this.coreCrypto.proteusLastResortPrekey();
88
91
  const lastPrekey = bazinga64_1.Encoder.toBase64(lastPrekeyBytes).asString;
89
92
  const lastPrekeyId = core_crypto_1.CoreCrypto.proteusLastResortPrekeyId();
@@ -117,9 +120,9 @@ class CoreCryptoWrapper {
117
120
  consumePrekey() {
118
121
  return this.prekeyTracker.consumePrekey();
119
122
  }
120
- async newPrekey(id) {
121
- const key = await this.coreCrypto.proteusNewPrekey(id);
122
- return { id, key: bazinga64_1.Encoder.toBase64(key).asString };
123
+ async newPrekey() {
124
+ const { id, pkb } = await this.coreCrypto.proteusNewPrekeyAuto();
125
+ return { id, key: bazinga64_1.Encoder.toBase64(pkb).asString };
123
126
  }
124
127
  async debugBreakSession(sessionId) {
125
128
  const fakePrekey = [
@@ -136,9 +139,28 @@ class CoreCryptoWrapper {
136
139
  async migrateFromCryptobox(dbName) {
137
140
  return this.coreCrypto.proteusCryptoboxMigrate(dbName);
138
141
  }
142
+ /**
143
+ * Will call the callback once corecrypto is ready.
144
+ * @param callback - Function to be called once corecrypto is ready.
145
+ * @see https://github.com/wireapp/wire-web-packages/pull/4972
146
+ */
147
+ onReady(callback) {
148
+ if (!this.coreCrypto.isLocked()) {
149
+ return callback();
150
+ }
151
+ return new Promise(resolve => {
152
+ const intervalId = setInterval(async () => {
153
+ if (!this.coreCrypto.isLocked()) {
154
+ clearInterval(intervalId);
155
+ await callback();
156
+ return resolve();
157
+ }
158
+ }, 100);
159
+ });
160
+ }
139
161
  async wipe() {
140
162
  await this.config.onWipe();
141
- return this.coreCrypto.wipe();
163
+ await this.onReady(() => this.coreCrypto.wipe());
142
164
  }
143
165
  }
144
166
  exports.CoreCryptoWrapper = CoreCryptoWrapper;
@@ -1,6 +1,5 @@
1
1
  import { PreKey } from '@wireapp/api-client/lib/auth';
2
2
  import { CryptoClient } from '../..';
3
- import type { CoreDatabase } from '../../../../../../storage/CoreDB';
4
3
  type CoreCryptoPrekeyGenerator = Pick<CryptoClient, 'newPrekey'>;
5
4
  interface PrekeysGeneratorConfig {
6
5
  /**
@@ -17,10 +16,10 @@ export declare class PrekeyTracker {
17
16
  private readonly generator;
18
17
  private config;
19
18
  private prekeyState;
20
- constructor(generator: CoreCryptoPrekeyGenerator, db: CoreDatabase, config: PrekeysGeneratorConfig);
19
+ constructor(generator: CoreCryptoPrekeyGenerator, config: PrekeysGeneratorConfig);
21
20
  private generatePrekeys;
21
+ setInitialState(nbPrekeys: number): number;
22
22
  consumePrekey(): Promise<void>;
23
- setInitialState(nbInitialPrekeys: number): Promise<void>;
24
23
  private numberOfMissingPrekeys;
25
24
  }
26
25
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"PrekeysTracker.d.ts","sourceRoot":"","sources":["../../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AAIpD,OAAO,EAAC,YAAY,EAAC,MAAM,OAAO,CAAC;AACnC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,kCAAkC,CAAC;AAEnE,KAAK,yBAAyB,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;AAEjE,UAAU,sBAAsB;IAC9B;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAC3C;AAED,qBAAa,aAAa;IAItB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAE1B,OAAO,CAAC,MAAM;IALhB,OAAO,CAAC,WAAW,CAAsB;gBAGtB,SAAS,EAAE,yBAAyB,EACrD,EAAE,EAAE,YAAY,EACR,MAAM,EAAE,sBAAsB;YAK1B,eAAe;IASvB,aAAa;IAUb,eAAe,CAAC,gBAAgB,EAAE,MAAM;IAI9C,OAAO,CAAC,sBAAsB;CAK/B"}
1
+ {"version":3,"file":"PrekeysTracker.d.ts","sourceRoot":"","sources":["../../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AAIpD,OAAO,EAAC,YAAY,EAAC,MAAM,OAAO,CAAC;AAEnC,KAAK,yBAAyB,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;AAEjE,UAAU,sBAAsB;IAC9B;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAC3C;AAED,qBAAa,aAAa;IAGZ,OAAO,CAAC,QAAQ,CAAC,SAAS;IAA6B,OAAO,CAAC,MAAM;IAFjF,OAAO,CAAC,WAAW,CAAsB;gBAEZ,SAAS,EAAE,yBAAyB,EAAU,MAAM,EAAE,sBAAsB;YAI3F,eAAe;IAQ7B,eAAe,CAAC,SAAS,EAAE,MAAM;IAI3B,aAAa;IAUnB,OAAO,CAAC,sBAAsB;CAK/B"}
@@ -21,21 +21,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.PrekeyTracker = void 0;
22
22
  const PrekeysTracker_store_1 = require("./PrekeysTracker.store");
23
23
  class PrekeyTracker {
24
- constructor(generator, db, config) {
24
+ constructor(generator, config) {
25
25
  this.generator = generator;
26
26
  this.config = config;
27
- this.prekeyState = new PrekeysTracker_store_1.PrekeysTrackerStore(db);
27
+ this.prekeyState = new PrekeysTracker_store_1.PrekeysTrackerStore();
28
28
  }
29
29
  async generatePrekeys(nb) {
30
30
  const prekeys = [];
31
- const ids = await this.prekeyState.createIds(nb);
32
- for (const id of ids) {
33
- prekeys.push(await this.generator.newPrekey(id));
31
+ for (let i = 0; i < nb; i++) {
32
+ prekeys.push(await this.generator.newPrekey());
34
33
  }
35
34
  return prekeys;
36
35
  }
36
+ setInitialState(nbPrekeys) {
37
+ return this.prekeyState.addPrekeys(nbPrekeys);
38
+ }
37
39
  async consumePrekey() {
38
- const nbPrekeys = await this.prekeyState.consumePrekey();
40
+ const nbPrekeys = this.prekeyState.consumePrekey();
39
41
  const missingPrekeys = this.numberOfMissingPrekeys(nbPrekeys);
40
42
  if (missingPrekeys > 0) {
41
43
  // when the number of local prekeys hit less than a quarter of what it should be, we refill the stock
@@ -43,9 +45,6 @@ class PrekeyTracker {
43
45
  this.config.onNewPrekeys(newPrekeys);
44
46
  }
45
47
  }
46
- async setInitialState(nbInitialPrekeys) {
47
- await this.prekeyState.createIds(nbInitialPrekeys);
48
- }
49
48
  numberOfMissingPrekeys(currentNumberOfPrekeys) {
50
49
  const threshold = Math.ceil(this.config.nbPrekeys / 2);
51
50
  const hasHitThreshold = currentNumberOfPrekeys <= threshold;
@@ -1,19 +1,14 @@
1
- import { CoreDatabase } from '../../../../../../storage/CoreDB';
2
1
  export declare class PrekeysTrackerStore {
3
- private readonly db;
4
- constructor(db: CoreDatabase);
5
- private getState;
6
- private saveState;
2
+ private setNbPrekeys;
7
3
  /**
8
4
  * Will mark one prekey as consumed and decrease the total number of prekeys of 1
9
5
  * @returns the number of valid prekeys that are left
10
6
  */
11
- consumePrekey(): Promise<number>;
12
- getNumberOfPrekeys(): Promise<number>;
7
+ consumePrekey(): number;
13
8
  /**
14
- * will generate nbIds ids that can be used to store prekeys
9
+ * Will add to the number of prekeys that are stored
15
10
  * @param nbIds the number of ids to generate
16
11
  */
17
- createIds(nbIds: number): Promise<number[]>;
12
+ addPrekeys(delta: number): number;
18
13
  }
19
14
  //# sourceMappingURL=PrekeysTracker.store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrekeysTracker.store.d.ts","sourceRoot":"","sources":["../../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,YAAY,EAAC,MAAM,kCAAkC,CAAC;AAQ9D,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,YAAY;YAE/B,QAAQ;YAIR,SAAS;IAIvB;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAOhC,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;IAK3C;;;OAGG;IACG,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAMlD"}
1
+ {"version":3,"file":"PrekeysTracker.store.d.ts","sourceRoot":"","sources":["../../../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.ts"],"names":[],"mappings":"AAyBA,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,YAAY;IAMpB;;;OAGG;IACH,aAAa,IAAI,MAAM;IAIvB;;;OAGG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAGlC"}
@@ -19,40 +19,26 @@
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.PrekeysTrackerStore = void 0;
22
- const STATE_PRIMARY_KEY = 'prekeys_state';
22
+ let state = { nbPrekeys: 0 };
23
23
  class PrekeysTrackerStore {
24
- constructor(db) {
25
- this.db = db;
26
- }
27
- async getState() {
28
- var _a;
29
- return (_a = (await this.db.get('prekeys', STATE_PRIMARY_KEY))) !== null && _a !== void 0 ? _a : { nbPrekeys: 0, highestId: 0 };
30
- }
31
- async saveState(state) {
32
- await this.db.put('prekeys', state, STATE_PRIMARY_KEY);
24
+ setNbPrekeys(delta) {
25
+ const newNbPrekeys = state.nbPrekeys + delta;
26
+ state = Object.assign(Object.assign({}, state), { nbPrekeys: newNbPrekeys });
27
+ return newNbPrekeys;
33
28
  }
34
29
  /**
35
30
  * Will mark one prekey as consumed and decrease the total number of prekeys of 1
36
31
  * @returns the number of valid prekeys that are left
37
32
  */
38
- async consumePrekey() {
39
- const currentState = await this.getState();
40
- const newState = Object.assign(Object.assign({}, currentState), { nbPrekeys: currentState.nbPrekeys - 1 });
41
- await this.saveState(newState);
42
- return newState.nbPrekeys;
43
- }
44
- async getNumberOfPrekeys() {
45
- const currentState = await this.getState();
46
- return currentState.nbPrekeys;
33
+ consumePrekey() {
34
+ return this.setNbPrekeys(-1);
47
35
  }
48
36
  /**
49
- * will generate nbIds ids that can be used to store prekeys
37
+ * Will add to the number of prekeys that are stored
50
38
  * @param nbIds the number of ids to generate
51
39
  */
52
- async createIds(nbIds) {
53
- const currentState = await this.getState();
54
- this.saveState({ nbPrekeys: currentState.highestId + nbIds, highestId: currentState.highestId + nbIds });
55
- return Array.from(new Array(nbIds)).map((_, i) => currentState.highestId + 1 + i);
40
+ addPrekeys(delta) {
41
+ return this.setNbPrekeys(delta);
56
42
  }
57
43
  }
58
44
  exports.PrekeysTrackerStore = PrekeysTrackerStore;
@@ -19,9 +19,7 @@
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  const PrekeysTracker_1 = require("./PrekeysTracker");
22
- const CoreDB_1 = require("../../../../../../storage/CoreDB");
23
22
  describe('PrekeysGenerator', () => {
24
- let db;
25
23
  const baseConfig = {
26
24
  nbPrekeys: 10,
27
25
  onNewPrekeys: jest.fn(),
@@ -29,15 +27,9 @@ describe('PrekeysGenerator', () => {
29
27
  const mockPrekeyTracker = {
30
28
  newPrekey: jest.fn().mockResolvedValue(Uint8Array.from([])),
31
29
  };
32
- beforeEach(async () => {
33
- db = await (0, CoreDB_1.openDB)('test');
34
- });
35
- afterEach(async () => {
36
- await db.clear('prekeys');
37
- });
38
30
  it('triggers the threshold callback when number of prekeys hits the limit', async () => {
39
- const prekeyTracker = new PrekeysTracker_1.PrekeyTracker(mockPrekeyTracker, db, baseConfig);
40
- await prekeyTracker.setInitialState(baseConfig.nbPrekeys);
31
+ const prekeyTracker = new PrekeysTracker_1.PrekeyTracker(mockPrekeyTracker, baseConfig);
32
+ prekeyTracker.setInitialState(baseConfig.nbPrekeys);
41
33
  expect(baseConfig.onNewPrekeys).not.toHaveBeenCalled();
42
34
  await prekeyTracker.consumePrekey();
43
35
  await prekeyTracker.consumePrekey();
@@ -2,7 +2,6 @@ import { PreKey } from '@wireapp/api-client/lib/auth';
2
2
  import type { CRUDEngine } from '@wireapp/store-engine';
3
3
  import type { CoreCryptoWrapper } from './CoreCryptoWrapper/CoreCryptoWrapper';
4
4
  import type { CryptoboxWrapper } from './CryptoboxWrapper';
5
- import { CoreDatabase } from '../../../../storage/CoreDB';
6
5
  import { SecretCrypto } from '../../../mls/types';
7
6
  export declare enum CryptoClientType {
8
7
  CORE_CRYPTO = 0,
@@ -18,6 +17,6 @@ type InitConfig = WrapConfig & {
18
17
  systemCrypto?: SecretCrypto;
19
18
  coreCryptoWasmFilePath?: string;
20
19
  };
21
- export declare function buildCryptoClient(clientType: CryptoClientType, db: CoreDatabase, { storeEngine, nbPrekeys, systemCrypto, coreCryptoWasmFilePath, onNewPrekeys }: InitConfig): Promise<CryptoClientDef>;
20
+ export declare function buildCryptoClient(clientType: CryptoClientType, { storeEngine, nbPrekeys, systemCrypto, coreCryptoWasmFilePath, onNewPrekeys }: InitConfig): Promise<CryptoClientDef>;
22
21
  export {};
23
22
  //# sourceMappingURL=CryptoClient.d.ts.map
@@ -1 +1 @@
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,4BAA4B,CAAC;AACxD,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,EAAE,EAAE,YAAY,EAChB,EAAC,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,sBAAsB,EAAE,YAAY,EAAC,EAAE,UAAU,GACvF,OAAO,CAAC,eAAe,CAAC,CAc1B"}
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"}
@@ -46,11 +46,11 @@ var CryptoClientType;
46
46
  (function (CryptoClientType) {
47
47
  CryptoClientType[CryptoClientType["CORE_CRYPTO"] = 0] = "CORE_CRYPTO";
48
48
  CryptoClientType[CryptoClientType["CRYPTOBOX"] = 1] = "CRYPTOBOX";
49
- })(CryptoClientType = exports.CryptoClientType || (exports.CryptoClientType = {}));
50
- async function buildCryptoClient(clientType, db, { storeEngine, nbPrekeys, systemCrypto, coreCryptoWasmFilePath, onNewPrekeys }) {
49
+ })(CryptoClientType || (exports.CryptoClientType = CryptoClientType = {}));
50
+ async function buildCryptoClient(clientType, { storeEngine, nbPrekeys, systemCrypto, coreCryptoWasmFilePath, onNewPrekeys }) {
51
51
  if (clientType === CryptoClientType.CORE_CRYPTO) {
52
52
  const { buildClient } = await Promise.resolve().then(() => __importStar(require('./CoreCryptoWrapper')));
53
- const client = await buildClient(storeEngine, coreCryptoWasmFilePath !== null && coreCryptoWasmFilePath !== void 0 ? coreCryptoWasmFilePath : '', db, {
53
+ const client = await buildClient(storeEngine, coreCryptoWasmFilePath !== null && coreCryptoWasmFilePath !== void 0 ? coreCryptoWasmFilePath : '', {
54
54
  systemCrypto,
55
55
  nbPrekeys,
56
56
  onNewPrekeys,
@@ -10,7 +10,7 @@ export interface CryptoClient<T = unknown> {
10
10
  /**
11
11
  * Will init an already existing client. The client should already exist in the database. If the client doesn't exist, it needs to be created using the `create` method.
12
12
  */
13
- init(): Promise<void>;
13
+ init(nbPrekeys: number): Promise<void>;
14
14
  /**
15
15
  * Will create a new client and store it in the database
16
16
  */
@@ -23,7 +23,7 @@ export interface CryptoClient<T = unknown> {
23
23
  saveSession(sessionId: string): Promise<void>;
24
24
  consumePrekey: () => Promise<void>;
25
25
  deleteSession(sessionId: string): Promise<void>;
26
- newPrekey(id: number): Promise<PreKey>;
26
+ newPrekey(): Promise<PreKey>;
27
27
  debugBreakSession(sessionId: string): void;
28
28
  debugResetIdentity(): Promise<void>;
29
29
  /**
@@ -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,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB;;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,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,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,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"}
@@ -33,7 +33,7 @@ export declare class CryptoboxWrapper implements CryptoClient {
33
33
  sessionExists(sessionId: string): Promise<boolean>;
34
34
  saveSession(): Promise<void>;
35
35
  deleteSession(sessionId: string): Promise<void>;
36
- newPrekey(id: number): Promise<{
36
+ newPrekey(): Promise<{
37
37
  id: number;
38
38
  key: string;
39
39
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"CryptoboxWrapper.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/ProteusService/CryptoClient/Cryptobox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CACX"}
@@ -97,9 +97,9 @@ class CryptoboxWrapper {
97
97
  async deleteSession(sessionId) {
98
98
  await this.cryptobox.session_delete(sessionId);
99
99
  }
100
- async newPrekey(id) {
100
+ async newPrekey() {
101
101
  // CryptoBox is generating prekeys internally
102
- return { id, key: '' };
102
+ return { id: 0, key: '' };
103
103
  }
104
104
  async debugBreakSession(sessionId) {
105
105
  const session = await this.cryptobox.session_load(sessionId);
@@ -1,13 +1,21 @@
1
1
  import type { APIClient } from '@wireapp/api-client/lib/APIClient';
2
2
  import type { PreKey, Context } from '@wireapp/api-client/lib/auth';
3
- import type { Conversation, OTRRecipients, QualifiedOTRRecipients, QualifiedUserClients, UserClients } from '@wireapp/api-client/lib/conversation';
4
- import type { QualifiedId, QualifiedUserPreKeyBundleMap, UserPreKeyBundleMap } from '@wireapp/api-client/lib/user';
3
+ import type { Conversation, QualifiedOTRRecipients, QualifiedUserClients } from '@wireapp/api-client/lib/conversation';
4
+ import type { QualifiedId, QualifiedUserPreKeyBundleMap } from '@wireapp/api-client/lib/user';
5
5
  import { CRUDEngine } from '@wireapp/store-engine';
6
6
  import { CryptoClient } from './CryptoClient';
7
7
  import type { AddUsersToProteusConversationParams, CreateProteusConversationParams, ProteusServiceConfig, SendProteusMessageParams } from './ProteusService.types';
8
8
  import { SendResult } from '../../../conversation';
9
9
  import type { EventHandlerResult } from '../../common.types';
10
10
  import { EventHandlerParams } from '../EventHandler';
11
+ export type EncryptionResult = {
12
+ /** the encrypted payloads for the clients that have a valid sessions */
13
+ payloads: QualifiedOTRRecipients;
14
+ /** user-client that do not have prekeys on backend (deleted clients) */
15
+ unknowns?: QualifiedUserClients;
16
+ /** users for whom we could retrieve a prekey and, thus, for which we could not encrypt the message */
17
+ failed?: QualifiedId[];
18
+ };
11
19
  export declare class ProteusService {
12
20
  private readonly apiClient;
13
21
  private readonly cryptoClient;
@@ -22,7 +30,7 @@ export declare class ProteusService {
22
30
  * Get the fingerprint of the local client.
23
31
  */
24
32
  getLocalFingerprint(): Promise<string>;
25
- constructSessionId(userId: string | QualifiedId, clientId: string, domain?: string): string;
33
+ constructSessionId(userId: QualifiedId, clientId: string): string;
26
34
  /**
27
35
  * Get the fingerprint of a remote client
28
36
  * @param userId ID of user
@@ -32,12 +40,11 @@ export declare class ProteusService {
32
40
  */
33
41
  getRemoteFingerprint(userId: QualifiedId, clientId: string, prekey?: PreKey): Promise<string>;
34
42
  createConversation({ conversationData, otherUserIds, }: CreateProteusConversationParams): Promise<Conversation>;
35
- addUsersToConversation({ conversationId, qualifiedUserIds }: AddUsersToProteusConversationParams): Promise<import("@wireapp/api-client/lib/event").ConversationMemberJoinEvent>;
36
- sendMessage({ userIds, sendAsProtobuf, conversationId, nativePush, targetMode, payload, onClientMismatch, }: SendProteusMessageParams): Promise<SendResult>;
43
+ addUsersToConversation({ conversationId, qualifiedUsers }: AddUsersToProteusConversationParams): Promise<import("@wireapp/api-client/lib/event").ConversationMemberJoinEvent>;
44
+ sendMessage({ userIds, conversationId, nativePush, targetMode, payload, onClientMismatch, }: SendProteusMessageParams): Promise<SendResult>;
37
45
  private decrypt;
38
- encrypt(plainText: Uint8Array, recipients: UserPreKeyBundleMap | UserClients, domain?: string): Promise<OTRRecipients<Uint8Array>>;
39
46
  deleteSession(userId: QualifiedId, clientId: string): Promise<void>;
40
- encryptQualified(plainText: Uint8Array, preKeyBundles: QualifiedUserPreKeyBundleMap | QualifiedUserClients): Promise<QualifiedOTRRecipients>;
47
+ encrypt(plainText: Uint8Array, recipients: QualifiedUserPreKeyBundleMap | QualifiedUserClients): Promise<EncryptionResult>;
41
48
  wipe(storeEngine?: CRUDEngine): Promise<void>;
42
49
  }
43
50
  //# 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;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WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;IAIlG;;;;;;OAMG;IACU,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAQ3E,kBAAkB,CAAC,EAC9B,gBAAgB,EAChB,YAAY,GACb,EAAE,+BAA+B,GAAG,OAAO,CAAC,YAAY,CAAC;IAiB7C,sBAAsB,CAAC,EAAC,cAAc,EAAE,gBAAgB,EAAC,EAAE,mCAAmC;IAI9F,WAAW,CAAC,EACvB,OAAO,EACP,cAAc,EACd,cAAc,EACd,UAAU,EACV,UAAU,EACV,OAAO,EACP,gBAAgB,GACjB,EAAE,wBAAwB,GAAG,OAAO,CAAC,UAAU,CAAC;YAmDnC,OAAO;IAuBR,OAAO,CAClB,SAAS,EAAE,UAAU,EACrB,UAAU,EAAE,mBAAmB,GAAG,WAAW,EAC7C,MAAM,GAAE,MAAW,GAClB,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAc9B,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM;IAS7C,gBAAgB,CAC3B,SAAS,EAAE,UAAU,EACrB,aAAa,EAAE,4BAA4B,GAAG,oBAAoB,GACjE,OAAO,CAAC,sBAAsB,CAAC;IAW5B,IAAI,CAAC,WAAW,CAAC,EAAE,UAAU;CAMpC"}
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,KAAK,EACV,YAAY,EAEZ,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAA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AE,MAAM,GAAG,MAAM;IAIxE;;;;;;OAMG;IACU,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAQ3E,kBAAkB,CAAC,EAC9B,gBAAgB,EAChB,YAAY,GACb,EAAE,+BAA+B,GAAG,OAAO,CAAC,YAAY,CAAC;IAiB7C,sBAAsB,CAAC,EAAC,cAAc,EAAE,cAAc,EAAC,EAAE,mCAAmC;IAI5F,WAAW,CAAC,EACvB,OAAO,EACP,cAAc,EACd,UAAU,EACV,UAAU,EACV,OAAO,EACP,gBAAgB,GACjB,EAAE,wBAAwB,GAAG,OAAO,CAAC,UAAU,CAAC;YA6CnC,OAAO;IAuBd,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,CAAC,WAAW,CAAC,EAAE,UAAU;CAMpC"}
@@ -55,8 +55,9 @@ class ProteusService {
55
55
  return handledEvent;
56
56
  }
57
57
  async initClient(storeEngine, context) {
58
+ var _a;
58
59
  const dbName = storeEngine.storeName;
59
- if (context.domain && this.config.useQualifiedIds) {
60
+ if (context.domain) {
60
61
  // We want sessions to be fully qualified from now on
61
62
  if (!cryptoMigrationStateStore_1.cryptoMigrationStore.qualifiedSessions.isReady(dbName)) {
62
63
  this.logger.info(`Migrating existing session ids to qualified ids.`);
@@ -76,7 +77,9 @@ class ProteusService {
76
77
  this.logger.error('Client was not able to perform DB migration: ', error);
77
78
  }
78
79
  }
79
- return this.cryptoClient.init();
80
+ const backendPrekeys = await this.apiClient.api.client.getClientPreKeys((_a = context.clientId) !== null && _a !== void 0 ? _a : '');
81
+ const totalUsableBackedPrekeys = backendPrekeys.length - 1; // we remove the last resort prekey from the total number of available prekeys
82
+ return this.cryptoClient.init(totalUsableBackedPrekeys);
80
83
  }
81
84
  createClient(entropy) {
82
85
  return this.cryptoClient.create(this.config.nbPrekeys, entropy);
@@ -87,8 +90,8 @@ class ProteusService {
87
90
  getLocalFingerprint() {
88
91
  return this.cryptoClient.getFingerprint();
89
92
  }
90
- constructSessionId(userId, clientId, domain) {
91
- return (0, SessionHandler_1.constructSessionId)({ clientId, userId, domain, useQualifiedIds: this.config.useQualifiedIds });
93
+ constructSessionId(userId, clientId) {
94
+ return (0, SessionHandler_1.constructSessionId)({ clientId, userId });
92
95
  }
93
96
  /**
94
97
  * Get the fingerprint of a remote client
@@ -116,28 +119,24 @@ class ProteusService {
116
119
  }
117
120
  return this.apiClient.api.conversation.postConversation(payload);
118
121
  }
119
- async addUsersToConversation({ conversationId, qualifiedUserIds }) {
120
- return this.apiClient.api.conversation.postMembers(conversationId, qualifiedUserIds);
122
+ async addUsersToConversation({ conversationId, qualifiedUsers }) {
123
+ return this.apiClient.api.conversation.postMembers(conversationId, qualifiedUsers);
121
124
  }
122
- async sendMessage({ userIds, sendAsProtobuf, conversationId, nativePush, targetMode, payload, onClientMismatch, }) {
125
+ async sendMessage({ userIds, conversationId, nativePush, targetMode, payload, onClientMismatch, }) {
126
+ var _a;
123
127
  const messageParams = await (0, getGenericMessageParams_1.getGenericMessageParams)({
124
128
  apiClient: this.apiClient,
125
129
  sendingClientId: this.apiClient.validatedClientId,
126
130
  conversationId,
127
131
  genericMessage: payload,
128
- useQualifiedIds: this.config.useQualifiedIds,
129
132
  options: {
130
133
  userIds,
131
- sendAsProtobuf,
132
134
  nativePush,
133
135
  targetMode,
134
- onClientMismatch,
135
136
  },
136
137
  });
137
- const { federated, sendingClientId, recipients, plainText, options } = messageParams;
138
- const response = federated
139
- ? await this.messageService.sendFederatedMessage(sendingClientId, recipients, plainText, Object.assign(Object.assign({}, options), { onClientMismatch: mismatch => onClientMismatch === null || onClientMismatch === void 0 ? void 0 : onClientMismatch(mismatch, false) }))
140
- : await this.messageService.sendMessage(sendingClientId, recipients, plainText, Object.assign(Object.assign({}, options), { sendAsProtobuf, onClientMismatch: mismatch => onClientMismatch === null || onClientMismatch === void 0 ? void 0 : onClientMismatch(mismatch, false) }));
138
+ const { sendingClientId, recipients, plainText, options } = messageParams;
139
+ const response = await this.messageService.sendMessage(sendingClientId, recipients, plainText, Object.assign(Object.assign({}, options), { onClientMismatch: mismatch => onClientMismatch === null || onClientMismatch === void 0 ? void 0 : onClientMismatch(mismatch, false) }));
141
140
  if (!response.canceled) {
142
141
  if (!(0, isClearFromMismatch_1.isClearFromMismatch)(response)) {
143
142
  // We warn the consumer that there is a mismatch that did not prevent message sending
@@ -146,8 +145,11 @@ class ProteusService {
146
145
  this.logger.log(`Successfully sent Proteus message to conversation '${conversationId.id}'`);
147
146
  }
148
147
  const sendingState = response.canceled ? conversation_1.MessageSendingState.CANCELED : conversation_1.MessageSendingState.OUTGOING_SENT;
149
- const failedToSend = 'failed_to_send' in response && Object.keys(response.failed_to_send).length > 0
150
- ? response.failed_to_send
148
+ const failedToSend = response.failed || Object.keys((_a = response.failed_to_send) !== null && _a !== void 0 ? _a : {}).length > 0
149
+ ? {
150
+ queued: response.failed_to_send,
151
+ failed: response.failed,
152
+ }
151
153
  : undefined;
152
154
  return {
153
155
  id: payload.messageId,
@@ -178,32 +180,26 @@ class ProteusService {
178
180
  throw (0, DecryptionErrorGenerator_1.generateDecryptionError)({ userId, clientId }, error);
179
181
  }
180
182
  }
181
- async encrypt(plainText, recipients, domain = '') {
182
- const sessions = await (0, SessionHandler_1.initSessions)({
183
- recipients,
184
- domain,
185
- apiClient: this.apiClient,
186
- cryptoClient: this.cryptoClient,
187
- logger: this.logger,
188
- });
189
- const payload = await this.cryptoClient.encrypt(sessions, plainText);
190
- return (0, SessionHandler_1.buildEncryptedPayloads)(payload);
191
- }
192
183
  deleteSession(userId, clientId) {
193
184
  return (0, SessionHandler_1.deleteSession)({
194
185
  userId,
195
186
  clientId,
196
- useQualifiedIds: this.config.useQualifiedIds,
197
187
  cryptoClient: this.cryptoClient,
198
188
  });
199
189
  }
200
- async encryptQualified(plainText, preKeyBundles) {
201
- const qualifiedOTRRecipients = {};
202
- for (const [domain, preKeyBundleMap] of Object.entries(preKeyBundles)) {
203
- const result = await this.encrypt(plainText, preKeyBundleMap, domain);
204
- qualifiedOTRRecipients[domain] = result;
205
- }
206
- return qualifiedOTRRecipients;
190
+ async encrypt(plainText, recipients) {
191
+ const { sessions, unknowns, failed } = await (0, SessionHandler_1.initSessions)({
192
+ recipients,
193
+ apiClient: this.apiClient,
194
+ cryptoClient: this.cryptoClient,
195
+ logger: this.logger,
196
+ });
197
+ const payloads = await this.cryptoClient.encrypt(sessions, plainText);
198
+ return {
199
+ payloads: (0, SessionHandler_1.buildEncryptedPayloads)(payloads),
200
+ unknowns,
201
+ failed,
202
+ };
207
203
  }
208
204
  async wipe(storeEngine) {
209
205
  if (storeEngine) {