@twin.org/synchronised-storage-service 0.0.1-next.3 → 0.0.1-next.4

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 (34) hide show
  1. package/dist/cjs/index.cjs +641 -176
  2. package/dist/esm/index.mjs +642 -178
  3. package/dist/types/entities/syncSnapshotEntry.d.ts +1 -2
  4. package/dist/types/helpers/blobStorageHelper.d.ts +33 -0
  5. package/dist/types/helpers/changeSetHelper.d.ts +19 -7
  6. package/dist/types/helpers/localSyncStateHelper.d.ts +8 -23
  7. package/dist/types/helpers/remoteSyncStateHelper.d.ts +15 -11
  8. package/dist/types/helpers/versions.d.ts +3 -0
  9. package/dist/types/index.d.ts +0 -2
  10. package/dist/types/models/ISyncPointerStore.d.ts +4 -0
  11. package/dist/types/models/ISyncSnapshot.d.ts +5 -1
  12. package/dist/types/models/ISyncState.d.ts +4 -0
  13. package/dist/types/models/ISynchronisedStorageServiceConfig.d.ts +12 -6
  14. package/dist/types/models/ISynchronisedStorageServiceConstructorOptions.d.ts +6 -2
  15. package/dist/types/synchronisedStorageRoutes.d.ts +9 -1
  16. package/dist/types/synchronisedStorageService.d.ts +13 -4
  17. package/docs/architecture.md +125 -0
  18. package/docs/changelog.md +15 -0
  19. package/docs/open-api/spec.json +244 -18
  20. package/docs/reference/classes/SyncSnapshotEntry.md +1 -1
  21. package/docs/reference/classes/SynchronisedStorageService.md +38 -5
  22. package/docs/reference/functions/synchronisedStorageGetDecryptionKeyRequest.md +31 -0
  23. package/docs/reference/index.md +1 -2
  24. package/docs/reference/interfaces/ISyncPointerStore.md +8 -0
  25. package/docs/reference/interfaces/ISyncSnapshot.md +10 -2
  26. package/docs/reference/interfaces/ISyncState.md +8 -0
  27. package/docs/reference/interfaces/ISynchronisedStorageServiceConfig.md +30 -10
  28. package/docs/reference/interfaces/ISynchronisedStorageServiceConstructorOptions.md +11 -3
  29. package/locales/en.json +46 -18
  30. package/package.json +3 -2
  31. package/dist/types/models/ISyncChange.d.ts +0 -18
  32. package/dist/types/models/ISyncChangeSet.d.ts +0 -36
  33. package/docs/reference/interfaces/ISyncChange.md +0 -33
  34. package/docs/reference/interfaces/ISyncChangeSet.md +0 -65
@@ -1,5 +1,4 @@
1
- import type { ISynchronisedEntity } from "@twin.org/synchronised-storage-models";
2
- import type { ISyncChange } from "../models/ISyncChange";
1
+ import type { ISyncChange, ISynchronisedEntity } from "@twin.org/synchronised-storage-models";
3
2
  /**
4
3
  * Class representing an entry for the sync snapshot.
5
4
  */
@@ -0,0 +1,33 @@
1
+ import type { IBlobStorageConnector } from "@twin.org/blob-storage-models";
2
+ import type { ILoggingConnector } from "@twin.org/logging-models";
3
+ import { type IVaultConnector } from "@twin.org/vault-models";
4
+ /**
5
+ * Class for performing blob storage operations.
6
+ */
7
+ export declare class BlobStorageHelper {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ readonly CLASS_NAME: string;
12
+ /**
13
+ * Create a new instance of BlobStorageHelper.
14
+ * @param logging The logging connector to use for logging.
15
+ * @param vaultConnector The vault connector to use for for the encryption key.
16
+ * @param blobStorageConnector The blob storage component to use.
17
+ * @param blobStorageEncryptionKeyId The id of the vault key to use for encrypting/decrypting blobs.
18
+ * @param isTrustedNode Is this a trusted node.
19
+ */
20
+ constructor(logging: ILoggingConnector | undefined, vaultConnector: IVaultConnector, blobStorageConnector: IBlobStorageConnector, blobStorageEncryptionKeyId: string, isTrustedNode: boolean);
21
+ /**
22
+ * Load a blob from storage.
23
+ * @param blobId The id of the blob to apply.
24
+ * @returns The blob.
25
+ */
26
+ load<T>(blobId: string): Promise<T | undefined>;
27
+ /**
28
+ * Save a blob.
29
+ * @param blob The blob to save.
30
+ * @returns The id of the blob.
31
+ */
32
+ saveBlob<T>(blob: T): Promise<string>;
33
+ }
@@ -1,10 +1,9 @@
1
- import { type IBlobStorageComponent } from "@twin.org/blob-storage-models";
2
1
  import type { IEventBusComponent } from "@twin.org/event-bus-models";
