@nmshd/transport 2.0.0-beta.7 → 2.0.0-beta.9

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 (83) hide show
  1. package/dist/buildInformation.js +4 -4
  2. package/dist/core/CoreCrypto.js +5 -4
  3. package/dist/core/CoreCrypto.js.map +1 -1
  4. package/dist/core/{TransportErrors.d.ts → CoreErrors.d.ts} +1 -2
  5. package/dist/core/{TransportErrors.js → CoreErrors.js} +13 -16
  6. package/dist/core/CoreErrors.js.map +1 -0
  7. package/dist/core/CoreIdHelper.js +2 -1
  8. package/dist/core/CoreIdHelper.js.map +1 -1
  9. package/dist/core/CoreUtil.js +2 -1
  10. package/dist/core/CoreUtil.js.map +1 -1
  11. package/dist/core/Reference.js +3 -3
  12. package/dist/core/Reference.js.map +1 -1
  13. package/dist/core/Transport.d.ts +1 -1
  14. package/dist/core/Transport.js +7 -6
  15. package/dist/core/Transport.js.map +1 -1
  16. package/dist/core/TransportController.d.ts +1 -0
  17. package/dist/core/TransportController.js +5 -1
  18. package/dist/core/TransportController.js.map +1 -1
  19. package/dist/core/TransportError.d.ts +2 -0
  20. package/dist/core/TransportError.js +7 -0
  21. package/dist/core/TransportError.js.map +1 -0
  22. package/dist/core/TransportLoggerFactory.js +2 -1
  23. package/dist/core/TransportLoggerFactory.js.map +1 -1
  24. package/dist/core/backbone/ClientResult.js +5 -4
  25. package/dist/core/backbone/ClientResult.js.map +1 -1
  26. package/dist/core/index.d.ts +2 -1
  27. package/dist/core/index.js +2 -1
  28. package/dist/core/index.js.map +1 -1
  29. package/dist/core/types/CoreDate.js +4 -3
  30. package/dist/core/types/CoreDate.js.map +1 -1
  31. package/dist/core/types/CoreId.js +2 -1
  32. package/dist/core/types/CoreId.js.map +1 -1
  33. package/dist/modules/accounts/AccountController.js +5 -5
  34. package/dist/modules/accounts/AccountController.js.map +1 -1
  35. package/dist/modules/accounts/IdentityController.js +1 -1
  36. package/dist/modules/accounts/IdentityController.js.map +1 -1
  37. package/dist/modules/accounts/IdentityUtil.js +1 -1
  38. package/dist/modules/accounts/IdentityUtil.js.map +1 -1
  39. package/dist/modules/challenges/ChallengeController.js +4 -4
  40. package/dist/modules/challenges/ChallengeController.js.map +1 -1
  41. package/dist/modules/devices/DeviceController.js +7 -7
  42. package/dist/modules/devices/DeviceController.js.map +1 -1
  43. package/dist/modules/devices/DeviceSecretController.js +6 -6
  44. package/dist/modules/devices/DeviceSecretController.js.map +1 -1
  45. package/dist/modules/devices/DevicesController.js +3 -3
  46. package/dist/modules/devices/DevicesController.js.map +1 -1
  47. package/dist/modules/files/FileController.js +9 -10
  48. package/dist/modules/files/FileController.js.map +1 -1
  49. package/dist/modules/messages/MessageController.js +12 -12
  50. package/dist/modules/messages/MessageController.js.map +1 -1
  51. package/dist/modules/relationshipTemplates/RelationshipTemplateController.js +3 -3
  52. package/dist/modules/relationshipTemplates/RelationshipTemplateController.js.map +1 -1
  53. package/dist/modules/relationships/RelationshipSecretController.js +14 -14
  54. package/dist/modules/relationships/RelationshipSecretController.js.map +1 -1
  55. package/dist/modules/relationships/RelationshipsController.js +25 -25
  56. package/dist/modules/relationships/RelationshipsController.js.map +1 -1
  57. package/dist/modules/relationships/local/Relationship.d.ts +1 -0
  58. package/dist/modules/relationships/local/Relationship.js +9 -9
  59. package/dist/modules/relationships/local/Relationship.js.map +1 -1
  60. package/dist/modules/secrets/SecretController.js +1 -1
  61. package/dist/modules/secrets/SecretController.js.map +1 -1
  62. package/dist/modules/sync/DatawalletModificationMapper.js +2 -2
  63. package/dist/modules/sync/DatawalletModificationMapper.js.map +1 -1
  64. package/dist/modules/sync/DatawalletModificationsProcessor.js +2 -2
  65. package/dist/modules/sync/DatawalletModificationsProcessor.js.map +1 -1
  66. package/dist/modules/sync/ExternalEventsProcessor.js +1 -1
  67. package/dist/modules/sync/ExternalEventsProcessor.js.map +1 -1
  68. package/dist/modules/sync/SyncController.js +10 -10
  69. package/dist/modules/sync/SyncController.js.map +1 -1
  70. package/dist/modules/tokens/AnonymousTokenController.js +1 -1
  71. package/dist/modules/tokens/AnonymousTokenController.js.map +1 -1
  72. package/dist/modules/tokens/TokenController.js +4 -4
  73. package/dist/modules/tokens/TokenController.js.map +1 -1
  74. package/dist/util/PasswordGenerator.js +2 -1
  75. package/dist/util/PasswordGenerator.js.map +1 -1
  76. package/dist/util/Random.js +8 -7
  77. package/dist/util/Random.js.map +1 -1
  78. package/lib-web/nmshd.transport.js +331 -303
  79. package/lib-web/nmshd.transport.js.map +1 -1
  80. package/lib-web/nmshd.transport.min.js +1 -1
  81. package/lib-web/nmshd.transport.min.js.map +1 -1
  82. package/package.json +1 -1
  83. package/dist/core/TransportErrors.js.map +0 -1
@@ -15,10 +15,10 @@ exports.buildInformation = void 0;
15
15
  const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-serval");
16
16
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
17
17
  exports.buildInformation = {
18
- version: "2.0.0-beta.7",
19
- build: "38",
20
- date: "2022-09-28T11:13:26+00:00",
21
- commit: "44a803a33359c25924b03d92bece8556be05af18",
18
+ version: "2.0.0-beta.9",
19
+ build: "40",
20
+ date: "2022-09-30T08:26:52+00:00",
21
+ commit: "159b06e94c2234ca5428c9658022a420942db650",
22
22
  dependencies: {"@js-soft/docdb-access-abstractions":"1.0.1","@js-soft/logging-abstractions":"1.0.0","@js-soft/simple-logger":"1.0.2","@js-soft/ts-utils":"2.3.0","axios":"^0.27.2","deep-equal":"^2.0.5","fast-json-patch":"^3.1.1","form-data":"^4.0.0","json-stringify-safe":"^5.0.1","lodash":"^4.17.21","luxon":"^3.0.4","qs":"^6.11.0","reflect-metadata":"^0.1.13","ts-simple-nameof":"^1.3.1","uuid":"^9.0.0"},
23
23
  libraries: {
24
24
  crypto: crypto_1.buildInformation,
@@ -40,7 +40,8 @@ exports.buildInformation = {
40
40
  Object.defineProperty(exports, "__esModule", ({ value: true }));
41
41
  exports.CoreCrypto = void 0;
42
42
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
43
- const util_1 = __webpack_require__(/*! ../util */ "./dist/util/index.js");
43
+ const PasswordGenerator_1 = __webpack_require__(/*! ../util/PasswordGenerator */ "./dist/util/PasswordGenerator.js");
44
+ const TransportError_1 = __webpack_require__(/*! ./TransportError */ "./dist/core/TransportError.js");
44
45
  const TransportVersion_1 = __webpack_require__(/*! ./types/TransportVersion */ "./dist/core/types/TransportVersion.js");
45
46
  class CoreCrypto {
46
47
  /**
@@ -126,7 +127,7 @@ class CoreCrypto {
126
127
  buffer = secret;
127
128
  }
128
129
  else {
129
- throw new Error("The secret type is invalid.");
130
+ throw new TransportError_1.TransportError("The secret type is invalid.");
130
131
  }
131
132
  return await crypto_1.CryptoDerivation.deriveKeyFromBase(buffer, keyId, context, keyAlgorithm);
132
133
  }
@@ -235,10 +236,10 @@ class CoreCrypto {
235
236
  return await crypto_1.CryptoRandom.bytes(size);
236
237
  }
237
238
  static async createAccountPassword() {
238
- return await util_1.PasswordGenerator.createStrongPassword(100, 100);
239
+ return await PasswordGenerator_1.PasswordGenerator.createStrongPassword(100, 100);
239
240
  }
240
241
  static invalidVersion(version) {
241
- return new Error(`The version ${version} is not supported.`);
242
+ return new TransportError_1.TransportError(`The version ${version} is not supported.`);
242
243
  }
243
244
  }
244
245
  exports.CoreCrypto = CoreCrypto;
@@ -319,6 +320,154 @@ exports.CoreError = CoreError;
319
320
 
320
321
  /***/ }),
321
322
 
323
+ /***/ "./dist/core/CoreErrors.js":
324
+ /*!*********************************!*\
325
+ !*** ./dist/core/CoreErrors.js ***!
326
+ \*********************************/
327
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
328
+
329
+ "use strict";
330
+
331
+ var __importDefault = (this && this.__importDefault) || function (mod) {
332
+ return (mod && mod.__esModule) ? mod : { "default": mod };
333
+ };
334
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
335
+ exports.CoreErrors = void 0;
336
+ const json_stringify_safe_1 = __importDefault(__webpack_require__(/*! json-stringify-safe */ "./node_modules/json-stringify-safe/stringify.js"));
337
+ const CoreError_1 = __webpack_require__(/*! ./CoreError */ "./dist/core/CoreError.js");
338
+ class Relationships {
339
+ wrongChangeStatus(status) {
340
+ return new CoreError_1.CoreError("error.transport.relationships.wrongChangeStatus", `The relationship change has the wrong status (${status}) to run this operation`);
341
+ }
342
+ }
343
+ class Device {
344
+ alreadyOnboarded() {
345
+ return new CoreError_1.CoreError("error.transport.devices.alreadyOnboarded", "The device has already been onboarded.");
346
+ }
347
+ }
348
+ class Messages {
349
+ plaintextMismatch(ownAddress) {
350
+ return new CoreError_1.CoreError("error.transport.messages.plaintextMismatch", `The own address ${ownAddress} was not named as a recipient within the signed MessagePlaintext. A replay attack might be the cause of this.`);
351
+ }
352
+ signatureListMismatch(address) {
353
+ return new CoreError_1.CoreError("error.transport.messages.signatureListMismatch", `The signature list didn't contain an entry for address ${address}.`);
354
+ }
355
+ signatureNotValid() {
356
+ return new CoreError_1.CoreError("error.transport.messages.signatureNotValid", "The digital signature on this message for peer key is invalid. An impersonination attack might be the cause of this.");
357
+ }
358
+ ownAddressNotInList(messageId) {
359
+ return new CoreError_1.CoreError("error.transport.messages.ownAddressNotInList", `The recipients list of message ${messageId} didn't contain an entry for the own address. This message should not have been received.`);
360
+ }
361
+ noMatchingRelationship(senderAddress) {
362
+ return new CoreError_1.CoreError("error.transport.messages.noMatchingRelationship", `A relationship with sender ${senderAddress} does not exist.`);
363
+ }
364
+ }
365
+ class Secrets {
366
+ wrongSecretType(secretId) {
367
+ return new CoreError_1.CoreError("error.transport.secrets.wrongBaseKeyType", "Given Secret type is not supported!", {
368
+ secretId: secretId
369
+ });
370
+ }
371
+ secretNotFound(type) {
372
+ return new CoreError_1.CoreError("error.transport.secrets.secretNotFound", `secret "${type}" not found`);
373
+ }
374
+ }
375
+ class Challenges {
376
+ challengeTypeRequiresRelationship() {
377
+ return new CoreError_1.CoreError("error.transport.challenges.challengeTypeRequiresRelationship", "The challenge type Relationship requires a relationship.");
378
+ }
379
+ }
380
+ class Datawallet {
381
+ encryptedPayloadIsNoCipher() {
382
+ return new CoreError_1.CoreError("error.transport.datawallet.encryptedPayloadIsNoCipher", "The given encrypted payload is no cipher.");
383
+ }
384
+ unsupportedModification(type, data) {
385
+ const errorCode = "error.transport.datawallet.unsupportedModification";
386
+ const formattedData = data ? (0, json_stringify_safe_1.default)(data) : "";
387
+ switch (type) {
388
+ case "unsupportedCacheChangedModificationCollection":
389
+ return new CoreError_1.CoreError(errorCode, `The following collections were received in CacheChanged datawallet modifications but are not supported by the current version of this library: ${formattedData}.`);
390
+ default:
391
+ throw new Error(`Given type '${type}' is not supported.`);
392
+ }
393
+ }
394
+ insufficientSupportedDatawalletVersion(supportedVersion, requiredVersion) {
395
+ return new CoreError_1.CoreError("error.transport.datawallet.insufficientSupportedDatawalletVersion", `The SupportedDatawalletVersion '${supportedVersion}' is too low. A minimum version of '${requiredVersion}' is required.`);
396
+ }
397
+ currentBiggerThanTarget(current, target) {
398
+ return new CoreError_1.CoreError("error.transport.datawallet.currentBiggerThanTarget", `The current datawallet version '${current}' is bigger than the target version '${target}'.`);
399
+ }
400
+ }
401
+ class Files {
402
+ plaintextHashMismatch() {
403
+ return new CoreError_1.CoreError("error.transport.files.plaintextHashMismatch", "The actual hash of the plaintext does not match the given plaintextHash. Something went wrong while encrypting/decrypting the file.");
404
+ }
405
+ cipherMismatch() {
406
+ return new CoreError_1.CoreError("error.transport.files.cipherMismatch", "The actual hash of the cipher does not match the given cipherHash. Something went wrong while storing/transmitting the file.");
407
+ }
408
+ invalidMetadata(id) {
409
+ return new CoreError_1.CoreError("error.transport.files.invalidMetadata", `The metadata of file id "${id}" is invalid.`);
410
+ }
411
+ fileContentUndefined() {
412
+ return new CoreError_1.CoreError("error.transport.files.fileContentUndefined", "The given file content is undefined.");
413
+ }
414
+ maxFileSizeExceeded(fileSize, platformMaxFileSize) {
415
+ return new CoreError_1.CoreError("error.transport.files.maxFileSizeExceeded", `The given file content size (${fileSize}) exceeds the max file size the backbone accepts (${platformMaxFileSize}).`);
416
+ }
417
+ }
418
+ class Tokens {
419
+ invalidTokenContent(id) {
420
+ return new CoreError_1.CoreError("error.transport.tokens.invalidTokenContent", `The content of token ${id} is not of type TokenContent`);
421
+ }
422
+ }
423
+ class General {
424
+ baseUrlNotSet() {
425
+ return new CoreError_1.CoreError("error.transport.general.baseUrlNotSet", "The baseUrl was not set.");
426
+ }
427
+ platformClientIdNotSet() {
428
+ return new CoreError_1.CoreError("error.transport.general.platformClientNotSet", "The platform clientSecret was not set.");
429
+ }
430
+ platformClientSecretNotSet() {
431
+ return new CoreError_1.CoreError("error.transport.general.platformClientNotSet", "The platform clientId was not set.");
432
+ }
433
+ platformClientInvalid() {
434
+ return new CoreError_1.CoreError("error.transport.general.platformClientInvalid", "The combination of platform clientId and clientSecret is invalid.");
435
+ }
436
+ incompatibleBackbone() {
437
+ return new CoreError_1.CoreError("error.transport.incompatibleBackbone", "The backbone sent an invalid payload.");
438
+ }
439
+ signatureNotValid(type) {
440
+ return new CoreError_1.CoreError("error.transport.signatureNotValid", `The ${type ? `${type}-` : ""}signature is not valid.`);
441
+ }
442
+ recordNotFound(entityName, entityId) {
443
+ return new CoreError_1.CoreError("error.transport.recordNotFound", `'${entityName instanceof Function ? entityName.name : entityName}' not found.`, entityId);
444
+ }
445
+ notSupported() {
446
+ return new CoreError_1.CoreError("error.transport.notSupported", "The method is not yet supported.");
447
+ }
448
+ realmLength() {
449
+ return new CoreError_1.CoreError("error.transport.identity.realmLength", "Realm must be of length 3.");
450
+ }
451
+ invalidTruncatedReference() {
452
+ return new CoreError_1.CoreError("error.transport.files.invalidTruncatedReference", "invalid truncated reference");
453
+ }
454
+ }
455
+ class CoreErrors {
456
+ }
457
+ exports.CoreErrors = CoreErrors;
458
+ CoreErrors.relationships = new Relationships();
459
+ CoreErrors.general = new General();
460
+ CoreErrors.messages = new Messages();
461
+ CoreErrors.secrets = new Secrets();
462
+ CoreErrors.device = new Device();
463
+ CoreErrors.files = new Files();
464
+ CoreErrors.challenges = new Challenges();
465
+ CoreErrors.datawallet = new Datawallet();
466
+ CoreErrors.tokens = new Tokens();
467
+ //# sourceMappingURL=CoreErrors.js.map
468
+
469
+ /***/ }),
470
+
322
471
  /***/ "./dist/core/CoreIdHelper.js":
