@twin.org/immutable-proof-service 0.0.3-next.1 → 0.0.3-next.10
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/entities/immutableProof.js +19 -3
- package/dist/es/entities/immutableProof.js.map +1 -1
- package/dist/es/immutableProofRoutes.js +39 -23
- package/dist/es/immutableProofRoutes.js.map +1 -1
- package/dist/es/immutableProofService.js +114 -84
- package/dist/es/immutableProofService.js.map +1 -1
- package/dist/es/models/IImmutableProofServiceConstructorOptions.js.map +1 -1
- package/dist/types/entities/immutableProof.d.ts +11 -2
- package/dist/types/immutableProofService.d.ts +3 -2
- package/dist/types/models/IImmutableProofServiceConstructorOptions.d.ts +7 -2
- package/docs/changelog.md +135 -0
- package/docs/open-api/spec.json +580 -24
- package/docs/reference/classes/ImmutableProof.md +19 -3
- package/docs/reference/classes/ImmutableProofService.md +2 -2
- package/docs/reference/interfaces/IImmutableProofServiceConstructorOptions.md +17 -3
- package/locales/en.json +7 -1
- package/package.json +4 -3
|
@@ -9,6 +9,10 @@ let ImmutableProof = class ImmutableProof {
|
|
|
9
9
|
* The id of the proof.
|
|
10
10
|
*/
|
|
11
11
|
id;
|
|
12
|
+
/**
|
|
13
|
+
* The organization id.
|
|
14
|
+
*/
|
|
15
|
+
organizationId;
|
|
12
16
|
/**
|
|
13
17
|
* The date/time of when the proof was created.
|
|
14
18
|
*/
|
|
@@ -18,18 +22,26 @@ let ImmutableProof = class ImmutableProof {
|
|
|
18
22
|
*/
|
|
19
23
|
proofObjectId;
|
|
20
24
|
/**
|
|
21
|
-
* The associated
|
|
25
|
+
* The associated integrity for the item.
|
|
22
26
|
*/
|
|
23
|
-
|
|
27
|
+
proofObjectIntegrity;
|
|
24
28
|
/**
|
|
25
29
|
* The verifiable storage id.
|
|
26
30
|
*/
|
|
27
31
|
verifiableStorageId;
|
|
32
|
+
/**
|
|
33
|
+
* The verifiable credential context.
|
|
34
|
+
*/
|
|
35
|
+
vcContext;
|
|
28
36
|
};
|
|
29
37
|
__decorate([
|
|
30
38
|
property({ type: "string", isPrimary: true }),
|
|
31
39
|
__metadata("design:type", String)
|
|
32
40
|
], ImmutableProof.prototype, "id", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
property({ type: "string" }),
|
|
43
|
+
__metadata("design:type", String)
|
|
44
|
+
], ImmutableProof.prototype, "organizationId", void 0);
|
|
33
45
|
__decorate([
|
|
34
46
|
property({ type: "string", format: "date-time", sortDirection: SortDirection.Descending }),
|
|
35
47
|
__metadata("design:type", String)
|
|
@@ -41,11 +53,15 @@ __decorate([
|
|
|
41
53
|
__decorate([
|
|
42
54
|
property({ type: "string" }),
|
|
43
55
|
__metadata("design:type", String)
|
|
44
|
-
], ImmutableProof.prototype, "
|
|
56
|
+
], ImmutableProof.prototype, "proofObjectIntegrity", void 0);
|
|
45
57
|
__decorate([
|
|
46
58
|
property({ type: "string", optional: true }),
|
|
47
59
|
__metadata("design:type", String)
|
|
48
60
|
], ImmutableProof.prototype, "verifiableStorageId", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
property({ type: "string", optional: true }),
|
|
63
|
+
__metadata("design:type", Object)
|
|
64
|
+
], ImmutableProof.prototype, "vcContext", void 0);
|
|
49
65
|
ImmutableProof = __decorate([
|
|
50
66
|
entity()
|
|
51
67
|
], ImmutableProof);
|
|
@@ -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;
|
|
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,mBAAmB,CAAU;IAEpC;;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;;2DACT;AAM7B;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 verifiable storage id.\n\t */\n\t@property({ type: \"string\", optional: true })\n\tpublic verifiableStorageId?: 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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentFactory, Guards } from "@twin.org/core";
|
|
2
2
|
import { ImmutableProofContexts, ImmutableProofFailure, ImmutableProofTypes } from "@twin.org/immutable-proof-models";
|
|
3
|
-
import { DidContexts, DidCryptoSuites, ProofTypes } from "@twin.org/standards-w3c-did";
|
|
3
|
+
import { DidContexts, DidCryptoSuites, ProofTypes, DidTypes } from "@twin.org/standards-w3c-did";
|
|
4
4
|
import { HeaderTypes, HttpStatusCode, MimeTypes } from "@twin.org/web";
|
|
5
5
|
/**
|
|
6
6
|
* The source used when communicating about these routes.
|
|
@@ -55,7 +55,7 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
55
55
|
response: {
|
|
56
56
|
statusCode: HttpStatusCode.created,
|
|
57
57
|
headers: {
|
|
58
|
-
[HeaderTypes.Location]: "test
|
|
58
|
+
[HeaderTypes.Location]: "test%3A1234567890"
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -83,7 +83,7 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
83
83
|
[HeaderTypes.Accept]: MimeTypes.Json
|
|
84
84
|
},
|
|
85
85
|
pathParams: {
|
|
86
|
-
id: "
|
|
86
|
+
id: "immutable-proof:1234567890"
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -98,20 +98,28 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
98
98
|
response: {
|
|
99
99
|
body: {
|
|
100
100
|
"@context": [
|
|
101
|
-
|
|
102
|
-
ImmutableProofContexts.
|
|
101
|
+
DidContexts.ContextVCv1,
|
|
102
|
+
ImmutableProofContexts.Context,
|
|
103
|
+
ImmutableProofContexts.ContextCommon
|
|
103
104
|
],
|
|
104
|
-
type: ImmutableProofTypes.ImmutableProof,
|
|
105
|
-
id: "
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
type: [DidTypes.VerifiableCredential, ImmutableProofTypes.ImmutableProof],
|
|
106
|
+
id: "immutable-proof:1234567890",
|
|
107
|
+
credentialSubject: {
|
|
108
|
+
id: "ais:1234567890",
|
|
109
|
+
proofIntegrity: "EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y="
|
|
110
|
+
},
|
|
108
111
|
proof: {
|
|
109
|
-
"@context": DidContexts.ContextDataIntegrity,
|
|
110
112
|
type: ProofTypes.DataIntegrityProof,
|
|
111
113
|
cryptosuite: DidCryptoSuites.EdDSAJcs2022,
|
|
112
114
|
created: "2024-08-22T11:56:56.272Z",
|
|
113
115
|
proofPurpose: "assertionMethod",
|
|
114
|
-
proofValue: "7DdiPPYtxLjCD3wA1po2rv..."
|
|
116
|
+
proofValue: "7DdiPPYtxLjCD3wA1po2rv...",
|
|
117
|
+
verificationMethod: "did:iota:testnet:0xcb07cabaa2f23b7e53d8cdc4228efb351ebb270554d13bc382e4f94ca8d3136b#immutable-proof-assertion",
|
|
118
|
+
verifiableStorageId: "verifiable-storage:1234567890",
|
|
119
|
+
immutableReceipt: {
|
|
120
|
+
id: "immutable-receipt:1234567890",
|
|
121
|
+
type: "ImmutableReceipt"
|
|
122
|
+
}
|
|
115
123
|
}
|
|
116
124
|
}
|
|
117
125
|
}
|
|
@@ -130,20 +138,28 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
130
138
|
},
|
|
131
139
|
body: {
|
|
132
140
|
"@context": [
|
|
133
|
-
|
|
134
|
-
ImmutableProofContexts.
|
|
141
|
+
DidContexts.ContextVCv1,
|
|
142
|
+
ImmutableProofContexts.Context,
|
|
143
|
+
ImmutableProofContexts.ContextCommon
|
|
135
144
|
],
|
|
136
|
-
type: ImmutableProofTypes.ImmutableProof,
|
|
137
|
-
id: "
|
|
138
|
-
|
|
139
|
-
|
|
145
|
+
type: [DidTypes.VerifiableCredential, ImmutableProofTypes.ImmutableProof],
|
|
146
|
+
id: "immutable-proof:1234567890",
|
|
147
|
+
credentialSubject: {
|
|
148
|
+
id: "ais:1234567890",
|
|
149
|
+
proofIntegrity: "EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y="
|
|
150
|
+
},
|
|
140
151
|
proof: {
|
|
141
|
-
"@context": DidContexts.ContextDataIntegrity,
|
|
142
152
|
type: ProofTypes.DataIntegrityProof,
|
|
143
153
|
cryptosuite: DidCryptoSuites.EdDSAJcs2022,
|
|
144
154
|
created: "2024-08-22T11:56:56.272Z",
|
|
145
155
|
proofPurpose: "assertionMethod",
|
|
146
|
-
proofValue: "7DdiPPYtxLjCD3wA1po2rv..."
|
|
156
|
+
proofValue: "7DdiPPYtxLjCD3wA1po2rv...",
|
|
157
|
+
verificationMethod: "did:iota:testnet:0xcb07cabaa2f23b7e53d8cdc4228efb351ebb270554d13bc382e4f94ca8d3136b#immutable-proof-assertion",
|
|
158
|
+
verifiableStorageId: "verifiable-storage:1234567890",
|
|
159
|
+
immutableReceipt: {
|
|
160
|
+
id: "immutable-receipt:1234567890",
|
|
161
|
+
type: "ImmutableReceipt"
|
|
162
|
+
}
|
|
147
163
|
}
|
|
148
164
|
}
|
|
149
165
|
}
|
|
@@ -169,7 +185,7 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
169
185
|
id: "immutableProofVerifyRequestExample",
|
|
170
186
|
request: {
|
|
171
187
|
pathParams: {
|
|
172
|
-
id: "
|
|
188
|
+
id: "immutable-proof:1234567890"
|
|
173
189
|
}
|
|
174
190
|
}
|
|
175
191
|
}
|
|
@@ -183,7 +199,7 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
183
199
|
id: "immutableProofVerifyResponseExample",
|
|
184
200
|
response: {
|
|
185
201
|
body: {
|
|
186
|
-
"@context": ImmutableProofContexts.
|
|
202
|
+
"@context": ImmutableProofContexts.Context,
|
|
187
203
|
type: ImmutableProofTypes.ImmutableProofVerification,
|
|
188
204
|
verified: true
|
|
189
205
|
}
|
|
@@ -198,10 +214,10 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
198
214
|
id: "immutableProofVerifyResponseFailExample",
|
|
199
215
|
response: {
|
|
200
216
|
body: {
|
|
201
|
-
"@context": ImmutableProofContexts.
|
|
217
|
+
"@context": ImmutableProofContexts.Context,
|
|
202
218
|
type: ImmutableProofTypes.ImmutableProofVerification,
|
|
203
219
|
verified: false,
|
|
204
|
-
failure: ImmutableProofFailure.
|
|
220
|
+
failure: ImmutableProofFailure.VerificationFailure
|
|
205
221
|
}
|
|
206
222
|
}
|
|
207
223
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"immutableProofRoutes.js","sourceRoot":"","sources":["../../src/immutableProofRoutes.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAON,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,6B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S,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 { DidContexts, DidCryptoSuites, ProofTypes } from \"@twin.org/standards-w3c-did\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"immutableProofRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsImmutableProof: ITag[] = [\n\t{\n\t\tname: \"Immutable Proof\",\n\t\tdescription: \"Endpoints which are modelled to access an immutable proof contract.\"\n\t}\n];\n\n/**\n * The REST routes for immutable proof.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesImmutableProof(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createRoute: IRestRoute<IImmutableProofCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"immutableProofCreate\",\n\t\tsummary: \"Create a proof\",\n\t\ttag: tagsImmutableProof[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\timmutableProofCreate(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IImmutableProofCreateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"immutableProofCreateRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tdocument: {\n\t\t\t\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\t\t\ttype: \"Person\",\n\t\t\t\t\t\t\t\tname: \"John Smith\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofCreateResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: HttpStatusCode.created,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.Location]: \"test:1234567890\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst getRoute: IRestRoute<IImmutableProofGetRequest, IImmutableProofGetResponse> = {\n\t\toperationId: \"immutableProofGet\",\n\t\tsummary: \"Get a proof\",\n\t\ttag: tagsImmutableProof[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\timmutableProofGet(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IImmutableProofGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"immutableProofGetRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.Json\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"ais:1234567890\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IImmutableProofGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": [\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.ContextRoot,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.ContextRootCommon\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\ttype: ImmutableProofTypes.ImmutableProof,\n\t\t\t\t\t\t\t\tid: \"ais:1234567890\",\n\t\t\t\t\t\t\t\tproofObjectId: \"test:1234567890\",\n\t\t\t\t\t\t\t\tproofObjectHash: \"EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y=\",\n\t\t\t\t\t\t\t\tproof: {\n\t\t\t\t\t\t\t\t\t\"@context\": DidContexts.ContextDataIntegrity,\n\t\t\t\t\t\t\t\t\ttype: ProofTypes.DataIntegrityProof,\n\t\t\t\t\t\t\t\t\tcryptosuite: DidCryptoSuites.EdDSAJcs2022,\n\t\t\t\t\t\t\t\t\tcreated: \"2024-08-22T11:56:56.272Z\",\n\t\t\t\t\t\t\t\t\tproofPurpose: \"assertionMethod\",\n\t\t\t\t\t\t\t\t\tproofValue: \"7DdiPPYtxLjCD3wA1po2rv...\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IImmutableProofGetResponse>(),\n\t\t\t\tmimeType: MimeTypes.JsonLd,\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofJsonLdGetResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.ContentType]: MimeTypes.JsonLd\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": [\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.ContextRoot,\n\t\t\t\t\t\t\t\t\tImmutableProofContexts.ContextRootCommon\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\ttype: ImmutableProofTypes.ImmutableProof,\n\t\t\t\t\t\t\t\tid: \"ais:1234567890\",\n\t\t\t\t\t\t\t\tproofObjectId: \"test:1234567890\",\n\t\t\t\t\t\t\t\tproofObjectHash: \"EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y=\",\n\t\t\t\t\t\t\t\tproof: {\n\t\t\t\t\t\t\t\t\t\"@context\": DidContexts.ContextDataIntegrity,\n\t\t\t\t\t\t\t\t\ttype: ProofTypes.DataIntegrityProof,\n\t\t\t\t\t\t\t\t\tcryptosuite: DidCryptoSuites.EdDSAJcs2022,\n\t\t\t\t\t\t\t\t\tcreated: \"2024-08-22T11:56:56.272Z\",\n\t\t\t\t\t\t\t\t\tproofPurpose: \"assertionMethod\",\n\t\t\t\t\t\t\t\t\tproofValue: \"7DdiPPYtxLjCD3wA1po2rv...\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst verifyRoute: IRestRoute<IImmutableProofVerifyRequest, IImmutableProofVerifyResponse> = {\n\t\toperationId: \"immutableProofVerify\",\n\t\tsummary: \"Verify a proof\",\n\t\ttag: tagsImmutableProof[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/:id/verify`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\timmutableProofVerify(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IImmutableProofVerifyRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"immutableProofVerifyRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"ais:1234567890\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IImmutableProofVerifyResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofVerifyResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": ImmutableProofContexts.ContextRoot,\n\t\t\t\t\t\t\t\ttype: ImmutableProofTypes.ImmutableProofVerification,\n\t\t\t\t\t\t\t\tverified: true\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IImmutableProofVerifyResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"immutableProofVerifyResponseFailExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\"@context\": ImmutableProofContexts.ContextRoot,\n\t\t\t\t\t\t\t\ttype: ImmutableProofTypes.ImmutableProofVerification,\n\t\t\t\t\t\t\t\tverified: false,\n\t\t\t\t\t\t\t\tfailure: ImmutableProofFailure.ProofTypeMismatch\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [createRoute, getRoute, verifyRoute];\n}\n\n/**\n * Create a proof.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function immutableProofCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofCreateRequest\n): Promise<ICreatedResponse> {\n\tGuards.object<IImmutableProofCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object(ROUTES_SOURCE, nameof(request.body.document), request.body.document);\n\n\tconst component = ComponentFactory.get<IImmutableProofComponent>(componentName);\n\tconst result = await component.create(request.body.document);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders: {\n\t\t\t[HeaderTypes.Location]: result\n\t\t}\n\t};\n}\n\n/**\n * Get the proof.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function immutableProofGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofGetRequest\n): Promise<IImmutableProofGetResponse> {\n\tGuards.object<IImmutableProofGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IImmutableProofGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst mimeType = request.headers?.[HeaderTypes.Accept] === MimeTypes.JsonLd ? \"jsonld\" : \"json\";\n\n\tconst component = ComponentFactory.get<IImmutableProofComponent>(componentName);\n\tconst result = await component.get(request.pathParams.id);\n\n\treturn {\n\t\theaders: {\n\t\t\t[HeaderTypes.ContentType]: mimeType === \"json\" ? MimeTypes.Json : MimeTypes.JsonLd\n\t\t},\n\t\tbody: result\n\t};\n}\n\n/**\n * Verify the proof.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function immutableProofVerify(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofVerifyRequest\n): Promise<IImmutableProofVerifyResponse> {\n\tGuards.object<IImmutableProofVerifyRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IImmutableProofVerifyRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst mimeType = request.headers?.[HeaderTypes.Accept] === MimeTypes.JsonLd ? \"jsonld\" : \"json\";\n\n\tconst component = ComponentFactory.get<IImmutableProofComponent>(componentName);\n\tconst result = await component.verify(request.pathParams.id);\n\n\treturn {\n\t\theaders: {\n\t\t\t[HeaderTypes.ContentType]: mimeType === \"json\" ? MimeTypes.Json : MimeTypes.JsonLd\n\t\t},\n\t\tbody: result\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"immutableProofRoutes.js","sourceRoot":"","sources":["../../src/immutableProofRoutes.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAON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,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM;SAClF;QACD,IAAI,EAAE,MAAM;KACZ,CAAC;AACH,CAAC;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,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\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,14 +1,14 @@
|
|
|
1
1
|
// Copyright 2024 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import {
|
|
3
|
+
import { TaskStatus } from "@twin.org/background-task-models";
|
|
4
4
|
import { ContextIdHelper, ContextIdKeys, ContextIdStore } from "@twin.org/context";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { BaseError, ComponentFactory, GeneralError, Guards, Is, JsonHelper, NotFoundError, ObjectHelper, RandomHelper, Urn, Validation } from "@twin.org/core";
|
|
6
|
+
import { IntegrityAlgorithm, IntegrityHelper } from "@twin.org/crypto";
|
|
7
7
|
import { JsonLdHelper, JsonLdProcessor } from "@twin.org/data-json-ld";
|
|
8
8
|
import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
9
9
|
import { IdentityConnectorFactory } from "@twin.org/identity-models";
|
|
10
10
|
import { ImmutableProofContexts, ImmutableProofFailure, ImmutableProofTopics, ImmutableProofTypes } from "@twin.org/immutable-proof-models";
|
|
11
|
-
import {
|
|
11
|
+
import { DidContexts, DidTypes, VerifiableCredentialHelper } from "@twin.org/standards-w3c-did";
|
|
12
12
|
import { VerifiableStorageConnectorFactory } from "@twin.org/verifiable-storage-models";
|
|
13
13
|
/**
|
|
14
14
|
* Class for performing immutable proof operations.
|
|
@@ -28,6 +28,11 @@ export class ImmutableProofService {
|
|
|
28
28
|
* @internal
|
|
29
29
|
*/
|
|
30
30
|
_config;
|
|
31
|
+
/**
|
|
32
|
+
* The logging component.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
_logging;
|
|
31
36
|
/**
|
|
32
37
|
* The identity connector.
|
|
33
38
|
* @internal
|
|
@@ -44,10 +49,10 @@ export class ImmutableProofService {
|
|
|
44
49
|
*/
|
|
45
50
|
_verifiableStorage;
|
|
46
51
|
/**
|
|
47
|
-
* The background task
|
|
52
|
+
* The background task component.
|
|
48
53
|
* @internal
|
|
49
54
|
*/
|
|
50
|
-
|
|
55
|
+
_backgroundTaskComponent;
|
|
51
56
|
/**
|
|
52
57
|
* The event bus component.
|
|
53
58
|
* @internal
|
|
@@ -70,9 +75,10 @@ export class ImmutableProofService {
|
|
|
70
75
|
constructor(options) {
|
|
71
76
|
this._proofStorage = EntityStorageConnectorFactory.get(options?.immutableProofEntityStorageType ?? "immutable-proof");
|
|
72
77
|
this._verifiableStorage = VerifiableStorageConnectorFactory.get(options?.verifiableStorageType ?? "verifiable-storage");
|
|
78
|
+
this._logging = ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
|
|
73
79
|
this._identityConnectorType = options?.identityConnectorType ?? "identity";
|
|
74
80
|
this._identityConnector = IdentityConnectorFactory.get(this._identityConnectorType);
|
|
75
|
-
this.
|
|
81
|
+
this._backgroundTaskComponent = ComponentFactory.get(options?.backgroundTaskComponentType ?? "background-task");
|
|
76
82
|
if (Is.stringValue(options?.eventBusComponentType)) {
|
|
77
83
|
this._eventBusComponent = ComponentFactory.get(options.eventBusComponentType);
|
|
78
84
|
}
|
|
@@ -92,7 +98,7 @@ export class ImmutableProofService {
|
|
|
92
98
|
* @returns Nothing.
|
|
93
99
|
*/
|
|
94
100
|
async start(nodeLoggingComponentType) {
|
|
95
|
-
await this.
|
|
101
|
+
await this._backgroundTaskComponent.registerHandler("immutable-proof", "@twin.org/immutable-proof-task", "processProofTask", async (task) => {
|
|
96
102
|
await this.finaliseTask(task);
|
|
97
103
|
});
|
|
98
104
|
}
|
|
@@ -109,30 +115,39 @@ export class ImmutableProofService {
|
|
|
109
115
|
const validationFailures = [];
|
|
110
116
|
await JsonLdHelper.validate(document, validationFailures);
|
|
111
117
|
Validation.asValidationError(ImmutableProofService.CLASS_NAME, "document", validationFailures);
|
|
112
|
-
const id =
|
|
118
|
+
const id = RandomHelper.generateUuidV7("compact");
|
|
113
119
|
const dateCreated = new Date(Date.now()).toISOString();
|
|
114
120
|
const proofObjectId = ObjectHelper.extractProperty(document, ["@id", "id"], false);
|
|
115
121
|
// We don't want to store the whole document in the immutable proof, as this could be large
|
|
116
122
|
// and also reveal information that should not be stored in the proof so we hash the document
|
|
117
123
|
// and store the hash
|
|
118
|
-
const
|
|
124
|
+
const proofObjectIntegrity = IntegrityHelper.generate(IntegrityAlgorithm.Sha256, ObjectHelper.toBytes(JsonHelper.canonicalize(document)));
|
|
125
|
+
const credentialSubject = {
|
|
126
|
+
"@context": [ImmutableProofContexts.Context, ImmutableProofContexts.ContextCommon],
|
|
127
|
+
type: ImmutableProofTypes.ImmutableProof,
|
|
128
|
+
id: proofObjectId,
|
|
129
|
+
proofIntegrity: proofObjectIntegrity
|
|
130
|
+
};
|
|
119
131
|
const proofEntity = {
|
|
120
132
|
id,
|
|
133
|
+
organizationId: contextIds[ContextIdKeys.Organization],
|
|
121
134
|
dateCreated,
|
|
122
135
|
proofObjectId,
|
|
123
|
-
|
|
136
|
+
proofObjectIntegrity
|
|
124
137
|
};
|
|
125
138
|
await this._proofStorage.set(proofEntity);
|
|
126
|
-
const
|
|
139
|
+
const fullId = new Urn(ImmutableProofService._NAMESPACE, id).toString();
|
|
127
140
|
const proofTaskPayload = {
|
|
128
|
-
proofId:
|
|
141
|
+
proofId: fullId,
|
|
129
142
|
identity: contextIds[ContextIdKeys.Organization],
|
|
130
143
|
identityConnectorType: this._identityConnectorType,
|
|
131
144
|
verificationMethodId: this._verificationMethodId,
|
|
132
|
-
|
|
145
|
+
credentialSubject
|
|
133
146
|
};
|
|
134
|
-
await this.
|
|
135
|
-
|
|
147
|
+
await this._backgroundTaskComponent.create("immutable-proof", proofTaskPayload, {
|
|
148
|
+
retainFor: 5000
|
|
149
|
+
});
|
|
150
|
+
return fullId;
|
|
136
151
|
}
|
|
137
152
|
catch (error) {
|
|
138
153
|
throw new GeneralError(ImmutableProofService.CLASS_NAME, "createFailed", undefined, error);
|
|
@@ -154,8 +169,8 @@ export class ImmutableProofService {
|
|
|
154
169
|
});
|
|
155
170
|
}
|
|
156
171
|
try {
|
|
157
|
-
const {
|
|
158
|
-
const result = await JsonLdProcessor.compact(
|
|
172
|
+
const { verifiableCredential } = await this.internalGet(id, false);
|
|
173
|
+
const result = await JsonLdProcessor.compact(verifiableCredential, verifiableCredential["@context"]);
|
|
159
174
|
return result;
|
|
160
175
|
}
|
|
161
176
|
catch (error) {
|
|
@@ -180,7 +195,7 @@ export class ImmutableProofService {
|
|
|
180
195
|
try {
|
|
181
196
|
const { verified, failure } = await this.internalGet(id, true);
|
|
182
197
|
return {
|
|
183
|
-
"@context": ImmutableProofContexts.
|
|
198
|
+
"@context": ImmutableProofContexts.Context,
|
|
184
199
|
type: ImmutableProofTypes.ImmutableProofVerification,
|
|
185
200
|
verified,
|
|
186
201
|
failure
|
|
@@ -223,54 +238,55 @@ export class ImmutableProofService {
|
|
|
223
238
|
throw new GeneralError(ImmutableProofService.CLASS_NAME, "removeVerifiableFailed", undefined, error);
|
|
224
239
|
}
|
|
225
240
|
}
|
|
226
|
-
/**
|
|
227
|
-
* Calculate the object hash.
|
|
228
|
-
* @param object The entry to calculate the hash for.
|
|
229
|
-
* @returns The hash.
|
|
230
|
-
* @internal
|
|
231
|
-
*/
|
|
232
|
-
calculateDocumentHash(nodeObject) {
|
|
233
|
-
return `sha256:${Converter.bytesToBase64(Sha256.sum256(ObjectHelper.toBytes(JsonHelper.canonicalize(nodeObject))))}`;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Map the stream entity to a model.
|
|
237
|
-
* @param proofEntity The stream entity.
|
|
238
|
-
* @returns The model.
|
|
239
|
-
* @internal
|
|
240
|
-
*/
|
|
241
|
-
proofEntityToJsonLd(proofEntity) {
|
|
242
|
-
const jsonLd = {
|
|
243
|
-
"@context": [ImmutableProofContexts.ContextRoot, ImmutableProofContexts.ContextRootCommon],
|
|
244
|
-
type: ImmutableProofTypes.ImmutableProof,
|
|
245
|
-
id: proofEntity.id,
|
|
246
|
-
proofObjectId: proofEntity.proofObjectId,
|
|
247
|
-
proofObjectHash: proofEntity.proofObjectHash,
|
|
248
|
-
verifiableStorageId: proofEntity.verifiableStorageId
|
|
249
|
-
};
|
|
250
|
-
return jsonLd;
|
|
251
|
-
}
|
|
252
241
|
/**
|
|
253
242
|
* Process a proof.
|
|
254
243
|
* @param proofEntity The proof entity to process.
|
|
255
244
|
* @internal
|
|
256
245
|
*/
|
|
257
246
|
async finaliseTask(task) {
|
|
258
|
-
if (
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
247
|
+
if (Is.object(task.payload)) {
|
|
248
|
+
if (task.status === TaskStatus.Success && Is.object(task.result)) {
|
|
249
|
+
const urnParsed = Urn.fromValidString(task.payload.proofId);
|
|
250
|
+
const proofId = urnParsed.namespaceSpecific(0);
|
|
251
|
+
const proofEntity = await this._proofStorage.get(proofId);
|
|
252
|
+
if (Is.object(proofEntity)) {
|
|
253
|
+
// Extract the proof from the task result vc
|
|
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
|
+
// Remove the verification method so that we reduce the linkage between
|
|
259
|
+
// the proof and the identity that issued it, we will reinstate on verification
|
|
260
|
+
delete proof.verificationMethod;
|
|
261
|
+
// Store the proof in the verifiable storage and get the id of where it is stored so we can retrieve it later
|
|
262
|
+
const verifiableCreateResult = await this._verifiableStorage.create(task.payload.identity, ObjectHelper.toBytes(proof));
|
|
263
|
+
// Update the proof entity with the verifiable storage id so we can retrieve it later
|
|
264
|
+
proofEntity.verifiableStorageId = verifiableCreateResult.id;
|
|
265
|
+
// Update the date created if we can extract it from the VC
|
|
266
|
+
const validFrom = VerifiableCredentialHelper.getValidFrom(task.result.verifiableCredential);
|
|
267
|
+
if (Is.stringValue(validFrom)) {
|
|
268
|
+
proofEntity.dateCreated = validFrom;
|
|
269
|
+
}
|
|
270
|
+
proofEntity.vcContext = VerifiableCredentialHelper.getContext(task.result.verifiableCredential);
|
|
271
|
+
await this._proofStorage.set(proofEntity);
|
|
272
|
+
await this._logging?.log({
|
|
273
|
+
source: ImmutableProofService.CLASS_NAME,
|
|
274
|
+
level: "info",
|
|
275
|
+
ts: Date.now(),
|
|
276
|
+
message: "createdProof",
|
|
277
|
+
data: { proofId: task.payload.proofId }
|
|
278
|
+
});
|
|
279
|
+
await this._eventBusComponent?.publish(ImmutableProofTopics.ProofCreated, { id: new Urn(ImmutableProofService._NAMESPACE, task.payload.proofId).toString() });
|
|
268
280
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
281
|
+
}
|
|
282
|
+
else if (task.status === TaskStatus.Failed) {
|
|
283
|
+
await this._logging?.log({
|
|
284
|
+
source: ImmutableProofService.CLASS_NAME,
|
|
285
|
+
level: "error",
|
|
286
|
+
ts: Date.now(),
|
|
287
|
+
message: "createProofFailed",
|
|
288
|
+
error: BaseError.fromError(task.error)
|
|
289
|
+
});
|
|
274
290
|
}
|
|
275
291
|
}
|
|
276
292
|
}
|
|
@@ -289,44 +305,58 @@ export class ImmutableProofService {
|
|
|
289
305
|
if (Is.empty(proofEntity)) {
|
|
290
306
|
throw new NotFoundError(ImmutableProofService.CLASS_NAME, "proofNotFound", id);
|
|
291
307
|
}
|
|
292
|
-
|
|
308
|
+
const verifiableCredential = {
|
|
309
|
+
"@context": [
|
|
310
|
+
proofEntity.vcContext ?? DidContexts.ContextVCv1,
|
|
311
|
+
ImmutableProofContexts.Context,
|
|
312
|
+
ImmutableProofContexts.ContextCommon
|
|
313
|
+
],
|
|
314
|
+
type: [DidTypes.VerifiableCredential, ImmutableProofTypes.ImmutableProof],
|
|
315
|
+
id,
|
|
316
|
+
issuer: proofEntity.organizationId,
|
|
317
|
+
credentialSubject: {
|
|
318
|
+
id: proofEntity.proofObjectId,
|
|
319
|
+
proofIntegrity: proofEntity.proofObjectIntegrity
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
VerifiableCredentialHelper.setValidFrom(verifiableCredential, proofEntity.dateCreated);
|
|
293
323
|
let verified = false;
|
|
294
324
|
let failure = ImmutableProofFailure.NotIssued;
|
|
295
325
|
if (Is.stringValue(proofEntity.verifiableStorageId)) {
|
|
296
326
|
failure = ImmutableProofFailure.ProofMissing;
|
|
297
327
|
const immutableResult = await this._verifiableStorage.get(proofEntity.verifiableStorageId);
|
|
298
328
|
if (Is.uint8Array(immutableResult.data)) {
|
|
299
|
-
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
else {
|
|
316
|
-
const isVerified = await this._identityConnector.verifyProof(unsecureDocument, proofJsonLd.proof);
|
|
317
|
-
if (isVerified) {
|
|
318
|
-
verified = true;
|
|
319
|
-
failure = undefined;
|
|
329
|
+
const proof = ObjectHelper.fromBytes(immutableResult.data);
|
|
330
|
+
const proofWithReceipt = {
|
|
331
|
+
...proof,
|
|
332
|
+
verificationMethod: `${proofEntity.organizationId}#${this._verificationMethodId}`,
|
|
333
|
+
verifiableStorageId: proofEntity.verifiableStorageId,
|
|
334
|
+
immutableReceipt: immutableResult.receipt
|
|
335
|
+
};
|
|
336
|
+
// Add the proof from the verifiable storage
|
|
337
|
+
// expand it with the verifiable storage id and receipt
|
|
338
|
+
verifiableCredential.proof = proofWithReceipt;
|
|
339
|
+
if (verify && Is.object(proof)) {
|
|
340
|
+
try {
|
|
341
|
+
const result = await this._identityConnector.checkVerifiableCredential(verifiableCredential);
|
|
342
|
+
if (result.revoked) {
|
|
343
|
+
verified = false;
|
|
344
|
+
failure = ImmutableProofFailure.Revoked;
|
|
320
345
|
}
|
|
321
346
|
else {
|
|
322
|
-
|
|
347
|
+
verified = true;
|
|
348
|
+
failure = undefined;
|
|
323
349
|
}
|
|
324
350
|
}
|
|
351
|
+
catch {
|
|
352
|
+
verified = false;
|
|
353
|
+
failure = ImmutableProofFailure.VerificationFailure;
|
|
354
|
+
}
|
|
325
355
|
}
|
|
326
356
|
}
|
|
327
357
|
}
|
|
328
358
|
return {
|
|
329
|
-
|
|
359
|
+
verifiableCredential: await JsonLdProcessor.compact(verifiableCredential, JsonLdProcessor.gatherContexts(verifiableCredential)),
|
|
330
360
|
verified,
|
|
331
361
|
failure
|
|
332
362
|
};
|