3
2
  import { type IIdentityConnector } from "@twin.org/identity-models";
4
3
  import type { ILoggingConnector } from "@twin.org/logging-models";
5
4
  import { type IProof } from "@twin.org/standards-w3c-did";
6
- import { type ISynchronisedEntity } from "@twin.org/synchronised-storage-models";
7
- import type { ISyncChangeSet } from "../models/ISyncChangeSet";
5
+ import { type ISyncChangeSet, type ISynchronisedEntity } from "@twin.org/synchronised-storage-models";
6
+ import type { BlobStorageHelper } from "./blobStorageHelper";
8
7
  /**
9
8
  * Class for performing change set operations.
10
9
  */
@@ -17,11 +16,16 @@ export declare class ChangeSetHelper<T extends ISynchronisedEntity = ISynchronis
17
16
  * Create a new instance of ChangeSetHelper.
18
17
  * @param logging The logging connector to use for logging.
19
18
  * @param eventBusComponent The event bus component to use for events.
20
- * @param blobStorageComponent The blob storage component to use for remote sync states.
21
19
  * @param identityConnector The identity connector to use for signing/verifying changesets.
20
+ * @param blobStorageHelper The blob storage component to use for remote sync states.
22
21
  * @param decentralisedStorageMethodId The id of the identity method to use when signing/verifying changesets.
23
22
  */
24
- constructor(logging: ILoggingConnector | undefined, eventBusComponent: IEventBusComponent, blobStorageComponent: IBlobStorageComponent, identityConnector: IIdentityConnector, decentralisedStorageMethodId: string);
23
+ constructor(logging: ILoggingConnector | undefined, eventBusComponent: IEventBusComponent, identityConnector: IIdentityConnector, blobStorageHelper: BlobStorageHelper, decentralisedStorageMethodId: string);
24
+ /**
25
+ * Set the node identity to use for signing changesets.
26
+ * @param nodeIdentity The identity of the node that is performing the update.
27
+ */
28
+ setNodeIdentity(nodeIdentity: string): void;
25
29
  /**
26
30
  * Get and verify a changeset.
27
31
  * @param changeSetStorageId The id of the sync changeset to apply.
@@ -43,10 +47,9 @@ export declare class ChangeSetHelper<T extends ISynchronisedEntity = ISynchronis
43
47
  /**
44
48
  * Store the changeset.
45
49
  * @param syncChangeSet The sync change set to store.
46
- * @param nodeIdentity The node identity to use for the changeset.
47
50
  * @returns The id of the change set.
48
51
  */
49
- storeChangeSet(syncChangeSet: ISyncChangeSet, nodeIdentity: string): Promise<string>;
52
+ storeChangeSet(syncChangeSet: ISyncChangeSet): Promise<string>;
50
53
  /**
51
54
  * Verify the proof of a sync changeset.
52
55
  * @param syncChangeset The sync changeset to verify.
@@ -59,4 +62,13 @@ export declare class ChangeSetHelper<T extends ISynchronisedEntity = ISynchronis
59
62
  * @returns The proof.
60
63
  */
61
64
  createChangeSetProof(syncChangeset: ISyncChangeSet): Promise<IProof>;