323
472
  /*!***********************************!*\
324
473
  !*** ./dist/core/CoreIdHelper.js ***!
@@ -330,6 +479,7 @@ exports.CoreError = CoreError;
330
479
  Object.defineProperty(exports, "__esModule", ({ value: true }));
331
480
  exports.CoreIdHelper = void 0;
332
481
  const Random_1 = __webpack_require__(/*! ../util/Random */ "./dist/util/Random.js");
482
+ const TransportError_1 = __webpack_require__(/*! ./TransportError */ "./dist/core/TransportError.js");
333
483
  const CoreId_1 = __webpack_require__(/*! ./types/CoreId */ "./dist/core/types/CoreId.js");
334
484
  class CoreIdHelper {
335
485
  constructor(prefix, validateOnly = false) {
@@ -339,7 +489,7 @@ class CoreIdHelper {
339
489
  }
340
490
  async generate() {
341
491
  if (this.validateOnly) {
342
- throw new Error("This CoreIdHelper is set up for validation only.");
492
+ throw new TransportError_1.TransportError("This CoreIdHelper is set up for validation only.");
343
493
  }
344
494
  return await CoreId_1.CoreId.generate(this.prefix);
345
495
  }
@@ -504,6 +654,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
504
654
  exports.CoreUtil = void 0;
505
655
  const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-serval");
506
656
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
657
+ const TransportError_1 = __webpack_require__(/*! ./TransportError */ "./dist/core/TransportError.js");
507
658
  class CoreUtil {
508
659
  static toBuffer(content, verbose = false) {
509
660
  let buffer;
@@ -520,7 +671,7 @@ class CoreUtil {
520
671
  buffer = new crypto_1.CoreBuffer(content);
521
672
  }
522
673
  else {
523
- throw new Error("The given content cannot be transformed to buffer.");
674
+ throw new TransportError_1.TransportError("The given content cannot be transformed to buffer.");
524
675
  }
525
676
  return buffer;
526
677
  }
@@ -654,7 +805,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
654
805
  exports.Reference = void 0;
655
806
  const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-serval");
656
807
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
657
- const TransportErrors_1 = __webpack_require__(/*! ./TransportErrors */ "./dist/core/TransportErrors.js");
808
+ const CoreErrors_1 = __webpack_require__(/*! ./CoreErrors */ "./dist/core/CoreErrors.js");
658
809
  const CoreId_1 = __webpack_require__(/*! ./types/CoreId */ "./dist/core/types/CoreId.js");
659
810
  class Reference extends ts_serval_1.Serializable {
660
811
  truncate() {
@@ -665,7 +816,7 @@ class Reference extends ts_serval_1.Serializable {
665
816
  const truncatedBuffer = crypto_1.CoreBuffer.fromBase64URL(value);
666
817
  const splitted = truncatedBuffer.toUtf8().split("|");
667
818
  if (splitted.length !== 3) {
668
- throw TransportErrors_1.TransportErrors.general.invalidTruncatedReference();
819
+ throw CoreErrors_1.CoreErrors.general.invalidTruncatedReference();
669
820
  }
670
821
  try {
671
822
  const id = CoreId_1.CoreId.from(splitted[0]);
@@ -681,7 +832,7 @@ class Reference extends ts_serval_1.Serializable {
681
832
  });
682
833
  }
683
834
  catch (e) {
684
- throw TransportErrors_1.TransportErrors.general.invalidTruncatedReference();
835
+ throw CoreErrors_1.CoreErrors.general.invalidTruncatedReference();
685
836
  }
686
837
  }
687
838
  static validateId(value, helper) {
@@ -729,8 +880,9 @@ const simple_logger_1 = __webpack_require__(/*! @js-soft/simple-logger */ "./nod
729
880
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
730
881
  const lodash_1 = __importDefault(__webpack_require__(/*! lodash */ "./node_modules/lodash/lodash.js"));
731
882
  const Identity_1 = __webpack_require__(/*! ../modules/accounts/data/Identity */ "./dist/modules/accounts/data/Identity.js");
883
+ const CoreErrors_1 = __webpack_require__(/*! ./CoreErrors */ "./dist/core/CoreErrors.js");
732
884
  const TransportContext_1 = __webpack_require__(/*! ./TransportContext */ "./dist/core/TransportContext.js");
733
- const TransportErrors_1 = __webpack_require__(/*! ./TransportErrors */ "./dist/core/TransportErrors.js");
885
+ const TransportError_1 = __webpack_require__(/*! ./TransportError */ "./dist/core/TransportError.js");
734
886
  const TransportLoggerFactory_1 = __webpack_require__(/*! ./TransportLoggerFactory */ "./dist/core/TransportLoggerFactory.js");
735
887
  let log;
736
888
  class Transport {
@@ -741,19 +893,19 @@ class Transport {
741
893
  TransportLoggerFactory_1.TransportLoggerFactory.init(loggerFactory);
742
894
  log = TransportLoggerFactory_1.TransportLoggerFactory.getLogger(Transport);
743
895
  if (!this._config.platformClientId) {
744
- throw TransportErrors_1.TransportErrors.general.platformClientIdNotSet().logWith(log);
896
+ throw CoreErrors_1.CoreErrors.general.platformClientIdNotSet().logWith(log);
745
897
  }
746
898
  if (!this._config.platformClientSecret) {
747
- throw TransportErrors_1.TransportErrors.general.platformClientSecretNotSet().logWith(log);
899
+ throw CoreErrors_1.CoreErrors.general.platformClientSecretNotSet().logWith(log);
748
900
  }
749
901
  if (!this._config.baseUrl) {
750
- throw TransportErrors_1.TransportErrors.general.baseUrlNotSet().logWith(log);
902
+ throw CoreErrors_1.CoreErrors.general.baseUrlNotSet().logWith(log);
751
903
  }
752
904
  if (this._config.supportedDatawalletVersion < 1) {
753
- throw new Error("The given identity version is invalid. The value must be 0 or higher.");
905
+ throw new TransportError_1.TransportError("The given identity version is invalid. The value must be 0 or higher.");
754
906
  }
755
907
  if (this._config.realm.length !== 3) {
756
- throw TransportErrors_1.TransportErrors.general.realmLength();
908
+ throw CoreErrors_1.CoreErrors.general.realmLength();
757
909
  }
758
910
  }
759
911
  get config() {
@@ -849,6 +1001,7 @@ var TransportContext;
849
1001
 
850
1002
  Object.defineProperty(exports, "__esModule", ({ value: true }));
851
1003
  exports.TransportController = exports.ControllerName = void 0;
1004
+ const TransportError_1 = __webpack_require__(/*! ./TransportError */ "./dist/core/TransportError.js");
852
1005
  const TransportLoggerFactory_1 = __webpack_require__(/*! ./TransportLoggerFactory */ "./dist/core/TransportLoggerFactory.js");
853
1006
  var ControllerName;
854
1007
  (function (ControllerName) {
@@ -914,7 +1067,7 @@ class TransportController {
914
1067
  }
915
1068
  init(..._args) {
916
1069
  if (this._initialized) {
917
- throw new Error(`The controller ${this.controllerName} is already initialized.`);
1070
+ throw new TransportError_1.TransportError(`The controller ${this.controllerName} is already initialized.`);
918
1071
  }
919
1072
  this._initialized = true;
920
1073
  return Promise.resolve(this);
@@ -922,160 +1075,29 @@ class TransportController {
922
1075
  parseArray(values, type) {
923
1076
  return values.map((v) => type.fromAny(v));
924
1077
  }
1078
+ newCacheEmptyError(entityName, id) {
1079
+ return new TransportError_1.TransportError(`The cache of ${entityName instanceof Function ? entityName.name : entityName} with id "${id}" is empty.`);
1080
+ }
925
1081
  }
926
1082
  exports.TransportController = TransportController;
927
1083
  //# sourceMappingURL=TransportController.js.map
928
1084
 
929
1085
  /***/ }),
930
1086
 
931
- /***/ "./dist/core/TransportErrors.js":
932
- /*!**************************************!*\
933
- !*** ./dist/core/TransportErrors.js ***!
934
- \**************************************/
935
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
1087
+ /***/ "./dist/core/TransportError.js":
1088
+ /*!*************************************!*\
1089
+ !*** ./dist/core/TransportError.js ***!
1090
+ \*************************************/
1091
+ /***/ ((__unused_webpack_module, exports) => {
936
1092
 
937
1093
  "use strict";
938
1094
 
939
- var __importDefault = (this && this.__importDefault) || function (mod) {
940
- return (mod && mod.__esModule) ? mod : { "default": mod };
941
- };
942
1095
  Object.defineProperty(exports, "__esModule", ({ value: true }));
943
- exports.TransportErrors = void 0;
944
- const json_stringify_safe_1 = __importDefault(__webpack_require__(/*! json-stringify-safe */ "./node_modules/json-stringify-safe/stringify.js"));
945
- const CoreError_1 = __webpack_require__(/*! ./CoreError */ "./dist/core/CoreError.js");
946
- class Relationships {
947
- wrongChangeStatus(status) {
948
- return new CoreError_1.CoreError("error.transport.relationships.wrongChangeStatus", `The relationship change has the wrong status (${status}) to run this operation`);
949
- }
950
- }
951
- class Device {
952
- alreadyOnboarded() {
953
- return new CoreError_1.CoreError("error.transport.devices.alreadyOnboarded", "The device has already been onboarded.");
954
- }
955
- }
956
- class Messages {
957
- plaintextMismatch(ownAddress) {
958
- return new CoreError_1.CoreError("error.transport.messages.plaintextMismatch", `The own address ${ownAddress} was not named as a recipient within the signed MessagePlaintext. A replay attack might be the cause of this.`);
959
- }
960
- signatureListMismatch(address) {
961
- return new CoreError_1.CoreError("error.transport.messages.signatureListMismatch", `The signature list didn't contain an entry for address ${address}.`);
962
- }
963
- signatureNotValid() {
964
- return new CoreError_1.CoreError("error.transport.messages.signatureNotValid", "The digital signature on this message for peer key is invalid. An impersonination attack might be the cause of this.");
965
- }
966
- ownAddressNotInList(messageId) {
967
- return new CoreError_1.CoreError("error.transport.messages.ownAddressNotInList", `The recipients list of message ${messageId} didn't contain an entry for the own address. This message should not have been received.`);
968
- }
969
- noMatchingRelationship(senderAddress) {
970
- return new CoreError_1.CoreError("error.transport.messages.noMatchingRelationship", `A relationship with sender ${senderAddress} does not exist.`);
971
- }
972
- }
973
- class Secrets {
974
- wrongSecretType(secretId) {
975
- return new CoreError_1.CoreError("error.transport.secrets.wrongBaseKeyType", "Given Secret type is not supported!", {
976
- secretId: secretId
977
- });
978
- }
979
- secretNotFound(type) {
980
- return new CoreError_1.CoreError("error.transport.secrets.secretNotFound", `secret "${type}" not found`);
981
- }
982
- }
983
- class Challenges {
984
- challengeTypeRequiresRelationship() {
985
- return new CoreError_1.CoreError("error.transport.challenges.challengeTypeRequiresRelationship", "The challenge type Relationship requires a relationship.");
986
- }
987
- }
988
- class Datawallet {
989
- encryptedPayloadIsNoCipher() {
990
- return new CoreError_1.CoreError("error.transport.datawallet.encryptedPayloadIsNoCipher", "The given encrypted payload is no cipher.");
991
- }
992
- unsupportedModification(type, data) {
993
- const errorCode = "error.transport.datawallet.unsupportedModification";
994
- const formattedData = data ? (0, json_stringify_safe_1.default)(data) : "";
995
- switch (type) {
996
- case "unsupportedCacheChangedModificationCollection":
997
- return new CoreError_1.CoreError(errorCode, `The following collections were received in CacheChanged datawallet modifications but are not supported by the current version of this library: ${formattedData}.`);
998
- default:
999
- throw new Error(`Given type '${type}' is not supported.`);
1000
- }
1001
- }
1002
- insufficientSupportedDatawalletVersion(supportedVersion, requiredVersion) {
1003
- return new CoreError_1.CoreError("error.transport.datawallet.insufficientSupportedDatawalletVersion", `The SupportedDatawalletVersion '${supportedVersion}' is too low. A minimum version of '${requiredVersion}' is required.`);
1004
- }
1005
- currentBiggerThanTarget(current, target) {
1006
- return new CoreError_1.CoreError("error.transport.datawallet.currentBiggerThanTarget", `The current datawallet version '${current}' is bigger than the target version '${target}'.`);
1007
- }
1008
- }
1009
- class Files {
1010
- plaintextHashMismatch() {
1011
- return new CoreError_1.CoreError("error.transport.files.plaintextHashMismatch", "The actual hash of the plaintext does not match the given plaintextHash. Something went wrong while encrypting/decrypting the file.");
1012
- }
1013
- cipherMismatch() {
1014
- return new CoreError_1.CoreError("error.transport.files.cipherMismatch", "The actual hash of the cipher does not match the given cipherHash. Something went wrong while storing/transmitting the file.");
1015
- }
1016
- invalidMetadata(id) {
1017
- return new CoreError_1.CoreError("error.transport.files.invalidMetadata", `The metadata of file id "${id}" is invalid.`);
1018
- }
1019
- fileContentUndefined() {
1020
- return new CoreError_1.CoreError("error.transport.files.fileContentUndefined", "The given file content is undefined.");
1021
- }
1022
- maxFileSizeExceeded(fileSize, platformMaxFileSize) {
1023
- return new CoreError_1.CoreError("error.transport.files.maxFileSizeExceeded", `The given file content size (${fileSize}) exceeds the max file size the backbone accepts (${platformMaxFileSize}).`);
1024
- }
1025
- }
1026
- class Tokens {
1027
- invalidTokenContent(id) {
1028
- return new CoreError_1.CoreError("error.transport.tokens.invalidTokenContent", `The content of token ${id} is not of type TokenContent`);
1029
- }
1030
- }
1031
- class General {
1032
- baseUrlNotSet() {
1033
- return new CoreError_1.CoreError("error.transport.general.baseUrlNotSet", "The baseUrl was not set.");
1034
- }
1035
- platformClientIdNotSet() {
1036
- return new CoreError_1.CoreError("error.transport.general.platformClientNotSet", "The platform clientSecret was not set.");
1037
- }
1038
- platformClientSecretNotSet() {
1039
- return new CoreError_1.CoreError("error.transport.general.platformClientNotSet", "The platform clientId was not set.");
1040
- }
1041
- platformClientInvalid() {
1042
- return new CoreError_1.CoreError("error.transport.general.platformClientInvalid", "The combination of platform clientId and clientSecret is invalid.");
1043
- }
1044
- cacheEmpty(entityName, id) {
1045
- return new Error(`The cache of ${entityName instanceof Function ? entityName.name : entityName} with id "${id}" is empty.`);
1046
- }
1047
- incompatibleBackbone() {
1048
- return new CoreError_1.CoreError("error.transport.incompatibleBackbone", "The backbone sent an invalid payload.");
1049
- }
1050
- signatureNotValid(type) {
1051
- return new CoreError_1.CoreError("error.transport.signatureNotValid", `The ${type ? `${type}-` : ""}signature is not valid.`);
1052
- }
1053
- recordNotFound(entityName, entityId) {
1054
- return new CoreError_1.CoreError("error.transport.recordNotFound", `'${entityName instanceof Function ? entityName.name : entityName}' not found.`, entityId);
1055
- }
1056
- notSupported() {
1057
- return new CoreError_1.CoreError("error.transport.notSupported", "The method is not yet supported.");
1058
- }
1059
- realmLength() {
1060
- return new CoreError_1.CoreError("error.transport.identity.realmLength", "Realm must be of length 3.");
1061
- }
1062
- invalidTruncatedReference() {
1063
- return new CoreError_1.CoreError("error.transport.files.invalidTruncatedReference", "invalid truncated reference");
1064
- }
1065
- }
1066
- class TransportErrors {
1096
+ exports.TransportError = void 0;
1097
+ class TransportError extends Error {
1067
1098
  }
1068
- exports.TransportErrors = TransportErrors;
1069
- TransportErrors.relationships = new Relationships();
1070
- TransportErrors.general = new General();
1071
- TransportErrors.messages = new Messages();
1072
- TransportErrors.secrets = new Secrets();
1073
- TransportErrors.device = new Device();
1074
- TransportErrors.files = new Files();
1075
- TransportErrors.challenges = new Challenges();
1076
- TransportErrors.datawallet = new Datawallet();
1077
- TransportErrors.tokens = new Tokens();
1078
- //# sourceMappingURL=TransportErrors.js.map
1099
+ exports.TransportError = TransportError;
1100
+ //# sourceMappingURL=TransportError.js.map
1079
1101
 
1080
1102
  /***/ }),
1081
1103
 
@@ -1106,19 +1128,20 @@ TransportIds.datawalletModification = new CoreIdHelper_1.CoreIdHelper("TRPDWM");
1106
1128
  /*!*********************************************!*\
1107
1129
  !*** ./dist/core/TransportLoggerFactory.js ***!
1108
1130
  \*********************************************/
1109
- /***/ ((__unused_webpack_module, exports) => {
1131
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
1110
1132
 
1111
1133
  "use strict";
1112
1134
 
1113
1135
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1114
1136
  exports.TransportLoggerFactory = void 0;
1137
+ const TransportError_1 = __webpack_require__(/*! ./TransportError */ "./dist/core/TransportError.js");
1115
1138
  class TransportLoggerFactory {
1116
1139
  static init(instance) {
1117
1140
  this.instance = instance;
1118
1141
  }
1119
1142
  static getLogger(name) {
1120
1143
  if (!this.isInitialized()) {
1121
- throw new Error("The logger factory is not yet initialized. Call TransportLoggerFactory.init() first.");
1144
+ throw new TransportError_1.TransportError("The logger factory is not yet initialized. Call TransportLoggerFactory.init() first.");
1122
1145
  }
1123
1146
  if (typeof name === "function") {
1124
1147
  return this.instance.getLogger(`Transport.${name.name}`);
@@ -1298,17 +1321,18 @@ BackboneIds.device = new CoreIdHelper_1.CoreIdHelper("DVC", true);
1298
1321
 
1299
1322
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1300
1323
  exports.ClientResult = void 0;
1324
+ const TransportError_1 = __webpack_require__(/*! ../TransportError */ "./dist/core/TransportError.js");
1301
1325
  const CoreDate_1 = __webpack_require__(/*! ../types/CoreDate */ "./dist/core/types/CoreDate.js");
1302
1326
  class ClientResult {
1303
1327
  constructor(isSuccess, value, error, platformParameters) {
1304
1328
  if (isSuccess && error) {
1305
- throw new Error("InvalidOperation: A result cannot be successful and contain an error");
1329
+ throw new TransportError_1.TransportError("InvalidOperation: A result cannot be successful and contain an error");
1306
1330
  }
1307
1331
  if (!isSuccess && !error) {
1308
- throw new Error("InvalidOperation: A failing result needs to contain an error");
1332
+ throw new TransportError_1.TransportError("InvalidOperation: A failing result needs to contain an error");
1309
1333
  }
1310
1334
  if (value !== undefined && !isSuccess) {
1311
- throw new Error("InvalidOperation: A value is only useful in case of a success.");
1335
+ throw new TransportError_1.TransportError("InvalidOperation: A value is only useful in case of a success.");
1312
1336
  }
1313
1337
  this._value = value;
1314
1338
  this._isSuccess = isSuccess;
@@ -1334,7 +1358,7 @@ class ClientResult {
1334
1358
  }
1335
1359
  get error() {
1336
1360
  if (this._isSuccess) {
1337
- throw new Error("Can't get the error of an succeeded result. Use 'value' instead.");
1361
+ throw new TransportError_1.TransportError("Can't get the error of an succeeded result. Use 'value' instead.");
1338
1362
  }
1339
1363
  return this._error;
1340
1364
  }
@@ -2116,6 +2140,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
2116
2140
  __exportStar(__webpack_require__(/*! ./backbone */ "./dist/core/backbone/index.js"), exports);
2117
2141
  __exportStar(__webpack_require__(/*! ./CoreCrypto */ "./dist/core/CoreCrypto.js"), exports);
2118
2142
  __exportStar(__webpack_require__(/*! ./CoreError */ "./dist/core/CoreError.js"), exports);
2143
+ __exportStar(__webpack_require__(/*! ./CoreErrors */ "./dist/core/CoreErrors.js"), exports);
2119
2144
  __exportStar(__webpack_require__(/*! ./CoreIdHelper */ "./dist/core/CoreIdHelper.js"), exports);
2120
2145
  __exportStar(__webpack_require__(/*! ./CoreSerializable */ "./dist/core/CoreSerializable.js"), exports);
2121
2146
  __exportStar(__webpack_require__(/*! ./CoreSerializableAsync */ "./dist/core/CoreSerializableAsync.js"), exports);
@@ -2127,7 +2152,7 @@ __exportStar(__webpack_require__(/*! ./Reference */ "./dist/core/Reference.js"),
2127
2152
  __exportStar(__webpack_require__(/*! ./Transport */ "./dist/core/Transport.js"), exports);
2128
2153
  __exportStar(__webpack_require__(/*! ./TransportContext */ "./dist/core/TransportContext.js"), exports);
2129
2154
  __exportStar(__webpack_require__(/*! ./TransportController */ "./dist/core/TransportController.js"), exports);
2130
- __exportStar(__webpack_require__(/*! ./TransportErrors */ "./dist/core/TransportErrors.js"), exports);
2155
+ __exportStar(__webpack_require__(/*! ./TransportError */ "./dist/core/TransportError.js"), exports);
2131
2156
  __exportStar(__webpack_require__(/*! ./TransportIds */ "./dist/core/TransportIds.js"), exports);
2132
2157
  __exportStar(__webpack_require__(/*! ./TransportLoggerFactory */ "./dist/core/TransportLoggerFactory.js"), exports);
2133
2158
  __exportStar(__webpack_require__(/*! ./types */ "./dist/core/types/index.js"), exports);
@@ -2218,6 +2243,7 @@ exports.CoreDate = void 0;
2218
2243
  const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-serval");
2219
2244
  const luxon_1 = __webpack_require__(/*! luxon */ "./node_modules/luxon/build/node/luxon.js");
2220
2245
  const CoreSerializable_1 = __webpack_require__(/*! ../CoreSerializable */ "./dist/core/CoreSerializable.js");
2246
+ const TransportError_1 = __webpack_require__(/*! ../TransportError */ "./dist/core/TransportError.js");
2221
2247
  let CoreDate = CoreDate_1 = class CoreDate extends CoreSerializable_1.CoreSerializable {
2222
2248
  constructor(dateTime = luxon_1.DateTime.utc()) {
2223
2249
  super();
@@ -2330,12 +2356,12 @@ let CoreDate = CoreDate_1 = class CoreDate extends CoreSerializable_1.CoreSerial
2330
2356
  }
2331
2357
  static preFrom(value) {
2332
2358
  if (typeof value === "undefined") {
2333
- throw new Error("The provided object is undefined and cannot be deserialized.");
2359
+ throw new TransportError_1.TransportError("The provided object is undefined and cannot be deserialized.");
2334
2360
  }
2335
2361
  if (typeof value === "object") {
2336
2362
  if (typeof value.date === "undefined") {
2337
2363
  if (typeof value.toISOString !== "function") {
2338
- throw new Error("The provided object doesn't have an 'toISOString' string method.");
2364
+ throw new TransportError_1.TransportError("The provided object doesn't have an 'toISOString' string method.");
2339
2365
  }
2340
2366
  const iso = value.toISOString();
2341
2367
  return luxon_1.DateTime.fromISO(iso, { zone: "utc" });
@@ -2348,7 +2374,7 @@ let CoreDate = CoreDate_1 = class CoreDate extends CoreSerializable_1.CoreSerial
2348
2374
  if (typeof value === "string") {
2349
2375
  return luxon_1.DateTime.fromISO(value, { zone: "utc" }).toUTC();
2350
2376
  }
2351
- throw new Error("The provided object is invalid cannot be deserialized.");
2377
+ throw new TransportError_1.TransportError("The provided object is invalid cannot be deserialized.");
2352
2378
  }
2353
2379
  static from(value) {
2354
2380
  return this.fromAny(value);
@@ -2470,6 +2496,7 @@ exports.CoreId = void 0;
2470
2496
  const ts_serval_1 = __webpack_require__(/*! @js-soft/ts-serval */ "@js-soft/ts-serval");
2471
2497
  const Random_1 = __webpack_require__(/*! ../../util/Random */ "./dist/util/Random.js");
2472
2498
  const CoreSerializable_1 = __webpack_require__(/*! ../CoreSerializable */ "./dist/core/CoreSerializable.js");
2499
+ const TransportError_1 = __webpack_require__(/*! ../TransportError */ "./dist/core/TransportError.js");
2473
2500
  /**
2474
2501
  * A CoreId is any kind of identifier we have in the system.
2475
2502
  */
@@ -2482,7 +2509,7 @@ let CoreId = class CoreId extends CoreSerializable_1.CoreSerializable {
2482
2509
  }
2483
2510
  static async generate(prefix = "") {
2484
2511
  if (prefix.length > 6) {
2485
- throw new Error(`The prefix "${prefix}" is too long. It must not be longer than 6 characters.`);
2512
+ throw new TransportError_1.TransportError(`The prefix "${prefix}" is too long. It must not be longer than 6 characters.`);
2486
2513
  }
2487
2514
  const random = await Random_1.Random.string(20 - prefix.length, Random_1.RandomCharacterRange.Alphanumeric);
2488
2515
  return this.from(prefix.toUpperCase() + random);
@@ -2843,7 +2870,7 @@ class AccountController {
2843
2870
  }
2844
2871
  get activeDevice() {
2845
2872
  if (!this._activeDevice) {
2846
- throw new Error("The DeviceController is not initialized yet.");
2873
+ throw new core_1.TransportError("The DeviceController is not initialized yet.");
2847
2874
  }
2848
2875
  return this._activeDevice;
2849
2876
  }
@@ -2887,7 +2914,7 @@ class AccountController {
2887
2914
  else if (!deviceSharedSecret && availableIdentityDoc && availableDeviceDoc) {
2888
2915
  // Login
2889
2916
  if (!availableBaseKeyDoc) {
2890
- throw core_1.TransportErrors.secrets.secretNotFound("BaseKey");
2917
+ throw core_1.CoreErrors.secrets.secretNotFound("BaseKey");
2891
2918
  }
2892
2919
  const [availableIdentity, availableDevice, availableBaseKey] = await Promise.all([
2893
2920
  Identity_1.Identity.from(availableIdentityDoc),
@@ -2901,7 +2928,7 @@ class AccountController {
2901
2928
  this.deviceAuthClient = new DeviceAuthClient_1.DeviceAuthClient(this.config, this.authenticator);
2902
2929
  }
2903
2930
  else {
2904
- throw new Error("The combination of deviceSharedSecret, existing identity or device is not allowed.");
2931
+ throw new core_1.TransportError("The combination of deviceSharedSecret, existing identity or device is not allowed.");
2905
2932
  }
2906
2933
  this._log.trace(`Using device ${this.activeDevice.id} for identity ${this.identity.address}.`);
2907
2934
  await this.initControllers();
@@ -2997,13 +3024,13 @@ class AccountController {
2997
3024
  if (deviceResponseResult.isError) {
2998
3025
  const error = deviceResponseResult.error;
2999
3026
  if (error.code === "error.platform.unauthorized") {
3000
- throw core_1.TransportErrors.general.platformClientInvalid();
3027
+ throw core_1.CoreErrors.general.platformClientInvalid();
3001
3028
  }
3002
3029
  }
3003
3030
  const deviceResponse = deviceResponseResult.value;
3004
3031
  this._log.trace(`Registered identity with address ${deviceResponse.address}, device id is ${deviceResponse.device.id}.`);
3005
3032
  if (!localAddress.equals(deviceResponse.address)) {
3006
- throw new Error("The backbone address does not match the local address.");
3033
+ throw new core_1.TransportError("The backbone address does not match the local address.");
3007
3034
  }
3008
3035
  const identity = Identity_1.Identity.from({
3009
3036
  address: core_1.CoreAddress.from(deviceResponse.address),
@@ -3184,7 +3211,7 @@ class IdentityController extends core_1.TransportController {
3184
3211
  async sign(content) {
3185
3212
  const privateKeyContainer = await this.parent.activeDevice.secrets.loadSecret(DeviceSecretController_1.DeviceSecretType.IdentitySignature);
3186
3213
  if (!privateKeyContainer || !(privateKeyContainer.secret instanceof crypto_1.CryptoSignaturePrivateKey)) {
3187
- throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretController_1.DeviceSecretType.IdentitySignature);
3214
+ throw core_1.CoreErrors.secrets.secretNotFound(DeviceSecretController_1.DeviceSecretType.IdentitySignature);
3188
3215
  }
3189
3216
  const privateKey = privateKeyContainer.secret;
3190
3217
  const signature = await core_1.CoreCrypto.sign(content, privateKey);
@@ -3228,7 +3255,7 @@ const core_1 = __webpack_require__(/*! ../../core */ "./dist/core/index.js");
3228
3255
  class IdentityUtil {
3229
3256
  static async createAddress(publicKey, realm) {
3230
3257
  if (realm.length !== 3)
3231
- throw core_1.TransportErrors.general.realmLength();
3258
+ throw core_1.CoreErrors.general.realmLength();
3232
3259
  const sha512buffer = await crypto_1.CryptoHash.hash(publicKey.publicKey, 2 /* CryptoHashAlgorithm.SHA512 */);
3233
3260
  const hash = await crypto_1.CryptoHash.hash(sha512buffer, 1 /* CryptoHashAlgorithm.SHA256 */);
3234
3261
  const hashedPublicKey = new crypto_1.CoreBuffer(hash.buffer.slice(0, 20));
@@ -4269,7 +4296,7 @@ class ChallengeController extends TransportController_1.TransportController {
4269
4296
  return { isValid: false };
4270
4297
  const relationship = await this.parent.relationships.getActiveRelationshipToIdentity(challenge.createdBy);
4271
4298
  if (!relationship) {
4272
- throw core_1.TransportErrors.general.recordNotFound(Relationship_1.Relationship, challenge.createdBy.toString());
4299
+ throw core_1.CoreErrors.general.recordNotFound(Relationship_1.Relationship, challenge.createdBy.toString());
4273
4300
  }
4274
4301
  const challengeBuffer = crypto_1.CoreBuffer.fromUtf8(signedChallenge.challenge);
4275
4302
  let isValid = false;
@@ -4278,7 +4305,7 @@ class ChallengeController extends TransportController_1.TransportController {
4278
4305
  isValid = await this.parent.relationships.verifyIdentity(relationship, challengeBuffer, signedChallenge.signature);
4279
4306
  break;
4280
4307
  case Challenge_1.ChallengeType.Device:
4281
- throw core_1.TransportErrors.general.notSupported();
4308
+ throw core_1.CoreErrors.general.notSupported();
4282
4309
  case Challenge_1.ChallengeType.Relationship:
4283
4310
  isValid = await this.parent.relationships.verify(relationship, challengeBuffer, signedChallenge.signature);
4284
4311
  break;
@@ -4320,7 +4347,7 @@ class ChallengeController extends TransportController_1.TransportController {
4320
4347
  }
4321
4348
  async createChallenge(type = Challenge_1.ChallengeType.Identity, relationship) {
4322
4349
  if (type === Challenge_1.ChallengeType.Relationship && !relationship) {
4323
- throw core_1.TransportErrors.challenges.challengeTypeRequiresRelationship();
4350
+ throw core_1.CoreErrors.challenges.challengeTypeRequiresRelationship();
4324
4351
  }
4325
4352
  const backboneResponse = (await this.authClient.createChallenge()).value;
4326
4353
  const challenge = Challenge_1.Challenge.from({
@@ -4344,7 +4371,7 @@ class ChallengeController extends TransportController_1.TransportController {
4344
4371
  break;
4345
4372
  case Challenge_1.ChallengeType.Relationship:
4346
4373
  if (!relationship) {
4347
- throw core_1.TransportErrors.challenges.challengeTypeRequiresRelationship();
4374
+ throw core_1.CoreErrors.challenges.challengeTypeRequiresRelationship();
4348
4375
  }
4349
4376
  signature = await this.parent.relationships.sign(relationship, challengeBuffer);
4350
4377
  break;
@@ -4601,7 +4628,7 @@ class DeviceController extends core_1.TransportController {
4601
4628
  }
4602
4629
  get device() {
4603
4630
  if (!this._device)
4604
- throw new Error("The Device controller is not initialized.");
4631
+ throw new core_1.TransportError("The Device controller is not initialized.");
4605
4632
  return this._device;
4606
4633
  }
4607
4634
  get deviceOrUndefined() {
@@ -4622,7 +4649,7 @@ class DeviceController extends core_1.TransportController {
4622
4649
  try {
4623
4650
  const credentialContainer = await this.secrets.loadSecret(DeviceSecretController_1.DeviceSecretType.DeviceCredentials);
4624
4651
  if (!credentialContainer) {
4625
- throw new Error("There was an error while accessing the device_credentials secret.");
4652
+ throw new core_1.TransportError("There was an error while accessing the device_credentials secret.");
4626
4653
  }
4627
4654
  const credentials = credentialContainer.secret;
4628
4655
  credentials.password = newPassword;
@@ -4646,7 +4673,7 @@ class DeviceController extends core_1.TransportController {
4646
4673
  async sign(content) {
4647
4674
  const privateKeyContainer = await this.secrets.loadSecret(DeviceSecretController_1.DeviceSecretType.DeviceSignature);
4648
4675
  if (!privateKeyContainer || !(privateKeyContainer.secret instanceof crypto_1.CryptoSignaturePrivateKey)) {
4649
- throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretController_1.DeviceSecretType.DeviceSignature);
4676
+ throw core_1.CoreErrors.secrets.secretNotFound(DeviceSecretController_1.DeviceSecretType.DeviceSignature);
4650
4677
  }
4651
4678
  const privateKey = privateKeyContainer.secret;
4652
4679
  const signature = await core_1.CoreCrypto.sign(content, privateKey);
@@ -4655,21 +4682,21 @@ class DeviceController extends core_1.TransportController {
4655
4682
  }
4656
4683
  async verify(content, signature) {
4657
4684
  if (!this.publicKey) {
4658
- throw new Error("The device has no public key to verify a signature. This can happen if the device is not onboarded yet.");
4685
+ throw new core_1.TransportError("The device has no public key to verify a signature. This can happen if the device is not onboarded yet.");
4659
4686
  }
4660
4687
  return await core_1.CoreCrypto.verify(content, signature, this.publicKey);
4661
4688
  }
4662
4689
  async getCredentials() {
4663
4690
  const credentialContainer = await this.secrets.loadSecret(DeviceSecretController_1.DeviceSecretType.DeviceCredentials);
4664
4691
  if (!credentialContainer) {
4665
- throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretController_1.DeviceSecretType.DeviceCredentials);
4692
+ throw core_1.CoreErrors.secrets.secretNotFound(DeviceSecretController_1.DeviceSecretType.DeviceCredentials);
4666
4693
  }
4667
4694
  if (!(credentialContainer.secret instanceof DeviceSecretCredentials_1.DeviceSecretCredentials)) {
4668
- throw core_1.TransportErrors.secrets.wrongSecretType(DeviceSecretController_1.DeviceSecretType.DeviceCredentials);
4695
+ throw core_1.CoreErrors.secrets.wrongSecretType(DeviceSecretController_1.DeviceSecretType.DeviceCredentials);
4669
4696
  }
4670
4697
  const credentials = credentialContainer.secret;
4671
4698
  if (!credentials.username || !credentials.password) {
4672
- throw core_1.TransportErrors.secrets.wrongSecretType(DeviceSecretController_1.DeviceSecretType.DeviceCredentials);
4699
+ throw core_1.CoreErrors.secrets.wrongSecretType(DeviceSecretController_1.DeviceSecretType.DeviceCredentials);
4673
4700
  }
4674
4701
  return {
4675
4702
  username: credentials.username,
@@ -4813,17 +4840,17 @@ class DeviceSecretController extends TransportController_1.TransportController {
4813
4840
  async createDeviceSharedSecret(device, deviceIndex, includeIdentityPrivateKey = false) {
4814
4841
  const synchronizationKey = await this.loadSecret(DeviceSecretType.IdentitySynchronizationMaster);
4815
4842
  if (!synchronizationKey || !(synchronizationKey.secret instanceof crypto_1.CryptoSecretKey)) {
4816
- throw core_1.TransportErrors.secrets.secretNotFound("SynchronizationKey");
4843
+ throw core_1.CoreErrors.secrets.secretNotFound("SynchronizationKey");
4817
4844
  }
4818
4845
  const baseKey = await this.loadSecret(DeviceSecretType.SharedSecretBaseKey);
4819
4846
  if (!baseKey || !(baseKey.secret instanceof crypto_1.CryptoSecretKey)) {
4820
- throw core_1.TransportErrors.secrets.secretNotFound("baseKey");
4847
+ throw core_1.CoreErrors.secrets.secretNotFound("baseKey");
4821
4848
  }
4822
4849
  let identityPrivateKey;
4823
4850
  if (includeIdentityPrivateKey) {
4824
4851
  identityPrivateKey = await this.loadSecret(DeviceSecretType.IdentitySignature);
4825
4852
  if (!identityPrivateKey || !(identityPrivateKey.secret instanceof crypto_1.CryptoSignaturePrivateKey)) {
4826
- throw core_1.TransportErrors.secrets.secretNotFound("IdentityKey");
4853
+ throw core_1.CoreErrors.secrets.secretNotFound("IdentityKey");
4827
4854
  }
4828
4855
  }
4829
4856
  const deviceSharedSecret = DeviceSharedSecret_1.DeviceSharedSecret.from({
@@ -4849,7 +4876,7 @@ class DeviceSecretController extends TransportController_1.TransportController {
4849
4876
  const serializedEvent = crypto_1.CoreBuffer.fromUtf8(JSON.stringify(event.payload));
4850
4877
  const privSync = await this.loadSecret(DeviceSecretType.IdentitySynchronizationMaster);
4851
4878
  if (!privSync || !(privSync.secret instanceof crypto_1.CryptoSecretKey)) {
4852
- throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretType.IdentitySynchronizationMaster);
4879
+ throw core_1.CoreErrors.secrets.secretNotFound(DeviceSecretType.IdentitySynchronizationMaster);
4853
4880
  }
4854
4881
  const encryptionKey = await core_1.CoreCrypto.deriveKeyFromBase(privSync.secret, index, "DataSync");
4855
4882
  const cipher = await core_1.CoreCrypto.encrypt(serializedEvent, encryptionKey);
@@ -4863,7 +4890,7 @@ class DeviceSecretController extends TransportController_1.TransportController {
4863
4890
  const payloadCipher = crypto_1.CryptoCipher.fromBase64(payloadCipherBase64);
4864
4891
  const privSync = await this.loadSecret(DeviceSecretType.IdentitySynchronizationMaster);
4865
4892
  if (!privSync || !(privSync.secret instanceof crypto_1.CryptoSecretKey)) {
4866
- throw core_1.TransportErrors.secrets.secretNotFound(DeviceSecretType.IdentitySynchronizationMaster);
4893
+ throw core_1.CoreErrors.secrets.secretNotFound(DeviceSecretType.IdentitySynchronizationMaster);
4867
4894
  }
4868
4895
  const decryptionKey = await core_1.CoreCrypto.deriveKeyFromBase(privSync.secret, index, "DataSync");
4869
4896
  const plaintext = await core_1.CoreCrypto.decrypt(payloadCipher, decryptionKey);
@@ -4873,7 +4900,7 @@ class DeviceSecretController extends TransportController_1.TransportController {
4873
4900
  }
4874
4901
  getBaseKey() {
4875
4902
  if (!this.baseKey) {
4876
- throw core_1.TransportErrors.general.recordNotFound(crypto_1.CryptoSecretKey, DeviceSecretType.SharedSecretBaseKey);
4903
+ throw core_1.CoreErrors.general.recordNotFound(crypto_1.CryptoSecretKey, DeviceSecretType.SharedSecretBaseKey);
4877
4904
  }
4878
4905
  return this.baseKey;
4879
4906
  }
@@ -4983,12 +5010,12 @@ class DevicesController extends TransportController_1.TransportController {
4983
5010
  async getSharedSecret(id) {
4984
5011
  const deviceDoc = await this.devices.read(id.toString());
4985
5012
  if (!deviceDoc) {
4986
- throw core_1.TransportErrors.general.recordNotFound(Device_1.Device, id.toString());
5013
+ throw core_1.CoreErrors.general.recordNotFound(Device_1.Device, id.toString());
4987
5014
  }
4988
5015
  const count = await this.devices.count();
4989
5016
  const device = Device_1.Device.from(deviceDoc);
4990
5017
  if (!device.initialPassword || device.publicKey || device.lastLoginAt) {
4991
- throw core_1.TransportErrors.device.alreadyOnboarded();
5018
+ throw core_1.CoreErrors.device.alreadyOnboarded();
4992
5019
  }
4993
5020
  const isAdmin = device.isAdmin === true;
4994
5021
  const secret = await this.parent.activeDevice.secrets.createDeviceSharedSecret(device, count, isAdmin);
@@ -4997,7 +5024,7 @@ class DevicesController extends TransportController_1.TransportController {
4997
5024
  async update(device) {
4998
5025
  const deviceDoc = await this.devices.read(device.id.toString());
4999
5026
  if (!deviceDoc) {
5000
- throw core_1.TransportErrors.general.recordNotFound(Device_1.Device, device.id.toString());
5027
+ throw core_1.CoreErrors.general.recordNotFound(Device_1.Device, device.id.toString());
5001
5028
  }
5002
5029
  await this.devices.update(deviceDoc, device);
5003
5030
  }
@@ -5480,7 +5507,7 @@ class FileController extends TransportController_1.TransportController {
5480
5507
  async updateCacheOfExistingFileInDb(id, response) {
5481
5508
  const fileDoc = await this.files.read(id);
5482
5509
  if (!fileDoc) {
5483
- throw core_1.TransportErrors.general.recordNotFound(File_1.File, id);
5510
+ throw core_1.CoreErrors.general.recordNotFound(File_1.File, id);
5484
5511
  }
5485
5512
  const file = File_1.File.from(fileDoc);
5486
5513
  await this.updateCacheOfFile(file, response);
@@ -5502,7 +5529,7 @@ class FileController extends TransportController_1.TransportController {
5502
5529
  const plaintextMetadataBuffer = await core_1.CoreCrypto.decrypt(cipher, secretKey);
5503
5530
  const plaintextMetadata = FileMetadata_1.FileMetadata.deserialize(plaintextMetadataBuffer.toUtf8());
5504
5531
  if (!(plaintextMetadata instanceof FileMetadata_1.FileMetadata)) {
5505
- throw core_1.TransportErrors.files.invalidMetadata(response.id);
5532
+ throw core_1.CoreErrors.files.invalidMetadata(response.id);
5506
5533
  }
5507
5534
  const cachedFile = CachedFile_1.CachedFile.fromBackbone(response, plaintextMetadata);
5508
5535
  return cachedFile;
@@ -5534,7 +5561,7 @@ class FileController extends TransportController_1.TransportController {
5534
5561
  const id = idOrFile instanceof core_1.CoreId ? idOrFile.toString() : idOrFile.id.toString();
5535
5562
  const fileDoc = await this.files.read(id);
5536
5563
  if (!fileDoc) {
5537
- throw core_1.TransportErrors.general.recordNotFound(File_1.File, id.toString());
5564
+ throw core_1.CoreErrors.general.recordNotFound(File_1.File, id.toString());
5538
5565
  }
5539
5566
  const file = File_1.File.from(fileDoc);
5540
5567
  file.setMetadata(metadata);
@@ -5546,7 +5573,7 @@ class FileController extends TransportController_1.TransportController {
5546
5573
  const content = input.buffer;
5547
5574
  const fileSize = content.length;
5548
5575
  if (fileSize > this.config.platformMaxUnencryptedFileSize) {
5549
- throw core_1.TransportErrors.files.maxFileSizeExceeded(fileSize, this.config.platformMaxUnencryptedFileSize);
5576
+ throw core_1.CoreErrors.files.maxFileSizeExceeded(fileSize, this.config.platformMaxUnencryptedFileSize);
5550
5577
  }
5551
5578
  const plaintextHashBuffer = await crypto_1.CryptoHash.hash(content, 2 /* CryptoHashAlgorithm.SHA512 */);
5552
5579
  const plaintextHash = core_1.CoreHash.from(plaintextHashBuffer.toBase64URL());
@@ -5609,23 +5636,22 @@ class FileController extends TransportController_1.TransportController {
5609
5636
  async downloadFileContent(idOrFile) {
5610
5637
  const file = idOrFile instanceof File_1.File ? idOrFile : await this.getFile(idOrFile);
5611
5638
  if (!file) {
5612
- throw core_1.TransportErrors.general.recordNotFound(File_1.File, idOrFile.toString());
5613
- }
5614
- if (!file.cache) {
5615
- throw core_1.TransportErrors.general.cacheEmpty(File_1.File, file.id.toString());
5639
+ throw core_1.CoreErrors.general.recordNotFound(File_1.File, idOrFile.toString());
5616
5640
  }
5641
+ if (!file.cache)
5642
+ throw this.newCacheEmptyError(File_1.File, file.id.toString());
5617
5643
  const downloadResponse = (await this.client.downloadFile(file.id.toString())).value;
5618
5644
  const buffer = crypto_1.CoreBuffer.fromObject(downloadResponse);
5619
5645
  const hash = await crypto_1.CryptoHash.hash(buffer, 2 /* CryptoHashAlgorithm.SHA512 */);
5620
5646
  const hashb64 = hash.toBase64URL();
5621
5647
  if (hashb64 !== file.cache.cipherHash.hash) {
5622
- throw core_1.TransportErrors.files.cipherMismatch();
5648
+ throw core_1.CoreErrors.files.cipherMismatch();
5623
5649
  }
5624
5650
  const cipher = crypto_1.CryptoCipher.fromBase64(buffer.toBase64URL());
5625
5651
  const decrypt = await core_1.CoreCrypto.decrypt(cipher, file.cache.cipherKey);
5626
5652
  const plaintextHashesMatch = await file.cache.plaintextHash.verify(decrypt, 2 /* CryptoHashAlgorithm.SHA512 */);
5627
5653
  if (!plaintextHashesMatch) {
5628
- throw core_1.TransportErrors.files.plaintextHashMismatch();
5654
+ throw core_1.CoreErrors.files.plaintextHashMismatch();
5629
5655
  }
5630
5656
  return decrypt;
5631
5657
  }
@@ -6361,7 +6387,7 @@ class MessageController extends TransportController_1.TransportController {
6361
6387
  async getMessagesByAddress(address) {
6362
6388
  const relationship = await this.parent.relationships.getActiveRelationshipToIdentity(address);
6363
6389
  if (!relationship) {
6364
- throw core_1.TransportErrors.messages.noMatchingRelationship(address.toString());
6390
+ throw core_1.CoreErrors.messages.noMatchingRelationship(address.toString());
6365
6391
  }
6366
6392
  return await this.getMessagesByRelationshipId(relationship.id);
6367
6393
  }
@@ -6401,7 +6427,7 @@ class MessageController extends TransportController_1.TransportController {
6401
6427
  async updateCacheOfExistingMessageInDb(id, response) {
6402
6428
  const messageDoc = await this.messages.read(id);
6403
6429
  if (!messageDoc) {
6404
- throw core_1.TransportErrors.general.recordNotFound(Message_1.Message, id);
6430
+ throw core_1.CoreErrors.general.recordNotFound(Message_1.Message, id);
6405
6431
  }
6406
6432
  const message = Message_1.Message.from(messageDoc);
6407
6433
  await this.updateCacheOfMessage(message, response);
@@ -6423,7 +6449,7 @@ class MessageController extends TransportController_1.TransportController {
6423
6449
  const envelope = this.getEnvelopeFromBackboneGetMessagesResponse(response);
6424
6450
  const [cachedMessage, messageKey, relationship] = await this.decryptMessage(envelope);
6425
6451
  if (!relationship) {
6426
- throw core_1.TransportErrors.general.recordNotFound(Relationship_1.Relationship, envelope.id.toString());
6452
+ throw core_1.CoreErrors.general.recordNotFound(Relationship_1.Relationship, envelope.id.toString());
6427
6453
  }
6428
6454
  const message = Message_1.Message.from({
6429
6455
  id: envelope.id,
@@ -6461,7 +6487,7 @@ class MessageController extends TransportController_1.TransportController {
6461
6487
  const id = idOrMessage instanceof core_1.CoreId ? idOrMessage.toString() : idOrMessage.id.toString();
6462
6488
  const messageDoc = await this.messages.read(id);
6463
6489
  if (!messageDoc) {
6464
- throw core_1.TransportErrors.general.recordNotFound(Message_1.Message, id.toString());
6490
+ throw core_1.CoreErrors.general.recordNotFound(Message_1.Message, id.toString());
6465
6491
  }
6466
6492
  const message = Message_1.Message.from(messageDoc);
6467
6493
  message.setMetadata(metadata);
@@ -6479,7 +6505,7 @@ class MessageController extends TransportController_1.TransportController {
6479
6505
  for (const recipient of parameters.recipients) {
6480
6506
  const relationship = await this.relationships.getActiveRelationshipToIdentity(core_1.CoreAddress.from(recipient));
6481
6507
  if (!relationship) {
6482
- throw core_1.TransportErrors.general.recordNotFound(Relationship_1.Relationship, recipient.toString());
6508
+ throw core_1.CoreErrors.general.recordNotFound(Relationship_1.Relationship, recipient.toString());
6483
6509
  }
6484
6510
  const cipherForRecipient = await this.secrets.encrypt(relationship.relationshipSecretId, serializedSecret);
6485
6511
  envelopeRecipients.push(MessageEnvelopeRecipient_1.MessageEnvelopeRecipient.from({
@@ -6508,7 +6534,7 @@ class MessageController extends TransportController_1.TransportController {
6508
6534
  for (const recipient of parameters.recipients) {
6509
6535
  const relationship = await this.relationships.getActiveRelationshipToIdentity(core_1.CoreAddress.from(recipient));
6510
6536
  if (!relationship) {
6511
- throw core_1.TransportErrors.general.recordNotFound(Relationship_1.Relationship, recipient.toString());
6537
+ throw core_1.CoreErrors.general.recordNotFound(Relationship_1.Relationship, recipient.toString());
6512
6538
  }
6513
6539
  const signature = await this.secrets.sign(relationship.relationshipSecretId, plaintextBuffer);
6514
6540
  const messageSignature = MessageSignature_1.MessageSignature.from({
@@ -6572,7 +6598,7 @@ class MessageController extends TransportController_1.TransportController {
6572
6598
  var _a, _b;
6573
6599
  const ownKeyCipher = (_a = envelope.recipients.find((r) => this.parent.identity.isMe(r.address))) === null || _a === void 0 ? void 0 : _a.encryptedKey;
6574
6600
  if (!ownKeyCipher) {
6575
- throw core_1.TransportErrors.messages.ownAddressNotInList(envelope.id.toString());
6601
+ throw core_1.CoreErrors.messages.ownAddressNotInList(envelope.id.toString());
6576
6602
  }
6577
6603
  const plaintextKeyBuffer = await this.secrets.decryptPeer(relationship.relationshipSecretId, ownKeyCipher, true);
6578
6604
  const plaintextKey = crypto_1.CryptoSecretKey.deserialize(plaintextKeyBuffer.toUtf8());
@@ -6580,7 +6606,7 @@ class MessageController extends TransportController_1.TransportController {
6580
6606
  const signedMessage = MessageSigned_1.MessageSigned.deserialize(plaintextMessageBuffer.toUtf8());
6581
6607
  const signature = (_b = signedMessage.signatures.find((s) => this.parent.identity.isMe(s.recipient))) === null || _b === void 0 ? void 0 : _b.signature;
6582
6608
  if (!signature) {
6583
- throw core_1.TransportErrors.messages.signatureListMismatch(envelope.id.toString());
6609
+ throw core_1.CoreErrors.messages.signatureListMismatch(envelope.id.toString());
6584
6610
  }
6585
6611
  const messagePlain = MessageContentWrapper_1.MessageContentWrapper.from(JSON.parse(signedMessage.message));
6586
6612
  if (signedMessage.signatures.length !== messagePlain.recipients.length) {
@@ -6589,7 +6615,7 @@ class MessageController extends TransportController_1.TransportController {
6589
6615
  const plainMessageBuffer = crypto_1.CoreBuffer.fromUtf8(signedMessage.message);
6590
6616
  const validSignature = await this.secrets.verifyPeer(relationship.relationshipSecretId, plainMessageBuffer, signature);
6591
6617
  if (!validSignature) {
6592
- throw core_1.TransportErrors.messages.signatureNotValid();
6618
+ throw core_1.CoreErrors.messages.signatureNotValid();
6593
6619
  }
6594
6620
  if (messagePlain.recipients.length !== envelope.recipients.length) {
6595
6621
  this.log.debug(`Number of signed recipients within the message does not match number of recipients from envelope ${envelope.id}.`);
@@ -6599,7 +6625,7 @@ class MessageController extends TransportController_1.TransportController {
6599
6625
  }
6600
6626
  const recipientFound = messagePlain.recipients.some((r) => this.parent.identity.isMe(r));
6601
6627
  if (!recipientFound) {
6602
- throw core_1.TransportErrors.messages.plaintextMismatch(envelope.id.toString());
6628
+ throw core_1.CoreErrors.messages.plaintextMismatch(envelope.id.toString());
6603
6629
  }
6604
6630
  return [messagePlain, plaintextKey];
6605
6631
  }
@@ -6610,7 +6636,7 @@ class MessageController extends TransportController_1.TransportController {
6610
6636
  let relationship;
6611
6637
  if (this.parent.identity.isMe(envelope.createdBy)) {
6612
6638
  if (!secretKey) {
6613
- throw new Error(`The own message (${envelope.id.toString()}) could not be decrypted, because no secret key was passed for it.`);
6639
+ throw new core_1.TransportError(`The own message (${envelope.id.toString()}) could not be decrypted, because no secret key was passed for it.`);
6614
6640
  }
6615
6641
  messageKey = secretKey;
6616
6642
  plainMessage = await this.decryptOwnEnvelope(envelope, secretKey);
@@ -6618,7 +6644,7 @@ class MessageController extends TransportController_1.TransportController {
6618
6644
  else {
6619
6645
  relationship = await this.relationships.getActiveRelationshipToIdentity(envelope.createdBy);
6620
6646
  if (!relationship) {
6621
- throw core_1.TransportErrors.messages.noMatchingRelationship(envelope.createdBy.toString());
6647
+ throw core_1.CoreErrors.messages.noMatchingRelationship(envelope.createdBy.toString());
6622
6648
  }
6623
6649
  const [peerMessage, peerKey] = await this.decryptPeerEnvelope(envelope, relationship);
6624
6650
  plainMessage = peerMessage;
@@ -7410,7 +7436,7 @@ class RelationshipTemplateController extends TransportController_1.TransportCont
7410
7436
  async updateCacheOfExistingTemplateInDb(id, response) {
7411
7437
  const templateDoc = await this.templates.read(id);
7412
7438
  if (!templateDoc) {
7413
- throw core_1.TransportErrors.general.recordNotFound(RelationshipTemplate_1.RelationshipTemplate, id);
7439
+ throw core_1.CoreErrors.general.recordNotFound(RelationshipTemplate_1.RelationshipTemplate, id);
7414
7440
  }
7415
7441
  const template = RelationshipTemplate_1.RelationshipTemplate.from(templateDoc);
7416
7442
  await this.updateCacheOfTemplate(template, response);
@@ -7434,7 +7460,7 @@ class RelationshipTemplateController extends TransportController_1.TransportCont
7434
7460
  const templateContent = RelationshipTemplateContentWrapper_1.RelationshipTemplateContentWrapper.deserialize(signedTemplate.serializedTemplate);
7435
7461
  const templateSignatureValid = await this.secrets.verifyTemplate(crypto_1.CoreBuffer.fromUtf8(signedTemplate.serializedTemplate), signedTemplate.deviceSignature, templateContent.identity.publicKey);
7436
7462
  if (!templateSignatureValid) {
7437
- throw core_1.TransportErrors.general.signatureNotValid("template");
7463
+ throw core_1.CoreErrors.general.signatureNotValid("template");
7438
7464
  }
7439
7465
  const cachedTemplate = CachedRelationshipTemplate_1.CachedRelationshipTemplate.from({
7440
7466
  content: templateContent.content,
@@ -7459,7 +7485,7 @@ class RelationshipTemplateController extends TransportController_1.TransportCont
7459
7485
  const id = idOrTemplate instanceof core_1.CoreId ? idOrTemplate.toString() : idOrTemplate.id.toString();
7460
7486
  const templateDoc = await this.templates.read(id);
7461
7487
  if (!templateDoc) {
7462
- throw core_1.TransportErrors.general.recordNotFound(RelationshipTemplate_1.RelationshipTemplate, id.toString());
7488
+ throw core_1.CoreErrors.general.recordNotFound(RelationshipTemplate_1.RelationshipTemplate, id.toString());
7463
7489
  }
7464
7490
  const template = RelationshipTemplate_1.RelationshipTemplate.from(templateDoc);
7465
7491
  template.setMetadata(metadata);
@@ -8020,8 +8046,8 @@ exports.RelationshipSecretController = void 0;
8020
8046
  const ts_utils_1 = __webpack_require__(/*! @js-soft/ts-utils */ "./node_modules/@js-soft/ts-utils/dist/index.js");
8021
8047
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
8022
8048
  const core_1 = __webpack_require__(/*! ../../core */ "./dist/core/index.js");
8049
+ const CoreErrors_1 = __webpack_require__(/*! ../../core/CoreErrors */ "./dist/core/CoreErrors.js");
8023
8050
  const CoreUtil_1 = __webpack_require__(/*! ../../core/CoreUtil */ "./dist/core/CoreUtil.js");
8024
- const TransportErrors_1 = __webpack_require__(/*! ../../core/TransportErrors */ "./dist/core/TransportErrors.js");
8025
8051
  const TransportIds_1 = __webpack_require__(/*! ../../core/TransportIds */ "./dist/core/TransportIds.js");
8026
8052
  const CachedRelationshipTemplate_1 = __webpack_require__(/*! ../relationshipTemplates/local/CachedRelationshipTemplate */ "./dist/modules/relationshipTemplates/local/CachedRelationshipTemplate.js");
8027
8053
  const RelationshipTemplatePublicKey_1 = __webpack_require__(/*! ../relationshipTemplates/transmission/RelationshipTemplatePublicKey */ "./dist/modules/relationshipTemplates/transmission/RelationshipTemplatePublicKey.js");
@@ -8039,11 +8065,11 @@ class RelationshipSecretController extends SecretController_1.SecretController {
8039
8065
  }
8040
8066
  const secretContainer = await this.loadActiveSecretByName(secretIdAsString);
8041
8067
  if (!secretContainer) {
8042
- throw TransportErrors_1.TransportErrors.general.recordNotFound("CryptoRelationshipRequestSecrets | CryptoRelationshipSecrets", secretIdAsString);
8068
+ throw CoreErrors_1.CoreErrors.general.recordNotFound("CryptoRelationshipRequestSecrets | CryptoRelationshipSecrets", secretIdAsString);
8043
8069
  }
8044
8070
  if (!(secretContainer.secret instanceof crypto_1.CryptoRelationshipRequestSecrets) &&
8045
8071
  !(secretContainer.secret instanceof crypto_1.CryptoRelationshipSecrets)) {
8046
- throw TransportErrors_1.TransportErrors.secrets.wrongSecretType(secretIdAsString);
8072
+ throw CoreErrors_1.CoreErrors.secrets.wrongSecretType(secretIdAsString);
8047
8073
  }
8048
8074
  const secret = secretContainer.secret;
8049
8075
  this.cache.set(relationshipSecretId, secret);
@@ -8059,10 +8085,10 @@ class RelationshipSecretController extends SecretController_1.SecretController {
8059
8085
  const templateKeyId = template.templateKey.id.toString();
8060
8086
  const exchangeKeypairContainer = await this.loadActiveSecretByName(templateKeyId);
8061
8087
  if (!exchangeKeypairContainer) {
8062
- throw TransportErrors_1.TransportErrors.general.recordNotFound(crypto_1.CryptoExchangeKeypair, templateKeyId);
8088
+ throw CoreErrors_1.CoreErrors.general.recordNotFound(crypto_1.CryptoExchangeKeypair, templateKeyId);
8063
8089
  }
8064
8090
  if (!(exchangeKeypairContainer.secret instanceof crypto_1.CryptoExchangeKeypair)) {
8065
- throw TransportErrors_1.TransportErrors.secrets.wrongSecretType(templateKeyId);
8091
+ throw CoreErrors_1.CoreErrors.secrets.wrongSecretType(templateKeyId);
8066
8092
  }
8067
8093
  const exchangeKeypair = exchangeKeypairContainer.secret;
8068
8094
  const secrets = await crypto_1.CryptoRelationshipSecrets.fromRelationshipRequest(publicRequestCrypto, exchangeKeypair);
@@ -8072,10 +8098,10 @@ class RelationshipSecretController extends SecretController_1.SecretController {
8072
8098
  async getPublicResponse(relationshipSecretId) {
8073
8099
  const secret = await this.loadActiveSecretByName(relationshipSecretId.toString());
8074
8100
  if (!secret) {
8075
- throw TransportErrors_1.TransportErrors.general.recordNotFound(crypto_1.CryptoRelationshipSecrets, relationshipSecretId.toString());
8101
+ throw CoreErrors_1.CoreErrors.general.recordNotFound(crypto_1.CryptoRelationshipSecrets, relationshipSecretId.toString());
8076
8102
  }
8077
8103
  if (!(secret.secret instanceof crypto_1.CryptoRelationshipSecrets)) {
8078
- throw TransportErrors_1.TransportErrors.secrets.wrongSecretType(secret.id.toString());
8104
+ throw CoreErrors_1.CoreErrors.secrets.wrongSecretType(secret.id.toString());
8079
8105
  }
8080
8106
  const publicResponse = secret.secret.toPublicResponse();
8081
8107
  return publicResponse;
@@ -8083,7 +8109,7 @@ class RelationshipSecretController extends SecretController_1.SecretController {
8083
8109
  async convertSecrets(relationshipSecretId, response) {
8084
8110
  const request = await this.getSecret(relationshipSecretId);
8085
8111
  if (request instanceof crypto_1.CryptoRelationshipSecrets) {
8086
- throw TransportErrors_1.TransportErrors.secrets.wrongSecretType();
8112
+ throw CoreErrors_1.CoreErrors.secrets.wrongSecretType();
8087
8113
  }
8088
8114
  const secrets = await crypto_1.CryptoRelationshipSecrets.fromRelationshipResponse(response, request);
8089
8115
  const container = await this.succeedSecretWithName(secrets, relationshipSecretId.toString());
@@ -8108,7 +8134,7 @@ class RelationshipSecretController extends SecretController_1.SecretController {
8108
8134
  const buffer = CoreUtil_1.CoreUtil.toBuffer(content);
8109
8135
  const secrets = await this.getSecret(relationshipSecretId);
8110
8136
  if (!(secrets instanceof crypto_1.CryptoRelationshipRequestSecrets)) {
8111
- throw TransportErrors_1.TransportErrors.secrets.wrongSecretType(secrets.id);
8137
+ throw CoreErrors_1.CoreErrors.secrets.wrongSecretType(secrets.id);
8112
8138
  }
8113
8139
  return await secrets.encryptRequest(buffer);
8114
8140
  }
@@ -8116,14 +8142,14 @@ class RelationshipSecretController extends SecretController_1.SecretController {
8116
8142
  const buffer = CoreUtil_1.CoreUtil.toBuffer(content);
8117
8143
  const secrets = await this.getSecret(relationshipSecretId);
8118
8144
  if (!(secrets instanceof crypto_1.CryptoRelationshipSecrets)) {
8119
- throw TransportErrors_1.TransportErrors.secrets.wrongSecretType(secrets.id);
8145
+ throw CoreErrors_1.CoreErrors.secrets.wrongSecretType(secrets.id);
8120
8146
  }
8121
8147
  return await secrets.encrypt(buffer);
8122
8148
  }
8123
8149
  async decryptRequest(relationshipSecretId, cipher) {
8124
8150
  const secrets = await this.getSecret(relationshipSecretId);
8125
8151
  if (!(secrets instanceof crypto_1.CryptoRelationshipRequestSecrets) && !(secrets instanceof crypto_1.CryptoRelationshipSecrets)) {
8126
- throw TransportErrors_1.TransportErrors.secrets.wrongSecretType(relationshipSecretId.toString());
8152
+ throw CoreErrors_1.CoreErrors.secrets.wrongSecretType(relationshipSecretId.toString());
8127
8153
  }
8128
8154
  return await secrets.decryptRequest(cipher);
8129
8155
  }
@@ -8140,7 +8166,7 @@ class RelationshipSecretController extends SecretController_1.SecretController {
8140
8166
  async decryptPeer(relationshipSecretId, cipher, omitCounterCheck = false) {
8141
8167
  const secrets = await this.getSecret(relationshipSecretId);
8142
8168
  if (!(secrets instanceof crypto_1.CryptoRelationshipSecrets)) {
8143
- throw TransportErrors_1.TransportErrors.secrets.wrongSecretType(secrets.id);
8169
+ throw CoreErrors_1.CoreErrors.secrets.wrongSecretType(secrets.id);
8144
8170
  }
8145
8171
  return await secrets.decryptPeer(cipher, omitCounterCheck);
8146
8172
  }
@@ -8151,7 +8177,7 @@ class RelationshipSecretController extends SecretController_1.SecretController {
8151
8177
  async decryptOwn(relationshipSecretId, cipher) {
8152
8178
  const secrets = await this.getSecret(relationshipSecretId);
8153
8179
  if (!(secrets instanceof crypto_1.CryptoRelationshipSecrets)) {
8154
- throw TransportErrors_1.TransportErrors.secrets.wrongSecretType(secrets.id);
8180
+ throw CoreErrors_1.CoreErrors.secrets.wrongSecretType(secrets.id);
8155
8181
  }
8156
8182
  return await secrets.decryptOwn(cipher);
8157
8183
  }
@@ -8169,7 +8195,7 @@ class RelationshipSecretController extends SecretController_1.SecretController {
8169
8195
  const bufferToVerify = CoreUtil_1.CoreUtil.toBuffer(content);
8170
8196
  const secrets = await this.getSecret(relationshipSecretId);
8171
8197
  if (secrets instanceof crypto_1.CryptoRelationshipRequestSecrets) {
8172
- throw TransportErrors_1.TransportErrors.secrets.wrongSecretType(secrets.id);
8198
+ throw CoreErrors_1.CoreErrors.secrets.wrongSecretType(secrets.id);
8173
8199
  }
8174
8200
  const valid = await secrets.verifyPeer(bufferToVerify, signature);
8175
8201
  return valid;
@@ -8267,9 +8293,9 @@ const ts_utils_1 = __webpack_require__(/*! @js-soft/ts-utils */ "./node_modules/
8267
8293
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
8268
8294
  const ts_simple_nameof_1 = __webpack_require__(/*! ts-simple-nameof */ "./node_modules/ts-simple-nameof/index.js");
8269
8295
  const core_1 = __webpack_require__(/*! ../../core */ "./dist/core/index.js");
8296
+ const CoreErrors_1 = __webpack_require__(/*! ../../core/CoreErrors */ "./dist/core/CoreErrors.js");
8270
8297
  const CoreUtil_1 = __webpack_require__(/*! ../../core/CoreUtil */ "./dist/core/CoreUtil.js");
8271
8298
  const DbCollectionName_1 = __webpack_require__(/*! ../../core/DbCollectionName */ "./dist/core/DbCollectionName.js");
8272
- const TransportErrors_1 = __webpack_require__(/*! ../../core/TransportErrors */ "./dist/core/TransportErrors.js");
8273
8299
  const TransportIds_1 = __webpack_require__(/*! ../../core/TransportIds */ "./dist/core/TransportIds.js");
8274
8300
  const events_1 = __webpack_require__(/*! ../../events */ "./dist/events/index.js");
8275
8301
  const RelationshipTemplate_1 = __webpack_require__(/*! ../relationshipTemplates/local/RelationshipTemplate */ "./dist/modules/relationshipTemplates/local/RelationshipTemplate.js");
@@ -8331,7 +8357,7 @@ class RelationshipsController extends core_1.TransportController {
8331
8357
  async updateCacheOfExistingRelationshipInDb(id, response) {
8332
8358
  const relationshipDoc = await this.relationships.read(id);
8333
8359
  if (!relationshipDoc)
8334
- throw TransportErrors_1.TransportErrors.general.recordNotFound(Relationship_1.Relationship, id);
8360
+ throw CoreErrors_1.CoreErrors.general.recordNotFound(Relationship_1.Relationship, id);
8335
8361
  const relationship = Relationship_1.Relationship.from(relationshipDoc);
8336
8362
  await this.updateCacheOfRelationship(relationship, response);
8337
8363
  await this.relationships.update(relationshipDoc, relationship);
@@ -8373,7 +8399,7 @@ class RelationshipsController extends core_1.TransportController {
8373
8399
  parameters = SendRelationshipParameters_1.SendRelationshipParameters.from(parameters);
8374
8400
  const template = parameters.template;
8375
8401
  if (!template.cache) {
8376
- throw TransportErrors_1.TransportErrors.general.cacheEmpty(RelationshipTemplate_1.RelationshipTemplate, template.id.toString());
8402
+ throw this.newCacheEmptyError(RelationshipTemplate_1.RelationshipTemplate, template.id.toString());
8377
8403
  }
8378
8404
  const secretId = await TransportIds_1.TransportIds.relationshipSecret.generate();
8379
8405
  const { requestCipher, requestContent } = await this.prepareRequest(secretId, template, parameters.content);
@@ -8390,7 +8416,7 @@ class RelationshipsController extends core_1.TransportController {
8390
8416
  const id = idOrRelationship instanceof core_1.CoreId ? idOrRelationship.toString() : idOrRelationship.id.toString();
8391
8417
  const relationshipDoc = await this.relationships.read(id);
8392
8418
  if (!relationshipDoc)
8393
- throw TransportErrors_1.TransportErrors.general.recordNotFound(Relationship_1.Relationship, id.toString());
8419
+ throw CoreErrors_1.CoreErrors.general.recordNotFound(Relationship_1.Relationship, id.toString());
8394
8420
  const relationship = Relationship_1.Relationship.from(relationshipDoc);
8395
8421
  relationship.metadata = metadata;
8396
8422
  relationship.metadataModifiedAt = core_1.CoreDate.utc();
@@ -8418,7 +8444,7 @@ class RelationshipsController extends core_1.TransportController {
8418
8444
  this._log.trace(`Parsing relationship template ${templateId} for ${response.id}...`);
8419
8445
  const template = await this.parent.relationshipTemplates.getRelationshipTemplate(templateId);
8420
8446
  if (!template) {
8421
- throw TransportErrors_1.TransportErrors.general.recordNotFound(RelationshipTemplate_1.RelationshipTemplate, templateId.toString());
8447
+ throw CoreErrors_1.CoreErrors.general.recordNotFound(RelationshipTemplate_1.RelationshipTemplate, templateId.toString());
8422
8448
  }
8423
8449
  this._log.trace(`Parsing relationship changes of ${response.id}...`);
8424
8450
  const changesPromises = [];
@@ -8440,7 +8466,7 @@ class RelationshipsController extends core_1.TransportController {
8440
8466
  }
8441
8467
  async prepareRequest(relationshipSecretId, template, content) {
8442
8468
  if (!template.cache) {
8443
- throw TransportErrors_1.TransportErrors.general.cacheEmpty(RelationshipTemplate_1.RelationshipTemplate, template.id.toString());
8469
+ throw this.newCacheEmptyError(RelationshipTemplate_1.RelationshipTemplate, template.id.toString());
8444
8470
  }
8445
8471
  const requestPublic = await this.secrets.createRequestorSecrets(template.cache, relationshipSecretId);
8446
8472
  const requestContent = RelationshipCreationChangeRequestContentWrapper_1.RelationshipCreationChangeRequestContentWrapper.from({
@@ -8476,9 +8502,9 @@ class RelationshipsController extends core_1.TransportController {
8476
8502
  return await this.applyCreationChange(change);
8477
8503
  case RelationshipChangeType_1.RelationshipChangeType.Termination:
8478
8504
  case RelationshipChangeType_1.RelationshipChangeType.TerminationCancellation:
8479
- throw TransportErrors_1.TransportErrors.general.notSupported();
8505
+ throw CoreErrors_1.CoreErrors.general.notSupported();
8480
8506
  default:
8481
- throw TransportErrors_1.TransportErrors.general.incompatibleBackbone();
8507
+ throw CoreErrors_1.CoreErrors.general.incompatibleBackbone();
8482
8508
  }
8483
8509
  }
8484
8510
  async applyCreationChange(change) {
@@ -8529,11 +8555,11 @@ class RelationshipsController extends core_1.TransportController {
8529
8555
  relationshipSignatureValid = await this.secrets.verifyPeer(secretId, crypto_1.CoreBuffer.fromUtf8(signedRequest.serializedRequest), signedRequest.relationshipSignature);
8530
8556
  }
8531
8557
  if (!relationshipSignatureValid) {
8532
- throw TransportErrors_1.TransportErrors.general.signatureNotValid("relationshipRequest");
8558
+ throw CoreErrors_1.CoreErrors.general.signatureNotValid("relationshipRequest");
8533
8559
  }
8534
8560
  const requestContent = RelationshipCreationChangeRequestContentWrapper_1.RelationshipCreationChangeRequestContentWrapper.deserialize(signedRequest.serializedRequest);
8535
8561
  if (!requestContent.templateId.equals(templateId)) {
8536
- throw new Error("The relationship request contains a wrong template id.");
8562
+ throw new core_1.TransportError("The relationship request contains a wrong template id.");
8537
8563
  }
8538
8564
  return requestContent;
8539
8565
  }
@@ -8568,11 +8594,11 @@ class RelationshipsController extends core_1.TransportController {
8568
8594
  relationshipSignatureValid = await this.secrets.verifyPeer(relationshipSecretId, crypto_1.CoreBuffer.fromUtf8(signedResponse.serializedResponse), signedResponse.relationshipSignature);
8569
8595
  }
8570
8596
  if (!relationshipSignatureValid) {
8571
- throw TransportErrors_1.TransportErrors.general.signatureNotValid("relationshipResponse");
8597
+ throw CoreErrors_1.CoreErrors.general.signatureNotValid("relationshipResponse");
8572
8598
  }
8573
8599
  const responseContent = RelationshipCreationChangeResponseContentWrapper_1.RelationshipCreationChangeResponseContentWrapper.deserialize(signedResponse.serializedResponse);
8574
8600
  if (!responseContent.relationshipId.equals(change.relationshipId)) {
8575
- throw new Error("The relationship response contains a wrong relationship id.");
8601
+ throw new core_1.TransportError("The relationship response contains a wrong relationship id.");
8576
8602
  }
8577
8603
  return responseContent;
8578
8604
  }
@@ -8593,14 +8619,14 @@ class RelationshipsController extends core_1.TransportController {
8593
8619
  const cipher = RelationshipCreationChangeResponseCipher_1.RelationshipCreationChangeResponseCipher.fromBase64(change.response.content);
8594
8620
  if (change.status !== RelationshipChangeStatus_1.RelationshipChangeStatus.Revoked) {
8595
8621
  if (!cipher.publicResponseCrypto) {
8596
- throw new Error("The response crypto is missing.");
8622
+ throw new core_1.TransportError("The response crypto is missing.");
8597
8623
  }
8598
8624
  await this.secrets.convertSecrets(relationship.relationshipSecretId, cipher.publicResponseCrypto);
8599
8625
  }
8600
8626
  const responseContent = await this.decryptCreationChangeResponse(change, relationship.relationshipSecretId);
8601
8627
  const response = RelationshipChangeResponse_1.RelationshipChangeResponse.fromBackbone(change.response, responseContent.content);
8602
8628
  if (!relationship.cache) {
8603
- throw TransportErrors_1.TransportErrors.general.cacheEmpty(Relationship_1.Relationship, relationship.id.toString());
8629
+ throw this.newCacheEmptyError(Relationship_1.Relationship, relationship.id.toString());
8604
8630
  }
8605
8631
  relationship.cache.changes[0].status = change.status;
8606
8632
  switch (change.status) {
@@ -8614,7 +8640,7 @@ class RelationshipsController extends core_1.TransportController {
8614
8640
  relationship.toRevoked(response);
8615
8641
  break;
8616
8642
  default:
8617
- throw TransportErrors_1.TransportErrors.general.incompatibleBackbone();
8643
+ throw CoreErrors_1.CoreErrors.general.incompatibleBackbone();
8618
8644
  }
8619
8645
  await this.relationships.update(relationshipDoc, relationship);
8620
8646
  return relationship;
@@ -8624,9 +8650,9 @@ class RelationshipsController extends core_1.TransportController {
8624
8650
  const templateId = core_1.CoreId.from(backboneRelationship.relationshipTemplateId);
8625
8651
  const template = await this.parent.relationshipTemplates.getRelationshipTemplate(templateId);
8626
8652
  if (!template)
8627
- throw TransportErrors_1.TransportErrors.general.recordNotFound(RelationshipTemplate_1.RelationshipTemplate, templateId.toString());
8653
+ throw CoreErrors_1.CoreErrors.general.recordNotFound(RelationshipTemplate_1.RelationshipTemplate, templateId.toString());
8628
8654
  if (!template.cache)
8629
- throw TransportErrors_1.TransportErrors.general.cacheEmpty(RelationshipTemplate_1.RelationshipTemplate, template.id.toString());
8655
+ throw this.newCacheEmptyError(RelationshipTemplate_1.RelationshipTemplate, template.id.toString());
8630
8656
  if (!change.request.content)
8631
8657
  throw this.newEmptyOrInvalidContentError(change);
8632
8658
  const secretId = await TransportIds_1.TransportIds.relationshipSecret.generate();
@@ -8641,21 +8667,21 @@ class RelationshipsController extends core_1.TransportController {
8641
8667
  async completeChange(targetStatus, change, content) {
8642
8668
  const relationshipDoc = await this.relationships.read(change.relationshipId.toString());
8643
8669
  if (!relationshipDoc) {
8644
- throw TransportErrors_1.TransportErrors.general.recordNotFound(Relationship_1.Relationship, change.relationshipId.toString());
8670
+ throw CoreErrors_1.CoreErrors.general.recordNotFound(Relationship_1.Relationship, change.relationshipId.toString());
8645
8671
  }
8646
8672
  const relationship = Relationship_1.Relationship.from(relationshipDoc);
8647
8673
  if (!relationship.cache) {
8648
8674
  await this.updateCacheOfRelationship(relationship);
8649
8675
  }
8650
8676
  if (!relationship.cache) {
8651
- throw TransportErrors_1.TransportErrors.general.cacheEmpty(Relationship_1.Relationship, relationship.id.toString());
8677
+ throw this.newCacheEmptyError(Relationship_1.Relationship, relationship.id.toString());
8652
8678
  }
8653
8679
  const queriedChange = relationship.cache.changes.find((r) => r.id.toString() === change.id.toString());
8654
8680
  if (!queriedChange) {
8655
- throw TransportErrors_1.TransportErrors.general.recordNotFound(RelationshipChange_1.RelationshipChange, change.id.toString());
8681
+ throw CoreErrors_1.CoreErrors.general.recordNotFound(RelationshipChange_1.RelationshipChange, change.id.toString());
8656
8682
  }
8657
8683
  if (queriedChange.status !== RelationshipChangeStatus_1.RelationshipChangeStatus.Pending) {
8658
- throw TransportErrors_1.TransportErrors.relationships.wrongChangeStatus(queriedChange.status);
8684
+ throw CoreErrors_1.CoreErrors.relationships.wrongChangeStatus(queriedChange.status);
8659
8685
  }
8660
8686
  let encryptedContent;
8661
8687
  if (content) {
@@ -8676,7 +8702,7 @@ class RelationshipsController extends core_1.TransportController {
8676
8702
  backboneResponse = (await this.client.revokeRelationshipChange(relationship.id.toString(), change.id.toString(), encryptedContent)).value;
8677
8703
  break;
8678
8704
  default:
8679
- throw new Error("target change status not supported");
8705
+ throw new core_1.TransportError("target change status not supported");
8680
8706
  }
8681
8707
  const backboneChange = backboneResponse.changes[backboneResponse.changes.length - 1];
8682
8708
  queriedChange.response = RelationshipChangeResponse_1.RelationshipChangeResponse.fromBackbone(backboneResponse.changes[backboneResponse.changes.length - 1].response, content);
@@ -8733,13 +8759,13 @@ class RelationshipsController extends core_1.TransportController {
8733
8759
  return responseCipher.toBase64();
8734
8760
  }
8735
8761
  throwWrongChangeType(type) {
8736
- throw new Error(`The relationship change has the wrong type (${type}) to run this operation`);
8762
+ throw new core_1.TransportError(`The relationship change has the wrong type (${type}) to run this operation`);
8737
8763
  }
8738
8764
  newChangeResponseMissingError(changeId) {
8739
- return new Error(`The response of the relationship change (${changeId}) is missing`);
8765
+ return new core_1.TransportError(`The response of the relationship change (${changeId}) is missing`);
8740
8766
  }
8741
8767
  newEmptyOrInvalidContentError(change) {
8742
- return new Error(`The content property of the relationship change ${change === null || change === void 0 ? void 0 : change.id} is missing or invalid`);
8768
+ return new core_1.TransportError(`The content property of the relationship change ${change === null || change === void 0 ? void 0 : change.id} is missing or invalid`);
8743
8769
  }
8744
8770
  }
8745
8771
  __decorate([
@@ -9023,23 +9049,20 @@ let Relationship = Relationship_1 = class Relationship extends core_1.CoreSynchr
9023
9049
  });
9024
9050
  }
9025
9051
  toActive(response) {
9026
- if (!this.cache) {
9027
- throw core_1.TransportErrors.general.cacheEmpty(Relationship_1, this.id.toString());
9028
- }
9052
+ if (!this.cache)
9053
+ throw this.newCacheEmptyError();
9029
9054
  this.cache.changes[0].response = response;
9030
9055
  this.status = RelationshipStatus_1.RelationshipStatus.Active;
9031
9056
  }
9032
9057
  toRejected(response) {
9033
- if (!this.cache) {
9034
- throw core_1.TransportErrors.general.cacheEmpty(Relationship_1, this.id.toString());
9035
- }
9058
+ if (!this.cache)
9059
+ throw this.newCacheEmptyError();
9036
9060
  this.cache.changes[0].response = response;
9037
9061
  this.status = RelationshipStatus_1.RelationshipStatus.Rejected;
9038
9062
  }
9039
9063
  toRevoked(response) {
9040
- if (!this.cache) {
9041
- throw core_1.TransportErrors.general.cacheEmpty(Relationship_1, this.id.toString());
9042
- }
9064
+ if (!this.cache)
9065
+ throw this.newCacheEmptyError();
9043
9066
  this.cache.changes[0].response = response;
9044
9067
  this.status = RelationshipStatus_1.RelationshipStatus.Revoked;
9045
9068
  }
@@ -9056,6 +9079,9 @@ let Relationship = Relationship_1 = class Relationship extends core_1.CoreSynchr
9056
9079
  this.metadataModifiedAt = core_1.CoreDate.utc();
9057
9080
  return this;
9058
9081
  }
9082
+ newCacheEmptyError() {
9083
+ return new core_1.TransportError(`The cache of the Relationship with id "${this.id}" is empty.`);
9084
+ }
9059
9085
  };
9060
9086
  __decorate([
9061
9087
  (0, ts_serval_1.validate)(),
@@ -9871,7 +9897,7 @@ class SecretController extends TransportController_1.TransportController {
9871
9897
  this.baseKey = baseKey.secret;
9872
9898
  }
9873
9899
  else {
9874
- throw core_1.TransportErrors.general.recordNotFound(crypto_1.CryptoSecretKey, DeviceSecretController_1.DeviceSecretType.SharedSecretBaseKey);
9900
+ throw core_1.CoreErrors.general.recordNotFound(crypto_1.CryptoSecretKey, DeviceSecretController_1.DeviceSecretType.SharedSecretBaseKey);
9875
9901
  }
9876
9902
  return this.baseKey;
9877
9903
  }
@@ -10135,7 +10161,7 @@ class DatawalletModificationMapper {
10135
10161
  type = DatawalletModification_1.DatawalletModificationType.CacheChanged;
10136
10162
  break;
10137
10163
  default:
10138
- throw new Error("Unsupported DatawalletModificationType '${backboneDatawalletModification.type}'");
10164
+ throw new core_1.TransportError("Unsupported DatawalletModificationType '${backboneDatawalletModification.type}'");
10139
10165
  }
10140
10166
  let payloadCategory;
10141
10167
  switch (backboneDatawalletModification.payloadCategory) {
@@ -10152,7 +10178,7 @@ class DatawalletModificationMapper {
10152
10178
  payloadCategory = undefined;
10153
10179
  break;
10154
10180
  default:
10155
- throw new Error(`Unsupported DatawalletModificationCategory '${backboneDatawalletModification.payloadCategory}'`);
10181
+ throw new core_1.TransportError(`Unsupported DatawalletModificationCategory '${backboneDatawalletModification.payloadCategory}'`);
10156
10182
  }
10157
10183
  return DatawalletModification_1.DatawalletModification.from({
10158
10184
  localId: await core_1.TransportIds.datawalletModification.generate(),
@@ -10289,7 +10315,7 @@ class DatawalletModificationsProcessor {
10289
10315
  const targetCollection = await this.collectionProvider.getCollection(updateModification.collection);
10290
10316
  const oldDoc = await targetCollection.read(updateModification.objectIdentifier.toString());
10291
10317
  if (!oldDoc) {
10292
- throw new Error("Document to update was not found.");
10318
+ throw new core_1.TransportError("Document to update was not found.");
10293
10319
  }
10294
10320
  const oldObject = core_1.CoreSerializable.fromUnknown(oldDoc);
10295
10321
  const newObject = { ...oldObject.toJSON(), ...updateModification.payload };
@@ -10326,7 +10352,7 @@ class DatawalletModificationsProcessor {
10326
10352
  const uniqueCollections = [...new Set(collections)];
10327
10353
  const collectionsWithUncacheableItems = uniqueCollections.filter((c) => !this.collectionsWithCacheableItems.includes(c));
10328
10354
  if (collectionsWithUncacheableItems.length > 0) {
10329
- throw core_1.TransportErrors.datawallet.unsupportedModification("unsupportedCacheChangedModificationCollection", collectionsWithUncacheableItems);
10355
+ throw core_1.CoreErrors.datawallet.unsupportedModification("unsupportedCacheChangedModificationCollection", collectionsWithUncacheableItems);
10330
10356
  }
10331
10357
  }
10332
10358
  groupCacheChangesByCollection(cacheChanges) {
@@ -10449,7 +10475,7 @@ class ExternalEventsProcessor {
10449
10475
  await this.applyRelationshipChangeCompletedEvent(externalEvent);
10450
10476
  break;
10451
10477
  default:
10452
- throw new Error(`'${externalEvent.type}' is not a supported external event type.`);
10478
+ throw new core_1.TransportError(`'${externalEvent.type}' is not a supported external event type.`);
10453
10479
  }
10454
10480
  this.results.push({
10455
10481
  externalEventId: externalEvent.id
@@ -10672,7 +10698,7 @@ class SyncController extends core_1.TransportController {
10672
10698
  if (this.config.supportedDatawalletVersion < identityDatawalletVersion) {
10673
10699
  // This means that the datawallet of the identity was upgraded by another device with a higher version.
10674
10700
  // It is necesssary to update the current device.
10675
- throw core_1.TransportErrors.datawallet.insufficientSupportedDatawalletVersion(this.config.supportedDatawalletVersion, identityDatawalletVersion);
10701
+ throw core_1.CoreErrors.datawallet.insufficientSupportedDatawalletVersion(this.config.supportedDatawalletVersion, identityDatawalletVersion);
10676
10702
  }
10677
10703
  this.log.trace("Synchronization of Datawallet events started...");
10678
10704
  try {
@@ -10684,7 +10710,7 @@ class SyncController extends core_1.TransportController {
10684
10710
  const outdatedErrorCode = "error.platform.validation.datawallet.insufficientSupportedDatawalletVersion";
10685
10711
  if (!(e instanceof core_1.RequestError) || e.code !== outdatedErrorCode)
10686
10712
  throw e;
10687
- throw core_1.TransportErrors.datawallet.insufficientSupportedDatawalletVersion(this.config.supportedDatawalletVersion, identityDatawalletVersion);
10713
+ throw core_1.CoreErrors.datawallet.insufficientSupportedDatawalletVersion(this.config.supportedDatawalletVersion, identityDatawalletVersion);
10688
10714
  }
10689
10715
  this.log.trace("Synchronization of Datawallet events ended...");
10690
10716
  await this.checkDatawalletVersion(identityDatawalletVersion);
@@ -10692,7 +10718,7 @@ class SyncController extends core_1.TransportController {
10692
10718
  async checkDatawalletVersion(identityDatawalletVersion) {
10693
10719
  var _a;
10694
10720
  if (this.config.supportedDatawalletVersion < identityDatawalletVersion) {
10695
- throw core_1.TransportErrors.datawallet.insufficientSupportedDatawalletVersion(this.config.supportedDatawalletVersion, identityDatawalletVersion);
10721
+ throw core_1.CoreErrors.datawallet.insufficientSupportedDatawalletVersion(this.config.supportedDatawalletVersion, identityDatawalletVersion);
10696
10722
  }
10697
10723
  if (this.config.supportedDatawalletVersion > identityDatawalletVersion) {
10698
10724
  await this.upgradeIdentityDatawalletVersion(identityDatawalletVersion, this.config.supportedDatawalletVersion);
@@ -10706,10 +10732,10 @@ class SyncController extends core_1.TransportController {
10706
10732
  if (identityDatawalletVersion === targetDatawalletVersion)
10707
10733
  return;
10708
10734
  if (this.config.supportedDatawalletVersion < targetDatawalletVersion) {
10709
- throw core_1.TransportErrors.datawallet.insufficientSupportedDatawalletVersion(targetDatawalletVersion, identityDatawalletVersion);
10735
+ throw core_1.CoreErrors.datawallet.insufficientSupportedDatawalletVersion(targetDatawalletVersion, identityDatawalletVersion);
10710
10736
  }
10711
10737
  if (identityDatawalletVersion > targetDatawalletVersion) {
10712
- throw core_1.TransportErrors.datawallet.currentBiggerThanTarget(identityDatawalletVersion, targetDatawalletVersion);
10738
+ throw core_1.CoreErrors.datawallet.currentBiggerThanTarget(identityDatawalletVersion, targetDatawalletVersion);
10713
10739
  }
10714
10740
  while (identityDatawalletVersion < targetDatawalletVersion) {
10715
10741
  identityDatawalletVersion++;
@@ -10726,10 +10752,10 @@ class SyncController extends core_1.TransportController {
10726
10752
  if (deviceDatawalletVersion === targetDatawalletVersion)
10727
10753
  return;
10728
10754
  if (this.config.supportedDatawalletVersion < targetDatawalletVersion) {
10729
- throw core_1.TransportErrors.datawallet.insufficientSupportedDatawalletVersion(targetDatawalletVersion, deviceDatawalletVersion);
10755
+ throw core_1.CoreErrors.datawallet.insufficientSupportedDatawalletVersion(targetDatawalletVersion, deviceDatawalletVersion);
10730
10756
  }
10731
10757
  if (deviceDatawalletVersion > targetDatawalletVersion) {
10732
- throw core_1.TransportErrors.datawallet.currentBiggerThanTarget(deviceDatawalletVersion, targetDatawalletVersion);
10758
+ throw core_1.CoreErrors.datawallet.currentBiggerThanTarget(deviceDatawalletVersion, targetDatawalletVersion);
10733
10759
  }
10734
10760
  while (deviceDatawalletVersion < targetDatawalletVersion) {
10735
10761
  deviceDatawalletVersion++;
@@ -10856,7 +10882,7 @@ class SyncController extends core_1.TransportController {
10856
10882
  }
10857
10883
  async finalizeExternalEventsSyncRun(externalEventResults) {
10858
10884
  if (!this.currentSyncRun) {
10859
- throw new Error("There is no active sync run to finalize");
10885
+ throw new core_1.TransportError("There is no active sync run to finalize");
10860
10886
  }
10861
10887
  const { backboneModifications, localModificationIds } = await this.prepareLocalDatawalletModificationsForPush();
10862
10888
  await this.client.finalizeExternalEventSync(this.currentSyncRun.id.toString(), {
@@ -10871,7 +10897,7 @@ class SyncController extends core_1.TransportController {
10871
10897
  }
10872
10898
  async finalizeDatawalletVersionUpgradeSyncRun(newDatawalletVersion) {
10873
10899
  if (!this.currentSyncRun) {
10874
- throw new Error("There is no active sync run to finalize");
10900
+ throw new core_1.TransportError("There is no active sync run to finalize");
10875
10901
  }
10876
10902
  const { backboneModifications, localModificationIds } = await this.prepareLocalDatawalletModificationsForPush();
10877
10903
  await this.client.finalizeDatawalletVersionUpgrade(this.currentSyncRun.id.toString(), {
@@ -10913,7 +10939,7 @@ class SyncController extends core_1.TransportController {
10913
10939
  await this.setSyncTimeByName("Datawallet");
10914
10940
  }
10915
10941
  newNoMigrationAvailableError(version) {
10916
- return new Error(`There is no migration available for the datawallet version '${version}'.`);
10942
+ return new core_1.TransportError(`There is no migration available for the datawallet version '${version}'.`);
10917
10943
  }
10918
10944
  }
10919
10945
  __decorate([
@@ -11461,7 +11487,7 @@ class AnonymousTokenController {
11461
11487
  const plaintextTokenBuffer = await core_1.CoreCrypto.decrypt(cipher, secretKey);
11462
11488
  const plaintextTokenContent = core_1.CoreSerializable.deserializeUnknown(plaintextTokenBuffer.toUtf8());
11463
11489
  if (!(plaintextTokenContent instanceof ts_serval_1.Serializable)) {
11464
- throw core_1.TransportErrors.tokens.invalidTokenContent(id.toString());
11490
+ throw core_1.CoreErrors.tokens.invalidTokenContent(id.toString());
11465
11491
  }
11466
11492
  const token = Token_1.Token.from({
11467
11493
  id: id,
@@ -11561,7 +11587,7 @@ class TokenController extends TransportController_1.TransportController {
11561
11587
  const id = idOrToken instanceof core_1.CoreId ? idOrToken.toString() : idOrToken.id.toString();
11562
11588
  const tokenDoc = await this.tokens.read(id);
11563
11589
  if (!tokenDoc) {
11564
- throw core_1.TransportErrors.general.recordNotFound(Token_1.Token, id.toString());
11590
+ throw core_1.CoreErrors.general.recordNotFound(Token_1.Token, id.toString());
11565
11591
  }
11566
11592
  const token = Token_1.Token.from(tokenDoc);
11567
11593
  token.setMetadata(metadata);
@@ -11598,7 +11624,7 @@ class TokenController extends TransportController_1.TransportController {
11598
11624
  async updateCacheOfExistingTokenInDb(id, response) {
11599
11625
  const tokenDoc = await this.tokens.read(id);
11600
11626
  if (!tokenDoc) {
11601
- core_1.TransportErrors.general.recordNotFound(Token_1.Token, id);
11627
+ core_1.CoreErrors.general.recordNotFound(Token_1.Token, id);
11602
11628
  return;
11603
11629
  }
11604
11630
  const token = Token_1.Token.from(tokenDoc);
@@ -11621,7 +11647,7 @@ class TokenController extends TransportController_1.TransportController {
11621
11647
  const plaintextTokenBuffer = await core_1.CoreCrypto.decrypt(cipher, secretKey);
11622
11648
  const plaintextTokenContent = core_1.CoreSerializable.deserializeUnknown(plaintextTokenBuffer.toUtf8());
11623
11649
  if (!(plaintextTokenContent instanceof ts_serval_1.Serializable)) {
11624
- throw core_1.TransportErrors.tokens.invalidTokenContent(response.id);
11650
+ throw core_1.CoreErrors.tokens.invalidTokenContent(response.id);
11625
11651
  }
11626
11652
  const cachedToken = CachedToken_1.CachedToken.from({
11627
11653
  createdAt: core_1.CoreDate.from(response.createdAt),
@@ -11649,7 +11675,7 @@ class TokenController extends TransportController_1.TransportController {
11649
11675
  token = await this.updateCacheOfExistingTokenInDb(id.toString());
11650
11676
  if (!token) {
11651
11677
  // This should not happen, we only update the cache if we found the tokenDoc
11652
- throw new Error(`Tried to update a token (with ID: '${id.toString()}') that doesn't exist in the local database.`);
11678
+ throw new core_1.TransportError(`Tried to update a token (with ID: '${id.toString()}') that doesn't exist in the local database.`);
11653
11679
  }
11654
11680
  return token;
11655
11681
  }
@@ -12145,6 +12171,7 @@ exports.TokenReference = TokenReference;
12145
12171
 
12146
12172
  Object.defineProperty(exports, "__esModule", ({ value: true }));
12147
12173
  exports.PasswordGenerator = void 0;
12174
+ const TransportError_1 = __webpack_require__(/*! ../core/TransportError */ "./dist/core/TransportError.js");
12148
12175
  const Random_1 = __webpack_require__(/*! ./Random */ "./dist/util/Random.js");
12149
12176
  const defaultPasswordRange = Random_1.RandomCharacterRange.AlphanumericEase + Random_1.RandomCharacterRange.SpecialCharacters;
12150
12177
  class PasswordGenerator {
@@ -12168,7 +12195,7 @@ class PasswordGenerator {
12168
12195
  if (minLength > maxLength)
12169
12196
  maxLength = minLength;
12170
12197
  if (minLength < 8) {
12171
- throw new Error("Minimum password length for a strong password should be 8 characters.");
12198
+ throw new TransportError_1.TransportError("Minimum password length for a strong password should be 8 characters.");
12172
12199
  }
12173
12200
  const specialCharacterBucket = {
12174
12201
  minLength: 1,
@@ -12335,6 +12362,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
12335
12362
  exports.Random = exports.RandomCharacterRange = void 0;
12336
12363
  const crypto_1 = __webpack_require__(/*! @nmshd/crypto */ "@nmshd/crypto");
12337
12364
  const uuid_1 = __webpack_require__(/*! uuid */ "./node_modules/uuid/dist/commonjs-browser/index.js");
12365
+ const TransportError_1 = __webpack_require__(/*! ../core/TransportError */ "./dist/core/TransportError.js");
12338
12366
  var RandomCharacterRange;
12339
12367
  (function (RandomCharacterRange) {
12340
12368
  RandomCharacterRange["Digit"] = "0123456789";
@@ -12358,7 +12386,7 @@ class Random {
12358
12386
  }
12359
12387
  static async int(length) {
12360
12388
  if (length > 21 || length <= 0) {
12361
- throw new Error("Length must be between 1 and 21.");
12389
+ throw new TransportError_1.TransportError("Length must be between 1 and 21.");
12362
12390
  }
12363
12391
  return parseInt(await this.string(length, RandomCharacterRange.Digit));
12364
12392
  }
@@ -12381,12 +12409,12 @@ class Random {
12381
12409
  }
12382
12410
  static async intBetween(min, max) {
12383
12411
  if (max <= min) {
12384
- throw new Error("Max must be larger than min.");
12412
+ throw new TransportError_1.TransportError("Max must be larger than min.");
12385
12413
  }
12386
12414
  const diff = max - min + 1;
12387
12415
  const bitLength = Math.abs(Math.ceil(Math.log2(diff)));
12388
12416
  if (bitLength > 32) {
12389
- throw new Error("The range between the numbers is too big, 32 bit is the maximum -> 4294967296");
12417
+ throw new TransportError_1.TransportError("The range between the numbers is too big, 32 bit is the maximum -> 4294967296");
12390
12418
  }
12391
12419
  const byteLength = Math.ceil(bitLength / 8);
12392
12420
  const bitMask = Math.pow(2, bitLength) - 1;
@@ -12405,7 +12433,7 @@ class Random {
12405
12433
  }
12406
12434
  static async intRandomLength(minLength, maxLength) {
12407
12435
  if (maxLength > 21) {
12408
- throw new Error("Max must be below 22.");
12436
+ throw new TransportError_1.TransportError("Max must be below 22.");
12409
12437
  }
12410
12438
  return parseInt(await this.stringRandomLength(minLength, maxLength, RandomCharacterRange.Digit));
12411
12439
  }
@@ -12424,7 +12452,7 @@ class Random {
12424
12452
  if (length <= 0)
12425
12453
  return "";
12426
12454
  if (allowedChars.length > 256) {
12427
- throw new Error("Input exceeds maximum length of 256.");
12455
+ throw new TransportError_1.TransportError("Input exceeds maximum length of 256.");
12428
12456
  }
12429
12457
  const ar = [];
12430
12458
  const inputLength = allowedChars.length;
@@ -12447,10 +12475,10 @@ class Random {
12447
12475
  }
12448
12476
  static async stringRandomLength(minLength, maxLength, allowedChars) {
12449
12477
  if (minLength > maxLength) {
12450
- throw new Error("maxLength must be larger than minLength.");
12478
+ throw new TransportError_1.TransportError("maxLength must be larger than minLength.");
12451
12479
  }
12452
12480
  if (minLength < 0) {
12453
- throw new Error("minlength must not be less than zero.");
12481
+ throw new TransportError_1.TransportError("minlength must not be less than zero.");
12454
12482
  }
12455
12483
  const length = maxLength > minLength ? await this.intBetween(minLength, maxLength) : maxLength;
12456
12484
  return await this.string(length, allowedChars);