@twin.org/immutable-proof-service 0.0.3-next.8 → 0.9.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/es/entities/immutableProof.js +3 -3
- package/dist/es/entities/immutableProof.js.map +1 -1
- package/dist/es/immutableProofRoutes.js +98 -14
- package/dist/es/immutableProofRoutes.js.map +1 -1
- package/dist/es/immutableProofService.js +78 -39
- package/dist/es/immutableProofService.js.map +1 -1
- package/dist/es/models/IImmutableProofServiceConstructorOptions.js.map +1 -1
- package/dist/es/restEntryPoints.js +3 -0
- package/dist/es/restEntryPoints.js.map +1 -1
- package/dist/types/entities/immutableProof.d.ts +2 -2
- package/dist/types/immutableProofRoutes.d.ts +20 -4
- package/dist/types/immutableProofService.d.ts +20 -10
- package/dist/types/models/IImmutableProofServiceConstructorOptions.d.ts +3 -4
- package/dist/types/restEntryPoints.d.ts +3 -0
- package/docs/changelog.md +247 -45
- package/docs/examples.md +127 -1
- package/docs/open-api/spec.json +216 -692
- package/docs/reference/classes/ImmutableProof.md +11 -11
- package/docs/reference/classes/ImmutableProofService.md +57 -17
- package/docs/reference/functions/immutableProofGet.md +1 -1
- package/docs/reference/functions/immutableProofRemove.md +31 -0
- package/docs/reference/functions/immutableProofRemoveNotarization.md +31 -0
- package/docs/reference/functions/immutableProofVerify.md +1 -1
- package/docs/reference/index.md +2 -0
- package/docs/reference/interfaces/IImmutableProofServiceConfig.md +2 -2
- package/docs/reference/interfaces/IImmutableProofServiceConstructorOptions.md +16 -22
- package/docs/reference/variables/restEntryPoints.md +2 -0
- package/locales/en.json +2 -1
- package/package.json +22 -22
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# TWIN Immutable Proof Service
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package implements the core immutable proof lifecycle, including proof creation, retrieval, verification, and storage coordination. It also exposes route and schema helpers so API hosts can register endpoints and entity schemas with consistent behaviour.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -26,9 +26,9 @@ let ImmutableProof = class ImmutableProof {
|
|
|
26
26
|
*/
|
|
27
27
|
proofObjectIntegrity;
|
|
28
28
|
/**
|
|
29
|
-
* The
|
|
29
|
+
* The notarization id.
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
notarizationId;
|
|
32
32
|
/**
|
|
33
33
|
* The verifiable credential context.
|
|
34
34
|
*/
|
|
@@ -57,7 +57,7 @@ __decorate([
|
|
|
57
57
|
__decorate([
|
|
58
58
|
property({ type: "string", optional: true }),
|
|
59
59
|
__metadata("design:type", String)
|
|
60
|
-
], ImmutableProof.prototype, "
|
|
60
|
+
], ImmutableProof.prototype, "notarizationId", void 0);
|
|
61
61
|
__decorate([
|
|
62
62
|
property({ type: "string", optional: true }),
|
|
63
63
|
__metadata("design:type", Object)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"immutableProof.js","sourceRoot":"","sources":["../../../src/entities/immutableProof.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGnE;;GAEG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAc;IAC1B;;OAEG;IAEI,EAAE,CAAU;IAEnB;;OAEG;IAEI,cAAc,CAAU;IAE/B;;OAEG;IAEI,WAAW,CAAU;IAE5B;;OAEG;IAEI,aAAa,CAAU;IAE9B;;OAEG;IAEI,oBAAoB,CAAU;IAErC;;OAEG;IAEI,
|
|
1
|
+
{"version":3,"file":"immutableProof.js","sourceRoot":"","sources":["../../../src/entities/immutableProof.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGnE;;GAEG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAc;IAC1B;;OAEG;IAEI,EAAE,CAAU;IAEnB;;OAEG;IAEI,cAAc,CAAU;IAE/B;;OAEG;IAEI,WAAW,CAAU;IAE5B;;OAEG;IAEI,aAAa,CAAU;IAE9B;;OAEG;IAEI,oBAAoB,CAAU;IAErC;;OAEG;IAEI,cAAc,CAAU;IAE/B;;OAEG;IAEI,SAAS,CAAmE;CACnF,CAAA;AArCO;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;;0CAC3B;AAMZ;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;sDACE;AAMxB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,CAAC,UAAU,EAAE,CAAC;;mDAC/D;AAMrB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;qDACf;AAMvB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;4DACQ;AAM9B;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;sDACd;AAMxB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;iDACsC;AAzCvE,cAAc;IAD1B,MAAM,EAAE;GACI,cAAc,CA0C1B","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { entity, property, SortDirection } from \"@twin.org/entity\";\nimport type { DidContexts } from \"@twin.org/standards-w3c-did\";\n\n/**\n * Class describing the immutable proof.\n */\n@entity()\nexport class ImmutableProof {\n\t/**\n\t * The id of the proof.\n\t */\n\t@property({ type: \"string\", isPrimary: true })\n\tpublic id!: string;\n\n\t/**\n\t * The organization id.\n\t */\n\t@property({ type: \"string\" })\n\tpublic organizationId!: string;\n\n\t/**\n\t * The date/time of when the proof was created.\n\t */\n\t@property({ type: \"string\", format: \"date-time\", sortDirection: SortDirection.Descending })\n\tpublic dateCreated!: string;\n\n\t/**\n\t * The associated id for the item.\n\t */\n\t@property({ type: \"string\", optional: true })\n\tpublic proofObjectId?: string;\n\n\t/**\n\t * The associated integrity for the item.\n\t */\n\t@property({ type: \"string\" })\n\tpublic proofObjectIntegrity!: string;\n\n\t/**\n\t * The notarization id.\n\t */\n\t@property({ type: \"string\", optional: true })\n\tpublic notarizationId?: string;\n\n\t/**\n\t * The verifiable credential context.\n\t */\n\t@property({ type: \"string\", optional: true })\n\tpublic vcContext?: typeof DidContexts.ContextVCv1 | typeof DidContexts.ContextVCv2;\n}\n"]}
|
|
@@ -115,11 +115,7 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
115
115
|
proofPurpose: "assertionMethod",
|
|
116
116
|
proofValue: "7DdiPPYtxLjCD3wA1po2rv...",
|
|
117
117
|
verificationMethod: "did:iota:testnet:0xcb07cabaa2f23b7e53d8cdc4228efb351ebb270554d13bc382e4f94ca8d3136b#immutable-proof-assertion",
|
|
118
|
-
|
|
119
|
-
immutableReceipt: {
|
|
120
|
-
id: "immutable-receipt:1234567890",
|
|
121
|
-
type: "ImmutableReceipt"
|
|
122
|
-
}
|
|
118
|
+
notarizationId: "notarization:iota:0xabcdef1234567890"
|
|
123
119
|
}
|
|
124
120
|
}
|
|
125
121
|
}
|
|
@@ -155,11 +151,7 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
155
151
|
proofPurpose: "assertionMethod",
|
|
156
152
|
proofValue: "7DdiPPYtxLjCD3wA1po2rv...",
|
|
157
153
|
verificationMethod: "did:iota:testnet:0xcb07cabaa2f23b7e53d8cdc4228efb351ebb270554d13bc382e4f94ca8d3136b#immutable-proof-assertion",
|
|
158
|
-
|
|
159
|
-
immutableReceipt: {
|
|
160
|
-
id: "immutable-receipt:1234567890",
|
|
161
|
-
type: "ImmutableReceipt"
|
|
162
|
-
}
|
|
154
|
+
notarizationId: "notarization:iota:0xabcdef1234567890"
|
|
163
155
|
}
|
|
164
156
|
}
|
|
165
157
|
}
|
|
@@ -228,7 +220,65 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
228
220
|
}
|
|
229
221
|
]
|
|
230
222
|
};
|
|
231
|
-
|
|
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];
|
|
232
282
|
}
|
|
233
283
|
/**
|
|
234
284
|
* Create a proof.
|
|
@@ -241,7 +291,7 @@ export async function immutableProofCreate(httpRequestContext, componentName, re
|
|
|
241
291
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
242
292
|
Guards.object(ROUTES_SOURCE, "request.body.document", request.body.document);
|
|
243
293
|
const component = ComponentFactory.get(componentName);
|
|
244
|
-
const result = await component.create(request.body.document);
|
|
294
|
+
const result = await component.create(request.body.document, request.body.options);
|
|
245
295
|
return {
|
|
246
296
|
statusCode: HttpStatusCode.created,
|
|
247
297
|
headers: {
|
|
@@ -250,7 +300,7 @@ export async function immutableProofCreate(httpRequestContext, componentName, re
|
|
|
250
300
|
};
|
|
251
301
|
}
|
|
252
302
|
/**
|
|
253
|
-
* Get
|
|
303
|
+
* Get a proof.
|
|
254
304
|
* @param httpRequestContext The request context for the API.
|
|
255
305
|
* @param componentName The name of the component to use in the routes.
|
|
256
306
|
* @param request The request.
|
|
@@ -271,7 +321,7 @@ export async function immutableProofGet(httpRequestContext, componentName, reque
|
|
|
271
321
|
};
|
|
272
322
|
}
|
|
273
323
|
/**
|
|
274
|
-
* Verify
|
|
324
|
+
* Verify a proof.
|
|
275
325
|
* @param httpRequestContext The request context for the API.
|
|
276
326
|
* @param componentName The name of the component to use in the routes.
|
|
277
327
|
* @param request The request.
|
|
@@ -291,4 +341,38 @@ export async function immutableProofVerify(httpRequestContext, componentName, re
|
|
|
291
341
|
body: result
|
|
292
342
|
};
|
|
293
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
|
+
}
|
|
294
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;AAE1C,OAAO,EACN,WAAW,EACX,eAAe,EACf,UAAU,EACV,QAAQ,EAER,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEvE;;GAEG;AACH,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAW;IACzC;QACC,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,qEAAqE;KAClF;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC/C,aAAqB,EACrB,aAAqB;IAErB,MAAM,WAAW,GAA+D;QAC/E,WAAW,EAAE,sBAAsB;QACnC,OAAO,EAAE,gBAAgB;QACzB,GAAG,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,IAAI;QAC/B,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,GAAG,aAAa,GAAG;QACzB,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,EAAE,CAC9C,oBAAoB,CAAC,kBAAkB,EAAE,aAAa,EAAE,OAAO,CAAC;QACjE,WAAW,EAAE;YACZ,IAAI,gCAAwC;YAC5C,QAAQ,EAAE;gBACT;oBACC,EAAE,EAAE,oCAAoC;oBACxC,OAAO,EAAE;wBACR,IAAI,EAAE;4BACL,QAAQ,EAAE;gCACT,UAAU,EAAE,oBAAoB;gCAChC,IAAI,EAAE,QAAQ;gCACd,IAAI,EAAE,YAAY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// 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\tverifiableStorageId: \"verifiable-storage:1234567890\",\n\t\t\t\t\t\t\t\t\timmutableReceipt: {\n\t\t\t\t\t\t\t\t\t\tid: \"immutable-receipt:1234567890\",\n\t\t\t\t\t\t\t\t\t\ttype: \"ImmutableReceipt\"\n\t\t\t\t\t\t\t\t\t}\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\tverifiableStorageId: \"verifiable-storage:1234567890\",\n\t\t\t\t\t\t\t\t\timmutableReceipt: {\n\t\t\t\t\t\t\t\t\t\tid: \"immutable-receipt:1234567890\",\n\t\t\t\t\t\t\t\t\t\ttype: \"ImmutableReceipt\"\n\t\t\t\t\t\t\t\t\t}\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);\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,GAAW;IACzC;QACC,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,qEAAqE;KAClF;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC/C,aAAqB,EACrB,aAAqB;IAErB,MAAM,WAAW,GAA+D;QAC/E,WAAW,EAAE,sBAAsB;QACnC,OAAO,EAAE,gBAAgB;QACzB,GAAG,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,IAAI;QAC/B,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,GAAG,aAAa,GAAG;QACzB,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,EAAE,CAC9C,oBAAoB,CAAC,kBAAkB,EAAE,aAAa,EAAE,OAAO,CAAC;QACjE,WAAW,EAAE;YACZ,IAAI,gCAAwC;YAC5C,QA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AAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACzC,kBAAuC,EACvC,aAAqB,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,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAA2B,aAAa,CAAC,CAAC;IAChF,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAE9C,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,SAAS;KACpC,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACrD,kBAAuC,EACvC,aAAqB,EACrB,OAAiD;IAEjD,MAAM,CAAC,MAAM,CAA2C,aAAa,aAAmB,OAAO,CAAC,CAAC;IACjG,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,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 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 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 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 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"]}
|
|
@@ -8,8 +8,8 @@ import { JsonLdHelper, JsonLdProcessor } from "@twin.org/data-json-ld";
|
|
|
8
8
|
import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
9
9
|
import { IdentityConnectorFactory } from "@twin.org/identity-models";
|
|
10
10
|
import { ImmutableProofContexts, ImmutableProofFailure, ImmutableProofTopics, ImmutableProofTypes } from "@twin.org/immutable-proof-models";
|
|
11
|
+
import { NotarizationConnectorFactory } from "@twin.org/notarization-models";
|
|
11
12
|
import { DidContexts, DidTypes, VerifiableCredentialHelper } from "@twin.org/standards-w3c-did";
|
|
12
|
-
import { VerifiableStorageConnectorFactory } from "@twin.org/verifiable-storage-models";
|
|
13
13
|
/**
|
|
14
14
|
* Class for performing immutable proof operations.
|
|
15
15
|
*/
|
|
@@ -44,10 +44,15 @@ export class ImmutableProofService {
|
|
|
44
44
|
*/
|
|
45
45
|
_proofStorage;
|
|
46
46
|
/**
|
|
47
|
-
* The
|
|
47
|
+
* The notarization connector type.
|
|
48
48
|
* @internal
|
|
49
49
|
*/
|
|
50
|
-
|
|
50
|
+
_notarizationConnectorType;
|
|
51
|
+
/**
|
|
52
|
+
* The notarization connector for the credentials.
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
_notarizationConnector;
|
|
51
56
|
/**
|
|
52
57
|
* The background task component.
|
|
53
58
|
* @internal
|
|
@@ -69,13 +74,14 @@ export class ImmutableProofService {
|
|
|
69
74
|
*/
|
|
70
75
|
_identityConnectorType;
|
|
71
76
|
/**
|
|
72
|
-
*
|
|
77
|
+
* Creates an instance of ImmutableProofService.
|
|
73
78
|
* @param options The dependencies for the immutable proof connector.
|
|
74
79
|
*/
|
|
75
80
|
constructor(options) {
|
|
76
81
|
this._proofStorage = EntityStorageConnectorFactory.get(options?.immutableProofEntityStorageType ?? "immutable-proof");
|
|
77
|
-
this.
|
|
78
|
-
this.
|
|
82
|
+
this._notarizationConnectorType = options?.notarizationConnectorType ?? "notarization";
|
|
83
|
+
this._notarizationConnector = NotarizationConnectorFactory.get(this._notarizationConnectorType);
|
|
84
|
+
this._logging = ComponentFactory.getIfExists(options?.loggingComponentType);
|
|
79
85
|
this._identityConnectorType = options?.identityConnectorType ?? "identity";
|
|
80
86
|
this._identityConnector = IdentityConnectorFactory.get(this._identityConnectorType);
|
|
81
87
|
this._backgroundTaskComponent = ComponentFactory.get(options?.backgroundTaskComponentType ?? "background-task");
|
|
@@ -95,7 +101,7 @@ export class ImmutableProofService {
|
|
|
95
101
|
/**
|
|
96
102
|
* The component needs to be started when the node is initialized.
|
|
97
103
|
* @param nodeLoggingComponentType The node logging component type.
|
|
98
|
-
* @returns
|
|
104
|
+
* @returns A promise that resolves when the background task handler has been registered.
|
|
99
105
|
*/
|
|
100
106
|
async start(nodeLoggingComponentType) {
|
|
101
107
|
await this._backgroundTaskComponent.registerHandler("immutable-proof", "@twin.org/immutable-proof-task", "processProofTask", async (task) => {
|
|
@@ -105,10 +111,15 @@ export class ImmutableProofService {
|
|
|
105
111
|
/**
|
|
106
112
|
* Create a new proof.
|
|
107
113
|
* @param document The document to create the proof for.
|
|
114
|
+
* @param options Optional settings for the proof.
|
|
115
|
+
* @param options.deleteLock An ISO 8601 date-time string specifying when the notarization lock expires; if omitted no lock is applied.
|
|
108
116
|
* @returns The id of the new proof.
|
|
109
117
|
*/
|
|
110
|
-
async create(document) {
|
|
118
|
+
async create(document, options) {
|
|
111
119
|
Guards.object(ImmutableProofService.CLASS_NAME, "document", document);
|
|
120
|
+
if (!Is.empty(options?.deleteLock)) {
|
|
121
|
+
Guards.dateTimeString(ImmutableProofService.CLASS_NAME, "options.deleteLock", options.deleteLock);
|
|
122
|
+
}
|
|
112
123
|
const contextIds = await ContextIdStore.getContextIds();
|
|
113
124
|
ContextIdHelper.guard(contextIds, ContextIdKeys.Organization);
|
|
114
125
|
try {
|
|
@@ -141,8 +152,10 @@ export class ImmutableProofService {
|
|
|
141
152
|
proofId: fullId,
|
|
142
153
|
identity: contextIds[ContextIdKeys.Organization],
|
|
143
154
|
identityConnectorType: this._identityConnectorType,
|
|
155
|
+
notarizationConnectorType: this._notarizationConnectorType,
|
|
144
156
|
verificationMethodId: this._verificationMethodId,
|
|
145
|
-
credentialSubject
|
|
157
|
+
credentialSubject,
|
|
158
|
+
deleteLockDateTime: options?.deleteLock
|
|
146
159
|
};
|
|
147
160
|
await this._backgroundTaskComponent.create("immutable-proof", proofTaskPayload, {
|
|
148
161
|
retainFor: 5000
|
|
@@ -206,12 +219,44 @@ export class ImmutableProofService {
|
|
|
206
219
|
}
|
|
207
220
|
}
|
|
208
221
|
/**
|
|
209
|
-
* Remove the
|
|
210
|
-
* @param id The id of the proof to remove
|
|
211
|
-
* @returns
|
|
222
|
+
* Remove the proof and its notarization.
|
|
223
|
+
* @param id The id of the proof to remove.
|
|
224
|
+
* @returns A promise that resolves when the proof and its notarization have been removed.
|
|
225
|
+
* @throws NotFoundError if the proof is not found.
|
|
226
|
+
*/
|
|
227
|
+
async remove(id) {
|
|
228
|
+
Guards.stringValue(ImmutableProofService.CLASS_NAME, "id", id);
|
|
229
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
230
|
+
ContextIdHelper.guard(contextIds, ContextIdKeys.Organization);
|
|
231
|
+
const urnParsed = Urn.fromValidString(id);
|
|
232
|
+
if (urnParsed.namespaceIdentifier() !== ImmutableProofService._NAMESPACE) {
|
|
233
|
+
throw new GeneralError(ImmutableProofService.CLASS_NAME, "namespaceMismatch", {
|
|
234
|
+
namespace: ImmutableProofService._NAMESPACE,
|
|
235
|
+
id
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
const proofId = urnParsed.namespaceSpecific(0);
|
|
240
|
+
const proofEntity = await this._proofStorage.get(proofId);
|
|
241
|
+
if (Is.empty(proofEntity)) {
|
|
242
|
+
throw new NotFoundError(ImmutableProofService.CLASS_NAME, "proofNotFound", id);
|
|
243
|
+
}
|
|
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 A promise that resolves when the notarization has been removed.
|
|
212
257
|
* @throws NotFoundError if the proof is not found.
|
|
213
258
|
*/
|
|
214
|
-
async
|
|
259
|
+
async removeNotarization(id) {
|
|
215
260
|
Guards.stringValue(ImmutableProofService.CLASS_NAME, "id", id);
|
|
216
261
|
const contextIds = await ContextIdStore.getContextIds();
|
|
217
262
|
ContextIdHelper.guard(contextIds, ContextIdKeys.Organization);
|
|
@@ -223,24 +268,24 @@ export class ImmutableProofService {
|
|
|
223
268
|
});
|
|
224
269
|
}
|
|
225
270
|
try {
|
|
226
|
-
const
|
|
227
|
-
const
|
|
228
|
-
if (Is.empty(
|
|
271
|
+
const proofId = urnParsed.namespaceSpecific(0);
|
|
272
|
+
const proofEntity = await this._proofStorage.get(proofId);
|
|
273
|
+
if (Is.empty(proofEntity)) {
|
|
229
274
|
throw new NotFoundError(ImmutableProofService.CLASS_NAME, "proofNotFound", id);
|
|
230
275
|
}
|
|
231
|
-
if (Is.stringValue(
|
|
232
|
-
await this.
|
|
233
|
-
delete
|
|
234
|
-
await this._proofStorage.set(
|
|
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);
|
|
235
280
|
}
|
|
236
281
|
}
|
|
237
282
|
catch (error) {
|
|
238
|
-
throw new GeneralError(ImmutableProofService.CLASS_NAME, "
|
|
283
|
+
throw new GeneralError(ImmutableProofService.CLASS_NAME, "removeNotarizationFailed", undefined, error);
|
|
239
284
|
}
|
|
240
285
|
}
|
|
241
286
|
/**
|
|
242
287
|
* Process a proof.
|
|
243
|
-
* @param
|
|
288
|
+
* @param task The background task to finalise.
|
|
244
289
|
* @internal
|
|
245
290
|
*/
|
|
246
291
|
async finaliseTask(task) {
|
|
@@ -250,15 +295,7 @@ export class ImmutableProofService {
|
|
|
250
295
|
const proofId = urnParsed.namespaceSpecific(0);
|
|
251
296
|
const proofEntity = await this._proofStorage.get(proofId);
|
|
252
297
|
if (Is.object(proofEntity)) {
|
|
253
|
-
|
|
254
|
-
const proof = task.result.verifiableCredential.proof;
|
|
255
|
-
// The proof context is always the last one in the generated vc contexts
|
|
256
|
-
// as that was the last operation performed, so we can extract it and use it for the proof itself
|
|
257
|
-
proof["@context"] = task.result.verifiableCredential["@context"][task.result.verifiableCredential["@context"].length - 1];
|
|
258
|
-
// Store the proof in the verifiable storage and get the id of where it is stored so we can retrieve it later
|
|
259
|
-
const verifiableCreateResult = await this._verifiableStorage.create(task.payload.identity, ObjectHelper.toBytes(proof));
|
|
260
|
-
// Update the proof entity with the verifiable storage id so we can retrieve it later
|
|
261
|
-
proofEntity.verifiableStorageId = verifiableCreateResult.id;
|
|
298
|
+
proofEntity.notarizationId = task.result.notarizationId;
|
|
262
299
|
// Update the date created if we can extract it from the VC
|
|
263
300
|
const validFrom = VerifiableCredentialHelper.getValidFrom(task.result.verifiableCredential);
|
|
264
301
|
if (Is.stringValue(validFrom)) {
|
|
@@ -275,6 +312,10 @@ export class ImmutableProofService {
|
|
|
275
312
|
});
|
|
276
313
|
await this._eventBusComponent?.publish(ImmutableProofTopics.ProofCreated, { id: new Urn(ImmutableProofService._NAMESPACE, task.payload.proofId).toString() });
|
|
277
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
|
+
}
|
|
278
319
|
}
|
|
279
320
|
else if (task.status === TaskStatus.Failed) {
|
|
280
321
|
await this._logging?.log({
|
|
@@ -319,18 +360,16 @@ export class ImmutableProofService {
|
|
|
319
360
|
VerifiableCredentialHelper.setValidFrom(verifiableCredential, proofEntity.dateCreated);
|
|
320
361
|
let verified = false;
|
|
321
362
|
let failure = ImmutableProofFailure.NotIssued;
|
|
322
|
-
if (Is.stringValue(proofEntity.
|
|
363
|
+
if (Is.stringValue(proofEntity.notarizationId)) {
|
|
323
364
|
failure = ImmutableProofFailure.ProofMissing;
|
|
324
|
-
const
|
|
325
|
-
if (Is.uint8Array(
|
|
326
|
-
const proof = ObjectHelper.fromBytes(
|
|
365
|
+
const notarization = await this._notarizationConnector.get(proofEntity.notarizationId);
|
|
366
|
+
if (Is.uint8Array(notarization.data)) {
|
|
367
|
+
const proof = ObjectHelper.fromBytes(notarization.data);
|
|
327
368
|
const proofWithReceipt = {
|
|
328
369
|
...proof,
|
|
329
|
-
|
|
330
|
-
|
|
370
|
+
verificationMethod: `${proofEntity.organizationId}#${this._verificationMethodId}`,
|
|
371
|
+
notarizationId: proofEntity.notarizationId
|
|
331
372
|
};
|
|
332
|
-
// Add the proof from the verifiable storage
|
|
333
|
-
// expand it with the verifiable storage id and receipt
|
|
334
373
|
verifiableCredential.proof = proofWithReceipt;
|
|
335
374
|
if (verify && Is.object(proof)) {
|
|
336
375
|
try {
|