65
+ /**
66
+ * Copy a change set.
67
+ * @param syncChangeSet The sync changeset to copy.
68
+ * @returns The id of the updated change set.
69
+ */
70
+ copyChangeset(syncChangeSet: ISyncChangeSet<T>): Promise<{
71
+ syncChangeSet: ISyncChangeSet<T>;
72
+ changeSetStorageId: string;
73
+ } | undefined>;
62
74
  }
@@ -15,10 +15,10 @@ export declare class LocalSyncStateHelper<T extends ISynchronisedEntity = ISynch
15
15
  /**
16
16
  * Create a new instance of LocalSyncStateHelper.
17
17
  * @param logging The logging connector to use for logging.
18
- * @param localSyncSnapshotEntryEntityStorage The storage connector for the local sync snapshot entries.
18
+ * @param snapshotEntryEntityStorage The storage connector for the sync snapshot entries.
19
19
  * @param changeSetHelper The change set helper to use for applying changesets.
20
20
  */
21
- constructor(logging: ILoggingConnector | undefined, localSyncSnapshotEntryEntityStorage: IEntityStorageConnector<SyncSnapshotEntry<T>>, changeSetHelper: ChangeSetHelper<T>);
21
+ constructor(logging: ILoggingConnector | undefined, snapshotEntryEntityStorage: IEntityStorageConnector<SyncSnapshotEntry<T>>, changeSetHelper: ChangeSetHelper<T>);
22
22
  /**
23
23
  * Add a new change to the local snapshot.
24
24
  * @param storageKey The storage key of the snapshot to add the change for.
@@ -28,43 +28,28 @@ export declare class LocalSyncStateHelper<T extends ISynchronisedEntity = ISynch
28
28
  */
29
29
  addLocalChange(storageKey: string, operation: SyncChangeOperation, id: string): Promise<void>;
30
30
  /**
31
- * Get the current local snapshot.
31
+ * Get the current local snapshot which contains just the changes for this node.
32
32
  * @param storageKey The storage key of the snapshot to get.
33
33
  * @returns The local snapshot entry.
34
34
  */
35
35
  getLocalChangeSnapshot(storageKey: string): Promise<SyncSnapshotEntry<T>>;
36
36
  /**
37
- * Set the current local snapshot.
37
+ * Set the current local snapshot with changes for this node.
38
38
  * @param localChangeSnapshot The local change snapshot to set.
39
39
  * @returns Nothing.
40
40
  */
41
41
  setLocalChangeSnapshot(localChangeSnapshot: SyncSnapshotEntry<T>): Promise<void>;
42
42
  /**
43
- * Get the current local snapshot.
43
+ * Get the current local snapshot with the changes for this node.
44
44
  * @param localChangeSnapshot The local change snapshot to remove.
45
45
  * @returns Nothing.
46
46
  */
47
47
  removeLocalChangeSnapshot(localChangeSnapshot: SyncSnapshotEntry<T>): Promise<void>;
48
48
  /**
49
- * Sync local data using a remote sync state.
49
+ * Apply a sync state to the local node.
50
50
  * @param storageKey The storage key of the snapshot to sync with.
51
- * @param remoteSyncState The sync state to sync with.
51
+ * @param syncState The sync state to sync with.
52
52
  * @returns Nothing.
53
53
  */
54
- syncFromRemote(storageKey: string, remoteSyncState: ISyncState): Promise<void>;
55
- /**
56
- * Process the modified snapshots and store them in the local storage.
57
- * @param modifiedSnapshots The modified snapshots to process.
58
- * @returns Nothing.
59
- */
60
- processModifiedSnapshots(modifiedSnapshots: {
61
- localSnapshot: SyncSnapshotEntry<T>;
62
- remoteSnapshot: SyncSnapshotEntry<T>;
63
- }[]): Promise<void>;
64
- /**
65
- * Process the new snapshots and store them in the local storage.
66
- * @param newSnapshots The new snapshots to process.
67
- * @returns Nothing.
68
- */
69
- private processNewSnapshots;
54
+ applySyncState(storageKey: string, syncState: ISyncState): Promise<void>;
70
55
  }
