@twin.org/immutable-proof-service 0.0.3-next.14 → 0.0.3-next.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/immutableProofRoutes.js +93 -1
- package/dist/es/immutableProofRoutes.js.map +1 -1
- package/dist/es/immutableProofService.js +48 -12
- package/dist/es/immutableProofService.js.map +1 -1
- package/dist/es/models/IImmutableProofServiceConstructorOptions.js.map +1 -1
- package/dist/types/immutableProofRoutes.d.ts +18 -2
- package/dist/types/immutableProofService.d.ts +12 -6
- package/dist/types/models/IImmutableProofServiceConstructorOptions.d.ts +0 -1
- package/docs/changelog.md +69 -0
- package/docs/open-api/spec.json +220 -2
- package/docs/reference/classes/ImmutableProofService.md +37 -7
- package/docs/reference/functions/immutableProofRemove.md +31 -0
- package/docs/reference/functions/immutableProofRemoveNotarization.md +31 -0
- package/docs/reference/index.md +2 -0
- package/docs/reference/interfaces/IImmutableProofServiceConstructorOptions.md +0 -6
- package/locales/en.json +1 -0
- package/package.json +5 -5
|
@@ -220,7 +220,65 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
220
220
|
}
|
|
221
221
|
]
|
|
222
222
|
};
|
|
223
|
-
|
|
223
|
+
const removeRoute = {
|
|
224
|
+
operationId: "immutableProofRemove",
|
|
225
|
+
summary: "Remove a proof",
|
|
226
|
+
tag: tagsImmutableProof[0].name,
|
|
227
|
+
method: "DELETE",
|
|
228
|
+
path: `${baseRouteName}/:id`,
|
|
229
|
+
handler: async (httpRequestContext, request) => immutableProofRemove(httpRequestContext, componentName, request),
|
|
230
|
+
requestType: {
|
|
231
|
+
type: "IImmutableProofRemoveRequest",
|
|
232
|
+
examples: [
|
|
233
|
+
{
|
|
234
|
+
id: "immutableProofRemoveRequestExample",
|
|
235
|
+
request: {
|
|
236
|
+
pathParams: {
|
|
237
|
+
id: "immutable-proof:1234567890"
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
},
|
|
243
|
+
responseType: [
|
|
244
|
+
{
|
|
245
|
+
type: "INoContentResponse"
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
type: "INotFoundResponse"
|
|
249
|
+
}
|
|
250
|
+
]
|
|
251
|
+
};
|
|
252
|
+
const removeNotarizationRoute = {
|
|
253
|
+
operationId: "immutableProofRemoveNotarization",
|
|
254
|
+
summary: "Remove the notarization for a proof",
|
|
255
|
+
tag: tagsImmutableProof[0].name,
|
|
256
|
+
method: "DELETE",
|
|
257
|
+
path: `${baseRouteName}/:id/notarization`,
|
|
258
|
+
handler: async (httpRequestContext, request) => immutableProofRemoveNotarization(httpRequestContext, componentName, request),
|
|
259
|
+
requestType: {
|
|
260
|
+
type: "IImmutableProofRemoveNotarizationRequest",
|
|
261
|
+
examples: [
|
|
262
|
+
{
|
|
263
|
+
id: "immutableProofRemoveNotarizationRequestExample",
|
|
264
|
+
request: {
|
|
265
|
+
pathParams: {
|
|
266
|
+
id: "immutable-proof:1234567890"
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
},
|
|
272
|
+
responseType: [
|
|
273
|
+
{
|
|
274
|
+
type: "INoContentResponse"
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
type: "INotFoundResponse"
|
|
278
|
+
}
|
|
279
|
+
]
|
|
280
|
+
};
|
|
281
|
+
return [createRoute, getRoute, verifyRoute, removeRoute, removeNotarizationRoute];
|
|
224
282
|
}
|
|
225
283
|
/**
|
|
226
284
|
* Create a proof.
|
|
@@ -283,4 +341,38 @@ export async function immutableProofVerify(httpRequestContext, componentName, re
|
|
|
283
341
|
body: result
|
|
284
342
|
};
|
|
285
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Remove the proof and its notarization.
|
|
346
|
+
* @param httpRequestContext The request context for the API.
|
|
347
|
+
* @param componentName The name of the component to use in the routes.
|
|
348
|
+
* @param request The request.
|
|
349
|
+
* @returns The response object with additional http response properties.
|
|
350
|
+
*/
|
|
351
|
+
export async function immutableProofRemove(httpRequestContext, componentName, request) {
|
|
352
|
+
Guards.object(ROUTES_SOURCE, "request", request);
|
|
353
|
+
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
354
|
+
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
355
|
+
const component = ComponentFactory.get(componentName);
|
|
356
|
+
await component.remove(request.pathParams.id);
|
|
357
|
+
return {
|
|
358
|
+
statusCode: HttpStatusCode.noContent
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Remove the notarization for a proof, keeping the proof entity.
|
|
363
|
+
* @param httpRequestContext The request context for the API.
|
|
364
|
+
* @param componentName The name of the component to use in the routes.
|
|
365
|
+
* @param request The request.
|
|
366
|
+
* @returns The response object with additional http response properties.
|
|
367
|
+
*/
|
|
368
|
+
export async function immutableProofRemoveNotarization(httpRequestContext, componentName, request) {
|
|
369
|
+
Guards.object(ROUTES_SOURCE, "request", request);
|
|
370
|
+
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
371
|
+
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
372
|
+
const component = ComponentFactory.get(componentName);
|
|
373
|
+
await component.removeNotarization(request.pathParams.id);
|
|
374
|
+
return {
|
|
375
|
+
statusCode: HttpStatusCode.noContent
|
|
376
|
+
};
|
|
377
|
+
}
|
|
286
378
|
//# sourceMappingURL=immutableProofRoutes.js.map
|
|
@@ -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;AA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,EACrB,OAAqC;IAErC,MAAM,CAAC,MAAM,CAA+B,aAAa,aAAmB,OAAO,CAAC,CAAC;IACrF,MAAM,CAAC,MAAM,CACZ,aAAa,wBAEb,OAAO,CAAC,UAAU,CAClB,CAAC;IACF,MAAM,CAAC,WAAW,CAAC,aAAa,2BAAiC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAExF,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC;IAEhG,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAA2B,aAAa,CAAC,CAAC;IAChF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAE7D,OAAO;QACN,OAAO,EAAE;YACR,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,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 {\n\tDidContexts,\n\tDidCryptoSuites,\n\tProofTypes,\n\tDidTypes,\n\ttype IProof\n} 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%3A1234567890\"\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: \"immutable-proof: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\tDidContexts.ContextVCv1,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.Context,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.ContextCommon\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\ttype: [DidTypes.VerifiableCredential, ImmutableProofTypes.ImmutableProof],\n\t\t\t\t\t\t\t\tid: \"immutable-proof:1234567890\",\n\t\t\t\t\t\t\t\tcredentialSubject: {\n\t\t\t\t\t\t\t\t\tid: \"ais:1234567890\",\n\t\t\t\t\t\t\t\t\tproofIntegrity: \"EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y=\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tproof: {\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\tverificationMethod:\n\t\t\t\t\t\t\t\t\t\t\"did:iota:testnet:0xcb07cabaa2f23b7e53d8cdc4228efb351ebb270554d13bc382e4f94ca8d3136b#immutable-proof-assertion\",\n\t\t\t\t\t\t\t\t\tnotarizationId: \"notarization:iota:0xabcdef1234567890\"\n\t\t\t\t\t\t\t\t} as IProof\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\tDidContexts.ContextVCv1,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.Context,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.ContextCommon\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\ttype: [DidTypes.VerifiableCredential, ImmutableProofTypes.ImmutableProof],\n\t\t\t\t\t\t\t\tid: \"immutable-proof:1234567890\",\n\t\t\t\t\t\t\t\tcredentialSubject: {\n\t\t\t\t\t\t\t\t\tid: \"ais:1234567890\",\n\t\t\t\t\t\t\t\t\tproofIntegrity: \"EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y=\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tproof: {\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\tverificationMethod:\n\t\t\t\t\t\t\t\t\t\t\"did:iota:testnet:0xcb07cabaa2f23b7e53d8cdc4228efb351ebb270554d13bc382e4f94ca8d3136b#immutable-proof-assertion\",\n\t\t\t\t\t\t\t\t\tnotarizationId: \"notarization:iota:0xabcdef1234567890\"\n\t\t\t\t\t\t\t\t} as IProof\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: \"immutable-proof: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.Context,\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.Context,\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.VerificationFailure\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, request.body.options);\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":"AAUA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EASN,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACjG,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,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C,MAAM,CACZ,aAAa,wBAEb,OAAO,CAAC,UAAU,CAClB,CAAC;IACF,MAAM,CAAC,WAAW,CAAC,aAAa,2BAAiC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAExF,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAA2B,aAAa,CAAC,CAAC;IAChF,MAAM,SAAS,CAAC,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAE1D,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,SAAS;KACpC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tICreatedResponse,\n\tIHttpRequestContext,\n\tINoContentResponse,\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 IImmutableProofRemoveNotarizationRequest,\n\ttype IImmutableProofRemoveRequest,\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, DidTypes } 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%3A1234567890\"\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: \"immutable-proof: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\tDidContexts.ContextVCv1,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.Context,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.ContextCommon\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\ttype: [DidTypes.VerifiableCredential, ImmutableProofTypes.ImmutableProof],\n\t\t\t\t\t\t\t\tid: \"immutable-proof:1234567890\",\n\t\t\t\t\t\t\t\tcredentialSubject: {\n\t\t\t\t\t\t\t\t\tid: \"ais:1234567890\",\n\t\t\t\t\t\t\t\t\tproofIntegrity: \"EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y=\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tproof: {\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\tverificationMethod:\n\t\t\t\t\t\t\t\t\t\t\"did:iota:testnet:0xcb07cabaa2f23b7e53d8cdc4228efb351ebb270554d13bc382e4f94ca8d3136b#immutable-proof-assertion\",\n\t\t\t\t\t\t\t\t\tnotarizationId: \"notarization:iota:0xabcdef1234567890\"\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\tDidContexts.ContextVCv1,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.Context,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.ContextCommon\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\ttype: [DidTypes.VerifiableCredential, ImmutableProofTypes.ImmutableProof],\n\t\t\t\t\t\t\t\tid: \"immutable-proof:1234567890\",\n\t\t\t\t\t\t\t\tcredentialSubject: {\n\t\t\t\t\t\t\t\t\tid: \"ais:1234567890\",\n\t\t\t\t\t\t\t\t\tproofIntegrity: \"EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y=\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tproof: {\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\tverificationMethod:\n\t\t\t\t\t\t\t\t\t\t\"did:iota:testnet:0xcb07cabaa2f23b7e53d8cdc4228efb351ebb270554d13bc382e4f94ca8d3136b#immutable-proof-assertion\",\n\t\t\t\t\t\t\t\t\tnotarizationId: \"notarization:iota:0xabcdef1234567890\"\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: \"immutable-proof: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.Context,\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.Context,\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.VerificationFailure\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 removeRoute: IRestRoute<IImmutableProofRemoveRequest, INoContentResponse> = {\n\t\toperationId: \"immutableProofRemove\",\n\t\tsummary: \"Remove a proof\",\n\t\ttag: tagsImmutableProof[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\timmutableProofRemove(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IImmutableProofRemoveRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"immutableProofRemoveRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"immutable-proof: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<INoContentResponse>()\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 removeNotarizationRoute: IRestRoute<\n\t\tIImmutableProofRemoveNotarizationRequest,\n\t\tINoContentResponse\n\t> = {\n\t\toperationId: \"immutableProofRemoveNotarization\",\n\t\tsummary: \"Remove the notarization for a proof\",\n\t\ttag: tagsImmutableProof[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/:id/notarization`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\timmutableProofRemoveNotarization(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IImmutableProofRemoveNotarizationRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"immutableProofRemoveNotarizationRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"immutable-proof: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<INoContentResponse>()\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, removeRoute, removeNotarizationRoute];\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, request.body.options);\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\n/**\n * Remove the proof and its notarization.\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 immutableProofRemove(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IImmutableProofRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IImmutableProofRemoveRequest[\"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<IImmutableProofComponent>(componentName);\n\tawait component.remove(request.pathParams.id);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Remove the notarization for a proof, keeping the proof entity.\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 immutableProofRemoveNotarization(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofRemoveNotarizationRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IImmutableProofRemoveNotarizationRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IImmutableProofRemoveNotarizationRequest[\"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<IImmutableProofComponent>(componentName);\n\tawait component.removeNotarization(request.pathParams.id);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n"]}
|
|
@@ -81,7 +81,7 @@ export class ImmutableProofService {
|
|
|
81
81
|
this._proofStorage = EntityStorageConnectorFactory.get(options?.immutableProofEntityStorageType ?? "immutable-proof");
|
|
82
82
|
this._notarizationConnectorType = options?.notarizationConnectorType ?? "notarization";
|
|
83
83
|
this._notarizationConnector = NotarizationConnectorFactory.get(this._notarizationConnectorType);
|
|
84
|
-
this._logging = ComponentFactory.getIfExists(options?.loggingComponentType
|
|
84
|
+
this._logging = ComponentFactory.getIfExists(options?.loggingComponentType);
|
|
85
85
|
this._identityConnectorType = options?.identityConnectorType ?? "identity";
|
|
86
86
|
this._identityConnector = IdentityConnectorFactory.get(this._identityConnectorType);
|
|
87
87
|
this._backgroundTaskComponent = ComponentFactory.get(options?.backgroundTaskComponentType ?? "background-task");
|
|
@@ -219,12 +219,12 @@ export class ImmutableProofService {
|
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
/**
|
|
222
|
-
* Remove the
|
|
223
|
-
* @param id The id of the proof to remove
|
|
222
|
+
* Remove the proof and its notarization.
|
|
223
|
+
* @param id The id of the proof to remove.
|
|
224
224
|
* @returns Nothing.
|
|
225
225
|
* @throws NotFoundError if the proof is not found.
|
|
226
226
|
*/
|
|
227
|
-
async
|
|
227
|
+
async remove(id) {
|
|
228
228
|
Guards.stringValue(ImmutableProofService.CLASS_NAME, "id", id);
|
|
229
229
|
const contextIds = await ContextIdStore.getContextIds();
|
|
230
230
|
ContextIdHelper.guard(contextIds, ContextIdKeys.Organization);
|
|
@@ -236,15 +236,47 @@ export class ImmutableProofService {
|
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
try {
|
|
239
|
-
const
|
|
240
|
-
const
|
|
241
|
-
if (Is.empty(
|
|
239
|
+
const proofId = urnParsed.namespaceSpecific(0);
|
|
240
|
+
const proofEntity = await this._proofStorage.get(proofId);
|
|
241
|
+
if (Is.empty(proofEntity)) {
|
|
242
242
|
throw new NotFoundError(ImmutableProofService.CLASS_NAME, "proofNotFound", id);
|
|
243
243
|
}
|
|
244
|
-
if (Is.stringValue(
|
|
245
|
-
await this._notarizationConnector.remove(contextIds[ContextIdKeys.Organization],
|
|
246
|
-
|
|
247
|
-
|
|
244
|
+
if (Is.stringValue(proofEntity.notarizationId)) {
|
|
245
|
+
await this._notarizationConnector.remove(contextIds[ContextIdKeys.Organization], proofEntity.notarizationId);
|
|
246
|
+
}
|
|
247
|
+
await this._proofStorage.remove(proofId);
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
throw new GeneralError(ImmutableProofService.CLASS_NAME, "removeFailed", undefined, error);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Remove only the notarization for the proof, keeping the proof entity.
|
|
255
|
+
* @param id The id of the proof to remove the notarization from.
|
|
256
|
+
* @returns Nothing.
|
|
257
|
+
* @throws NotFoundError if the proof is not found.
|
|
258
|
+
*/
|
|
259
|
+
async removeNotarization(id) {
|
|
260
|
+
Guards.stringValue(ImmutableProofService.CLASS_NAME, "id", id);
|
|
261
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
262
|
+
ContextIdHelper.guard(contextIds, ContextIdKeys.Organization);
|
|
263
|
+
const urnParsed = Urn.fromValidString(id);
|
|
264
|
+
if (urnParsed.namespaceIdentifier() !== ImmutableProofService._NAMESPACE) {
|
|
265
|
+
throw new GeneralError(ImmutableProofService.CLASS_NAME, "namespaceMismatch", {
|
|
266
|
+
namespace: ImmutableProofService._NAMESPACE,
|
|
267
|
+
id
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
const proofId = urnParsed.namespaceSpecific(0);
|
|
272
|
+
const proofEntity = await this._proofStorage.get(proofId);
|
|
273
|
+
if (Is.empty(proofEntity)) {
|
|
274
|
+
throw new NotFoundError(ImmutableProofService.CLASS_NAME, "proofNotFound", id);
|
|
275
|
+
}
|
|
276
|
+
if (Is.stringValue(proofEntity.notarizationId)) {
|
|
277
|
+
await this._notarizationConnector.remove(contextIds[ContextIdKeys.Organization], proofEntity.notarizationId);
|
|
278
|
+
delete proofEntity.notarizationId;
|
|
279
|
+
await this._proofStorage.set(proofEntity);
|
|
248
280
|
}
|
|
249
281
|
}
|
|
250
282
|
catch (error) {
|
|
@@ -253,7 +285,7 @@ export class ImmutableProofService {
|
|
|
253
285
|
}
|
|
254
286
|
/**
|
|
255
287
|
* Process a proof.
|
|
256
|
-
* @param
|
|
288
|
+
* @param task The background task to finalise.
|
|
257
289
|
* @internal
|
|
258
290
|
*/
|
|
259
291
|
async finaliseTask(task) {
|
|
@@ -280,6 +312,10 @@ export class ImmutableProofService {
|
|
|
280
312
|
});
|
|
281
313
|
await this._eventBusComponent?.publish(ImmutableProofTopics.ProofCreated, { id: new Urn(ImmutableProofService._NAMESPACE, task.payload.proofId).toString() });
|
|
282
314
|
}
|
|
315
|
+
else if (Is.stringValue(task.result.notarizationId)) {
|
|
316
|
+
// The proof was removed before the task completed; clean up the orphaned notarization.
|
|
317
|
+
await this._notarizationConnector.remove(task.payload.identity, task.result.notarizationId);
|
|
318
|
+
}
|
|
283
319
|
}
|
|
284
320
|
else if (task.status === TaskStatus.Failed) {
|
|
285
321
|
await this._logging?.log({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"immutableProofService.js","sourceRoot":"","sources":["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: 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\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 { IntegrityAlgorithm, IntegrityHelper } 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 {\n\tNotarizationConnectorFactory,\n\ttype INotarizationConnector\n} from \"@twin.org/notarization-models\";\nimport {\n\tDidContexts,\n\tDidTypes,\n\tVerifiableCredentialHelper,\n\ttype IDidVerifiableCredential,\n\ttype IProof\n} from \"@twin.org/standards-w3c-did\";\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 notarization connector type.\n\t * @internal\n\t */\n\tprivate readonly _notarizationConnectorType: string;\n\n\t/**\n\t * The notarization connector for the credentials.\n\t * @internal\n\t */\n\tprivate readonly _notarizationConnector: INotarizationConnector;\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._notarizationConnectorType = options?.notarizationConnectorType ?? \"notarization\";\n\t\tthis._notarizationConnector = NotarizationConnectorFactory.get(this._notarizationConnectorType);\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\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 * @param options Optional settings for the proof.\n\t * @param options.deleteLock An ISO 8601 date-time string specifying when the notarization lock expires; if omitted no lock is applied.\n\t * @returns The id of the new proof.\n\t */\n\tpublic async create(\n\t\tdocument: IJsonLdNodeObject,\n\t\toptions?: { deleteLock?: string }\n\t): Promise<string> {\n\t\tGuards.object<IJsonLdNodeObject>(ImmutableProofService.CLASS_NAME, nameof(document), document);\n\n\t\tif (!Is.empty(options?.deleteLock)) {\n\t\t\tGuards.dateTimeString(\n\t\t\t\tImmutableProofService.CLASS_NAME,\n\t\t\t\tnameof(options.deleteLock),\n\t\t\t\toptions.deleteLock\n\t\t\t);\n\t\t}\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 = RandomHelper.generateUuidV7(\"compact\");\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 proofObjectIntegrity = IntegrityHelper.generate(\n\t\t\t\tIntegrityAlgorithm.Sha256,\n\t\t\t\tObjectHelper.toBytes(JsonHelper.canonicalize(document))\n\t\t\t);\n\n\t\t\tconst credentialSubject: IImmutableProof = {\n\t\t\t\t\"@context\": [ImmutableProofContexts.Context, ImmutableProofContexts.ContextCommon],\n\t\t\t\ttype: ImmutableProofTypes.ImmutableProof,\n\t\t\t\tid: proofObjectId,\n\t\t\t\tproofIntegrity: proofObjectIntegrity\n\t\t\t};\n\n\t\t\tconst proofEntity: ImmutableProof = {\n\t\t\t\tid,\n\t\t\t\torganizationId: contextIds[ContextIdKeys.Organization],\n\t\t\t\tdateCreated,\n\t\t\t\tproofObjectId,\n\t\t\t\tproofObjectIntegrity\n\t\t\t};\n\t\t\tawait this._proofStorage.set(proofEntity);\n\n\t\t\tconst fullId = new Urn(ImmutableProofService._NAMESPACE, id).toString();\n\n\t\t\tconst proofTaskPayload: IImmutableProofTaskPayload = {\n\t\t\t\tproofId: fullId,\n\t\t\t\tidentity: contextIds[ContextIdKeys.Organization],\n\t\t\t\tidentityConnectorType: this._identityConnectorType,\n\t\t\t\tnotarizationConnectorType: this._notarizationConnectorType,\n\t\t\t\tverificationMethodId: this._verificationMethodId,\n\t\t\t\tcredentialSubject,\n\t\t\t\tdeleteLockDateTime: options?.deleteLock\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 fullId;\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<IDidVerifiableCredential> {\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 { verifiableCredential } = await this.internalGet(id, false);\n\n\t\t\tconst result = await JsonLdProcessor.compact(\n\t\t\t\tverifiableCredential,\n\t\t\t\tverifiableCredential[\"@context\"]\n\t\t\t);\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.Context,\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 notarization 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.notarizationId)) {\n\t\t\t\tawait this._notarizationConnector.remove(\n\t\t\t\t\tcontextIds[ContextIdKeys.Organization],\n\t\t\t\t\tstreamEntity.notarizationId\n\t\t\t\t);\n\t\t\t\tdelete streamEntity.notarizationId;\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\"removeNotarizationFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\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 urnParsed = Urn.fromValidString(task.payload.proofId);\n\t\t\t\tconst proofId = urnParsed.namespaceSpecific(0);\n\n\t\t\t\tconst proofEntity = await this._proofStorage.get(proofId);\n\n\t\t\t\tif (Is.object(proofEntity)) {\n\t\t\t\t\tproofEntity.notarizationId = task.result.notarizationId;\n\n\t\t\t\t\t// Update the date created if we can extract it from the VC\n\t\t\t\t\tconst validFrom = VerifiableCredentialHelper.getValidFrom(\n\t\t\t\t\t\ttask.result.verifiableCredential\n\t\t\t\t\t);\n\t\t\t\t\tif (Is.stringValue(validFrom)) {\n\t\t\t\t\t\tproofEntity.dateCreated = validFrom;\n\t\t\t\t\t}\n\t\t\t\t\tproofEntity.vcContext = VerifiableCredentialHelper.getContext(\n\t\t\t\t\t\ttask.result.verifiableCredential\n\t\t\t\t\t);\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\tverifiableCredential: IDidVerifiableCredential;\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\tconst verifiableCredential: IDidVerifiableCredential = {\n\t\t\t\"@context\": [\n\t\t\t\tproofEntity.vcContext ?? DidContexts.ContextVCv1,\n\t\t\t\tImmutableProofContexts.Context,\n\t\t\t\tImmutableProofContexts.ContextCommon\n\t\t\t],\n\t\t\ttype: [DidTypes.VerifiableCredential, ImmutableProofTypes.ImmutableProof],\n\t\t\tid,\n\t\t\tissuer: proofEntity.organizationId,\n\t\t\tcredentialSubject: {\n\t\t\t\tid: proofEntity.proofObjectId,\n\t\t\t\tproofIntegrity: proofEntity.proofObjectIntegrity\n\t\t\t}\n\t\t} as IDidVerifiableCredential;\n\n\t\tVerifiableCredentialHelper.setValidFrom(verifiableCredential, proofEntity.dateCreated);\n\n\t\tlet verified = false;\n\t\tlet failure: ImmutableProofFailure | undefined = ImmutableProofFailure.NotIssued;\n\n\t\tif (Is.stringValue(proofEntity.notarizationId)) {\n\t\t\tfailure = ImmutableProofFailure.ProofMissing;\n\t\t\tconst notarization = await this._notarizationConnector.get(proofEntity.notarizationId);\n\n\t\t\tif (Is.uint8Array(notarization.data)) {\n\t\t\t\tconst proof = ObjectHelper.fromBytes<IProof>(notarization.data);\n\n\t\t\t\tconst proofWithReceipt = {\n\t\t\t\t\t...proof,\n\t\t\t\t\tverificationMethod: `${proofEntity.organizationId}#${this._verificationMethodId}`,\n\t\t\t\t\tnotarizationId: proofEntity.notarizationId\n\t\t\t\t};\n\n\t\t\t\tverifiableCredential.proof = proofWithReceipt;\n\n\t\t\t\tif (verify && Is.object<IProof>(proof)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result =\n\t\t\t\t\t\t\tawait this._identityConnector.checkVerifiableCredential(verifiableCredential);\n\t\t\t\t\t\tif (result.revoked) {\n\t\t\t\t\t\t\tverified = false;\n\t\t\t\t\t\t\tfailure = ImmutableProofFailure.Revoked;\n\t\t\t\t\t\t} else {\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}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tverified = false;\n\t\t\t\t\t\tfailure = ImmutableProofFailure.VerificationFailure;\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\tverifiableCredential: await JsonLdProcessor.compact(\n\t\t\t\tverifiableCredential,\n\t\t\t\tJsonLdProcessor.gatherContexts(verifiableCredential)\n\t\t\t),\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,YAAY,EACZ,MAAM,EACN,EAAE,EACF,UAAU,EACV,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,GAAG,EACH,UAAU,EAEV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACvE,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,EAMnB,MAAM,kCAAkC,CAAC;AAO1C,OAAO,EACN,4BAA4B,EAE5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,WAAW,EACX,QAAQ,EACR,0BAA0B,EAG1B,MAAM,6BAA6B,CAAC;AAKrC;;GAEG;AACH,MAAM,OAAO,qBAAqB;IACjC;;OAEG;IACI,MAAM,CAAU,UAAU,2BAA2C;IAE5E;;;OAGG;IACK,MAAM,CAAU,UAAU,GAAW,iBAAiB,CAAC;IAE/D;;;OAGG;IACc,OAAO,CAA+B;IAEvD;;;OAGG;IACc,QAAQ,CAAqB;IAE9C;;;OAGG;IACc,kBAAkB,CAAqB;IAExD;;;OAGG;IACc,aAAa,CAA0C;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CAAC;6BAAM,CAAC;4BACP,QAAQ,GAAG,IAAI,CAAC;4BAChB,OAAO,GAAG,SAAS,CAAC;wBACrB,CAAC;oBACF,CAAC;oBAAC,MAAM,CAAC;wBACR,QAAQ,GAAG,KAAK,CAAC;wBACjB,OAAO,GAAG,qBAAqB,CAAC,mBAAmB,CAAC;oBACrD,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO;YACN,oBAAoB,EAAE,MAAM,eAAe,CAAC,OAAO,CAClD,oBAAoB,EACpB,eAAe,CAAC,cAAc,CAAC,oBAAoB,CAAC,CACpD;YACD,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\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 { IntegrityAlgorithm, IntegrityHelper } 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 IImmutableProofCredential,\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 {\n\tNotarizationConnectorFactory,\n\ttype INotarizationConnector\n} from \"@twin.org/notarization-models\";\nimport {\n\tDidContexts,\n\tDidTypes,\n\tVerifiableCredentialHelper,\n\ttype IDidVerifiableCredential,\n\ttype IProof\n} from \"@twin.org/standards-w3c-did\";\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 notarization connector type.\n\t * @internal\n\t */\n\tprivate readonly _notarizationConnectorType: string;\n\n\t/**\n\t * The notarization connector for the credentials.\n\t * @internal\n\t */\n\tprivate readonly _notarizationConnector: INotarizationConnector;\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._notarizationConnectorType = options?.notarizationConnectorType ?? \"notarization\";\n\t\tthis._notarizationConnector = NotarizationConnectorFactory.get(this._notarizationConnectorType);\n\n\t\tthis._logging = ComponentFactory.getIfExists<ILoggingComponent>(options?.loggingComponentType);\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\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 * @param options Optional settings for the proof.\n\t * @param options.deleteLock An ISO 8601 date-time string specifying when the notarization lock expires; if omitted no lock is applied.\n\t * @returns The id of the new proof.\n\t */\n\tpublic async create(\n\t\tdocument: IJsonLdNodeObject,\n\t\toptions?: { deleteLock?: string }\n\t): Promise<string> {\n\t\tGuards.object<IJsonLdNodeObject>(ImmutableProofService.CLASS_NAME, nameof(document), document);\n\n\t\tif (!Is.empty(options?.deleteLock)) {\n\t\t\tGuards.dateTimeString(\n\t\t\t\tImmutableProofService.CLASS_NAME,\n\t\t\t\tnameof(options.deleteLock),\n\t\t\t\toptions.deleteLock\n\t\t\t);\n\t\t}\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 = RandomHelper.generateUuidV7(\"compact\");\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 proofObjectIntegrity = IntegrityHelper.generate(\n\t\t\t\tIntegrityAlgorithm.Sha256,\n\t\t\t\tObjectHelper.toBytes(JsonHelper.canonicalize(document))\n\t\t\t);\n\n\t\t\tconst credentialSubject: IImmutableProof = {\n\t\t\t\t\"@context\": [ImmutableProofContexts.Context, ImmutableProofContexts.ContextCommon],\n\t\t\t\ttype: ImmutableProofTypes.ImmutableProof,\n\t\t\t\tid: proofObjectId,\n\t\t\t\tproofIntegrity: proofObjectIntegrity\n\t\t\t};\n\n\t\t\tconst proofEntity: ImmutableProof = {\n\t\t\t\tid,\n\t\t\t\torganizationId: contextIds[ContextIdKeys.Organization],\n\t\t\t\tdateCreated,\n\t\t\t\tproofObjectId,\n\t\t\t\tproofObjectIntegrity\n\t\t\t};\n\t\t\tawait this._proofStorage.set(proofEntity);\n\n\t\t\tconst fullId = new Urn(ImmutableProofService._NAMESPACE, id).toString();\n\n\t\t\tconst proofTaskPayload: IImmutableProofTaskPayload = {\n\t\t\t\tproofId: fullId,\n\t\t\t\tidentity: contextIds[ContextIdKeys.Organization],\n\t\t\t\tidentityConnectorType: this._identityConnectorType,\n\t\t\t\tnotarizationConnectorType: this._notarizationConnectorType,\n\t\t\t\tverificationMethodId: this._verificationMethodId,\n\t\t\t\tcredentialSubject,\n\t\t\t\tdeleteLockDateTime: options?.deleteLock\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 fullId;\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<IImmutableProofCredential> {\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 { verifiableCredential } = await this.internalGet(id, false);\n\n\t\t\tconst result = await JsonLdProcessor.compact(\n\t\t\t\tverifiableCredential,\n\t\t\t\tverifiableCredential[\"@context\"]\n\t\t\t);\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.Context,\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 proof and its notarization.\n\t * @param id The id of the proof to remove.\n\t * @returns Nothing.\n\t * @throws NotFoundError if the proof is not found.\n\t */\n\tpublic async remove(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 proofId = urnParsed.namespaceSpecific(0);\n\t\t\tconst proofEntity = await this._proofStorage.get(proofId);\n\n\t\t\tif (Is.empty(proofEntity)) {\n\t\t\t\tthrow new NotFoundError(ImmutableProofService.CLASS_NAME, \"proofNotFound\", id);\n\t\t\t}\n\n\t\t\tif (Is.stringValue(proofEntity.notarizationId)) {\n\t\t\t\tawait this._notarizationConnector.remove(\n\t\t\t\t\tcontextIds[ContextIdKeys.Organization],\n\t\t\t\t\tproofEntity.notarizationId\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tawait this._proofStorage.remove(proofId);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(ImmutableProofService.CLASS_NAME, \"removeFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Remove only the notarization for the proof, keeping the proof entity.\n\t * @param id The id of the proof to remove the notarization from.\n\t * @returns Nothing.\n\t * @throws NotFoundError if the proof is not found.\n\t */\n\tpublic async removeNotarization(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 proofId = urnParsed.namespaceSpecific(0);\n\t\t\tconst proofEntity = await this._proofStorage.get(proofId);\n\n\t\t\tif (Is.empty(proofEntity)) {\n\t\t\t\tthrow new NotFoundError(ImmutableProofService.CLASS_NAME, \"proofNotFound\", id);\n\t\t\t}\n\n\t\t\tif (Is.stringValue(proofEntity.notarizationId)) {\n\t\t\t\tawait this._notarizationConnector.remove(\n\t\t\t\t\tcontextIds[ContextIdKeys.Organization],\n\t\t\t\t\tproofEntity.notarizationId\n\t\t\t\t);\n\t\t\t\tdelete proofEntity.notarizationId;\n\t\t\t\tawait this._proofStorage.set(proofEntity);\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\"removeNotarizationFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Process a proof.\n\t * @param task The background task to finalise.\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 urnParsed = Urn.fromValidString(task.payload.proofId);\n\t\t\t\tconst proofId = urnParsed.namespaceSpecific(0);\n\n\t\t\t\tconst proofEntity = await this._proofStorage.get(proofId);\n\n\t\t\t\tif (Is.object(proofEntity)) {\n\t\t\t\t\tproofEntity.notarizationId = task.result.notarizationId;\n\n\t\t\t\t\t// Update the date created if we can extract it from the VC\n\t\t\t\t\tconst validFrom = VerifiableCredentialHelper.getValidFrom(\n\t\t\t\t\t\ttask.result.verifiableCredential\n\t\t\t\t\t);\n\t\t\t\t\tif (Is.stringValue(validFrom)) {\n\t\t\t\t\t\tproofEntity.dateCreated = validFrom;\n\t\t\t\t\t}\n\t\t\t\t\tproofEntity.vcContext = VerifiableCredentialHelper.getContext(\n\t\t\t\t\t\ttask.result.verifiableCredential\n\t\t\t\t\t);\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} else if (Is.stringValue(task.result.notarizationId)) {\n\t\t\t\t\t// The proof was removed before the task completed; clean up the orphaned notarization.\n\t\t\t\t\tawait this._notarizationConnector.remove(\n\t\t\t\t\t\ttask.payload.identity,\n\t\t\t\t\t\ttask.result.notarizationId\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\tverifiableCredential: IImmutableProofCredential;\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\tconst verifiableCredential: IImmutableProofCredential = {\n\t\t\t\"@context\": [\n\t\t\t\tproofEntity.vcContext ?? DidContexts.ContextVCv1,\n\t\t\t\tImmutableProofContexts.Context,\n\t\t\t\tImmutableProofContexts.ContextCommon\n\t\t\t],\n\t\t\ttype: [DidTypes.VerifiableCredential, ImmutableProofTypes.ImmutableProof],\n\t\t\tid,\n\t\t\tissuer: proofEntity.organizationId,\n\t\t\tcredentialSubject: {\n\t\t\t\tid: proofEntity.proofObjectId,\n\t\t\t\tproofIntegrity: proofEntity.proofObjectIntegrity\n\t\t\t}\n\t\t} as IImmutableProofCredential;\n\n\t\tVerifiableCredentialHelper.setValidFrom(\n\t\t\tverifiableCredential as IDidVerifiableCredential,\n\t\t\tproofEntity.dateCreated\n\t\t);\n\n\t\tlet verified = false;\n\t\tlet failure: ImmutableProofFailure | undefined = ImmutableProofFailure.NotIssued;\n\n\t\tif (Is.stringValue(proofEntity.notarizationId)) {\n\t\t\tfailure = ImmutableProofFailure.ProofMissing;\n\t\t\tconst notarization = await this._notarizationConnector.get(proofEntity.notarizationId);\n\n\t\t\tif (Is.uint8Array(notarization.data)) {\n\t\t\t\tconst proof = ObjectHelper.fromBytes<IProof>(notarization.data);\n\n\t\t\t\tconst proofWithReceipt = {\n\t\t\t\t\t...proof,\n\t\t\t\t\tverificationMethod: `${proofEntity.organizationId}#${this._verificationMethodId}`,\n\t\t\t\t\tnotarizationId: proofEntity.notarizationId\n\t\t\t\t};\n\n\t\t\t\tverifiableCredential.proof = proofWithReceipt;\n\n\t\t\t\tif (verify && Is.object<IProof>(proof)) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = await this._identityConnector.checkVerifiableCredential(\n\t\t\t\t\t\t\tverifiableCredential as IDidVerifiableCredential\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (result.revoked) {\n\t\t\t\t\t\t\tverified = false;\n\t\t\t\t\t\t\tfailure = ImmutableProofFailure.Revoked;\n\t\t\t\t\t\t} else {\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}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tverified = false;\n\t\t\t\t\t\tfailure = ImmutableProofFailure.VerificationFailure;\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\tverifiableCredential: await JsonLdProcessor.compact(\n\t\t\t\tverifiableCredential,\n\t\t\t\tJsonLdProcessor.gatherContexts(verifiableCredential)\n\t\t\t),\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 notarization connector type.\n\t * @default notarization\n\t */\n\tnotarizationConnectorType?: string;\n\n\t/**\n\t * The logging component type.\n\t
|
|
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 notarization connector type.\n\t * @default notarization\n\t */\n\tnotarizationConnectorType?: string;\n\n\t/**\n\t * The logging component type.\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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ICreatedResponse, IHttpRequestContext, IRestRoute, ITag } from "@twin.org/api-models";
|
|
2
|
-
import { type IImmutableProofCreateRequest, type IImmutableProofGetRequest, type IImmutableProofGetResponse, type IImmutableProofVerifyRequest, type IImmutableProofVerifyResponse } from "@twin.org/immutable-proof-models";
|
|
1
|
+
import type { ICreatedResponse, IHttpRequestContext, INoContentResponse, IRestRoute, ITag } from "@twin.org/api-models";
|
|
2
|
+
import { type IImmutableProofCreateRequest, type IImmutableProofGetRequest, type IImmutableProofGetResponse, type IImmutableProofRemoveNotarizationRequest, type IImmutableProofRemoveRequest, type IImmutableProofVerifyRequest, type IImmutableProofVerifyResponse } from "@twin.org/immutable-proof-models";
|
|
3
3
|
/**
|
|
4
4
|
* The tag to associate with the routes.
|
|
5
5
|
*/
|
|
@@ -35,3 +35,19 @@ export declare function immutableProofGet(httpRequestContext: IHttpRequestContex
|
|
|
35
35
|
* @returns The response object with additional http response properties.
|
|
36
36
|
*/
|
|
37
37
|
export declare function immutableProofVerify(httpRequestContext: IHttpRequestContext, componentName: string, request: IImmutableProofVerifyRequest): Promise<IImmutableProofVerifyResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Remove the proof and its notarization.
|
|
40
|
+
* @param httpRequestContext The request context for the API.
|
|
41
|
+
* @param componentName The name of the component to use in the routes.
|
|
42
|
+
* @param request The request.
|
|
43
|
+
* @returns The response object with additional http response properties.
|
|
44
|
+
*/
|
|
45
|
+
export declare function immutableProofRemove(httpRequestContext: IHttpRequestContext, componentName: string, request: IImmutableProofRemoveRequest): Promise<INoContentResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Remove the notarization for a proof, keeping the proof entity.
|
|
48
|
+
* @param httpRequestContext The request context for the API.
|
|
49
|
+
* @param componentName The name of the component to use in the routes.
|
|
50
|
+
* @param request The request.
|
|
51
|
+
* @returns The response object with additional http response properties.
|
|
52
|
+
*/
|
|
53
|
+
export declare function immutableProofRemoveNotarization(httpRequestContext: IHttpRequestContext, componentName: string, request: IImmutableProofRemoveNotarizationRequest): Promise<INoContentResponse>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type IJsonLdNodeObject } from "@twin.org/data-json-ld";
|
|
2
|
-
import { type IImmutableProofComponent, type IImmutableProofVerification } from "@twin.org/immutable-proof-models";
|
|
3
|
-
import { type IDidVerifiableCredential } from "@twin.org/standards-w3c-did";
|
|
2
|
+
import { type IImmutableProofComponent, type IImmutableProofCredential, type IImmutableProofVerification } from "@twin.org/immutable-proof-models";
|
|
4
3
|
import type { IImmutableProofServiceConstructorOptions } from "./models/IImmutableProofServiceConstructorOptions.js";
|
|
5
4
|
/**
|
|
6
5
|
* Class for performing immutable proof operations.
|
|
@@ -42,7 +41,7 @@ export declare class ImmutableProofService implements IImmutableProofComponent {
|
|
|
42
41
|
* @returns The proof.
|
|
43
42
|
* @throws NotFoundError if the proof is not found.
|
|
44
43
|
*/
|
|
45
|
-
get(id: string): Promise<
|
|
44
|
+
get(id: string): Promise<IImmutableProofCredential>;
|
|
46
45
|
/**
|
|
47
46
|
* Verify a proof.
|
|
48
47
|
* @param id The id of the proof to verify.
|
|
@@ -51,10 +50,17 @@ export declare class ImmutableProofService implements IImmutableProofComponent {
|
|
|
51
50
|
*/
|
|
52
51
|
verify(id: string): Promise<IImmutableProofVerification>;
|
|
53
52
|
/**
|
|
54
|
-
* Remove the
|
|
55
|
-
* @param id The id of the proof to remove
|
|
53
|
+
* Remove the proof and its notarization.
|
|
54
|
+
* @param id The id of the proof to remove.
|
|
56
55
|
* @returns Nothing.
|
|
57
56
|
* @throws NotFoundError if the proof is not found.
|
|
58
57
|
*/
|
|
59
|
-
|
|
58
|
+
remove(id: string): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Remove only the notarization for the proof, keeping the proof entity.
|
|
61
|
+
* @param id The id of the proof to remove the notarization from.
|
|
62
|
+
* @returns Nothing.
|
|
63
|
+
* @throws NotFoundError if the proof is not found.
|
|
64
|
+
*/
|
|
65
|
+
removeNotarization(id: string): Promise<void>;
|
|
60
66
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.17](https://github.com/iotaledger/twin-immutable-proof/compare/immutable-proof-service-v0.0.3-next.16...immutable-proof-service-v0.0.3-next.17) (2026-06-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* remove default loggers ([1f59001](https://github.com/iotaledger/twin-immutable-proof/commit/1f59001038a9b83b5e3675c4cee2c4131023e9ff))
|
|
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.16 to 0.0.3-next.17
|
|
16
|
+
* @twin.org/immutable-proof-task bumped from 0.0.3-next.16 to 0.0.3-next.17
|
|
17
|
+
|
|
18
|
+
## [0.0.3-next.16](https://github.com/iotaledger/twin-immutable-proof/compare/immutable-proof-service-v0.0.3-next.15...immutable-proof-service-v0.0.3-next.16) (2026-05-29)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* add context id features ([#14](https://github.com/iotaledger/twin-immutable-proof/issues/14)) ([ed5a594](https://github.com/iotaledger/twin-immutable-proof/commit/ed5a594eaa7d50f74b1c09a7a560d48b33a4ecd1))
|
|
24
|
+
* add logging ([#18](https://github.com/iotaledger/twin-immutable-proof/issues/18)) ([e331ce8](https://github.com/iotaledger/twin-immutable-proof/commit/e331ce843393554750c2708ebce1273056b6399a))
|
|
25
|
+
* add validate-locales ([d6a7c07](https://github.com/iotaledger/twin-immutable-proof/commit/d6a7c0794a1922981a42f56cc24724d7cee727f6))
|
|
26
|
+
* eslint migration to flat config ([c8536f2](https://github.com/iotaledger/twin-immutable-proof/commit/c8536f219c7709c6c08b9266e537831f9054dda9))
|
|
27
|
+
* immutable proof as vc ([#31](https://github.com/iotaledger/twin-immutable-proof/issues/31)) ([79cdb03](https://github.com/iotaledger/twin-immutable-proof/commit/79cdb03eb86c4f6d2ab1d5bf235f74ff74e8b877))
|
|
28
|
+
* remove unused namespace ([a39864c](https://github.com/iotaledger/twin-immutable-proof/commit/a39864c0b2ca8753334a34028b8e5823a14162b4))
|
|
29
|
+
* remove vm linkage in on chain proof ([4034336](https://github.com/iotaledger/twin-immutable-proof/commit/4034336177261dcf3b017524a56f3f6537545227))
|
|
30
|
+
* replace verifiable storage with notarization as immutable proof ([#41](https://github.com/iotaledger/twin-immutable-proof/issues/41)) ([54f2154](https://github.com/iotaledger/twin-immutable-proof/commit/54f215469b0bdc9ea94cad572ca13b8533144104))
|
|
31
|
+
* typescript 6 update ([34d8aea](https://github.com/iotaledger/twin-immutable-proof/commit/34d8aea0ea0c1e1252de1882517abb1683d98313))
|
|
32
|
+
* update background tasks ([f25741c](https://github.com/iotaledger/twin-immutable-proof/commit/f25741c704e2c8311bc98bc69d4d926c523c781e))
|
|
33
|
+
* update contexts ([#22](https://github.com/iotaledger/twin-immutable-proof/issues/22)) ([645b880](https://github.com/iotaledger/twin-immutable-proof/commit/645b8803540408c74e3891b2c5ff9aefd5908d9f))
|
|
34
|
+
* update contexts and namespaces ([#20](https://github.com/iotaledger/twin-immutable-proof/issues/20)) ([d38aa69](https://github.com/iotaledger/twin-immutable-proof/commit/d38aa696c73e4fcc304f08fb458d5900109abcb4))
|
|
35
|
+
* update data types to use fully qualified names ([e94d0f5](https://github.com/iotaledger/twin-immutable-proof/commit/e94d0f5db93856b5b59cfd34e55252fa13a7f4e0))
|
|
36
|
+
* update dependencies ([1ec6b18](https://github.com/iotaledger/twin-immutable-proof/commit/1ec6b18e93198a8fc4935700863cdab1c3df7b64))
|
|
37
|
+
* update dependencies ([7d6b321](https://github.com/iotaledger/twin-immutable-proof/commit/7d6b321928ca0434ee530816b1440f1687b94a6e))
|
|
38
|
+
* update framework core ([e708d4d](https://github.com/iotaledger/twin-immutable-proof/commit/e708d4dd3febcfbcd64663d5be004eab1d26c0fb))
|
|
39
|
+
* update remove methods ([#45](https://github.com/iotaledger/twin-immutable-proof/issues/45)) ([9db19bb](https://github.com/iotaledger/twin-immutable-proof/commit/9db19bb4c8e6f5d66139755e8b8a8071a77c4887))
|
|
40
|
+
* update schemas ([ab0569a](https://github.com/iotaledger/twin-immutable-proof/commit/ab0569adf3419beefd8aef7793fdbe5b2fe2d93e))
|
|
41
|
+
* use shared store mechanism ([#3](https://github.com/iotaledger/twin-immutable-proof/issues/3)) ([7042a40](https://github.com/iotaledger/twin-immutable-proof/commit/7042a40f0ef8b01463f07aeb1efae4f417162fa1))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Bug Fixes
|
|
45
|
+
|
|
46
|
+
* constructor component name ([06ea7c3](https://github.com/iotaledger/twin-immutable-proof/commit/06ea7c3602a7b465870300bf02f358d95312d49a))
|
|
47
|
+
* Missing user and node identity on create ([#1](https://github.com/iotaledger/twin-immutable-proof/issues/1)) ([80ea2f9](https://github.com/iotaledger/twin-immutable-proof/commit/80ea2f901afc7531f4a522227a61e6fa1482484d))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
### Dependencies
|
|
51
|
+
|
|
52
|
+
* The following workspace dependencies were updated
|
|
53
|
+
* dependencies
|
|
54
|
+
* @twin.org/immutable-proof-models bumped from 0.0.3-next.15 to 0.0.3-next.16
|
|
55
|
+
* @twin.org/immutable-proof-task bumped from 0.0.3-next.15 to 0.0.3-next.16
|
|
56
|
+
|
|
57
|
+
## [0.0.3-next.15](https://github.com/iotaledger/twin-immutable-proof/compare/immutable-proof-service-v0.0.3-next.14...immutable-proof-service-v0.0.3-next.15) (2026-05-29)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### Features
|
|
61
|
+
|
|
62
|
+
* update remove methods ([#45](https://github.com/iotaledger/twin-immutable-proof/issues/45)) ([9db19bb](https://github.com/iotaledger/twin-immutable-proof/commit/9db19bb4c8e6f5d66139755e8b8a8071a77c4887))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Dependencies
|
|
66
|
+
|
|
67
|
+
* The following workspace dependencies were updated
|
|
68
|
+
* dependencies
|
|
69
|
+
* @twin.org/immutable-proof-models bumped from 0.0.3-next.14 to 0.0.3-next.15
|
|
70
|
+
* @twin.org/immutable-proof-task bumped from 0.0.3-next.14 to 0.0.3-next.15
|
|
71
|
+
|
|
3
72
|
## [0.0.3-next.14](https://github.com/iotaledger/twin-immutable-proof/compare/immutable-proof-service-v0.0.3-next.13...immutable-proof-service-v0.0.3-next.14) (2026-05-28)
|
|
4
73
|
|
|
5
74
|
|
package/docs/open-api/spec.json
CHANGED
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
"content": {
|
|
190
190
|
"application/json": {
|
|
191
191
|
"schema": {
|
|
192
|
-
"$ref": "https://schema.twindev.org/
|
|
192
|
+
"$ref": "https://schema.twindev.org/immutable-proof/ImmutableProofCredential"
|
|
193
193
|
},
|
|
194
194
|
"examples": {
|
|
195
195
|
"immutableProofGetResponseExample": {
|
|
@@ -223,7 +223,7 @@
|
|
|
223
223
|
},
|
|
224
224
|
"application/ld+json": {
|
|
225
225
|
"schema": {
|
|
226
|
-
"$ref": "https://schema.twindev.org/
|
|
226
|
+
"$ref": "https://schema.twindev.org/immutable-proof/ImmutableProofCredential"
|
|
227
227
|
},
|
|
228
228
|
"examples": {
|
|
229
229
|
"immutableProofJsonLdGetResponseExample": {
|
|
@@ -344,6 +344,114 @@
|
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
|
+
},
|
|
348
|
+
"delete": {
|
|
349
|
+
"operationId": "immutableProofRemove",
|
|
350
|
+
"summary": "Remove a proof",
|
|
351
|
+
"tags": [
|
|
352
|
+
"Immutable Proof"
|
|
353
|
+
],
|
|
354
|
+
"parameters": [
|
|
355
|
+
{
|
|
356
|
+
"name": "id",
|
|
357
|
+
"description": "The id of the immutable proof to remove.",
|
|
358
|
+
"in": "path",
|
|
359
|
+
"required": true,
|
|
360
|
+
"schema": {
|
|
361
|
+
"type": "string"
|
|
362
|
+
},
|
|
363
|
+
"style": "simple",
|
|
364
|
+
"example": "immutable-proof:1234567890"
|
|
365
|
+
}
|
|
366
|
+
],
|
|
367
|
+
"security": [
|
|
368
|
+
{
|
|
369
|
+
"jwtBearerAuthScheme": []
|
|
370
|
+
}
|
|
371
|
+
],
|
|
372
|
+
"responses": {
|
|
373
|
+
"204": {
|
|
374
|
+
"description": "The rest request ended in success with no data."
|
|
375
|
+
},
|
|
376
|
+
"400": {
|
|
377
|
+
"description": "The server cannot process the request, see the content for more details.",
|
|
378
|
+
"content": {
|
|
379
|
+
"application/json": {
|
|
380
|
+
"schema": {
|
|
381
|
+
"$ref": "#/components/schemas/Error"
|
|
382
|
+
},
|
|
383
|
+
"examples": {
|
|
384
|
+
"exampleResponse": {
|
|
385
|
+
"value": {
|
|
386
|
+
"name": "GeneralError",
|
|
387
|
+
"message": "errorMessage",
|
|
388
|
+
"properties": {
|
|
389
|
+
"foo": "bar"
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
"401": {
|
|
398
|
+
"description": "You are not authorized to use the API or no credentials were supplied, see the content for more details.",
|
|
399
|
+
"content": {
|
|
400
|
+
"application/json": {
|
|
401
|
+
"schema": {
|
|
402
|
+
"$ref": "#/components/schemas/Error"
|
|
403
|
+
},
|
|
404
|
+
"examples": {
|
|
405
|
+
"exampleResponse": {
|
|
406
|
+
"value": {
|
|
407
|
+
"name": "UnauthorizedError",
|
|
408
|
+
"message": "errorMessage"
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
"404": {
|
|
416
|
+
"description": "The resource you tried to access does not exist, see the content for more details.",
|
|
417
|
+
"content": {
|
|
418
|
+
"application/json": {
|
|
419
|
+
"schema": {
|
|
420
|
+
"$ref": "#/components/schemas/NotFoundResponse"
|
|
421
|
+
},
|
|
422
|
+
"examples": {
|
|
423
|
+
"exampleResponse": {
|
|
424
|
+
"value": {
|
|
425
|
+
"name": "NotFoundError",
|
|
426
|
+
"message": "errorMessage",
|
|
427
|
+
"properties": {
|
|
428
|
+
"notFoundId": "1"
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
"500": {
|
|
437
|
+
"description": "The server has encountered a situation it does not know how to handle, see the content for more details.",
|
|
438
|
+
"content": {
|
|
439
|
+
"application/json": {
|
|
440
|
+
"schema": {
|
|
441
|
+
"$ref": "#/components/schemas/Error"
|
|
442
|
+
},
|
|
443
|
+
"examples": {
|
|
444
|
+
"exampleResponse": {
|
|
445
|
+
"value": {
|
|
446
|
+
"name": "InternalServerError",
|
|
447
|
+
"message": "errorMessage"
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
347
455
|
}
|
|
348
456
|
},
|
|
349
457
|
"/immutable-proof/{id}/verify": {
|
|
@@ -488,6 +596,116 @@
|
|
|
488
596
|
}
|
|
489
597
|
}
|
|
490
598
|
}
|
|
599
|
+
},
|
|
600
|
+
"/immutable-proof/{id}/notarization": {
|
|
601
|
+
"delete": {
|
|
602
|
+
"operationId": "immutableProofRemoveNotarization",
|
|
603
|
+
"summary": "Remove the notarization for a proof",
|
|
604
|
+
"tags": [
|
|
605
|
+
"Immutable Proof"
|
|
606
|
+
],
|
|
607
|
+
"parameters": [
|
|
608
|
+
{
|
|
609
|
+
"name": "id",
|
|
610
|
+
"description": "The id of the immutable proof to remove the notarization from.",
|
|
611
|
+
"in": "path",
|
|
612
|
+
"required": true,
|
|
613
|
+
"schema": {
|
|
614
|
+
"type": "string"
|
|
615
|
+
},
|
|
616
|
+
"style": "simple",
|
|
617
|
+
"example": "immutable-proof:1234567890"
|
|
618
|
+
}
|
|
619
|
+
],
|
|
620
|
+
"security": [
|
|
621
|
+
{
|
|
622
|
+
"jwtBearerAuthScheme": []
|
|
623
|
+
}
|
|
624
|
+
],
|
|
625
|
+
"responses": {
|
|
626
|
+
"204": {
|
|
627
|
+
"description": "The rest request ended in success with no data."
|
|
628
|
+
},
|
|
629
|
+
"400": {
|
|
630
|
+
"description": "The server cannot process the request, see the content for more details.",
|
|
631
|
+
"content": {
|
|
632
|
+
"application/json": {
|
|
633
|
+
"schema": {
|
|
634
|
+
"$ref": "#/components/schemas/Error"
|
|
635
|
+
},
|
|
636
|
+
"examples": {
|
|
637
|
+
"exampleResponse": {
|
|
638
|
+
"value": {
|
|
639
|
+
"name": "GeneralError",
|
|
640
|
+
"message": "errorMessage",
|
|
641
|
+
"properties": {
|
|
642
|
+
"foo": "bar"
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
},
|
|
650
|
+
"401": {
|
|
651
|
+
"description": "You are not authorized to use the API or no credentials were supplied, see the content for more details.",
|
|
652
|
+
"content": {
|
|
653
|
+
"application/json": {
|
|
654
|
+
"schema": {
|
|
655
|
+
"$ref": "#/components/schemas/Error"
|
|
656
|
+
},
|
|
657
|
+
"examples": {
|
|
658
|
+
"exampleResponse": {
|
|
659
|
+
"value": {
|
|
660
|
+
"name": "UnauthorizedError",
|
|
661
|
+
"message": "errorMessage"
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
"404": {
|
|
669
|
+
"description": "The resource you tried to access does not exist, see the content for more details.",
|
|
670
|
+
"content": {
|
|
671
|
+
"application/json": {
|
|
672
|
+
"schema": {
|
|
673
|
+
"$ref": "#/components/schemas/NotFoundResponse"
|
|
674
|
+
},
|
|
675
|
+
"examples": {
|
|
676
|
+
"exampleResponse": {
|
|
677
|
+
"value": {
|
|
678
|
+
"name": "NotFoundError",
|
|
679
|
+
"message": "errorMessage",
|
|
680
|
+
"properties": {
|
|
681
|
+
"notFoundId": "1"
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
},
|
|
689
|
+
"500": {
|
|
690
|
+
"description": "The server has encountered a situation it does not know how to handle, see the content for more details.",
|
|
691
|
+
"content": {
|
|
692
|
+
"application/json": {
|
|
693
|
+
"schema": {
|
|
694
|
+
"$ref": "#/components/schemas/Error"
|
|
695
|
+
},
|
|
696
|
+
"examples": {
|
|
697
|
+
"exampleResponse": {
|
|
698
|
+
"value": {
|
|
699
|
+
"name": "InternalServerError",
|
|
700
|
+
"message": "errorMessage"
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
}
|
|
491
709
|
}
|
|
492
710
|
},
|
|
493
711
|
"components": {
|
|
@@ -118,7 +118,7 @@ The id of the new proof.
|
|
|
118
118
|
|
|
119
119
|
### get() {#get}
|
|
120
120
|
|
|
121
|
-
> **get**(`id`): `Promise`\<`
|
|
121
|
+
> **get**(`id`): `Promise`\<`IImmutableProofCredential`\>
|
|
122
122
|
|
|
123
123
|
Get a proof.
|
|
124
124
|
|
|
@@ -132,7 +132,7 @@ The id of the proof to get.
|
|
|
132
132
|
|
|
133
133
|
#### Returns
|
|
134
134
|
|
|
135
|
-
`Promise`\<`
|
|
135
|
+
`Promise`\<`IImmutableProofCredential`\>
|
|
136
136
|
|
|
137
137
|
The proof.
|
|
138
138
|
|
|
@@ -176,11 +176,11 @@ NotFoundError if the proof is not found.
|
|
|
176
176
|
|
|
177
177
|
***
|
|
178
178
|
|
|
179
|
-
###
|
|
179
|
+
### remove() {#remove}
|
|
180
180
|
|
|
181
|
-
> **
|
|
181
|
+
> **remove**(`id`): `Promise`\<`void`\>
|
|
182
182
|
|
|
183
|
-
Remove the
|
|
183
|
+
Remove the proof and its notarization.
|
|
184
184
|
|
|
185
185
|
#### Parameters
|
|
186
186
|
|
|
@@ -188,7 +188,7 @@ Remove the notarization for the proof.
|
|
|
188
188
|
|
|
189
189
|
`string`
|
|
190
190
|
|
|
191
|
-
The id of the proof to remove
|
|
191
|
+
The id of the proof to remove.
|
|
192
192
|
|
|
193
193
|
#### Returns
|
|
194
194
|
|
|
@@ -202,4 +202,34 @@ NotFoundError if the proof is not found.
|
|
|
202
202
|
|
|
203
203
|
#### Implementation of
|
|
204
204
|
|
|
205
|
-
`IImmutableProofComponent.
|
|
205
|
+
`IImmutableProofComponent.remove`
|
|
206
|
+
|
|
207
|
+
***
|
|
208
|
+
|
|
209
|
+
### removeNotarization() {#removenotarization}
|
|
210
|
+
|
|
211
|
+
> **removeNotarization**(`id`): `Promise`\<`void`\>
|
|
212
|
+
|
|
213
|
+
Remove only the notarization for the proof, keeping the proof entity.
|
|
214
|
+
|
|
215
|
+
#### Parameters
|
|
216
|
+
|
|
217
|
+
##### id
|
|
218
|
+
|
|
219
|
+
`string`
|
|
220
|
+
|
|
221
|
+
The id of the proof to remove the notarization from.
|
|
222
|
+
|
|
223
|
+
#### Returns
|
|
224
|
+
|
|
225
|
+
`Promise`\<`void`\>
|
|
226
|
+
|
|
227
|
+
Nothing.
|
|
228
|
+
|
|
229
|
+
#### Throws
|
|
230
|
+
|
|
231
|
+
NotFoundError if the proof is not found.
|
|
232
|
+
|
|
233
|
+
#### Implementation of
|
|
234
|
+
|
|
235
|
+
`IImmutableProofComponent.removeNotarization`
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Function: immutableProofRemove()
|
|
2
|
+
|
|
3
|
+
> **immutableProofRemove**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`INoContentResponse`\>
|
|
4
|
+
|
|
5
|
+
Remove the proof and its notarization.
|
|
6
|
+
|
|
7
|
+
## Parameters
|
|
8
|
+
|
|
9
|
+
### httpRequestContext
|
|
10
|
+
|
|
11
|
+
`IHttpRequestContext`
|
|
12
|
+
|
|
13
|
+
The request context for the API.
|
|
14
|
+
|
|
15
|
+
### componentName
|
|
16
|
+
|
|
17
|
+
`string`
|
|
18
|
+
|
|
19
|
+
The name of the component to use in the routes.
|
|
20
|
+
|
|
21
|
+
### request
|
|
22
|
+
|
|
23
|
+
`IImmutableProofRemoveRequest`
|
|
24
|
+
|
|
25
|
+
The request.
|
|
26
|
+
|
|
27
|
+
## Returns
|
|
28
|
+
|
|
29
|
+
`Promise`\<`INoContentResponse`\>
|
|
30
|
+
|
|
31
|
+
The response object with additional http response properties.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Function: immutableProofRemoveNotarization()
|
|
2
|
+
|
|
3
|
+
> **immutableProofRemoveNotarization**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`INoContentResponse`\>
|
|
4
|
+
|
|
5
|
+
Remove the notarization for a proof, keeping the proof entity.
|
|
6
|
+
|
|
7
|
+
## Parameters
|
|
8
|
+
|
|
9
|
+
### httpRequestContext
|
|
10
|
+
|
|
11
|
+
`IHttpRequestContext`
|
|
12
|
+
|
|
13
|
+
The request context for the API.
|
|
14
|
+
|
|
15
|
+
### componentName
|
|
16
|
+
|
|
17
|
+
`string`
|
|
18
|
+
|
|
19
|
+
The name of the component to use in the routes.
|
|
20
|
+
|
|
21
|
+
### request
|
|
22
|
+
|
|
23
|
+
`IImmutableProofRemoveNotarizationRequest`
|
|
24
|
+
|
|
25
|
+
The request.
|
|
26
|
+
|
|
27
|
+
## Returns
|
|
28
|
+
|
|
29
|
+
`Promise`\<`INoContentResponse`\>
|
|
30
|
+
|
|
31
|
+
The response object with additional http response properties.
|
package/docs/reference/index.md
CHANGED
|
@@ -21,4 +21,6 @@
|
|
|
21
21
|
- [immutableProofCreate](functions/immutableProofCreate.md)
|
|
22
22
|
- [immutableProofGet](functions/immutableProofGet.md)
|
|
23
23
|
- [immutableProofVerify](functions/immutableProofVerify.md)
|
|
24
|
+
- [immutableProofRemove](functions/immutableProofRemove.md)
|
|
25
|
+
- [immutableProofRemoveNotarization](functions/immutableProofRemoveNotarization.md)
|
|
24
26
|
- [initSchema](functions/initSchema.md)
|
package/locales/en.json
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"createFailed": "Creating the proof failed",
|
|
6
6
|
"getFailed": "Getting the proof failed",
|
|
7
7
|
"verifyFailed": "Verifying the proof failed",
|
|
8
|
+
"removeFailed": "Removing the Immutable Proof failed",
|
|
8
9
|
"removeNotarizationFailed": "Removing notarization entry from the Immutable Proof failed",
|
|
9
10
|
"proofNotFound": "The proof with the Id \"{notFoundId}\" was not found",
|
|
10
11
|
"createProofFailed": "Creating the immutable proof failed"
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/immutable-proof-service",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.17",
|
|
4
4
|
"description": "Core proof lifecycle service with route helpers for create, get, and verify operations",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/iotaledger/immutable-proof.git",
|
|
7
|
+
"url": "git+https://github.com/iotaledger/twin-immutable-proof.git",
|
|
8
8
|
"directory": "packages/immutable-proof-service"
|
|
9
9
|
},
|
|
10
10
|
"author": "martyn.janes@iota.org",
|
|
@@ -24,8 +24,8 @@
|
|
|
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.
|
|
28
|
-
"@twin.org/immutable-proof-task": "0.0.3-next.
|
|
27
|
+
"@twin.org/immutable-proof-models": "0.0.3-next.17",
|
|
28
|
+
"@twin.org/immutable-proof-task": "0.0.3-next.17",
|
|
29
29
|
"@twin.org/logging-models": "next",
|
|
30
30
|
"@twin.org/nameof": "next",
|
|
31
31
|
"@twin.org/notarization-models": "next",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"business-logic"
|
|
62
62
|
],
|
|
63
63
|
"bugs": {
|
|
64
|
-
"url": "git+https://github.com/iotaledger/immutable-proof/issues"
|
|
64
|
+
"url": "git+https://github.com/iotaledger/twin-immutable-proof/issues"
|
|
65
65
|
},
|
|
66
66
|
"homepage": "https://twindev.org"
|
|
67
67
|
}
|