@twin.org/identity-service 0.0.2-next.9 → 0.0.3-next.2

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.
Files changed (40) hide show
  1. package/dist/es/identityProfileRoutes.js +389 -0
  2. package/dist/es/identityProfileRoutes.js.map +1 -0
  3. package/dist/es/identityProfileService.js +165 -0
  4. package/dist/es/identityProfileService.js.map +1 -0
  5. package/dist/es/identityResolverRoutes.js +87 -0
  6. package/dist/es/identityResolverRoutes.js.map +1 -0
  7. package/dist/es/identityResolverService.js +98 -0
  8. package/dist/es/identityResolverService.js.map +1 -0
  9. package/dist/es/identityRoutes.js +946 -0
  10. package/dist/es/identityRoutes.js.map +1 -0
  11. package/dist/es/identityService.js +391 -0
  12. package/dist/es/identityService.js.map +1 -0
  13. package/dist/es/index.js +15 -0
  14. package/dist/es/index.js.map +1 -0
  15. package/dist/es/models/IIdentityProfileServiceConstructorOptions.js +2 -0
  16. package/dist/es/models/IIdentityProfileServiceConstructorOptions.js.map +1 -0
  17. package/dist/es/models/IIdentityResolverServiceConfig.js +4 -0
  18. package/dist/es/models/IIdentityResolverServiceConfig.js.map +1 -0
  19. package/dist/es/models/IIdentityResolverServiceConstructorOptions.js +2 -0
  20. package/dist/es/models/IIdentityResolverServiceConstructorOptions.js.map +1 -0
  21. package/dist/es/models/IIdentityServiceConfig.js +4 -0
  22. package/dist/es/models/IIdentityServiceConfig.js.map +1 -0
  23. package/dist/es/models/IIdentityServiceConstructorOptions.js +2 -0
  24. package/dist/es/models/IIdentityServiceConstructorOptions.js.map +1 -0
  25. package/dist/es/restEntryPoints.js +24 -0
  26. package/dist/es/restEntryPoints.js.map +1 -0
  27. package/dist/types/identityProfileService.d.ts +6 -1
  28. package/dist/types/identityResolverService.d.ts +6 -1
  29. package/dist/types/identityService.d.ts +6 -1
  30. package/dist/types/index.d.ts +12 -12
  31. package/dist/types/models/IIdentityResolverServiceConstructorOptions.d.ts +1 -1
  32. package/dist/types/models/IIdentityServiceConstructorOptions.d.ts +1 -1
  33. package/docs/changelog.md +66 -0
  34. package/docs/open-api/spec.json +115 -130
  35. package/docs/reference/classes/IdentityProfileService.md +18 -0
  36. package/docs/reference/classes/IdentityResolverService.md +18 -0
  37. package/docs/reference/classes/IdentityService.md +22 -4
  38. package/package.json +7 -8
  39. package/dist/cjs/index.cjs +0 -2071
  40. package/dist/esm/index.mjs +0 -2039
