@twin.org/immutable-proof-service 0.0.3-next.3 → 0.0.3-next.5

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.
@@ -98,15 +98,15 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
98
98
  response: {
99
99
  body: {
100
100
  "@context": [
101
- ImmutableProofContexts.ContextRoot,
102
- ImmutableProofContexts.ContextRootCommon
101
+ ImmutableProofContexts.Namespace,
102
+ ImmutableProofContexts.NamespaceCommon
103
103
  ],
104
104
  type: ImmutableProofTypes.ImmutableProof,
105
105
  id: "ais:1234567890",
106
106
  proofObjectId: "test:1234567890",
107
107
  proofObjectHash: "EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y=",
108
108
  proof: {
109
- "@context": DidContexts.ContextDataIntegrity,
109
+ "@context": DidContexts.NamespaceDataIntegrity,
110
110
  type: ProofTypes.DataIntegrityProof,
111
111
  cryptosuite: DidCryptoSuites.EdDSAJcs2022,
112
112
  created: "2024-08-22T11:56:56.272Z",
@@ -130,15 +130,15 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
130
130
  },
131
131
  body: {
132
132
  "@context": [
133
- ImmutableProofContexts.ContextRoot,
134
- ImmutableProofContexts.ContextRootCommon
133
+ ImmutableProofContexts.Namespace,
134
+ ImmutableProofContexts.NamespaceCommon
135
135
  ],
136
136
  type: ImmutableProofTypes.ImmutableProof,
137
137
  id: "ais:1234567890",
138
138
  proofObjectId: "test:1234567890",
139
139
  proofObjectHash: "EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y=",
140
140
  proof: {
141
- "@context": DidContexts.ContextDataIntegrity,
141
+ "@context": DidContexts.NamespaceDataIntegrity,
142
142
  type: ProofTypes.DataIntegrityProof,
143
143
  cryptosuite: DidCryptoSuites.EdDSAJcs2022,
144
144
  created: "2024-08-22T11:56:56.272Z",
@@ -183,7 +183,7 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
183
183
  id: "immutableProofVerifyResponseExample",
184
184
  response: {
185
185
  body: {
186
- "@context": ImmutableProofContexts.ContextRoot,
186
+ "@context": ImmutableProofContexts.Namespace,
187
187
  type: ImmutableProofTypes.ImmutableProofVerification,
188
188
  verified: true
189
189
  }
@@ -198,7 +198,7 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
198
198
  id: "immutableProofVerifyResponseFailExample",
199
199
  response: {
200
200
  body: {
201
- "@context": ImmutableProofContexts.ContextRoot,
201
+ "@context": ImmutableProofContexts.Namespace,
202
202
  type: ImmutableProofTypes.ImmutableProofVerification,
203
203
  verified: false,
204
204
  failure: ImmutableProofFailure.ProofTypeMismatch
@@ -1 +1 @@
1
- {"version":3,"file":"immutableProofRoutes.js","sourceRoot":"","sources":["../../src/immutableProofRoutes.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAON,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEvE;;GAEG;AACH,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAW;IACzC;QACC,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,qEAAqE;KAClF;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC/C,aAAqB,EACrB,aAAqB;IAErB,MAAM,WAAW,GAA+D;QAC/E,WAAW,EAAE,sBAAsB;QACnC,OAAO,EAAE,gBAAgB;QACzB,GAAG,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,IAAI;QAC/B,MAAM,EAA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n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tICreatedResponse,\n\tIHttpRequestContext,\n\tINotFoundResponse,\n\tIRestRoute,\n\tITag\n} from \"@twin.org/api-models\";\nimport { ComponentFactory, Guards } from \"@twin.org/core\";\nimport {\n\ttype IImmutableProofComponent,\n\ttype IImmutableProofCreateRequest,\n\ttype IImmutableProofGetRequest,\n\ttype IImmutableProofGetResponse,\n\ttype IImmutableProofVerifyRequest,\n\ttype IImmutableProofVerifyResponse,\n\tImmutableProofContexts,\n\tImmutableProofFailure,\n\tImmutableProofTypes\n} from \"@twin.org/immutable-proof-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { DidContexts, DidCryptoSuites, ProofTypes } from \"@twin.org/standards-w3c-did\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"immutableProofRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsImmutableProof: ITag[] = [\n\t{\n\t\tname: \"Immutable Proof\",\n\t\tdescription: \"Endpoints which are modelled to access an immutable proof contract.\"\n\t}\n];\n\n/**\n * The REST routes for immutable proof.\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 generateRestRoutesImmutableProof(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createRoute: IRestRoute<IImmutableProofCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"immutableProofCreate\",\n\t\tsummary: \"Create a proof\",\n\t\ttag: tagsImmutableProof[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\timmutableProofCreate(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IImmutableProofCreateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"immutableProofCreateRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tdocument: {\n\t\t\t\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\t\t\ttype: \"Person\",\n\t\t\t\t\t\t\t\tname: \"John Smith\"\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\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofCreateResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: HttpStatusCode.created,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.Location]: \"test:1234567890\"\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\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst getRoute: IRestRoute<IImmutableProofGetRequest, IImmutableProofGetResponse> = {\n\t\toperationId: \"immutableProofGet\",\n\t\tsummary: \"Get a proof\",\n\t\ttag: tagsImmutableProof[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\timmutableProofGet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IImmutableProofGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"immutableProofGetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.Json\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"ais:1234567890\"\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<IImmutableProofGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": [\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.ContextRoot,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.ContextRootCommon\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\ttype: ImmutableProofTypes.ImmutableProof,\n\t\t\t\t\t\t\t\tid: \"ais:1234567890\",\n\t\t\t\t\t\t\t\tproofObjectId: \"test:1234567890\",\n\t\t\t\t\t\t\t\tproofObjectHash: \"EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y=\",\n\t\t\t\t\t\t\t\tproof: {\n\t\t\t\t\t\t\t\t\t\"@context\": DidContexts.ContextDataIntegrity,\n\t\t\t\t\t\t\t\t\ttype: ProofTypes.DataIntegrityProof,\n\t\t\t\t\t\t\t\t\tcryptosuite: DidCryptoSuites.EdDSAJcs2022,\n\t\t\t\t\t\t\t\t\tcreated: \"2024-08-22T11:56:56.272Z\",\n\t\t\t\t\t\t\t\t\tproofPurpose: \"assertionMethod\",\n\t\t\t\t\t\t\t\t\tproofValue: \"7DdiPPYtxLjCD3wA1po2rv...\"\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\t{\n\t\t\t\ttype: nameof<IImmutableProofGetResponse>(),\n\t\t\t\tmimeType: MimeTypes.JsonLd,\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofJsonLdGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.ContentType]: MimeTypes.JsonLd\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": [\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.ContextRoot,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.ContextRootCommon\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\ttype: ImmutableProofTypes.ImmutableProof,\n\t\t\t\t\t\t\t\tid: \"ais:1234567890\",\n\t\t\t\t\t\t\t\tproofObjectId: \"test:1234567890\",\n\t\t\t\t\t\t\t\tproofObjectHash: \"EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y=\",\n\t\t\t\t\t\t\t\tproof: {\n\t\t\t\t\t\t\t\t\t\"@context\": DidContexts.ContextDataIntegrity,\n\t\t\t\t\t\t\t\t\ttype: ProofTypes.DataIntegrityProof,\n\t\t\t\t\t\t\t\t\tcryptosuite: DidCryptoSuites.EdDSAJcs2022,\n\t\t\t\t\t\t\t\t\tcreated: \"2024-08-22T11:56:56.272Z\",\n\t\t\t\t\t\t\t\t\tproofPurpose: \"assertionMethod\",\n\t\t\t\t\t\t\t\t\tproofValue: \"7DdiPPYtxLjCD3wA1po2rv...\"\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\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst verifyRoute: IRestRoute<IImmutableProofVerifyRequest, IImmutableProofVerifyResponse> = {\n\t\toperationId: \"immutableProofVerify\",\n\t\tsummary: \"Verify a proof\",\n\t\ttag: tagsImmutableProof[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id/verify`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\timmutableProofVerify(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IImmutableProofVerifyRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"immutableProofVerifyRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"ais:1234567890\"\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<IImmutableProofVerifyResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofVerifyResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": ImmutableProofContexts.ContextRoot,\n\t\t\t\t\t\t\t\ttype: ImmutableProofTypes.ImmutableProofVerification,\n\t\t\t\t\t\t\t\tverified: true\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\t{\n\t\t\t\ttype: nameof<IImmutableProofVerifyResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofVerifyResponseFailExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": ImmutableProofContexts.ContextRoot,\n\t\t\t\t\t\t\t\ttype: ImmutableProofTypes.ImmutableProofVerification,\n\t\t\t\t\t\t\t\tverified: false,\n\t\t\t\t\t\t\t\tfailure: ImmutableProofFailure.ProofTypeMismatch\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\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [createRoute, getRoute, verifyRoute];\n}\n\n/**\n * Create a proof.\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 immutableProofCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofCreateRequest\n): Promise<ICreatedResponse> {\n\tGuards.object<IImmutableProofCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object(ROUTES_SOURCE, nameof(request.body.document), request.body.document);\n\n\tconst component = ComponentFactory.get<IImmutableProofComponent>(componentName);\n\tconst result = await component.create(request.body.document);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders: {\n\t\t\t[HeaderTypes.Location]: result\n\t\t}\n\t};\n}\n\n/**\n * Get the proof.\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 immutableProofGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofGetRequest\n): Promise<IImmutableProofGetResponse> {\n\tGuards.object<IImmutableProofGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IImmutableProofGetRequest[\"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 mimeType = request.headers?.[HeaderTypes.Accept] === MimeTypes.JsonLd ? \"jsonld\" : \"json\";\n\n\tconst component = ComponentFactory.get<IImmutableProofComponent>(componentName);\n\tconst result = await component.get(request.pathParams.id);\n\n\treturn {\n\t\theaders: {\n\t\t\t[HeaderTypes.ContentType]: mimeType === \"json\" ? MimeTypes.Json : MimeTypes.JsonLd\n\t\t},\n\t\tbody: result\n\t};\n}\n\n/**\n * Verify the proof.\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 immutableProofVerify(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofVerifyRequest\n): Promise<IImmutableProofVerifyResponse> {\n\tGuards.object<IImmutableProofVerifyRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IImmutableProofVerifyRequest[\"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 mimeType = request.headers?.[HeaderTypes.Accept] === MimeTypes.JsonLd ? \"jsonld\" : \"json\";\n\n\tconst component = ComponentFactory.get<IImmutableProofComponent>(componentName);\n\tconst result = await component.verify(request.pathParams.id);\n\n\treturn {\n\t\theaders: {\n\t\t\t[HeaderTypes.ContentType]: mimeType === \"json\" ? MimeTypes.Json : MimeTypes.JsonLd\n\t\t},\n\t\tbody: result\n\t};\n}\n"]}
1
+ {"version":3,"file":"immutableProofRoutes.js","sourceRoot":"","sources":["../../src/immutableProofRoutes.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAON,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEvE;;GAEG;AACH,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAW;IACzC;QACC,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,qEAAqE;KAClF;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC/C,aAAqB,EACrB,aAAqB;IAErB,MAAM,WAAW,GAA+D;QAC/E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,CAAC,CAAC,SAAS,CAAC,MAAM;SAClF;QACD,IAAI,EAAE,MAAM;KACZ,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tICreatedResponse,\n\tIHttpRequestContext,\n\tINotFoundResponse,\n\tIRestRoute,\n\tITag\n} from \"@twin.org/api-models\";\nimport { ComponentFactory, Guards } from \"@twin.org/core\";\nimport {\n\ttype IImmutableProofComponent,\n\ttype IImmutableProofCreateRequest,\n\ttype IImmutableProofGetRequest,\n\ttype IImmutableProofGetResponse,\n\ttype IImmutableProofVerifyRequest,\n\ttype IImmutableProofVerifyResponse,\n\tImmutableProofContexts,\n\tImmutableProofFailure,\n\tImmutableProofTypes\n} from \"@twin.org/immutable-proof-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { DidContexts, DidCryptoSuites, ProofTypes } from \"@twin.org/standards-w3c-did\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"immutableProofRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsImmutableProof: ITag[] = [\n\t{\n\t\tname: \"Immutable Proof\",\n\t\tdescription: \"Endpoints which are modelled to access an immutable proof contract.\"\n\t}\n];\n\n/**\n * The REST routes for immutable proof.\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 generateRestRoutesImmutableProof(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createRoute: IRestRoute<IImmutableProofCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"immutableProofCreate\",\n\t\tsummary: \"Create a proof\",\n\t\ttag: tagsImmutableProof[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\timmutableProofCreate(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IImmutableProofCreateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"immutableProofCreateRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tdocument: {\n\t\t\t\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\t\t\ttype: \"Person\",\n\t\t\t\t\t\t\t\tname: \"John Smith\"\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\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofCreateResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: HttpStatusCode.created,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.Location]: \"test:1234567890\"\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\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst getRoute: IRestRoute<IImmutableProofGetRequest, IImmutableProofGetResponse> = {\n\t\toperationId: \"immutableProofGet\",\n\t\tsummary: \"Get a proof\",\n\t\ttag: tagsImmutableProof[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\timmutableProofGet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IImmutableProofGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"immutableProofGetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.Json\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"ais:1234567890\"\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<IImmutableProofGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": [\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.Namespace,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.NamespaceCommon\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\ttype: ImmutableProofTypes.ImmutableProof,\n\t\t\t\t\t\t\t\tid: \"ais:1234567890\",\n\t\t\t\t\t\t\t\tproofObjectId: \"test:1234567890\",\n\t\t\t\t\t\t\t\tproofObjectHash: \"EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y=\",\n\t\t\t\t\t\t\t\tproof: {\n\t\t\t\t\t\t\t\t\t\"@context\": DidContexts.NamespaceDataIntegrity,\n\t\t\t\t\t\t\t\t\ttype: ProofTypes.DataIntegrityProof,\n\t\t\t\t\t\t\t\t\tcryptosuite: DidCryptoSuites.EdDSAJcs2022,\n\t\t\t\t\t\t\t\t\tcreated: \"2024-08-22T11:56:56.272Z\",\n\t\t\t\t\t\t\t\t\tproofPurpose: \"assertionMethod\",\n\t\t\t\t\t\t\t\t\tproofValue: \"7DdiPPYtxLjCD3wA1po2rv...\"\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\t{\n\t\t\t\ttype: nameof<IImmutableProofGetResponse>(),\n\t\t\t\tmimeType: MimeTypes.JsonLd,\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofJsonLdGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.ContentType]: MimeTypes.JsonLd\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": [\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.Namespace,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.NamespaceCommon\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\ttype: ImmutableProofTypes.ImmutableProof,\n\t\t\t\t\t\t\t\tid: \"ais:1234567890\",\n\t\t\t\t\t\t\t\tproofObjectId: \"test:1234567890\",\n\t\t\t\t\t\t\t\tproofObjectHash: \"EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y=\",\n\t\t\t\t\t\t\t\tproof: {\n\t\t\t\t\t\t\t\t\t\"@context\": DidContexts.NamespaceDataIntegrity,\n\t\t\t\t\t\t\t\t\ttype: ProofTypes.DataIntegrityProof,\n\t\t\t\t\t\t\t\t\tcryptosuite: DidCryptoSuites.EdDSAJcs2022,\n\t\t\t\t\t\t\t\t\tcreated: \"2024-08-22T11:56:56.272Z\",\n\t\t\t\t\t\t\t\t\tproofPurpose: \"assertionMethod\",\n\t\t\t\t\t\t\t\t\tproofValue: \"7DdiPPYtxLjCD3wA1po2rv...\"\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\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst verifyRoute: IRestRoute<IImmutableProofVerifyRequest, IImmutableProofVerifyResponse> = {\n\t\toperationId: \"immutableProofVerify\",\n\t\tsummary: \"Verify a proof\",\n\t\ttag: tagsImmutableProof[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id/verify`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\timmutableProofVerify(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IImmutableProofVerifyRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"immutableProofVerifyRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"ais:1234567890\"\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<IImmutableProofVerifyResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofVerifyResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": ImmutableProofContexts.Namespace,\n\t\t\t\t\t\t\t\ttype: ImmutableProofTypes.ImmutableProofVerification,\n\t\t\t\t\t\t\t\tverified: true\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\t{\n\t\t\t\ttype: nameof<IImmutableProofVerifyResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofVerifyResponseFailExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": ImmutableProofContexts.Namespace,\n\t\t\t\t\t\t\t\ttype: ImmutableProofTypes.ImmutableProofVerification,\n\t\t\t\t\t\t\t\tverified: false,\n\t\t\t\t\t\t\t\tfailure: ImmutableProofFailure.ProofTypeMismatch\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\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [createRoute, getRoute, verifyRoute];\n}\n\n/**\n * Create a proof.\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 immutableProofCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofCreateRequest\n): Promise<ICreatedResponse> {\n\tGuards.object<IImmutableProofCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object(ROUTES_SOURCE, nameof(request.body.document), request.body.document);\n\n\tconst component = ComponentFactory.get<IImmutableProofComponent>(componentName);\n\tconst result = await component.create(request.body.document);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders: {\n\t\t\t[HeaderTypes.Location]: result\n\t\t}\n\t};\n}\n\n/**\n * Get the proof.\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 immutableProofGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofGetRequest\n): Promise<IImmutableProofGetResponse> {\n\tGuards.object<IImmutableProofGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IImmutableProofGetRequest[\"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 mimeType = request.headers?.[HeaderTypes.Accept] === MimeTypes.JsonLd ? \"jsonld\" : \"json\";\n\n\tconst component = ComponentFactory.get<IImmutableProofComponent>(componentName);\n\tconst result = await component.get(request.pathParams.id);\n\n\treturn {\n\t\theaders: {\n\t\t\t[HeaderTypes.ContentType]: mimeType === \"json\" ? MimeTypes.Json : MimeTypes.JsonLd\n\t\t},\n\t\tbody: result\n\t};\n}\n\n/**\n * Verify the proof.\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 immutableProofVerify(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofVerifyRequest\n): Promise<IImmutableProofVerifyResponse> {\n\tGuards.object<IImmutableProofVerifyRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IImmutableProofVerifyRequest[\"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 mimeType = request.headers?.[HeaderTypes.Accept] === MimeTypes.JsonLd ? \"jsonld\" : \"json\";\n\n\tconst component = ComponentFactory.get<IImmutableProofComponent>(componentName);\n\tconst result = await component.verify(request.pathParams.id);\n\n\treturn {\n\t\theaders: {\n\t\t\t[HeaderTypes.ContentType]: mimeType === \"json\" ? MimeTypes.Json : MimeTypes.JsonLd\n\t\t},\n\t\tbody: result\n\t};\n}\n"]}
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
3
  import { TaskStatus } from "@twin.org/background-task-models";
4
4
  import { ContextIdHelper, ContextIdKeys, ContextIdStore } from "@twin.org/context";
5
- import { ComponentFactory, Converter, GeneralError, Guards, Is, JsonHelper, NotFoundError, ObjectHelper, RandomHelper, Urn, Validation } from "@twin.org/core";
5
+ import { BaseError, ComponentFactory, Converter, GeneralError, Guards, Is, JsonHelper, NotFoundError, ObjectHelper, RandomHelper, Urn, Validation } from "@twin.org/core";
6
6
  import { Sha256 } from "@twin.org/crypto";
7
7
  import { JsonLdHelper, JsonLdProcessor } from "@twin.org/data-json-ld";
8
8
  import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
@@ -28,6 +28,11 @@ export class ImmutableProofService {
28
28
  * @internal
29
29
  */
30
30
  _config;
31
+ /**
32
+ * The logging component.
33
+ * @internal
34
+ */
35
+ _logging;
31
36
  /**
32
37
  * The identity connector.
33
38
  * @internal
@@ -70,6 +75,7 @@ export class ImmutableProofService {
70
75
  constructor(options) {
71
76
  this._proofStorage = EntityStorageConnectorFactory.get(options?.immutableProofEntityStorageType ?? "immutable-proof");
72
77
  this._verifiableStorage = VerifiableStorageConnectorFactory.get(options?.verifiableStorageType ?? "verifiable-storage");
78
+ this._logging = ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
73
79
  this._identityConnectorType = options?.identityConnectorType ?? "identity";
74
80
  this._identityConnector = IdentityConnectorFactory.get(this._identityConnectorType);
75
81
  this._backgroundTaskComponent = ComponentFactory.get(options?.backgroundTaskComponentType ?? "background-task");
@@ -131,7 +137,9 @@ export class ImmutableProofService {
131
137
  verificationMethodId: this._verificationMethodId,
132
138
  document: immutableProof
133
139
  };
134
- await this._backgroundTaskComponent.create("immutable-proof", proofTaskPayload);
140
+ await this._backgroundTaskComponent.create("immutable-proof", proofTaskPayload, {
141
+ retainFor: 5000
142
+ });
135
143
  return new Urn(ImmutableProofService._NAMESPACE, id).toString();
136
144
  }
137
145
  catch (error) {
@@ -180,7 +188,7 @@ export class ImmutableProofService {
180
188
  try {
181
189
  const { verified, failure } = await this.internalGet(id, true);
182
190
  return {
183
- "@context": ImmutableProofContexts.ContextRoot,
191
+ "@context": ImmutableProofContexts.Namespace,
184
192
  type: ImmutableProofTypes.ImmutableProofVerification,
185
193
  verified,
186
194
  failure
@@ -240,7 +248,7 @@ export class ImmutableProofService {
240
248
  */
241
249
  proofEntityToJsonLd(proofEntity) {
242
250
  const jsonLd = {
243
- "@context": [ImmutableProofContexts.ContextRoot, ImmutableProofContexts.ContextRootCommon],
251
+ "@context": [ImmutableProofContexts.Namespace, ImmutableProofContexts.NamespaceCommon],
244
252
  type: ImmutableProofTypes.ImmutableProof,
245
253
  id: proofEntity.id,
246
254
  proofObjectId: proofEntity.proofObjectId,
@@ -255,22 +263,40 @@ export class ImmutableProofService {
255
263
  * @internal
256
264
  */
257
265
  async finaliseTask(task) {
258
- if (task.status === TaskStatus.Success && Is.object(task.payload) && Is.object(task.result)) {
259
- const proofEntity = await this._proofStorage.get(task.payload.proofId);
260
- if (Is.object(proofEntity)) {
261
- const immutableProof = this.proofEntityToJsonLd(proofEntity);
262
- // As we are adding the proof to the data we update its context
263
- immutableProof["@context"] = JsonLdProcessor.combineContexts([ImmutableProofContexts.ContextRoot, ImmutableProofContexts.ContextRootCommon], task.result.proof["@context"]);
264
- immutableProof.proof = task.result.proof;
265
- ObjectHelper.propertyDelete(immutableProof.proof, "@context");
266
- if (Is.stringValue(immutableProof.proof.created)) {
267
- proofEntity.dateCreated = immutableProof.proof.created;
266
+ if (Is.object(task.payload)) {
267
+ if (task.status === TaskStatus.Success && Is.object(task.result)) {
268
+ const proofEntity = await this._proofStorage.get(task.payload.proofId);
269
+ if (Is.object(proofEntity)) {
270
+ const immutableProof = this.proofEntityToJsonLd(proofEntity);
271
+ // As we are adding the proof to the data we update its context
272
+ immutableProof["@context"] = JsonLdProcessor.combineContexts([ImmutableProofContexts.Namespace, ImmutableProofContexts.NamespaceCommon], task.result.proof["@context"]);
273
+ immutableProof.proof = task.result.proof;
274
+ ObjectHelper.propertyDelete(immutableProof.proof, "@context");
275
+ if (Is.stringValue(immutableProof.proof.created)) {
276
+ proofEntity.dateCreated = immutableProof.proof.created;
277
+ }
278
+ const compacted = await JsonLdProcessor.compact(immutableProof, immutableProof["@context"]);
279
+ const verifiableCreateResult = await this._verifiableStorage.create(task.payload.identity, ObjectHelper.toBytes(compacted));
280
+ proofEntity.verifiableStorageId = verifiableCreateResult.id;
281
+ await this._proofStorage.set(proofEntity);
282
+ await this._logging?.log({
283
+ source: ImmutableProofService.CLASS_NAME,
284
+ level: "info",
285
+ ts: Date.now(),
286
+ message: "createdProof",
287
+ data: { proofId: task.payload.proofId }
288
+ });
289
+ await this._eventBusComponent?.publish(ImmutableProofTopics.ProofCreated, { id: new Urn(ImmutableProofService._NAMESPACE, task.payload.proofId).toString() });
268
290
  }
269
- const compacted = await JsonLdProcessor.compact(immutableProof, immutableProof["@context"]);
270
- const verifiableCreateResult = await this._verifiableStorage.create(task.payload.identity, ObjectHelper.toBytes(compacted));
271
- proofEntity.verifiableStorageId = verifiableCreateResult.id;
272
- await this._proofStorage.set(proofEntity);
273
- await this._eventBusComponent?.publish(ImmutableProofTopics.ProofCreated, { id: new Urn(ImmutableProofService._NAMESPACE, task.payload.proofId).toString() });
291
+ }
292
+ else if (task.status === TaskStatus.Failed) {
293
+ await this._logging?.log({
294
+ source: ImmutableProofService.CLASS_NAME,
295
+ level: "error",
296
+ ts: Date.now(),
297
+ message: "createProofFailed",
298
+ error: BaseError.fromError(task.error)
299
+ });
274
300
  }
275
301
  }
276
302
  }
@@ -1 +1 @@
1
- {"version":3,"file":"immutableProofService.js","sourceRoot":"","sources":["../../src/immutableProofService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EAGV,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EACN,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,UAAU,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,GAAG,EACH,UAAU,EAEV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,eAAe,EAA0B,MAAM,wBAAwB,CAAC;AAC/F,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,wBAAwB,EAA2B,MAAM,2BAA2B,CAAC;AAC9F,OAAO,EACN,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EAKnB,MAAM,kCAAkC,CAAC;AAM1C,OAAO,E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,CAAC,mBAAmB,CAAC;gBAElE,yEAAyE;gBACzE,MAAM,cAAc,GAAG,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBAC3D,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC;oBAC/B,WAAW,CAAC,UAAU,CAAC,GAAG,eAAe,CAAC,eAAe,CACxD,WAAW,CAAC,UAAU,CAAC,EACvB,cAAc,CACiB,CAAC;gBAClC,CAAC;gBAED,IAAI,MAAM,IAAI,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC5C,IAAI,WAAW,CAAC,KAAK,CAAC,WAAW,KAAK,eAAe,CAAC,YAAY,EAAE,CAAC;wBACpE,OAAO,GAAG,qBAAqB,CAAC,mBAAmB,CAAC;oBACrD,CAAC;yBAAM,IAAI,WAAW,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,kBAAkB,EAAE,CAAC;wBACrE,OAAO,GAAG,qBAAqB,CAAC,iBAAiB,CAAC;oBACnD,CAAC;yBAAM,CAAC;wBACP,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAC3D,gBAAgB,EAChB,WAAW,CAAC,KAAK,CACjB,CAAC;wBAEF,IAAI,UAAU,EAAE,CAAC;4BAChB,QAAQ,GAAG,IAAI,CAAC;4BAChB,OAAO,GAAG,SAAS,CAAC;wBACrB,CAAC;6BAAM,CAAC;4BACP,OAAO,GAAG,qBAAqB,CAAC,iBAAiB,CAAC;wBACnD,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO;YACN,cAAc,EAAE,WAAW;YAC3B,QAAQ;YACR,OAAO;SACP,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tTaskStatus,\n\ttype IBackgroundTask,\n\ttype IBackgroundTaskComponent\n} from \"@twin.org/background-task-models\";\nimport { ContextIdHelper, ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tComponentFactory,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tJsonHelper,\n\tNotFoundError,\n\tObjectHelper,\n\tRandomHelper,\n\tUrn,\n\tValidation,\n\ttype IValidationFailure\n} from \"@twin.org/core\";\nimport { Sha256 } from \"@twin.org/crypto\";\nimport { JsonLdHelper, JsonLdProcessor, type IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport type { IEventBusComponent } from \"@twin.org/event-bus-models\";\nimport { IdentityConnectorFactory, type IIdentityConnector } from \"@twin.org/identity-models\";\nimport {\n\tImmutableProofContexts,\n\tImmutableProofFailure,\n\tImmutableProofTopics,\n\tImmutableProofTypes,\n\ttype IImmutableProof,\n\ttype IImmutableProofComponent,\n\ttype IImmutableProofEventBusProofCreated,\n\ttype IImmutableProofVerification\n} from \"@twin.org/immutable-proof-models\";\nimport type {\n\tIImmutableProofTaskPayload,\n\tIImmutableProofTaskResult\n} from \"@twin.org/immutable-proof-task\";\nimport { nameof, nameofKebabCase } from \"@twin.org/nameof\";\nimport { DidCryptoSuites, ProofTypes } from \"@twin.org/standards-w3c-did\";\nimport {\n\tVerifiableStorageConnectorFactory,\n\ttype IVerifiableStorageConnector\n} from \"@twin.org/verifiable-storage-models\";\nimport type { ImmutableProof } from \"./entities/immutableProof.js\";\nimport type { IImmutableProofServiceConfig } from \"./models/IImmutableProofServiceConfig.js\";\nimport type { IImmutableProofServiceConstructorOptions } from \"./models/IImmutableProofServiceConstructorOptions.js\";\n\n/**\n * Class for performing immutable proof operations.\n */\nexport class ImmutableProofService implements IImmutableProofComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ImmutableProofService>();\n\n\t/**\n\t * The namespace for the service.\n\t * @internal\n\t */\n\tprivate static readonly _NAMESPACE: string = \"immutable-proof\";\n\n\t/**\n\t * The configuration for the connector.\n\t * @internal\n\t */\n\tprivate readonly _config: IImmutableProofServiceConfig;\n\n\t/**\n\t * The identity connector.\n\t * @internal\n\t */\n\tprivate readonly _identityConnector: IIdentityConnector;\n\n\t/**\n\t * The entity storage for proofs.\n\t * @internal\n\t */\n\tprivate readonly _proofStorage: IEntityStorageConnector<ImmutableProof>;\n\n\t/**\n\t * The verifiable storage for the credentials.\n\t * @internal\n\t */\n\tprivate readonly _verifiableStorage: IVerifiableStorageConnector;\n\n\t/**\n\t * The background task component.\n\t * @internal\n\t */\n\tprivate readonly _backgroundTaskComponent: IBackgroundTaskComponent;\n\n\t/**\n\t * The event bus component.\n\t * @internal\n\t */\n\tprivate readonly _eventBusComponent?: IEventBusComponent;\n\n\t/**\n\t * The verification method id to use for the proofs.\n\t * @internal\n\t */\n\tprivate readonly _verificationMethodId: string;\n\n\t/**\n\t * The identity connector type.\n\t * @internal\n\t */\n\tprivate readonly _identityConnectorType: string;\n\n\t/**\n\t * Create a new instance of ImmutableProofService.\n\t * @param options The dependencies for the immutable proof connector.\n\t */\n\tconstructor(options?: IImmutableProofServiceConstructorOptions) {\n\t\tthis._proofStorage = EntityStorageConnectorFactory.get(\n\t\t\toptions?.immutableProofEntityStorageType ?? nameofKebabCase<ImmutableProof>()\n\t\t);\n\n\t\tthis._verifiableStorage = VerifiableStorageConnectorFactory.get(\n\t\t\toptions?.verifiableStorageType ?? \"verifiable-storage\"\n\t\t);\n\n\t\tthis._identityConnectorType = options?.identityConnectorType ?? \"identity\";\n\n\t\tthis._identityConnector = IdentityConnectorFactory.get(this._identityConnectorType);\n\n\t\tthis._backgroundTaskComponent = ComponentFactory.get(\n\t\t\toptions?.backgroundTaskComponentType ?? \"background-task\"\n\t\t);\n\n\t\tif (Is.stringValue(options?.eventBusComponentType)) {\n\t\t\tthis._eventBusComponent = ComponentFactory.get(options.eventBusComponentType);\n\t\t}\n\n\t\tthis._config = options?.config ?? {};\n\t\tthis._verificationMethodId = this._config.verificationMethodId ?? \"immutable-proof-assertion\";\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 ImmutableProofService.CLASS_NAME;\n\t}\n\n\t/**\n\t * The component needs to be started when the node is initialized.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns Nothing.\n\t */\n\tpublic async start(nodeLoggingComponentType?: string): Promise<void> {\n\t\tawait this._backgroundTaskComponent.registerHandler<\n\t\t\tIImmutableProofTaskPayload,\n\t\t\tIImmutableProofTaskResult\n\t\t>(\"immutable-proof\", \"@twin.org/immutable-proof-task\", \"processProofTask\", async task => {\n\t\t\tawait this.finaliseTask(task);\n\t\t});\n\t}\n\n\t/**\n\t * Create a new proof.\n\t * @param document The document to create the proof for.\n\t * @returns The id of the new proof.\n\t */\n\tpublic async create(document: IJsonLdNodeObject): Promise<string> {\n\t\tGuards.object<IJsonLdNodeObject>(ImmutableProofService.CLASS_NAME, nameof(document), document);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tContextIdHelper.guard(contextIds, ContextIdKeys.Organization);\n\n\t\ttry {\n\t\t\tconst validationFailures: IValidationFailure[] = [];\n\t\t\tawait JsonLdHelper.validate(document, validationFailures);\n\t\t\tValidation.asValidationError(\n\t\t\t\tImmutableProofService.CLASS_NAME,\n\t\t\t\tnameof(document),\n\t\t\t\tvalidationFailures\n\t\t\t);\n\n\t\t\tconst id = Converter.bytesToHex(RandomHelper.generate(32), false);\n\n\t\t\tconst dateCreated = new Date(Date.now()).toISOString();\n\n\t\t\tconst proofObjectId = ObjectHelper.extractProperty<string>(document, [\"@id\", \"id\"], false);\n\n\t\t\t// We don't want to store the whole document in the immutable proof, as this could be large\n\t\t\t// and also reveal information that should not be stored in the proof so we hash the document\n\t\t\t// and store the hash\n\t\t\tconst proofObjectHash = this.calculateDocumentHash(document);\n\n\t\t\tconst proofEntity: ImmutableProof = {\n\t\t\t\tid,\n\t\t\t\tdateCreated,\n\t\t\t\tproofObjectId,\n\t\t\t\tproofObjectHash\n\t\t\t};\n\t\t\tawait this._proofStorage.set(proofEntity);\n\n\t\t\tconst immutableProof = this.proofEntityToJsonLd(proofEntity);\n\n\t\t\tconst proofTaskPayload: IImmutableProofTaskPayload = {\n\t\t\t\tproofId: id,\n\t\t\t\tidentity: contextIds[ContextIdKeys.Organization],\n\t\t\t\tidentityConnectorType: this._identityConnectorType,\n\t\t\t\tverificationMethodId: this._verificationMethodId,\n\t\t\t\tdocument: immutableProof as unknown as IJsonLdNodeObject\n\t\t\t};\n\n\t\t\tawait this._backgroundTaskComponent.create(\"immutable-proof\", proofTaskPayload);\n\n\t\t\treturn new Urn(ImmutableProofService._NAMESPACE, id).toString();\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"createFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get a proof.\n\t * @param id The id of the proof to get.\n\t * @returns The proof.\n\t * @throws NotFoundError if the proof is not found.\n\t */\n\tpublic async get(id: string): Promise<IImmutableProof> {\n\t\tGuards.stringValue(ImmutableProofService.CLASS_NAME, nameof(id), id);\n\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tif (urnParsed.namespaceIdentifier() !== ImmutableProofService._NAMESPACE) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: ImmutableProofService._NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst { immutableProof } = await this.internalGet(id, false);\n\n\t\t\tconst result = await JsonLdProcessor.compact(immutableProof, immutableProof[\"@context\"]);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"getFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Verify a proof.\n\t * @param id The id of the proof to verify.\n\t * @returns The result of the verification and any failures.\n\t * @throws NotFoundError if the proof is not found.\n\t */\n\tpublic async verify(id: string): Promise<IImmutableProofVerification> {\n\t\tGuards.stringValue(ImmutableProofService.CLASS_NAME, nameof(id), id);\n\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tif (urnParsed.namespaceIdentifier() !== ImmutableProofService._NAMESPACE) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: ImmutableProofService._NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst { verified, failure } = await this.internalGet(id, true);\n\n\t\t\treturn {\n\t\t\t\t\"@context\": ImmutableProofContexts.ContextRoot,\n\t\t\t\ttype: ImmutableProofTypes.ImmutableProofVerification,\n\t\t\t\tverified,\n\t\t\t\tfailure\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"verifyFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Remove the verifiable storage for the proof.\n\t * @param id The id of the proof to remove the storage from.\n\t * @returns Nothing.\n\t * @throws NotFoundError if the proof is not found.\n\t */\n\tpublic async removeVerifiable(id: string): Promise<void> {\n\t\tGuards.stringValue(ImmutableProofService.CLASS_NAME, nameof(id), id);\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tContextIdHelper.guard(contextIds, ContextIdKeys.Organization);\n\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tif (urnParsed.namespaceIdentifier() !== ImmutableProofService._NAMESPACE) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: ImmutableProofService._NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst streamId = urnParsed.namespaceSpecific(0);\n\t\t\tconst streamEntity = await this._proofStorage.get(streamId);\n\n\t\t\tif (Is.empty(streamEntity)) {\n\t\t\t\tthrow new NotFoundError(ImmutableProofService.CLASS_NAME, \"proofNotFound\", id);\n\t\t\t}\n\n\t\t\tif (Is.stringValue(streamEntity.verifiableStorageId)) {\n\t\t\t\tawait this._verifiableStorage.remove(\n\t\t\t\t\tcontextIds[ContextIdKeys.Organization],\n\t\t\t\t\tstreamEntity.verifiableStorageId\n\t\t\t\t);\n\t\t\t\tdelete streamEntity.verifiableStorageId;\n\t\t\t\tawait this._proofStorage.set(streamEntity);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tImmutableProofService.CLASS_NAME,\n\t\t\t\t\"removeVerifiableFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Calculate the object hash.\n\t * @param object The entry to calculate the hash for.\n\t * @returns The hash.\n\t * @internal\n\t */\n\tprivate calculateDocumentHash(nodeObject: IJsonLdNodeObject): string {\n\t\treturn `sha256:${Converter.bytesToBase64(Sha256.sum256(ObjectHelper.toBytes(JsonHelper.canonicalize(nodeObject))))}`;\n\t}\n\n\t/**\n\t * Map the stream entity to a model.\n\t * @param proofEntity The stream entity.\n\t * @returns The model.\n\t * @internal\n\t */\n\tprivate proofEntityToJsonLd(proofEntity: ImmutableProof): IImmutableProof {\n\t\tconst jsonLd: IImmutableProof = {\n\t\t\t\"@context\": [ImmutableProofContexts.ContextRoot, ImmutableProofContexts.ContextRootCommon],\n\t\t\ttype: ImmutableProofTypes.ImmutableProof,\n\t\t\tid: proofEntity.id,\n\t\t\tproofObjectId: proofEntity.proofObjectId,\n\t\t\tproofObjectHash: proofEntity.proofObjectHash,\n\t\t\tverifiableStorageId: proofEntity.verifiableStorageId\n\t\t};\n\n\t\treturn jsonLd;\n\t}\n\n\t/**\n\t * Process a proof.\n\t * @param proofEntity The proof entity to process.\n\t * @internal\n\t */\n\tprivate async finaliseTask(\n\t\ttask: IBackgroundTask<IImmutableProofTaskPayload, IImmutableProofTaskResult>\n\t): Promise<void> {\n\t\tif (task.status === TaskStatus.Success && Is.object(task.payload) && Is.object(task.result)) {\n\t\t\tconst proofEntity = await this._proofStorage.get(task.payload.proofId);\n\n\t\t\tif (Is.object(proofEntity)) {\n\t\t\t\tconst immutableProof: IImmutableProof = this.proofEntityToJsonLd(proofEntity);\n\n\t\t\t\t// As we are adding the proof to the data we update its context\n\t\t\t\timmutableProof[\"@context\"] = JsonLdProcessor.combineContexts(\n\t\t\t\t\t[ImmutableProofContexts.ContextRoot, ImmutableProofContexts.ContextRootCommon],\n\t\t\t\t\ttask.result.proof[\"@context\"]\n\t\t\t\t) as IImmutableProof[\"@context\"];\n\t\t\t\timmutableProof.proof = task.result.proof;\n\t\t\t\tObjectHelper.propertyDelete(immutableProof.proof, \"@context\");\n\n\t\t\t\tif (Is.stringValue(immutableProof.proof.created)) {\n\t\t\t\t\tproofEntity.dateCreated = immutableProof.proof.created;\n\t\t\t\t}\n\n\t\t\t\tconst compacted = await JsonLdProcessor.compact(immutableProof, immutableProof[\"@context\"]);\n\n\t\t\t\tconst verifiableCreateResult = await this._verifiableStorage.create(\n\t\t\t\t\ttask.payload.identity,\n\t\t\t\t\tObjectHelper.toBytes(compacted)\n\t\t\t\t);\n\n\t\t\t\tproofEntity.verifiableStorageId = verifiableCreateResult.id;\n\n\t\t\t\tawait this._proofStorage.set(proofEntity);\n\n\t\t\t\tawait this._eventBusComponent?.publish<IImmutableProofEventBusProofCreated>(\n\t\t\t\t\tImmutableProofTopics.ProofCreated,\n\t\t\t\t\t{ id: new Urn(ImmutableProofService._NAMESPACE, task.payload.proofId).toString() }\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Verify a proof.\n\t * @param id The id of the proof to verify.\n\t * @param verify Validate the proof.\n\t * @returns The result of the verification and any failures.\n\t * @throws NotFoundError if the proof is not found.\n\t * @internal\n\t */\n\tprivate async internalGet(\n\t\tid: string,\n\t\tverify: boolean\n\t): Promise<{\n\t\tverified: boolean;\n\t\tfailure?: ImmutableProofFailure;\n\t\timmutableProof: IImmutableProof;\n\t}> {\n\t\tconst urnParsed = Urn.fromValidString(id);\n\t\tconst proofId = urnParsed.namespaceSpecific(0);\n\t\tconst proofEntity = await this._proofStorage.get(proofId);\n\n\t\tif (Is.empty(proofEntity)) {\n\t\t\tthrow new NotFoundError(ImmutableProofService.CLASS_NAME, \"proofNotFound\", id);\n\t\t}\n\n\t\tlet proofJsonLd = this.proofEntityToJsonLd(proofEntity);\n\t\tlet verified = false;\n\t\tlet failure: ImmutableProofFailure | undefined = ImmutableProofFailure.NotIssued;\n\n\t\tif (Is.stringValue(proofEntity.verifiableStorageId)) {\n\t\t\tfailure = ImmutableProofFailure.ProofMissing;\n\t\t\tconst immutableResult = await this._verifiableStorage.get(proofEntity.verifiableStorageId);\n\n\t\t\tif (Is.uint8Array(immutableResult.data)) {\n\t\t\t\tproofJsonLd = ObjectHelper.fromBytes<IImmutableProof>(immutableResult.data);\n\n\t\t\t\tconst unsecureDocument = ObjectHelper.clone(proofJsonLd) as unknown as IJsonLdNodeObject;\n\t\t\t\tproofJsonLd.immutableReceipt = immutableResult.receipt;\n\t\t\t\tproofJsonLd.verifiableStorageId = proofEntity.verifiableStorageId;\n\n\t\t\t\t// As we are adding the receipt to the data we update the JSON-LD context\n\t\t\t\tconst receiptContext = immutableResult.receipt[\"@context\"];\n\t\t\t\tif (!Is.empty(receiptContext)) {\n\t\t\t\t\tproofJsonLd[\"@context\"] = JsonLdProcessor.combineContexts(\n\t\t\t\t\t\tproofJsonLd[\"@context\"],\n\t\t\t\t\t\treceiptContext\n\t\t\t\t\t) as IImmutableProof[\"@context\"];\n\t\t\t\t}\n\n\t\t\t\tif (verify && Is.object(proofJsonLd.proof)) {\n\t\t\t\t\tif (proofJsonLd.proof.cryptosuite !== DidCryptoSuites.EdDSAJcs2022) {\n\t\t\t\t\t\tfailure = ImmutableProofFailure.CryptoSuiteMismatch;\n\t\t\t\t\t} else if (proofJsonLd.proof.type !== ProofTypes.DataIntegrityProof) {\n\t\t\t\t\t\tfailure = ImmutableProofFailure.ProofTypeMismatch;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst isVerified = await this._identityConnector.verifyProof(\n\t\t\t\t\t\t\tunsecureDocument,\n\t\t\t\t\t\t\tproofJsonLd.proof\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (isVerified) {\n\t\t\t\t\t\t\tverified = true;\n\t\t\t\t\t\t\tfailure = undefined;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tfailure = ImmutableProofFailure.SignatureMismatch;\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\t\treturn {\n\t\t\timmutableProof: proofJsonLd,\n\t\t\tverified,\n\t\t\tfailure\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"immutableProofService.js","sourceRoot":"","sources":["../../src/immutableProofService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EAGV,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnF,OAAO,EACN,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,UAAU,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,GAAG,EACH,UAAU,EAEV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,eAAe,EAA0B,MAAM,wBAAwB,CAAC;AAC/F,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,wBAAwB,EAA2B,MAAM,2BAA2B,CAAC;AAC9F,OAAO,EACN,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAm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AAK,CAAC,EAAE,CAAC;oBAC5C,IAAI,WAAW,CAAC,KAAK,CAAC,WAAW,KAAK,eAAe,CAAC,YAAY,EAAE,CAAC;wBACpE,OAAO,GAAG,qBAAqB,CAAC,mBAAmB,CAAC;oBACrD,CAAC;yBAAM,IAAI,WAAW,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,kBAAkB,EAAE,CAAC;wBACrE,OAAO,GAAG,qBAAqB,CAAC,iBAAiB,CAAC;oBACnD,CAAC;yBAAM,CAAC;wBACP,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAC3D,gBAAgB,EAChB,WAAW,CAAC,KAAK,CACjB,CAAC;wBAEF,IAAI,UAAU,EAAE,CAAC;4BAChB,QAAQ,GAAG,IAAI,CAAC;4BAChB,OAAO,GAAG,SAAS,CAAC;wBACrB,CAAC;6BAAM,CAAC;4BACP,OAAO,GAAG,qBAAqB,CAAC,iBAAiB,CAAC;wBACnD,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO;YACN,cAAc,EAAE,WAAW;YAC3B,QAAQ;YACR,OAAO;SACP,CAAC;IACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tTaskStatus,\n\ttype IBackgroundTask,\n\ttype IBackgroundTaskComponent\n} from \"@twin.org/background-task-models\";\nimport { ContextIdHelper, ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport {\n\tBaseError,\n\tComponentFactory,\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tJsonHelper,\n\tNotFoundError,\n\tObjectHelper,\n\tRandomHelper,\n\tUrn,\n\tValidation,\n\ttype IValidationFailure\n} from \"@twin.org/core\";\nimport { Sha256 } from \"@twin.org/crypto\";\nimport { JsonLdHelper, JsonLdProcessor, type IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport type { IEventBusComponent } from \"@twin.org/event-bus-models\";\nimport { IdentityConnectorFactory, type IIdentityConnector } from \"@twin.org/identity-models\";\nimport {\n\tImmutableProofContexts,\n\tImmutableProofFailure,\n\tImmutableProofTopics,\n\tImmutableProofTypes,\n\ttype IImmutableProof,\n\ttype IImmutableProofComponent,\n\ttype IImmutableProofEventBusProofCreated,\n\ttype IImmutableProofVerification\n} from \"@twin.org/immutable-proof-models\";\nimport type {\n\tIImmutableProofTaskPayload,\n\tIImmutableProofTaskResult\n} from \"@twin.org/immutable-proof-task\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof, nameofKebabCase } from \"@twin.org/nameof\";\nimport { DidCryptoSuites, ProofTypes } from \"@twin.org/standards-w3c-did\";\nimport {\n\tVerifiableStorageConnectorFactory,\n\ttype IVerifiableStorageConnector\n} from \"@twin.org/verifiable-storage-models\";\nimport type { ImmutableProof } from \"./entities/immutableProof.js\";\nimport type { IImmutableProofServiceConfig } from \"./models/IImmutableProofServiceConfig.js\";\nimport type { IImmutableProofServiceConstructorOptions } from \"./models/IImmutableProofServiceConstructorOptions.js\";\n\n/**\n * Class for performing immutable proof operations.\n */\nexport class ImmutableProofService implements IImmutableProofComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ImmutableProofService>();\n\n\t/**\n\t * The namespace for the service.\n\t * @internal\n\t */\n\tprivate static readonly _NAMESPACE: string = \"immutable-proof\";\n\n\t/**\n\t * The configuration for the connector.\n\t * @internal\n\t */\n\tprivate readonly _config: IImmutableProofServiceConfig;\n\n\t/**\n\t * The logging component.\n\t * @internal\n\t */\n\tprivate readonly _logging?: ILoggingComponent;\n\n\t/**\n\t * The identity connector.\n\t * @internal\n\t */\n\tprivate readonly _identityConnector: IIdentityConnector;\n\n\t/**\n\t * The entity storage for proofs.\n\t * @internal\n\t */\n\tprivate readonly _proofStorage: IEntityStorageConnector<ImmutableProof>;\n\n\t/**\n\t * The verifiable storage for the credentials.\n\t * @internal\n\t */\n\tprivate readonly _verifiableStorage: IVerifiableStorageConnector;\n\n\t/**\n\t * The background task component.\n\t * @internal\n\t */\n\tprivate readonly _backgroundTaskComponent: IBackgroundTaskComponent;\n\n\t/**\n\t * The event bus component.\n\t * @internal\n\t */\n\tprivate readonly _eventBusComponent?: IEventBusComponent;\n\n\t/**\n\t * The verification method id to use for the proofs.\n\t * @internal\n\t */\n\tprivate readonly _verificationMethodId: string;\n\n\t/**\n\t * The identity connector type.\n\t * @internal\n\t */\n\tprivate readonly _identityConnectorType: string;\n\n\t/**\n\t * Create a new instance of ImmutableProofService.\n\t * @param options The dependencies for the immutable proof connector.\n\t */\n\tconstructor(options?: IImmutableProofServiceConstructorOptions) {\n\t\tthis._proofStorage = EntityStorageConnectorFactory.get(\n\t\t\toptions?.immutableProofEntityStorageType ?? nameofKebabCase<ImmutableProof>()\n\t\t);\n\n\t\tthis._verifiableStorage = VerifiableStorageConnectorFactory.get(\n\t\t\toptions?.verifiableStorageType ?? \"verifiable-storage\"\n\t\t);\n\n\t\tthis._logging = ComponentFactory.getIfExists<ILoggingComponent>(\n\t\t\toptions?.loggingComponentType ?? \"logging\"\n\t\t);\n\n\t\tthis._identityConnectorType = options?.identityConnectorType ?? \"identity\";\n\n\t\tthis._identityConnector = IdentityConnectorFactory.get(this._identityConnectorType);\n\n\t\tthis._backgroundTaskComponent = ComponentFactory.get(\n\t\t\toptions?.backgroundTaskComponentType ?? \"background-task\"\n\t\t);\n\n\t\tif (Is.stringValue(options?.eventBusComponentType)) {\n\t\t\tthis._eventBusComponent = ComponentFactory.get(options.eventBusComponentType);\n\t\t}\n\n\t\tthis._config = options?.config ?? {};\n\t\tthis._verificationMethodId = this._config.verificationMethodId ?? \"immutable-proof-assertion\";\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 ImmutableProofService.CLASS_NAME;\n\t}\n\n\t/**\n\t * The component needs to be started when the node is initialized.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns Nothing.\n\t */\n\tpublic async start(nodeLoggingComponentType?: string): Promise<void> {\n\t\tawait this._backgroundTaskComponent.registerHandler<\n\t\t\tIImmutableProofTaskPayload,\n\t\t\tIImmutableProofTaskResult\n\t\t>(\"immutable-proof\", \"@twin.org/immutable-proof-task\", \"processProofTask\", async task => {\n\t\t\tawait this.finaliseTask(task);\n\t\t});\n\t}\n\n\t/**\n\t * Create a new proof.\n\t * @param document The document to create the proof for.\n\t * @returns The id of the new proof.\n\t */\n\tpublic async create(document: IJsonLdNodeObject): Promise<string> {\n\t\tGuards.object<IJsonLdNodeObject>(ImmutableProofService.CLASS_NAME, nameof(document), document);\n\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tContextIdHelper.guard(contextIds, ContextIdKeys.Organization);\n\n\t\ttry {\n\t\t\tconst validationFailures: IValidationFailure[] = [];\n\t\t\tawait JsonLdHelper.validate(document, validationFailures);\n\t\t\tValidation.asValidationError(\n\t\t\t\tImmutableProofService.CLASS_NAME,\n\t\t\t\tnameof(document),\n\t\t\t\tvalidationFailures\n\t\t\t);\n\n\t\t\tconst id = Converter.bytesToHex(RandomHelper.generate(32), false);\n\n\t\t\tconst dateCreated = new Date(Date.now()).toISOString();\n\n\t\t\tconst proofObjectId = ObjectHelper.extractProperty<string>(document, [\"@id\", \"id\"], false);\n\n\t\t\t// We don't want to store the whole document in the immutable proof, as this could be large\n\t\t\t// and also reveal information that should not be stored in the proof so we hash the document\n\t\t\t// and store the hash\n\t\t\tconst proofObjectHash = this.calculateDocumentHash(document);\n\n\t\t\tconst proofEntity: ImmutableProof = {\n\t\t\t\tid,\n\t\t\t\tdateCreated,\n\t\t\t\tproofObjectId,\n\t\t\t\tproofObjectHash\n\t\t\t};\n\t\t\tawait this._proofStorage.set(proofEntity);\n\n\t\t\tconst immutableProof = this.proofEntityToJsonLd(proofEntity);\n\n\t\t\tconst proofTaskPayload: IImmutableProofTaskPayload = {\n\t\t\t\tproofId: id,\n\t\t\t\tidentity: contextIds[ContextIdKeys.Organization],\n\t\t\t\tidentityConnectorType: this._identityConnectorType,\n\t\t\t\tverificationMethodId: this._verificationMethodId,\n\t\t\t\tdocument: immutableProof as unknown as IJsonLdNodeObject\n\t\t\t};\n\n\t\t\tawait this._backgroundTaskComponent.create(\"immutable-proof\", proofTaskPayload, {\n\t\t\t\tretainFor: 5000\n\t\t\t});\n\n\t\t\treturn new Urn(ImmutableProofService._NAMESPACE, id).toString();\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"createFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get a proof.\n\t * @param id The id of the proof to get.\n\t * @returns The proof.\n\t * @throws NotFoundError if the proof is not found.\n\t */\n\tpublic async get(id: string): Promise<IImmutableProof> {\n\t\tGuards.stringValue(ImmutableProofService.CLASS_NAME, nameof(id), id);\n\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tif (urnParsed.namespaceIdentifier() !== ImmutableProofService._NAMESPACE) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: ImmutableProofService._NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst { immutableProof } = await this.internalGet(id, false);\n\n\t\t\tconst result = await JsonLdProcessor.compact(immutableProof, immutableProof[\"@context\"]);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"getFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Verify a proof.\n\t * @param id The id of the proof to verify.\n\t * @returns The result of the verification and any failures.\n\t * @throws NotFoundError if the proof is not found.\n\t */\n\tpublic async verify(id: string): Promise<IImmutableProofVerification> {\n\t\tGuards.stringValue(ImmutableProofService.CLASS_NAME, nameof(id), id);\n\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tif (urnParsed.namespaceIdentifier() !== ImmutableProofService._NAMESPACE) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: ImmutableProofService._NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst { verified, failure } = await this.internalGet(id, true);\n\n\t\t\treturn {\n\t\t\t\t\"@context\": ImmutableProofContexts.Namespace,\n\t\t\t\ttype: ImmutableProofTypes.ImmutableProofVerification,\n\t\t\t\tverified,\n\t\t\t\tfailure\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"verifyFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Remove the verifiable storage for the proof.\n\t * @param id The id of the proof to remove the storage from.\n\t * @returns Nothing.\n\t * @throws NotFoundError if the proof is not found.\n\t */\n\tpublic async removeVerifiable(id: string): Promise<void> {\n\t\tGuards.stringValue(ImmutableProofService.CLASS_NAME, nameof(id), id);\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tContextIdHelper.guard(contextIds, ContextIdKeys.Organization);\n\n\t\tconst urnParsed = Urn.fromValidString(id);\n\n\t\tif (urnParsed.namespaceIdentifier() !== ImmutableProofService._NAMESPACE) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: ImmutableProofService._NAMESPACE,\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst streamId = urnParsed.namespaceSpecific(0);\n\t\t\tconst streamEntity = await this._proofStorage.get(streamId);\n\n\t\t\tif (Is.empty(streamEntity)) {\n\t\t\t\tthrow new NotFoundError(ImmutableProofService.CLASS_NAME, \"proofNotFound\", id);\n\t\t\t}\n\n\t\t\tif (Is.stringValue(streamEntity.verifiableStorageId)) {\n\t\t\t\tawait this._verifiableStorage.remove(\n\t\t\t\t\tcontextIds[ContextIdKeys.Organization],\n\t\t\t\t\tstreamEntity.verifiableStorageId\n\t\t\t\t);\n\t\t\t\tdelete streamEntity.verifiableStorageId;\n\t\t\t\tawait this._proofStorage.set(streamEntity);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tImmutableProofService.CLASS_NAME,\n\t\t\t\t\"removeVerifiableFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Calculate the object hash.\n\t * @param object The entry to calculate the hash for.\n\t * @returns The hash.\n\t * @internal\n\t */\n\tprivate calculateDocumentHash(nodeObject: IJsonLdNodeObject): string {\n\t\treturn `sha256:${Converter.bytesToBase64(Sha256.sum256(ObjectHelper.toBytes(JsonHelper.canonicalize(nodeObject))))}`;\n\t}\n\n\t/**\n\t * Map the stream entity to a model.\n\t * @param proofEntity The stream entity.\n\t * @returns The model.\n\t * @internal\n\t */\n\tprivate proofEntityToJsonLd(proofEntity: ImmutableProof): IImmutableProof {\n\t\tconst jsonLd: IImmutableProof = {\n\t\t\t\"@context\": [ImmutableProofContexts.Namespace, ImmutableProofContexts.NamespaceCommon],\n\t\t\ttype: ImmutableProofTypes.ImmutableProof,\n\t\t\tid: proofEntity.id,\n\t\t\tproofObjectId: proofEntity.proofObjectId,\n\t\t\tproofObjectHash: proofEntity.proofObjectHash,\n\t\t\tverifiableStorageId: proofEntity.verifiableStorageId\n\t\t};\n\n\t\treturn jsonLd;\n\t}\n\n\t/**\n\t * Process a proof.\n\t * @param proofEntity The proof entity to process.\n\t * @internal\n\t */\n\tprivate async finaliseTask(\n\t\ttask: IBackgroundTask<IImmutableProofTaskPayload, IImmutableProofTaskResult>\n\t): Promise<void> {\n\t\tif (Is.object(task.payload)) {\n\t\t\tif (task.status === TaskStatus.Success && Is.object(task.result)) {\n\t\t\t\tconst proofEntity = await this._proofStorage.get(task.payload.proofId);\n\n\t\t\t\tif (Is.object(proofEntity)) {\n\t\t\t\t\tconst immutableProof: IImmutableProof = this.proofEntityToJsonLd(proofEntity);\n\n\t\t\t\t\t// As we are adding the proof to the data we update its context\n\t\t\t\t\timmutableProof[\"@context\"] = JsonLdProcessor.combineContexts(\n\t\t\t\t\t\t[ImmutableProofContexts.Namespace, ImmutableProofContexts.NamespaceCommon],\n\t\t\t\t\t\ttask.result.proof[\"@context\"]\n\t\t\t\t\t) as IImmutableProof[\"@context\"];\n\t\t\t\t\timmutableProof.proof = task.result.proof;\n\t\t\t\t\tObjectHelper.propertyDelete(immutableProof.proof, \"@context\");\n\n\t\t\t\t\tif (Is.stringValue(immutableProof.proof.created)) {\n\t\t\t\t\t\tproofEntity.dateCreated = immutableProof.proof.created;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst compacted = await JsonLdProcessor.compact(\n\t\t\t\t\t\timmutableProof,\n\t\t\t\t\t\timmutableProof[\"@context\"]\n\t\t\t\t\t);\n\n\t\t\t\t\tconst verifiableCreateResult = await this._verifiableStorage.create(\n\t\t\t\t\t\ttask.payload.identity,\n\t\t\t\t\t\tObjectHelper.toBytes(compacted)\n\t\t\t\t\t);\n\n\t\t\t\t\tproofEntity.verifiableStorageId = verifiableCreateResult.id;\n\n\t\t\t\t\tawait this._proofStorage.set(proofEntity);\n\n\t\t\t\t\tawait this._logging?.log({\n\t\t\t\t\t\tsource: ImmutableProofService.CLASS_NAME,\n\t\t\t\t\t\tlevel: \"info\",\n\t\t\t\t\t\tts: Date.now(),\n\t\t\t\t\t\tmessage: \"createdProof\",\n\t\t\t\t\t\tdata: { proofId: task.payload.proofId }\n\t\t\t\t\t});\n\n\t\t\t\t\tawait this._eventBusComponent?.publish<IImmutableProofEventBusProofCreated>(\n\t\t\t\t\t\tImmutableProofTopics.ProofCreated,\n\t\t\t\t\t\t{ id: new Urn(ImmutableProofService._NAMESPACE, task.payload.proofId).toString() }\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (task.status === TaskStatus.Failed) {\n\t\t\t\tawait this._logging?.log({\n\t\t\t\t\tsource: ImmutableProofService.CLASS_NAME,\n\t\t\t\t\tlevel: \"error\",\n\t\t\t\t\tts: Date.now(),\n\t\t\t\t\tmessage: \"createProofFailed\",\n\t\t\t\t\terror: BaseError.fromError(task.error)\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Verify a proof.\n\t * @param id The id of the proof to verify.\n\t * @param verify Validate the proof.\n\t * @returns The result of the verification and any failures.\n\t * @throws NotFoundError if the proof is not found.\n\t * @internal\n\t */\n\tprivate async internalGet(\n\t\tid: string,\n\t\tverify: boolean\n\t): Promise<{\n\t\tverified: boolean;\n\t\tfailure?: ImmutableProofFailure;\n\t\timmutableProof: IImmutableProof;\n\t}> {\n\t\tconst urnParsed = Urn.fromValidString(id);\n\t\tconst proofId = urnParsed.namespaceSpecific(0);\n\t\tconst proofEntity = await this._proofStorage.get(proofId);\n\n\t\tif (Is.empty(proofEntity)) {\n\t\t\tthrow new NotFoundError(ImmutableProofService.CLASS_NAME, \"proofNotFound\", id);\n\t\t}\n\n\t\tlet proofJsonLd = this.proofEntityToJsonLd(proofEntity);\n\t\tlet verified = false;\n\t\tlet failure: ImmutableProofFailure | undefined = ImmutableProofFailure.NotIssued;\n\n\t\tif (Is.stringValue(proofEntity.verifiableStorageId)) {\n\t\t\tfailure = ImmutableProofFailure.ProofMissing;\n\t\t\tconst immutableResult = await this._verifiableStorage.get(proofEntity.verifiableStorageId);\n\n\t\t\tif (Is.uint8Array(immutableResult.data)) {\n\t\t\t\tproofJsonLd = ObjectHelper.fromBytes<IImmutableProof>(immutableResult.data);\n\n\t\t\t\tconst unsecureDocument = ObjectHelper.clone(proofJsonLd) as unknown as IJsonLdNodeObject;\n\t\t\t\tproofJsonLd.immutableReceipt = immutableResult.receipt;\n\t\t\t\tproofJsonLd.verifiableStorageId = proofEntity.verifiableStorageId;\n\n\t\t\t\t// As we are adding the receipt to the data we update the JSON-LD context\n\t\t\t\tconst receiptContext = immutableResult.receipt[\"@context\"];\n\t\t\t\tif (!Is.empty(receiptContext)) {\n\t\t\t\t\tproofJsonLd[\"@context\"] = JsonLdProcessor.combineContexts(\n\t\t\t\t\t\tproofJsonLd[\"@context\"],\n\t\t\t\t\t\treceiptContext\n\t\t\t\t\t) as IImmutableProof[\"@context\"];\n\t\t\t\t}\n\n\t\t\t\tif (verify && Is.object(proofJsonLd.proof)) {\n\t\t\t\t\tif (proofJsonLd.proof.cryptosuite !== DidCryptoSuites.EdDSAJcs2022) {\n\t\t\t\t\t\tfailure = ImmutableProofFailure.CryptoSuiteMismatch;\n\t\t\t\t\t} else if (proofJsonLd.proof.type !== ProofTypes.DataIntegrityProof) {\n\t\t\t\t\t\tfailure = ImmutableProofFailure.ProofTypeMismatch;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst isVerified = await this._identityConnector.verifyProof(\n\t\t\t\t\t\t\tunsecureDocument,\n\t\t\t\t\t\t\tproofJsonLd.proof\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (isVerified) {\n\t\t\t\t\t\t\tverified = true;\n\t\t\t\t\t\t\tfailure = undefined;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tfailure = ImmutableProofFailure.SignatureMismatch;\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\t\treturn {\n\t\t\timmutableProof: proofJsonLd,\n\t\t\tverified,\n\t\t\tfailure\n\t\t};\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"IImmutableProofServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IImmutableProofServiceConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IImmutableProofServiceConfig } from \"./IImmutableProofServiceConfig.js\";\n\n/**\n * Options for the immutable proof service constructor.\n */\nexport interface IImmutableProofServiceConstructorOptions {\n\t/**\n\t * The entity storage for proofs.\n\t * @default immutable-proof\n\t */\n\timmutableProofEntityStorageType?: string;\n\n\t/**\n\t * The verifiable storage.\n\t * @default verifiable-storage\n\t */\n\tverifiableStorageType?: string;\n\n\t/**\n\t * The identity connector type.\n\t * @default identity\n\t */\n\tidentityConnectorType?: string;\n\n\t/**\n\t * The background task component type.\n\t * @default background-task\n\t */\n\tbackgroundTaskComponentType?: string;\n\n\t/**\n\t * The event bus component type, defaults to no event bus.\n\t */\n\teventBusComponentType?: string;\n\n\t/**\n\t * The configuration for the connector.\n\t */\n\tconfig?: IImmutableProofServiceConfig;\n}\n"]}
1
+ {"version":3,"file":"IImmutableProofServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IImmutableProofServiceConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IImmutableProofServiceConfig } from \"./IImmutableProofServiceConfig.js\";\n\n/**\n * Options for the immutable proof service constructor.\n */\nexport interface IImmutableProofServiceConstructorOptions {\n\t/**\n\t * The entity storage for proofs.\n\t * @default immutable-proof\n\t */\n\timmutableProofEntityStorageType?: string;\n\n\t/**\n\t * The verifiable storage.\n\t * @default verifiable-storage\n\t */\n\tverifiableStorageType?: string;\n\n\t/**\n\t * The logging component type.\n\t * @default logging\n\t */\n\tloggingComponentType?: string;\n\n\t/**\n\t * The identity connector type.\n\t * @default identity\n\t */\n\tidentityConnectorType?: string;\n\n\t/**\n\t * The background task component type.\n\t * @default background-task\n\t */\n\tbackgroundTaskComponentType?: string;\n\n\t/**\n\t * The event bus component type, defaults to no event bus.\n\t */\n\teventBusComponentType?: string;\n\n\t/**\n\t * The configuration for the connector.\n\t */\n\tconfig?: IImmutableProofServiceConfig;\n}\n"]}
@@ -13,6 +13,11 @@ export interface IImmutableProofServiceConstructorOptions {
13
13
  * @default verifiable-storage
14
14
  */
15
15
  verifiableStorageType?: string;
16
+ /**
17
+ * The logging component type.
18
+ * @default logging
19
+ */
20
+ loggingComponentType?: string;
16
21
  /**
17
22
  * The identity connector type.
18
23
  * @default identity
package/docs/changelog.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @twin.org/immutable-proof-service - Changelog
2
2
 
3
+ ## [0.0.3-next.5](https://github.com/twinfoundation/immutable-proof/compare/immutable-proof-service-v0.0.3-next.4...immutable-proof-service-v0.0.3-next.5) (2026-01-14)
4
+
5
+
6
+ ### Features
7
+
8
+ * update contexts and namespaces ([#20](https://github.com/twinfoundation/immutable-proof/issues/20)) ([d38aa69](https://github.com/twinfoundation/immutable-proof/commit/d38aa696c73e4fcc304f08fb458d5900109abcb4))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/immutable-proof-models bumped from 0.0.3-next.4 to 0.0.3-next.5
16
+ * @twin.org/immutable-proof-task bumped from 0.0.3-next.4 to 0.0.3-next.5
17
+
18
+ ## [0.0.3-next.4](https://github.com/twinfoundation/immutable-proof/compare/immutable-proof-service-v0.0.3-next.3...immutable-proof-service-v0.0.3-next.4) (2026-01-07)
19
+
20
+
21
+ ### Features
22
+
23
+ * add logging ([#18](https://github.com/twinfoundation/immutable-proof/issues/18)) ([e331ce8](https://github.com/twinfoundation/immutable-proof/commit/e331ce843393554750c2708ebce1273056b6399a))
24
+
25
+
26
+ ### Dependencies
27
+
28
+ * The following workspace dependencies were updated
29
+ * dependencies
30
+ * @twin.org/immutable-proof-models bumped from 0.0.3-next.3 to 0.0.3-next.4
31
+ * @twin.org/immutable-proof-task bumped from 0.0.3-next.3 to 0.0.3-next.4
32
+
3
33
  ## [0.0.3-next.3](https://github.com/twinfoundation/immutable-proof/compare/immutable-proof-service-v0.0.3-next.2...immutable-proof-service-v0.0.3-next.3) (2025-11-28)
4
34
 
5
35
 
@@ -32,6 +32,20 @@ verifiable-storage
32
32
 
33
33
  ***
34
34
 
35
+ ### loggingComponentType?
36
+
37
+ > `optional` **loggingComponentType**: `string`
38
+
39
+ The logging component type.
40
+
41
+ #### Default
42
+
43
+ ```ts
44
+ logging
45
+ ```
46
+
47
+ ***
48
+
35
49
  ### identityConnectorType?
36
50
 
37
51
  > `optional` **identityConnectorType**: `string`
package/locales/en.json CHANGED
@@ -6,7 +6,13 @@
6
6
  "getFailed": "Getting the proof failed",
7
7
  "verifyFailed": "Verifying the proof failed",
8
8
  "removeVerifiableFailed": "Removing verifiable entry from the Immutable Proof failed",
9
- "proofNotFound": "The proof with the Id \"{notFoundId}\" was not found"
9
+ "proofNotFound": "The proof with the Id \"{notFoundId}\" was not found",
10
+ "createProofFailed": "Creating the immutable proof failed"
11
+ }
12
+ },
13
+ "info": {
14
+ "immutableProofService": {
15
+ "createdProof": "The immutable proof with Id \"{proofId}\" has been created successfully"
10
16
  }
11
17
  }
12
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/immutable-proof-service",
3
- "version": "0.0.3-next.3",
3
+ "version": "0.0.3-next.5",
4
4
  "description": "Immutable proof contract implementation and REST endpoint definitions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,8 +24,9 @@
24
24
  "@twin.org/entity-storage-models": "next",
25
25
  "@twin.org/event-bus-models": "next",
26
26
  "@twin.org/identity-models": "next",
27
- "@twin.org/immutable-proof-models": "0.0.3-next.3",
28
- "@twin.org/immutable-proof-task": "0.0.3-next.3",
27
+ "@twin.org/immutable-proof-models": "0.0.3-next.5",
28
+ "@twin.org/immutable-proof-task": "0.0.3-next.5",
29
+ "@twin.org/logging-models": "next",
29
30
  "@twin.org/nameof": "next",
30
31
  "@twin.org/standards-w3c-did": "next",
31
32
  "@twin.org/vault-models": "next",