@@ -1,10 +1,9 @@
1
- import { type IBlobStorageComponent } from "@twin.org/blob-storage-models";
2
1
  import type { IEventBusComponent } from "@twin.org/event-bus-models";
3
2
  import type { ILoggingConnector } from "@twin.org/logging-models";
4
- import { type ISynchronisedEntity } from "@twin.org/synchronised-storage-models";
3
+ import { type ISyncChange, type ISyncChangeSet, type ISynchronisedEntity } from "@twin.org/synchronised-storage-models";
5
4
  import type { IVerifiableStorageConnector } from "@twin.org/verifiable-storage-models";
5
+ import type { BlobStorageHelper } from "./blobStorageHelper";
6
6
  import type { ChangeSetHelper } from "./changeSetHelper";
7
- import type { ISyncChange } from "../models/ISyncChange";
8
7
  import type { ISyncPointerStore } from "../models/ISyncPointerStore";
9
8
  import type { ISyncState } from "../models/ISyncState";
10
9
  /**
@@ -19,32 +18,37 @@ export declare class RemoteSyncStateHelper<T extends ISynchronisedEntity = ISync
19
18
  * Create a new instance of DecentralisedEntityStorageConnector.
20
19
  * @param logging The logging connector to use for logging.
21
20
  * @param eventBusComponent The event bus component to use for events.
22
- * @param blobStorageComponent The blob storage component to use for remote sync states.
23
21
  * @param verifiableSyncPointerStorageConnector The verifiable storage connector to use for storing sync pointers.
22
+ * @param blobStorageHelper The blob storage helper to use for remote sync states.
24
23
  * @param changeSetHelper The change set helper to use for managing changesets.
25
- * @param synchronisedStorageKey The synchronised storage key to use for verified storage operations.
24
+ * @param isTrustedNode Whether the node is trusted or not.
26
25
  */
27
- constructor(logging: ILoggingConnector | undefined, eventBusComponent: IEventBusComponent, blobStorageComponent: IBlobStorageComponent, verifiableSyncPointerStorageConnector: IVerifiableStorageConnector, changeSetHelper: ChangeSetHelper<T>, synchronisedStorageKey: string);
26
+ constructor(logging: ILoggingConnector | undefined, eventBusComponent: IEventBusComponent, verifiableSyncPointerStorageConnector: IVerifiableStorageConnector, blobStorageHelper: BlobStorageHelper, changeSetHelper: ChangeSetHelper<T>, isTrustedNode: boolean);
28
27
  /**
29
28
  * Set the node identity to use for signing changesets.
30
29
  * @param nodeIdentity The identity of the node that is performing the update.
31
30
  */
32
31
  setNodeIdentity(nodeIdentity: string): void;
33
32
  /**
34
- * Create and store a change set.
33
+ * Set the synchronised storage key.
34
+ * @param synchronisedStorageKey The synchronised storage key to use.
35
+ */
36
+ setSynchronisedStorageKey(synchronisedStorageKey: string): void;
37
+ /**
38
+ * Build a changeset.
35
39
  * @param storageKey The storage key of the change set.
36
40
  * @param changes The changes to apply.
37
41
  * @param completeCallback The callback to call when the changeset is created and stored.
38
42
  * @returns The storage id of the change set if created.
39
43
  */
40
- createAndStoreChangeSet(storageKey: string, changes: ISyncChange<T>[], completeCallback: (id?: string) => Promise<void>): Promise<void>;
44
+ buildChangeSet(storageKey: string, changes: ISyncChange<T>[], completeCallback: (syncChangeSet?: ISyncChangeSet<T>, id?: string) => Promise<void>): Promise<void>;
41
45
  /**
42
46
  * Finalise the full details for the sync change set.
43
47
  * @param storageKey The storage key of the change set.
44
48
  * @param completeCallback The callback to call when the changeset is populated.
45
49
  * @returns Nothing.
46
50
  */
