@twin.org/immutable-proof-service 0.0.3-next.7 → 0.0.3-next.9
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 +41 -19
- package/dist/es/immutableProofRoutes.js.map +1 -1
- package/dist/es/immutableProofService.js +77 -73
- package/dist/es/immutableProofService.js.map +1 -1
- package/dist/types/entities/immutableProof.d.ts +11 -2
- package/dist/types/immutableProofService.d.ts +3 -2
- package/docs/changelog.md +30 -0
- package/docs/open-api/spec.json +587 -20
- package/docs/reference/classes/ImmutableProof.md +19 -3
- package/docs/reference/classes/ImmutableProofService.md +2 -2
- package/package.json +3 -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
|
}
|
|
@@ -97,18 +97,29 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
97
97
|
id: "immutableProofGetResponseExample",
|
|
98
98
|
response: {
|
|
99
99
|
body: {
|
|
100
|
-
"@context": [
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
"@context": [
|
|
101
|
+
DidContexts.ContextVCv1,
|
|
102
|
+
ImmutableProofContexts.Context,
|
|
103
|
+
ImmutableProofContexts.ContextCommon
|
|
104
|
+
],
|
|
105
|
+
type: [DidTypes.VerifiableCredential, ImmutableProofTypes.ImmutableProof],
|
|
106
|
+
id: "immutable-proof:1234567890",
|
|
107
|
+
credentialSubject: {
|
|
108
|
+
id: "ais:1234567890",
|
|
109
|
+
proofIntegrity: "EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y="
|
|
110
|
+
},
|
|
105
111
|
proof: {
|
|
106
|
-
"@context": DidContexts.ContextDataIntegrity,
|
|
107
112
|
type: ProofTypes.DataIntegrityProof,
|
|
108
113
|
cryptosuite: DidCryptoSuites.EdDSAJcs2022,
|
|
109
114
|
created: "2024-08-22T11:56:56.272Z",
|
|
110
115
|
proofPurpose: "assertionMethod",
|
|
111
|
-
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
|
+
}
|
|
112
123
|
}
|
|
113
124
|
}
|
|
114
125
|
}
|
|
@@ -126,18 +137,29 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
126
137
|
[HeaderTypes.ContentType]: MimeTypes.JsonLd
|
|
127
138
|
},
|
|
128
139
|
body: {
|
|
129
|
-
"@context": [
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
"@context": [
|
|
141
|
+
DidContexts.ContextVCv1,
|
|
142
|
+
ImmutableProofContexts.Context,
|
|
143
|
+
ImmutableProofContexts.ContextCommon
|
|
144
|
+
],
|
|
145
|
+
type: [DidTypes.VerifiableCredential, ImmutableProofTypes.ImmutableProof],
|
|
146
|
+
id: "immutable-proof:1234567890",
|
|
147
|
+
credentialSubject: {
|
|
148
|
+
id: "ais:1234567890",
|
|
149
|
+
proofIntegrity: "EAOKyDN0mYQbBh91eMdVeroxQx1H4GfnRbmt6n/2L/Y="
|
|
150
|
+
},
|
|
134
151
|
proof: {
|
|
135
|
-
"@context": DidContexts.ContextDataIntegrity,
|
|
136
152
|
type: ProofTypes.DataIntegrityProof,
|
|
137
153
|
cryptosuite: DidCryptoSuites.EdDSAJcs2022,
|
|
138
154
|
created: "2024-08-22T11:56:56.272Z",
|
|
139
155
|
proofPurpose: "assertionMethod",
|
|
140
|
-
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
|
+
}
|
|
141
163
|
}
|
|
142
164
|
}
|
|
143
165
|
}
|
|
@@ -163,7 +185,7 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
163
185
|
id: "immutableProofVerifyRequestExample",
|
|
164
186
|
request: {
|
|
165
187
|
pathParams: {
|
|
166
|
-
id: "
|
|
188
|
+
id: "immutable-proof:1234567890"
|
|
167
189
|
}
|
|
168
190
|
}
|
|
169
191
|
}
|
|
@@ -195,7 +217,7 @@ export function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
195
217
|
"@context": ImmutableProofContexts.Context,
|
|
196
218
|
type: ImmutableProofTypes.ImmutableProofVerification,
|
|
197
219
|
verified: false,
|
|
198
|
-
failure: ImmutableProofFailure.
|
|
220
|
+
failure: ImmutableProofFailure.VerificationFailure
|
|
199
221
|
}
|
|
200
222
|
}
|
|
201
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,6BAA6B,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEvE;;GAEG;AACH,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAW;IACzC;QACC,IAAI,EAAE,iBAAiB;QACvB,WAAW,EAAE,qEAAqE;KAClF;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC/C,aAAqB,EACrB,aAAqB;IAErB,MAAM,WAAW,GAA+D;QAC/E,WAAW,EAAE,sBAAsB;QACnC,OAAO,EAAE,gBAAgB;QACzB,GAAG,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,IAAI;QAC/B,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,GAAG,aAAa,GAAG;QACzB,OAAO,EAAE,KAAK,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undResponse,\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\": [ImmutableProofContexts.Context, ImmutableProofContexts.ContextCommon],\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\": [ImmutableProofContexts.Context, ImmutableProofContexts.ContextCommon],\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.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.ProofTypeMismatch\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<INotFoundResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [createRoute, getRoute, verifyRoute];\n}\n\n/**\n * Create a proof.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function immutableProofCreate(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofCreateRequest\n): Promise<ICreatedResponse> {\n\tGuards.object<IImmutableProofCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object(ROUTES_SOURCE, nameof(request.body.document), request.body.document);\n\n\tconst component = ComponentFactory.get<IImmutableProofComponent>(componentName);\n\tconst result = await component.create(request.body.document);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders: {\n\t\t\t[HeaderTypes.Location]: result\n\t\t}\n\t};\n}\n\n/**\n * Get the proof.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function immutableProofGet(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofGetRequest\n): Promise<IImmutableProofGetResponse> {\n\tGuards.object<IImmutableProofGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IImmutableProofGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst mimeType = request.headers?.[HeaderTypes.Accept] === MimeTypes.JsonLd ? \"jsonld\" : \"json\";\n\n\tconst component = ComponentFactory.get<IImmutableProofComponent>(componentName);\n\tconst result = await component.get(request.pathParams.id);\n\n\treturn {\n\t\theaders: {\n\t\t\t[HeaderTypes.ContentType]: mimeType === \"json\" ? MimeTypes.Json : MimeTypes.JsonLd\n\t\t},\n\t\tbody: result\n\t};\n}\n\n/**\n * Verify the proof.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function immutableProofVerify(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IImmutableProofVerifyRequest\n): Promise<IImmutableProofVerifyResponse> {\n\tGuards.object<IImmutableProofVerifyRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IImmutableProofVerifyRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst mimeType = request.headers?.[HeaderTypes.Accept] === MimeTypes.JsonLd ? \"jsonld\" : \"json\";\n\n\tconst component = ComponentFactory.get<IImmutableProofComponent>(componentName);\n\tconst result = await component.verify(request.pathParams.id);\n\n\treturn {\n\t\theaders: {\n\t\t\t[HeaderTypes.ContentType]: mimeType === \"json\" ? MimeTypes.Json : MimeTypes.JsonLd\n\t\t},\n\t\tbody: result\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"immutableProofRoutes.js","sourceRoot":"","sources":["../../src/immutableProofRoutes.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAON,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,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,EAA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,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"]}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
import { TaskStatus } from "@twin.org/background-task-models";
|
|
4
4
|
import { ContextIdHelper, ContextIdKeys, ContextIdStore } from "@twin.org/context";
|
|
5
|
-
import { BaseError, ComponentFactory,
|
|
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.
|
|
@@ -115,32 +115,39 @@ export class ImmutableProofService {
|
|
|
115
115
|
const validationFailures = [];
|
|
116
116
|
await JsonLdHelper.validate(document, validationFailures);
|
|
117
117
|
Validation.asValidationError(ImmutableProofService.CLASS_NAME, "document", validationFailures);
|
|
118
|
-
const id =
|
|
118
|
+
const id = RandomHelper.generateUuidV7("compact");
|
|
119
119
|
const dateCreated = new Date(Date.now()).toISOString();
|
|
120
120
|
const proofObjectId = ObjectHelper.extractProperty(document, ["@id", "id"], false);
|
|
121
121
|
// We don't want to store the whole document in the immutable proof, as this could be large
|
|
122
122
|
// and also reveal information that should not be stored in the proof so we hash the document
|
|
123
123
|
// and store the hash
|
|
124
|
-
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
|
+
};
|
|
125
131
|
const proofEntity = {
|
|
126
132
|
id,
|
|
133
|
+
organizationId: contextIds[ContextIdKeys.Organization],
|
|
127
134
|
dateCreated,
|
|
128
135
|
proofObjectId,
|
|
129
|
-
|
|
136
|
+
proofObjectIntegrity
|
|
130
137
|
};
|
|
131
138
|
await this._proofStorage.set(proofEntity);
|
|
132
|
-
const
|
|
139
|
+
const fullId = new Urn(ImmutableProofService._NAMESPACE, id).toString();
|
|
133
140
|
const proofTaskPayload = {
|
|
134
|
-
proofId:
|
|
141
|
+
proofId: fullId,
|
|
135
142
|
identity: contextIds[ContextIdKeys.Organization],
|
|
136
143
|
identityConnectorType: this._identityConnectorType,
|
|
137
144
|
verificationMethodId: this._verificationMethodId,
|
|
138
|
-
|
|
145
|
+
credentialSubject
|
|
139
146
|
};
|
|
140
147
|
await this._backgroundTaskComponent.create("immutable-proof", proofTaskPayload, {
|
|
141
148
|
retainFor: 5000
|
|
142
149
|
});
|
|
143
|
-
return
|
|
150
|
+
return fullId;
|
|
144
151
|
}
|
|
145
152
|
catch (error) {
|
|
146
153
|
throw new GeneralError(ImmutableProofService.CLASS_NAME, "createFailed", undefined, error);
|
|
@@ -162,8 +169,8 @@ export class ImmutableProofService {
|
|
|
162
169
|
});
|
|
163
170
|
}
|
|
164
171
|
try {
|
|
165
|
-
const {
|
|
166
|
-
const result = await JsonLdProcessor.compact(
|
|
172
|
+
const { verifiableCredential } = await this.internalGet(id, false);
|
|
173
|
+
const result = await JsonLdProcessor.compact(verifiableCredential, verifiableCredential["@context"]);
|
|
167
174
|
return result;
|
|
168
175
|
}
|
|
169
176
|
catch (error) {
|
|
@@ -231,32 +238,6 @@ export class ImmutableProofService {
|
|
|
231
238
|
throw new GeneralError(ImmutableProofService.CLASS_NAME, "removeVerifiableFailed", undefined, error);
|
|
232
239
|
}
|
|
233
240
|
}
|
|
234
|
-
/**
|
|
235
|
-
* Calculate the object hash.
|
|
236
|
-
* @param object The entry to calculate the hash for.
|
|
237
|
-
* @returns The hash.
|
|
238
|
-
* @internal
|
|
239
|
-
*/
|
|
240
|
-
calculateDocumentHash(nodeObject) {
|
|
241
|
-
return `sha256:${Converter.bytesToBase64(Sha256.sum256(ObjectHelper.toBytes(JsonHelper.canonicalize(nodeObject))))}`;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Map the stream entity to a model.
|
|
245
|
-
* @param proofEntity The stream entity.
|
|
246
|
-
* @returns The model.
|
|
247
|
-
* @internal
|
|
248
|
-
*/
|
|
249
|
-
proofEntityToJsonLd(proofEntity) {
|
|
250
|
-
const jsonLd = {
|
|
251
|
-
"@context": [ImmutableProofContexts.Context, ImmutableProofContexts.ContextCommon],
|
|
252
|
-
type: ImmutableProofTypes.ImmutableProof,
|
|
253
|
-
id: proofEntity.id,
|
|
254
|
-
proofObjectId: proofEntity.proofObjectId,
|
|
255
|
-
proofObjectHash: proofEntity.proofObjectHash,
|
|
256
|
-
verifiableStorageId: proofEntity.verifiableStorageId
|
|
257
|
-
};
|
|
258
|
-
return jsonLd;
|
|
259
|
-
}
|
|
260
241
|
/**
|
|
261
242
|
* Process a proof.
|
|
262
243
|
* @param proofEntity The proof entity to process.
|
|
@@ -265,19 +246,28 @@ export class ImmutableProofService {
|
|
|
265
246
|
async finaliseTask(task) {
|
|
266
247
|
if (Is.object(task.payload)) {
|
|
267
248
|
if (task.status === TaskStatus.Success && Is.object(task.result)) {
|
|
268
|
-
const
|
|
249
|
+
const urnParsed = Urn.fromValidString(task.payload.proofId);
|
|
250
|
+
const proofId = urnParsed.namespaceSpecific(0);
|
|
251
|
+
const proofEntity = await this._proofStorage.get(proofId);
|
|
269
252
|
if (Is.object(proofEntity)) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const verifiableCreateResult = await this._verifiableStorage.create(task.payload.identity, ObjectHelper.toBytes(
|
|
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
|
|
280
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);
|
|
281
271
|
await this._proofStorage.set(proofEntity);
|
|
282
272
|
await this._logging?.log({
|
|
283
273
|
source: ImmutableProofService.CLASS_NAME,
|
|
@@ -315,44 +305,58 @@ export class ImmutableProofService {
|
|
|
315
305
|
if (Is.empty(proofEntity)) {
|
|
316
306
|
throw new NotFoundError(ImmutableProofService.CLASS_NAME, "proofNotFound", id);
|
|
317
307
|
}
|
|
318
|
-
|
|
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);
|
|
319
323
|
let verified = false;
|
|
320
324
|
let failure = ImmutableProofFailure.NotIssued;
|
|
321
325
|
if (Is.stringValue(proofEntity.verifiableStorageId)) {
|
|
322
326
|
failure = ImmutableProofFailure.ProofMissing;
|
|
323
327
|
const immutableResult = await this._verifiableStorage.get(proofEntity.verifiableStorageId);
|
|
324
328
|
if (Is.uint8Array(immutableResult.data)) {
|
|
325
|
-
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
else {
|
|
342
|
-
const isVerified = await this._identityConnector.verifyProof(unsecureDocument, proofJsonLd.proof);
|
|
343
|
-
if (isVerified) {
|
|
344
|
-
verified = true;
|
|
345
|
-
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;
|
|
346
345
|
}
|
|
347
346
|
else {
|
|
348
|
-
|
|
347
|
+
verified = true;
|
|
348
|
+
failure = undefined;
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
|
+
catch {
|
|
352
|
+
verified = false;
|
|
353
|
+
failure = ImmutableProofFailure.VerificationFailure;
|
|
354
|
+
}
|
|
351
355
|
}
|
|
352
356
|
}
|
|
353
357
|
}
|
|
354
358
|
return {
|
|
355
|
-
|
|
359
|
+
verifiableCredential: await JsonLdProcessor.compact(verifiableCredential, JsonLdProcessor.gatherContexts(verifiableCredential)),
|
|
356
360
|
verified,
|
|
357
361
|
failure
|
|
358
362
|
};
|