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