47
- finaliseFullChanges(storageKey: string, completeCallback: (id?: string) => Promise<void>): Promise<void>;
51
+ finaliseFullChanges(storageKey: string, completeCallback: (syncChangeSet?: ISyncChangeSet<T>, id?: string) => Promise<void>): Promise<void>;
48
52
  /**
49
53
  * Add a new changeset into the sync state.
50
54
  * @param storageKey The storage key of the change set to add.
@@ -58,7 +62,7 @@ export declare class RemoteSyncStateHelper<T extends ISynchronisedEntity = ISync
58
62
  * @param batchSize The batch size to use for consolidation.
59
63
  * @returns Nothing.
60
64
  */
61
- consolidateFromLocal(storageKey: string, batchSize: number): Promise<void>;
65
+ consolidationStart(storageKey: string, batchSize: number): Promise<void>;
62
66
  /**
63
67
  * Get the sync pointer store.
64
68
  * @returns The sync pointer store.
@@ -83,7 +87,7 @@ export declare class RemoteSyncStateHelper<T extends ISynchronisedEntity = ISync
83
87
  */
84
88
  getRemoteSyncState(syncPointerId: string): Promise<ISyncState | undefined>;
85
89
  /**
86
- * Handle the batch response.
90
+ * Handle the batch response which is triggered from a consolidation request.
87
91
  * @param response The batch response to handle.
88
92
  */
89
93
  private handleBatchResponse;
@@ -0,0 +1,3 @@
1
+ export declare const SYNC_STATE_VERSION: string;
2
+ export declare const SYNC_POINTER_STORE_VERSION: string;
3
+ export declare const SYNC_SNAPSHOT_VERSION: string;
@@ -1,6 +1,4 @@
1
1
  export * from "./entities/syncSnapshotEntry";
2
- export * from "./models/ISyncChange";
3
- export * from "./models/ISyncChangeSet";
4
2
  export * from "./models/ISynchronisedStorageServiceConfig";
5
3
  export * from "./models/ISynchronisedStorageServiceConstructorOptions";
6
4
  export * from "./models/ISyncPointerStore";
@@ -2,6 +2,10 @@
2
2
  * The object definition for the sync pointer store.
3
3
  */
