@wireapp/core 38.8.2 → 38.9.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 (21) hide show
  1. package/lib/conversation/ConversationService/ConversationService.js +1 -1
  2. package/lib/conversation/ConversationService/ConversationService.types.d.ts +2 -0
  3. package/lib/conversation/ConversationService/ConversationService.types.d.ts.map +1 -1
  4. package/lib/conversation/message/Message.types.d.ts +1 -2
  5. package/lib/conversation/message/Message.types.d.ts.map +1 -1
  6. package/lib/conversation/message/Message.types.js +1 -2
  7. package/lib/conversation/message/MessageService.d.ts +2 -2
  8. package/lib/conversation/message/MessageService.d.ts.map +1 -1
  9. package/lib/conversation/message/MessageService.js +2 -2
  10. package/lib/conversation/message/MessageService.test.js +3 -2
  11. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts.map +1 -1
  12. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.js +7 -2
  13. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts +2 -2
  14. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts.map +1 -1
  15. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.js +3 -4
  16. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.test.js +78 -94
  17. package/lib/messagingProtocols/proteus/ProteusService/WithMockedGenerics.test.js +2 -2
  18. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts.map +1 -1
  19. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.js +15 -15
  20. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.test.js +50 -42
  21. package/package.json +4 -4
@@ -234,7 +234,7 @@ class ConversationService {
234
234
  return {
235
235
  id: payload.messageId,
236
236
  sentAt,
237
- state: sentAt ? conversation_2.MessageSendingState.OUTGOING_SENT : conversation_2.MessageSendingState.CANCELLED,
237
+ state: sentAt ? conversation_2.MessageSendingState.OUTGOING_SENT : conversation_2.MessageSendingState.CANCELED,
238
238
  };
239
239
  }
240
240
  async addUsersToMLSConversation({ qualifiedUserIds, groupId, conversationId, }) {
@@ -91,5 +91,7 @@ export type SendResult = {
91
91
  sentAt: string;
92
92
  /** The sending state of the payload (has the payload been succesfully sent or canceled) */
93
93
  state: MessageSendingState;
94
+ /** In case the message was sent to some federated backend, if the backend was down at the moment of sending the `failedToSend` property will contain all the users/devices that couldn't get the message */
95
+ failedToSend?: QualifiedUserClients;
94
96
  };
95
97
  //# sourceMappingURL=ConversationService.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConversationService.types.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.types.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,YAAY,EACb,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAC,QAAQ,EAAC,MAAM,wDAAwD,CAAC;AAChF,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAE3D,OAAO,EAAC,mBAAmB,EAAC,MAAM,IAAI,CAAC;AAEvC,oBAAY,iBAAiB;IAC3B,IAAI,IAAA;IACJ,KAAK,IAAA;IACL,aAAa,IAAA;CACd;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,GAAG,WAAW,GAAG,oBAAoB,CAAC;IAExE;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,gBAAgB,CAAC,EAAE,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;IAE/D;;;;;OAKG;IACH,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC;AAED,MAAM,WAAW,uBAAuB;IACtC;;;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AAG,gBAAgB,GAAG;IACpD;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,oBAAoB,CAAC,GAAG,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC;AAE9D,MAAM,MAAM,cAAc,GAAG;IAC3B,cAAc,EAAE,WAAW,CAAC;IAC5B,gBAAgB,EAAE,WAAW,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,WAAW,CAAC;IAC5B,gBAAgB,EAAE,WAAW,EAAE,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;IAAC,YAAY,EAAE,YAAY,CAAA;CAAC,CAAC;AAE7E,MAAM,MAAM,UAAU,GAAG;IACvB,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,2FAA2F;IAC3F,KAAK,EAAE,mBAAmB,CAAC;IAC3B,4MAA4M;IAC5M,YAAY,CAAC,EAAE,oBAAoB,CAAC;CACrC,CAAC"}
@@ -1,7 +1,6 @@
1
1
  export declare enum MessageSendingState {
2
2
  INCOMING = "INCOMING",
3
3
  OUTGOING_SENT = "OUTGOING_SENT",
4
- OUTGOING_UNSENT = "OUTGOING_UNSENT",
5
- CANCELLED = "CANCELLED"
4
+ CANCELED = "CANCELED"
6
5
  }
7
6
  //# sourceMappingURL=Message.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Message.types.d.ts","sourceRoot":"","sources":["../../../src/conversation/message/Message.types.ts"],"names":[],"mappings":"AAmBA,oBAAY,mBAAmB;IAC7B,QAAQ,aAAa;IACrB,aAAa,kBAAkB;IAC/B,eAAe,oBAAoB;IACnC,SAAS,cAAc;CACxB"}
1
+ {"version":3,"file":"Message.types.d.ts","sourceRoot":"","sources":["../../../src/conversation/message/Message.types.ts"],"names":[],"mappings":"AAmBA,oBAAY,mBAAmB;IAC7B,QAAQ,aAAa;IACrB,aAAa,kBAAkB;IAC/B,QAAQ,aAAa;CACtB"}
@@ -23,6 +23,5 @@ var MessageSendingState;
23
23
  (function (MessageSendingState) {
24
24
  MessageSendingState["INCOMING"] = "INCOMING";
25
25
  MessageSendingState["OUTGOING_SENT"] = "OUTGOING_SENT";
26
- MessageSendingState["OUTGOING_UNSENT"] = "OUTGOING_UNSENT";
27
- MessageSendingState["CANCELLED"] = "CANCELLED";
26
+ MessageSendingState["CANCELED"] = "CANCELED";
28
27
  })(MessageSendingState = exports.MessageSendingState || (exports.MessageSendingState = {}));
@@ -25,7 +25,7 @@ export declare class MessageService {
25
25
  nativePush?: boolean;
26
26
  onClientMismatch?: (mismatch: ClientMismatch) => void | boolean | Promise<boolean>;
27
27
  }): Promise<ClientMismatch & {
28
- errored?: boolean;
28
+ canceled?: boolean;
29
29
  }>;
