@twin.org/synchronised-storage-rest-client 0.0.1-next.9 → 0.0.3-next.2
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.
- package/dist/es/index.js +4 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/synchronisedStorageRestClient.js +58 -0
- package/dist/es/synchronisedStorageRestClient.js.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/{synchronisedStorageClient.d.ts → synchronisedStorageRestClient.d.ts} +12 -8
- package/docs/changelog.md +133 -0
- package/docs/reference/classes/{SynchronisedStorageClient.md → SynchronisedStorageRestClient.md} +32 -18
- package/docs/reference/index.md +1 -1
- package/package.json +22 -9
- package/dist/cjs/index.cjs +0 -59
- package/dist/esm/index.mjs +0 -57
package/dist/es/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,oCAAoC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./synchronisedStorageRestClient.js\";\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { BaseRestClient } from "@twin.org/api-core";
|
|
4
|
+
import { Guards } from "@twin.org/core";
|
|
5
|
+
import { HeaderHelper, HeaderTypes } from "@twin.org/web";
|
|
6
|
+
/**
|
|
7
|
+
* Client for performing synchronised storage through to REST endpoints.
|
|
8
|
+
*/
|
|
9
|
+
export class SynchronisedStorageRestClient extends BaseRestClient {
|
|
10
|
+
/**
|
|
11
|
+
* Runtime name for the class.
|
|
12
|
+
*/
|
|
13
|
+
static CLASS_NAME = "SynchronisedStorageRestClient";
|
|
14
|
+
/**
|
|
15
|
+
* Create a new instance of SynchronisedStorageRestClient.
|
|
16
|
+
* @param config The configuration for the client.
|
|
17
|
+
*/
|
|
18
|
+
constructor(config) {
|
|
19
|
+
super(SynchronisedStorageRestClient.CLASS_NAME, config, "synchronised-storage");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns the class name of the component.
|
|
23
|
+
* @returns The class name of the component.
|
|
24
|
+
*/
|
|
25
|
+
className() {
|
|
26
|
+
return SynchronisedStorageRestClient.CLASS_NAME;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the decryption key for the synchronised storage.
|
|
30
|
+
* This is used to decrypt the data stored in the synchronised storage.
|
|
31
|
+
* @param trustPayload Trust payload to verify the requesters identity.
|
|
32
|
+
* @returns The decryption key.
|
|
33
|
+
*/
|
|
34
|
+
async getDecryptionKey(trustPayload) {
|
|
35
|
+
const response = await this.fetch("/decryption-key", "GET", {
|
|
36
|
+
headers: {
|
|
37
|
+
[HeaderTypes.Authorization]: HeaderHelper.createBearer(trustPayload)
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return response.body.decryptionKey;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Synchronise a set of changes from an untrusted node, assumes this is a trusted node.
|
|
44
|
+
* @param syncChangeSet The change set to synchronise.
|
|
45
|
+
* @param trustPayload Trust payload to verify the requesters identity.
|
|
46
|
+
* @returns Nothing.
|
|
47
|
+
*/
|
|
48
|
+
async syncChangeSet(syncChangeSet, trustPayload) {
|
|
49
|
+
Guards.object(SynchronisedStorageRestClient.CLASS_NAME, "syncChangeSet", syncChangeSet);
|
|
50
|
+
await this.fetch("/sync-changeset", "POST", {
|
|
51
|
+
headers: {
|
|
52
|
+
[HeaderTypes.Authorization]: HeaderHelper.createBearer(trustPayload)
|
|
53
|
+
},
|
|
54
|
+
body: syncChangeSet
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=synchronisedStorageRestClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synchronisedStorageRestClient.js","sourceRoot":"","sources":["../../src/synchronisedStorageRestClient.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AASxC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,6BACZ,SAAQ,cAAc;IAGtB;;OAEG;IACI,MAAM,CAAU,UAAU,mCAAmD;IAEpF;;;OAGG;IACH,YAAY,MAA6B;QACxC,KAAK,CAAC,6BAA6B,CAAC,UAAU,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC;IACjF,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,6BAA6B,CAAC,UAAU,CAAC;IACjD,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,gBAAgB,CAAC,YAAqB;QAClD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAChC,iBAAiB,EACjB,KAAK,EACL;YACC,OAAO,EAAE;gBACR,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,YAAY,CAAC;aACpE;SACD,CACD,CAAC;QAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,aAAa,CAAC,aAA6B,EAAE,YAAqB;QAC9E,MAAM,CAAC,MAAM,CACZ,6BAA6B,CAAC,UAAU,mBAExC,aAAa,CACb,CAAC;QAEF,MAAM,IAAI,CAAC,KAAK,CAA4C,iBAAiB,EAAE,MAAM,EAAE;YACtF,OAAO,EAAE;gBACR,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,YAAY,CAAC;aACpE;YACD,IAAI,EAAE,aAAa;SACnB,CAAC,CAAC;IACJ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { BaseRestClient } from \"@twin.org/api-core\";\nimport type { IBaseRestClientConfig, INoContentResponse } from \"@twin.org/api-models\";\nimport { Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type {\n\tISyncChangeSet,\n\tISyncChangeSetRequest,\n\tISyncDecryptionKeyRequest,\n\tISyncDecryptionKeyResponse,\n\tISynchronisedStorageComponent\n} from \"@twin.org/synchronised-storage-models\";\nimport { HeaderHelper, HeaderTypes } from \"@twin.org/web\";\n\n/**\n * Client for performing synchronised storage through to REST endpoints.\n */\nexport class SynchronisedStorageRestClient\n\textends BaseRestClient\n\timplements ISynchronisedStorageComponent\n{\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<SynchronisedStorageRestClient>();\n\n\t/**\n\t * Create a new instance of SynchronisedStorageRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(SynchronisedStorageRestClient.CLASS_NAME, config, \"synchronised-storage\");\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn SynchronisedStorageRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Get the decryption key for the synchronised storage.\n\t * This is used to decrypt the data stored in the synchronised storage.\n\t * @param trustPayload Trust payload to verify the requesters identity.\n\t * @returns The decryption key.\n\t */\n\tpublic async getDecryptionKey(trustPayload: unknown): Promise<string> {\n\t\tconst response = await this.fetch<ISyncDecryptionKeyRequest, ISyncDecryptionKeyResponse>(\n\t\t\t\"/decryption-key\",\n\t\t\t\"GET\",\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Authorization]: HeaderHelper.createBearer(trustPayload)\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.body.decryptionKey;\n\t}\n\n\t/**\n\t * Synchronise a set of changes from an untrusted node, assumes this is a trusted node.\n\t * @param syncChangeSet The change set to synchronise.\n\t * @param trustPayload Trust payload to verify the requesters identity.\n\t * @returns Nothing.\n\t */\n\tpublic async syncChangeSet(syncChangeSet: ISyncChangeSet, trustPayload: unknown): Promise<void> {\n\t\tGuards.object<ISyncChangeSet>(\n\t\t\tSynchronisedStorageRestClient.CLASS_NAME,\n\t\t\tnameof(syncChangeSet),\n\t\t\tsyncChangeSet\n\t\t);\n\n\t\tawait this.fetch<ISyncChangeSetRequest, INoContentResponse>(\"/sync-changeset\", \"POST\", {\n\t\t\theaders: {\n\t\t\t\t[HeaderTypes.Authorization]: HeaderHelper.createBearer(trustPayload)\n\t\t\t},\n\t\t\tbody: syncChangeSet\n\t\t});\n\t}\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./synchronisedStorageRestClient.js";
|
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
import { BaseRestClient } from "@twin.org/api-core";
|
|
2
2
|
import type { IBaseRestClientConfig } from "@twin.org/api-models";
|
|
3
|
-
import type { IProof } from "@twin.org/standards-w3c-did";
|
|
4
3
|
import type { ISyncChangeSet, ISynchronisedStorageComponent } from "@twin.org/synchronised-storage-models";
|
|
5
4
|
/**
|
|
6
5
|
* Client for performing synchronised storage through to REST endpoints.
|
|
7
6
|
*/
|
|
8
|
-
export declare class
|
|
7
|
+
export declare class SynchronisedStorageRestClient extends BaseRestClient implements ISynchronisedStorageComponent {
|
|
9
8
|
/**
|
|
10
9
|
* Runtime name for the class.
|
|
11
10
|
*/
|
|
12
|
-
readonly CLASS_NAME: string;
|
|
11
|
+
static readonly CLASS_NAME: string;
|
|
13
12
|
/**
|
|
14
|
-
* Create a new instance of
|
|
13
|
+
* Create a new instance of SynchronisedStorageRestClient.
|
|
15
14
|
* @param config The configuration for the client.
|
|
16
15
|
*/
|
|
17
16
|
constructor(config: IBaseRestClientConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Returns the class name of the component.
|
|
19
|
+
* @returns The class name of the component.
|
|
20
|
+
*/
|
|
21
|
+
className(): string;
|
|
18
22
|
/**
|
|
19
23
|
* Get the decryption key for the synchronised storage.
|
|
20
24
|
* This is used to decrypt the data stored in the synchronised storage.
|
|
21
|
-
* @param
|
|
22
|
-
* @param proof The proof of the request so we know the request is from the specified node.
|
|
25
|
+
* @param trustPayload Trust payload to verify the requesters identity.
|
|
23
26
|
* @returns The decryption key.
|
|
24
27
|
*/
|
|
25
|
-
getDecryptionKey(
|
|
28
|
+
getDecryptionKey(trustPayload: unknown): Promise<string>;
|
|
26
29
|
/**
|
|
27
30
|
* Synchronise a set of changes from an untrusted node, assumes this is a trusted node.
|
|
28
31
|
* @param syncChangeSet The change set to synchronise.
|
|
32
|
+
* @param trustPayload Trust payload to verify the requesters identity.
|
|
29
33
|
* @returns Nothing.
|
|
30
34
|
*/
|
|
31
|
-
syncChangeSet(syncChangeSet: ISyncChangeSet): Promise<void>;
|
|
35
|
+
syncChangeSet(syncChangeSet: ISyncChangeSet, trustPayload: unknown): Promise<void>;
|
|
32
36
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,138 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.2](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.3-next.1...synchronised-storage-rest-client-v0.0.3-next.2) (2025-12-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* use trust component ([424f0d6](https://github.com/twinfoundation/synchronised-storage/commit/424f0d6aaacfdc7700c46fe6c2def23b2eacddc9))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/synchronised-storage-models bumped from 0.0.3-next.1 to 0.0.3-next.2
|
|
16
|
+
|
|
17
|
+
## [0.0.3-next.1](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.3-next.0...synchronised-storage-rest-client-v0.0.3-next.1) (2025-11-12)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* add context id features ([#24](https://github.com/twinfoundation/synchronised-storage/issues/24)) ([5266b18](https://github.com/twinfoundation/synchronised-storage/commit/5266b18088317c7dc274a209a79102a6fc88a8e4))
|
|
23
|
+
* add rights management integration ([d003d33](https://github.com/twinfoundation/synchronised-storage/commit/d003d33d2d2b4a4aa1379071eed71a707ebcb4de))
|
|
24
|
+
* add validate-locales ([e3d7b98](https://github.com/twinfoundation/synchronised-storage/commit/e3d7b98839e9ca624855717c8957d572c4e09abf))
|
|
25
|
+
* blob storage connector instead of component ([#7](https://github.com/twinfoundation/synchronised-storage/issues/7)) ([ea27241](https://github.com/twinfoundation/synchronised-storage/commit/ea27241cf0810b52ab7a6be7346809d127b7109a))
|
|
26
|
+
* eslint migration to flat config ([f601c14](https://github.com/twinfoundation/synchronised-storage/commit/f601c14f6adef3290554dc7df6e6b3528aa0dc2b))
|
|
27
|
+
* initial commit ([16949b8](https://github.com/twinfoundation/synchronised-storage/commit/16949b8e5bdb190f053c52af352290e3fd964f9a))
|
|
28
|
+
* update framework core ([99f09cc](https://github.com/twinfoundation/synchronised-storage/commit/99f09cc94cfb9fff6b3a345775eeae2ab3192ed2))
|
|
29
|
+
* update to in built vc auth mechanism ([411a371](https://github.com/twinfoundation/synchronised-storage/commit/411a3716830195ebf54755a1633b05d5c3f96754))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Dependencies
|
|
33
|
+
|
|
34
|
+
* The following workspace dependencies were updated
|
|
35
|
+
* dependencies
|
|
36
|
+
* @twin.org/synchronised-storage-models bumped from 0.0.3-next.0 to 0.0.3-next.1
|
|
37
|
+
|
|
38
|
+
## [0.0.1-next.16](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.1-next.15...synchronised-storage-rest-client-v0.0.1-next.16) (2025-10-09)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Features
|
|
42
|
+
|
|
43
|
+
* add validate-locales ([e3d7b98](https://github.com/twinfoundation/synchronised-storage/commit/e3d7b98839e9ca624855717c8957d572c4e09abf))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Dependencies
|
|
47
|
+
|
|
48
|
+
* The following workspace dependencies were updated
|
|
49
|
+
* dependencies
|
|
50
|
+
* @twin.org/synchronised-storage-models bumped from 0.0.1-next.15 to 0.0.1-next.16
|
|
51
|
+
|
|
52
|
+
## [0.0.1-next.15](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.1-next.14...synchronised-storage-rest-client-v0.0.1-next.15) (2025-09-23)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Features
|
|
56
|
+
|
|
57
|
+
* update to in built vc auth mechanism ([411a371](https://github.com/twinfoundation/synchronised-storage/commit/411a3716830195ebf54755a1633b05d5c3f96754))
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### Dependencies
|
|
61
|
+
|
|
62
|
+
* The following workspace dependencies were updated
|
|
63
|
+
* dependencies
|
|
64
|
+
* @twin.org/synchronised-storage-models bumped from 0.0.1-next.14 to 0.0.1-next.15
|
|
65
|
+
|
|
66
|
+
## [0.0.1-next.14](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.1-next.13...synchronised-storage-rest-client-v0.0.1-next.14) (2025-09-22)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
### Features
|
|
70
|
+
|
|
71
|
+
* add rights management integration ([d003d33](https://github.com/twinfoundation/synchronised-storage/commit/d003d33d2d2b4a4aa1379071eed71a707ebcb4de))
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
### Dependencies
|
|
75
|
+
|
|
76
|
+
* The following workspace dependencies were updated
|
|
77
|
+
* dependencies
|
|
78
|
+
* @twin.org/synchronised-storage-models bumped from 0.0.1-next.13 to 0.0.1-next.14
|
|
79
|
+
|
|
80
|
+
## [0.0.1-next.13](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.1-next.12...synchronised-storage-rest-client-v0.0.1-next.13) (2025-08-29)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### Features
|
|
84
|
+
|
|
85
|
+
* eslint migration to flat config ([f601c14](https://github.com/twinfoundation/synchronised-storage/commit/f601c14f6adef3290554dc7df6e6b3528aa0dc2b))
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
### Dependencies
|
|
89
|
+
|
|
90
|
+
* The following workspace dependencies were updated
|
|
91
|
+
* dependencies
|
|
92
|
+
* @twin.org/synchronised-storage-models bumped from 0.0.1-next.12 to 0.0.1-next.13
|
|
93
|
+
|
|
94
|
+
## [0.0.1-next.12](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.1-next.11...synchronised-storage-rest-client-v0.0.1-next.12) (2025-08-21)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
### Features
|
|
98
|
+
|
|
99
|
+
* update framework core ([99f09cc](https://github.com/twinfoundation/synchronised-storage/commit/99f09cc94cfb9fff6b3a345775eeae2ab3192ed2))
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
### Dependencies
|
|
103
|
+
|
|
104
|
+
* The following workspace dependencies were updated
|
|
105
|
+
* dependencies
|
|
106
|
+
* @twin.org/synchronised-storage-models bumped from 0.0.1-next.11 to 0.0.1-next.12
|
|
107
|
+
|
|
108
|
+
## [0.0.1-next.11](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.1-next.10...synchronised-storage-rest-client-v0.0.1-next.11) (2025-08-15)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
### Miscellaneous Chores
|
|
112
|
+
|
|
113
|
+
* **synchronised-storage-rest-client:** Synchronize repo versions
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
### Dependencies
|
|
117
|
+
|
|
118
|
+
* The following workspace dependencies were updated
|
|
119
|
+
* dependencies
|
|
120
|
+
* @twin.org/synchronised-storage-models bumped from 0.0.1-next.10 to 0.0.1-next.11
|
|
121
|
+
|
|
122
|
+
## [0.0.1-next.10](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.1-next.9...synchronised-storage-rest-client-v0.0.1-next.10) (2025-08-15)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
### Miscellaneous Chores
|
|
126
|
+
|
|
127
|
+
* **synchronised-storage-rest-client:** Synchronize repo versions
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
### Dependencies
|
|
131
|
+
|
|
132
|
+
* The following workspace dependencies were updated
|
|
133
|
+
* dependencies
|
|
134
|
+
* @twin.org/synchronised-storage-models bumped from 0.0.1-next.9 to 0.0.1-next.10
|
|
135
|
+
|
|
3
136
|
## [0.0.1-next.9](https://github.com/twinfoundation/synchronised-storage/compare/synchronised-storage-rest-client-v0.0.1-next.8...synchronised-storage-rest-client-v0.0.1-next.9) (2025-08-13)
|
|
4
137
|
|
|
5
138
|
|
package/docs/reference/classes/{SynchronisedStorageClient.md → SynchronisedStorageRestClient.md}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Class:
|
|
1
|
+
# Class: SynchronisedStorageRestClient
|
|
2
2
|
|
|
3
3
|
Client for performing synchronised storage through to REST endpoints.
|
|
4
4
|
|
|
@@ -14,9 +14,9 @@ Client for performing synchronised storage through to REST endpoints.
|
|
|
14
14
|
|
|
15
15
|
### Constructor
|
|
16
16
|
|
|
17
|
-
> **new
|
|
17
|
+
> **new SynchronisedStorageRestClient**(`config`): `SynchronisedStorageRestClient`
|
|
18
18
|
|
|
19
|
-
Create a new instance of
|
|
19
|
+
Create a new instance of SynchronisedStorageRestClient.
|
|
20
20
|
|
|
21
21
|
#### Parameters
|
|
22
22
|
|
|
@@ -28,7 +28,7 @@ The configuration for the client.
|
|
|
28
28
|
|
|
29
29
|
#### Returns
|
|
30
30
|
|
|
31
|
-
`
|
|
31
|
+
`SynchronisedStorageRestClient`
|
|
32
32
|
|
|
33
33
|
#### Overrides
|
|
34
34
|
|
|
@@ -38,36 +38,44 @@ The configuration for the client.
|
|
|
38
38
|
|
|
39
39
|
### CLASS\_NAME
|
|
40
40
|
|
|
41
|
-
> `readonly` **CLASS\_NAME**: `string`
|
|
41
|
+
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
42
42
|
|
|
43
43
|
Runtime name for the class.
|
|
44
44
|
|
|
45
|
+
## Methods
|
|
46
|
+
|
|
47
|
+
### className()
|
|
48
|
+
|
|
49
|
+
> **className**(): `string`
|
|
50
|
+
|
|
51
|
+
Returns the class name of the component.
|
|
52
|
+
|
|
53
|
+
#### Returns
|
|
54
|
+
|
|
55
|
+
`string`
|
|
56
|
+
|
|
57
|
+
The class name of the component.
|
|
58
|
+
|
|
45
59
|
#### Implementation of
|
|
46
60
|
|
|
47
|
-
`ISynchronisedStorageComponent.
|
|
61
|
+
`ISynchronisedStorageComponent.className`
|
|
48
62
|
|
|
49
|
-
|
|
63
|
+
***
|
|
50
64
|
|
|
51
65
|
### getDecryptionKey()
|
|
52
66
|
|
|
53
|
-
> **getDecryptionKey**(`
|
|
67
|
+
> **getDecryptionKey**(`trustPayload`): `Promise`\<`string`\>
|
|
54
68
|
|
|
55
69
|
Get the decryption key for the synchronised storage.
|
|
56
70
|
This is used to decrypt the data stored in the synchronised storage.
|
|
57
71
|
|
|
58
72
|
#### Parameters
|
|
59
73
|
|
|
60
|
-
#####
|
|
61
|
-
|
|
62
|
-
`string`
|
|
63
|
-
|
|
64
|
-
The identity of the node requesting the decryption key.
|
|
74
|
+
##### trustPayload
|
|
65
75
|
|
|
66
|
-
|
|
76
|
+
`unknown`
|
|
67
77
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
The proof of the request so we know the request is from the specified node.
|
|
78
|
+
Trust payload to verify the requesters identity.
|
|
71
79
|
|
|
72
80
|
#### Returns
|
|
73
81
|
|
|
@@ -83,7 +91,7 @@ The decryption key.
|
|
|
83
91
|
|
|
84
92
|
### syncChangeSet()
|
|
85
93
|
|
|
86
|
-
> **syncChangeSet**(`syncChangeSet`): `Promise`\<`void`\>
|
|
94
|
+
> **syncChangeSet**(`syncChangeSet`, `trustPayload`): `Promise`\<`void`\>
|
|
87
95
|
|
|
88
96
|
Synchronise a set of changes from an untrusted node, assumes this is a trusted node.
|
|
89
97
|
|
|
@@ -95,6 +103,12 @@ Synchronise a set of changes from an untrusted node, assumes this is a trusted n
|
|
|
95
103
|
|
|
96
104
|
The change set to synchronise.
|
|
97
105
|
|
|
106
|
+
##### trustPayload
|
|
107
|
+
|
|
108
|
+
`unknown`
|
|
109
|
+
|
|
110
|
+
Trust payload to verify the requesters identity.
|
|
111
|
+
|
|
98
112
|
#### Returns
|
|
99
113
|
|
|
100
114
|
`Promise`\<`void`\>
|
package/docs/reference/index.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/synchronised-storage-rest-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-next.2",
|
|
4
4
|
"description": "Synchronised storage contract implementation which can connect to REST endpoints",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,28 +16,41 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@twin.org/api-core": "next",
|
|
18
18
|
"@twin.org/api-models": "next",
|
|
19
|
+
"@twin.org/context": "next",
|
|
19
20
|
"@twin.org/core": "next",
|
|
20
21
|
"@twin.org/entity": "next",
|
|
22
|
+
"@twin.org/identity-authentication": "next",
|
|
21
23
|
"@twin.org/nameof": "next",
|
|
22
24
|
"@twin.org/standards-w3c-did": "next",
|
|
23
|
-
"@twin.org/synchronised-storage-models": "0.0.
|
|
25
|
+
"@twin.org/synchronised-storage-models": "0.0.3-next.2",
|
|
26
|
+
"@twin.org/web": "next"
|
|
24
27
|
},
|
|
25
|
-
"main": "./dist/
|
|
26
|
-
"module": "./dist/esm/index.mjs",
|
|
28
|
+
"main": "./dist/es/index.js",
|
|
27
29
|
"types": "./dist/types/index.d.ts",
|
|
28
30
|
"exports": {
|
|
29
31
|
".": {
|
|
30
32
|
"types": "./dist/types/index.d.ts",
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
+
"import": "./dist/es/index.js",
|
|
34
|
+
"default": "./dist/es/index.js"
|
|
33
35
|
},
|
|
34
36
|
"./locales/*.json": "./locales/*.json"
|
|
35
37
|
},
|
|
36
38
|
"files": [
|
|
37
|
-
"dist/
|
|
38
|
-
"dist/esm",
|
|
39
|
+
"dist/es",
|
|
39
40
|
"dist/types",
|
|
40
41
|
"locales",
|
|
41
42
|
"docs"
|
|
42
|
-
]
|
|
43
|
+
],
|
|
44
|
+
"keywords": [
|
|
45
|
+
"twin",
|
|
46
|
+
"trade",
|
|
47
|
+
"iota",
|
|
48
|
+
"framework",
|
|
49
|
+
"blockchain",
|
|
50
|
+
"synchronised-storage"
|
|
51
|
+
],
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "git+https://github.com/twinfoundation/synchronised-storage/issues"
|
|
54
|
+
},
|
|
55
|
+
"homepage": "https://twindev.org"
|
|
43
56
|
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var apiCore = require('@twin.org/api-core');
|
|
4
|
-
var core = require('@twin.org/core');
|
|
5
|
-
|
|
6
|
-
// Copyright 2024 IOTA Stiftung.
|
|
7
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
8
|
-
/**
|
|
9
|
-
* Client for performing synchronised storage through to REST endpoints.
|
|
10
|
-
*/
|
|
11
|
-
class SynchronisedStorageClient extends apiCore.BaseRestClient {
|
|
12
|
-
/**
|
|
13
|
-
* Runtime name for the class.
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
static _CLASS_NAME = "SynchronisedStorageClient";
|
|
17
|
-
/**
|
|
18
|
-
* Runtime name for the class.
|
|
19
|
-
*/
|
|
20
|
-
CLASS_NAME = SynchronisedStorageClient._CLASS_NAME;
|
|
21
|
-
/**
|
|
22
|
-
* Create a new instance of SynchronisedStorageClient.
|
|
23
|
-
* @param config The configuration for the client.
|
|
24
|
-
*/
|
|
25
|
-
constructor(config) {
|
|
26
|
-
super(SynchronisedStorageClient._CLASS_NAME, config, "synchronised-storage");
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Get the decryption key for the synchronised storage.
|
|
30
|
-
* This is used to decrypt the data stored in the synchronised storage.
|
|
31
|
-
* @param nodeIdentity The identity of the node requesting the decryption key.
|
|
32
|
-
* @param proof The proof of the request so we know the request is from the specified node.
|
|
33
|
-
* @returns The decryption key.
|
|
34
|
-
*/
|
|
35
|
-
async getDecryptionKey(nodeIdentity, proof) {
|
|
36
|
-
core.Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
|
37
|
-
core.Guards.object(this.CLASS_NAME, "proof", proof);
|
|
38
|
-
const response = await this.fetch("/decryption-key", "POST", {
|
|
39
|
-
body: {
|
|
40
|
-
nodeIdentity,
|
|
41
|
-
proof
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
return response.body.decryptionKey;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Synchronise a set of changes from an untrusted node, assumes this is a trusted node.
|
|
48
|
-
* @param syncChangeSet The change set to synchronise.
|
|
49
|
-
* @returns Nothing.
|
|
50
|
-
*/
|
|
51
|
-
async syncChangeSet(syncChangeSet) {
|
|
52
|
-
core.Guards.object(this.CLASS_NAME, "syncChangeSet", syncChangeSet);
|
|
53
|
-
await this.fetch("/sync-changeset", "POST", {
|
|
54
|
-
body: syncChangeSet
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
exports.SynchronisedStorageClient = SynchronisedStorageClient;
|
package/dist/esm/index.mjs
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { BaseRestClient } from '@twin.org/api-core';
|
|
2
|
-
import { Guards } from '@twin.org/core';
|
|
3
|
-
|
|
4
|
-
// Copyright 2024 IOTA Stiftung.
|
|
5
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
6
|
-
/**
|
|
7
|
-
* Client for performing synchronised storage through to REST endpoints.
|
|
8
|
-
*/
|
|
9
|
-
class SynchronisedStorageClient extends BaseRestClient {
|
|
10
|
-
/**
|
|
11
|
-
* Runtime name for the class.
|
|
12
|
-
* @internal
|
|
13
|
-
*/
|
|
14
|
-
static _CLASS_NAME = "SynchronisedStorageClient";
|
|
15
|
-
/**
|
|
16
|
-
* Runtime name for the class.
|
|
17
|
-
*/
|
|
18
|
-
CLASS_NAME = SynchronisedStorageClient._CLASS_NAME;
|
|
19
|
-
/**
|
|
20
|
-
* Create a new instance of SynchronisedStorageClient.
|
|
21
|
-
* @param config The configuration for the client.
|
|
22
|
-
*/
|
|
23
|
-
constructor(config) {
|
|
24
|
-
super(SynchronisedStorageClient._CLASS_NAME, config, "synchronised-storage");
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Get the decryption key for the synchronised storage.
|
|
28
|
-
* This is used to decrypt the data stored in the synchronised storage.
|
|
29
|
-
* @param nodeIdentity The identity of the node requesting the decryption key.
|
|
30
|
-
* @param proof The proof of the request so we know the request is from the specified node.
|
|
31
|
-
* @returns The decryption key.
|
|
32
|
-
*/
|
|
33
|
-
async getDecryptionKey(nodeIdentity, proof) {
|
|
34
|
-
Guards.stringValue(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
|
35
|
-
Guards.object(this.CLASS_NAME, "proof", proof);
|
|
36
|
-
const response = await this.fetch("/decryption-key", "POST", {
|
|
37
|
-
body: {
|
|
38
|
-
nodeIdentity,
|
|
39
|
-
proof
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
return response.body.decryptionKey;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Synchronise a set of changes from an untrusted node, assumes this is a trusted node.
|
|
46
|
-
* @param syncChangeSet The change set to synchronise.
|
|
47
|
-
* @returns Nothing.
|
|
48
|
-
*/
|
|
49
|
-
async syncChangeSet(syncChangeSet) {
|
|
50
|
-
Guards.object(this.CLASS_NAME, "syncChangeSet", syncChangeSet);
|
|
51
|
-
await this.fetch("/sync-changeset", "POST", {
|
|
52
|
-
body: syncChangeSet
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { SynchronisedStorageClient };
|