4
4
  export interface ISyncPointerStore {
5
+ /**
6
+ * The version of the sync pointer store.
7
+ */
8
+ version: string;
5
9
  /**
6
10
  * The mapping from storage keys to sync pointers.
7
11
  */
@@ -2,6 +2,10 @@
2
2
  * The object definition for a sync snapshot.
3
3
  */
4
4
  export interface ISyncSnapshot {
5
+ /**
6
+ * The version of the sync state.
7
+ */
8
+ version: string;
5
9
  /**
6
10
  * The id of the snapshot.
7
11
  */
@@ -13,7 +17,7 @@ export interface ISyncSnapshot {
13
17
  /**
14
18
  * The date the snapshot was last modified.
15
19
  */
16
- dateModified?: string;
20
+ dateModified: string;
17
21
  /**
18
22
  * The ids of the storage for the change sets in the snapshot.
19
23
  */
@@ -3,6 +3,10 @@ import type { ISyncSnapshot } from "./ISyncSnapshot";
3
3
  * The object definition for a sync state.
4
4
  */
5
5
  export interface ISyncState {
6
+ /**
7
+ * The version of the sync state.
8
+ */
9
+ version: string;
6
10
  /**
7
11
  * The snapshots.
8
12
  */
@@ -3,12 +3,7 @@
3
3
  */
4
4
  export interface ISynchronisedStorageServiceConfig {
5
5
  /**
6
- * The key to use for the remote synchronised storage, the initial item will have been
7
- * generated by a trusted node.
8
- */
9
- synchronisedStorageKey: string;
10
- /**
11
- * The id of the identity method to use when signing/verifying changesets.
6
+ * The id of the identity method to use when signing/verifying requests and changesets.
12
7
  * @default synchronised-storage-assertion
13
8
  */
14
9
  synchronisedStorageMethodId?: string;
@@ -32,4 +27,15 @@ export interface ISynchronisedStorageServiceConfig {
32
27
  * @default 1000
33
28
  */
34
29
  consolidationBatchSize?: number;
30
+ /**
31
+ * The encryption key id from the vault to use for blob storage, only required for trusted nodes, untrusted nodes will request the key.
32
+ * @default synchronised-storage-blob-encryption-key
33
+ */
34
+ blobStorageEncryptionKeyId?: string;
35
+ /**
36
+ * The verifiable storage key to use, already expected to be created.
37
+ * if the key is not found in the keys.json it is considered to be a custom verifiable storage id.
38
+ * @default local
39
+ */
40
+ verifiableStorageKeyId: "mainnet" | "testnet" | "devnet" | string;
35
41
  }
@@ -11,16 +11,20 @@ export interface ISynchronisedStorageServiceConstructorOptions {
11
11
  * The event bus component type.
12
12
  */
13
13
  eventBusComponentType?: string;
14
+ /**
15
+ * The vault connector type.
16
+ */
17
+ vaultConnectorType?: string;
14
18
  /**
15
19
  * The entity storage connector type to use for sync snapshots.
16
20
  * @default sync-snapshot-entry
17
21
  */
18
22
  syncSnapshotStorageConnectorType?: string;
19
23
  /**
20
- * The blob storage component used for remote sync state.
24
+ * The blob storage connector used for remote sync state.
21
25
  * @default blob-storage
22
26
  */
23
- blobStorageComponentType?: string;
27
+ blobStorageConnectorType?: string;
24
28
  /**
25
29
  * The verifiable storage connector type to use for decentralised state.
26
30
  * @default verifiable-storage
@@ -1,5 +1,5 @@
1
1
  import type { IHttpRequestContext, INoContentResponse, IRestRoute, ITag } from "@twin.org/api-models";
2
- import type { ISyncChangeSetRequest } from "@twin.org/synchronised-storage-models";
2
+ import type { ISyncChangeSetRequest, ISyncDecryptionKeyRequest, ISyncDecryptionKeyResponse } from "@twin.org/synchronised-storage-models";
3
3
  /**
4
4
  * The tag to associate with the routes.
5
5
  */
@@ -19,3 +19,11 @@ export declare function generateRestRoutesSynchronisedStorage(baseRouteName: str
19
19
  * @returns The response object with additional http response properties.
20
20
  */
21
21
  export declare function synchronisedStorageSyncChangeSetRequest(httpRequestContext: IHttpRequestContext, componentName: string, request: ISyncChangeSetRequest): Promise<INoContentResponse>;
22
+ /**
23
+ * Request the decryption key.
24
+ * @param httpRequestContext The request context for the API.
25
+ * @param componentName The name of the component to use in the routes.
26
+ * @param request The request.
27
+ * @returns The response object with additional http response properties.
28
+ */
29
+ export declare function synchronisedStorageGetDecryptionKeyRequest(httpRequestContext: IHttpRequestContext, componentName: string, request: ISyncDecryptionKeyRequest): Promise<ISyncDecryptionKeyResponse>;
@@ -1,4 +1,5 @@
1
- import { type ISynchronisedEntity, type ISynchronisedStorageComponent } from "@twin.org/synchronised-storage-models";
1
+ import { type IProof } from "@twin.org/standards-w3c-did";
2
+ import { type ISyncChangeSet, type ISynchronisedEntity, type ISynchronisedStorageComponent } from "@twin.org/synchronised-storage-models";
2
3
  import type { ISynchronisedStorageServiceConstructorOptions } from "./models/ISynchronisedStorageServiceConstructorOptions";
3
4
  /**
4
5
  * Class for performing synchronised storage operations.
@@ -34,9 +35,17 @@ export declare class SynchronisedStorageService<T extends ISynchronisedEntity =
34
35
  [id: string]: unknown;
35
36
  }): Promise<void>;
36
37
  /**
37
- * Synchronise a complete set of changes, assumes this is a trusted node.
38
- * @param changeSetStorageId The id of the change set to synchronise in blob storage.
38
+ * Get the decryption key for the synchronised storage.
39
+ * This is used to decrypt the data stored in the synchronised storage.
40
+ * @param nodeIdentity The identity of the node requesting the decryption key.
41
+ * @param proof The proof of the request so we know the request is from the specified node.
42
+ * @returns The decryption key.
43
+ */
44
+ getDecryptionKey(nodeIdentity: string, proof: IProof): Promise<string>;
45
+ /**
46
+ * Synchronise a set of changes from an untrusted node, assumes this is a trusted node.
47
+ * @param syncChangeSet The change set to synchronise.
39
48
  * @returns Nothing.
40
49
  */
41
- syncChangeSet(changeSetStorageId: string): Promise<void>;
50
+ syncChangeSet(syncChangeSet: ISyncChangeSet<T>): Promise<void>;
42
51
  }
@@ -0,0 +1,125 @@
1
+ # Synchronised Storage Service Architecture
2
+
3
+ ## Overview
4
+
5
+ The Synchronised Storage Service implements a distributed, eventually-consistent data replication system built on a decentralised architecture. The system provides conflict-free, cryptographically-verifiable synchronisation of entity storage mutations across a network of heterogeneous nodes through a combination of trusted node coordination and decentralised storage protocols.
6
+
7
+ ## Core Architecture
8
+
9
+ ### System Components
10
+
11
+ #### 1. Entity Storage Layer
12
+
13
+ - **Purpose**: Persistent data layer storing application entities
14
+ - **Interface**: CRUD operations with change event emission via event bus
15
+ - **Implementation**: Pluggable storage connectors (Memory, File System, Database)
16
+ - **Change Detection**: Mutation observers capture CREATE, UPDATE, DELETE operations
17
+ - **Event Emission**: Publishes change notifications to event bus for downstream processing
18
+
19
+ #### 2. Change Capture Subsystem
20
+
21
+ - **Event Bus Integration**: Subscribes to entity storage change events via decoupled event bus architecture
22
+ - **Change Sets**: Immutable collections of related entity mutations aggregated from event notifications
23
+ - **Serialisation**: Compressed binary format with cryptographic signatures
24
+ - **Metadata**: Timestamps, node identity, operation vectors
25
+ - **Batching**: Configurable aggregation windows for performance optimisation
26
+
27
+ #### 3. Cryptographic Verification Layer
28
+
29
+ - **Digital Signatures**: DID Proofs on change set payloads
30
+ - **Identity Management**: DID-based node authentication
31
+ - **Proof Chains**: Verifiable computation proofs for data integrity
32
+ - **Encryption**: RSA-2048 encryption for sensitive payload data with SPKI keys available to regular nodes, and PKCS and SPKI on the trusted nodes
33
+
34
+ #### 5. Event Bus Architecture
35
+
36
+ - **Decoupled Communication**: Asynchronous message passing between entity storage and change capture systems
37
+ - **Topic-Based Routing**: Structured message topics for different operation types (create, update, delete)
38
+ - **Pluggable Connectors**: Support for various event bus implementations (Local, Redis, AMQP, Kafka)
39
+ - **Message Serialisation**: JSON-based message payloads with type-safe schemas
40
+
41
+ #### 6. Network Topology
42
+
43
+ ```text
44
+ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
45
+ │ Regular Node │ │ Regular Node │ │ Regular Node │
46
+ │ │ │ │ │ │
47
+ └────────┬────────┘ └────────┬────────┘ └────────┬────────┘
48
+ │ │ │
49
+ └──────────────────────┼──────────────────────┘
50
+
51
+ ┌─────────────────┴─────────────────┐
52
+ │ │
53
+ ┌──────────▼──────────┐ ┌────────▼────────────┐
54
+ │ Trusted Node A │ │ Trusted Node B │
55
+ │ • Change Validation │ │ • Change Validation │
56
+ │ • Load Distribution │ │ • Load Distribution │
57
+ │ • State Consensus │◄────────────►│ • State Consensus │
58
+ └──────────┬──────────┘ └─────────┬───────────┘
59
+ │ │
60
+ └─────────────────┬─────────────────┘
61
+
62
+ ┌───────────▼────────────┐
63
+ │ Verifiable Storage │
64
+ │ • On-chain Pointers │
65
+ │ • State Root Hashes │
66
+ │ • Access Control │
67
+ └───────────┬────────────┘
68
+
69
+ ┌───────────▼────────────┐
70
+ │ Decentralised Storage │
71
+ │ • IPFS/Content Hash │
72
+ │ • Immutable Blobs │
73
+ │ • Distributed Refs │
74
+ └────────────────────────┘
75
+ ```
76
+
77
+ ## Node Types & Responsibilities
78
+
79
+ ### Regular Nodes
80
+
81
+ - **Local Change Monitoring**: Capture entity storage mutations via event bus
82
+ - **Change Set Generation**: Aggregate mutations into signed, compressed payloads
83
+ - **Trusted Node Communication**: Submit change sets for global replication
84
+ - **Sync State Polling**: Periodically query verifiable storage for remote updates
85
+ - **Conflict Resolution**: Apply three-way merge algorithms for concurrent modifications
86
+ - **Resource Constraints**: Minimal storage and computational requirements
87
+
88
+ ### Trusted Nodes
89
+
90
+ - **Multi-Node Architecture**: Multiple trusted nodes operate in parallel to distribute processing load and provide high availability
91
+ - **Change Validation**: Verify cryptographic signatures and node permissions across the cluster
92
+ - **Change Set Consolidation**: Periodic compaction of historical change logs distributed across trusted node instances
93
+ - **Decentralised Storage Interface**: Upload/download operations to IPFS-like systems with load balancing
94
+ - **Verifiable Storage Updates**: Atomic updates to on-chain state pointers with consensus agreement
95
+ - **Load Distribution**: Automatic distribution of regular node connections and change processing across available trusted nodes
96
+
97
+ ## Data Flow Architecture
98
+
99
+ ### 1. Local Change Detection
100
+
101
+ ```typescript
102
+ EntityStorage → ChangeCapture → LocalSnapshot → EventBus
103
+ ```
104
+
105
+ ### 2. Change Set Propagation
106
+
107
+ ```typescript
108
+ LocalNode → [Sign] → ChangeSet → TrustedNode → [Validation] → GlobalState
109
+ ```
110
+
111
+ ### 3. Global State Persistence
112
+
113
+ ```typescript
114
+ TrustedNode → [Sign & Compression] → DecentralisedStorage → [StateRoot] → VerifiableStorage
115
+ ```
116
+
117
+ ### 4. Remote Synchronisation
118
+
119
+ ```typescript
120
+ AnyNode → [Poll] → VerifiableStorage → [Fetch] → DecentralisedStorage → [Merge] → LocalState
121
+ ```
122
+
123
+ ## Data Structures
124
+
125
+ - ChangeSet - contains a set of changes that a regular node will send to a trusted node - will contain a proof generated by the identity of the regular node
package/docs/changelog.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.1-next.4](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-service-v0.0.1-next.3...synchronised-storage-service-v0.0.1-next.4) (2025-08-08)
4
+
5
+
6
+ ### Features
7
+
8
+ * add payload versioning ([3bbbce0](https://github.com/twinfoundation/synchronised-storage/commit/3bbbce0bdf24bbe67c1a265704538d505d7feb91))
9
+ * blob storage connector instead of component ([#7](https://github.com/twinfoundation/synchronised-storage/issues/7)) ([ea27241](https://github.com/twinfoundation/synchronised-storage/commit/ea27241cf0810b52ab7a6be7346809d127b7109a))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * The following workspace dependencies were updated
15
+ * dependencies
16
+ * @twin.org/synchronised-storage-models bumped from 0.0.1-next.3 to 0.0.1-next.4
17
+
3
18
  ## [0.0.1-next.3](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-service-v0.0.1-next.2...synchronised-storage-service-v0.0.1-next.3) (2025-07-25)
4
19
 
5
20