@wireapp/core 46.13.1 → 46.14.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.
@@ -386,9 +386,9 @@ describe('ConversationService', () => {
386
386
  const conversationId = { id: 'conversationId', domain: 'staging.zinfra.io' };
387
387
  const mockGroupId = 'mock-group-id';
388
388
  const mockMLSMessageAddEvent = createMLSMessageAddEventMock(conversationId);
389
- jest
390
- .spyOn(mlsService, 'handleMLSMessageAddEvent')
391
- .mockRejectedValueOnce(new Error(CoreCryptoMLSError_1.CoreCryptoMLSError.DECRYPTION.WRONG_EPOCH));
389
+ const wrongEpochError = new Error();
390
+ wrongEpochError.name = CoreCryptoMLSError_1.CORE_CRYPTO_ERROR_NAMES.MlsErrorWrongEpoch;
391
+ jest.spyOn(mlsService, 'handleMLSMessageAddEvent').mockRejectedValueOnce(wrongEpochError);
392
392
  const remoteEpoch = 5;
393
393
  const localEpoch = 4;
394
394
  jest.spyOn(mlsService, 'conversationExists').mockResolvedValueOnce(true);
@@ -409,9 +409,9 @@ describe('ConversationService', () => {
409
409
  const conversationId = { id: 'conversationId', domain: 'staging.zinfra.io' };
410
410
  const mockGroupId = 'mock-group-id';
411
411
  const mockMLSMessageAddEvent = createMLSMessageAddEventMock(conversationId, conversation_1.SUBCONVERSATION_ID.CONFERENCE);
412
- jest
413
- .spyOn(mlsService, 'handleMLSMessageAddEvent')
414
- .mockRejectedValueOnce(new Error(CoreCryptoMLSError_1.CoreCryptoMLSError.DECRYPTION.WRONG_EPOCH));
412
+ const wrongEpochError = new Error();
413
+ wrongEpochError.name = CoreCryptoMLSError_1.CORE_CRYPTO_ERROR_NAMES.MlsErrorWrongEpoch;
414
+ jest.spyOn(mlsService, 'handleMLSMessageAddEvent').mockRejectedValueOnce(wrongEpochError);
415
415
  const remoteEpoch = 5;
416
416
  const localEpoch = 4;
417
417
  jest.spyOn(mlsService, 'conversationExists').mockResolvedValueOnce(true);
@@ -432,9 +432,9 @@ describe('ConversationService', () => {
432
432
  const [conversationService, { apiClient, mlsService }] = await buildConversationService();
433
433
  const conversationId = { id: 'conversationId', domain: 'staging.zinfra.io' };
434
434
  const mockMLSWelcomeMessageEvent = createMLSWelcomeMessageEventMock(conversationId);
435
- jest
436
- .spyOn(mlsService, 'handleMLSWelcomeMessageEvent')
437
- .mockRejectedValueOnce(new Error(CoreCryptoMLSError_1.CoreCryptoMLSError.ORPHAN_WELCOME_MESSAGE));
435
+ const orphanWelcomeMessageError = new Error();
436
+ orphanWelcomeMessageError.name = CoreCryptoMLSError_1.CORE_CRYPTO_ERROR_NAMES.MlsErrorOrphanWelcomeMessage;
437
+ jest.spyOn(mlsService, 'handleMLSWelcomeMessageEvent').mockRejectedValueOnce(orphanWelcomeMessageError);
438
438
  jest.spyOn(apiClient.api.conversation, 'getConversation').mockResolvedValueOnce({
439
439
  qualified_id: conversationId,
440
440
  protocol: conversation_1.ConversationProtocol.MLS,
@@ -1,15 +1,17 @@
1
- export declare const CoreCryptoMLSError: {
2
- readonly DECRYPTION: {
3
- readonly WRONG_EPOCH: "Incoming message is for the wrong epoch";
4
- readonly ALREADY_DECRYPTED: "We already decrypted this message once";
5
- readonly EXTERNAL_COMMIT_NOT_MERGED: "You tried to join with an external commit but did not merge it yet. We will reapply this message for you when you merge your external commit";
6
- readonly FUTURE_EPOCH: "Incoming message is for a future epoch. We will buffer it until the commit for that epoch arrives";
7
- readonly STALE_COMMIT: "The received commit is deemed stale and is from an older epoch.";
8
- readonly STALE_PROPOSAL: "The received proposal is deemed stale and is from an older epoch.";
9
- readonly DUPLICATE_MESSAGE: "We already decrypted this message once";
10
- };
11
- readonly CONVERSATION_ALREADY_EXISTS: "Conversation already exists";
12
- readonly ORPHAN_WELCOME_MESSAGE: "Although this Welcome seems valid, the local KeyPackage it references has already been deleted locally. Join this group with an external commit";
1
+ export declare const CORE_CRYPTO_ERROR_NAMES: {
2
+ MlsErrorConversationAlreadyExists: string;
3
+ MlsErrorDuplicateMessage: string;
4
+ MlsErrorBufferedFutureMessage: string;
5
+ MlsErrorMessageEpochTooOld: string;
6
+ MlsErrorSelfCommitIgnored: string;
7
+ MlsErrorUnmergedPendingGroup: string;
8
+ MlsErrorStaleProposal: string;
9
+ MlsErrorStaleCommit: string;
10
+ MlsErrorOther: string;
11
+ ProteusErrorSessionNotFound: string;
12
+ ProteusErrorRemoteIdentityChanged: string;
13
+ MlsErrorWrongEpoch: string;
14
+ MlsErrorOrphanWelcomeMessage: string;
13
15
  };
14
16
  export declare const isCoreCryptoMLSWrongEpochError: (error: unknown) => boolean;
15
17
  export declare const isCoreCryptoMLSConversationAlreadyExistsError: (error: unknown) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"CoreCryptoMLSError.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/mls/MLSService/CoreCryptoMLSError.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,kBAAkB;;;;;;;;;;;;CAcrB,CAAC;AAEX,eAAO,MAAM,8BAA8B,UAAW,OAAO,KAAG,OAE/D,CAAC;AAEF,eAAO,MAAM,6CAA6C,UAAW,OAAO,KAAG,OAE9E,CAAC;AAEF,eAAO,MAAM,wCAAwC,UAAW,OAAO,KAAG,OAEzE,CAAC;AAWF,eAAO,MAAM,iCAAiC,UAAW,OAAO,KAAG,KAAK,IAAI,KAE3E,CAAC"}
1
+ {"version":3,"file":"CoreCryptoMLSError.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/mls/MLSService/CoreCryptoMLSError.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;CAcnC,CAAC;AAEF,eAAO,MAAM,8BAA8B,UAAW,OAAO,KAAG,OAE/D,CAAC;AAEF,eAAO,MAAM,6CAA6C,UAAW,OAAO,KAAG,OAE9E,CAAC;AAEF,eAAO,MAAM,wCAAwC,UAAW,OAAO,KAAG,OAEzE,CAAC;AAUF,eAAO,MAAM,iCAAiC,UAAW,OAAO,KAAG,KAAK,IAAI,KAE3E,CAAC"}
@@ -18,41 +18,42 @@
18
18
  *
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.shouldMLSDecryptionErrorBeIgnored = exports.isCoreCryptoMLSOrphanWelcomeMessageError = exports.isCoreCryptoMLSConversationAlreadyExistsError = exports.isCoreCryptoMLSWrongEpochError = exports.CoreCryptoMLSError = void 0;
22
- exports.CoreCryptoMLSError = {
23
- DECRYPTION: {
24
- WRONG_EPOCH: 'Incoming message is for the wrong epoch',
25
- ALREADY_DECRYPTED: 'We already decrypted this message once',
26
- EXTERNAL_COMMIT_NOT_MERGED: 'You tried to join with an external commit but did not merge it yet. We will reapply this message for you when you merge your external commit',
27
- FUTURE_EPOCH: 'Incoming message is for a future epoch. We will buffer it until the commit for that epoch arrives',
28
- STALE_COMMIT: 'The received commit is deemed stale and is from an older epoch.',
29
- STALE_PROPOSAL: 'The received proposal is deemed stale and is from an older epoch.',
30
- DUPLICATE_MESSAGE: 'We already decrypted this message once',
31
- },
32
- CONVERSATION_ALREADY_EXISTS: 'Conversation already exists',
33
- ORPHAN_WELCOME_MESSAGE: 'Although this Welcome seems valid, the local KeyPackage it references has already been deleted locally. Join this group with an external commit',
21
+ exports.shouldMLSDecryptionErrorBeIgnored = exports.isCoreCryptoMLSOrphanWelcomeMessageError = exports.isCoreCryptoMLSConversationAlreadyExistsError = exports.isCoreCryptoMLSWrongEpochError = exports.CORE_CRYPTO_ERROR_NAMES = void 0;
22
+ exports.CORE_CRYPTO_ERROR_NAMES = {
23
+ MlsErrorConversationAlreadyExists: 'MlsErrorConversationAlreadyExists',
24
+ MlsErrorDuplicateMessage: 'MlsErrorDuplicateMessage',
25
+ MlsErrorBufferedFutureMessage: 'MlsErrorBufferedFutureMessage',
26
+ MlsErrorMessageEpochTooOld: 'MlsErrorMessageEpochTooOld',
27
+ MlsErrorSelfCommitIgnored: 'MlsErrorSelfCommitIgnored',
28
+ MlsErrorUnmergedPendingGroup: 'MlsErrorUnmergedPendingGroup',
29
+ MlsErrorStaleProposal: 'MlsErrorStaleProposal',
30
+ MlsErrorStaleCommit: 'MlsErrorStaleCommit',
31
+ MlsErrorOther: 'MlsErrorOther',
32
+ ProteusErrorSessionNotFound: 'ProteusErrorSessionNotFound',
33
+ ProteusErrorRemoteIdentityChanged: 'ProteusErrorRemoteIdentityChanged',
34
+ MlsErrorWrongEpoch: 'MlsErrorWrongEpoch',
35
+ MlsErrorOrphanWelcomeMessage: 'MlsErrorOrphanWelcomeMessage',
34
36
  };
35
37
  const isCoreCryptoMLSWrongEpochError = (error) => {
36
- return error instanceof Error && error.message === exports.CoreCryptoMLSError.DECRYPTION.WRONG_EPOCH;
38
+ return error instanceof Error && error.name === exports.CORE_CRYPTO_ERROR_NAMES.MlsErrorWrongEpoch;
37
39
  };
38
40
  exports.isCoreCryptoMLSWrongEpochError = isCoreCryptoMLSWrongEpochError;
39
41
  const isCoreCryptoMLSConversationAlreadyExistsError = (error) => {
40
- return error instanceof Error && error.message === exports.CoreCryptoMLSError.CONVERSATION_ALREADY_EXISTS;
42
+ return error instanceof Error && error.name === exports.CORE_CRYPTO_ERROR_NAMES.MlsErrorConversationAlreadyExists;
41
43
  };
42
44
  exports.isCoreCryptoMLSConversationAlreadyExistsError = isCoreCryptoMLSConversationAlreadyExistsError;
43
45
  const isCoreCryptoMLSOrphanWelcomeMessageError = (error) => {
44
- return error instanceof Error && error.message === exports.CoreCryptoMLSError.ORPHAN_WELCOME_MESSAGE;
46
+ return error instanceof Error && error.name === exports.CORE_CRYPTO_ERROR_NAMES.MlsErrorOrphanWelcomeMessage;
45
47
  };
46
48
  exports.isCoreCryptoMLSOrphanWelcomeMessageError = isCoreCryptoMLSOrphanWelcomeMessageError;
47
- const mlsDecryptionErrorsToIgnore = [
48
- exports.CoreCryptoMLSError.DECRYPTION.ALREADY_DECRYPTED,
49
- exports.CoreCryptoMLSError.DECRYPTION.EXTERNAL_COMMIT_NOT_MERGED,
50
- exports.CoreCryptoMLSError.DECRYPTION.FUTURE_EPOCH,
51
- exports.CoreCryptoMLSError.DECRYPTION.STALE_COMMIT,
52
- exports.CoreCryptoMLSError.DECRYPTION.STALE_PROPOSAL,
53
- exports.CoreCryptoMLSError.DECRYPTION.DUPLICATE_MESSAGE,
49
+ const mlsDecryptionErrorNamesToIgnore = [
50
+ exports.CORE_CRYPTO_ERROR_NAMES.MlsErrorStaleCommit,
51
+ exports.CORE_CRYPTO_ERROR_NAMES.MlsErrorStaleProposal,
52
+ exports.CORE_CRYPTO_ERROR_NAMES.MlsErrorDuplicateMessage,
53
+ exports.CORE_CRYPTO_ERROR_NAMES.MlsErrorBufferedFutureMessage,
54
+ exports.CORE_CRYPTO_ERROR_NAMES.MlsErrorUnmergedPendingGroup,
54
55
  ];
55
56
  const shouldMLSDecryptionErrorBeIgnored = (error) => {
56
- return error instanceof Error && mlsDecryptionErrorsToIgnore.includes(error.message);
57
+ return error instanceof Error && mlsDecryptionErrorNamesToIgnore.includes(error.name);
57
58
  };
58
59
  exports.shouldMLSDecryptionErrorBeIgnored = shouldMLSDecryptionErrorBeIgnored;
@@ -570,9 +570,9 @@ describe('MLSService', () => {
570
570
  const [mlsService] = await createMLSService();
571
571
  const mockGroupId = 'mock-group-id';
572
572
  jest.spyOn(mlsService, 'conversationExists').mockResolvedValueOnce(false);
573
- jest
574
- .spyOn(mlsService, 'registerConversation')
575
- .mockRejectedValueOnce(new Error(CoreCryptoMLSError_1.CoreCryptoMLSError.CONVERSATION_ALREADY_EXISTS));
573
+ const conversationAlreadyExistsError = new Error();
574
+ conversationAlreadyExistsError.name = CoreCryptoMLSError_1.CORE_CRYPTO_ERROR_NAMES.MlsErrorConversationAlreadyExists;
575
+ jest.spyOn(mlsService, 'registerConversation').mockRejectedValueOnce(conversationAlreadyExistsError);
576
576
  const wasConversationEstablished = await mlsService.tryEstablishingMLSGroup(mockGroupId);
577
577
  expect(mlsService.registerConversation).toHaveBeenCalledWith(mockGroupId, []);
578
578
  expect(wasConversationEstablished).toBe(false);
@@ -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;AAItD,OAAO,EAAoB,YAAY,EAAC,MAAM,+CAA+C,CAAC;AAC9F,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAEnD,KAAK,MAAM,GAAG;IACZ,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC1C,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,KAAK,YAAY,GAAG,IAAI,CAAC,MAAM,EAAE,mBAAmB,GAAG,cAAc,CAAC,GAAG;IACvE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AAEF,wBAAsB,WAAW,CAC/B,WAAW,EAAE,UAAU,EACvB,EAAC,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAC,EAAE,MAAM,GACjE,OAAO,CAAC,iBAAiB,CAAC,CAqB5B;AAED,qBAAa,iBAAkB,YAAW,YAAY;IAKlD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IALzB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,SAAgB,OAAO,EAAE,MAAM,CAAC;gBAGb,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,YAAY;IAMvC,eAAe;IAIf,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,UAAU;IAIjD,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU;IAI9C,IAAI,CAAC,gBAAgB,CAAC,EAAE,MAAM;IAOxB,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU;;;;;;;IAqBpD,cAAc;IAId,oBAAoB,CAAC,SAAS,EAAE,MAAM;IAIhC,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU;IAK/D,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAIvD,aAAa,CAAC,SAAS,EAAE,MAAM;IAI/B,WAAW,CAAC,SAAS,EAAE,MAAM;IAI7B,aAAa,CAAC,SAAS,EAAE,MAAM;IAI/B,aAAa;IAIP,SAAS;;;;IAKT,iBAAiB,CAAC,SAAS,EAAE,MAAM;IAUnC,kBAAkB;IAIlB,oBAAoB,CAAC,MAAM,EAAE,MAAM;IAIzC;;;;OAIG;IACH,OAAO,CAAC,OAAO;IAgBT,IAAI;CAIX"}
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;AAKpD,OAAO,EAAC,UAAU,EAAgD,MAAM,sBAAsB,CAAC;AAC/F,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAItD,OAAO,EAAoB,YAAY,EAAC,MAAM,+CAA+C,CAAC;AAC9F,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AAEnD,KAAK,MAAM,GAAG;IACZ,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5D,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC1C,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,KAAK,YAAY,GAAG,IAAI,CAAC,MAAM,EAAE,mBAAmB,GAAG,cAAc,CAAC,GAAG;IACvE,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AAmBF,wBAAsB,WAAW,CAC/B,WAAW,EAAE,UAAU,EACvB,EAAC,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,YAAY,EAAC,EAAE,MAAM,GACjE,OAAO,CAAC,iBAAiB,CAAC,CAyB5B;AAED,qBAAa,iBAAkB,YAAW,YAAY;IAKlD,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IALzB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,SAAgB,OAAO,EAAE,MAAM,CAAC;gBAGb,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,YAAY;IAMvC,eAAe;IAIf,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,UAAU;IAIjD,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU;IAI9C,IAAI,CAAC,gBAAgB,CAAC,EAAE,MAAM;IAOxB,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU;;;;;;;IAqBpD,cAAc;IAId,oBAAoB,CAAC,SAAS,EAAE,MAAM;IAIhC,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU;IAK/D,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU;IAIvD,aAAa,CAAC,SAAS,EAAE,MAAM;IAI/B,WAAW,CAAC,SAAS,EAAE,MAAM;IAI7B,aAAa,CAAC,SAAS,EAAE,MAAM;IAI/B,aAAa;IAIP,SAAS;;;;IAKT,iBAAiB,CAAC,SAAS,EAAE,MAAM;IAUnC,kBAAkB;IAIlB,oBAAoB,CAAC,MAAM,EAAE,MAAM;IAIzC;;;;OAIG;IACH,OAAO,CAAC,OAAO;IAgBT,IAAI;CAIX"}
@@ -22,9 +22,24 @@ exports.CoreCryptoWrapper = void 0;
22
22
  exports.buildClient = buildClient;
23
23
  const bazinga64_1 = require("bazinga64");
24
24
  const idb_1 = require("idb");
25
+ const commons_1 = require("@wireapp/commons");
25
26
  const core_crypto_1 = require("@wireapp/core-crypto");
26
27
  const PrekeysTracker_1 = require("./PrekeysTracker");
27
28
  const secretKeyGenerator_1 = require("../../../../../secretStore/secretKeyGenerator");
29
+ const logger = commons_1.LogFactory.getLogger('@wireapp/core/CoreCryptoWrapper');
30
+ const logFunctions = {
31
+ 1: logger.debug,
32
+ 2: logger.debug,
33
+ 3: logger.debug,
34
+ 4: logger.info,
35
+ 5: logger.warn,
36
+ 6: logger.error,
37
+ };
38
+ const coreCryptoLogger = {
39
+ log: (level, message, context) => {
40
+ logFunctions[level].call(logger, { message, context });
41
+ },
42
+ };
28
43
  async function buildClient(storeEngine, { wasmFilePath, generateSecretKey, nbPrekeys, onNewPrekeys }) {
29
44
  let key;
30
45
  const coreCryptoDbName = `corecrypto-${storeEngine.storeName}`;
@@ -47,6 +62,8 @@ async function buildClient(storeEngine, { wasmFilePath, generateSecretKey, nbPre
47
62
  key: bazinga64_1.Encoder.toBase64(key.key).asString,
48
63
  wasmFilePath,
49
64
  });
65
+ (0, core_crypto_1.setLogger)(coreCryptoLogger);
66
+ (0, core_crypto_1.setMaxLogLevel)(core_crypto_1.CoreCryptoLogLevel.Info);
50
67
  return new CoreCryptoWrapper(coreCrypto, { nbPrekeys, onNewPrekeys, onWipe: key.deleteKey });
51
68
  }
52
69
  class CoreCryptoWrapper {
@@ -1,12 +1,18 @@
1
1
  import { QualifiedId } from '@wireapp/api-client/lib/user';
2
2
  import { DecryptionError } from '../../../../errors/DecryptionError';
3
3
  export declare const ProteusErrors: {
4
+ readonly SessionNotFound: 102;
4
5
  readonly InvalidMessage: 201;
5
6
  readonly RemoteIdentityChanged: 204;
6
7
  readonly InvalidSignature: 207;
7
8
  readonly DuplicateMessage: 209;
8
9
  readonly Unknown: 999;
9
10
  };
11
+ export declare const CORE_CRYPTO_PROTEUS_ERROR_NAMES: {
12
+ ProteusErrorSessionNotFound: string;
13
+ ProteusErrorRemoteIdentityChanged: string;
14
+ ProteusErrorDuplicateMessage: string;
15
+ };
10
16
  type SenderInfo = {
11
17
  clientId: string;
12
18
  userId: QualifiedId;
@@ -1 +1 @@
1
- {"version":3,"file":"DecryptionErrorGenerator.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/ProteusService/DecryptionErrorGenerator/DecryptionErrorGenerator.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAIzD,OAAO,EAAC,eAAe,EAAC,MAAM,oCAAoC,CAAC;AAEnE,eAAO,MAAM,aAAa;;;;;;CAMhB,CAAC;AAWX,KAAK,UAAU,GAAG;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAC,CAAC;AAC1D,eAAO,MAAM,uBAAuB,eAAgB,UAAU,SAAS,GAAG,KAAG,eAW5E,CAAC"}
1
+ {"version":3,"file":"DecryptionErrorGenerator.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/ProteusService/DecryptionErrorGenerator/DecryptionErrorGenerator.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAIzD,OAAO,EAAC,eAAe,EAAC,MAAM,oCAAoC,CAAC;AAEnE,eAAO,MAAM,aAAa;;;;;;;CAOhB,CAAC;AAYX,eAAO,MAAM,+BAA+B;;;;CAI3C,CAAC;AAEF,KAAK,UAAU,GAAG;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAC,CAAC;AA0B1D,eAAO,MAAM,uBAAuB,eAAgB,UAAU,SAAS,GAAG,KAAG,eAS5E,CAAC"}
@@ -18,9 +18,10 @@
18
18
  *
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.generateDecryptionError = exports.ProteusErrors = void 0;
21
+ exports.generateDecryptionError = exports.CORE_CRYPTO_PROTEUS_ERROR_NAMES = exports.ProteusErrors = void 0;
22
22
  const DecryptionError_1 = require("../../../../errors/DecryptionError");
23
23
  exports.ProteusErrors = {
24
+ SessionNotFound: 102,
24
25
  InvalidMessage: 201,
25
26
  RemoteIdentityChanged: 204,
26
27
  InvalidSignature: 207,
@@ -33,13 +34,34 @@ const isCoreCryptoError = (error) => {
33
34
  const isCryptoboxError = (error) => {
34
35
  return 'code' in error;
35
36
  };
37
+ exports.CORE_CRYPTO_PROTEUS_ERROR_NAMES = {
38
+ ProteusErrorSessionNotFound: 'ProteusErrorSessionNotFound',
39
+ ProteusErrorRemoteIdentityChanged: 'ProteusErrorRemoteIdentityChanged',
40
+ ProteusErrorDuplicateMessage: 'ProteusErrorDuplicateMessage',
41
+ };
42
+ function getErrorCode(error) {
43
+ if (isCoreCryptoError(error) && typeof error.proteusErrorCode === 'number') {
44
+ return error.proteusErrorCode;
45
+ }
46
+ if (isCryptoboxError(error) && typeof error.code === 'number') {
47
+ return error.code;
48
+ }
49
+ if (error.name === exports.CORE_CRYPTO_PROTEUS_ERROR_NAMES.ProteusErrorSessionNotFound) {
50
+ return exports.ProteusErrors.SessionNotFound;
51
+ }
52
+ if (error.name === exports.CORE_CRYPTO_PROTEUS_ERROR_NAMES.ProteusErrorRemoteIdentityChanged) {
53
+ return exports.ProteusErrors.RemoteIdentityChanged;
54
+ }
55
+ if (error.name === exports.CORE_CRYPTO_PROTEUS_ERROR_NAMES.ProteusErrorDuplicateMessage) {
56
+ return exports.ProteusErrors.DuplicateMessage;
57
+ }
58
+ return exports.ProteusErrors.Unknown;
59
+ }
36
60
  const generateDecryptionError = (senderInfo, error) => {
37
61
  const { clientId, userId } = senderInfo;
38
62
  const sender = `${userId.id} (${clientId})`;
39
- const coreCryptoCode = isCoreCryptoError(error) ? error.proteusErrorCode : null;
40
- const cryptoboxCode = isCryptoboxError(error) ? error.code : null;
41
- const code = coreCryptoCode ?? cryptoboxCode ?? exports.ProteusErrors.Unknown;
42
- const message = `Decryption error from ${sender} (${error.message})`;
63
+ const code = getErrorCode(error);
64
+ const message = `Decryption error from ${sender} (name: ${error.name}) (message: ${error.message})`;
43
65
  return new DecryptionError_1.DecryptionError(message, code);
44
66
  };
45
67
  exports.generateDecryptionError = generateDecryptionError;
@@ -26,14 +26,14 @@ describe('generateDecryptionError', () => {
26
26
  const coreCryptoError = { proteusErrorCode, message: 'decryption error' };
27
27
  const error = (0, DecryptionErrorGenerator_1.generateDecryptionError)(basePayload, coreCryptoError);
28
28
  expect(error).toBeInstanceOf(DecryptionError_1.DecryptionError);
29
- expect(error.message).toBe(`Decryption error from user1 (client1) (${coreCryptoError.message})`);
29
+ expect(error.message).toBe(`Decryption error from user1 (client1) (name: undefined) (message: ${coreCryptoError.message})`);
30
30
  expect(error.code).toBe(coreCryptoError.proteusErrorCode);
31
31
  });
32
32
  it.each([Math.floor(Math.random() * 100), 0])('handles cryptobox error', code => {
33
33
  const coreCryptoError = { code, message: 'decryption error' };
34
34
  const error = (0, DecryptionErrorGenerator_1.generateDecryptionError)(basePayload, coreCryptoError);
35
35
  expect(error).toBeInstanceOf(DecryptionError_1.DecryptionError);
36
- expect(error.message).toBe(`Decryption error from user1 (client1) (${coreCryptoError.message})`);
36
+ expect(error.message).toBe(`Decryption error from user1 (client1) (name: undefined) (message: ${coreCryptoError.message})`);
37
37
  expect(error.code).toBe(coreCryptoError.code);
38
38
  });
39
39
  });
package/package.json CHANGED
@@ -61,6 +61,6 @@
61
61
  "test:coverage": "jest --coverage",
62
62
  "watch": "tsc --watch"
63
63
  },
64
- "version": "46.13.1",
65
- "gitHead": "06484a73c78b6a63d5ededc0e6722becaed69156"
64
+ "version": "46.14.0",
65
+ "gitHead": "dee974243f22cbc162793639d1a355fdee4b1691"
66
66
  }