@twin.org/synchronised-storage-service 0.0.1-next.6 → 0.0.1-next.8

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.
@@ -6,7 +6,6 @@ var web = require('@twin.org/web');
6
6
  var blobStorageModels = require('@twin.org/blob-storage-models');
7
7
  var entityStorageModels = require('@twin.org/entity-storage-models');
8
8
  var identityModels = require('@twin.org/identity-models');
9
- var loggingModels = require('@twin.org/logging-models');
10
9
  var standardsW3cDid = require('@twin.org/standards-w3c-did');
11
10
  var synchronisedStorageModels = require('@twin.org/synchronised-storage-models');
12
11
  var vaultModels = require('@twin.org/vault-models');
@@ -297,10 +296,10 @@ class BlobStorageHelper {
297
296
  */
298
297
  CLASS_NAME = "BlobStorageHelper";
299
298
  /**
300
- * The logging connector to use for logging.
299
+ * The logging component to use for logging.
301
300
  * @internal
302
301
  */
303
- _logging;
302
+ _loggingComponent;
304
303
  /**
305
304
  * The vault connector.
306
305
  * @internal
@@ -323,14 +322,14 @@ class BlobStorageHelper {
323
322
  _isTrustedNode;
324
323
  /**
325
324
  * Create a new instance of BlobStorageHelper.
326
- * @param logging The logging connector to use for logging.
325
+ * @param loggingComponent The logging connector to use for logging.
327
326
  * @param vaultConnector The vault connector to use for for the encryption key.
328
327
  * @param blobStorageConnector The blob storage component to use.
329
328
  * @param blobStorageEncryptionKeyId The id of the vault key to use for encrypting/decrypting blobs.
330
329
  * @param isTrustedNode Is this a trusted node.
331
330
  */
332
- constructor(logging, vaultConnector, blobStorageConnector, blobStorageEncryptionKeyId, isTrustedNode) {
333
- this._logging = logging;
331
+ constructor(loggingComponent, vaultConnector, blobStorageConnector, blobStorageEncryptionKeyId, isTrustedNode) {
332
+ this._loggingComponent = loggingComponent;
334
333
  this._vaultConnector = vaultConnector;
335
334
  this._blobStorageConnector = blobStorageConnector;
336
335
  this._blobStorageEncryptionKeyId = blobStorageEncryptionKeyId;
@@ -342,7 +341,7 @@ class BlobStorageHelper {
342
341
  * @returns The blob.
343
342
  */
344
343
  async loadBlob(blobId) {
345
- await this._logging?.log({
344
+ await this._loggingComponent?.log({
346
345
  level: "info",
347
346
  source: this.CLASS_NAME,
348
347
  message: "loadBlob",
@@ -365,7 +364,7 @@ class BlobStorageHelper {
365
364
  compressedBlob = rsa.decrypt(encryptedBlob);
366
365
  }
367
366
  const decompressedBlob = await core.Compression.decompress(compressedBlob, core.CompressionType.Gzip);
368
- await this._logging?.log({
367
+ await this._loggingComponent?.log({
369
368
  level: "info",
370
369
  source: this.CLASS_NAME,
371
370
  message: "loadedBlob",
@@ -377,7 +376,7 @@ class BlobStorageHelper {
377
376
  }
378
377
  }
379
378
  catch (error) {
380
- await this._logging?.log({
379
+ await this._loggingComponent?.log({
381
380
  level: "error",
382
381
  source: this.CLASS_NAME,
383
382
  message: "loadBlobFailed",
@@ -387,7 +386,7 @@ class BlobStorageHelper {
387
386
  error: core.BaseError.fromError(error)
388
387
  });
389
388
  }
390
- await this._logging?.log({
389
+ await this._loggingComponent?.log({
391
390
  level: "info",
392
391
  source: this.CLASS_NAME,
393
392
  message: "loadBlobEmpty",
@@ -402,7 +401,7 @@ class BlobStorageHelper {
402
401
  * @returns The id of the blob.
403
402
  */
404
403
  async saveBlob(blob) {
405
- await this._logging?.log({
404
+ await this._loggingComponent?.log({
406
405
  level: "info",
407
406
  source: this.CLASS_NAME,
408
407
  message: "saveBlob"
@@ -414,7 +413,7 @@ class BlobStorageHelper {
414
413
  const encryptedBlob = await this._vaultConnector.encrypt(this._blobStorageEncryptionKeyId, vaultModels.VaultEncryptionType.Rsa2048, compressedBlob);
415
414
  try {
416
415
  const blobId = await this._blobStorageConnector.set(encryptedBlob);
417
- await this._logging?.log({
416
+ await this._loggingComponent?.log({
418
417
  level: "info",
419
418
  source: this.CLASS_NAME,
420
419
  message: "savedBlob",
@@ -425,7 +424,7 @@ class BlobStorageHelper {
425
424
  return blobId;
426
425
  }
427
426
  catch (error) {
428
- await this._logging?.log({
427
+ await this._loggingComponent?.log({
429
428
  level: "error",
430
429
  source: this.CLASS_NAME,
431
430
  message: "saveBlobFailed",
@@ -440,7 +439,7 @@ class BlobStorageHelper {
440
439
  * @returns Nothing.
441
440
  */
442
441
  async removeBlob(blobId) {
443
- await this._logging?.log({
442
+ await this._loggingComponent?.log({
444
443
  level: "info",
445
444
  source: this.CLASS_NAME,
446
445
  message: "removeBlob",
@@ -450,7 +449,7 @@ class BlobStorageHelper {
450
449
  });
451
450
  try {
452
451
  await this._blobStorageConnector.remove(blobId);
453
- await this._logging?.log({
452
+ await this._loggingComponent?.log({
454
453
  level: "info",
455
454
  source: this.CLASS_NAME,
456
455
  message: "removedBlob",
@@ -460,7 +459,7 @@ class BlobStorageHelper {
460
459
  });
461
460
  }
462
461
  catch (error) {
463
- await this._logging?.log({
462
+ await this._loggingComponent?.log({
464
463
  level: "error",
465
464
  source: this.CLASS_NAME,
466
465
  message: "removeBlobFailed",
@@ -470,7 +469,7 @@ class BlobStorageHelper {
470
469
  error: core.BaseError.fromError(error)
471
470
  });
472
471
  }
473
- await this._logging?.log({
472
+ await this._loggingComponent?.log({
474
473
  level: "info",
475
474
  source: this.CLASS_NAME,
476
475
  message: "removeBlobEmpty",
@@ -492,10 +491,10 @@ class ChangeSetHelper {
492
491
  */
493
492
  CLASS_NAME = "ChangeSetHelper";
494
493
  /**
495
- * The logging connector to use for logging.
494
+ * The logging component to use for logging.
496
495
  * @internal
497
496
  */
498
- _logging;
497
+ _loggingComponent;
499
498
  /**
500
499
  * The event bus component.
501
500
  * @internal
@@ -523,14 +522,14 @@ class ChangeSetHelper {
523
522
  _nodeIdentity;
524
523
  /**
525
524
  * Create a new instance of ChangeSetHelper.
526
- * @param logging The logging connector to use for logging.
525
+ * @param loggingComponent The logging connector to use for logging.
527
526
  * @param eventBusComponent The event bus component to use for events.
528
527
  * @param identityConnector The identity connector to use for signing/verifying changesets.
529
528
  * @param blobStorageHelper The blob storage component to use for remote sync states.
530
529
  * @param decentralisedStorageMethodId The id of the identity method to use when signing/verifying changesets.
531
530
  */
532
- constructor(logging, eventBusComponent, identityConnector, blobStorageHelper, decentralisedStorageMethodId) {
533
- this._logging = logging;
531
+ constructor(loggingComponent, eventBusComponent, identityConnector, blobStorageHelper, decentralisedStorageMethodId) {
532
+ this._loggingComponent = loggingComponent;
534
533
  this._eventBusComponent = eventBusComponent;
535
534
  this._decentralisedStorageMethodId = decentralisedStorageMethodId;
536
535
  this._blobStorageHelper = blobStorageHelper;
@@ -549,7 +548,7 @@ class ChangeSetHelper {
549
548
  * @returns The changeset if it was verified.
550
549
  */
551
550
  async getAndVerifyChangeset(changeSetStorageId) {
552
- await this._logging?.log({
551
+ await this._loggingComponent?.log({
553
552
  level: "info",
554
553
  source: this.CLASS_NAME,
555
554
  message: "getChangeSet",
@@ -565,7 +564,7 @@ class ChangeSetHelper {
565
564
  }
566
565
  }
567
566
  catch (error) {
568
- await this._logging?.log({
567
+ await this._loggingComponent?.log({
569
568
  level: "warn",
570
569
  source: this.CLASS_NAME,
571
570
  message: "getChangeSetError",
@@ -575,7 +574,7 @@ class ChangeSetHelper {
575
574
  error: core.BaseError.fromError(error)
576
575
  });
577
576
  }
578
- await this._logging?.log({
577
+ await this._loggingComponent?.log({
579
578
  level: "info",
580
579
  source: this.CLASS_NAME,
581
580
  message: "getChangeSetEmpty",
@@ -606,7 +605,7 @@ class ChangeSetHelper {
606
605
  async applyChangeset(syncChangeset) {
607
606
  if (core.Is.arrayValue(syncChangeset.changes)) {
608
607
  for (const change of syncChangeset.changes) {
609
- await this._logging?.log({
608
+ await this._loggingComponent?.log({
610
609
  level: "info",
611
610
  source: this.CLASS_NAME,
612
611
  message: "changeSetApplyingChange",
@@ -652,7 +651,7 @@ class ChangeSetHelper {
652
651
  * @returns The id of the change set.
653
652
  */
654
653
  async storeChangeSet(syncChangeSet) {
655
- await this._logging?.log({
654
+ await this._loggingComponent?.log({
656
655
  level: "info",
657
656
  source: this.CLASS_NAME,
658
657
  message: "changeSetStoring",
@@ -669,7 +668,7 @@ class ChangeSetHelper {
669
668
  */
670
669
  async verifyChangesetProof(syncChangeset) {
671
670
  if (core.Is.empty(syncChangeset.proof)) {
672
- await this._logging?.log({
671
+ await this._loggingComponent?.log({
673
672
  level: "info",
674
673
  source: this.CLASS_NAME,
675
674
  message: "verifyChangeSetProofMissing",
@@ -682,7 +681,7 @@ class ChangeSetHelper {
682
681
  // If the proof or verification method is missing, the proof is invalid
683
682
  const verificationMethod = syncChangeset.proof?.verificationMethod;
684
683
  if (!core.Is.stringValue(verificationMethod)) {
685
- await this._logging?.log({
684
+ await this._loggingComponent?.log({
686
685
  level: "error",
687
686
  source: this.CLASS_NAME,
688
687
  message: "verifyChangeSetProofMissing",
@@ -696,7 +695,7 @@ class ChangeSetHelper {
696
695
  // otherwise you could sign a changeset for another node
697
696
  const changeSetNodeIdentity = identityModels.DocumentHelper.parseId(verificationMethod ?? "");
698
697
  if (changeSetNodeIdentity.id !== syncChangeset.nodeIdentity) {
699
- await this._logging?.log({
698
+ await this._loggingComponent?.log({
700
699
  level: "error",
701
700
  source: this.CLASS_NAME,
702
701
  message: "verifyChangeSetProofNodeIdentityMismatch",
@@ -709,7 +708,7 @@ class ChangeSetHelper {
709
708
  delete changeSetWithoutProof.proof;
710
709
  const isValid = await this._identityConnector.verifyProof(changeSetWithoutProof, syncChangeset.proof);
711
710
  if (!isValid) {
712
- await this._logging?.log({
711
+ await this._loggingComponent?.log({
713
712
  level: "error",
714
713
  source: this.CLASS_NAME,
715
714
  message: "verifyChangeSetProofInvalid",
@@ -719,7 +718,7 @@ class ChangeSetHelper {
719
718
  });
720
719
  }
721
720
  else {
722
- await this._logging?.log({
721
+ await this._loggingComponent?.log({
723
722
  level: "error",
724
723
  source: this.CLASS_NAME,
725
724
  message: "verifyChangeSetProofValid",
@@ -740,7 +739,7 @@ class ChangeSetHelper {
740
739
  const changeSetWithoutProof = core.ObjectHelper.clone(syncChangeset);
741
740
  delete changeSetWithoutProof.proof;
742
741
  const proof = await this._identityConnector.createProof(this._nodeIdentity, identityModels.DocumentHelper.joinId(this._nodeIdentity, this._decentralisedStorageMethodId), standardsW3cDid.ProofTypes.DataIntegrityProof, changeSetWithoutProof);
743
- await this._logging?.log({
742
+ await this._loggingComponent?.log({
744
743
  level: "info",
745
744
  source: this.CLASS_NAME,
746
745
  message: "createdChangeSetProof",
@@ -760,7 +759,7 @@ class ChangeSetHelper {
760
759
  if (core.Is.stringValue(this._nodeIdentity)) {
761
760
  const verified = await this.verifyChangesetProof(syncChangeSet);
762
761
  if (verified) {
763
- await this._logging?.log({
762
+ await this._loggingComponent?.log({
764
763
  level: "info",
765
764
  source: this.CLASS_NAME,
766
765
  message: "copyChangeSet",
@@ -789,7 +788,7 @@ class ChangeSetHelper {
789
788
  async reset(storageKey, resetMode) {
790
789
  // If we are applying a consolidation we need to reset the local db
791
790
  // but keep any entries from the local node, as they might have been updated
792
- await this._logging?.log({
791
+ await this._loggingComponent?.log({
793
792
  level: "info",
794
793
  source: this.CLASS_NAME,
795
794
  message: "storageReset",
@@ -821,10 +820,10 @@ class LocalSyncStateHelper {
821
820
  */
822
821
  CLASS_NAME = "LocalSyncStateHelper";
823
822
  /**
824
- * The logging connector to use for logging.
823
+ * The logging component to use for logging.
825
824
  * @internal
826
825
  */
827
- _logging;
826
+ _loggingComponent;
828
827
  /**
829
828
  * The storage connector for the sync snapshot entries.
830
829
  * @internal
@@ -837,12 +836,12 @@ class LocalSyncStateHelper {
837
836
  _changeSetHelper;
838
837
  /**
839
838
  * Create a new instance of LocalSyncStateHelper.
840
- * @param logging The logging connector to use for logging.
839
+ * @param loggingComponent The logging connector to use for logging.
841
840
  * @param snapshotEntryEntityStorage The storage connector for the sync snapshot entries.
842
841
  * @param changeSetHelper The change set helper to use for applying changesets.
843
842
  */
844
- constructor(logging, snapshotEntryEntityStorage, changeSetHelper) {
845
- this._logging = logging;
843
+ constructor(loggingComponent, snapshotEntryEntityStorage, changeSetHelper) {
844
+ this._loggingComponent = loggingComponent;
846
845
  this._snapshotEntryEntityStorage = snapshotEntryEntityStorage;
847
846
  this._changeSetHelper = changeSetHelper;
848
847
  }
@@ -854,7 +853,7 @@ class LocalSyncStateHelper {
854
853
  * @returns Nothing.
855
854
  */
856
855
  async addLocalChange(storageKey, operation, id) {
857
- await this._logging?.log({
856
+ await this._loggingComponent?.log({
858
857
  level: "info",
859
858
  source: this.CLASS_NAME,
860
859
  message: "addLocalChange",
@@ -892,7 +891,7 @@ class LocalSyncStateHelper {
892
891
  * @returns The local snapshot entry.
893
892
  */
894
893
  async getSnapshots(storageKey, isLocal) {
895
- await this._logging?.log({
894
+ await this._loggingComponent?.log({
896
895
  level: "info",
897
896
  source: this.CLASS_NAME,
898
897
  message: "getSnapshots",
@@ -915,7 +914,7 @@ class LocalSyncStateHelper {
915
914
  ]
916
915
  });
917
916
  if (queryResult.entities.length > 0) {
918
- await this._logging?.log({
917
+ await this._loggingComponent?.log({
919
918
  level: "info",
920
919
  source: this.CLASS_NAME,
921
920
  message: "getSnapshotsExists",
@@ -925,7 +924,7 @@ class LocalSyncStateHelper {
925
924
  });
926
925
  return queryResult.entities;
927
926
  }
928
- await this._logging?.log({
927
+ await this._loggingComponent?.log({
929
928
  level: "info",
930
929
  source: this.CLASS_NAME,
931
930
  message: "getSnapshotsDoesNotExist",
@@ -954,7 +953,7 @@ class LocalSyncStateHelper {
954
953
  * @returns Nothing.
955
954
  */
956
955
  async setLocalChangeSnapshot(localChangeSnapshot) {
957
- await this._logging?.log({
956
+ await this._loggingComponent?.log({
958
957
  level: "info",
959
958
  source: this.CLASS_NAME,
960
959
  message: "setLocalChangeSnapshot",
@@ -970,7 +969,7 @@ class LocalSyncStateHelper {
970
969
  * @returns Nothing.
971
970
  */
972
971
  async removeLocalChangeSnapshot(localChangeSnapshot) {
973
- await this._logging?.log({
972
+ await this._loggingComponent?.log({
974
973
  level: "info",
975
974
  source: this.CLASS_NAME,
976
975
  message: "removeLocalChangeSnapshot",
@@ -987,7 +986,7 @@ class LocalSyncStateHelper {
987
986
  * @returns Nothing.
988
987
  */
989
988
  async applySyncState(storageKey, syncState) {
990
- await this._logging?.log({
989
+ await this._loggingComponent?.log({
991
990
  level: "info",
992
991
  source: this.CLASS_NAME,
993
992
  message: "applySyncState",
@@ -1012,7 +1011,7 @@ class LocalSyncStateHelper {
1012
1011
  // If we have an epoch gap or no existing snapshots then we need to apply
1013
1012
  // a full sync from a consolidation
1014
1013
  if (!existingSnapshots.some(s => s.isConsolidated) || hasEpochGap) {
1015
- await this._logging?.log({
1014
+ await this._loggingComponent?.log({
1016
1015
  level: "info",
1017
1016
  source: this.CLASS_NAME,
1018
1017
  message: "applySnapshotNoExisting",
@@ -1023,7 +1022,7 @@ class LocalSyncStateHelper {
1023
1022
  const mostRecentConsolidation = syncStateSnapshots.findIndex(snapshot => snapshot.isConsolidated);
1024
1023
  if (mostRecentConsolidation !== -1) {
1025
1024
  // We found the most recent consolidated snapshot, we can use it
1026
- await this._logging?.log({
1025
+ await this._loggingComponent?.log({
1027
1026
  level: "info",
1028
1027
  source: this.CLASS_NAME,
1029
1028
  message: "applySnapshotFoundConsolidated",
@@ -1051,7 +1050,7 @@ class LocalSyncStateHelper {
1051
1050
  }
1052
1051
  }
1053
1052
  else {
1054
- await this._logging?.log({
1053
+ await this._loggingComponent?.log({
1055
1054
  level: "info",
1056
1055
  source: this.CLASS_NAME,
1057
1056
  message: "applySnapshotNoConsolidated",
@@ -1076,7 +1075,7 @@ class LocalSyncStateHelper {
1076
1075
  const referencedExistingSnapshots = Object.keys(existingSnapshotsMap);
1077
1076
  let completedProcessing = false;
1078
1077
  for (const snapshot of syncStateSnapshots) {
1079
- await this._logging?.log({
1078
+ await this._loggingComponent?.log({
1080
1079
  level: "info",
1081
1080
  source: this.CLASS_NAME,
1082
1081
  message: "applySnapshot",
@@ -1137,7 +1136,7 @@ class LocalSyncStateHelper {
1137
1136
  */
1138
1137
  async processModifiedSnapshots(modifiedSnapshots) {
1139
1138
  for (const modifiedSnapshot of modifiedSnapshots) {
1140
- await this._logging?.log({
1139
+ await this._loggingComponent?.log({
1141
1140
  level: "info",
1142
1141
  source: this.CLASS_NAME,
1143
1142
  message: "processModifiedSnapshot",
@@ -1170,7 +1169,7 @@ class LocalSyncStateHelper {
1170
1169
  */
1171
1170
  async processNewSnapshots(newSnapshots) {
1172
1171
  for (const newSnapshot of newSnapshots) {
1173
- await this._logging?.log({
1172
+ await this._loggingComponent?.log({
1174
1173
  level: "info",
1175
1174
  source: this.CLASS_NAME,
1176
1175
  message: "processNewSnapshot",
@@ -1201,10 +1200,10 @@ class RemoteSyncStateHelper {
1201
1200
  */
1202
1201
  CLASS_NAME = "RemoteSyncStateHelper";
1203
1202
  /**
1204
- * The logging connector to use for logging.
1203
+ * The logging component to use for logging.
1205
1204
  * @internal
1206
1205
  */
1207
- _logging;
1206
+ _loggingComponent;
1208
1207
  /**
1209
1208
  * The event bus component.
1210
1209
  * @internal
@@ -1257,7 +1256,7 @@ class RemoteSyncStateHelper {
1257
1256
  _maxConsolidations;
1258
1257
  /**
1259
1258
  * Create a new instance of DecentralisedEntityStorageConnector.
1260
- * @param logging The logging connector to use for logging.
1259
+ * @param loggingComponent The logging component to use for logging.
1261
1260
  * @param eventBusComponent The event bus component to use for events.
1262
1261
  * @param verifiableSyncPointerStorageConnector The verifiable storage connector to use for storing sync pointers.
1263
1262
  * @param blobStorageHelper The blob storage helper to use for remote sync states.
@@ -1265,8 +1264,8 @@ class RemoteSyncStateHelper {
1265
1264
  * @param isTrustedNode Whether the node is trusted or not.
1266
1265
  * @param maxConsolidations The maximum number of consolidations to keep in storage.
1267
1266
  */
1268
- constructor(logging, eventBusComponent, verifiableSyncPointerStorageConnector, blobStorageHelper, changeSetHelper, isTrustedNode, maxConsolidations) {
1269
- this._logging = logging;
1267
+ constructor(loggingComponent, eventBusComponent, verifiableSyncPointerStorageConnector, blobStorageHelper, changeSetHelper, isTrustedNode, maxConsolidations) {
1268
+ this._loggingComponent = loggingComponent;
1270
1269
  this._eventBusComponent = eventBusComponent;
1271
1270
  this._verifiableSyncPointerStorageConnector = verifiableSyncPointerStorageConnector;
1272
1271
  this._changeSetHelper = changeSetHelper;
@@ -1304,7 +1303,7 @@ class RemoteSyncStateHelper {
1304
1303
  * @returns The storage id of the change set if created.
1305
1304
  */
1306
1305
  async buildChangeSet(storageKey, changes, completeCallback) {
1307
- await this._logging?.log({
1306
+ await this._loggingComponent?.log({
1308
1307
  level: "info",
1309
1308
  source: this.CLASS_NAME,
1310
1309
  message: "buildingChangeSet",
@@ -1330,7 +1329,7 @@ class RemoteSyncStateHelper {
1330
1329
  // Once all the requests are handled the callback will be called
1331
1330
  for (const change of setChanges) {
1332
1331
  // Create a request for each change to populate the full details
1333
- await this._logging?.log({
1332
+ await this._loggingComponent?.log({
1334
1333
  level: "info",
1335
1334
  source: this.CLASS_NAME,
1336
1335
  message: "createChangeSetRequestingItem",
@@ -1353,7 +1352,7 @@ class RemoteSyncStateHelper {
1353
1352
  * @returns Nothing.
1354
1353
  */
1355
1354
  async finaliseFullChanges(storageKey, completeCallback) {
1356
- await this._logging?.log({
1355
+ await this._loggingComponent?.log({
1357
1356
  level: "info",
1358
1357
  source: this.CLASS_NAME,
1359
1358
  message: "finalisingSyncChanges",
@@ -1394,7 +1393,7 @@ class RemoteSyncStateHelper {
1394
1393
  await completeCallback(syncChangeSet, changeSetStorageId);
1395
1394
  }
1396
1395
  catch (err) {
1397
- await this._logging?.log({
1396
+ await this._loggingComponent?.log({
1398
1397
  level: "error",
1399
1398
  source: this.CLASS_NAME,
1400
1399
  message: "finalisingSyncChangesFailed",
@@ -1417,7 +1416,7 @@ class RemoteSyncStateHelper {
1417
1416
  * @returns Nothing.
1418
1417
  */
1419
1418
  async addChangeSetToSyncState(storageKey, changeSetStorageId) {
1420
- await this._logging?.log({
1419
+ await this._loggingComponent?.log({
1421
1420
  level: "info",
1422
1421
  source: this.CLASS_NAME,
1423
1422
  message: "addChangeSetToSyncState",
@@ -1474,7 +1473,7 @@ class RemoteSyncStateHelper {
1474
1473
  * @returns Nothing.
1475
1474
  */
1476
1475
  async consolidationStart(storageKey, batchSize) {
1477
- await this._logging?.log({
1476
+ await this._loggingComponent?.log({
1478
1477
  level: "info",
1479
1478
  source: this.CLASS_NAME,
1480
1479
  message: "consolidationStarting"
@@ -1489,7 +1488,7 @@ class RemoteSyncStateHelper {
1489
1488
  async getVerifiableSyncPointerStore() {
1490
1489
  if (core.Is.stringValue(this._synchronisedStorageKey)) {
1491
1490
  try {
1492
- await this._logging?.log({
1491
+ await this._loggingComponent?.log({
1493
1492
  level: "info",
1494
1493
  source: this.CLASS_NAME,
1495
1494
  message: "verifiableSyncPointerStoreRetrieving",
@@ -1500,7 +1499,7 @@ class RemoteSyncStateHelper {
1500
1499
  const syncPointerStore = await this._verifiableSyncPointerStorageConnector.get(this._synchronisedStorageKey, { includeData: true });
1501
1500
  if (core.Is.uint8Array(syncPointerStore.data)) {
1502
1501
  const syncPointer = core.ObjectHelper.fromBytes(syncPointerStore.data);
1503
- await this._logging?.log({
1502
+ await this._loggingComponent?.log({
1504
1503
  level: "info",
1505
1504
  source: this.CLASS_NAME,
1506
1505
  message: "verifiableSyncPointerStoreRetrieved",
@@ -1516,7 +1515,7 @@ class RemoteSyncStateHelper {
1516
1515
  throw err;
1517
1516
  }
1518
1517
  }
1519
- await this._logging?.log({
1518
+ await this._loggingComponent?.log({
1520
1519
  level: "info",
1521
1520
  source: this.CLASS_NAME,
1522
1521
  message: "verifiableSyncPointerStoreNotFound",
@@ -1538,7 +1537,7 @@ class RemoteSyncStateHelper {
1538
1537
  */
1539
1538
  async storeVerifiableSyncPointerStore(syncPointerStore) {
1540
1539
  if (core.Is.stringValue(this._nodeIdentity) && core.Is.stringValue(this._synchronisedStorageKey)) {
1541
- await this._logging?.log({
1540
+ await this._loggingComponent?.log({
1542
1541
  level: "info",
1543
1542
  source: this.CLASS_NAME,
1544
1543
  message: "verifiableSyncPointerStoreStoring",
@@ -1556,7 +1555,7 @@ class RemoteSyncStateHelper {
1556
1555
  * @returns The id of the sync state.
1557
1556
  */
1558
1557
  async storeRemoteSyncState(syncState) {
1559
- await this._logging?.log({
1558
+ await this._loggingComponent?.log({
1560
1559
  level: "info",
1561
1560
  source: this.CLASS_NAME,
1562
1561
  message: "syncStateStoring",
@@ -1599,7 +1598,7 @@ class RemoteSyncStateHelper {
1599
1598
  */
1600
1599
  async getSyncState(syncPointerId) {
1601
1600
  try {
1602
- await this._logging?.log({
1601
+ await this._loggingComponent?.log({
1603
1602
  level: "info",
1604
1603
  source: this.CLASS_NAME,
1605
1604
  message: "syncStateRetrieving",
@@ -1609,7 +1608,7 @@ class RemoteSyncStateHelper {
1609
1608
  });
1610
1609
  const syncState = await this._blobStorageHelper.loadBlob(syncPointerId);
1611
1610
  if (core.Is.object(syncState)) {
1612
- await this._logging?.log({
1611
+ await this._loggingComponent?.log({
1613
1612
  level: "info",
1614
1613
  source: this.CLASS_NAME,
1615
1614
  message: "syncStateRetrieved",
@@ -1622,7 +1621,7 @@ class RemoteSyncStateHelper {
1622
1621
  }
1623
1622
  }
1624
1623
  catch (error) {
1625
- await this._logging?.log({
1624
+ await this._loggingComponent?.log({
1626
1625
  level: "warn",
1627
1626
  source: this.CLASS_NAME,
1628
1627
  message: "getSyncStateError",
@@ -1632,7 +1631,7 @@ class RemoteSyncStateHelper {
1632
1631
  error: core.BaseError.fromError(error)
1633
1632
  });
1634
1633
  }
1635
- await this._logging?.log({
1634
+ await this._loggingComponent?.log({
1636
1635
  level: "info",
1637
1636
  source: this.CLASS_NAME,
1638
1637
  message: "syncStateNotFound",
@@ -1704,7 +1703,7 @@ class RemoteSyncStateHelper {
1704
1703
  // Remove the batch response storage ids for the storage key
1705
1704
  // as we have consolidated the changes
1706
1705
  delete this._batchResponseStorageIds[response.storageKey];
1707
- await this._logging?.log({
1706
+ await this._loggingComponent?.log({
1708
1707
  level: "info",
1709
1708
  source: this.CLASS_NAME,
1710
1709
  message: "consolidationCompleted"
@@ -1717,7 +1716,7 @@ class RemoteSyncStateHelper {
1717
1716
  * @param response The item response to handle.
1718
1717
  */
1719
1718
  async handleLocalItemResponse(response) {
1720
- await this._logging?.log({
1719
+ await this._loggingComponent?.log({
1721
1720
  level: "info",
1722
1721
  source: this.CLASS_NAME,
1723
1722
  message: "createChangeSetRespondingItem",
@@ -1771,10 +1770,10 @@ class SynchronisedStorageService {
1771
1770
  */
1772
1771
  CLASS_NAME = "SynchronisedStorageService";
1773
1772
  /**
1774
- * The logging connector to use for logging.
1773
+ * The logging component to use for logging.
1775
1774
  * @internal
1776
1775
  */
1777
- _logging;
1776
+ _loggingComponent;
1778
1777
  /**
1779
1778
  * The event bus component.
1780
1779
  * @internal
@@ -1868,18 +1867,25 @@ class SynchronisedStorageService {
1868
1867
  core.Guards.object(this.CLASS_NAME, "options", options);
1869
1868
  core.Guards.object(this.CLASS_NAME, "options.config", options.config);
1870
1869
  this._eventBusComponent = core.ComponentFactory.get(options.eventBusComponentType ?? "event-bus");
1871
- this._logging = loggingModels.LoggingConnectorFactory.getIfExists(options.loggingConnectorType ?? "logging");
1870
+ this._loggingComponent = core.ComponentFactory.getIfExists(options.loggingComponentType ?? "logging");
1872
1871
  this._vaultConnector = vaultModels.VaultConnectorFactory.get(options.vaultConnectorType ?? "vault");
1873
1872
  this._localSyncSnapshotEntryEntityStorage = entityStorageModels.EntityStorageConnectorFactory.get(options.syncSnapshotStorageConnectorType ?? "sync-snapshot-entry");
1874
1873
  this._verifiableSyncPointerStorageConnector = verifiableStorageModels.VerifiableStorageConnectorFactory.get(options.verifiableStorageConnectorType ?? "verifiable-storage");
1875
1874
  this._blobStorageConnector = blobStorageModels.BlobStorageConnectorFactory.get(options.blobStorageConnectorType ?? "blob-storage");
1876
1875
  this._identityConnector = identityModels.IdentityConnectorFactory.get(options.identityConnectorType ?? "identity");
1877
1876
  this._taskSchedulerComponent = core.ComponentFactory.get(options.taskSchedulerComponentType ?? "task-scheduler");
1877
+ // If this is empty we assume the local node has the rights to write to the verifiable storage.
1878
+ let isTrustedNode = true;
1879
+ if (!core.Is.empty(options.trustedSynchronisedStorageComponentType)) {
1880
+ isTrustedNode = false;
1881
+ // If it is set then we used the trusted component to send changesets to
1882
+ this._trustedSynchronisedStorageComponent =
1883
+ core.ComponentFactory.get(options.trustedSynchronisedStorageComponentType);
1884
+ }
1878
1885
  this._config = {
1879
1886
  synchronisedStorageMethodId: options.config.synchronisedStorageMethodId ?? "synchronised-storage-assertion",
1880
1887
  entityUpdateIntervalMinutes: options.config.entityUpdateIntervalMinutes ??
1881
1888
  SynchronisedStorageService._DEFAULT_ENTITY_UPDATE_INTERVAL_MINUTES,
1882
- isTrustedNode: options.config.isTrustedNode ?? false,
1883
1889
  consolidationIntervalMinutes: options.config.consolidationIntervalMinutes ??
1884
1890
  SynchronisedStorageService._DEFAULT_CONSOLIDATION_INTERVAL_MINUTES,
1885
1891
  consolidationBatchSize: options.config.consolidationBatchSize ??
@@ -1890,17 +1896,10 @@ class SynchronisedStorageService {
1890
1896
  };
1891
1897
  this._synchronisedStorageKey =
1892
1898
  verifiableStorageKeys[options.config.verifiableStorageKeyId] ?? options.config.verifiableStorageKeyId;
1893
- // If this is not a trusted node, we need to use a synchronised storage service
1894
- // to synchronise with a trusted node.
1895
- if (!this._config.isTrustedNode) {
1896
- core.Guards.stringValue(this.CLASS_NAME, "options.trustedSynchronisedStorageComponentType", options.trustedSynchronisedStorageComponentType);
1897
- this._trustedSynchronisedStorageComponent =
1898
- core.ComponentFactory.get(options.trustedSynchronisedStorageComponentType);
1899
- }
1900
- this._blobStorageHelper = new BlobStorageHelper(this._logging, this._vaultConnector, this._blobStorageConnector, this._config.blobStorageEncryptionKeyId, this._config.isTrustedNode);
1901
- this._changeSetHelper = new ChangeSetHelper(this._logging, this._eventBusComponent, this._identityConnector, this._blobStorageHelper, this._config.synchronisedStorageMethodId);
1902
- this._localSyncStateHelper = new LocalSyncStateHelper(this._logging, this._localSyncSnapshotEntryEntityStorage, this._changeSetHelper);
1903
- this._remoteSyncStateHelper = new RemoteSyncStateHelper(this._logging, this._eventBusComponent, this._verifiableSyncPointerStorageConnector, this._blobStorageHelper, this._changeSetHelper, this._config.isTrustedNode, this._config.maxConsolidations);
1899
+ this._blobStorageHelper = new BlobStorageHelper(this._loggingComponent, this._vaultConnector, this._blobStorageConnector, this._config.blobStorageEncryptionKeyId, isTrustedNode);
1900
+ this._changeSetHelper = new ChangeSetHelper(this._loggingComponent, this._eventBusComponent, this._identityConnector, this._blobStorageHelper, this._config.synchronisedStorageMethodId);
1901
+ this._localSyncStateHelper = new LocalSyncStateHelper(this._loggingComponent, this._localSyncSnapshotEntryEntityStorage, this._changeSetHelper);
1902
+ this._remoteSyncStateHelper = new RemoteSyncStateHelper(this._loggingComponent, this._eventBusComponent, this._verifiableSyncPointerStorageConnector, this._blobStorageHelper, this._changeSetHelper, isTrustedNode, this._config.maxConsolidations);
1904
1903
  this._serviceStarted = false;
1905
1904
  this._activeStorageKeys = {};
1906
1905
  this._eventBusComponent.subscribe(synchronisedStorageModels.SynchronisedStorageTopics.RegisterStorageKey, async (event) => this.registerStorageKey(event.data));
@@ -1925,7 +1924,7 @@ class SynchronisedStorageService {
1925
1924
  this._remoteSyncStateHelper.setSynchronisedStorageKey(this._synchronisedStorageKey);
1926
1925
  this._serviceStarted = true;
1927
1926
  // If this is not a trusted node we need to request the decryption key from a trusted node
1928
- if (!this._config.isTrustedNode && !core.Is.empty(this._trustedSynchronisedStorageComponent)) {
1927
+ if (!core.Is.empty(this._trustedSynchronisedStorageComponent)) {
1929
1928
  const proof = await this._identityConnector.createProof(this._nodeIdentity, identityModels.DocumentHelper.joinId(this._nodeIdentity, this._config.synchronisedStorageMethodId), standardsW3cDid.ProofTypes.DataIntegrityProof, { nodeIdentity });
1930
1929
  const decryptionKey = await this._trustedSynchronisedStorageComponent.getDecryptionKey(this._nodeIdentity, proof);
1931
1930
  // We don't have the private key so instead we store the key as a secret in the vault
@@ -1958,7 +1957,7 @@ class SynchronisedStorageService {
1958
1957
  * @returns The decryption key.
1959
1958
  */
1960
1959
  async getDecryptionKey(nodeIdentity, proof) {
1961
- if (!this._config.isTrustedNode) {
1960
+ if (!core.Is.empty(this._trustedSynchronisedStorageComponent)) {
1962
1961
  throw new core.GeneralError(this.CLASS_NAME, "notTrustedNode");
1963
1962
  }
1964
1963
  core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
@@ -1981,11 +1980,11 @@ class SynchronisedStorageService {
1981
1980
  * @returns Nothing.
1982
1981
  */
1983
1982
  async syncChangeSet(syncChangeSet) {
1984
- if (!this._config.isTrustedNode) {
1983
+ if (!core.Is.empty(this._trustedSynchronisedStorageComponent)) {
1985
1984
  throw new core.GeneralError(this.CLASS_NAME, "notTrustedNode");
1986
1985
  }
1987
1986
  core.Guards.object(this.CLASS_NAME, "syncChangeSet", syncChangeSet);
1988
- await this._logging?.log({
1987
+ await this._loggingComponent?.log({
1989
1988
  level: "info",
1990
1989
  source: this.CLASS_NAME,
1991
1990
  message: "syncChangeSetForRemoteNode",
@@ -2014,7 +2013,7 @@ class SynchronisedStorageService {
2014
2013
  */
2015
2014
  async startEntitySync(storageKey) {
2016
2015
  try {
2017
- await this._logging?.log({
2016
+ await this._loggingComponent?.log({
2018
2017
  level: "info",
2019
2018
  source: this.CLASS_NAME,
2020
2019
  message: "startEntitySync",
@@ -2028,7 +2027,7 @@ class SynchronisedStorageService {
2028
2027
  await this.updateFromLocalSyncState(storageKey);
2029
2028
  }
2030
2029
  catch (error) {
2031
- await this._logging?.log({
2030
+ await this._loggingComponent?.log({
2032
2031
  level: "error",
2033
2032
  source: this.CLASS_NAME,
2034
2033
  message: "entitySyncFailed",
@@ -2043,7 +2042,7 @@ class SynchronisedStorageService {
2043
2042
  * @internal
2044
2043
  */
2045
2044
  async updateFromRemoteSyncState(storageKey) {
2046
- await this._logging?.log({
2045
+ await this._loggingComponent?.log({
2047
2046
  level: "info",
2048
2047
  source: this.CLASS_NAME,
2049
2048
  message: "updateFromRemoteSyncState",
@@ -2069,7 +2068,7 @@ class SynchronisedStorageService {
2069
2068
  * @internal
2070
2069
  */
2071
2070
  async updateFromLocalSyncState(storageKey) {
2072
- await this._logging?.log({
2071
+ await this._loggingComponent?.log({
2073
2072
  level: "info",
2074
2073
  source: this.CLASS_NAME,
2075
2074
  message: "updateFromLocalSyncState",
@@ -2083,7 +2082,7 @@ class SynchronisedStorageService {
2083
2082
  if (core.Is.arrayValue(localChangeSnapshot.changes)) {
2084
2083
  await this._remoteSyncStateHelper.buildChangeSet(storageKey, localChangeSnapshot.changes, async (syncChangeSet, changeSetStorageId) => {
2085
2084
  if (core.Is.empty(syncChangeSet) && core.Is.empty(changeSetStorageId)) {
2086
- await this._logging?.log({
2085
+ await this._loggingComponent?.log({
2087
2086
  level: "info",
2088
2087
  source: this.CLASS_NAME,
2089
2088
  message: "builtStorageChangeSetNone",
@@ -2093,7 +2092,7 @@ class SynchronisedStorageService {
2093
2092
  });
2094
2093
  }
2095
2094
  else {
2096
- await this._logging?.log({
2095
+ await this._loggingComponent?.log({
2097
2096
  level: "info",
2098
2097
  source: this.CLASS_NAME,
2099
2098
  message: "builtStorageChangeSet",
@@ -2103,7 +2102,8 @@ class SynchronisedStorageService {
2103
2102
  }
2104
2103
  });
2105
2104
  // Send the local changes to the remote storage if we are a trusted node
2106
- if (this._config.isTrustedNode && core.Is.stringValue(changeSetStorageId)) {
2105
+ if (core.Is.empty(this._trustedSynchronisedStorageComponent) &&
2106
+ core.Is.stringValue(changeSetStorageId)) {
2107
2107
  // If we are a trusted node, we can add the change set to the sync state
2108
2108
  // and remove the local change snapshot
2109
2109
  await this._remoteSyncStateHelper.addChangeSetToSyncState(storageKey, changeSetStorageId);
@@ -2113,7 +2113,7 @@ class SynchronisedStorageService {
2113
2113
  core.Is.object(syncChangeSet)) {
2114
2114
  // If we are not a trusted node, we need to send the changes to the trusted node
2115
2115
  // and then remove the local change snapshot
2116
- await this._logging?.log({
2116
+ await this._loggingComponent?.log({
2117
2117
  level: "info",
2118
2118
  source: this.CLASS_NAME,
2119
2119
  message: "sendingChangeSetToTrustedNode",
@@ -2129,7 +2129,7 @@ class SynchronisedStorageService {
2129
2129
  });
2130
2130
  }
2131
2131
  else {
2132
- await this._logging?.log({
2132
+ await this._loggingComponent?.log({
2133
2133
  level: "info",
2134
2134
  source: this.CLASS_NAME,
2135
2135
  message: "updateFromLocalSyncStateNoChanges",
@@ -2158,7 +2158,7 @@ class SynchronisedStorageService {
2158
2158
  SynchronisedStorageService._DEFAULT_CONSOLIDATION_BATCH_SIZE);
2159
2159
  }
2160
2160
  catch (error) {
2161
- await this._logging?.log({
2161
+ await this._loggingComponent?.log({
2162
2162
  level: "error",
2163
2163
  source: this.CLASS_NAME,
2164
2164
  message: "consolidationSyncFailed",
@@ -2172,7 +2172,7 @@ class SynchronisedStorageService {
2172
2172
  * @internal
2173
2173
  */
2174
2174
  async registerStorageKey(syncRegisterStorageKey) {
2175
- await this._logging?.log({
2175
+ await this._loggingComponent?.log({
2176
2176
  level: "info",
2177
2177
  source: this.CLASS_NAME,
2178
2178
  message: "registerStorageKey",
@@ -2194,7 +2194,7 @@ class SynchronisedStorageService {
2194
2194
  */
2195
2195
  async activateStorageKey(storageKey) {
2196
2196
  if (!core.Is.empty(this._activeStorageKeys[storageKey]) && !this._activeStorageKeys[storageKey]) {
2197
- await this._logging?.log({
2197
+ await this._loggingComponent?.log({
2198
2198
  level: "info",
2199
2199
  source: this.CLASS_NAME,
2200
2200
  message: "activateStorageKey",
@@ -2211,7 +2211,8 @@ class SynchronisedStorageService {
2211
2211
  }
2212
2212
  ], async () => this.startEntitySync(storageKey));
2213
2213
  }
2214
- if (this._config.isTrustedNode && this._config.consolidationIntervalMinutes > 0) {
2214
+ if (!core.Is.empty(this._trustedSynchronisedStorageComponent) &&
2215
+ this._config.consolidationIntervalMinutes > 0) {
2215
2216
  await this._taskSchedulerComponent.addTask(`synchronised-storage-consolidation-${storageKey}`, [
2216
2217
  {
2217
2218
  nextTriggerTime: Date.now(),