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