@twin.org/synchronised-storage-service 0.0.1-next.7 → 0.0.1-next.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.
@@ -278,9 +278,9 @@ function initSchema() {
278
278
  entity.EntitySchemaFactory.register("SyncSnapshotEntry", () => entity.EntitySchemaHelper.getSchema(exports.SyncSnapshotEntry));
279
279
  }
280
280
 
281
- var mainnet = "";
282
- var testnet = "";
283
- var devnet = "";
281
+ var mainnet = "verifiable:iota:0x0000000000000000000000000000000000000000000000000000000000000000:0x0000000000000000000000000000000000000000000000000000000000000000";
282
+ var testnet = "verifiable:iota:0x0000000000000000000000000000000000000000000000000000000000000000:0x0000000000000000000000000000000000000000000000000000000000000000";
283
+ var devnet = "verifiable:iota:0x0000000000000000000000000000000000000000000000000000000000000000:0x0000000000000000000000000000000000000000000000000000000000000000";
284
284
  var verifiableStorageKeys = {
285
285
  mainnet: mainnet,
286
286
  testnet: testnet,
@@ -1866,6 +1866,7 @@ class SynchronisedStorageService {
1866
1866
  constructor(options) {
1867
1867
  core.Guards.object(this.CLASS_NAME, "options", options);
1868
1868
  core.Guards.object(this.CLASS_NAME, "options.config", options.config);
1869
+ core.Guards.stringValue(this.CLASS_NAME, "options.config.verifiableStorageKeyId", options.config.verifiableStorageKeyId);
1869
1870
  this._eventBusComponent = core.ComponentFactory.get(options.eventBusComponentType ?? "event-bus");
1870
1871
  this._loggingComponent = core.ComponentFactory.getIfExists(options.loggingComponentType ?? "logging");
1871
1872
  this._vaultConnector = vaultModels.VaultConnectorFactory.get(options.vaultConnectorType ?? "vault");
@@ -1874,11 +1875,18 @@ class SynchronisedStorageService {
1874
1875
  this._blobStorageConnector = blobStorageModels.BlobStorageConnectorFactory.get(options.blobStorageConnectorType ?? "blob-storage");
1875
1876
  this._identityConnector = identityModels.IdentityConnectorFactory.get(options.identityConnectorType ?? "identity");
1876
1877
  this._taskSchedulerComponent = core.ComponentFactory.get(options.taskSchedulerComponentType ?? "task-scheduler");
1878
+ // If this is empty we assume the local node has the rights to write to the verifiable storage.
1879
+ let isTrustedNode = true;
1880
+ if (!core.Is.empty(options.trustedSynchronisedStorageComponentType)) {
1881
+ isTrustedNode = false;
1882
+ // If it is set then we used the trusted component to send changesets to
1883
+ this._trustedSynchronisedStorageComponent =
1884
+ core.ComponentFactory.get(options.trustedSynchronisedStorageComponentType);
1885
+ }
1877
1886
  this._config = {
1878
1887
  synchronisedStorageMethodId: options.config.synchronisedStorageMethodId ?? "synchronised-storage-assertion",
1879
1888
  entityUpdateIntervalMinutes: options.config.entityUpdateIntervalMinutes ??
1880
1889
  SynchronisedStorageService._DEFAULT_ENTITY_UPDATE_INTERVAL_MINUTES,
1881
- isTrustedNode: options.config.isTrustedNode ?? false,
1882
1890
  consolidationIntervalMinutes: options.config.consolidationIntervalMinutes ??
1883
1891
  SynchronisedStorageService._DEFAULT_CONSOLIDATION_INTERVAL_MINUTES,
1884
1892
  consolidationBatchSize: options.config.consolidationBatchSize ??
@@ -1889,17 +1897,11 @@ class SynchronisedStorageService {
1889
1897
  };
1890
1898
  this._synchronisedStorageKey =
1891
1899
  verifiableStorageKeys[options.config.verifiableStorageKeyId] ?? options.config.verifiableStorageKeyId;
1892
- // If this is not a trusted node, we need to use a synchronised storage service
1893
- // to synchronise with a trusted node.
1894
- if (!this._config.isTrustedNode) {
1895
- core.Guards.stringValue(this.CLASS_NAME, "options.trustedSynchronisedStorageComponentType", options.trustedSynchronisedStorageComponentType);
1896
- this._trustedSynchronisedStorageComponent =
1897
- core.ComponentFactory.get(options.trustedSynchronisedStorageComponentType);
1898
- }
1899
- this._blobStorageHelper = new BlobStorageHelper(this._loggingComponent, this._vaultConnector, this._blobStorageConnector, this._config.blobStorageEncryptionKeyId, this._config.isTrustedNode);
1900
+ core.Guards.stringValue(this.CLASS_NAME, "synchronisedStorageKey", this._synchronisedStorageKey);
1901
+ this._blobStorageHelper = new BlobStorageHelper(this._loggingComponent, this._vaultConnector, this._blobStorageConnector, this._config.blobStorageEncryptionKeyId, isTrustedNode);
1900
1902
  this._changeSetHelper = new ChangeSetHelper(this._loggingComponent, this._eventBusComponent, this._identityConnector, this._blobStorageHelper, this._config.synchronisedStorageMethodId);
1901
1903
  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, this._config.isTrustedNode, this._config.maxConsolidations);
1904
+ this._remoteSyncStateHelper = new RemoteSyncStateHelper(this._loggingComponent, this._eventBusComponent, this._verifiableSyncPointerStorageConnector, this._blobStorageHelper, this._changeSetHelper, isTrustedNode, this._config.maxConsolidations);
1903
1905
  this._serviceStarted = false;
1904
1906
  this._activeStorageKeys = {};
1905
1907
  this._eventBusComponent.subscribe(synchronisedStorageModels.SynchronisedStorageTopics.RegisterStorageKey, async (event) => this.registerStorageKey(event.data));
@@ -1924,7 +1926,7 @@ class SynchronisedStorageService {
1924
1926
  this._remoteSyncStateHelper.setSynchronisedStorageKey(this._synchronisedStorageKey);
1925
1927
  this._serviceStarted = true;
1926
1928
  // If this is not a trusted node we need to request the decryption key from a trusted node
1927
- if (!this._config.isTrustedNode && !core.Is.empty(this._trustedSynchronisedStorageComponent)) {
1929
+ if (!core.Is.empty(this._trustedSynchronisedStorageComponent)) {
1928
1930
  const proof = await this._identityConnector.createProof(this._nodeIdentity, identityModels.DocumentHelper.joinId(this._nodeIdentity, this._config.synchronisedStorageMethodId), standardsW3cDid.ProofTypes.DataIntegrityProof, { nodeIdentity });
1929
1931
  const decryptionKey = await this._trustedSynchronisedStorageComponent.getDecryptionKey(this._nodeIdentity, proof);
1930
1932
  // We don't have the private key so instead we store the key as a secret in the vault
@@ -1957,7 +1959,7 @@ class SynchronisedStorageService {
1957
1959
  * @returns The decryption key.
1958
1960
  */
1959
1961
  async getDecryptionKey(nodeIdentity, proof) {
1960
- if (!this._config.isTrustedNode) {
1962
+ if (!core.Is.empty(this._trustedSynchronisedStorageComponent)) {
1961
1963
  throw new core.GeneralError(this.CLASS_NAME, "notTrustedNode");
1962
1964
  }
1963
1965
  core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
@@ -1980,7 +1982,7 @@ class SynchronisedStorageService {
1980
1982
  * @returns Nothing.
1981
1983
  */
1982
1984
  async syncChangeSet(syncChangeSet) {
1983
- if (!this._config.isTrustedNode) {
1985
+ if (!core.Is.empty(this._trustedSynchronisedStorageComponent)) {
1984
1986
  throw new core.GeneralError(this.CLASS_NAME, "notTrustedNode");
1985
1987
  }
1986
1988
  core.Guards.object(this.CLASS_NAME, "syncChangeSet", syncChangeSet);
@@ -2102,7 +2104,8 @@ class SynchronisedStorageService {
2102
2104
  }
2103
2105
  });
2104
2106
  // Send the local changes to the remote storage if we are a trusted node
2105
- if (this._config.isTrustedNode && core.Is.stringValue(changeSetStorageId)) {
2107
+ if (core.Is.empty(this._trustedSynchronisedStorageComponent) &&
2108
+ core.Is.stringValue(changeSetStorageId)) {
2106
2109
  // If we are a trusted node, we can add the change set to the sync state
2107
2110
  // and remove the local change snapshot
2108
2111
  await this._remoteSyncStateHelper.addChangeSetToSyncState(storageKey, changeSetStorageId);
@@ -2210,7 +2213,8 @@ class SynchronisedStorageService {
2210
2213
  }
2211
2214
  ], async () => this.startEntitySync(storageKey));
2212
2215
  }
2213
- if (this._config.isTrustedNode && this._config.consolidationIntervalMinutes > 0) {
2216
+ if (!core.Is.empty(this._trustedSynchronisedStorageComponent) &&
2217
+ this._config.consolidationIntervalMinutes > 0) {
2214
2218
  await this._taskSchedulerComponent.addTask(`synchronised-storage-consolidation-${storageKey}`, [
2215
2219
  {
2216
2220
  nextTriggerTime: Date.now(),
@@ -276,9 +276,9 @@ function initSchema() {
276
276
  EntitySchemaFactory.register("SyncSnapshotEntry", () => EntitySchemaHelper.getSchema(SyncSnapshotEntry));
277
277
  }
278
278
 
279
- var mainnet = "";
280
- var testnet = "";
281
- var devnet = "";
279
+ var mainnet = "verifiable:iota:0x0000000000000000000000000000000000000000000000000000000000000000:0x0000000000000000000000000000000000000000000000000000000000000000";
280
+ var testnet = "verifiable:iota:0x0000000000000000000000000000000000000000000000000000000000000000:0x0000000000000000000000000000000000000000000000000000000000000000";
281
+ var devnet = "verifiable:iota:0x0000000000000000000000000000000000000000000000000000000000000000:0x0000000000000000000000000000000000000000000000000000000000000000";
282
282
  var verifiableStorageKeys = {
283
283
  mainnet: mainnet,
284
284
  testnet: testnet,
@@ -1864,6 +1864,7 @@ class SynchronisedStorageService {
1864
1864
  constructor(options) {
1865
1865
  Guards.object(this.CLASS_NAME, "options", options);
1866
1866
  Guards.object(this.CLASS_NAME, "options.config", options.config);
1867
+ Guards.stringValue(this.CLASS_NAME, "options.config.verifiableStorageKeyId", options.config.verifiableStorageKeyId);
1867
1868
  this._eventBusComponent = ComponentFactory.get(options.eventBusComponentType ?? "event-bus");
1868
1869
  this._loggingComponent = ComponentFactory.getIfExists(options.loggingComponentType ?? "logging");
1869
1870
  this._vaultConnector = VaultConnectorFactory.get(options.vaultConnectorType ?? "vault");
@@ -1872,11 +1873,18 @@ class SynchronisedStorageService {
1872
1873
  this._blobStorageConnector = BlobStorageConnectorFactory.get(options.blobStorageConnectorType ?? "blob-storage");
1873
1874
  this._identityConnector = IdentityConnectorFactory.get(options.identityConnectorType ?? "identity");
1874
1875
  this._taskSchedulerComponent = ComponentFactory.get(options.taskSchedulerComponentType ?? "task-scheduler");
1876
+ // If this is empty we assume the local node has the rights to write to the verifiable storage.
1877
+ let isTrustedNode = true;
1878
+ if (!Is.empty(options.trustedSynchronisedStorageComponentType)) {
1879
+ isTrustedNode = false;
1880
+ // If it is set then we used the trusted component to send changesets to
1881
+ this._trustedSynchronisedStorageComponent =
1882
+ ComponentFactory.get(options.trustedSynchronisedStorageComponentType);
1883
+ }
1875
1884
  this._config = {
1876
1885
  synchronisedStorageMethodId: options.config.synchronisedStorageMethodId ?? "synchronised-storage-assertion",
1877
1886
  entityUpdateIntervalMinutes: options.config.entityUpdateIntervalMinutes ??
1878
1887
  SynchronisedStorageService._DEFAULT_ENTITY_UPDATE_INTERVAL_MINUTES,
1879
- isTrustedNode: options.config.isTrustedNode ?? false,
1880
1888
  consolidationIntervalMinutes: options.config.consolidationIntervalMinutes ??
1881
1889
  SynchronisedStorageService._DEFAULT_CONSOLIDATION_INTERVAL_MINUTES,
1882
1890
  consolidationBatchSize: options.config.consolidationBatchSize ??
@@ -1887,17 +1895,11 @@ class SynchronisedStorageService {
1887
1895
  };
1888
1896
  this._synchronisedStorageKey =
1889
1897
  verifiableStorageKeys[options.config.verifiableStorageKeyId] ?? options.config.verifiableStorageKeyId;
1890
- // If this is not a trusted node, we need to use a synchronised storage service
1891
- // to synchronise with a trusted node.
1892
- if (!this._config.isTrustedNode) {
1893
- Guards.stringValue(this.CLASS_NAME, "options.trustedSynchronisedStorageComponentType", options.trustedSynchronisedStorageComponentType);
1894
- this._trustedSynchronisedStorageComponent =
1895
- ComponentFactory.get(options.trustedSynchronisedStorageComponentType);
1896
- }
1897
- this._blobStorageHelper = new BlobStorageHelper(this._loggingComponent, this._vaultConnector, this._blobStorageConnector, this._config.blobStorageEncryptionKeyId, this._config.isTrustedNode);
1898
+ Guards.stringValue(this.CLASS_NAME, "synchronisedStorageKey", this._synchronisedStorageKey);
1899
+ this._blobStorageHelper = new BlobStorageHelper(this._loggingComponent, this._vaultConnector, this._blobStorageConnector, this._config.blobStorageEncryptionKeyId, isTrustedNode);
1898
1900
  this._changeSetHelper = new ChangeSetHelper(this._loggingComponent, this._eventBusComponent, this._identityConnector, this._blobStorageHelper, this._config.synchronisedStorageMethodId);
1899
1901
  this._localSyncStateHelper = new LocalSyncStateHelper(this._loggingComponent, this._localSyncSnapshotEntryEntityStorage, this._changeSetHelper);
1900
- this._remoteSyncStateHelper = new RemoteSyncStateHelper(this._loggingComponent, this._eventBusComponent, this._verifiableSyncPointerStorageConnector, this._blobStorageHelper, this._changeSetHelper, this._config.isTrustedNode, this._config.maxConsolidations);
1902
+ this._remoteSyncStateHelper = new RemoteSyncStateHelper(this._loggingComponent, this._eventBusComponent, this._verifiableSyncPointerStorageConnector, this._blobStorageHelper, this._changeSetHelper, isTrustedNode, this._config.maxConsolidations);
1901
1903
  this._serviceStarted = false;
1902
1904
  this._activeStorageKeys = {};
1903
1905
  this._eventBusComponent.subscribe(SynchronisedStorageTopics.RegisterStorageKey, async (event) => this.registerStorageKey(event.data));
@@ -1922,7 +1924,7 @@ class SynchronisedStorageService {
1922
1924
  this._remoteSyncStateHelper.setSynchronisedStorageKey(this._synchronisedStorageKey);
1923
1925
  this._serviceStarted = true;
1924
1926
  // If this is not a trusted node we need to request the decryption key from a trusted node
1925
- if (!this._config.isTrustedNode && !Is.empty(this._trustedSynchronisedStorageComponent)) {
1927
+ if (!Is.empty(this._trustedSynchronisedStorageComponent)) {
1926
1928
  const proof = await this._identityConnector.createProof(this._nodeIdentity, DocumentHelper.joinId(this._nodeIdentity, this._config.synchronisedStorageMethodId), ProofTypes.DataIntegrityProof, { nodeIdentity });
1927
1929
  const decryptionKey = await this._trustedSynchronisedStorageComponent.getDecryptionKey(this._nodeIdentity, proof);
1928
1930
  // We don't have the private key so instead we store the key as a secret in the vault
@@ -1955,7 +1957,7 @@ class SynchronisedStorageService {
1955
1957
  * @returns The decryption key.
1956
1958
  */
1957
1959
  async getDecryptionKey(nodeIdentity, proof) {
1958
- if (!this._config.isTrustedNode) {
1960
+ if (!Is.empty(this._trustedSynchronisedStorageComponent)) {
1959
1961
  throw new GeneralError(this.CLASS_NAME, "notTrustedNode");
1960
1962
  }
1961
1963
  Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
@@ -1978,7 +1980,7 @@ class SynchronisedStorageService {
1978
1980
  * @returns Nothing.
1979
1981
  */
1980
1982
  async syncChangeSet(syncChangeSet) {
1981
- if (!this._config.isTrustedNode) {
1983
+ if (!Is.empty(this._trustedSynchronisedStorageComponent)) {
1982
1984
  throw new GeneralError(this.CLASS_NAME, "notTrustedNode");
1983
1985
  }
1984
1986
  Guards.object(this.CLASS_NAME, "syncChangeSet", syncChangeSet);
@@ -2100,7 +2102,8 @@ class SynchronisedStorageService {
2100
2102
  }
2101
2103
  });
2102
2104
  // Send the local changes to the remote storage if we are a trusted node
2103
- if (this._config.isTrustedNode && Is.stringValue(changeSetStorageId)) {
2105
+ if (Is.empty(this._trustedSynchronisedStorageComponent) &&
2106
+ Is.stringValue(changeSetStorageId)) {
2104
2107
  // If we are a trusted node, we can add the change set to the sync state
2105
2108
  // and remove the local change snapshot
2106
2109
  await this._remoteSyncStateHelper.addChangeSetToSyncState(storageKey, changeSetStorageId);
@@ -2208,7 +2211,8 @@ class SynchronisedStorageService {
2208
2211
  }
2209
2212
  ], async () => this.startEntitySync(storageKey));
2210
2213
  }
2211
- if (this._config.isTrustedNode && this._config.consolidationIntervalMinutes > 0) {
2214
+ if (!Is.empty(this._trustedSynchronisedStorageComponent) &&
2215
+ this._config.consolidationIntervalMinutes > 0) {
2212
2216
  await this._taskSchedulerComponent.addTask(`synchronised-storage-consolidation-${storageKey}`, [
2213
2217
  {
2214
2218
  nextTriggerTime: Date.now(),
@@ -12,11 +12,6 @@ export interface ISynchronisedStorageServiceConfig {
12
12
  * @default 5
13
13
  */
14
14
  entityUpdateIntervalMinutes?: number;
15
- /**
16
- * Is this a node that has permission to write to the verifiable storage?
17
- * @default false
18
- */
19
- isTrustedNode?: boolean;
20
15
  /**
21
16
  * Interval to perform consolidation of changesets, only used if isTrustedNode is set.
22
17
  * @default 60
@@ -42,6 +42,7 @@ export interface ISynchronisedStorageServiceConstructorOptions {
42
42
  taskSchedulerComponentType?: string;
43
43
  /**
44
44
  * The synchronised entity storage component type to use if this node is not trusted.
45
+ * If this is set, this node uses it as the trusted node to store changesets.
45
46
  */
46
47
  trustedSynchronisedStorageComponentType?: string;
47
48
  /**
package/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.1-next.9](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-service-v0.0.1-next.8...synchronised-storage-service-v0.0.1-next.9) (2025-08-13)
4
+
5
+
6
+ ### Features
7
+
8
+ * add guards for verifiable storage keys ([5182e8b](https://github.com/twinfoundation/synchronised-storage/commit/5182e8b2a7868e8d396fd02964b0ed7f0c0a5947))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/synchronised-storage-models bumped from 0.0.1-next.8 to 0.0.1-next.9
16
+
17
+ ## [0.0.1-next.8](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-service-v0.0.1-next.7...synchronised-storage-service-v0.0.1-next.8) (2025-08-13)
18
+
19
+
20
+ ### Features
21
+
22
+ * remove isTrustedNode from config and rely on trusted component ([cc2d987](https://github.com/twinfoundation/synchronised-storage/commit/cc2d98795044fc97b33fadf871188f6103f5c987))
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/synchronised-storage-models bumped from 0.0.1-next.7 to 0.0.1-next.8
30
+
3
31
  ## [0.0.1-next.7](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-service-v0.0.1-next.6...synchronised-storage-service-v0.0.1-next.7) (2025-08-12)
4
32
 
5
33
 
@@ -32,20 +32,6 @@ How often to check for entity updates in minutes.
32
32
 
33
33
  ***
34
34
 
35
- ### isTrustedNode?
36
-
37
- > `optional` **isTrustedNode**: `boolean`
38
-
39
- Is this a node that has permission to write to the verifiable storage?
40
-
41
- #### Default
42
-
43
- ```ts
44
- false
45
- ```
46
-
47
- ***
48
-
49
35
  ### consolidationIntervalMinutes?
50
36
 
51
37
  > `optional` **consolidationIntervalMinutes**: `number`
@@ -103,6 +103,7 @@ task-scheduler
103
103
  > `optional` **trustedSynchronisedStorageComponentType**: `string`
104
104
 
105
105
  The synchronised entity storage component type to use if this node is not trusted.
106
+ If this is set, this node uses it as the trusted node to store changesets.
106
107
 
107
108
  ***
108
109
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/synchronised-storage-service",
3
- "version": "0.0.1-next.7",
3
+ "version": "0.0.1-next.9",
4
4
  "description": "Synchronised storage contract implementation and REST endpoint definitions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,7 +26,7 @@
26
26
  "@twin.org/logging-models": "next",
27
27
  "@twin.org/nameof": "next",
28
28
  "@twin.org/standards-w3c-did": "next",
29
- "@twin.org/synchronised-storage-models": "0.0.1-next.7",
29
+ "@twin.org/synchronised-storage-models": "0.0.1-next.9",
30
30
  "@twin.org/verifiable-storage-models": "next",
31
31
  "@twin.org/web": "next"
32
32
  },