@twin.org/verifiable-storage-service 0.0.3-next.8 → 0.9.0-next.1
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/README.md +3 -1
- package/dist/es/models/IVerifiableStorageServiceConfig.js.map +1 -1
- package/dist/es/restEntryPoints.js +3 -0
- package/dist/es/restEntryPoints.js.map +1 -1
- package/dist/es/verifiableStorageRoutes.js +2 -2
- package/dist/es/verifiableStorageRoutes.js.map +1 -1
- package/dist/es/verifiableStorageService.js +6 -4
- package/dist/es/verifiableStorageService.js.map +1 -1
- package/dist/types/models/IVerifiableStorageServiceConfig.d.ts +1 -1
- package/dist/types/restEntryPoints.d.ts +3 -0
- package/dist/types/verifiableStorageRoutes.d.ts +2 -2
- package/dist/types/verifiableStorageService.d.ts +5 -4
- package/docs/changelog.md +204 -89
- package/docs/examples.md +29 -1
- package/docs/open-api/spec.json +8 -926
- package/docs/reference/classes/VerifiableStorageService.md +14 -10
- package/docs/reference/functions/verifiableStorageGet.md +1 -1
- package/docs/reference/functions/verifiableStorageUpdate.md +1 -1
- package/docs/reference/interfaces/IVerifiableStorageServiceConfig.md +3 -3
- package/docs/reference/interfaces/IVerifiableStorageServiceConstructorOptions.md +2 -2
- package/docs/reference/variables/restEntryPoints.md +2 -0
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# TWIN Verifiable Storage Service
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package provides the service layer for verifiable storage, exposing component logic and REST route definitions that can be mounted in API applications. It translates storage operations into a consistent service interface for upstream consumers.
|
|
4
|
+
|
|
5
|
+
The package is useful when you need to host verifiable storage capabilities behind HTTP endpoints while retaining the same contracts used by connectors and clients.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IVerifiableStorageServiceConfig.js","sourceRoot":"","sources":["../../../src/models/IVerifiableStorageServiceConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the Verifiable Storage Service.\n */\nexport interface IVerifiableStorageServiceConfig {\n\t/**\n\t *
|
|
1
|
+
{"version":3,"file":"IVerifiableStorageServiceConfig.js","sourceRoot":"","sources":["../../../src/models/IVerifiableStorageServiceConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the Verifiable Storage Service.\n */\nexport interface IVerifiableStorageServiceConfig {\n\t/**\n\t * The default connector namespace to use; falls back to the first registered connector if not provided.\n\t */\n\tdefaultNamespace?: string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restEntryPoints.js","sourceRoot":"","sources":["../../src/restEntryPoints.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,mCAAmC,EACnC,qBAAqB,EACrB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,CAAC,MAAM,eAAe,GAA2B;IACtD;QACC,IAAI,EAAE,YAAY;QAClB,gBAAgB,EAAE,YAAY;QAC9B,IAAI,EAAE,qBAAqB;QAC3B,cAAc,EAAE,mCAAmC;KACnD;CACD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IRestRouteEntryPoint } from \"@twin.org/api-models\";\nimport {\n\tgenerateRestRoutesVerifiableStorage,\n\ttagsVerifiableStorage\n} from \"./verifiableStorageRoutes.js\";\n\nexport const restEntryPoints: IRestRouteEntryPoint[] = [\n\t{\n\t\tname: \"verifiable\",\n\t\tdefaultBaseRoute: \"verifiable\",\n\t\ttags: tagsVerifiableStorage,\n\t\tgenerateRoutes: generateRestRoutesVerifiableStorage\n\t}\n];\n"]}
|
|
1
|
+
{"version":3,"file":"restEntryPoints.js","sourceRoot":"","sources":["../../src/restEntryPoints.ts"],"names":[],"mappings":"AAGA,OAAO,EACN,mCAAmC,EACnC,qBAAqB,EACrB,MAAM,8BAA8B,CAAC;AAEtC;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAA2B;IACtD;QACC,IAAI,EAAE,YAAY;QAClB,gBAAgB,EAAE,YAAY;QAC9B,IAAI,EAAE,qBAAqB;QAC3B,cAAc,EAAE,mCAAmC;KACnD;CACD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IRestRouteEntryPoint } from \"@twin.org/api-models\";\nimport {\n\tgenerateRestRoutesVerifiableStorage,\n\ttagsVerifiableStorage\n} from \"./verifiableStorageRoutes.js\";\n\n/**\n * The REST entry points for the verifiable storage service.\n */\nexport const restEntryPoints: IRestRouteEntryPoint[] = [\n\t{\n\t\tname: \"verifiable\",\n\t\tdefaultBaseRoute: \"verifiable\",\n\t\ttags: tagsVerifiableStorage,\n\t\tgenerateRoutes: generateRestRoutesVerifiableStorage\n\t}\n];\n"]}
|
|
@@ -204,7 +204,7 @@ export async function verifiableStorageCreate(httpRequestContext, componentName,
|
|
|
204
204
|
};
|
|
205
205
|
}
|
|
206
206
|
/**
|
|
207
|
-
*
|
|
207
|
+
* Update a verifiable storage item.
|
|
208
208
|
* @param httpRequestContext The request context for the API.
|
|
209
209
|
* @param componentName The name of the component to use in the routes.
|
|
210
210
|
* @param request The request.
|
|
@@ -225,7 +225,7 @@ export async function verifiableStorageUpdate(httpRequestContext, componentName,
|
|
|
225
225
|
};
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
228
|
-
* Get
|
|
228
|
+
* Get a verifiable storage item.
|
|
229
229
|
* @param componentName The name of the component to use in the routes.
|
|
230
230
|
* @param request The request.
|
|
231
231
|
* @returns The response object with additional http response properties.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifiableStorageRoutes.js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identifier: Apache-2.0.\nimport type {\n\tIHttpRequestContext,\n\tINoContentResponse,\n\tIRestRoute,\n\tITag\n} from \"@twin.org/api-models\";\nimport { ContextIdHelper, ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { ComponentFactory, Converter, Guards, Is } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type {\n\tIVerifiableStorageComponent,\n\tIVerifiableStorageCreateRequest,\n\tIVerifiableStorageCreateResponse,\n\tIVerifiableStorageGetRequest,\n\tIVerifiableStorageGetResponse,\n\tIVerifiableStorageRemoveRequest,\n\tIVerifiableStorageUpdateRequest,\n\tIVerifiableStorageUpdateResponse\n} from \"@twin.org/verifiable-storage-models\";\nimport { HeaderTypes, HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"verifiableStorageRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsVerifiableStorage: ITag[] = [\n\t{\n\t\tname: \"VerifiableStorage\",\n\t\tdescription: \"Endpoints which are modelled to access a verifiable storage.\"\n\t}\n];\n\n/**\n * The REST routes for VerifiableStorage.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesVerifiableStorage(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createRoute: IRestRoute<IVerifiableStorageCreateRequest, IVerifiableStorageCreateResponse> =\n\t\t{\n\t\t\toperationId: \"verifiableStorageCreate\",\n\t\t\tsummary: \"Create an item in verifiable storage\",\n\t\t\ttag: tagsVerifiableStorage[0].name,\n\t\t\tmethod: \"POST\",\n\t\t\tpath: `${baseRouteName}/`,\n\t\t\thandler: async (httpRequestContext, request) =>\n\t\t\t\tverifiableStorageCreate(httpRequestContext, componentName, request),\n\t\t\trequestType: {\n\t\t\t\ttype: nameof<IVerifiableStorageCreateRequest>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"verifiableStorageCreateRequestExample\",\n\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tdata: \"SGVsbG8gd29ybGQ=\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\tresponseType: [\n\t\t\t\t{\n\t\t\t\t\ttype: nameof<IVerifiableStorageCreateResponse>(),\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"verifiableStorageCreateResponseExample\",\n\t\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\t\tstatusCode: HttpStatusCode.created,\n\t\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t\t[HeaderTypes.Location]:\n\t\t\t\t\t\t\t\t\t\t\"verifiable:iota:aW90YS1uZnQ6dHN0OjB4NzYyYjljNDllYTg2OWUwZWJkYTliYmZhNzY5Mzk0NDdhNDI4ZGNmMTc4YzVkMTVhYjQ0N2UyZDRmYmJiNGViMg==\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\treceipt: {\n\t\t\t\t\t\t\t\t\t\t\"@context\": \"https://schema.twindev.org/verifiable-storage/\",\n\t\t\t\t\t\t\t\t\t\ttype: \"VerifiableStorageIotaReceipt2026\"\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tid: \"verifiable:iota:aW90YS1uZnQ6dHN0OjB4NzYyYjljNDllYTg2OWUwZWJkYTliYmZhNzY5Mzk0NDdhNDI4ZGNmMTc4YzVkMTVhYjQ0N2UyZDRmYmJiNGViMg==\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t]\n\t\t};\n\n\tconst updateRoute: IRestRoute<IVerifiableStorageUpdateRequest, IVerifiableStorageUpdateResponse> =\n\t\t{\n\t\t\toperationId: \"verifiableStorageUpdate\",\n\t\t\tsummary: \"Update an item in verifiable storage\",\n\t\t\ttag: tagsVerifiableStorage[0].name,\n\t\t\tmethod: \"PUT\",\n\t\t\tpath: `${baseRouteName}/:id`,\n\t\t\thandler: async (httpRequestContext, request) =>\n\t\t\t\tverifiableStorageUpdate(httpRequestContext, componentName, request),\n\t\t\trequestType: {\n\t\t\t\ttype: nameof<IVerifiableStorageUpdateRequest>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"verifiableStorageUpdateRequestExample\",\n\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\t\tid: \"verifiable:iota:aW90YS1uZnQ6dHN0OjB4NzYyYjljNDllYTg2OWUwZWJkYTliYmZhNzY5Mzk0NDdhNDI4ZGNmMTc4YzVkMTVhYjQ0N2UyZDRmYmJiNGViMg==\"\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tdata: \"SGVsbG8gd29ybGQ=\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\tresponseType: [\n\t\t\t\t{\n\t\t\t\t\ttype: nameof<IVerifiableStorageUpdateResponse>(),\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"verifiableStorageUpdateResponseExample\",\n\t\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\t\"@context\": \"https://schema.twindev.org/verifiable-storage/\",\n\t\t\t\t\t\t\t\t\ttype: \"VerifiableStorageIotaReceipt2026\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t]\n\t\t};\n\n\tconst getRoute: IRestRoute<IVerifiableStorageGetRequest, IVerifiableStorageGetResponse> = {\n\t\toperationId: \"verifiableStorageGet\",\n\t\tsummary: \"Get an verifiable storage item\",\n\t\ttag: tagsVerifiableStorage[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) => verifiableStorageGet(componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IVerifiableStorageGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"verifiableStorageGetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"verifiable:iota:aW90YS1uZnQ6dHN0OjB4NzYyYjljNDllYTg2OWUwZWJkYTliYmZhNzY5Mzk0NDdhNDI4ZGNmMTc4YzVkMTVhYjQ0N2UyZDRmYmJiNGViMg==\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IVerifiableStorageGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"verifiableStorageGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tdata: \"SGVsbG8gd29ybGQ=\",\n\t\t\t\t\t\t\t\treceipt: {\n\t\t\t\t\t\t\t\t\t\"@context\": \"https://www.w3.org/ns/activitystreams\",\n\t\t\t\t\t\t\t\t\ttype: \"Create\",\n\t\t\t\t\t\t\t\t\tactor: \"https://example.org/actor\",\n\t\t\t\t\t\t\t\t\tobject: \"https://example.org/object\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst removeRoute: IRestRoute<IVerifiableStorageRemoveRequest, INoContentResponse> = {\n\t\toperationId: \"verifiableStorageRemove\",\n\t\tsummary: \"Remove an item from verifiable storage\",\n\t\ttag: tagsVerifiableStorage[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tverifiableStorageRemove(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IVerifiableStorageRemoveRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"verifiableStorageRemoveRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"verifiable:iota:aW90YS1uZnQ6dHN0OjB4NzYyYjljNDllYTg2OWUwZWJkYTliYmZhNzY5Mzk0NDdhNDI4ZGNmMTc4YzVkMTVhYjQ0N2UyZDRmYmJiNGViMg==\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [createRoute, updateRoute, getRoute, removeRoute];\n}\n\n/**\n * Create a verifiable storage item.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function verifiableStorageCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IVerifiableStorageCreateRequest\n): Promise<IVerifiableStorageCreateResponse> {\n\tGuards.object<IVerifiableStorageCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IVerifiableStorageCreateRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\tGuards.stringBase64(ROUTES_SOURCE, nameof(request.body.data), request.body.data);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tContextIdHelper.guard(contextIds, ContextIdKeys.Organization);\n\n\tconst component = ComponentFactory.get<IVerifiableStorageComponent>(componentName);\n\tconst result = await component.create(\n\t\tConverter.base64ToBytes(request.body.data),\n\t\trequest.body.allowList,\n\t\t{\n\t\t\tmaxAllowListSize: request.body.maxAllowListSize\n\t\t},\n\t\trequest.body.namespace,\n\t\tcontextIds[ContextIdKeys.Organization]\n\t);\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders: {\n\t\t\t[HeaderTypes.Location]: result.id\n\t\t},\n\t\tbody: {\n\t\t\treceipt: result.receipt,\n\t\t\tid: result.id\n\t\t}\n\t};\n}\n\n/**\n * UPdate an Verifiable Storage.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function verifiableStorageUpdate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IVerifiableStorageUpdateRequest\n): Promise<IVerifiableStorageUpdateResponse> {\n\tGuards.object<IVerifiableStorageUpdateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IVerifiableStorageGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tGuards.object<IVerifiableStorageUpdateRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\tGuards.stringBase64(ROUTES_SOURCE, nameof(request.body.data), request.body.data);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tContextIdHelper.guard(contextIds, ContextIdKeys.Organization);\n\n\tconst component = ComponentFactory.get<IVerifiableStorageComponent>(componentName);\n\tconst result = await component.update(\n\t\trequest.pathParams.id,\n\t\tIs.stringBase64(request.body.data) ? Converter.base64ToBytes(request.body.data) : undefined,\n\t\trequest.body.allowList,\n\t\tcontextIds[ContextIdKeys.Organization]\n\t);\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Get an Verifiable Storage.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function verifiableStorageGet(\n\tcomponentName: string,\n\trequest: IVerifiableStorageGetRequest\n): Promise<IVerifiableStorageGetResponse> {\n\tGuards.object<IVerifiableStorageGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IVerifiableStorageGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IVerifiableStorageComponent>(componentName);\n\tconst result = await component.get(request.pathParams.id, request.body);\n\treturn {\n\t\tbody: {\n\t\t\tdata: Is.uint8Array(result.data) ? Converter.bytesToBase64(result.data) : undefined,\n\t\t\treceipt: result.receipt,\n\t\t\tallowList: result.allowList\n\t\t}\n\t};\n}\n\n/**\n * Remove a verifiable storage item.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function verifiableStorageRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IVerifiableStorageRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IVerifiableStorageRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IVerifiableStorageRemoveRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tContextIdHelper.guard(contextIds, ContextIdKeys.Organization);\n\n\tconst component = ComponentFactory.get<IVerifiableStorageComponent>(componentName);\n\tawait component.remove(request.pathParams.id, contextIds[ContextIdKeys.Organization]);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"verifiableStorageRoutes.js","sourceRoot":"","sources":["../../src/verifiableStorageRoutes.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAYzE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE5D;;GAEG;AACH,MAAM,aAAa,GAAG,yBAAyB,CAAC;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAW;IAC5C;QACC,IAAI,EAAE,mBAAmB;QACzB,WAAW,EAAE,8DAA8D;KAC3E;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,mCAAmC,CAClD,aAAqB,EACrB,aAAqB;IAErB,MAAM,WAAW,GAChB;QACC,WAAW,EAAE,yBAAyB;QACtC,OAAO,EAAE,sCAAsC;QAC/C,GAAG,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAC,IAAI;QAClC,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,GAAG,aAAa,GAAG;QACzB,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,EAAE,CAC9C,uBAAuB,CAAC,kBAAkB,EAAE,aAAa,EAAE,OAAO,CAAC;QACpE,WAAW,EAAE;YACZ,IAAI,mCAA2C;YAC/C,QAAQ,EAAE;gBACT;oBACC,EAAE,EAAE,uCAAuC;oBAC3C,OAAO,EAAE;wBACR,IAAI,EAAE;4BACL,IAAI,EAAE,kBAAkB;yBACxB;qBACD;iBACD;aACD;SACD;QACD,YAAY,EAAE;YACb;gBACC,IAAI,oCAA4C;gBAChD,QAAQ,EAAE;oBACT;wBACC,EAAE,EAAE,wCAAwC;wBAC5C,QAAQ,EAAE;4BACT,U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AAC,SAAS;KACpC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIHttpRequestContext,\n\tINoContentResponse,\n\tIRestRoute,\n\tITag\n} from \"@twin.org/api-models\";\nimport { ContextIdHelper, ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { ComponentFactory, Converter, Guards, Is } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type {\n\tIVerifiableStorageComponent,\n\tIVerifiableStorageCreateRequest,\n\tIVerifiableStorageCreateResponse,\n\tIVerifiableStorageGetRequest,\n\tIVerifiableStorageGetResponse,\n\tIVerifiableStorageRemoveRequest,\n\tIVerifiableStorageUpdateRequest,\n\tIVerifiableStorageUpdateResponse\n} from \"@twin.org/verifiable-storage-models\";\nimport { HeaderTypes, HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"verifiableStorageRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsVerifiableStorage: ITag[] = [\n\t{\n\t\tname: \"VerifiableStorage\",\n\t\tdescription: \"Endpoints which are modelled to access a verifiable storage.\"\n\t}\n];\n\n/**\n * The REST routes for VerifiableStorage.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesVerifiableStorage(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createRoute: IRestRoute<IVerifiableStorageCreateRequest, IVerifiableStorageCreateResponse> =\n\t\t{\n\t\t\toperationId: \"verifiableStorageCreate\",\n\t\t\tsummary: \"Create an item in verifiable storage\",\n\t\t\ttag: tagsVerifiableStorage[0].name,\n\t\t\tmethod: \"POST\",\n\t\t\tpath: `${baseRouteName}/`,\n\t\t\thandler: async (httpRequestContext, request) =>\n\t\t\t\tverifiableStorageCreate(httpRequestContext, componentName, request),\n\t\t\trequestType: {\n\t\t\t\ttype: nameof<IVerifiableStorageCreateRequest>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"verifiableStorageCreateRequestExample\",\n\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tdata: \"SGVsbG8gd29ybGQ=\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\tresponseType: [\n\t\t\t\t{\n\t\t\t\t\ttype: nameof<IVerifiableStorageCreateResponse>(),\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"verifiableStorageCreateResponseExample\",\n\t\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\t\tstatusCode: HttpStatusCode.created,\n\t\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t\t[HeaderTypes.Location]:\n\t\t\t\t\t\t\t\t\t\t\"verifiable:iota:aW90YS1uZnQ6dHN0OjB4NzYyYjljNDllYTg2OWUwZWJkYTliYmZhNzY5Mzk0NDdhNDI4ZGNmMTc4YzVkMTVhYjQ0N2UyZDRmYmJiNGViMg==\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\treceipt: {\n\t\t\t\t\t\t\t\t\t\t\"@context\": \"https://schema.twindev.org/verifiable-storage/\",\n\t\t\t\t\t\t\t\t\t\ttype: \"VerifiableStorageIotaReceipt2026\"\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tid: \"verifiable:iota:aW90YS1uZnQ6dHN0OjB4NzYyYjljNDllYTg2OWUwZWJkYTliYmZhNzY5Mzk0NDdhNDI4ZGNmMTc4YzVkMTVhYjQ0N2UyZDRmYmJiNGViMg==\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t]\n\t\t};\n\n\tconst updateRoute: IRestRoute<IVerifiableStorageUpdateRequest, IVerifiableStorageUpdateResponse> =\n\t\t{\n\t\t\toperationId: \"verifiableStorageUpdate\",\n\t\t\tsummary: \"Update an item in verifiable storage\",\n\t\t\ttag: tagsVerifiableStorage[0].name,\n\t\t\tmethod: \"PUT\",\n\t\t\tpath: `${baseRouteName}/:id`,\n\t\t\thandler: async (httpRequestContext, request) =>\n\t\t\t\tverifiableStorageUpdate(httpRequestContext, componentName, request),\n\t\t\trequestType: {\n\t\t\t\ttype: nameof<IVerifiableStorageUpdateRequest>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"verifiableStorageUpdateRequestExample\",\n\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\t\tid: \"verifiable:iota:aW90YS1uZnQ6dHN0OjB4NzYyYjljNDllYTg2OWUwZWJkYTliYmZhNzY5Mzk0NDdhNDI4ZGNmMTc4YzVkMTVhYjQ0N2UyZDRmYmJiNGViMg==\"\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tdata: \"SGVsbG8gd29ybGQ=\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\tresponseType: [\n\t\t\t\t{\n\t\t\t\t\ttype: nameof<IVerifiableStorageUpdateResponse>(),\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"verifiableStorageUpdateResponseExample\",\n\t\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\t\"@context\": \"https://schema.twindev.org/verifiable-storage/\",\n\t\t\t\t\t\t\t\t\ttype: \"VerifiableStorageIotaReceipt2026\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t}\n\t\t\t]\n\t\t};\n\n\tconst getRoute: IRestRoute<IVerifiableStorageGetRequest, IVerifiableStorageGetResponse> = {\n\t\toperationId: \"verifiableStorageGet\",\n\t\tsummary: \"Get an verifiable storage item\",\n\t\ttag: tagsVerifiableStorage[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) => verifiableStorageGet(componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IVerifiableStorageGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"verifiableStorageGetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"verifiable:iota:aW90YS1uZnQ6dHN0OjB4NzYyYjljNDllYTg2OWUwZWJkYTliYmZhNzY5Mzk0NDdhNDI4ZGNmMTc4YzVkMTVhYjQ0N2UyZDRmYmJiNGViMg==\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IVerifiableStorageGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"verifiableStorageGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tdata: \"SGVsbG8gd29ybGQ=\",\n\t\t\t\t\t\t\t\treceipt: {\n\t\t\t\t\t\t\t\t\t\"@context\": \"https://www.w3.org/ns/activitystreams\",\n\t\t\t\t\t\t\t\t\ttype: \"Create\",\n\t\t\t\t\t\t\t\t\tactor: \"https://example.org/actor\",\n\t\t\t\t\t\t\t\t\tobject: \"https://example.org/object\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst removeRoute: IRestRoute<IVerifiableStorageRemoveRequest, INoContentResponse> = {\n\t\toperationId: \"verifiableStorageRemove\",\n\t\tsummary: \"Remove an item from verifiable storage\",\n\t\ttag: tagsVerifiableStorage[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tverifiableStorageRemove(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IVerifiableStorageRemoveRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"verifiableStorageRemoveRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"verifiable:iota:aW90YS1uZnQ6dHN0OjB4NzYyYjljNDllYTg2OWUwZWJkYTliYmZhNzY5Mzk0NDdhNDI4ZGNmMTc4YzVkMTVhYjQ0N2UyZDRmYmJiNGViMg==\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [createRoute, updateRoute, getRoute, removeRoute];\n}\n\n/**\n * Create a verifiable storage item.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function verifiableStorageCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IVerifiableStorageCreateRequest\n): Promise<IVerifiableStorageCreateResponse> {\n\tGuards.object<IVerifiableStorageCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IVerifiableStorageCreateRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\tGuards.stringBase64(ROUTES_SOURCE, nameof(request.body.data), request.body.data);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tContextIdHelper.guard(contextIds, ContextIdKeys.Organization);\n\n\tconst component = ComponentFactory.get<IVerifiableStorageComponent>(componentName);\n\tconst result = await component.create(\n\t\tConverter.base64ToBytes(request.body.data),\n\t\trequest.body.allowList,\n\t\t{\n\t\t\tmaxAllowListSize: request.body.maxAllowListSize\n\t\t},\n\t\trequest.body.namespace,\n\t\tcontextIds[ContextIdKeys.Organization]\n\t);\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders: {\n\t\t\t[HeaderTypes.Location]: result.id\n\t\t},\n\t\tbody: {\n\t\t\treceipt: result.receipt,\n\t\t\tid: result.id\n\t\t}\n\t};\n}\n\n/**\n * Update a verifiable storage item.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function verifiableStorageUpdate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IVerifiableStorageUpdateRequest\n): Promise<IVerifiableStorageUpdateResponse> {\n\tGuards.object<IVerifiableStorageUpdateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IVerifiableStorageGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tGuards.object<IVerifiableStorageUpdateRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\tGuards.stringBase64(ROUTES_SOURCE, nameof(request.body.data), request.body.data);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tContextIdHelper.guard(contextIds, ContextIdKeys.Organization);\n\n\tconst component = ComponentFactory.get<IVerifiableStorageComponent>(componentName);\n\tconst result = await component.update(\n\t\trequest.pathParams.id,\n\t\tIs.stringBase64(request.body.data) ? Converter.base64ToBytes(request.body.data) : undefined,\n\t\trequest.body.allowList,\n\t\tcontextIds[ContextIdKeys.Organization]\n\t);\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Get a verifiable storage item.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function verifiableStorageGet(\n\tcomponentName: string,\n\trequest: IVerifiableStorageGetRequest\n): Promise<IVerifiableStorageGetResponse> {\n\tGuards.object<IVerifiableStorageGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IVerifiableStorageGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<IVerifiableStorageComponent>(componentName);\n\tconst result = await component.get(request.pathParams.id, request.body);\n\treturn {\n\t\tbody: {\n\t\t\tdata: Is.uint8Array(result.data) ? Converter.bytesToBase64(result.data) : undefined,\n\t\t\treceipt: result.receipt,\n\t\t\tallowList: result.allowList\n\t\t}\n\t};\n}\n\n/**\n * Remove a verifiable storage item.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function verifiableStorageRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IVerifiableStorageRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IVerifiableStorageRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IVerifiableStorageRemoveRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tContextIdHelper.guard(contextIds, ContextIdKeys.Organization);\n\n\tconst component = ComponentFactory.get<IVerifiableStorageComponent>(componentName);\n\tawait component.remove(request.pathParams.id, contextIds[ContextIdKeys.Organization]);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n"]}
|
|
@@ -23,6 +23,7 @@ export class VerifiableStorageService {
|
|
|
23
23
|
/**
|
|
24
24
|
* Create a new instance of VerifiableStorageService.
|
|
25
25
|
* @param options The options for the service.
|
|
26
|
+
* @throws {GeneralError} If no connectors are registered.
|
|
26
27
|
*/
|
|
27
28
|
constructor(options) {
|
|
28
29
|
const names = VerifiableStorageConnectorFactory.names();
|
|
@@ -82,12 +83,12 @@ export class VerifiableStorageService {
|
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
85
|
-
* Get
|
|
86
|
+
* Get a verifiable storage item.
|
|
86
87
|
* @param id The id of the verifiable storage item to get.
|
|
87
88
|
* @param options Additional options for getting the verifiable storage item.
|
|
88
89
|
* @param options.includeData Should the data be included in the response, defaults to true.
|
|
89
90
|
* @param options.includeAllowList Should the allow list be included in the response, defaults to true.
|
|
90
|
-
* @returns The data for the verifiable storage item.
|
|
91
|
+
* @returns The data and receipt for the verifiable storage item.
|
|
91
92
|
*/
|
|
92
93
|
async get(id, options) {
|
|
93
94
|
Urn.guard(VerifiableStorageService.CLASS_NAME, "id", id);
|
|
@@ -102,9 +103,9 @@ export class VerifiableStorageService {
|
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
105
|
* Remove a verifiable storage item.
|
|
105
|
-
* @param id The id of the
|
|
106
|
+
* @param id The id of the verifiable storage item to remove.
|
|
106
107
|
* @param controller The identity of the controller to access the vault keys.
|
|
107
|
-
* @returns
|
|
108
|
+
* @returns A promise that resolves when the item has been removed.
|
|
108
109
|
*/
|
|
109
110
|
async remove(id, controller) {
|
|
110
111
|
Urn.guard(VerifiableStorageService.CLASS_NAME, "id", id);
|
|
@@ -121,6 +122,7 @@ export class VerifiableStorageService {
|
|
|
121
122
|
* Get the connector from the uri.
|
|
122
123
|
* @param id The id of the item in urn format.
|
|
123
124
|
* @returns The connector.
|
|
125
|
+
* @throws GeneralError If the namespace does not match.
|
|
124
126
|
* @internal
|
|
125
127
|
*/
|
|
126
128
|
getConnector(id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifiableStorageService.js","sourceRoot":"","sources":["../../src/verifiableStorageService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAG3D,OAAO,EACN,iCAAiC,EAGjC,MAAM,qCAAqC,CAAC;AAG7C;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACpC;;OAEG;IACI,MAAM,CAAU,UAAU,8BAA8C;IAE/E;;;OAGG;IACK,MAAM,CAAU,UAAU,GAAW,YAAY,CAAC;IAE1D;;;OAGG;IACc,iBAAiB,CAAS;IAE3C;;;OAGG;IACH,YAAY,OAAqD;QAChE,MAAM,KAAK,GAAG,iCAAiC,CAAC,KAAK,EAAE,CAAC;QACxD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,YAAY,CAAC,wBAAwB,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QAC7E,CAAC;QAED,IAAI,CAAC,iBAAiB,GAAG,OAAO,EAAE,MAAM,EAAE,gBAAgB,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,wBAAwB,CAAC,UAAU,CAAC;IAC5C,CAAC;IAED;;;;;;;;;OASG;IACI,KAAK,CAAC,MAAM,CAClB,IAAgB,EAChB,SAAoB,EACpB,OAEC,EACD,SAAkB,EAClB,UAAmB;QAKnB,MAAM,CAAC,UAAU,CAAC,wBAAwB,CAAC,UAAU,UAAgB,IAAI,CAAC,CAAC;QAC3E,MAAM,CAAC,WAAW,CAAC,wBAAwB,CAAC,UAAU,gBAAsB,UAAU,C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AAC;QACJ,CAAC;QAED,OAAO,iCAAiC,CAAC,GAAG,CAC3C,KAAK,CAAC,eAAe,EAAE,CACvB,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Urn } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tVerifiableStorageConnectorFactory,\n\ttype IVerifiableStorageComponent,\n\ttype IVerifiableStorageConnector\n} from \"@twin.org/verifiable-storage-models\";\nimport type { IVerifiableStorageServiceConstructorOptions } from \"./models/IVerifiableStorageServiceConstructorOptions.js\";\n\n/**\n * Service for performing Verifiable Storage operations to a connector.\n */\nexport class VerifiableStorageService implements IVerifiableStorageComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<VerifiableStorageService>();\n\n\t/**\n\t * The namespace supported by the verifiableStorage service.\n\t * @internal\n\t */\n\tprivate static readonly _NAMESPACE: string = \"verifiable\";\n\n\t/**\n\t * The default namespace for the connector to use.\n\t * @internal\n\t */\n\tprivate readonly _defaultNamespace: string;\n\n\t/**\n\t * Create a new instance of VerifiableStorageService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: IVerifiableStorageServiceConstructorOptions) {\n\t\tconst names = VerifiableStorageConnectorFactory.names();\n\t\tif (names.length === 0) {\n\t\t\tthrow new GeneralError(VerifiableStorageService.CLASS_NAME, \"noConnectors\");\n\t\t}\n\n\t\tthis._defaultNamespace = options?.config?.defaultNamespace ?? names[0];\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 VerifiableStorageService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a verifiable storage item.\n\t * @param data The data for the verifiable storage item.\n\t * @param allowList The list of identities that are allowed to modify the item.\n\t * @param options Additional options for creating the item.\n\t * @param options.maxAllowListSize The maximum size of the allow list.\n\t * @param namespace The namespace to use for the connector to use.\n\t * @param controller The identity of the controller to access the vault keys.\n\t * @returns The id of the created verifiable storage item.\n\t */\n\tpublic async create(\n\t\tdata: Uint8Array,\n\t\tallowList?: string[],\n\t\toptions?: {\n\t\t\tmaxAllowListSize?: number;\n\t\t},\n\t\tnamespace?: string,\n\t\tcontroller?: string\n\t): Promise<{\n\t\tid: string;\n\t\treceipt: IJsonLdNodeObject;\n\t}> {\n\t\tGuards.uint8Array(VerifiableStorageService.CLASS_NAME, nameof(data), data);\n\t\tGuards.stringValue(VerifiableStorageService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst connectorNamespace = namespace ?? this._defaultNamespace;\n\n\t\t\tconst verifiableStorageConnector =\n\t\t\t\tVerifiableStorageConnectorFactory.get<IVerifiableStorageConnector>(connectorNamespace);\n\n\t\t\tconst verifiableStorageResult = await verifiableStorageConnector.create(\n\t\t\t\tcontroller,\n\t\t\t\tdata,\n\t\t\t\tallowList,\n\t\t\t\toptions\n\t\t\t);\n\n\t\t\treturn verifiableStorageResult;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(VerifiableStorageService.CLASS_NAME, \"createFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Update an item in verifiable storage.\n\t * @param id The id of the item to update.\n\t * @param data The data to store, optional if updating the allow list.\n\t * @param allowList Updated list of identities that are allowed to modify the item.\n\t * @param controller The identity of the controller to access the vault keys.\n\t * @returns The updated receipt.\n\t */\n\tpublic async update(\n\t\tid: string,\n\t\tdata?: Uint8Array,\n\t\tallowList?: string[],\n\t\tcontroller?: string\n\t): Promise<IJsonLdNodeObject> {\n\t\tUrn.guard(VerifiableStorageService.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(VerifiableStorageService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst verifiableStorageConnector = this.getConnector(id);\n\t\t\tconst verifiableStorageResult = await verifiableStorageConnector.update(\n\t\t\t\tcontroller,\n\t\t\t\tid,\n\t\t\t\tdata,\n\t\t\t\tallowList\n\t\t\t);\n\n\t\t\treturn verifiableStorageResult;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(VerifiableStorageService.CLASS_NAME, \"updateFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get an Verifiable Storage.\n\t * @param id The id of the verifiable storage item to get.\n\t * @param options Additional options for getting the verifiable storage item.\n\t * @param options.includeData Should the data be included in the response, defaults to true.\n\t * @param options.includeAllowList Should the allow list be included in the response, defaults to true.\n\t * @returns The data for the verifiable storage item.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\toptions?: { includeData?: boolean; includeAllowList?: boolean }\n\t): Promise<{\n\t\tdata?: Uint8Array;\n\t\treceipt: IJsonLdNodeObject;\n\t}> {\n\t\tUrn.guard(VerifiableStorageService.CLASS_NAME, nameof(id), id);\n\n\t\ttry {\n\t\t\tconst verifiableStorageConnector = this.getConnector(id);\n\t\t\tconst result = await verifiableStorageConnector.get(id, options);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(VerifiableStorageService.CLASS_NAME, \"getFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Remove a verifiable storage item.\n\t * @param id The id of the Verifiable Storage to remove.\n\t * @param controller The identity of the controller to access the vault keys.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(id: string, controller?: string): Promise<void> {\n\t\tUrn.guard(VerifiableStorageService.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(VerifiableStorageService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst verifiableStorageConnector = this.getConnector(id);\n\t\t\tawait verifiableStorageConnector.remove(controller, id);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(VerifiableStorageService.CLASS_NAME, \"removeFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get the connector from the uri.\n\t * @param id The id of the item in urn format.\n\t * @returns The connector.\n\t * @internal\n\t */\n\tprivate getConnector(id: string): IVerifiableStorageConnector {\n\t\tconst idUri = Urn.fromValidString(id);\n\n\t\tif (idUri.namespaceIdentifier() !== VerifiableStorageService._NAMESPACE) {\n\t\t\tthrow new GeneralError(VerifiableStorageService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: VerifiableStorageService._NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\treturn VerifiableStorageConnectorFactory.get<IVerifiableStorageConnector>(\n\t\t\tidUri.namespaceMethod()\n\t\t);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"verifiableStorageService.js","sourceRoot":"","sources":["../../src/verifiableStorageService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAG3D,OAAO,EACN,iCAAiC,EAGjC,MAAM,qCAAqC,CAAC;AAG7C;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACpC;;OAEG;IACI,MAAM,CAAU,UAAU,8BAA8C;IAE/E;;;OAGG;IACK,MAAM,CAAU,UAAU,GAAW,YAAY,CAAC;IAE1D;;;OAGG;IACc,iBAAiB,CAAS;IAE3C;;;;OAIG;IACH,YAAY,OAAqD;QAChE,MAAM,KAAK,GAAG,iCAAiC,CAAC,KAAK,EAAE,CAAC;QACxD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,YAAY,CAAC,wBAAwB,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QAC7E,CAAC;QAED,IAAI,CAAC,iBAAiB,GAAG,OAAO,EAAE,MAAM,EAAE,gBAAgB,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,wBAAwB,CAAC,UAAU,CAAC;IAC5C,CAAC;IAED;;;;;;;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CAAC,EAAE,CAAC,CAAC;QAEtC,IAAI,KAAK,CAAC,mBAAmB,EAAE,KAAK,wBAAwB,CAAC,UAAU,EAAE,CAAC;YACzE,MAAM,IAAI,YAAY,CAAC,wBAAwB,CAAC,UAAU,EAAE,mBAAmB,EAAE;gBAChF,SAAS,EAAE,wBAAwB,CAAC,UAAU;gBAC9C,EAAE;aACF,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,iCAAiC,CAAC,GAAG,CAC3C,KAAK,CAAC,eAAe,EAAE,CACvB,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Urn } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tVerifiableStorageConnectorFactory,\n\ttype IVerifiableStorageComponent,\n\ttype IVerifiableStorageConnector\n} from \"@twin.org/verifiable-storage-models\";\nimport type { IVerifiableStorageServiceConstructorOptions } from \"./models/IVerifiableStorageServiceConstructorOptions.js\";\n\n/**\n * Service for performing Verifiable Storage operations to a connector.\n */\nexport class VerifiableStorageService implements IVerifiableStorageComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<VerifiableStorageService>();\n\n\t/**\n\t * The namespace supported by the verifiableStorage service.\n\t * @internal\n\t */\n\tprivate static readonly _NAMESPACE: string = \"verifiable\";\n\n\t/**\n\t * The default namespace for the connector to use.\n\t * @internal\n\t */\n\tprivate readonly _defaultNamespace: string;\n\n\t/**\n\t * Create a new instance of VerifiableStorageService.\n\t * @param options The options for the service.\n\t * @throws {GeneralError} If no connectors are registered.\n\t */\n\tconstructor(options?: IVerifiableStorageServiceConstructorOptions) {\n\t\tconst names = VerifiableStorageConnectorFactory.names();\n\t\tif (names.length === 0) {\n\t\t\tthrow new GeneralError(VerifiableStorageService.CLASS_NAME, \"noConnectors\");\n\t\t}\n\n\t\tthis._defaultNamespace = options?.config?.defaultNamespace ?? names[0];\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 VerifiableStorageService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a verifiable storage item.\n\t * @param data The data for the verifiable storage item.\n\t * @param allowList The list of identities that are allowed to modify the item.\n\t * @param options Additional options for creating the item.\n\t * @param options.maxAllowListSize The maximum size of the allow list.\n\t * @param namespace The namespace to use for the connector to use.\n\t * @param controller The identity of the controller to access the vault keys.\n\t * @returns The id of the created verifiable storage item.\n\t */\n\tpublic async create(\n\t\tdata: Uint8Array,\n\t\tallowList?: string[],\n\t\toptions?: {\n\t\t\tmaxAllowListSize?: number;\n\t\t},\n\t\tnamespace?: string,\n\t\tcontroller?: string\n\t): Promise<{\n\t\tid: string;\n\t\treceipt: IJsonLdNodeObject;\n\t}> {\n\t\tGuards.uint8Array(VerifiableStorageService.CLASS_NAME, nameof(data), data);\n\t\tGuards.stringValue(VerifiableStorageService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst connectorNamespace = namespace ?? this._defaultNamespace;\n\n\t\t\tconst verifiableStorageConnector =\n\t\t\t\tVerifiableStorageConnectorFactory.get<IVerifiableStorageConnector>(connectorNamespace);\n\n\t\t\tconst verifiableStorageResult = await verifiableStorageConnector.create(\n\t\t\t\tcontroller,\n\t\t\t\tdata,\n\t\t\t\tallowList,\n\t\t\t\toptions\n\t\t\t);\n\n\t\t\treturn verifiableStorageResult;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(VerifiableStorageService.CLASS_NAME, \"createFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Update an item in verifiable storage.\n\t * @param id The id of the item to update.\n\t * @param data The data to store, optional if updating the allow list.\n\t * @param allowList Updated list of identities that are allowed to modify the item.\n\t * @param controller The identity of the controller to access the vault keys.\n\t * @returns The updated receipt.\n\t */\n\tpublic async update(\n\t\tid: string,\n\t\tdata?: Uint8Array,\n\t\tallowList?: string[],\n\t\tcontroller?: string\n\t): Promise<IJsonLdNodeObject> {\n\t\tUrn.guard(VerifiableStorageService.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(VerifiableStorageService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst verifiableStorageConnector = this.getConnector(id);\n\t\t\tconst verifiableStorageResult = await verifiableStorageConnector.update(\n\t\t\t\tcontroller,\n\t\t\t\tid,\n\t\t\t\tdata,\n\t\t\t\tallowList\n\t\t\t);\n\n\t\t\treturn verifiableStorageResult;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(VerifiableStorageService.CLASS_NAME, \"updateFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get a verifiable storage item.\n\t * @param id The id of the verifiable storage item to get.\n\t * @param options Additional options for getting the verifiable storage item.\n\t * @param options.includeData Should the data be included in the response, defaults to true.\n\t * @param options.includeAllowList Should the allow list be included in the response, defaults to true.\n\t * @returns The data and receipt for the verifiable storage item.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\toptions?: { includeData?: boolean; includeAllowList?: boolean }\n\t): Promise<{\n\t\tdata?: Uint8Array;\n\t\treceipt: IJsonLdNodeObject;\n\t}> {\n\t\tUrn.guard(VerifiableStorageService.CLASS_NAME, nameof(id), id);\n\n\t\ttry {\n\t\t\tconst verifiableStorageConnector = this.getConnector(id);\n\t\t\tconst result = await verifiableStorageConnector.get(id, options);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(VerifiableStorageService.CLASS_NAME, \"getFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Remove a verifiable storage item.\n\t * @param id The id of the verifiable storage item to remove.\n\t * @param controller The identity of the controller to access the vault keys.\n\t * @returns A promise that resolves when the item has been removed.\n\t */\n\tpublic async remove(id: string, controller?: string): Promise<void> {\n\t\tUrn.guard(VerifiableStorageService.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(VerifiableStorageService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst verifiableStorageConnector = this.getConnector(id);\n\t\t\tawait verifiableStorageConnector.remove(controller, id);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(VerifiableStorageService.CLASS_NAME, \"removeFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get the connector from the uri.\n\t * @param id The id of the item in urn format.\n\t * @returns The connector.\n\t * @throws GeneralError If the namespace does not match.\n\t * @internal\n\t */\n\tprivate getConnector(id: string): IVerifiableStorageConnector {\n\t\tconst idUri = Urn.fromValidString(id);\n\n\t\tif (idUri.namespaceIdentifier() !== VerifiableStorageService._NAMESPACE) {\n\t\t\tthrow new GeneralError(VerifiableStorageService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: VerifiableStorageService._NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\treturn VerifiableStorageConnectorFactory.get<IVerifiableStorageConnector>(\n\t\t\tidUri.namespaceMethod()\n\t\t);\n\t}\n}\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export interface IVerifiableStorageServiceConfig {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* The default connector namespace to use; falls back to the first registered connector if not provided.
|
|
7
7
|
*/
|
|
8
8
|
defaultNamespace?: string;
|
|
9
9
|
}
|
|
@@ -20,7 +20,7 @@ export declare function generateRestRoutesVerifiableStorage(baseRouteName: strin
|
|
|
20
20
|
*/
|
|
21
21
|
export declare function verifiableStorageCreate(httpRequestContext: IHttpRequestContext, componentName: string, request: IVerifiableStorageCreateRequest): Promise<IVerifiableStorageCreateResponse>;
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Update a verifiable storage item.
|
|
24
24
|
* @param httpRequestContext The request context for the API.
|
|
25
25
|
* @param componentName The name of the component to use in the routes.
|
|
26
26
|
* @param request The request.
|
|
@@ -28,7 +28,7 @@ export declare function verifiableStorageCreate(httpRequestContext: IHttpRequest
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function verifiableStorageUpdate(httpRequestContext: IHttpRequestContext, componentName: string, request: IVerifiableStorageUpdateRequest): Promise<IVerifiableStorageUpdateResponse>;
|
|
30
30
|
/**
|
|
31
|
-
* Get
|
|
31
|
+
* Get a verifiable storage item.
|
|
32
32
|
* @param componentName The name of the component to use in the routes.
|
|
33
33
|
* @param request The request.
|
|
34
34
|
* @returns The response object with additional http response properties.
|
|
@@ -12,6 +12,7 @@ export declare class VerifiableStorageService implements IVerifiableStorageCompo
|
|
|
12
12
|
/**
|
|
13
13
|
* Create a new instance of VerifiableStorageService.
|
|
14
14
|
* @param options The options for the service.
|
|
15
|
+
* @throws {GeneralError} If no connectors are registered.
|
|
15
16
|
*/
|
|
16
17
|
constructor(options?: IVerifiableStorageServiceConstructorOptions);
|
|
17
18
|
/**
|
|
@@ -45,12 +46,12 @@ export declare class VerifiableStorageService implements IVerifiableStorageCompo
|
|
|
45
46
|
*/
|
|
46
47
|
update(id: string, data?: Uint8Array, allowList?: string[], controller?: string): Promise<IJsonLdNodeObject>;
|
|
47
48
|
/**
|
|
48
|
-
* Get
|
|
49
|
+
* Get a verifiable storage item.
|
|
49
50
|
* @param id The id of the verifiable storage item to get.
|
|
50
51
|
* @param options Additional options for getting the verifiable storage item.
|
|
51
52
|
* @param options.includeData Should the data be included in the response, defaults to true.
|
|
52
53
|
* @param options.includeAllowList Should the allow list be included in the response, defaults to true.
|
|
53
|
-
* @returns The data for the verifiable storage item.
|
|
54
|
+
* @returns The data and receipt for the verifiable storage item.
|
|
54
55
|
*/
|
|
55
56
|
get(id: string, options?: {
|
|
56
57
|
includeData?: boolean;
|
|
@@ -61,9 +62,9 @@ export declare class VerifiableStorageService implements IVerifiableStorageCompo
|
|
|
61
62
|
}>;
|
|
62
63
|
/**
|
|
63
64
|
* Remove a verifiable storage item.
|
|
64
|
-
* @param id The id of the
|
|
65
|
+
* @param id The id of the verifiable storage item to remove.
|
|
65
66
|
* @param controller The identity of the controller to access the vault keys.
|
|
66
|
-
* @returns
|
|
67
|
+
* @returns A promise that resolves when the item has been removed.
|
|
67
68
|
*/
|
|
68
69
|
remove(id: string, controller?: string): Promise<void>;
|
|
69
70
|
}
|