@@ -1,2071 +0,0 @@
1
- 'use strict';
2
-
3
- var apiModels = require('@twin.org/api-models');
4
- var core = require('@twin.org/core');
5
- var web = require('@twin.org/web');
6
- var identityModels = require('@twin.org/identity-models');
7
- var standardsW3cDid = require('@twin.org/standards-w3c-did');
8
-
9
- // Copyright 2024 IOTA Stiftung.
10
- // SPDX-License-Identifier: Apache-2.0.
11
- /**
12
- * The source used when communicating about these routes.
13
- */
14
- const ROUTES_SOURCE$2 = "identityProfileRoutes";
15
- /**
16
- * The tag to associate with the routes.
17
- */
18
- const tagsIdentityProfile = [
19
- {
20
- name: "Identity Profile",
21
- description: "Service to provide all features related to digital identity profiles."
22
- }
23
- ];
24
- /**
25
- * The REST routes for identity.
26
- * @param baseRouteName Prefix to prepend to the paths.
27
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
28
- * @returns The generated routes.
29
- */
30
- function generateRestRoutesIdentityProfile(baseRouteName, componentName) {
31
- const identityProfileCreateRoute = {
32
- operationId: "identityProfileCreate",
33
- summary: "Create an identity profile",
34
- tag: tagsIdentityProfile[0].name,
35
- method: "POST",
36
- path: `${baseRouteName}/`,
37
- handler: async (httpRequestContext, request) => identityProfileCreate(httpRequestContext, componentName, request),
38
- requestType: {
39
- type: "IIdentityProfileCreateRequest",
40
- examples: [
41
- {
42
- id: "identityProfileCreateRequestExample",
43
- request: {
44
- body: {
45
- publicProfile: {
46
- "@context": "https://schema.org",
47
- "@type": "Person",
48
- jobTitle: "Professor",
49
- name: "Jane Doe"
50
- },
51
- privateProfile: {
52
- "@context": "https://schema.org",
53
- "@type": "Person",
54
- telephone: "(425) 123-4567",
55
- url: "http://www.janedoe.com"
56
- }
57
- }
58
- }
59
- }
60
- ]
61
- },
62
- responseType: [
63
- {
64
- type: "INoContentResponse"
65
- },
66
- {
67
- type: "IConflictResponse"
68
- }
69
- ]
70
- };
71
- const identityProfileGetRoute = {
72
- operationId: "identityProfileGet",
73
- summary: "Get the identity profile properties",
74
- tag: tagsIdentityProfile[0].name,
75
- method: "GET",
76
- path: `${baseRouteName}/`,
77
- handler: async (httpRequestContext, request) => identityGet(httpRequestContext, componentName, request),
78
- requestType: {
79
- type: "IIdentityProfileGetRequest",
80
- examples: [
81
- {
82
- id: "identityGetProfileRequestExample",
83
- request: {
84
- query: {
85
- publicPropertyNames: "name,jobTitle"
86
- }
87
- }
88
- }
89
- ]
90
- },
91
- responseType: [
92
- {
93
- type: "IIdentityProfileGetResponse",
94
- examples: [
95
- {
96
- id: "identityGetResponseExample",
97
- response: {
98
- body: {
99
- identity: "did:iota:tst:0xc57d94b088f4c6d2cb32ded014813d0c786aa00134c8ee22f84b1e2545602a70",
100
- publicProfile: {
101
- "@context": "https://schema.org",
102
- "@type": "Person",
103
- jobTitle: "Professor",
104
- name: "Jane Doe"
105
- }
106
- }
107
- }
108
- }
109
- ]
110
- },
111
- {
112
- type: "INotFoundResponse"
113
- }
114
- ]
115
- };
116
- const identityProfileGetPublicRoute = {
117
- operationId: "identityProfileGetPublic",
118
- summary: "Get the identity profile public properties",
119
- tag: tagsIdentityProfile[0].name,
120
- method: "GET",
121
- path: `${baseRouteName}/:identity/public`,
122
- handler: async (httpRequestContext, request) => identityGetPublic(httpRequestContext, componentName, request),
123
- requestType: {
124
- type: "IIdentityProfileGetPublicRequest",
125
- examples: [
126
- {
127
- id: "identityGetPublicProfileRequestExample",
128
- request: {
129
- pathParams: {
130
- identity: "did:iota:tst:0xc57d94b088f4c6d2cb32ded014813d0c786aa00134c8ee22f84b1e2545602a70"
131
- },
132
- query: {
133
- propertyNames: "role,email,name"
134
- }
135
- }
136
- }
137
- ]
138
- },
139
- responseType: [
140
- {
141
- type: "IIdentityProfileGetPublicResponse",
142
- mimeType: web.MimeTypes.JsonLd,
143
- examples: [
144
- {
145
- id: "identityGetPublicResponseExample",
146
- response: {
147
- headers: {
148
- [web.HeaderTypes.ContentType]: web.MimeTypes.JsonLd
149
- },
150
- body: {
151
- "@context": "https://schema.org",
152
- "@type": "Person",
153
- jobTitle: "Professor",
154
- name: "Jane Doe"
155
- }
156
- }
157
- }
158
- ]
159
- },
160
- {
161
- type: "INotFoundResponse"
162
- }
163
- ],
164
- skipAuth: true
165
- };
166
- const identityProfileUpdateRoute = {
167
- operationId: "identityProfileUpdate",
168
- summary: "Update an identity profile properties",
169
- tag: tagsIdentityProfile[0].name,
170
- method: "PUT",
171
- path: `${baseRouteName}/`,
172
- handler: async (httpRequestContext, request) => identityProfileUpdate(httpRequestContext, componentName, request),
173
- requestType: {
174
- type: "IIdentityProfileUpdateRequest",
175
- examples: [
176
- {
177
- id: "identityProfileUpdateRequestExample",
178
- request: {
179
- body: {
180
- publicProfile: {
181
- "@context": "https://schema.org",
182
- "@type": "Person",
183
- jobTitle: "Professor",
184
- name: "Jane Doe"
185
- },
186
- privateProfile: {
187
- "@context": "https://schema.org",
188
- "@type": "Person",
189
- telephone: "(425) 123-4567",
190
- url: "http://www.janedoe.com"
191
- }
192
- }
193
- }
194
- }
195
- ]
196
- },
197
- responseType: [
198
- {
199
- type: "INoContentResponse"
200
- },
201
- {
202
- type: "INotFoundResponse"
203
- }
204
- ]
205
- };
206
- const identityProfileRemoveRoute = {
207
- operationId: "identityProfileRemove",
208
- summary: "Remove an identity profile",
209
- tag: tagsIdentityProfile[0].name,
210
- method: "DELETE",
211
- path: `${baseRouteName}/`,
212
- handler: async (httpRequestContext, request) => identityProfileRemove(httpRequestContext, componentName),
213
- responseType: [
214
- {
215
- type: "INoContentResponse"
216
- },
217
- {
218
- type: "INotFoundResponse"
219
- }
220
- ]
221
- };
222
- const identityProfileListRoute = {
223
- operationId: "identitiesProfileList",
224
- summary: "Get the list of profile data for identities",
225
- tag: tagsIdentityProfile[0].name,
226
- method: "GET",
227
- path: `${baseRouteName}/query/`,
228
- handler: async (httpRequestContext, request) => identitiesList(httpRequestContext, componentName, request),
229
- requestType: {
230
- type: "IIdentityProfileListRequest",
231
- examples: [
232
- {
233
- id: "identityProfileListRequestExample",
234
- request: {
235
- query: {}
236
- }
237
- },
238
- {
239
- id: "identityProfileListRequestFilteredExample",
240
- request: {
241
- query: {
242
- publicFilters: "jobTitle:Professor"
243
- }
244
- }
245
- }
246
- ]
247
- },
248
- responseType: [
249
- {
250
- type: "IIdentityProfileListResponse",
251
- examples: [
252
- {
253
- id: "identitiesProfileListResponseExample",
254
- response: {
255
- body: {
256
- items: [
257
- {
258
- identity: "did:iota:tst:0xc57d94b088f4c6d2cb32ded014813d0c786aa00134c8ee22f84b1e2545602a70",
259
- publicProfile: {
260
- "@context": "https://schema.org",
261
- "@type": "Person",
262
- jobTitle: "Professor",
263
- name: "Jane Doe"
264
- }
265
- }
266
- ],
267
- cursor: "1"
268
- }
269
- }
270
- }
271
- ]
272
- }
273
- ]
274
- };
275
- return [
276
- identityProfileCreateRoute,
277
- identityProfileGetRoute,
278
- identityProfileGetPublicRoute,
279
- identityProfileUpdateRoute,
280
- identityProfileRemoveRoute,
281
- identityProfileListRoute
282
- ];
283
- }
284
- /**
285
- * Create an identity profile.
286
- * @param httpRequestContext The request context for the API.
287
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
288
- * @param request The request.
289
- * @returns The response object with additional http response properties.
290
- */
291
- async function identityProfileCreate(httpRequestContext, componentName, request) {
292
- core.Guards.object(ROUTES_SOURCE$2, "request", request);
293
- core.Guards.object(ROUTES_SOURCE$2, "request.body", request.body);
294
- const component = core.ComponentFactory.get(componentName);
295
- await component.create(request.body.publicProfile, request.body.privateProfile, httpRequestContext.userIdentity);
296
- return {
297
- statusCode: web.HttpStatusCode.noContent
298
- };
299
- }
300
- /**
301
- * Get the identity profile.
302
- * @param httpRequestContext The request context for the API.
303
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
304
- * @param request The request.
305
- * @returns The response object with additional http response properties.
306
- */
307
- async function identityGet(httpRequestContext, componentName, request) {
308
- core.Guards.object(ROUTES_SOURCE$2, "request", request);
309
- const component = core.ComponentFactory.get(componentName);
310
- const result = await component.get(apiModels.HttpParameterHelper.arrayFromString(request?.query?.publicPropertyNames), apiModels.HttpParameterHelper.arrayFromString(request?.query?.privatePropertyNames), httpRequestContext.userIdentity);
311
- return {
312
- body: result
313
- };
314
- }
315
- /**
316
- * Get the identity public profile.
317
- * @param httpRequestContext The request context for the API.
318
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
319
- * @param request The request.
320
- * @returns The response object with additional http response properties.
321
- */
322
- async function identityGetPublic(httpRequestContext, componentName, request) {
323
- core.Guards.object(ROUTES_SOURCE$2, "request", request);
324
- core.Guards.stringValue(ROUTES_SOURCE$2, "request.pathParams.identity", request.pathParams?.identity);
325
- const component = core.ComponentFactory.get(componentName);
326
- const result = await component.getPublic(request?.pathParams.identity, apiModels.HttpParameterHelper.arrayFromString(request?.query?.propertyNames));
327
- return {
328
- headers: {
329
- [web.HeaderTypes.ContentType]: web.MimeTypes.JsonLd
330
- },
331
- body: result
332
- };
333
- }
334
- /**
335
- * Update an identity profile.
336
- * @param httpRequestContext The request context for the API.
337
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
338
- * @param request The request.
339
- * @returns The response object with additional http response properties.
340
- */
341
- async function identityProfileUpdate(httpRequestContext, componentName, request) {
342
- core.Guards.object(ROUTES_SOURCE$2, "request", request);
343
- core.Guards.object(ROUTES_SOURCE$2, "request.body", request.body);
344
- const component = core.ComponentFactory.get(componentName);
345
- await component.update(request.body.publicProfile, request.body.privateProfile, httpRequestContext.userIdentity);
346
- return {
347
- statusCode: web.HttpStatusCode.noContent
348
- };
349
- }
350
- /**
351
- * Remove an identity profile.
352
- * @param httpRequestContext The request context for the API.
353
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
354
- * @param request The request.
355
- * @returns The response object with additional http response properties.
356
- */
357
- async function identityProfileRemove(httpRequestContext, componentName, request) {
358
- const component = core.ComponentFactory.get(componentName);
359
- await component.remove(httpRequestContext.userIdentity);
360
- return {
361
- statusCode: web.HttpStatusCode.noContent
362
- };
363
- }
364
- /**
365
- * Get the list of organizations.
366
- * @param httpRequestContext The request context for the API.
367
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
368
- * @param request The request.
369
- * @returns The response object with additional http response properties.
370
- */
371
- async function identitiesList(httpRequestContext, componentName, request) {
372
- const component = core.ComponentFactory.get(componentName);
373
- const publicFilterPairs = apiModels.HttpParameterHelper.arrayFromString(request?.query?.publicFilters);
374
- const publicFilters = publicFilterPairs?.map(pair => {
375
- const parts = pair.split(":");
376
- return {
377
- propertyName: parts[0],
378
- propertyValue: parts[1]
379
- };
380
- });
381
- return {
382
- body: await component.list(publicFilters, apiModels.HttpParameterHelper.arrayFromString(request?.query?.publicPropertyNames), request?.query?.cursor, core.Coerce.integer(request.query?.limit))
383
- };
384
- }
385
-
386
- // Copyright 2024 IOTA Stiftung.
387
- // SPDX-License-Identifier: Apache-2.0.
388
- /**
389
- * Class which implements the identity profile contract.
390
- */
391
- class IdentityProfileService {
392
- /**
393
- * Runtime name for the class.
394
- */
395
- static CLASS_NAME = "IdentityProfileService";
396
- /**
397
- * The identity profile connector.
398
- * @internal
399
- */
400
- _identityProfileConnector;
401
- /**
402
- * Create a new instance of IdentityProfileService.
403
- * @param options The dependencies for the identity profile service.
404
- */
405
- constructor(options) {
406
- this._identityProfileConnector = identityModels.IdentityProfileConnectorFactory.get(options?.profileEntityConnectorType ?? "identity-profile");
407
- }
408
- /**
409
- * Create the profile properties for an identity.
410
- * @param publicProfile The public profile data as JSON-LD.
411
- * @param privateProfile The private profile data as JSON-LD.
412
- * @param identity The identity to perform the profile operation on.
413
- * @returns Nothing.
414
- */
415
- async create(publicProfile, privateProfile, identity) {
416
- core.Guards.stringValue(IdentityProfileService.CLASS_NAME, "identity", identity);
417
- try {
418
- await this._identityProfileConnector.create(identity, publicProfile, privateProfile);
419
- }
420
- catch (error) {
421
- if (core.BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {
422
- throw error;
423
- }
424
- throw new core.GeneralError(IdentityProfileService.CLASS_NAME, "createFailed", { identity }, error);
425
- }
426
- }
427
- /**
428
- * Get the profile properties for an identity.
429
- * @param publicPropertyNames The public properties to get for the profile, defaults to all.
430
- * @param privatePropertyNames The private properties to get for the profile, defaults to all.
431
- * @param identity The identity to perform the profile operation on.
432
- * @returns The items identity and the properties.
433
- */
434
- async get(publicPropertyNames, privatePropertyNames, identity) {
435
- core.Guards.stringValue(IdentityProfileService.CLASS_NAME, "identity", identity);
436
- try {
437
- const result = await this._identityProfileConnector.get(identity, publicPropertyNames, privatePropertyNames);
438
- if (core.Is.undefined(result)) {
439
- throw new core.NotFoundError(IdentityProfileService.CLASS_NAME, "notFound", identity);
440
- }
441
- return {
442
- identity,
443
- publicProfile: result.publicProfile,
444
- privateProfile: result.privateProfile
445
- };
446
- }
447
- catch (error) {
448
- if (core.BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {
449
- throw error;
450
- }
451
- throw new core.GeneralError(IdentityProfileService.CLASS_NAME, "getFailed", undefined, error);
452
- }
453
- }
454
- /**
455
- * Get the public profile properties for an identity.
456
- * @param identity The identity to perform the profile operation on.
457
- * @param propertyNames The properties to get for the item, defaults to all.
458
- * @returns The items properties.
459
- */
460
- async getPublic(identity, propertyNames) {
461
- core.Guards.stringValue(IdentityProfileService.CLASS_NAME, "identity", identity);
462
- try {
463
- const result = await this._identityProfileConnector.get(identity, propertyNames);
464
- if (core.Is.undefined(result)) {
465
- throw new core.NotFoundError(IdentityProfileService.CLASS_NAME, "notFound", identity);
466
- }
467
- return result.publicProfile;
468
- }
469
- catch (error) {
470
- if (core.BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {
471
- throw error;
472
- }
473
- throw new core.GeneralError(IdentityProfileService.CLASS_NAME, "getPublicFailed", undefined, error);
474
- }
475
- }
476
- /**
477
- * Update the profile properties of an identity.
478
- * @param publicProfile The public profile data as JSON-LD.
479
- * @param privateProfile The private profile data as JSON-LD.
480
- * @param identity The identity to perform the profile operation on.
481
- * @returns Nothing.
482
- */
483
- async update(publicProfile, privateProfile, identity) {
484
- core.Guards.stringValue(IdentityProfileService.CLASS_NAME, "identity", identity);
485
- try {
486
- const result = await this._identityProfileConnector.get(identity);
487
- if (core.Is.undefined(result)) {
488
- throw new core.NotFoundError(IdentityProfileService.CLASS_NAME, "notFound", identity);
489
- }
490
- await this._identityProfileConnector.update(identity, publicProfile, privateProfile);
491
- }
492
- catch (error) {
493
- if (core.BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {
494
- throw error;
495
- }
496
- throw new core.GeneralError(IdentityProfileService.CLASS_NAME, "updateFailed", { identity }, error);
497
- }
498
- }
499
- /**
500
- * Delete the profile for an identity.
501
- * @param identity The identity to perform the profile operation on.
502
- * @returns Nothing.
503
- */
504
- async remove(identity) {
505
- core.Guards.stringValue(IdentityProfileService.CLASS_NAME, "identity", identity);
506
- try {
507
- const result = await this._identityProfileConnector.get(identity);
508
- if (core.Is.undefined(result)) {
509
- throw new core.NotFoundError(IdentityProfileService.CLASS_NAME, "notFound", identity);
510
- }
511
- await this._identityProfileConnector.remove(identity);
512
- }
513
- catch (error) {
514
- if (core.BaseError.someErrorClass(error, IdentityProfileService.CLASS_NAME)) {
515
- throw error;
516
- }
517
- throw new core.GeneralError(IdentityProfileService.CLASS_NAME, "removeFailed", { identity }, error);
518
- }
519
- }
520
- /**
521
- * Get a list of the requested types.
522
- * @param publicFilters The filters to apply to the identities public profiles.
523
- * @param publicPropertyNames The public properties to get for the profile, defaults to all.
524
- * @param cursor The cursor for paged requests.
525
- * @param limit The maximum number of items in a page.
526
- * @returns The list of items and cursor for paging.
527
- */
528
- async list(publicFilters, publicPropertyNames, cursor, limit) {
529
- try {
530
- // We don't want to return private profile for this type of query
531
- // as it would expose the values to the REST api
532
- return this._identityProfileConnector.list(publicFilters, undefined, publicPropertyNames, undefined, cursor, limit);
533
- }
534
- catch (error) {
535
- throw new core.GeneralError(IdentityProfileService.CLASS_NAME, "listFailed", undefined, error);
536
- }
537
- }
538
- }
539
-
540
- /**
541
- * The source used when communicating about these routes.
542
- */
543
- const ROUTES_SOURCE$1 = "identityResolverRoutes";
544
- /**
545
- * The tag to associate with the routes.
546
- */
547
- const tagsIdentityResolver = [
548
- {
549
- name: "Identity",
550
- description: "Service to provide all features related to digital identity."
551
- }
552
- ];
553
- /**
554
- * The REST routes for identity.
555
- * @param baseRouteName Prefix to prepend to the paths.
556
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
557
- * @returns The generated routes.
558
- */
559
- function generateRestRoutesIdentityResolver(baseRouteName, componentName) {
560
- const identityResolveRoute = {
561
- operationId: "identityResolve",
562
- summary: "Resolve an identity",
563
- tag: tagsIdentityResolver[0].name,
564
- method: "GET",
565
- path: `${baseRouteName}/:identity`,
566
- handler: async (httpRequestContext, request) => identityResolve(httpRequestContext, componentName, request),
567
- requestType: {
568
- type: "IIdentityResolveRequest",
569
- examples: [
570
- {
571
- id: "identityResolveRequestExample",
572
- request: {
573
- pathParams: {
574
- identity: "did:iota:tst:0xe3088ba9aa8c28e1d139708a14e8c0fdff11ee8223baac4aa5bcf3321e4bfc6a"
575
- }
576
- }
577
- }
578
- ]
579
- },
580
- responseType: [
581
- {
582
- type: "IIdentityResolveResponse",
583
- examples: [
584
- {
585
- id: "identityResolveResponseExample",
586
- response: {
587
- body: {
588
- "@context": standardsW3cDid.DidContexts.Context,
589
- id: "did:iota:tst:0xe3088ba9aa8c28e1d139708a14e8c0fdff11ee8223baac4aa5bcf3321e4bfc6a",
590
- service: [
591
- {
592
- id: "did:iota:tst:0xe3088ba9aa8c28e1d139708a14e8c0fdff11ee8223baac4aa5bcf3321e4bfc6a#revocation",
593
- type: "RevocationBitmap2022",
594
- serviceEndpoint: "data:application/octet-stream;base64,eJyzMmAAAwABr"
595
- }
596
- ]
597
- }
598
- }
599
- }
600
- ]
601
- }
602
- ],
603
- skipAuth: true
604
- };
605
- return [identityResolveRoute];
606
- }
607
- /**
608
- * Resolve an identity.
609
- * @param httpRequestContext The request context for the API.
610
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
611
- * @param request The request.
612
- * @returns The response object with additional http response properties.
613
- */
614
- async function identityResolve(httpRequestContext, componentName, request) {
615
- core.Guards.object(ROUTES_SOURCE$1, "request", request);
616
- core.Guards.object(ROUTES_SOURCE$1, "request.pathParams", request.pathParams);
617
- core.Guards.stringValue(ROUTES_SOURCE$1, "request.pathParams.identity", request.pathParams.identity);
618
- const component = core.ComponentFactory.get(componentName);
619
- const result = await component.identityResolve(request.pathParams.identity);
620
- return {
621
- body: result
622
- };
623
- }
624
-
625
- // Copyright 2024 IOTA Stiftung.
626
- // SPDX-License-Identifier: Apache-2.0.
627
- /**
628
- * Class which implements the identity resolver contract.
629
- */
630
- class IdentityResolverService {
631
- /**
632
- * Runtime name for the class.
633
- */
634
- static CLASS_NAME = "IdentityResolverService";
635
- /**
636
- * The default namespace for the connector to use.
637
- * @internal
638
- */
639
- _defaultNamespace;
640
- /**
641
- * Fallback connector type to use if the namespace connector is not available.
642
- * @internal
643
- */
644
- _fallbackResolverConnectorType;
645
- /**
646
- * Create a new instance of IdentityResolverService.
647
- * @param options The options for the service.
648
- */
649
- constructor(options) {
650
- const names = identityModels.IdentityResolverConnectorFactory.names();
651
- if (names.length === 0) {
652
- throw new core.GeneralError(IdentityResolverService.CLASS_NAME, "noConnectors");
653
- }
654
- this._defaultNamespace = options?.config?.defaultNamespace ?? names[0];
655
- this._fallbackResolverConnectorType = options?.fallbackResolverConnectorType ?? "universal";
656
- }
657
- /**
658
- * Resolve an identity.
659
- * @param identity The id of the document to resolve.
660
- * @returns The resolved document.
661
- */
662
- async identityResolve(identity) {
663
- core.Urn.guard(IdentityResolverService.CLASS_NAME, "identity", identity);
664
- try {
665
- const identityResolverConnector = this.getConnectorByUri(identity);
666
- const document = await identityResolverConnector.resolveDocument(identity);
667
- return document;
668
- }
669
- catch (error) {
670
- throw new core.GeneralError(IdentityResolverService.CLASS_NAME, "identityResolveFailed", {
671
- identity
672
- }, error);
673
- }
674
- }
675
- /**
676
- * Get the connector from the namespace.
677
- * @param namespace The namespace for the identity.
678
- * @returns The connector.
679
- * @internal
680
- */
681
- getConnectorByNamespace(namespace) {
682
- const namespaceMethod = namespace ?? this._defaultNamespace;
683
- let connector = identityModels.IdentityResolverConnectorFactory.getIfExists(namespaceMethod);
684
- if (core.Is.empty(connector)) {
685
- // Let's see if a fallback 'universal' connector is registered
686
- connector = identityModels.IdentityResolverConnectorFactory.getIfExists(this._fallbackResolverConnectorType);
687
- if (core.Is.empty(connector)) {
688
- throw new core.GeneralError(IdentityResolverService.CLASS_NAME, "connectorNotFound", {
689
- namespace: namespaceMethod
690
- });
691
- }
692
- }
693
- return connector;
694
- }
695
- /**
696
- * Get the connector from the uri.
697
- * @param id The id of the identity in urn format.
698
- * @returns The connector.
699
- * @internal
700
- */
701
- getConnectorByUri(id) {
702
- const idUri = core.Urn.fromValidString(id);
703
- if (idUri.namespaceIdentifier() !== "did") {
704
- throw new core.GeneralError(IdentityResolverService.CLASS_NAME, "namespaceMismatch", {
705
- namespace: "did",
706
- id
707
- });
708
- }
709
- return this.getConnectorByNamespace(idUri.namespaceMethod());
710
- }
711
- }
712
-
713
- /**
714
- * The source used when communicating about these routes.
715
- */
716
- const ROUTES_SOURCE = "identityRoutes";
717
- /**
718
- * The tag to associate with the routes.
719
- */
720
- const tagsIdentity = [
721
- {
722
- name: "Identity",
723
- description: "Service to provide all features related to digital identity."
724
- }
725
- ];
726
- /**
727
- * The REST routes for identity.
728
- * @param baseRouteName Prefix to prepend to the paths.
729
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
730
- * @returns The generated routes.
731
- */
732
- function generateRestRoutesIdentity(baseRouteName, componentName) {
733
- const identityCreateRoute = {
734
- operationId: "identityCreate",
735
- summary: "Create an identity",
736
- tag: tagsIdentity[0].name,
737
- method: "POST",
738
- path: `${baseRouteName}/`,
739
- handler: async (httpRequestContext, request) => identityCreate(httpRequestContext, componentName, request),
740
- requestType: {
741
- type: "IIdentityCreateRequest",
742
- examples: [
743
- {
744
- id: "identityCreateRequestExample",
745
- request: {}
746
- }
747
- ]
748
- },
749
- responseType: [
750
- {
751
- type: "IIdentityCreateResponse",
752
- examples: [
753
- {
754
- id: "identityCreateResponseExample",
755
- response: {
756
- body: {
757
- "@context": standardsW3cDid.DidContexts.Context,
758
- id: "did:iota:tst:0xe3088ba9aa8c28e1d139708a14e8c0fdff11ee8223baac4aa5bcf3321e4bfc6a",
759
- service: [
760
- {
761
- id: "did:iota:tst:0xe3088ba9aa8c28e1d139708a14e8c0fdff11ee8223baac4aa5bcf3321e4bfc6a#revocation",
762
- type: "RevocationBitmap2022",
763
- serviceEndpoint: "data:application/octet-stream;base64,eJyzMmAAAwABr"
764
- }
765
- ]
766
- }
767
- }
768
- }
769
- ]
770
- }
771
- ]
772
- };
773
- const identityRemoveRoute = {
774
- operationId: "identityRemove",
775
- summary: "Remove an identity",
776
- tag: tagsIdentity[0].name,
777
- method: "DELETE",
778
- path: `${baseRouteName}/:identity`,
779
- handler: async (httpRequestContext, request) => identityRemove(httpRequestContext, componentName, request),
780
- requestType: {
781
- type: "IIdentityRemoveRequest",
782
- examples: [
783
- {
784
- id: "identityRemoveRequestExample",
785
- request: {
786
- pathParams: {
787
- identity: "did:iota:tst:0xe3088ba9aa8c28e1d139708a14e8c0fdff11ee8223baac4aa5bcf3321e4bfc6a"
788
- }
789
- }
790
- }
791
- ]
792
- },
793
- responseType: [
794
- {
795
- type: "INoContentResponse"
796
- }
797
- ]
798
- };
799
- const identityVerificationMethodCreateRoute = {
800
- operationId: "identityVerificationMethodCreate",
801
- summary: "Create an identity verification method",
802
- tag: tagsIdentity[0].name,
803
- method: "POST",
804
- path: `${baseRouteName}/:identity/verification-method`,
805
- handler: async (httpRequestContext, request) => identityVerificationMethodCreate(httpRequestContext, componentName, request),
806
- requestType: {
807
- type: "IIdentityVerificationMethodCreateRequest",
808
- examples: [
809
- {
810
- id: "identityVerificationMethodCreateRequestExample",
811
- request: {
812
- pathParams: {
813
- identity: "did:iota:tst:0xe3088ba9aa8c28e1d139708a14e8c0fdff11ee8223baac4aa5bcf3321e4bfc6a"
814
- },
815
- body: {
816
- verificationMethodType: "assertionMethod",
817
- verificationMethodId: "my-assertion"
818
- }
819
- }
820
- }
821
- ]
822
- },
823
- responseType: [
824
- {
825
- type: "IIdentityVerificationMethodCreateResponse",
826
- examples: [
827
- {
828
- id: "identityVerificationMethodCreateResponseExample",
829
- response: {
830
- body: {
831
- id: "did:iota:tst:0x70ce5abe69e7c56dd69684dd6da65812b9758b03a0081331ca560b34d73d5ff0#my-assertion",
832
- controller: "did:iota:tst:0x70ce5abe69e7c56dd69684dd6da65812b9758b03a0081331ca560b34d73d5ff0",
833
- type: "JsonWebKey2020",
834
- publicKeyJwk: {
835
- kty: "OKP",
836
- alg: "EdDSA",
837
- kid: "f_fj3rGsZFSYvnS_xv5MgyIBlExq-lgDciu0YQ--S3s",
838
- crv: "Ed25519",
839
- x: "SFm32z7y9C17olpaTeocG25WV2CNTUl5MhM679Z4bok"
840
- }
841
- }
842
- }
843
- }
844
- ]
845
- }
846
- ]
847
- };
848
- const identityVerificationMethodRemoveRoute = {
849
- operationId: "identityVerificationMethodRemove",
850
- summary: "Remove an identity verification method",
851
- tag: tagsIdentity[0].name,
852
- method: "DELETE",
853
- path: `${baseRouteName}/:identity/verification-method/:verificationMethodId`,
854
- handler: async (httpRequestContext, request) => identityVerificationMethodRemove(httpRequestContext, componentName, request),
855
- requestType: {
856
- type: "IIdentityVerificationMethodRemoveRequest",
857
- examples: [
858
- {
859
- id: "identityVerificationMethodRemoveRequestExample",
860
- request: {
861
- pathParams: {
862
- identity: "did:iota:tst:0xe3088ba9aa8c28e1d139708a14e8c0fdff11ee8223baac4aa5bcf3321e4bfc6a",
863
- verificationMethodId: "my-assertion"
864
- }
865
- }
866
- }
867
- ]
868
- },
869
- responseType: [
870
- {
871
- type: "INoContentResponse",
872
- examples: [
873
- {
874
- id: "identityVerificationMethodCreateResponseExample",
875
- response: {
876
- statusCode: web.HttpStatusCode.noContent
877
- }
878
- }
879
- ]
880
- }
881
- ]
882
- };
883
- const identityServiceCreateRoute = {
884
- operationId: "identityServiceCreate",
885
- summary: "Create an identity service",
886
- tag: tagsIdentity[0].name,
887
- method: "POST",
888
- path: `${baseRouteName}/:identity/service`,
889
- handler: async (httpRequestContext, request) => identityServiceCreate(httpRequestContext, componentName, request),
890
- requestType: {
891
- type: "IIdentityServiceCreateRequest",
892
- examples: [
893
- {
894
- id: "identityServiceCreateRequestExample",
895
- request: {
896
- pathParams: {
897
- identity: "did:iota:tst:0xe3088ba9aa8c28e1d139708a14e8c0fdff11ee8223baac4aa5bcf3321e4bfc6a"
898
- },
899
- body: {
900
- serviceId: "did:example:123#linked-domain",
901
- type: "LinkedDomains",
902
- endpoint: "https://bar.example.com"
903
- }
904
- }
905
- }
906
- ]
907
- },
908
- responseType: [
909
- {
910
- type: "IIdentityServiceCreateResponse",
911
- examples: [
912
- {
913
- id: "identityServiceCreateResponseExample",
914
- response: {
915
- body: {
916
- id: "did:example:123#linked-domain",
917
- type: "LinkedDomains",
918
- serviceEndpoint: "https://bar.example.com"
919
- }
920
- }
921
- }
922
- ]
923
- }
924
- ]
925
- };
926
- const identityServiceRemoveRoute = {
927
- operationId: "identityServiceRemove",
928
- summary: "Remove an identity service",
929
- tag: tagsIdentity[0].name,
930
- method: "DELETE",
931
- path: `${baseRouteName}/:identity/service/:serviceId`,
932
- handler: async (httpRequestContext, request) => identityServiceRemove(httpRequestContext, componentName, request),
933
- requestType: {
934
- type: "IIdentityServiceRemoveRequest",
935
- examples: [
936
- {
937
- id: "identityServiceRemoveRequestExample",
938
- request: {
939
- pathParams: {
940
- identity: "did:iota:tst:0xe3088ba9aa8c28e1d139708a14e8c0fdff11ee8223baac4aa5bcf3321e4bfc6a",
941
- serviceId: "did:example:123#linked-domain"
942
- }
943
- }
944
- }
945
- ]
946
- },
947
- responseType: [
948
- {
949
- type: "INoContentResponse",
950
- examples: [
951
- {
952
- id: "identityServiceCreateResponseExample",
953
- response: {
954
- statusCode: web.HttpStatusCode.noContent
955
- }
956
- }
957
- ]
958
- }
959
- ]
960
- };
961
- const identityVerifiableCredentialCreateRoute = {
962
- operationId: "identityVerifiableCredentialCreate",
963
- summary: "Create an identity verifiable credential",
964
- tag: tagsIdentity[0].name,
965
- method: "POST",
966
- path: `${baseRouteName}/:identity/verifiable-credential`,
967
- handler: async (httpRequestContext, request) => identityVerifiableCredentialCreate(httpRequestContext, componentName, request),
968
- requestType: {
969
- type: "IIdentityVerifiableCredentialCreateRequest",
970
- examples: [
971
- {
972
- id: "identityVerifiableCredentialCreateRequestExample",
973
- request: {
974
- pathParams: {
975
- identity: "did:entity-storage:0x879c31386f992cfa29b77fe31e37256d69f6a57653cee4eb60ad4c4613c5515a",
976
- verificationMethodId: "my-assertion"
977
- },
978
- body: {
979
- credentialId: "https://example.com/credentials/3732",
980
- subject: {
981
- "@context": "https://schema.org",
982
- "@type": "Person",
983
- id: "did:entity-storage:0x4757993355b921a8229bd780f30921b6a0216a72e6c3f37a09d13b8426a17def",
984
- name: "Jane Doe"
985
- },
986
- revocationIndex: 5
987
- }
988
- }
989
- }
990
- ]
991
- },
992
- responseType: [
993
- {
994
- type: "IIdentityVerifiableCredentialCreateResponse",
995
- examples: [
996
- {
997
- id: "identityVerifiableCredentialCreateResponseExample",
998
- response: {
999
- body: {
1000
- verifiableCredential: {
1001
- "@context": ["https://www.w3.org/2018/credentials/v1", "https://schema.org"],
1002
- id: "https://example.com/credentials/3732",
1003
- type: ["VerifiableCredential", "Person"],
1004
- credentialSubject: {
1005
- id: "did:entity-storage:0x4757993355b921a8229bd780f30921b6a0216a72e6c3f37a09d13b8426a17def",
1006
- name: "Jane Doe"
1007
- },
1008
- issuer: "did:entity-storage:0x879c31386f992cfa29b77fe31e37256d69f6a57653cee4eb60ad4c4613c5515a",
1009
- issuanceDate: "2025-01-24T09:21:51.500Z",
1010
- credentialStatus: {
1011
- id: "did:entity-storage:0x879c31386f992cfa29b77fe31e37256d69f6a57653cee4eb60ad4c4613c5515a#revocation",
1012
- type: "BitstringStatusList",
1013
- revocationBitmapIndex: "5"
1014
- }
1015
- },
1016
- jwt: "eyJraWQiOi...D1Z3AQ"
1017
- }
1018
- }
1019
- }
1020
- ]
1021
- }
1022
- ]
1023
- };
1024
- const identityVerifiableCredentialVerifyRoute = {
1025
- operationId: "identityVerifiableCredentialVerify",
1026
- summary: "Verify an identity verifiable credential",
1027
- tag: tagsIdentity[0].name,
1028
- method: "GET",
1029
- path: `${baseRouteName}/verifiable-credential/verify`,
1030
- handler: async (httpRequestContext, request) => identityVerifiableCredentialVerify(httpRequestContext, componentName, request),
1031
- requestType: {
1032
- type: "IIdentityVerifiableCredentialVerifyRequest",
1033
- examples: [
1034
- {
1035
- id: "identityVerifiableCredentialVerifyRequestExample",
1036
- request: {
1037
- query: {
1038
- jwt: "eyJraWQiOi...D1Z3AQ"
1039
- }
1040
- }
1041
- }
1042
- ]
1043
- },
1044
- responseType: [
1045
- {
1046
- type: "IIdentityVerifiableCredentialVerifyResponse",
1047
- examples: [
1048
- {
1049
- id: "identityVerifiableCredentialVerifyResponseExample",
1050
- response: {
1051
- body: {
1052
- revoked: false,
1053
- verifiableCredential: {
1054
- "@context": ["https://www.w3.org/2018/credentials/v1", "https://schema.org"],
1055
- id: "https://example.com/credentials/3732",
1056
- type: ["VerifiableCredential", "Person"],
1057
- credentialSubject: {
1058
- id: "did:entity-storage:0x4757993355b921a8229bd780f30921b6a0216a72e6c3f37a09d13b8426a17def",
1059
- name: "Jane Doe"
1060
- },
1061
- issuer: "did:entity-storage:0x879c31386f992cfa29b77fe31e37256d69f6a57653cee4eb60ad4c4613c5515a",
1062
- issuanceDate: "2025-01-24T09:21:51.500Z",
1063
- credentialStatus: {
1064
- id: "did:entity-storage:0x879c31386f992cfa29b77fe31e37256d69f6a57653cee4eb60ad4c4613c5515a#revocation",
1065
- type: "BitstringStatusList",
1066
- revocationBitmapIndex: "5"
1067
- }
1068
- }
1069
- }
1070
- }
1071
- }
1072
- ]
1073
- }
1074
- ],
1075
- skipAuth: true
1076
- };
1077
- const identityVerifiableCredentialRevokeRoute = {
1078
- operationId: "identityVerifiableCredentialRevoke",
1079
- summary: "Revoke an identity verifiable credential",
1080
- tag: tagsIdentity[0].name,
1081
- method: "GET",
1082
- path: `${baseRouteName}/:identity/verifiable-credential/revoke/:revocationIndex`,
1083
- handler: async (httpRequestContext, request) => identityVerifiableCredentialRevoke(httpRequestContext, componentName, request),
1084
- requestType: {
1085
- type: "IIdentityVerifiableCredentialRevokeRequest",
1086
- examples: [
1087
- {
1088
- id: "identityVerifiableCredentialRevokeRequestExample",
1089
- request: {
1090
- pathParams: {
1091
- identity: "did:entity-storage:0x879c31386f992cfa29b77fe31e37256d69f6a57653cee4eb60ad4c4613c5515a",
1092
- revocationIndex: 5
1093
- }
1094
- }
1095
- }
1096
- ]
1097
- },
1098
- responseType: [
1099
- {
1100
- type: "INoContentResponse",
1101
- examples: [
1102
- {
1103
- id: "identityServiceRevokeResponseExample",
1104
- response: {
1105
- statusCode: web.HttpStatusCode.noContent
1106
- }
1107
- }
1108
- ]
1109
- }
1110
- ]
1111
- };
1112
- const identityVerifiableCredentialUnrevokeRoute = {
1113
- operationId: "identityVerifiableCredentialUnrevoke",
1114
- summary: "Unrevoke an identity verifiable credential",
1115
- tag: tagsIdentity[0].name,
1116
- method: "GET",
1117
- path: `${baseRouteName}/:identity/verifiable-credential/unrevoke/:revocationIndex`,
1118
- handler: async (httpRequestContext, request) => identityVerifiableCredentialUnrevoke(httpRequestContext, componentName, request),
1119
- requestType: {
1120
- type: "IIdentityVerifiableCredentialUnrevokeRequest",
1121
- examples: [
1122
- {
1123
- id: "identityVerifiableCredentialUnrevokeRequestExample",
1124
- request: {
1125
- pathParams: {
1126
- identity: "did:entity-storage:0x879c31386f992cfa29b77fe31e37256d69f6a57653cee4eb60ad4c4613c5515a",
1127
- revocationIndex: 5
1128
- }
1129
- }
1130
- }
1131
- ]
1132
- },
1133
- responseType: [
1134
- {
1135
- type: "INoContentResponse",
1136
- examples: [
1137
- {
1138
- id: "identityServiceUnrevokeResponseExample",
1139
- response: {
1140
- statusCode: web.HttpStatusCode.noContent
1141
- }
1142
- }
1143
- ]
1144
- }
1145
- ]
1146
- };
1147
- const identityVerifiablePresentationCreateRoute = {
1148
- operationId: "identityVerifiablePresentationCreate",
1149
- summary: "Create an identity verifiable presentation",
1150
- tag: tagsIdentity[0].name,
1151
- method: "POST",
1152
- path: `${baseRouteName}/:identity/verifiable-presentation`,
1153
- handler: async (httpRequestContext, request) => identityVerifiablePresentationCreate(httpRequestContext, componentName, request),
1154
- requestType: {
1155
- type: "IIdentityVerifiablePresentationCreateRequest",
1156
- examples: [
1157
- {
1158
- id: "identityVerifiablePresentationCreateRequestExample",
1159
- request: {
1160
- pathParams: {
1161
- identity: "did:entity-storage:0x879c31386f992cfa29b77fe31e37256d69f6a57653cee4eb60ad4c4613c5515a",
1162
- verificationMethodId: "my-assertion"
1163
- },
1164
- body: {
1165
- presentationId: "https://example.com/presentation/3732",
1166
- verifiableCredentials: ["eyJraWQiOi...D1Z3AQ"]
1167
- }
1168
- }
1169
- }
1170
- ]
1171
- },
1172
- responseType: [
1173
- {
1174
- type: "IIdentityVerifiablePresentationCreateResponse",
1175
- examples: [
1176
- {
1177
- id: "IIdentityVerifiablePresentationCreateResponseExample",
1178
- response: {
1179
- body: {
1180
- verifiablePresentation: {
1181
- "@context": ["https://www.w3.org/2018/credentials/v1", "https://schema.org"],
1182
- id: "presentationId",
1183
- type: ["VerifiablePresentation", "Person"],
1184
- verifiableCredential: ["eyJraWQiOi...D1Z3AQ"],
1185
- holder: "did:entity-storage:0xcea318e06e89f3fb4048160770effd84d0cfa5801fee13dfa6f9413a00429cec"
1186
- },
1187
- jwt: "eyJraWQiOi...D1Z3AQ"
1188
- }
1189
- }
1190
- }
1191
- ]
1192
- }
1193
- ]
1194
- };
1195
- const identityVerifiablePresentationVerifyRoute = {
1196
- operationId: "identityVerifiablePresentationVerify",
1197
- summary: "Verify an identity verifiable presentation",
1198
- tag: tagsIdentity[0].name,
1199
- method: "GET",
1200
- path: `${baseRouteName}/verifiable-presentation/verify`,
1201
- handler: async (httpRequestContext, request) => identityVerifiablePresentationVerify(httpRequestContext, componentName, request),
1202
- requestType: {
1203
- type: "IIdentityVerifiablePresentationVerifyRequest",
1204
- examples: [
1205
- {
1206
- id: "identityVerifiablePresentationVerifyRequestExample",
1207
- request: {
1208
- query: {
1209
- jwt: "eyJraWQiOi...D1Z3AQ"
1210
- }
1211
- }
1212
- }
1213
- ]
1214
- },
1215
- responseType: [
1216
- {
1217
- type: "IIdentityVerifiablePresentationVerifyResponse",
1218
- examples: [
1219
- {
1220
- id: "identityVerifiablePresentationVerifyResponseExample",
1221
- response: {
1222
- body: {
1223
- revoked: false,
1224
- verifiablePresentation: {
1225
- "@context": ["https://www.w3.org/2018/credentials/v1", "https://schema.org"],
1226
- id: "presentationId",
1227
- type: ["VerifiablePresentation", "Person"],
1228
- verifiableCredential: ["eyJraWQiOi...D1Z3AQ"],
1229
- holder: "did:entity-storage:0xcea318e06e89f3fb4048160770effd84d0cfa5801fee13dfa6f9413a00429cec"
1230
- }
1231
- }
1232
- }
1233
- }
1234
- ]
1235
- }
1236
- ],
1237
- skipAuth: true
1238
- };
1239
- const identityProofCreateRoute = {
1240
- operationId: "identityProofCreate",
1241
- summary: "Create an identity proof",
1242
- tag: tagsIdentity[0].name,
1243
- method: "POST",
1244
- path: `${baseRouteName}/:identity/proof`,
1245
- handler: async (httpRequestContext, request) => identityProofCreate(httpRequestContext, componentName, request),
1246
- requestType: {
1247
- type: "IIdentityProofCreateRequest",
1248
- examples: [
1249
- {
1250
- id: "identityProofCreateRequestExample",
1251
- request: {
1252
- pathParams: {
1253
- identity: "did:entity-storage:0xda2df3ebc91ee0d5229d6532ffd0f4426952a94f34988b0ca906694dfd366a6a",
1254
- verificationMethodId: "my-verification-id"
1255
- },
1256
- body: {
1257
- proofType: "DataIntegrityProof",
1258
- document: {
1259
- "@context": [
1260
- "https://www.w3.org/2018/credentials/v1",
1261
- "https://www.w3.org/2018/credentials/examples/v1"
1262
- ],
1263
- id: "urn:uuid:58172aac-d8ba-11ed-83dd-0b3aef56cc33",
1264
- type: ["VerifiableCredential", "AlumniCredential"],
1265
- name: "Alumni Credential",
1266
- description: "A minimum viable example of an Alumni Credential.",
1267
- issuer: "https://vc.example/issuers/5678",
1268
- validFrom: "2023-01-01T00:00:00Z",
1269
- credentialSubject: {
1270
- id: "did:example:abcdefgh",
1271
- alumniOf: "The School of Examples"
1272
- }
1273
- }
1274
- }
1275
- }
1276
- }
1277
- ]
1278
- },
1279
- responseType: [
1280
- {
1281
- type: "IIdentityProofCreateResponse",
1282
- examples: [
1283
- {
1284
- id: "identityProofCreateResponseExample",
1285
- response: {
1286
- body: {
1287
- "@context": [
1288
- "https://www.w3.org/ns/credentials/v2",
1289
- "https://www.w3.org/ns/credentials/examples/v2"
1290
- ],
1291
- type: "DataIntegrityProof",
1292
- cryptosuite: "eddsa-jcs-2022",
1293
- created: "2024-01-31T16:00:45.490Z",
1294
- verificationMethod: "did:entity-storage:0x0101010101010101010101010101010101010101010101010101010101010101#my-verification-id",
1295
- proofPurpose: "assertionMethod",
1296
- proofValue: "z2zGoejwpX6HH2T11BZaniEVZrqRKDpwbQSvPcL7eL9M7hV5P9zQQZxs85n6qyDzkkXCL8aFUWfwQD5bxVGqDK1fa"
1297
- }
1298
- }
1299
- }
1300
- ]
1301
- }
1302
- ]
1303
- };
1304
- const identityProofVerifyRoute = {
1305
- operationId: "identityProofVerify",
1306
- summary: "Verify an identity proof",
1307
- tag: tagsIdentity[0].name,
1308
- method: "POST",
1309
- path: `${baseRouteName}/proof/verify`,
1310
- handler: async (httpRequestContext, request) => identityProofVerify(httpRequestContext, componentName, request),
1311
- requestType: {
1312
- type: "IIdentityProofVerifyRequest",
1313
- examples: [
1314
- {
1315
- id: "identityProofVerifyRequestExample",
1316
- request: {
1317
- body: {
1318
- document: {
1319
- "@context": [
1320
- "https://www.w3.org/2018/credentials/v1",
1321
- "https://www.w3.org/2018/credentials/examples/v1"
1322
- ],
1323
- id: "urn:uuid:58172aac-d8ba-11ed-83dd-0b3aef56cc33",
1324
- type: ["VerifiableCredential", "AlumniCredential"],
1325
- name: "Alumni Credential",
1326
- description: "A minimum viable example of an Alumni Credential.",
1327
- issuer: "https://vc.example/issuers/5678",
1328
- validFrom: "2023-01-01T00:00:00Z",
1329
- credentialSubject: {
1330
- id: "did:example:abcdefgh",
1331
- alumniOf: "The School of Examples"
1332
- }
1333
- },
1334
- proof: {
1335
- "@context": "https://www.w3.org/ns/credentials/v2",
1336
- type: "DataIntegrityProof",
1337
- cryptosuite: "eddsa-jcs-2022",
1338
- created: "2025-01-24T11:32:13.106Z",
1339
- verificationMethod: "did:entity-storage:0xda2df3ebc91ee0d5229d6532ffd0f4426952a94f34988b0ca906694dfd366a6a#my-verification-id",
1340
- proofPurpose: "assertionMethod",
1341
- proofValue: "2fVLgANruCBoRPBCJavi54mZtkQdyMz6T2N4XVyB96asawiriKrVWoktcSQ7dMGrBTiemBBDpcLE2HfiTBCGuBmq"
1342
- }
1343
- }
1344
- }
1345
- }
1346
- ]
1347
- },
1348
- responseType: [
1349
- {
1350
- type: "IIdentityProofVerifyResponse",
1351
- examples: [
1352
- {
1353
- id: "identityProofVerifyResponseExample",
1354
- response: {
1355
- body: {
1356
- verified: true
1357
- }
1358
- }
1359
- }
1360
- ]
1361
- }
1362
- ],
1363
- skipAuth: true
1364
- };
1365
- return [
1366
- identityCreateRoute,
1367
- identityRemoveRoute,
1368
- identityVerificationMethodCreateRoute,
1369
- identityVerificationMethodRemoveRoute,
1370
- identityServiceCreateRoute,
1371
- identityServiceRemoveRoute,
1372
- identityVerifiableCredentialCreateRoute,
1373
- identityVerifiableCredentialVerifyRoute,
1374
- identityVerifiableCredentialRevokeRoute,
1375
- identityVerifiableCredentialUnrevokeRoute,
1376
- identityVerifiablePresentationCreateRoute,
1377
- identityVerifiablePresentationVerifyRoute,
1378
- identityProofCreateRoute,
1379
- identityProofVerifyRoute
1380
- ];
1381
- }
1382
- /**
1383
- * Create an identity.
1384
- * @param httpRequestContext The request context for the API.
1385
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1386
- * @param request The request.
1387
- * @returns The response object with additional http response properties.
1388
- */
1389
- async function identityCreate(httpRequestContext, componentName, request) {
1390
- core.Guards.object(ROUTES_SOURCE, "request", request);
1391
- core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.userIdentity", httpRequestContext.userIdentity);
1392
- const component = core.ComponentFactory.get(componentName);
1393
- const result = await component.identityCreate(request.body?.namespace, httpRequestContext.userIdentity);
1394
- return {
1395
- body: result
1396
- };
1397
- }
1398
- /**
1399
- * Remove an identity.
1400
- * @param httpRequestContext The request context for the API.
1401
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1402
- * @param request The request.
1403
- * @returns The response object with additional http response properties.
1404
- */
1405
- async function identityRemove(httpRequestContext, componentName, request) {
1406
- core.Guards.object(ROUTES_SOURCE, "request", request);
1407
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
1408
- core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.userIdentity", httpRequestContext.userIdentity);
1409
- const component = core.ComponentFactory.get(componentName);
1410
- await component.identityRemove(request.pathParams.identity, httpRequestContext.userIdentity);
1411
- return {
1412
- statusCode: web.HttpStatusCode.noContent
1413
- };
1414
- }
1415
- /**
1416
- * Create an identity verification method.
1417
- * @param httpRequestContext The request context for the API.
1418
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1419
- * @param request The request.
1420
- * @returns The response object with additional http response properties.
1421
- */
1422
- async function identityVerificationMethodCreate(httpRequestContext, componentName, request) {
1423
- core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.userIdentity", httpRequestContext.userIdentity);
1424
- core.Guards.object(ROUTES_SOURCE, "request", request);
1425
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
1426
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.identity", request.pathParams.identity);
1427
- const component = core.ComponentFactory.get(componentName);
1428
- const result = await component.verificationMethodCreate(request.pathParams.identity, request.body.verificationMethodType, request.body.verificationMethodId, httpRequestContext.userIdentity);
1429
- return {
1430
- body: result
1431
- };
1432
- }
1433
- /**
1434
- * Remove an identity verification method.
1435
- * @param httpRequestContext The request context for the API.
1436
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1437
- * @param request The request.
1438
- * @returns The response object with additional http response properties.
1439
- */
1440
- async function identityVerificationMethodRemove(httpRequestContext, componentName, request) {
1441
- core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.userIdentity", httpRequestContext.userIdentity);
1442
- core.Guards.object(ROUTES_SOURCE, "request", request);
1443
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
1444
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.identity", request.pathParams.identity);
1445
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.verificationMethodId", request.pathParams.verificationMethodId);
1446
- const component = core.ComponentFactory.get(componentName);
1447
- await component.verificationMethodRemove(identityModels.DocumentHelper.joinId(request.pathParams.identity, request.pathParams.verificationMethodId), httpRequestContext.userIdentity);
1448
- return {
1449
- statusCode: web.HttpStatusCode.noContent
1450
- };
1451
- }
1452
- /**
1453
- * Create an identity service.
1454
- * @param httpRequestContext The request context for the API.
1455
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1456
- * @param request The request.
1457
- * @returns The response object with additional http response properties.
1458
- */
1459
- async function identityServiceCreate(httpRequestContext, componentName, request) {
1460
- core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.userIdentity", httpRequestContext.userIdentity);
1461
- core.Guards.object(ROUTES_SOURCE, "request", request);
1462
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
1463
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.identity", request.pathParams.identity);
1464
- const component = core.ComponentFactory.get(componentName);
1465
- const result = await component.serviceCreate(request.pathParams.identity, request.body.serviceId, request.body.type, request.body.endpoint, httpRequestContext.userIdentity);
1466
- return {
1467
- body: result
1468
- };
1469
- }
1470
- /**
1471
- * Remove an identity service.
1472
- * @param httpRequestContext The request context for the API.
1473
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1474
- * @param request The request.
1475
- * @returns The response object with additional http response properties.
1476
- */
1477
- async function identityServiceRemove(httpRequestContext, componentName, request) {
1478
- core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.userIdentity", httpRequestContext.userIdentity);
1479
- core.Guards.object(ROUTES_SOURCE, "request", request);
1480
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
1481
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.identity", request.pathParams.identity);
1482
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.serviceId", request.pathParams.serviceId);
1483
- const component = core.ComponentFactory.get(componentName);
1484
- await component.serviceRemove(identityModels.DocumentHelper.joinId(request.pathParams.identity, request.pathParams.serviceId), httpRequestContext.userIdentity);
1485
- return {
1486
- statusCode: web.HttpStatusCode.noContent
1487
- };
1488
- }
1489
- /**
1490
- * Create a verifiable credential.
1491
- * @param httpRequestContext The request context for the API.
1492
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1493
- * @param request The request.
1494
- * @returns The response object with additional http response properties.
1495
- */
1496
- async function identityVerifiableCredentialCreate(httpRequestContext, componentName, request) {
1497
- core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.userIdentity", httpRequestContext.userIdentity);
1498
- core.Guards.object(ROUTES_SOURCE, "request", request);
1499
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
1500
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.identity", request.pathParams.identity);
1501
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.verificationMethodId", request.pathParams.verificationMethodId);
1502
- const component = core.ComponentFactory.get(componentName);
1503
- const result = await component.verifiableCredentialCreate(identityModels.DocumentHelper.joinId(request.pathParams.identity, request.pathParams.verificationMethodId), request.body.credentialId, request.body.subject, {
1504
- revocationIndex: request.body.revocationIndex,
1505
- expirationDate: core.Coerce.date(request.body.expirationDate)
1506
- }, httpRequestContext.userIdentity);
1507
- return {
1508
- body: result
1509
- };
1510
- }
1511
- /**
1512
- * Verify a verifiable credential.
1513
- * @param httpRequestContext The request context for the API.
1514
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1515
- * @param request The request.
1516
- * @returns The response object with additional http response properties.
1517
- */
1518
- async function identityVerifiableCredentialVerify(httpRequestContext, componentName, request) {
1519
- core.Guards.object(ROUTES_SOURCE, "request", request);
1520
- core.Guards.object(ROUTES_SOURCE, "request.query", request.query);
1521
- core.Guards.stringValue(ROUTES_SOURCE, "request.query.jwt", request.query.jwt);
1522
- const component = core.ComponentFactory.get(componentName);
1523
- const result = await component.verifiableCredentialVerify(request.query.jwt);
1524
- return {
1525
- body: result
1526
- };
1527
- }
1528
- /**
1529
- * Revoke a verifiable credential.
1530
- * @param httpRequestContext The request context for the API.
1531
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1532
- * @param request The request.
1533
- * @returns The response object with additional http response properties.
1534
- */
1535
- async function identityVerifiableCredentialRevoke(httpRequestContext, componentName, request) {
1536
- core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.userIdentity", httpRequestContext.userIdentity);
1537
- core.Guards.object(ROUTES_SOURCE, "request", request);
1538
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
1539
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.identity", request.pathParams.identity);
1540
- const revocationIndex = core.Coerce.number(request.pathParams.revocationIndex);
1541
- core.Guards.integer(ROUTES_SOURCE, "request.pathParams.revocationIndex", revocationIndex);
1542
- const component = core.ComponentFactory.get(componentName);
1543
- await component.verifiableCredentialRevoke(request.pathParams.identity, revocationIndex, httpRequestContext.userIdentity);
1544
- return {
1545
- statusCode: web.HttpStatusCode.noContent
1546
- };
1547
- }
1548
- /**
1549
- * Unrevoke a verifiable credential.
1550
- * @param httpRequestContext The request context for the API.
1551
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1552
- * @param request The request.
1553
- * @returns The response object with additional http response properties.
1554
- */
1555
- async function identityVerifiableCredentialUnrevoke(httpRequestContext, componentName, request) {
1556
- core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.userIdentity", httpRequestContext.userIdentity);
1557
- core.Guards.object(ROUTES_SOURCE, "request", request);
1558
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
1559
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.identity", request.pathParams.identity);
1560
- const revocationIndex = core.Coerce.number(request.pathParams.revocationIndex);
1561
- core.Guards.integer(ROUTES_SOURCE, "request.pathParams.revocationIndex", revocationIndex);
1562
- const component = core.ComponentFactory.get(componentName);
1563
- await component.verifiableCredentialUnrevoke(request.pathParams.identity, revocationIndex, httpRequestContext.userIdentity);
1564
- return {
1565
- statusCode: web.HttpStatusCode.noContent
1566
- };
1567
- }
1568
- /**
1569
- * Create a verifiable presentation.
1570
- * @param httpRequestContext The request context for the API.
1571
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1572
- * @param request The request.
1573
- * @returns The response object with additional http response properties.
1574
- */
1575
- async function identityVerifiablePresentationCreate(httpRequestContext, componentName, request) {
1576
- core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.userIdentity", httpRequestContext.userIdentity);
1577
- core.Guards.object(ROUTES_SOURCE, "request", request);
1578
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
1579
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.identity", request.pathParams.identity);
1580
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.verificationMethodId", request.pathParams.verificationMethodId);
1581
- const component = core.ComponentFactory.get(componentName);
1582
- const result = await component.verifiablePresentationCreate(identityModels.DocumentHelper.joinId(request.pathParams.identity, request.pathParams.verificationMethodId), request.body.presentationId, request.body.contexts, request.body.types, request.body.verifiableCredentials, request.body.expiresInMinutes, httpRequestContext.userIdentity);
1583
- return {
1584
- body: result
1585
- };
1586
- }
1587
- /**
1588
- * Verify a verifiable presentation.
1589
- * @param httpRequestContext The request context for the API.
1590
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1591
- * @param request The request.
1592
- * @returns The response object with additional http response properties.
1593
- */
1594
- async function identityVerifiablePresentationVerify(httpRequestContext, componentName, request) {
1595
- core.Guards.object(ROUTES_SOURCE, "request", request);
1596
- core.Guards.object(ROUTES_SOURCE, "request.query", request.query);
1597
- core.Guards.stringValue(ROUTES_SOURCE, "request.query.jwt", request.query.jwt);
1598
- const component = core.ComponentFactory.get(componentName);
1599
- const result = await component.verifiablePresentationVerify(request.query.jwt);
1600
- return {
1601
- body: result
1602
- };
1603
- }
1604
- /**
1605
- * Create an identity proof.
1606
- * @param httpRequestContext The request context for the API.
1607
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1608
- * @param request The request.
1609
- * @returns The response object with additional http response properties.
1610
- */
1611
- async function identityProofCreate(httpRequestContext, componentName, request) {
1612
- core.Guards.stringValue(ROUTES_SOURCE, "httpRequestContext.userIdentity", httpRequestContext.userIdentity);
1613
- core.Guards.object(ROUTES_SOURCE, "request", request);
1614
- core.Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
1615
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.identity", request.pathParams.identity);
1616
- core.Guards.stringValue(ROUTES_SOURCE, "request.pathParams.verificationMethodId", request.pathParams.verificationMethodId);
1617
- core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
1618
- const component = core.ComponentFactory.get(componentName);
1619
- const result = await component.proofCreate(request.pathParams.identity, request.body.proofType, request.body.document, httpRequestContext.userIdentity);
1620
- return {
1621
- body: result
1622
- };
1623
- }
1624
- /**
1625
- * Verify an identity proof.
1626
- * @param httpRequestContext The request context for the API.
1627
- * @param componentName The name of the component to use in the routes stored in the ComponentFactory.
1628
- * @param request The request.
1629
- * @returns The response object with additional http response properties.
1630
- */
1631
- async function identityProofVerify(httpRequestContext, componentName, request) {
1632
- core.Guards.object(ROUTES_SOURCE, "request", request);
1633
- core.Guards.object(ROUTES_SOURCE, "request.body", request.body);
1634
- const component = core.ComponentFactory.get(componentName);
1635
- const result = await component.proofVerify(request.body.document, request.body.proof);
1636
- return {
1637
- body: {
1638
- verified: result
1639
- }
1640
- };
1641
- }
1642
-
1643
- // Copyright 2024 IOTA Stiftung.
1644
- // SPDX-License-Identifier: Apache-2.0.
1645
- /**
1646
- * Class which implements the identity contract.
1647
- */
1648
- class IdentityService {
1649
- /**
1650
- * Runtime name for the class.
1651
- */
1652
- static CLASS_NAME = "IdentityService";
1653
- /**
1654
- * The default namespace for the connector to use.
1655
- * @internal
1656
- */
1657
- _defaultNamespace;
1658
- /**
1659
- * Create a new instance of IdentityService.
1660
- * @param options The options for the service.
1661
- */
1662
- constructor(options) {
1663
- const names = identityModels.IdentityConnectorFactory.names();
1664
- if (names.length === 0) {
1665
- throw new core.GeneralError(IdentityService.CLASS_NAME, "noConnectors");
1666
- }
1667
- this._defaultNamespace = options?.config?.defaultNamespace ?? names[0];
1668
- }
1669
- /**
1670
- * Create a new identity.
1671
- * @param namespace The namespace of the connector to use for the identity, defaults to service configured namespace.
1672
- * @param controller The controller of the identity who can make changes.
1673
- * @returns The created identity document.
1674
- */
1675
- async identityCreate(namespace, controller) {
1676
- core.Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
1677
- try {
1678
- const identityConnector = this.getConnectorByNamespace(namespace);
1679
- return identityConnector.createDocument(controller);
1680
- }
1681
- catch (error) {
1682
- throw new core.GeneralError(IdentityService.CLASS_NAME, "identityCreateFailed", undefined, error);
1683
- }
1684
- }
1685
- /**
1686
- * Remove an identity.
1687
- * @param identity The id of the document to remove.
1688
- * @param controller The controller of the identity who can make changes.
1689
- * @returns Nothing.
1690
- */
1691
- async identityRemove(identity, controller) {
1692
- core.Guards.stringValue(IdentityService.CLASS_NAME, "identity", identity);
1693
- core.Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
1694
- try {
1695
- const identityConnector = this.getConnectorByUri(identity);
1696
- return identityConnector.removeDocument(controller, identity);
1697
- }
1698
- catch (error) {
1699
- throw new core.GeneralError(IdentityService.CLASS_NAME, "identityRemoveFailed", { identity }, error);
1700
- }
1701
- }
1702
- /**
1703
- * Add a verification method to the document in JSON Web key Format.
1704
- * @param identity The id of the document to add the verification method to.
1705
- * @param verificationMethodType The type of the verification method to add.
1706
- * @param verificationMethodId The id of the verification method, if undefined uses the kid of the generated JWK.
1707
- * @param controller The controller of the identity who can make changes.
1708
- * @returns The verification method.
1709
- * @throws NotFoundError if the id can not be resolved.
1710
- * @throws NotSupportedError if the platform does not support multiple keys.
1711
- */
1712
- async verificationMethodCreate(identity, verificationMethodType, verificationMethodId, controller) {
1713
- core.Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
1714
- core.Urn.guard(IdentityService.CLASS_NAME, "identity", identity);
1715
- core.Guards.arrayOneOf(IdentityService.CLASS_NAME, "verificationMethodType", verificationMethodType, Object.values(standardsW3cDid.DidVerificationMethodType));
1716
- try {
1717
- const identityConnector = this.getConnectorByUri(identity);
1718
- const verificationMethod = await identityConnector.addVerificationMethod(controller, identity, verificationMethodType, verificationMethodId);
1719
- return verificationMethod;
1720
- }
1721
- catch (error) {
1722
- throw new core.GeneralError(IdentityService.CLASS_NAME, "verificationMethodCreateFailed", { identity }, error);
1723
- }
1724
- }
1725
- /**
1726
- * Remove a verification method from the document.
1727
- * @param verificationMethodId The id of the verification method.
1728
- * @param controller The controller of the identity who can make changes.
1729
- * @returns Nothing.
1730
- * @throws NotFoundError if the id can not be resolved.
1731
- * @throws NotSupportedError if the platform does not support multiple revocable keys.
1732
- */
1733
- async verificationMethodRemove(verificationMethodId, controller) {
1734
- core.Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
1735
- core.Urn.guard(IdentityService.CLASS_NAME, "verificationMethodId", verificationMethodId);
1736
- try {
1737
- const idParts = identityModels.DocumentHelper.parseId(verificationMethodId);
1738
- const identityConnector = this.getConnectorByUri(idParts.id);
1739
- await identityConnector.removeVerificationMethod(controller, verificationMethodId);
1740
- }
1741
- catch (error) {
1742
- throw new core.GeneralError(IdentityService.CLASS_NAME, "verificationMethodRemoveFailed", { verificationMethodId }, error);
1743
- }
1744
- }
1745
- /**
1746
- * Add a service to the document.
1747
- * @param identity The id of the document to add the service to.
1748
- * @param serviceId The id of the service.
1749
- * @param serviceType The type of the service.
1750
- * @param serviceEndpoint The endpoint for the service.
1751
- * @param controller The controller of the identity who can make changes.
1752
- * @returns The service.
1753
- * @throws NotFoundError if the id can not be resolved.
1754
- */
1755
- async serviceCreate(identity, serviceId, serviceType, serviceEndpoint, controller) {
1756
- core.Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
1757
- core.Urn.guard(IdentityService.CLASS_NAME, "identity", identity);
1758
- core.Guards.stringValue(IdentityService.CLASS_NAME, "serviceId", serviceId);
1759
- if (core.Is.array(serviceType)) {
1760
- core.Guards.arrayValue(IdentityService.CLASS_NAME, "serviceType", serviceType);
1761
- }
1762
- else {
1763
- core.Guards.stringValue(IdentityService.CLASS_NAME, "serviceType", serviceType);
1764
- }
1765
- if (core.Is.array(serviceEndpoint)) {
1766
- core.Guards.arrayValue(IdentityService.CLASS_NAME, "serviceEndpoint", serviceEndpoint);
1767
- }
1768
- else {
1769
- core.Guards.stringValue(IdentityService.CLASS_NAME, "serviceEndpoint", serviceEndpoint);
1770
- }
1771
- try {
1772
- const identityConnector = this.getConnectorByUri(identity);
1773
- const service = await identityConnector.addService(controller, identity, serviceId, serviceType, serviceEndpoint);
1774
- return service;
1775
- }
1776
- catch (error) {
1777
- throw new core.GeneralError(IdentityService.CLASS_NAME, "serviceCreateFailed", { identity, serviceId }, error);
1778
- }
1779
- }
1780
- /**
1781
- * Remove a service from the document.
1782
- * @param serviceId The id of the service.
1783
- * @param controller The controller of the identity who can make changes.
1784
- * @returns Nothing.
1785
- * @throws NotFoundError if the id can not be resolved.
1786
- */
1787
- async serviceRemove(serviceId, controller) {
1788
- core.Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
1789
- core.Urn.guard(IdentityService.CLASS_NAME, "serviceId", serviceId);
1790
- try {
1791
- const idParts = identityModels.DocumentHelper.parseId(serviceId);
1792
- const identityConnector = this.getConnectorByUri(idParts.id);
1793
- await identityConnector.removeService(controller, serviceId);
1794
- }
1795
- catch (error) {
1796
- throw new core.GeneralError(IdentityService.CLASS_NAME, "serviceRemoveFailed", { serviceId }, error);
1797
- }
1798
- }
1799
- /**
1800
- * Create a verifiable credential for a verification method.
1801
- * @param verificationMethodId The verification method id to use.
1802
- * @param id The id of the credential.
1803
- * @param subject The credential subject to store in the verifiable credential.
1804
- * @param options Additional options for creating the verifiable credential.
1805
- * @param options.revocationIndex The bitmap revocation index of the credential, if undefined will not have revocation status.
1806
- * @param options.expirationDate The date the verifiable credential is valid until.
1807
- * @param controller The controller of the identity who can make changes.
1808
- * @returns The created verifiable credential and its token.
1809
- * @throws NotFoundError if the id can not be resolved.
1810
- */
1811
- async verifiableCredentialCreate(verificationMethodId, id, subject, options, controller) {
1812
- core.Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
1813
- core.Urn.guard(IdentityService.CLASS_NAME, "verificationMethodId", verificationMethodId);
1814
- core.Guards.objectValue(IdentityService.CLASS_NAME, "subject", subject);
1815
- try {
1816
- const idParts = identityModels.DocumentHelper.parseId(verificationMethodId);
1817
- const identityConnector = this.getConnectorByUri(idParts.id);
1818
- const service = await identityConnector.createVerifiableCredential(controller, verificationMethodId, id, subject, options);
1819
- return service;
1820
- }
1821
- catch (error) {
1822
- throw new core.GeneralError(IdentityService.CLASS_NAME, "verifiableCredentialCreateFailed", { verificationMethodId }, error);
1823
- }
1824
- }
1825
- /**
1826
- * Verify a verifiable credential is valid.
1827
- * @param credentialJwt The credential to verify.
1828
- * @returns The credential stored in the jwt and the revocation status.
1829
- */
1830
- async verifiableCredentialVerify(credentialJwt) {
1831
- core.Guards.stringValue(IdentityService.CLASS_NAME, "credentialJwt", credentialJwt);
1832
- const jwtDecoded = await web.Jwt.decode(credentialJwt);
1833
- const jwtHeader = jwtDecoded.header;
1834
- const jwtPayload = jwtDecoded.payload;
1835
- const jwtSignature = jwtDecoded.signature;
1836
- if (core.Is.undefined(jwtHeader) ||
1837
- core.Is.undefined(jwtPayload) ||
1838
- core.Is.undefined(jwtPayload.iss) ||
1839
- core.Is.undefined(jwtSignature)) {
1840
- throw new core.GeneralError(IdentityService.CLASS_NAME, "jwtDecodeFailed");
1841
- }
1842
- try {
1843
- const identityConnector = this.getConnectorByUri(jwtPayload.iss);
1844
- const service = await identityConnector.checkVerifiableCredential(credentialJwt);
1845
- return service;
1846
- }
1847
- catch (error) {
1848
- throw new core.GeneralError(IdentityService.CLASS_NAME, "verifiableCredentialVerifyFailed", undefined, error);
1849
- }
1850
- }
1851
- /**
1852
- * Revoke verifiable credential.
1853
- * @param issuerIdentity The id of the document to update the revocation list for.
1854
- * @param credentialIndex The revocation bitmap index revoke.
1855
- * @param controller The controller of the identity who can make changes.
1856
- * @returns Nothing.
1857
- */
1858
- async verifiableCredentialRevoke(issuerIdentity, credentialIndex, controller) {
1859
- core.Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
1860
- core.Guards.stringValue(IdentityService.CLASS_NAME, "issuerIdentity", issuerIdentity);
1861
- core.Guards.number(IdentityService.CLASS_NAME, "credentialIndex", credentialIndex);
1862
- try {
1863
- const idParts = identityModels.DocumentHelper.parseId(issuerIdentity);
1864
- const identityConnector = this.getConnectorByUri(idParts.id);
1865
- return identityConnector.revokeVerifiableCredentials(controller, issuerIdentity, [
1866
- credentialIndex
1867
- ]);
1868
- }
1869
- catch (error) {
1870
- throw new core.GeneralError(IdentityService.CLASS_NAME, "verifiableCredentialRevokeFailed", { issuerIdentity, credentialIndex }, error);
1871
- }
1872
- }
1873
- /**
1874
- * Unrevoke verifiable credential.
1875
- * @param issuerIdentity The id of the document to update the revocation list for.
1876
- * @param credentialIndex The revocation bitmap index to un revoke.
1877
- * @param controller The controller of the identity who can make changes.
1878
- * @returns Nothing.
1879
- */
1880
- async verifiableCredentialUnrevoke(issuerIdentity, credentialIndex, controller) {
1881
- core.Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
1882
- core.Guards.stringValue(IdentityService.CLASS_NAME, "issuerIdentity", issuerIdentity);
1883
- core.Guards.number(IdentityService.CLASS_NAME, "credentialIndex", credentialIndex);
1884
- try {
1885
- const idParts = identityModels.DocumentHelper.parseId(issuerIdentity);
1886
- const identityConnector = this.getConnectorByUri(idParts.id);
1887
- return identityConnector.unrevokeVerifiableCredentials(controller, issuerIdentity, [
1888
- credentialIndex
1889
- ]);
1890
- }
1891
- catch (error) {
1892
- throw new core.GeneralError(IdentityService.CLASS_NAME, "verifiableCredentialUnrevokeFailed", { issuerIdentity, credentialIndex }, error);
1893
- }
1894
- }
1895
- /**
1896
- * Create a verifiable presentation from the supplied verifiable credentials.
1897
- * @param verificationMethodId The method to associate with the presentation.
1898
- * @param presentationId The id of the presentation.
1899
- * @param contexts The contexts for the data stored in the verifiable credential.
1900
- * @param types The types for the data stored in the verifiable credential.
1901
- * @param verifiableCredentials The credentials to use for creating the presentation in jwt format.
1902
- * @param expiresInMinutes The time in minutes for the presentation to expire.
1903
- * @param controller The controller of the identity who can make changes.
1904
- * @returns The created verifiable presentation and its token.
1905
- * @throws NotFoundError if the id can not be resolved.
1906
- */
1907
- async verifiablePresentationCreate(verificationMethodId, presentationId, contexts, types, verifiableCredentials, expiresInMinutes, controller) {
1908
- core.Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
1909
- core.Guards.stringValue(IdentityService.CLASS_NAME, "verificationMethodId", verificationMethodId);
1910
- try {
1911
- const idParts = identityModels.DocumentHelper.parseId(verificationMethodId);
1912
- const identityConnector = this.getConnectorByUri(idParts.id);
1913
- return identityConnector.createVerifiablePresentation(controller, verificationMethodId, presentationId, contexts, types, verifiableCredentials, expiresInMinutes);
1914
- }
1915
- catch (error) {
1916
- throw new core.GeneralError(IdentityService.CLASS_NAME, "verifiablePresentationCreateFailed", { verificationMethodId }, error);
1917
- }
1918
- }
1919
- /**
1920
- * Verify a verifiable presentation is valid.
1921
- * @param presentationJwt The presentation to verify.
1922
- * @returns The presentation stored in the jwt and the revocation status.
1923
- */
1924
- async verifiablePresentationVerify(presentationJwt) {
1925
- core.Guards.stringValue(IdentityService.CLASS_NAME, "presentationJwt", presentationJwt);
1926
- const jwtDecoded = await web.Jwt.decode(presentationJwt);
1927
- const jwtHeader = jwtDecoded.header;
1928
- const jwtPayload = jwtDecoded.payload;
1929
- const jwtSignature = jwtDecoded.signature;
1930
- if (core.Is.undefined(jwtHeader) ||
1931
- core.Is.undefined(jwtPayload) ||
1932
- core.Is.undefined(jwtPayload.iss) ||
1933
- core.Is.undefined(jwtSignature)) {
1934
- throw new core.GeneralError(IdentityService.CLASS_NAME, "jwtDecodeFailed");
1935
- }
1936
- try {
1937
- const identityConnector = this.getConnectorByUri(jwtPayload.iss);
1938
- const service = await identityConnector.checkVerifiablePresentation(presentationJwt);
1939
- return service;
1940
- }
1941
- catch (error) {
1942
- throw new core.GeneralError(IdentityService.CLASS_NAME, "verifiablePresentationVerifyFailed", undefined, error);
1943
- }
1944
- }
1945
- /**
1946
- * Create a proof for a document with the specified verification method.
1947
- * @param verificationMethodId The verification method id to use.
1948
- * @param proofType The type of proof to create.
1949
- * @param unsecureDocument The unsecure document to create the proof for.
1950
- * @param controller The controller of the identity who can make changes.
1951
- * @returns The proof.
1952
- */
1953
- async proofCreate(verificationMethodId, proofType, unsecureDocument, controller) {
1954
- core.Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
1955
- core.Guards.stringValue(IdentityService.CLASS_NAME, "verificationMethodId", verificationMethodId);
1956
- core.Guards.arrayOneOf(IdentityService.CLASS_NAME, "proofType", proofType, Object.values(standardsW3cDid.ProofTypes));
1957
- core.Guards.object(IdentityService.CLASS_NAME, "unsecureDocument", unsecureDocument);
1958
- try {
1959
- const idParts = identityModels.DocumentHelper.parseId(verificationMethodId);
1960
- const identityConnector = this.getConnectorByUri(idParts.id);
1961
- return identityConnector.createProof(controller, verificationMethodId, proofType, unsecureDocument);
1962
- }
1963
- catch (error) {
1964
- throw new core.GeneralError(IdentityService.CLASS_NAME, "proofCreateFailed", { verificationMethodId }, error);
1965
- }
1966
- }
1967
- /**
1968
- * Verify proof for a document with the specified verification method.
1969
- * @param document The document to verify.
1970
- * @param proof The proof to verify.
1971
- * @returns True if the proof is verified.
1972
- */
1973
- async proofVerify(document, proof) {
1974
- core.Guards.object(IdentityService.CLASS_NAME, "document", document);
1975
- core.Guards.object(IdentityService.CLASS_NAME, "proof", proof);
1976
- core.Guards.stringValue(IdentityService.CLASS_NAME, "proof.verificationMethod", proof.verificationMethod);
1977
- try {
1978
- const idParts = identityModels.DocumentHelper.parseId(proof.verificationMethod);
1979
- const identityConnector = this.getConnectorByUri(idParts.id);
1980
- return identityConnector.verifyProof(document, proof);
1981
- }
1982
- catch (error) {
1983
- throw new core.GeneralError(IdentityService.CLASS_NAME, "proofVerifyFailed", undefined, error);
1984
- }
1985
- }
1986
- /**
1987
- * Get the connector from the namespace.
1988
- * @param namespace The namespace for the identity.
1989
- * @returns The connector.
1990
- * @internal
1991
- */
1992
- getConnectorByNamespace(namespace) {
1993
- const namespaceMethod = namespace ?? this._defaultNamespace;
1994
- const connector = identityModels.IdentityConnectorFactory.getIfExists(namespaceMethod);
1995
- if (core.Is.empty(connector)) {
1996
- throw new core.GeneralError(IdentityService.CLASS_NAME, "connectorNotFound", {
1997
- namespace: namespaceMethod
1998
- });
1999
- }
2000
- return connector;
2001
- }
2002
- /**
2003
- * Get the connector from the uri.
2004
- * @param id The id of the identity in urn format.
2005
- * @returns The connector.
2006
- * @internal
2007
- */
2008
- getConnectorByUri(id) {
2009
- const idUri = core.Urn.fromValidString(id);
2010
- if (idUri.namespaceIdentifier() !== "did") {
2011
- throw new core.GeneralError(IdentityService.CLASS_NAME, "namespaceMismatch", {
2012
- namespace: "did",
2013
- id
2014
- });
2015
- }
2016
- return this.getConnectorByNamespace(idUri.namespaceMethod());
2017
- }
2018
- }
2019
-
2020
- const restEntryPoints = [
2021
- {
2022
- name: "identityResolver",
2023
- defaultBaseRoute: "identity",
2024
- tags: tagsIdentityResolver,
2025
- generateRoutes: generateRestRoutesIdentityResolver
2026
- },
2027
- {
2028
- name: "identity",
2029
- defaultBaseRoute: "identity",
2030
- tags: tagsIdentity,
2031
- generateRoutes: generateRestRoutesIdentity
2032
- },
2033
- {
2034
- name: "identityProfile",
2035
- defaultBaseRoute: "identity/profile",
2036
- tags: tagsIdentityProfile,
2037
- generateRoutes: generateRestRoutesIdentityProfile
2038
- }
2039
- ];
2040
-
2041
- exports.IdentityProfileService = IdentityProfileService;
2042
- exports.IdentityResolverService = IdentityResolverService;
2043
- exports.IdentityService = IdentityService;
2044
- exports.generateRestRoutesIdentity = generateRestRoutesIdentity;
2045
- exports.generateRestRoutesIdentityProfile = generateRestRoutesIdentityProfile;
2046
- exports.generateRestRoutesIdentityResolver = generateRestRoutesIdentityResolver;
2047
- exports.identitiesList = identitiesList;
2048
- exports.identityCreate = identityCreate;
2049
- exports.identityGet = identityGet;
2050
- exports.identityGetPublic = identityGetPublic;
2051
- exports.identityProfileCreate = identityProfileCreate;
2052
- exports.identityProfileRemove = identityProfileRemove;
2053
- exports.identityProfileUpdate = identityProfileUpdate;
2054
- exports.identityProofCreate = identityProofCreate;
2055
- exports.identityProofVerify = identityProofVerify;
2056
- exports.identityRemove = identityRemove;
2057
- exports.identityResolve = identityResolve;
2058
- exports.identityServiceCreate = identityServiceCreate;
2059
- exports.identityServiceRemove = identityServiceRemove;
2060
- exports.identityVerifiableCredentialCreate = identityVerifiableCredentialCreate;
2061
- exports.identityVerifiableCredentialRevoke = identityVerifiableCredentialRevoke;
2062
- exports.identityVerifiableCredentialUnrevoke = identityVerifiableCredentialUnrevoke;
2063
- exports.identityVerifiableCredentialVerify = identityVerifiableCredentialVerify;
2064
- exports.identityVerifiablePresentationCreate = identityVerifiablePresentationCreate;
2065
- exports.identityVerifiablePresentationVerify = identityVerifiablePresentationVerify;
2066
- exports.identityVerificationMethodCreate = identityVerificationMethodCreate;
2067
- exports.identityVerificationMethodRemove = identityVerificationMethodRemove;
2068
- exports.restEntryPoints = restEntryPoints;
2069
- exports.tagsIdentity = tagsIdentity;
2070
- exports.tagsIdentityProfile = tagsIdentityProfile;
2071
- exports.tagsIdentityResolver = tagsIdentityResolver;