30
30
  /**
31
31
  * Sends a message to a federated backend.
@@ -46,7 +46,7 @@ export declare class MessageService {
46
46
  nativePush?: boolean;
47
47
  onClientMismatch?: (mismatch: MessageSendingStatus) => void | boolean | Promise<boolean>;
48
48
  }): Promise<MessageSendingStatus & {
49
- errored?: boolean;
49
+ canceled?: boolean;
50
50
  }>;
51
51
  private sendFederatedOtrMessage;
52
52
  private sendOTRMessage;
@@ -1 +1 @@
1
- {"version":3,"file":"MessageService.d.ts","sourceRoot":"","sources":["../../../src/conversation/message/MessageService.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,cAAc,EACd,oBAAoB,EAIpB,oBAAoB,EACpB,WAAW,EACZ,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAE,4BAA4B,EAAE,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAQ5G,OAA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OAWG;IACU,oBAAoB,CAC/B,eAAe,EAAE,MAAM,EACvB,UAAU,EAAE,oBAAoB,GAAG,4BAA4B,EAC/D,SAAS,EAAE,UAAU,EACrB,OAAO,EAAE;QACP,SAAS,CAAC,EAAE,UAAU,CAAC;QACvB,cAAc,CAAC,EAAE,WAAW,CAAC;QAC7B,aAAa,CAAC,EAAE,OAAO,GAAG,WAAW,EAAE,CAAC;QACxC,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;KAC1F,GACA,OAAO,CAAC,oBAAoB,GAAG;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAC,CAAC;YAsBzC,uBAAuB;YAiEvB,cAAc;YAmCd,uBAAuB;IAiBrC,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,qBAAqB;YAIf,sBAAsB;IAmBpC;;;;;;;OAOG;YACW,+BAA+B;YAuB/B,sBAAsB;CAoDrC"}
@@ -75,7 +75,7 @@ class MessageService {
75
75
  const mismatch = error.response.data;
76
76
  const shouldStopSending = options.onClientMismatch && (await options.onClientMismatch(mismatch)) === false;
77
77
  if (shouldStopSending) {
78
- return Object.assign(Object.assign({}, mismatch), { errored: true });
78
+ return Object.assign(Object.assign({}, mismatch), { canceled: true });
79
79
  }
80
80
  const reEncryptedMessage = await this.reencryptAfterMismatch(mismatch, encryptedPayload, plainText);
81
81
  return send(reEncryptedMessage);
@@ -108,7 +108,7 @@ class MessageService {
108
108
  const mismatch = error.response.data;
109
109
  const shouldStopSending = options.onClientMismatch && (await options.onClientMismatch(mismatch)) === false;
110
110
  if (shouldStopSending) {
111
- return Object.assign(Object.assign({}, mismatch), { errored: true });
111
+ return Object.assign(Object.assign({}, mismatch), { canceled: true });
112
112
  }
113
113
  const reEncryptedPayload = await this.reencryptAfterFederatedMismatch(mismatch, encryptedPayload, plainText);
114
114
  return send(reEncryptedPayload);
@@ -89,14 +89,15 @@ const buildMessageService = async () => {
89
89
  };
90
90
  describe('MessageService', () => {
91
91
  describe('sendFederatedMessage', () => {
92
- it('sends a message', async () => {
92
+ it('sends a message and forwards backend response', async () => {
93
93
  const [messageService, { apiClient }] = await buildMessageService();
94
94
  jest.spyOn(apiClient.api.conversation, 'postOTRMessageV2').mockResolvedValue(baseMessageSendingStatus);
95
95
  const recipients = generateQualifiedRecipients([user1, user2]);
96
- await messageService.sendFederatedMessage('senderclientid', recipients, new Uint8Array(), {
96
+ const result = await messageService.sendFederatedMessage('senderclientid', recipients, new Uint8Array(), {
97
97
  conversationId: { id: 'convid', domain: '' },
98
98
  });
99
99
  expect(apiClient.api.conversation.postOTRMessageV2).toHaveBeenCalled();
100
+ expect(result).toEqual(baseMessageSendingStatus);
100
101
  });
101
102
  describe('client mismatch', () => {
102
103
  it('handles client mismatch internally if no onClientMismatch is given', async () => {
@@ -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,KAAK,EACV,YAAY,EAEZ,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACZ,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAC,WAAW,EAAE,4BAA4B,EAAE,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAIjH,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAG5C,OAAO,KAAK,EACV,mCAAmC,EACnC,+BAA+B,EAC/B,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;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wB,GAAG,OAAO,CAAC,UAAU,CAAC;YA2CnC,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;IAWlC,IAAI;CAGL"}
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,aAAa,EACb,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,EACZ,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAC,WAAW,EAAE,4BAA4B,EAAE,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAIjH,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAG5C,OAAO,KAAK,EACV,mCAAmC,EACnC,+BAA+B,EAC/B,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAA0C,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAE1F,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAC,kBAAkB,EAAqB,MAAM,iBAAiB,CAAC;AAWvE,qBAAa,cAAc;IAKvB,OAAO,CAAC,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a,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;IAWlC,IAAI;CAGL"}
@@ -137,17 +137,22 @@ class ProteusService {
137
137
  const response = federated
138
138
  ? await this.messageService.sendFederatedMessage(sendingClientId, recipients, plainText, Object.assign(Object.assign({}, options), { onClientMismatch: mismatch => onClientMismatch === null || onClientMismatch === void 0 ? void 0 : onClientMismatch(mismatch, false) }))
139
139
  : 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) }));
140
- if (!response.errored) {
140
+ if (!response.canceled) {
141
141
  if (!(0, isClearFromMismatch_1.isClearFromMismatch)(response)) {
142
142
  // We warn the consumer that there is a mismatch that did not prevent message sending
143
143
  await (onClientMismatch === null || onClientMismatch === void 0 ? void 0 : onClientMismatch(response, true));
144
144
  }
145
145
  this.logger.log(`Successfully sent Proteus message to conversation '${conversationId.id}'`);
146
146
  }
147
+ const sendingState = response.canceled ? conversation_1.MessageSendingState.CANCELED : conversation_1.MessageSendingState.OUTGOING_SENT;
148
+ const failedToSend = 'failed_to_send' in response && Object.keys(response.failed_to_send).length > 0
149
+ ? response.failed_to_send
150
+ : undefined;
147
151
  return {
148
152
  id: payload.messageId,
149
153
  sentAt: response.time,
150
- state: response.errored ? conversation_1.MessageSendingState.CANCELLED : conversation_1.MessageSendingState.OUTGOING_SENT,
154
+ state: sendingState,
155
+ failedToSend,
151
156
  };
152
157
  }
153
158
  async decrypt(encryptedText, userId, clientId) {
@@ -1,8 +1,8 @@
1
1
  import { APIClient } from '@wireapp/api-client';
2
- import { CoreCrypto } from '@wireapp/core-crypto';
2
+ import { CryptoClient } from './CryptoClient';
3
3
  import { ProteusService } from './ProteusService';
4
4
  export declare const buildProteusService: (federated?: boolean) => Promise<[ProteusService, {
5
5
  apiClient: APIClient;
6
- coreCrypto: CoreCrypto;
6
+ cryptoClient: CryptoClient;
7
7
  }]>;
8
8
  //# sourceMappingURL=ProteusService.mocks.d.ts.map
@@ -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;AAC9C,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAGhD,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAIhD,eAAO,MAAM,mBAAmB;eAEQ,SAAS;gBAAc,UAAU;GAgBxE,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;eAEQ,SAAS;kBAAgB,YAAY;GAgB5E,CAAC"}
@@ -21,7 +21,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.buildProteusService = void 0;
22
22
  const client_1 = require("@wireapp/api-client/lib/client");
23
23
  const api_client_1 = require("@wireapp/api-client");
24
- const core_crypto_1 = require("@wireapp/core-crypto");
25
24
  const CoreCryptoWrapper_1 = require("./CryptoClient/CoreCryptoWrapper");
26
25
  const ProteusService_1 = require("./ProteusService");
27
26
  const PayloadHelper_1 = require("../../../test/PayloadHelper");
@@ -32,11 +31,11 @@ const buildProteusService = async (federated = false) => {
32
31
  userId: (0, PayloadHelper_1.getUUID)(),
33
32
  clientId: (0, PayloadHelper_1.getUUID)(),
34
33
  };
35
- const coreCrypto = await core_crypto_1.CoreCrypto.deferredInit('store-name', 'key');
36
- const proteusService = new ProteusService_1.ProteusService(apiClient, new CoreCryptoWrapper_1.CoreCryptoWrapper(coreCrypto, {}, {}), {
34
+ const cryptoClient = new CoreCryptoWrapper_1.CoreCryptoWrapper({}, {}, {});
35
+ const proteusService = new ProteusService_1.ProteusService(apiClient, cryptoClient, {
37
36
  nbPrekeys: 0,
38
37
  useQualifiedIds: federated,
39
38
  });
40
- return [proteusService, { apiClient, coreCrypto }];
39
+ return [proteusService, { apiClient, cryptoClient }];
41
40
  };
42
41
  exports.buildProteusService = buildProteusService;
@@ -65,7 +65,7 @@ jest.mock('./CryptoClient/PrekeysTracker', () => {
65
65
  jest.mock('../Utility/Recipients', () => (Object.assign(Object.assign({}, jest.requireActual('../Utility/Recipients')), { getRecipientsForConversation: jest.fn(), getQualifiedRecipientsForConversation: jest.fn() })));
66
66
  const MockedRecipients = Recipients;
67
67
  const prepareDataForEncryption = async (useQualifiedIds = true) => {
68
- const [proteusService, { coreCrypto, apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)(useQualifiedIds);
68
+ const [proteusService, { cryptoClient, apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)(useQualifiedIds);
69
69
  const domain = 'staging.zinfra.io';
70
70
  //user 1
71
71
  const firstUserId = 'bc0c99f1-49a5-4ad2-889a-62885af37088';
@@ -88,7 +88,7 @@ const prepareDataForEncryption = async (useQualifiedIds = true) => {
88
88
  //user 2
89
89
  const secondUserId = 'cd0c88f1-49a5-4ar2-889a-62885af37069';
90
90
  //user 2 client
91
- const thirdClientId = 'be67218b77d02d69';
91
+ const thirdClientId = 'ce67218b77d02d69';
92
92
  //user 2 sessions
93
93
  const secondClientSessionId = (0, SessionHandler_1.constructSessionId)({
94
94
  userId: secondUserId,
@@ -107,7 +107,7 @@ const prepareDataForEncryption = async (useQualifiedIds = true) => {
107
107
  key: 'pQABARn//wKhAFggJ1Fbpg5l6wnzKOJE+vXpRnkqUYhIvVnR5lNXEbO2o/0DoQChAFggHxZvgvtDktY/vqBcpjjo6rQnXvcNQhfwmy8AJQJKlD0E9g==',
108
108
  };
109
109
  return {
110
- services: { proteusService, apiClient, coreCryptoClient: coreCrypto },
110
+ services: { proteusService, apiClient, cryptoClient },
111
111
  data: {
112
112
  firstUser: {
113
113
  id: firstUserId,
@@ -130,29 +130,35 @@ const prepareDataForEncryption = async (useQualifiedIds = true) => {
130
130
  describe('ProteusService', () => {
131
131
  describe('getRemoteFingerprint', () => {
132
132
  it('create a session if session does not exists', async () => {
133
- const [proteusService, { apiClient, coreCrypto }] = await (0, ProteusService_mocks_1.buildProteusService)();
133
+ const [proteusService, { apiClient, cryptoClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
134
134
  const expectedFingerprint = 'fingerprint-client1';
135
- const getPrekeyMock = jest.spyOn(apiClient.api.user, 'getClientPreKey').mockResolvedValue({
136
- client: 'client1',
137
- prekey: {
138
- id: 123,
139
- key: 'pQABARhIAqEAWCCaJpFa9c626ORmjj1aV6OnOYgmTjfoiE3ynOfNfGAOmgOhAKEAWCD60VMzRrLfO+1GSjgyhnVp2N7L58DM+eeJhZJi1tBLfQT2',
140
- },
141
- });
142
- jest.spyOn(coreCrypto, 'proteusFingerprintRemote').mockResolvedValue(expectedFingerprint);
143
- jest.spyOn(coreCrypto, 'proteusSessionExists').mockResolvedValue(false);
144
135
  const userId = { id: 'user1', domain: 'domain.com' };
145
136
  const clientId = 'client1';
137
+ jest.spyOn(apiClient.api.user, 'postQualifiedMultiPreKeyBundles').mockResolvedValue({
138
+ [userId.domain]: {
139
+ [userId.id]: {
140
+ [clientId]: {
141
+ id: 123,
142
+ key: 'pQABARhIAqEAWCCaJpFa9c626ORmjj1aV6OnOYgmTjfoiE3ynOfNfGAOmgOhAKEAWCD60VMzRrLfO+1GSjgyhnVp2N7L58DM+eeJhZJi1tBLfQT2',
143
+ },
144
+ },
145
+ },
146
+ });
147
+ jest.spyOn(cryptoClient, 'getRemoteFingerprint').mockResolvedValue(expectedFingerprint);
148
+ jest.spyOn(cryptoClient, 'sessionFromPrekey').mockResolvedValue(undefined);
149
+ jest.spyOn(cryptoClient, 'saveSession').mockResolvedValue(undefined);
150
+ jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(false);
146
151
  const result = await proteusService.getRemoteFingerprint(userId, clientId);
147
- expect(getPrekeyMock).toHaveBeenCalledWith(userId, clientId);
148
152
  expect(result).toBe(expectedFingerprint);
149
153
  });
150
154
  it('create a session from given prekey if session does not exists', async () => {
151
- const [proteusService, { apiClient, coreCrypto }] = await (0, ProteusService_mocks_1.buildProteusService)();
155
+ const [proteusService, { apiClient, cryptoClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
152
156
  const expectedFingerprint = 'fingerprint-client1';
153
157
  const getPrekeyMock = jest.spyOn(apiClient.api.user, 'getClientPreKey');
154
- jest.spyOn(coreCrypto, 'proteusFingerprintRemote').mockResolvedValue(expectedFingerprint);
155
- jest.spyOn(coreCrypto, 'proteusSessionExists').mockResolvedValue(false);
158
+ jest.spyOn(cryptoClient, 'getRemoteFingerprint').mockResolvedValue(expectedFingerprint);
159
+ jest.spyOn(cryptoClient, 'sessionFromPrekey').mockResolvedValue(undefined);
160
+ jest.spyOn(cryptoClient, 'saveSession').mockResolvedValue(undefined);
161
+ jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(false);
156
162
  const userId = { id: 'user1', domain: 'domain.com' };
157
163
  const clientId = 'client1';
158
164
  const result = await proteusService.getRemoteFingerprint(userId, clientId, {
@@ -163,12 +169,12 @@ describe('ProteusService', () => {
163
169
  expect(result).toBe(expectedFingerprint);
164
170
  });
165
171
  it('returns the fingerprint from existing session', async () => {
166
- const [proteusService, { apiClient, coreCrypto }] = await (0, ProteusService_mocks_1.buildProteusService)();
172
+ const [proteusService, { apiClient, cryptoClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
167
173
  const expectedFingerprint = 'fingerprint-client1';
168
174
  const getPrekeyMock = jest.spyOn(apiClient.api.user, 'getClientPreKey');
169
- const sessionFromPrekeyMock = jest.spyOn(coreCrypto, 'proteusSessionFromPrekey');
170
- jest.spyOn(coreCrypto, 'proteusFingerprintRemote').mockResolvedValue(expectedFingerprint);
171
- jest.spyOn(coreCrypto, 'proteusSessionExists').mockResolvedValue(true);
175
+ const sessionFromPrekeyMock = jest.spyOn(cryptoClient, 'sessionFromPrekey');
176
+ jest.spyOn(cryptoClient, 'getRemoteFingerprint').mockResolvedValue(expectedFingerprint);
177
+ jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(true);
172
178
  const userId = { id: 'user1', domain: 'domain.com' };
173
179
  const clientId = 'client1';
174
180
  const result = await proteusService.getRemoteFingerprint(userId, clientId);
@@ -188,9 +194,10 @@ describe('ProteusService', () => {
188
194
  };
189
195
  const decryptedMessage = {};
190
196
  it('decrypts incoming proteus encrypted events when session already exists', async () => {
191
- const [proteusService, { coreCrypto }] = await (0, ProteusService_mocks_1.buildProteusService)();
192
- jest.spyOn(coreCrypto, 'proteusSessionExists').mockResolvedValue(true);
193
- const createSessionSpy = jest.spyOn(coreCrypto, 'proteusSessionFromMessage');
197
+ const [proteusService, { cryptoClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
198
+ jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(true);
199
+ const createSessionSpy = jest.spyOn(cryptoClient, 'sessionFromMessage');
200
+ jest.spyOn(cryptoClient, 'decrypt').mockResolvedValue(new Uint8Array());
194
201
  jest.spyOn(protocol_messaging_1.GenericMessage, 'decode').mockReturnValue(decryptedMessage);
195
202
  const result = await proteusService.handleEvent(eventPayload);
196
203
  expect(result).toBeDefined();
@@ -198,10 +205,11 @@ describe('ProteusService', () => {
198
205
  expect(result === null || result === void 0 ? void 0 : result.decryptedData).toBe(decryptedMessage);
199
206
  });
200
207
  it('decrypts incoming proteus encrypted and creates session if not already existing', async () => {
201
- const [proteusService, { coreCrypto }] = await (0, ProteusService_mocks_1.buildProteusService)();
202
- jest.spyOn(coreCrypto, 'proteusSessionExists').mockResolvedValue(false);
203
- const createSessionSpy = jest.spyOn(coreCrypto, 'proteusSessionFromMessage');
204
- const decryptSpy = jest.spyOn(coreCrypto, 'proteusDecrypt');
208
+ const [proteusService, { cryptoClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
209
+ jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(false);
210
+ jest.spyOn(cryptoClient, 'saveSession').mockResolvedValue(undefined);
211
+ const createSessionSpy = jest.spyOn(cryptoClient, 'sessionFromMessage').mockResolvedValue(new Uint8Array());
212
+ const decryptSpy = jest.spyOn(cryptoClient, 'decrypt');
205
213
  jest.spyOn(protocol_messaging_1.GenericMessage, 'decode').mockReturnValue(decryptedMessage);
206
214
  const result = await proteusService.handleEvent(eventPayload);
207
215
  expect(result).toBeDefined();
@@ -212,28 +220,18 @@ describe('ProteusService', () => {
212
220
  });
213
221
  describe('"encrypt"', () => {
214
222
  it('returns encrypted payload', async () => {
215
- const { services, data: { firstUser, validPreKey, encryptedMessageBuffer, messageBuffer }, } = await prepareDataForEncryption(false);
223
+ const { services, data: { firstUser, encryptedMessageBuffer, messageBuffer }, } = await prepareDataForEncryption(false);
216
224
  const userClients = {
217
225
  [firstUser.id]: [firstUser.clients.first, firstUser.clients.second],
218
226
  };
219
- const preKeyBundleMap = {
220
- [firstUser.id]: {
221
- [firstUser.clients.first]: validPreKey,
222
- [firstUser.clients.second]: validPreKey,
223
- },
224
- };
225
227
  const encryptedPayload = new Map([
226
228
  [firstUser.sessions.first, encryptedMessageBuffer],
227
229
  [firstUser.sessions.second, encryptedMessageBuffer],
228
230
  ]);
229
- jest
230
- .spyOn(services.apiClient.api.user, 'postMultiPreKeyBundles')
231
- .mockImplementationOnce(() => Promise.resolve(preKeyBundleMap));
232
- jest
233
- .spyOn(services.coreCryptoClient, 'proteusEncryptBatched')
234
- .mockImplementationOnce(() => Promise.resolve(encryptedPayload));
231
+ jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(true);
232
+ jest.spyOn(services.cryptoClient, 'encrypt').mockImplementationOnce(() => Promise.resolve(encryptedPayload));
235
233
  const encrypted = await services.proteusService.encrypt(messageBuffer, userClients);
236
- expect(services.coreCryptoClient.proteusEncryptBatched).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second], messageBuffer);
234
+ expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second], messageBuffer);
237
235
  expect(encrypted).toEqual({
238
236
  [firstUser.id]: {
239
237
  [firstUser.clients.first]: encryptedMessageBuffer,
@@ -242,33 +240,20 @@ describe('ProteusService', () => {
242
240
  });
243
241
  });
244
242
  it('returns encrypted payload for multiple users', async () => {
245
- const { services, data: { firstUser, secondUser, validPreKey, encryptedMessageBuffer, messageBuffer }, } = await prepareDataForEncryption(false);
243
+ const { services, data: { firstUser, secondUser, encryptedMessageBuffer, messageBuffer }, } = await prepareDataForEncryption(false);
246
244
  const userClients = {
247
245
  [firstUser.id]: [firstUser.clients.first, firstUser.clients.second],
248
246
  [secondUser.id]: [secondUser.clients.first],
249
247
  };
250
- const preKeyBundleMap = {
251
- [firstUser.id]: {
252
- [firstUser.clients.first]: validPreKey,
253
- [firstUser.clients.second]: null,
254
- },
255
- [secondUser.id]: {
256
- [secondUser.clients.first]: validPreKey,
257
- },
258
- };
259
248
  const encryptedPayload = new Map([
260
249
  [firstUser.sessions.first, encryptedMessageBuffer],
261
250
  [firstUser.sessions.second, encryptedMessageBuffer],
262
251
  [secondUser.sessions.first, encryptedMessageBuffer],
263
252
  ]);
264
- jest
265
- .spyOn(services.apiClient.api.user, 'postMultiPreKeyBundles')
266
- .mockImplementationOnce(() => Promise.resolve(preKeyBundleMap));
267
- jest
268
- .spyOn(services.coreCryptoClient, 'proteusEncryptBatched')
269
- .mockImplementationOnce(() => Promise.resolve(encryptedPayload));
253
+ jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(true);
254
+ jest.spyOn(services.cryptoClient, 'encrypt').mockResolvedValueOnce(encryptedPayload);
270
255
  const encrypted = await services.proteusService.encrypt(messageBuffer, userClients);
271
- expect(services.coreCryptoClient.proteusEncryptBatched).toHaveBeenCalledWith([firstUser.sessions.first, secondUser.sessions.first], messageBuffer);
256
+ expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second, secondUser.sessions.first], messageBuffer);
272
257
  expect(encrypted).toEqual({
273
258
  [firstUser.id]: {
274
259
  [firstUser.clients.first]: encryptedMessageBuffer,
@@ -282,33 +267,21 @@ describe('ProteusService', () => {
282
267
  });
283
268
  describe('"encryptQualified"', () => {
284
269
  it('returns encrypted payload', async () => {
285
- const { services, data: { firstUser, validPreKey, encryptedMessageBuffer, messageBuffer, domain }, } = await prepareDataForEncryption();
270
+ const { services, data: { firstUser, encryptedMessageBuffer, messageBuffer, domain }, } = await prepareDataForEncryption();
286
271
  const userClients = {
287
272
  [domain]: {
288
273
  [firstUser.id]: [firstUser.clients.first, firstUser.clients.second],
289
274
  },
290
275
  };
291
- const preKeyBundleMap = {
292
- [domain]: {
293
- [firstUser.id]: {
294
- [firstUser.clients.first]: validPreKey,
295
- [firstUser.clients.second]: validPreKey,
296
- },
297
- },
298
- };
299
276
  const encryptedPayload = new Map([
300
277
  [firstUser.sessions.first, encryptedMessageBuffer],
301
278
  [firstUser.sessions.second, encryptedMessageBuffer],
302
279
  ]);
303
- jest
304
- .spyOn(services.apiClient.api.user, 'postQualifiedMultiPreKeyBundles')
305
- .mockImplementationOnce(() => Promise.resolve(preKeyBundleMap));
306
- jest
307
- .spyOn(services.coreCryptoClient, 'proteusEncryptBatched')
308
- .mockImplementationOnce(() => Promise.resolve(encryptedPayload));
280
+ jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(true);
281
+ jest.spyOn(services.cryptoClient, 'encrypt').mockResolvedValueOnce(encryptedPayload);
309
282
  const encrypted = await services.proteusService.encryptQualified(messageBuffer, userClients);
310
283
  // console.log({encrypted, missing});
311
- expect(services.coreCryptoClient.proteusEncryptBatched).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second], messageBuffer);
284
+ expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second], messageBuffer);
312
285
  expect(encrypted).toEqual({
313
286
  [domain]: {
314
287
  [firstUser.id]: {
@@ -319,40 +292,27 @@ describe('ProteusService', () => {
319
292
  });
320
293
  });
321
294
  it('returns missing clients and encrypted payload for multiple users', async () => {
322
- const { services, data: { firstUser, secondUser, validPreKey, encryptedMessageBuffer, messageBuffer, domain }, } = await prepareDataForEncryption();
295
+ const { services, data: { firstUser, secondUser, encryptedMessageBuffer, messageBuffer, domain }, } = await prepareDataForEncryption();
323
296
  const userClients = {
324
297
  [domain]: {
325
298
  [firstUser.id]: [firstUser.clients.first, firstUser.clients.second],
326
299
  [secondUser.id]: [secondUser.clients.first],
327
300
  },
328
301
  };
329
- const preKeyBundleMap = {
330
- [domain]: {
331
- [firstUser.id]: {
332
- [firstUser.clients.first]: validPreKey,
333
- [firstUser.clients.second]: null,
334
- },
335
- [secondUser.id]: {
336
- [secondUser.clients.first]: validPreKey,
337
- },
338
- },
339
- };
340
302
  const encryptedPayload = new Map([
341
303
  [firstUser.sessions.first, encryptedMessageBuffer],
304
+ [firstUser.sessions.second, encryptedMessageBuffer],
342
305
  [secondUser.sessions.first, encryptedMessageBuffer],
343
306
  ]);
344
- jest
345
- .spyOn(services.apiClient.api.user, 'postQualifiedMultiPreKeyBundles')
346
- .mockImplementationOnce(() => Promise.resolve(preKeyBundleMap));
347
- jest
348
- .spyOn(services.coreCryptoClient, 'proteusEncryptBatched')
349
- .mockImplementationOnce(() => Promise.resolve(encryptedPayload));
307
+ jest.spyOn(services.cryptoClient, 'sessionExists').mockResolvedValue(true);
308
+ jest.spyOn(services.cryptoClient, 'encrypt').mockResolvedValueOnce(encryptedPayload);
350
309
  const encrypted = await services.proteusService.encryptQualified(messageBuffer, userClients);
351
- expect(services.coreCryptoClient.proteusEncryptBatched).toHaveBeenCalledWith([firstUser.sessions.first, secondUser.sessions.first], messageBuffer);
310
+ expect(services.cryptoClient.encrypt).toHaveBeenCalledWith([firstUser.sessions.first, firstUser.sessions.second, secondUser.sessions.first], messageBuffer);
352
311
  expect(encrypted).toEqual({
353
312
  [domain]: {
354
313
  [firstUser.id]: {
355
314
  [firstUser.clients.first]: encryptedMessageBuffer,
315
+ [firstUser.clients.second]: encryptedMessageBuffer,
356
316
  },
357
317
  [secondUser.id]: {
358
318
  [secondUser.clients.first]: encryptedMessageBuffer,
@@ -468,6 +428,30 @@ describe('ProteusService', () => {
468
428
  }));
469
429
  });
470
430
  });
431
+ it(`returns the recipients that could not receive the message`, async () => {
432
+ const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)(true);
433
+ const recipients = {
434
+ domain1: { user1: ['client1'], user2: ['client11', 'client12'] },
435
+ domain2: { user3: ['client3'] },
436
+ };
437
+ MockedRecipients.getQualifiedRecipientsForConversation.mockResolvedValue({});
438
+ jest.spyOn(proteusService['messageService'], 'sendFederatedMessage').mockResolvedValue({
439
+ missing: {},
440
+ redundant: {},
441
+ failed_to_send: { domain2: recipients.domain2 },
442
+ time: new Date().toISOString(),
443
+ deleted: {},
444
+ });
445
+ const result = await proteusService.sendMessage({
446
+ protocol: conversation_1.ConversationProtocol.PROTEUS,
447
+ conversationId: { id: 'conv1', domain: 'domain1' },
448
+ payload: message,
449
+ targetMode: conversation_2.MessageTargetMode.USERS_CLIENTS,
450
+ userIds: recipients,
451
+ });
452
+ expect(result.state).toBe(conversation_2.MessageSendingState.OUTGOING_SENT);
453
+ expect(result.failedToSend).toEqual({ domain2: recipients.domain2 });
454
+ });
471
455
  });
472
456
  });
473
457
  });
@@ -81,14 +81,14 @@ describe('sendGenericMessage', () => {
81
81
  });
82
82
  jest
83
83
  .spyOn(proteusService['messageService'], 'sendMessage')
84
- .mockReturnValue(Promise.resolve({ time: '', errored: true }));
84
+ .mockReturnValue(Promise.resolve({ time: '', canceled: true }));
85
85
  const message = (0, MessageBuilder_1.buildTextMessage)({ text: 'test' });
86
86
  const payloadBundle = await proteusService.sendMessage({
87
87
  payload: message,
88
88
  conversationId: { id: 'conv1', domain: '' },
89
89
  protocol: conversation_1.ConversationProtocol.PROTEUS,
90
90
  });
91
- expect(payloadBundle.state).toBe(conversation_2.MessageSendingState.CANCELLED);
91
+ expect(payloadBundle.state).toBe(conversation_2.MessageSendingState.CANCELED);
92
92
  });
93
93
  });
94
94
  });
@@ -1 +1 @@
1
- {"version":3,"file":"SessionHandler.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAC,WAAW,EAAC,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAE9E,OAAO,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAK9C,OAAO,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAC;AAE/D,UAAU,wBAAwB;IAChC,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,QAAA,MAAM,kBAAkB,kDAAiD,wBAAwB,KAAG,MAKnG,CAAC;AA2GF;;;GAGG;AACH,QAAA,MAAM,WAAW;YAC6B,WAAW;cAAY,MAAM;;;eAClC,SAAS;kBAAgB,YAAY;MAC3E,QAAQ,MAAM,CAYhB,CAAC;AAyBF,UAAU,wCAAwC;IAChD,UAAU,EAAE,WAAW,GAAG,mBAAmB,CAAC;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,QAAA,MAAM,YAAY,6DAMf,wCAAwC,KAAG,QAAQ,MAAM,EAAE,CAgC7D,CAAC;AAEF,UAAU,mBAAmB;IAC3B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;CAC1B;AACD,iBAAe,aAAa,CAAC,MAAM,EAAE,mBAAmB,iBAGvD;AA+CD,KAAK,iBAAiB,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D;;GAEG;AACH,QAAA,MAAM,sBAAsB,uDAO3B,CAAC;AAEF,OAAO,EAAC,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAC,CAAC"}
1
+ {"version":3,"file":"SessionHandler.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAC,WAAW,EAAC,MAAM,sCAAsC,CAAC;AACjE,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAC,MAAM,8BAA8B,CAAC;AAE9E,OAAO,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAK9C,OAAO,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAC;AAE/D,UAAU,wBAAwB;IAChC,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,QAAA,MAAM,kBAAkB,kDAAiD,wBAAwB,KAAG,MAKnG,CAAC;AAuFF;;;GAGG;AACH,QAAA,MAAM,WAAW;YAC6B,WAAW;cAAY,MAAM;;;eAClC,SAAS;kBAAgB,YAAY;MAC3E,QAAQ,MAAM,CAmBhB,CAAC;AAyBF,UAAU,wCAAwC;IAChD,UAAU,EAAE,WAAW,GAAG,mBAAmB,CAAC;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,QAAA,MAAM,YAAY,6DAMf,wCAAwC,KAAG,QAAQ,MAAM,EAAE,CAgC7D,CAAC;AAEF,UAAU,mBAAmB;IAC3B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;CAC1B;AACD,iBAAe,aAAa,CAAC,MAAM,EAAE,mBAAmB,iBAGvD;AA+CD,KAAK,iBAAiB,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAC9D;;GAEG;AACH,QAAA,MAAM,sBAAsB,uDAO3B,CAAC;AAEF,OAAO,EAAC,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAC,CAAC"}
@@ -43,13 +43,6 @@ const parseSessionId = (sessionId) => {
43
43
  }
44
44
  return match.groups;
45
45
  };
46
- const createSession = async ({ sessionId, initialPrekey, cryptoClient, apiClient, }) => {
47
- const { userId, clientId, domain } = parseSessionId(sessionId);
48
- const prekey = initialPrekey !== null && initialPrekey !== void 0 ? initialPrekey : (await apiClient.api.user.getClientPreKey({ id: userId, domain: domain !== null && domain !== void 0 ? domain : '' }, clientId)).prekey;
49
- const prekeyBuffer = bazinga64_1.Decoder.fromBase64(prekey.key).asBytes;
50
- await cryptoClient.sessionFromPrekey(sessionId, prekeyBuffer);
51
- await cryptoClient.saveSession(sessionId);
52
- };
53
46
  const createLegacySessions = async ({ userClients, apiClient, cryptoClient, logger, }) => {
54
47
  const preKeyBundleMap = await apiClient.api.user.postMultiPreKeyBundles(userClients);
55
48
  const sessions = await createSessionsFromPreKeys({
@@ -87,15 +80,22 @@ const createQualifiedSessions = async ({ userClientMap, domain, apiClient, crypt
87
80
  const initSession = async ({ userId, clientId, initialPrekey }, { cryptoClient, apiClient }) => {
88
81
  const sessionId = constructSessionId({ userId, clientId, useQualifiedIds: !!userId.domain });
89
82
  const sessionExists = await cryptoClient.sessionExists(sessionId);
90
- if (!sessionExists) {
91
- await createSession({
92
- sessionId,
93
- initialPrekey,
94
- apiClient: apiClient,
95
- cryptoClient,
96
- });
83
+ if (sessionExists) {
84
+ return sessionId;
85
+ }
86
+ if (initialPrekey) {
87
+ const prekeyBuffer = bazinga64_1.Decoder.fromBase64(initialPrekey.key).asBytes;
88
+ await cryptoClient.sessionFromPrekey(sessionId, prekeyBuffer);
89
+ await cryptoClient.saveSession(sessionId);
90
+ return sessionId;
97
91
  }
98
- return sessionId;
92
+ const sessions = await initSessions({
93
+ recipients: { [userId.id]: [clientId] },
94
+ domain: userId.domain,
95
+ apiClient,
96
+ cryptoClient,
97
+ });
98
+ return sessions[0];
99
99
  };
100
100
  exports.initSession = initSession;
101
101
  /**
@@ -18,10 +18,28 @@
18
18
  *
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
+ const api_client_1 = require("@wireapp/api-client");
21
22
  const SessionHandler_1 = require("./SessionHandler");
22
- const CoreCryptoWrapper_1 = require("../../ProteusService/CryptoClient/CoreCryptoWrapper");
23
- const ProteusService_mocks_1 = require("../../ProteusService/ProteusService.mocks");
23
+ function generatePrekeys(userId, clientIds) {
24
+ const clients = clientIds.reduce((prekeys, clientId, index) => {
25
+ return Object.assign(Object.assign({}, prekeys), { [clientId]: {
26
+ id: index,
27
+ key: 'pQABARn//wKhAFggJ1Fbpg5l6wnzKOJE+vXpRnkqUYhIvVnR5lNXEbO2o/0DoQChAFggHxZvgvtDktY/vqBcpjjo6rQnXvcNQhfwmy8AJQJKlD0E9g==',
28
+ } });
29
+ }, {});
30
+ return {
31
+ [userId.id]: Object.assign({}, clients),
32
+ };
33
+ }
24
34
  describe('SessionHandler', () => {
35
+ const cryptoClient = {
36
+ sessionFromMessage: jest.fn(),
37
+ sessionFromPrekey: jest.fn(),
38
+ sessionExists: jest.fn(),
39
+ saveSession: jest.fn(),
40
+ deleteSession: jest.fn(),
41
+ };
42
+ const apiClient = new api_client_1.APIClient({ urls: api_client_1.APIClient.BACKEND.STAGING });
25
43
  describe('constructSessionId', () => {
26
44
  describe('constructs a session ID', () => {
27
45
  it('without a domain', () => {
@@ -66,35 +84,42 @@ describe('SessionHandler', () => {
66
84
  });
67
85
  describe('initSession', () => {
68
86
  it('only returns sessions that already exists', async () => {
69
- const { apiClient, coreCrypto } = (await (0, ProteusService_mocks_1.buildProteusService)())[1];
70
- jest.spyOn(coreCrypto, 'proteusSessionExists').mockResolvedValue(true);
71
- const sessionFromPrekeySpy = jest.spyOn(coreCrypto, 'proteusSessionFromPrekey');
72
- await (0, SessionHandler_1.initSession)({ userId: { id: 'user1', domain: 'domain' }, clientId: 'client1' }, { apiClient, cryptoClient: new CoreCryptoWrapper_1.CoreCryptoWrapper(coreCrypto, {}, {}) });
73
- expect(sessionFromPrekeySpy).not.toHaveBeenCalled();
87
+ jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(true);
88
+ await (0, SessionHandler_1.initSession)({ userId: { id: 'user1', domain: 'domain' }, clientId: 'client1' }, { apiClient, cryptoClient });
89
+ expect(cryptoClient.sessionFromPrekey).not.toHaveBeenCalled();
74
90
  });
75
91
  it('creates the session if it does not already exist', async () => {
76
- const { apiClient, coreCrypto } = (await (0, ProteusService_mocks_1.buildProteusService)())[1];
77
- jest.spyOn(coreCrypto, 'proteusSessionExists').mockResolvedValue(false);
78
- jest.spyOn(apiClient.api.user, 'getClientPreKey').mockResolvedValue({
79
- prekey: {
80
- id: 1,
81
- key: 'pQABARn//wKhAFggJ1Fbpg5l6wnzKOJE+vXpRnkqUYhIvVnR5lNXEbO2o/0DoQChAFggHxZvgvtDktY/vqBcpjjo6rQnXvcNQhfwmy8AJQJKlD0E9g==',
82
- },
83
- client: 'client1',
92
+ const userId = { id: 'user1', domain: 'domain' };
93
+ const clientId = 'client1';
94
+ jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(false);
95
+ jest
96
+ .spyOn(apiClient.api.user, 'postQualifiedMultiPreKeyBundles')
97
+ .mockResolvedValue({ domain: generatePrekeys(userId, [clientId]) });
98
+ const sessionId = (0, SessionHandler_1.constructSessionId)({
99
+ userId,
100
+ clientId,
101
+ useQualifiedIds: true,
84
102
  });
103
+ await (0, SessionHandler_1.initSession)({ userId, clientId }, { apiClient, cryptoClient });
104
+ expect(cryptoClient.sessionFromPrekey).toHaveBeenCalledWith(sessionId, expect.any(Object));
105
+ });
106
+ it('indicates the consumer if a session could not be created', async () => {
107
+ const userId = { id: 'user1', domain: 'domain' };
108
+ const clientId = 'client1';
109
+ jest
110
+ .spyOn(apiClient.api.user, 'postQualifiedMultiPreKeyBundles')
111
+ .mockResolvedValue({ domain: generatePrekeys(userId, [clientId]) });
85
112
  const sessionId = (0, SessionHandler_1.constructSessionId)({
86
- userId: { id: 'user1', domain: 'domain' },
87
- clientId: 'client1',
113
+ userId,
114
+ clientId,
88
115
  useQualifiedIds: true,
89
116
  });
90
- const sessionFromPrekeySpy = jest.spyOn(coreCrypto, 'proteusSessionFromPrekey');
91
- await (0, SessionHandler_1.initSession)({ userId: { id: 'user1', domain: 'domain' }, clientId: 'client1' }, { apiClient, cryptoClient: new CoreCryptoWrapper_1.CoreCryptoWrapper(coreCrypto, {}, {}) });
92
- expect(sessionFromPrekeySpy).toHaveBeenCalledWith(sessionId, expect.any(Object));
117
+ await (0, SessionHandler_1.initSession)({ userId, clientId }, { apiClient, cryptoClient });
118
+ expect(cryptoClient.sessionFromPrekey).toHaveBeenCalledWith(sessionId, expect.any(Object));
93
119
  });
94
120
  });
95
121
  describe('initSessions', () => {
96
122
  it('creates new sessions only for sessions that are missing', async () => {
97
- const { apiClient, coreCrypto } = (await (0, ProteusService_mocks_1.buildProteusService)())[1];
98
123
  const existingUserClients = {
99
124
  'existing-user1': ['client1'],
100
125
  'existing-user2': ['client1', 'client2'],
@@ -104,32 +129,15 @@ describe('SessionHandler', () => {
104
129
  'missing-user2': ['client1', 'client2'],
105
130
  };
106
131
  jest.spyOn(apiClient.api.user, 'postQualifiedMultiPreKeyBundles').mockResolvedValue({});
107
- jest.spyOn(apiClient.api.user, 'postMultiPreKeyBundles').mockResolvedValue({
108
- 'missing-user1': {
109
- client1: {
110
- id: 1,
111
- key: 'pQABARn//wKhAFggJ1Fbpg5l6wnzKOJE+vXpRnkqUYhIvVnR5lNXEbO2o/0DoQChAFggHxZvgvtDktY/vqBcpjjo6rQnXvcNQhfwmy8AJQJKlD0E9g==',
112
- },
113
- },
114
- 'missing-user2': {
115
- client1: {
116
- id: 1,
117
- key: 'pQABARn//wKhAFggJ1Fbpg5l6wnzKOJE+vXpRnkqUYhIvVnR5lNXEbO2o/0DoQChAFggHxZvgvtDktY/vqBcpjjo6rQnXvcNQhfwmy8AJQJKlD0E9g==',
118
- },
119
- client2: {
120
- id: 1,
121
- key: 'pQABARn//wKhAFggJ1Fbpg5l6wnzKOJE+vXpRnkqUYhIvVnR5lNXEbO2o/0DoQChAFggHxZvgvtDktY/vqBcpjjo6rQnXvcNQhfwmy8AJQJKlD0E9g==',
122
- },
123
- },
124
- });
132
+ jest.spyOn(apiClient.api.user, 'postMultiPreKeyBundles').mockResolvedValue(Object.assign(Object.assign({}, generatePrekeys({ id: 'missing-user1', domain: '' }, ['client1'])), generatePrekeys({ id: 'missing-user2', domain: '' }, ['client1', 'client2'])));
125
133
  jest
126
- .spyOn(coreCrypto, 'proteusSessionExists')
134
+ .spyOn(cryptoClient, 'sessionExists')
127
135
  .mockImplementation(sessionId => Promise.resolve(sessionId.includes('missing')));
128
- const sessionFromPrekeySpy = jest.spyOn(coreCrypto, 'proteusSessionFromPrekey');
136
+ const sessionFromPrekeySpy = jest.spyOn(cryptoClient, 'sessionFromPrekey');
129
137
  const sessions = await (0, SessionHandler_1.initSessions)({
130
138
  recipients: Object.assign(Object.assign({}, existingUserClients), missingUserClients),
131
139
  apiClient,
132
- cryptoClient: new CoreCryptoWrapper_1.CoreCryptoWrapper(coreCrypto, {}, {}),
140
+ cryptoClient,
133
141
  });
134
142
  expect(sessionFromPrekeySpy).toHaveBeenCalledTimes(3);
135
143
  expect(sessions).toHaveLength(6);
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "./lib/cryptography/AssetCryptography/crypto.node": "./lib/cryptography/AssetCryptography/crypto.browser.js"
12
12
  },
13
13
  "dependencies": {
14
- "@wireapp/api-client": "^22.15.0",
14
+ "@wireapp/api-client": "^22.15.1",
15
15
  "@wireapp/commons": "^5.0.4",
16
16
  "@wireapp/core-crypto": "0.6.0-rc.3",
17
17
  "@wireapp/cryptobox": "12.8.0",
@@ -19,7 +19,7 @@
19
19
  "@wireapp/protocol-messaging": "1.44.0",
20
20
  "@wireapp/store-engine": "5.0.3",
21
21
  "@wireapp/store-engine-dexie": "^2.0.5",
22
- "axios": "1.2.6",
22
+ "axios": "1.3.0",
23
23
  "bazinga64": "6.0.3",
24
24
  "hash.js": "1.1.7",
25
25
  "http-status-codes": "2.2.0",
@@ -60,6 +60,6 @@
60
60
  "test:coverage": "jest --coverage",
61
61
  "watch": "tsc --watch"
62
62
  },
63
- "version": "38.8.2",
64
- "gitHead": "a3496f10bd03a239ba33affb747c3c9edf087599"
63
+ "version": "38.9.0",
64
+ "gitHead": "5f56977765637ca340d3934a66b89ec738db614a"
65
65
  }