@twin.org/identity-service 0.0.3-next.9 → 0.9.0
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/README.md +2 -2
- package/dist/es/identityProfileRoutes.js +1 -2
- package/dist/es/identityProfileRoutes.js.map +1 -1
- package/dist/es/identityProfileService.js +3 -3
- package/dist/es/identityProfileService.js.map +1 -1
- package/dist/es/identityResolverRoutes.js +3 -4
- package/dist/es/identityResolverRoutes.js.map +1 -1
- package/dist/es/identityResolverService.js +3 -0
- package/dist/es/identityResolverService.js.map +1 -1
- package/dist/es/identityRoutes.js +284 -14
- package/dist/es/identityRoutes.js.map +1 -1
- package/dist/es/identityService.js +154 -31
- package/dist/es/identityService.js.map +1 -1
- package/dist/es/models/IIdentityResolverServiceConfig.js.map +1 -1
- package/dist/es/models/IIdentityServiceConfig.js.map +1 -1
- package/dist/es/models/IIdentityServiceConstructorOptions.js.map +1 -1
- package/dist/es/restEntryPoints.js +3 -0
- package/dist/es/restEntryPoints.js.map +1 -1
- package/dist/types/identityProfileService.d.ts +3 -3
- package/dist/types/identityResolverRoutes.d.ts +1 -1
- package/dist/types/identityResolverService.d.ts +1 -0
- package/dist/types/identityRoutes.d.ts +33 -1
- package/dist/types/identityService.d.ts +59 -12
- package/dist/types/models/IIdentityResolverServiceConfig.d.ts +1 -1
- package/dist/types/models/IIdentityServiceConfig.d.ts +1 -1
- package/dist/types/models/IIdentityServiceConstructorOptions.d.ts +4 -0
- package/dist/types/restEntryPoints.d.ts +3 -0
- package/docs/changelog.md +682 -101
- package/docs/examples.md +196 -1
- package/docs/open-api/spec.json +804 -482
- package/docs/reference/classes/IdentityProfileService.md +11 -11
- package/docs/reference/classes/IdentityResolverService.md +7 -3
- package/docs/reference/classes/IdentityService.md +188 -44
- package/docs/reference/functions/generateRestRoutesIdentityResolver.md +1 -1
- package/docs/reference/functions/identityAlsoKnownAsCreate.md +31 -0
- package/docs/reference/functions/identityAlsoKnownAsRemove.md +31 -0
- package/docs/reference/functions/identityVerifiableCredentialVerifyDocument.md +31 -0
- package/docs/reference/functions/identityVerifiablePresentationVerifyDocument.md +31 -0
- package/docs/reference/index.md +4 -0
- package/docs/reference/interfaces/IIdentityProfileServiceConstructorOptions.md +2 -2
- package/docs/reference/interfaces/IIdentityResolverServiceConfig.md +3 -3
- package/docs/reference/interfaces/IIdentityResolverServiceConstructorOptions.md +4 -4
- package/docs/reference/interfaces/IIdentityServiceConfig.md +3 -3
- package/docs/reference/interfaces/IIdentityServiceConstructorOptions.md +10 -2
- package/docs/reference/variables/restEntryPoints.md +2 -0
- package/locales/en.json +2 -0
- package/package.json +17 -16
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// Copyright 2024 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import { GeneralError, Guards, Is, Urn } from "@twin.org/core";
|
|
4
|
-
import { DocumentHelper, IdentityConnectorFactory } from "@twin.org/identity-models";
|
|
3
|
+
import { ComponentFactory, GeneralError, Guards, Is, Urn } from "@twin.org/core";
|
|
4
|
+
import { DocumentHelper, IdentityConnectorFactory, IdentityMetricIds, IdentityMetrics } from "@twin.org/identity-models";
|
|
5
5
|
import { DidVerificationMethodType, ProofTypes } from "@twin.org/standards-w3c-did";
|
|
6
|
+
import { MetricHelper } from "@twin.org/telemetry-models";
|
|
6
7
|
import { Jwt } from "@twin.org/web";
|
|
7
8
|
/**
|
|
8
9
|
* Class which implements the identity contract.
|
|
@@ -17,9 +18,15 @@ export class IdentityService {
|
|
|
17
18
|
* @internal
|
|
18
19
|
*/
|
|
19
20
|
_defaultNamespace;
|
|
21
|
+
/**
|
|
22
|
+
* The telemetry component.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
_telemetryComponent;
|
|
20
26
|
/**
|
|
21
27
|
* Create a new instance of IdentityService.
|
|
22
28
|
* @param options The options for the service.
|
|
29
|
+
* @throws GeneralError if no connectors are registered.
|
|
23
30
|
*/
|
|
24
31
|
constructor(options) {
|
|
25
32
|
const names = IdentityConnectorFactory.names();
|
|
@@ -27,6 +34,7 @@ export class IdentityService {
|
|
|
27
34
|
throw new GeneralError(IdentityService.CLASS_NAME, "noConnectors");
|
|
28
35
|
}
|
|
29
36
|
this._defaultNamespace = options?.config?.defaultNamespace ?? names[0];
|
|
37
|
+
this._telemetryComponent = ComponentFactory.getIfExists(options?.telemetryComponentType);
|
|
30
38
|
}
|
|
31
39
|
/**
|
|
32
40
|
* Returns the class name of the component.
|
|
@@ -35,6 +43,16 @@ export class IdentityService {
|
|
|
35
43
|
className() {
|
|
36
44
|
return IdentityService.CLASS_NAME;
|
|
37
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Register all identity metrics with the telemetry component.
|
|
48
|
+
* @returns A promise that resolves when all metrics have been registered.
|
|
49
|
+
*/
|
|
50
|
+
async start() {
|
|
51
|
+
if (Is.undefined(this._telemetryComponent)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
await MetricHelper.createMetrics(this._telemetryComponent, IdentityMetrics);
|
|
55
|
+
}
|
|
38
56
|
/**
|
|
39
57
|
* Create a new identity.
|
|
40
58
|
* @param namespace The namespace of the connector to use for the identity, defaults to service configured namespace.
|
|
@@ -46,6 +64,9 @@ export class IdentityService {
|
|
|
46
64
|
try {
|
|
47
65
|
const identityConnector = this.getConnectorByNamespace(namespace);
|
|
48
66
|
const result = await identityConnector.createDocument(controller);
|
|
67
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.DidsCreated, {
|
|
68
|
+
namespace: namespace ?? this._defaultNamespace
|
|
69
|
+
});
|
|
49
70
|
return result;
|
|
50
71
|
}
|
|
51
72
|
catch (error) {
|
|
@@ -56,7 +77,7 @@ export class IdentityService {
|
|
|
56
77
|
* Remove an identity.
|
|
57
78
|
* @param identity The id of the document to remove.
|
|
58
79
|
* @param controller The controller of the identity who can make changes.
|
|
59
|
-
* @returns
|
|
80
|
+
* @returns A promise that resolves when the identity has been removed.
|
|
60
81
|
*/
|
|
61
82
|
async identityRemove(identity, controller) {
|
|
62
83
|
Guards.stringValue(IdentityService.CLASS_NAME, "identity", identity);
|
|
@@ -64,6 +85,7 @@ export class IdentityService {
|
|
|
64
85
|
try {
|
|
65
86
|
const identityConnector = this.getConnectorByUri(identity);
|
|
66
87
|
const result = await identityConnector.removeDocument(controller, identity);
|
|
88
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.DidsRemoved);
|
|
67
89
|
return result;
|
|
68
90
|
}
|
|
69
91
|
catch (error) {
|
|
@@ -97,7 +119,7 @@ export class IdentityService {
|
|
|
97
119
|
* Remove a verification method from the document.
|
|
98
120
|
* @param verificationMethodId The id of the verification method.
|
|
99
121
|
* @param controller The controller of the identity who can make changes.
|
|
100
|
-
* @returns
|
|
122
|
+
* @returns A promise that resolves when the verification method has been removed.
|
|
101
123
|
* @throws NotFoundError if the id can not be resolved.
|
|
102
124
|
* @throws NotSupportedError if the platform does not support multiple revocable keys.
|
|
103
125
|
*/
|
|
@@ -152,7 +174,7 @@ export class IdentityService {
|
|
|
152
174
|
* Remove a service from the document.
|
|
153
175
|
* @param serviceId The id of the service.
|
|
154
176
|
* @param controller The controller of the identity who can make changes.
|
|
155
|
-
* @returns
|
|
177
|
+
* @returns A promise that resolves when the service has been removed.
|
|
156
178
|
* @throws NotFoundError if the id can not be resolved.
|
|
157
179
|
*/
|
|
158
180
|
async serviceRemove(serviceId, controller) {
|
|
@@ -167,6 +189,52 @@ export class IdentityService {
|
|
|
167
189
|
throw new GeneralError(IdentityService.CLASS_NAME, "serviceRemoveFailed", { serviceId }, error);
|
|
168
190
|
}
|
|
169
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Add an alias to the alsoKnownAs property on the document.
|
|
194
|
+
* If the alias is already present the operation is a no-op.
|
|
195
|
+
* @param documentId The id of the document to update.
|
|
196
|
+
* @param alias The alias to add. Must be a Url or Urn (typically another DID).
|
|
197
|
+
* @param controller The controller of the identity who can make changes.
|
|
198
|
+
* @returns A promise that resolves when the alias has been added.
|
|
199
|
+
* @throws GeneralError if the alias is not a Url or Urn.
|
|
200
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
201
|
+
*/
|
|
202
|
+
async alsoKnownAsAdd(documentId, alias, controller) {
|
|
203
|
+
Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
|
|
204
|
+
Guards.stringValue(IdentityService.CLASS_NAME, "documentId", documentId);
|
|
205
|
+
Guards.stringValue(IdentityService.CLASS_NAME, "alias", alias);
|
|
206
|
+
try {
|
|
207
|
+
const idParts = DocumentHelper.parseId(documentId);
|
|
208
|
+
const identityConnector = this.getConnectorByUri(idParts.id);
|
|
209
|
+
await identityConnector.addAlsoKnownAs(controller, documentId, alias);
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
throw new GeneralError(IdentityService.CLASS_NAME, "alsoKnownAsAddFailed", { identity: documentId, alias }, error);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Remove an alias from the alsoKnownAs property on the document.
|
|
217
|
+
* If the alias is not present the operation is a no-op.
|
|
218
|
+
* @param documentId The id of the document to update.
|
|
219
|
+
* @param alias The alias to remove. Must be a Url or Urn.
|
|
220
|
+
* @param controller The controller of the identity who can make changes.
|
|
221
|
+
* @returns A promise that resolves when the alias has been removed.
|
|
222
|
+
* @throws GeneralError if the alias is not a Url or Urn.
|
|
223
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
224
|
+
*/
|
|
225
|
+
async alsoKnownAsRemove(documentId, alias, controller) {
|
|
226
|
+
Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
|
|
227
|
+
Guards.stringValue(IdentityService.CLASS_NAME, "documentId", documentId);
|
|
228
|
+
Guards.stringValue(IdentityService.CLASS_NAME, "alias", alias);
|
|
229
|
+
try {
|
|
230
|
+
const idParts = DocumentHelper.parseId(documentId);
|
|
231
|
+
const identityConnector = this.getConnectorByUri(idParts.id);
|
|
232
|
+
await identityConnector.removeAlsoKnownAs(controller, documentId, alias);
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
throw new GeneralError(IdentityService.CLASS_NAME, "alsoKnownAsRemoveFailed", { identity: documentId, alias }, error);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
170
238
|
/**
|
|
171
239
|
* Create a verifiable credential for a verification method.
|
|
172
240
|
* @param verificationMethodId The verification method id to use.
|
|
@@ -175,6 +243,8 @@ export class IdentityService {
|
|
|
175
243
|
* @param options Additional options for creating the verifiable credential.
|
|
176
244
|
* @param options.revocationIndex The bitmap revocation index of the credential, if undefined will not have revocation status.
|
|
177
245
|
* @param options.expirationDate The date the verifiable credential is valid until.
|
|
246
|
+
* @param options.jwtHeaderFields Additional fields to include in the JWT header when creating the verifiable credential in jwt format.
|
|
247
|
+
* @param options.jwtPayloadFields Additional fields to include in the JWT payload when creating the verifiable credential in jwt format.
|
|
178
248
|
* @param controller The controller of the identity who can make changes.
|
|
179
249
|
* @returns The created verifiable credential and its token.
|
|
180
250
|
* @throws NotFoundError if the id can not be resolved.
|
|
@@ -182,11 +252,15 @@ export class IdentityService {
|
|
|
182
252
|
async verifiableCredentialCreate(verificationMethodId, id, subject, options, controller) {
|
|
183
253
|
Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
|
|
184
254
|
Urn.guard(IdentityService.CLASS_NAME, "verificationMethodId", verificationMethodId);
|
|
185
|
-
Guards.
|
|
255
|
+
Guards.object(IdentityService.CLASS_NAME, "subject", subject);
|
|
186
256
|
try {
|
|
187
257
|
const idParts = DocumentHelper.parseId(verificationMethodId);
|
|
188
258
|
const identityConnector = this.getConnectorByUri(idParts.id);
|
|
189
259
|
const service = await identityConnector.createVerifiableCredential(controller, verificationMethodId, id, subject, options);
|
|
260
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VcsCreated, {
|
|
261
|
+
hasRevocation: Is.number(options?.revocationIndex),
|
|
262
|
+
hasExpiration: Is.date(options?.expirationDate)
|
|
263
|
+
});
|
|
190
264
|
return service;
|
|
191
265
|
}
|
|
192
266
|
catch (error) {
|
|
@@ -195,12 +269,31 @@ export class IdentityService {
|
|
|
195
269
|
}
|
|
196
270
|
/**
|
|
197
271
|
* Verify a verifiable credential is valid.
|
|
198
|
-
* @param
|
|
272
|
+
* @param credential The credential to verify.
|
|
199
273
|
* @returns The credential stored in the jwt and the revocation status.
|
|
200
274
|
*/
|
|
201
|
-
async verifiableCredentialVerify(
|
|
202
|
-
|
|
203
|
-
|
|
275
|
+
async verifiableCredentialVerify(credential) {
|
|
276
|
+
if (Is.object(credential)) {
|
|
277
|
+
Guards.objectValue(IdentityService.CLASS_NAME, "credential", credential);
|
|
278
|
+
Guards.stringValue(IdentityService.CLASS_NAME, "credential.issuer", credential.issuer);
|
|
279
|
+
Guards.objectValue(IdentityService.CLASS_NAME, "credential.proof", credential.proof);
|
|
280
|
+
try {
|
|
281
|
+
const identityConnector = this.getConnectorByUri(credential.issuer);
|
|
282
|
+
const service = await identityConnector.checkVerifiableCredential(credential);
|
|
283
|
+
if (service.revoked) {
|
|
284
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VcsVerificationFailed, { failureReason: "revoked" });
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VcsVerified);
|
|
288
|
+
}
|
|
289
|
+
return service;
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
throw new GeneralError(IdentityService.CLASS_NAME, "verifiableCredentialVerifyFailed", undefined, error);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
Guards.stringValue(IdentityService.CLASS_NAME, "credential", credential);
|
|
296
|
+
const jwtDecoded = await Jwt.decode(credential);
|
|
204
297
|
const jwtHeader = jwtDecoded.header;
|
|
205
298
|
const jwtPayload = jwtDecoded.payload;
|
|
206
299
|
const jwtSignature = jwtDecoded.signature;
|
|
@@ -212,7 +305,13 @@ export class IdentityService {
|
|
|
212
305
|
}
|
|
213
306
|
try {
|
|
214
307
|
const identityConnector = this.getConnectorByUri(jwtPayload.iss);
|
|
215
|
-
const service = await identityConnector.checkVerifiableCredential(
|
|
308
|
+
const service = await identityConnector.checkVerifiableCredential(credential);
|
|
309
|
+
if (service.revoked) {
|
|
310
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VcsVerificationFailed, { failureReason: "revoked" });
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VcsVerified);
|
|
314
|
+
}
|
|
216
315
|
return service;
|
|
217
316
|
}
|
|
218
317
|
catch (error) {
|
|
@@ -222,9 +321,9 @@ export class IdentityService {
|
|
|
222
321
|
/**
|
|
223
322
|
* Revoke verifiable credential.
|
|
224
323
|
* @param issuerIdentity The id of the document to update the revocation list for.
|
|
225
|
-
* @param credentialIndex The revocation bitmap index revoke.
|
|
324
|
+
* @param credentialIndex The revocation bitmap index to revoke.
|
|
226
325
|
* @param controller The controller of the identity who can make changes.
|
|
227
|
-
* @returns
|
|
326
|
+
* @returns A promise that resolves when the credential has been revoked.
|
|
228
327
|
*/
|
|
229
328
|
async verifiableCredentialRevoke(issuerIdentity, credentialIndex, controller) {
|
|
230
329
|
Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
|
|
@@ -234,6 +333,7 @@ export class IdentityService {
|
|
|
234
333
|
const idParts = DocumentHelper.parseId(issuerIdentity);
|
|
235
334
|
const identityConnector = this.getConnectorByUri(idParts.id);
|
|
236
335
|
const result = await identityConnector.revokeVerifiableCredentials(controller, issuerIdentity, [credentialIndex]);
|
|
336
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VcsRevoked);
|
|
237
337
|
return result;
|
|
238
338
|
}
|
|
239
339
|
catch (error) {
|
|
@@ -245,7 +345,7 @@ export class IdentityService {
|
|
|
245
345
|
* @param issuerIdentity The id of the document to update the revocation list for.
|
|
246
346
|
* @param credentialIndex The revocation bitmap index to un revoke.
|
|
247
347
|
* @param controller The controller of the identity who can make changes.
|
|
248
|
-
* @returns
|
|
348
|
+
* @returns A promise that resolves when the credential has been unrevoked.
|
|
249
349
|
*/
|
|
250
350
|
async verifiableCredentialUnrevoke(issuerIdentity, credentialIndex, controller) {
|
|
251
351
|
Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
|
|
@@ -255,6 +355,7 @@ export class IdentityService {
|
|
|
255
355
|
const idParts = DocumentHelper.parseId(issuerIdentity);
|
|
256
356
|
const identityConnector = this.getConnectorByUri(idParts.id);
|
|
257
357
|
const result = await identityConnector.unrevokeVerifiableCredentials(controller, issuerIdentity, [credentialIndex]);
|
|
358
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VcsUnrevoked);
|
|
258
359
|
return result;
|
|
259
360
|
}
|
|
260
361
|
catch (error) {
|
|
@@ -268,18 +369,24 @@ export class IdentityService {
|
|
|
268
369
|
* @param contexts The contexts for the data stored in the verifiable credential.
|
|
269
370
|
* @param types The types for the data stored in the verifiable credential.
|
|
270
371
|
* @param verifiableCredentials The credentials to use for creating the presentation in jwt format.
|
|
271
|
-
* @param
|
|
372
|
+
* @param options Additional options for creating the verifiable presentation.
|
|
373
|
+
* @param options.expirationDate The date the verifiable presentation is valid until.
|
|
374
|
+
* @param options.jwtHeaderFields Additional fields to include in the JWT header when creating the verifiable presentation in jwt format.
|
|
375
|
+
* @param options.jwtPayloadFields Additional fields to include in the JWT payload when creating the verifiable presentation in jwt format.
|
|
272
376
|
* @param controller The controller of the identity who can make changes.
|
|
273
377
|
* @returns The created verifiable presentation and its token.
|
|
274
378
|
* @throws NotFoundError if the id can not be resolved.
|
|
275
379
|
*/
|
|
276
|
-
async verifiablePresentationCreate(verificationMethodId, presentationId, contexts, types, verifiableCredentials,
|
|
380
|
+
async verifiablePresentationCreate(verificationMethodId, presentationId, contexts, types, verifiableCredentials, options, controller) {
|
|
277
381
|
Guards.stringValue(IdentityService.CLASS_NAME, "controller", controller);
|
|
278
382
|
Guards.stringValue(IdentityService.CLASS_NAME, "verificationMethodId", verificationMethodId);
|
|
279
383
|
try {
|
|
280
384
|
const idParts = DocumentHelper.parseId(verificationMethodId);
|
|
281
385
|
const identityConnector = this.getConnectorByUri(idParts.id);
|
|
282
|
-
const result = await identityConnector.createVerifiablePresentation(controller, verificationMethodId, presentationId, contexts, types, verifiableCredentials,
|
|
386
|
+
const result = await identityConnector.createVerifiablePresentation(controller, verificationMethodId, presentationId, contexts, types, verifiableCredentials, options);
|
|
387
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VpsCreated, {
|
|
388
|
+
credentialCount: verifiableCredentials.length
|
|
389
|
+
});
|
|
283
390
|
return result;
|
|
284
391
|
}
|
|
285
392
|
catch (error) {
|
|
@@ -288,24 +395,38 @@ export class IdentityService {
|
|
|
288
395
|
}
|
|
289
396
|
/**
|
|
290
397
|
* Verify a verifiable presentation is valid.
|
|
291
|
-
* @param
|
|
398
|
+
* @param presentation The presentation to verify.
|
|
292
399
|
* @returns The presentation stored in the jwt and the revocation status.
|
|
293
400
|
*/
|
|
294
|
-
async verifiablePresentationVerify(
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
Is.undefined(
|
|
303
|
-
|
|
304
|
-
|
|
401
|
+
async verifiablePresentationVerify(presentation) {
|
|
402
|
+
let holder;
|
|
403
|
+
if (Is.stringValue(presentation)) {
|
|
404
|
+
Guards.stringValue(IdentityService.CLASS_NAME, "presentation", presentation);
|
|
405
|
+
const jwtDecoded = await Jwt.decode(presentation);
|
|
406
|
+
const jwtHeader = jwtDecoded.header;
|
|
407
|
+
const jwtPayload = jwtDecoded.payload;
|
|
408
|
+
const jwtSignature = jwtDecoded.signature;
|
|
409
|
+
if (Is.undefined(jwtHeader) ||
|
|
410
|
+
Is.undefined(jwtPayload) ||
|
|
411
|
+
Is.undefined(jwtPayload.iss) ||
|
|
412
|
+
Is.undefined(jwtSignature)) {
|
|
413
|
+
throw new GeneralError(IdentityService.CLASS_NAME, "jwtDecodeFailed");
|
|
414
|
+
}
|
|
415
|
+
holder = jwtPayload.iss;
|
|
305
416
|
}
|
|
417
|
+
else {
|
|
418
|
+
holder = presentation.holder;
|
|
419
|
+
}
|
|
420
|
+
Guards.stringValue(IdentityService.CLASS_NAME, "holder", holder);
|
|
306
421
|
try {
|
|
307
|
-
const identityConnector = this.getConnectorByUri(
|
|
308
|
-
const service = await identityConnector.checkVerifiablePresentation(
|
|
422
|
+
const identityConnector = this.getConnectorByUri(holder);
|
|
423
|
+
const service = await identityConnector.checkVerifiablePresentation(presentation);
|
|
424
|
+
if (service.revoked) {
|
|
425
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VpsVerificationFailed, { failureReason: "revoked" });
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
await MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VpsVerified);
|
|
429
|
+
}
|
|
309
430
|
return service;
|
|
310
431
|
}
|
|
311
432
|
catch (error) {
|
|
@@ -359,6 +480,7 @@ export class IdentityService {
|
|
|
359
480
|
* Get the connector from the namespace.
|
|
360
481
|
* @param namespace The namespace for the identity.
|
|
361
482
|
* @returns The connector.
|
|
483
|
+
* @throws GeneralError if the connector is not found.
|
|
362
484
|
* @internal
|
|
363
485
|
*/
|
|
364
486
|
getConnectorByNamespace(namespace) {
|
|
@@ -375,6 +497,7 @@ export class IdentityService {
|
|
|
375
497
|
* Get the connector from the uri.
|
|
376
498
|
* @param id The id of the identity in urn format.
|
|
377
499
|
* @returns The connector.
|
|
500
|
+
* @throws GeneralError if the namespace does not match or the connector is not found.
|
|
378
501
|
* @internal
|
|
379
502
|
*/
|
|
380
503
|
getConnectorByUri(id) {
|
|
@@ -1 +1 @@
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CAAC,iBAAiB,CAAC;QAE5D,MAAM,SAAS,GAAG,wBAAwB,CAAC,WAAW,CAAqB,eAAe,CAAC,CAAC;QAE5F,IAAI,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,YAAY,CAAC,eAAe,CAAC,UAAU,EAAE,mBAAmB,EAAE;gBACvE,SAAS,EAAE,eAAe;aAC1B,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACK,iBAAiB,CAAC,EAAU;QACnC,MAAM,KAAK,GAAG,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QAEtC,IAAI,KAAK,CAAC,mBAAmB,EAAE,KAAK,KAAK,EAAE,CAAC;YAC3C,MAAM,IAAI,YAAY,CAAC,eAAe,CAAC,UAAU,EAAE,mBAAmB,EAAE;gBACvE,SAAS,EAAE,KAAK;gBAChB,EAAE;aACF,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC;IAC9D,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Is, Urn } from \"@twin.org/core\";\nimport type { IJsonLdContextDefinitionRoot, IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport {\n\tDocumentHelper,\n\tIdentityConnectorFactory,\n\ttype IIdentityComponent,\n\ttype IIdentityConnector\n} from \"@twin.org/identity-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tDidVerificationMethodType,\n\tProofTypes,\n\ttype IDidDocument,\n\ttype IDidDocumentVerificationMethod,\n\ttype IProof,\n\ttype IDidService,\n\ttype IDidVerifiableCredential,\n\ttype IDidVerifiablePresentation\n} from \"@twin.org/standards-w3c-did\";\nimport { Jwt } from \"@twin.org/web\";\nimport type { IIdentityServiceConstructorOptions } from \"./models/IIdentityServiceConstructorOptions.js\";\n\n/**\n * Class which implements the identity contract.\n */\nexport class IdentityService implements IIdentityComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IdentityService>();\n\n\t/**\n\t * The default namespace for the connector to use.\n\t * @internal\n\t */\n\tprivate readonly _defaultNamespace: string;\n\n\t/**\n\t * Create a new instance of IdentityService.\n\t * @param options The options for the service.\n\t */\n\tconstructor(options?: IIdentityServiceConstructorOptions) {\n\t\tconst names = IdentityConnectorFactory.names();\n\t\tif (names.length === 0) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"noConnectors\");\n\t\t}\n\n\t\tthis._defaultNamespace = options?.config?.defaultNamespace ?? names[0];\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn IdentityService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new identity.\n\t * @param namespace The namespace of the connector to use for the identity, defaults to service configured namespace.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The created identity document.\n\t */\n\tpublic async identityCreate(namespace?: string, controller?: string): Promise<IDidDocument> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByNamespace(namespace);\n\t\t\tconst result = await identityConnector.createDocument(controller);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"identityCreateFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Remove an identity.\n\t * @param identity The id of the document to remove.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t */\n\tpublic async identityRemove(identity: string, controller?: string): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(identity);\n\t\t\tconst result = await identityConnector.removeDocument(controller, identity);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"identityRemoveFailed\",\n\t\t\t\t{ identity },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Add a verification method to the document in JSON Web key Format.\n\t * @param identity The id of the document to add the verification method to.\n\t * @param verificationMethodType The type of the verification method to add.\n\t * @param verificationMethodId The id of the verification method, if undefined uses the kid of the generated JWK.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The verification method.\n\t * @throws NotFoundError if the id can not be resolved.\n\t * @throws NotSupportedError if the platform does not support multiple keys.\n\t */\n\tpublic async verificationMethodCreate(\n\t\tidentity: string,\n\t\tverificationMethodType: DidVerificationMethodType,\n\t\tverificationMethodId?: string,\n\t\tcontroller?: string\n\t): Promise<IDidDocumentVerificationMethod> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(identity), identity);\n\n\t\tGuards.arrayOneOf(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(verificationMethodType),\n\t\t\tverificationMethodType,\n\t\t\tObject.values(DidVerificationMethodType)\n\t\t);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(identity);\n\n\t\t\tconst verificationMethod = await identityConnector.addVerificationMethod(\n\t\t\t\tcontroller,\n\t\t\t\tidentity,\n\t\t\t\tverificationMethodType,\n\t\t\t\tverificationMethodId\n\t\t\t);\n\n\t\t\treturn verificationMethod;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verificationMethodCreateFailed\",\n\t\t\t\t{ identity },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove a verification method from the document.\n\t * @param verificationMethodId The id of the verification method.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t * @throws NotFoundError if the id can not be resolved.\n\t * @throws NotSupportedError if the platform does not support multiple revocable keys.\n\t */\n\tpublic async verificationMethodRemove(\n\t\tverificationMethodId: string,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(verificationMethodId), verificationMethodId);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tawait identityConnector.removeVerificationMethod(controller, verificationMethodId);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verificationMethodRemoveFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Add a service to the document.\n\t * @param identity The id of the document to add the service to.\n\t * @param serviceId The id of the service.\n\t * @param serviceType The type of the service.\n\t * @param serviceEndpoint The endpoint for the service.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The service.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async serviceCreate(\n\t\tidentity: string,\n\t\tserviceId: string,\n\t\tserviceType: string | string[],\n\t\tserviceEndpoint: string | string[],\n\t\tcontroller?: string\n\t): Promise<IDidService> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(serviceId), serviceId);\n\t\tif (Is.array(serviceType)) {\n\t\t\tGuards.arrayValue<string>(IdentityService.CLASS_NAME, nameof(serviceType), serviceType);\n\t\t} else {\n\t\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(serviceType), serviceType);\n\t\t}\n\t\tif (Is.array(serviceEndpoint)) {\n\t\t\tGuards.arrayValue<string>(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\tnameof(serviceEndpoint),\n\t\t\t\tserviceEndpoint\n\t\t\t);\n\t\t} else {\n\t\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(serviceEndpoint), serviceEndpoint);\n\t\t}\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(identity);\n\n\t\t\tconst service = await identityConnector.addService(\n\t\t\t\tcontroller,\n\t\t\t\tidentity,\n\t\t\t\tserviceId,\n\t\t\t\tserviceType,\n\t\t\t\tserviceEndpoint\n\t\t\t);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"serviceCreateFailed\",\n\t\t\t\t{ identity, serviceId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove a service from the document.\n\t * @param serviceId The id of the service.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async serviceRemove(serviceId: string, controller?: string): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(serviceId), serviceId);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(serviceId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tawait identityConnector.removeService(controller, serviceId);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"serviceRemoveFailed\",\n\t\t\t\t{ serviceId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a verifiable credential for a verification method.\n\t * @param verificationMethodId The verification method id to use.\n\t * @param id The id of the credential.\n\t * @param subject The credential subject to store in the verifiable credential.\n\t * @param options Additional options for creating the verifiable credential.\n\t * @param options.revocationIndex The bitmap revocation index of the credential, if undefined will not have revocation status.\n\t * @param options.expirationDate The date the verifiable credential is valid until.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The created verifiable credential and its token.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async verifiableCredentialCreate(\n\t\tverificationMethodId: string,\n\t\tid: string | undefined,\n\t\tsubject: IJsonLdNodeObject,\n\t\toptions?: {\n\t\t\trevocationIndex?: number;\n\t\t\texpirationDate?: Date;\n\t\t},\n\t\tcontroller?: string\n\t): Promise<{\n\t\tverifiableCredential: IDidVerifiableCredential;\n\t\tjwt: string;\n\t}> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(verificationMethodId), verificationMethodId);\n\t\tGuards.objectValue(IdentityService.CLASS_NAME, nameof(subject), subject);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst service = await identityConnector.createVerifiableCredential(\n\t\t\t\tcontroller,\n\t\t\t\tverificationMethodId,\n\t\t\t\tid,\n\t\t\t\tsubject,\n\t\t\t\toptions\n\t\t\t);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialCreateFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify a verifiable credential is valid.\n\t * @param credentialJwt The credential to verify.\n\t * @returns The credential stored in the jwt and the revocation status.\n\t */\n\tpublic async verifiableCredentialVerify(credentialJwt: string): Promise<{\n\t\trevoked: boolean;\n\t\tverifiableCredential?: IDidVerifiableCredential;\n\t}> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(credentialJwt), credentialJwt);\n\n\t\tconst jwtDecoded = await Jwt.decode(credentialJwt);\n\n\t\tconst jwtHeader = jwtDecoded.header;\n\t\tconst jwtPayload = jwtDecoded.payload;\n\t\tconst jwtSignature = jwtDecoded.signature;\n\n\t\tif (\n\t\t\tIs.undefined(jwtHeader) ||\n\t\t\tIs.undefined(jwtPayload) ||\n\t\t\tIs.undefined(jwtPayload.iss) ||\n\t\t\tIs.undefined(jwtSignature)\n\t\t) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"jwtDecodeFailed\");\n\t\t}\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(jwtPayload.iss);\n\n\t\t\tconst service = await identityConnector.checkVerifiableCredential(credentialJwt);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialVerifyFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Revoke verifiable credential.\n\t * @param issuerIdentity The id of the document to update the revocation list for.\n\t * @param credentialIndex The revocation bitmap index revoke.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t */\n\tpublic async verifiableCredentialRevoke(\n\t\tissuerIdentity: string,\n\t\tcredentialIndex: number,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(issuerIdentity), issuerIdentity);\n\t\tGuards.number(IdentityService.CLASS_NAME, nameof(credentialIndex), credentialIndex);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(issuerIdentity);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.revokeVerifiableCredentials(\n\t\t\t\tcontroller,\n\t\t\t\tissuerIdentity,\n\t\t\t\t[credentialIndex]\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialRevokeFailed\",\n\t\t\t\t{ issuerIdentity, credentialIndex },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Unrevoke verifiable credential.\n\t * @param issuerIdentity The id of the document to update the revocation list for.\n\t * @param credentialIndex The revocation bitmap index to un revoke.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns Nothing.\n\t */\n\tpublic async verifiableCredentialUnrevoke(\n\t\tissuerIdentity: string,\n\t\tcredentialIndex: number,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(issuerIdentity), issuerIdentity);\n\t\tGuards.number(IdentityService.CLASS_NAME, nameof(credentialIndex), credentialIndex);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(issuerIdentity);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.unrevokeVerifiableCredentials(\n\t\t\t\tcontroller,\n\t\t\t\tissuerIdentity,\n\t\t\t\t[credentialIndex]\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialUnrevokeFailed\",\n\t\t\t\t{ issuerIdentity, credentialIndex },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a verifiable presentation from the supplied verifiable credentials.\n\t * @param verificationMethodId The method to associate with the presentation.\n\t * @param presentationId The id of the presentation.\n\t * @param contexts The contexts for the data stored in the verifiable credential.\n\t * @param types The types for the data stored in the verifiable credential.\n\t * @param verifiableCredentials The credentials to use for creating the presentation in jwt format.\n\t * @param expiresInMinutes The time in minutes for the presentation to expire.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The created verifiable presentation and its token.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async verifiablePresentationCreate(\n\t\tverificationMethodId: string,\n\t\tpresentationId: string | undefined,\n\t\tcontexts: IJsonLdContextDefinitionRoot | undefined,\n\t\ttypes: string | string[] | undefined,\n\t\tverifiableCredentials: (string | IDidVerifiableCredential)[],\n\t\texpiresInMinutes?: number,\n\t\tcontroller?: string\n\t): Promise<{\n\t\tverifiablePresentation: IDidVerifiablePresentation;\n\t\tjwt: string;\n\t}> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(verificationMethodId),\n\t\t\tverificationMethodId\n\t\t);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.createVerifiablePresentation(\n\t\t\t\tcontroller,\n\t\t\t\tverificationMethodId,\n\t\t\t\tpresentationId,\n\t\t\t\tcontexts,\n\t\t\t\ttypes,\n\t\t\t\tverifiableCredentials,\n\t\t\t\texpiresInMinutes\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiablePresentationCreateFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify a verifiable presentation is valid.\n\t * @param presentationJwt The presentation to verify.\n\t * @returns The presentation stored in the jwt and the revocation status.\n\t */\n\tpublic async verifiablePresentationVerify(presentationJwt: string): Promise<{\n\t\trevoked: boolean;\n\t\tverifiablePresentation?: IDidVerifiablePresentation;\n\t\tissuers?: IDidDocument[];\n\t}> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(presentationJwt), presentationJwt);\n\n\t\tconst jwtDecoded = await Jwt.decode(presentationJwt);\n\n\t\tconst jwtHeader = jwtDecoded.header;\n\t\tconst jwtPayload = jwtDecoded.payload;\n\t\tconst jwtSignature = jwtDecoded.signature;\n\n\t\tif (\n\t\t\tIs.undefined(jwtHeader) ||\n\t\t\tIs.undefined(jwtPayload) ||\n\t\t\tIs.undefined(jwtPayload.iss) ||\n\t\t\tIs.undefined(jwtSignature)\n\t\t) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"jwtDecodeFailed\");\n\t\t}\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(jwtPayload.iss);\n\n\t\t\tconst service = await identityConnector.checkVerifiablePresentation(presentationJwt);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiablePresentationVerifyFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a proof for a document with the specified verification method.\n\t * @param verificationMethodId The verification method id to use.\n\t * @param proofType The type of proof to create.\n\t * @param unsecureDocument The unsecure document to create the proof for.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The proof.\n\t */\n\tpublic async proofCreate(\n\t\tverificationMethodId: string,\n\t\tproofType: ProofTypes,\n\t\tunsecureDocument: IJsonLdNodeObject,\n\t\tcontroller?: string\n\t): Promise<IProof> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(verificationMethodId),\n\t\t\tverificationMethodId\n\t\t);\n\t\tGuards.arrayOneOf<ProofTypes>(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(proofType),\n\t\t\tproofType,\n\t\t\tObject.values(ProofTypes)\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(unsecureDocument),\n\t\t\tunsecureDocument\n\t\t);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.createProof(\n\t\t\t\tcontroller,\n\t\t\t\tverificationMethodId,\n\t\t\t\tproofType,\n\t\t\t\tunsecureDocument\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"proofCreateFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify proof for a document with the specified verification method.\n\t * @param document The document to verify.\n\t * @param proof The proof to verify.\n\t * @returns True if the proof is verified.\n\t */\n\tpublic async proofVerify(document: IJsonLdNodeObject, proof: IProof): Promise<boolean> {\n\t\tGuards.object<IJsonLdNodeObject>(IdentityService.CLASS_NAME, nameof(document), document);\n\t\tGuards.object<IProof>(IdentityService.CLASS_NAME, nameof(proof), proof);\n\t\tGuards.stringValue(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(proof.verificationMethod),\n\t\t\tproof.verificationMethod\n\t\t);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(proof.verificationMethod);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.verifyProof(document, proof);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"proofVerifyFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get the connector from the namespace.\n\t * @param namespace The namespace for the identity.\n\t * @returns The connector.\n\t * @internal\n\t */\n\tprivate getConnectorByNamespace(namespace?: string): IIdentityConnector {\n\t\tconst namespaceMethod = namespace ?? this._defaultNamespace;\n\n\t\tconst connector = IdentityConnectorFactory.getIfExists<IIdentityConnector>(namespaceMethod);\n\n\t\tif (Is.empty(connector)) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"connectorNotFound\", {\n\t\t\t\tnamespace: namespaceMethod\n\t\t\t});\n\t\t}\n\n\t\treturn connector;\n\t}\n\n\t/**\n\t * Get the connector from the uri.\n\t * @param id The id of the identity in urn format.\n\t * @returns The connector.\n\t * @internal\n\t */\n\tprivate getConnectorByUri(id: string): IIdentityConnector {\n\t\tconst idUri = Urn.fromValidString(id);\n\n\t\tif (idUri.namespaceIdentifier() !== \"did\") {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: \"did\",\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\treturn this.getConnectorByNamespace(idUri.namespaceMethod());\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"identityService.js","sourceRoot":"","sources":["../../src/identityService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAEjF,OAAO,EACN,cAAc,EACd,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EAGf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACN,yBAAyB,EACzB,UAAU,EAOV,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,YAAY,EAA4B,MAAM,4BAA4B,CAAC;AACpF,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC;;GAEG;AACH,MAAM,OAAO,eAAe;IAC3B;;OAEG;IACI,MAAM,CAAU,UAAU,qBAAqC;IAEtE;;;OAGG;IACc,iBAAiB,CAAS;IAE3C;;;OAGG;IACc,mBAAmB,CAAuB;IAE3D;;;;OAIG;IACH,YAAY,OAA4C;QACvD,MAAM,KAAK,GAAG,wBAAwB,CAAC,KA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C,QAAQ,EAAE,KAAK,CAAC,CAAC;YACpE,OAAO,MAAM,CAAC;QACf,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,YAAY,CAAC,eAAe,CAAC,UAAU,EAAE,mBAAmB,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAC3F,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACK,uBAAuB,CAAC,SAAkB;QACjD,MAAM,eAAe,GAAG,SAAS,IAAI,IAAI,CAAC,iBAAiB,CAAC;QAE5D,MAAM,SAAS,GAAG,wBAAwB,CAAC,WAAW,CAAqB,eAAe,CAAC,CAAC;QAE5F,IAAI,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,YAAY,CAAC,eAAe,CAAC,UAAU,EAAE,mBAAmB,EAAE;gBACvE,SAAS,EAAE,eAAe;aAC1B,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;;;OAMG;IACK,iBAAiB,CAAC,EAAU;QACnC,MAAM,KAAK,GAAG,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QAEtC,IAAI,KAAK,CAAC,mBAAmB,EAAE,KAAK,KAAK,EAAE,CAAC;YAC3C,MAAM,IAAI,YAAY,CAAC,eAAe,CAAC,UAAU,EAAE,mBAAmB,EAAE;gBACvE,SAAS,EAAE,KAAK;gBAChB,EAAE;aACF,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC;IAC9D,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ComponentFactory, GeneralError, Guards, Is, Urn } from \"@twin.org/core\";\nimport type { IJsonLdContextDefinitionRoot, IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport {\n\tDocumentHelper,\n\tIdentityConnectorFactory,\n\tIdentityMetricIds,\n\tIdentityMetrics,\n\ttype IIdentityComponent,\n\ttype IIdentityConnector\n} from \"@twin.org/identity-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tDidVerificationMethodType,\n\tProofTypes,\n\ttype IDidDocument,\n\ttype IDidDocumentVerificationMethod,\n\ttype IProof,\n\ttype IDidService,\n\ttype IDidVerifiableCredential,\n\ttype IDidVerifiablePresentation\n} from \"@twin.org/standards-w3c-did\";\nimport { MetricHelper, type ITelemetryComponent } from \"@twin.org/telemetry-models\";\nimport { Jwt } from \"@twin.org/web\";\nimport type { IIdentityServiceConstructorOptions } from \"./models/IIdentityServiceConstructorOptions.js\";\n\n/**\n * Class which implements the identity contract.\n */\nexport class IdentityService implements IIdentityComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<IdentityService>();\n\n\t/**\n\t * The default namespace for the connector to use.\n\t * @internal\n\t */\n\tprivate readonly _defaultNamespace: string;\n\n\t/**\n\t * The telemetry component.\n\t * @internal\n\t */\n\tprivate readonly _telemetryComponent?: ITelemetryComponent;\n\n\t/**\n\t * Create a new instance of IdentityService.\n\t * @param options The options for the service.\n\t * @throws GeneralError if no connectors are registered.\n\t */\n\tconstructor(options?: IIdentityServiceConstructorOptions) {\n\t\tconst names = IdentityConnectorFactory.names();\n\t\tif (names.length === 0) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"noConnectors\");\n\t\t}\n\n\t\tthis._defaultNamespace = options?.config?.defaultNamespace ?? names[0];\n\n\t\tthis._telemetryComponent = ComponentFactory.getIfExists<ITelemetryComponent>(\n\t\t\toptions?.telemetryComponentType\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn IdentityService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Register all identity metrics with the telemetry component.\n\t * @returns A promise that resolves when all metrics have been registered.\n\t */\n\tpublic async start(): Promise<void> {\n\t\tif (Is.undefined(this._telemetryComponent)) {\n\t\t\treturn;\n\t\t}\n\n\t\tawait MetricHelper.createMetrics(this._telemetryComponent, IdentityMetrics);\n\t}\n\n\t/**\n\t * Create a new identity.\n\t * @param namespace The namespace of the connector to use for the identity, defaults to service configured namespace.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The created identity document.\n\t */\n\tpublic async identityCreate(namespace?: string, controller?: string): Promise<IDidDocument> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByNamespace(namespace);\n\t\t\tconst result = await identityConnector.createDocument(controller);\n\t\t\tawait MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.DidsCreated, {\n\t\t\t\tnamespace: namespace ?? this._defaultNamespace\n\t\t\t});\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"identityCreateFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Remove an identity.\n\t * @param identity The id of the document to remove.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns A promise that resolves when the identity has been removed.\n\t */\n\tpublic async identityRemove(identity: string, controller?: string): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(identity);\n\t\t\tconst result = await identityConnector.removeDocument(controller, identity);\n\t\t\tawait MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.DidsRemoved);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"identityRemoveFailed\",\n\t\t\t\t{ identity },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Add a verification method to the document in JSON Web key Format.\n\t * @param identity The id of the document to add the verification method to.\n\t * @param verificationMethodType The type of the verification method to add.\n\t * @param verificationMethodId The id of the verification method, if undefined uses the kid of the generated JWK.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The verification method.\n\t * @throws NotFoundError if the id can not be resolved.\n\t * @throws NotSupportedError if the platform does not support multiple keys.\n\t */\n\tpublic async verificationMethodCreate(\n\t\tidentity: string,\n\t\tverificationMethodType: DidVerificationMethodType,\n\t\tverificationMethodId?: string,\n\t\tcontroller?: string\n\t): Promise<IDidDocumentVerificationMethod> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(identity), identity);\n\n\t\tGuards.arrayOneOf(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(verificationMethodType),\n\t\t\tverificationMethodType,\n\t\t\tObject.values(DidVerificationMethodType)\n\t\t);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(identity);\n\n\t\t\tconst verificationMethod = await identityConnector.addVerificationMethod(\n\t\t\t\tcontroller,\n\t\t\t\tidentity,\n\t\t\t\tverificationMethodType,\n\t\t\t\tverificationMethodId\n\t\t\t);\n\n\t\t\treturn verificationMethod;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verificationMethodCreateFailed\",\n\t\t\t\t{ identity },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove a verification method from the document.\n\t * @param verificationMethodId The id of the verification method.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns A promise that resolves when the verification method has been removed.\n\t * @throws NotFoundError if the id can not be resolved.\n\t * @throws NotSupportedError if the platform does not support multiple revocable keys.\n\t */\n\tpublic async verificationMethodRemove(\n\t\tverificationMethodId: string,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(verificationMethodId), verificationMethodId);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tawait identityConnector.removeVerificationMethod(controller, verificationMethodId);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verificationMethodRemoveFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Add a service to the document.\n\t * @param identity The id of the document to add the service to.\n\t * @param serviceId The id of the service.\n\t * @param serviceType The type of the service.\n\t * @param serviceEndpoint The endpoint for the service.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The service.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async serviceCreate(\n\t\tidentity: string,\n\t\tserviceId: string,\n\t\tserviceType: string | string[],\n\t\tserviceEndpoint: string | string[],\n\t\tcontroller?: string\n\t): Promise<IDidService> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(identity), identity);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(serviceId), serviceId);\n\t\tif (Is.array(serviceType)) {\n\t\t\tGuards.arrayValue<string>(IdentityService.CLASS_NAME, nameof(serviceType), serviceType);\n\t\t} else {\n\t\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(serviceType), serviceType);\n\t\t}\n\t\tif (Is.array(serviceEndpoint)) {\n\t\t\tGuards.arrayValue<string>(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\tnameof(serviceEndpoint),\n\t\t\t\tserviceEndpoint\n\t\t\t);\n\t\t} else {\n\t\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(serviceEndpoint), serviceEndpoint);\n\t\t}\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(identity);\n\n\t\t\tconst service = await identityConnector.addService(\n\t\t\t\tcontroller,\n\t\t\t\tidentity,\n\t\t\t\tserviceId,\n\t\t\t\tserviceType,\n\t\t\t\tserviceEndpoint\n\t\t\t);\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"serviceCreateFailed\",\n\t\t\t\t{ identity, serviceId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove a service from the document.\n\t * @param serviceId The id of the service.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns A promise that resolves when the service has been removed.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async serviceRemove(serviceId: string, controller?: string): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(serviceId), serviceId);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(serviceId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tawait identityConnector.removeService(controller, serviceId);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"serviceRemoveFailed\",\n\t\t\t\t{ serviceId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Add an alias to the alsoKnownAs property on the document.\n\t * If the alias is already present the operation is a no-op.\n\t * @param documentId The id of the document to update.\n\t * @param alias The alias to add. Must be a Url or Urn (typically another DID).\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns A promise that resolves when the alias has been added.\n\t * @throws GeneralError if the alias is not a Url or Urn.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async alsoKnownAsAdd(\n\t\tdocumentId: string,\n\t\talias: string,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(documentId), documentId);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(alias), alias);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(documentId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tawait identityConnector.addAlsoKnownAs(controller, documentId, alias);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"alsoKnownAsAddFailed\",\n\t\t\t\t{ identity: documentId, alias },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Remove an alias from the alsoKnownAs property on the document.\n\t * If the alias is not present the operation is a no-op.\n\t * @param documentId The id of the document to update.\n\t * @param alias The alias to remove. Must be a Url or Urn.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns A promise that resolves when the alias has been removed.\n\t * @throws GeneralError if the alias is not a Url or Urn.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async alsoKnownAsRemove(\n\t\tdocumentId: string,\n\t\talias: string,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(documentId), documentId);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(alias), alias);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(documentId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tawait identityConnector.removeAlsoKnownAs(controller, documentId, alias);\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"alsoKnownAsRemoveFailed\",\n\t\t\t\t{ identity: documentId, alias },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a verifiable credential for a verification method.\n\t * @param verificationMethodId The verification method id to use.\n\t * @param id The id of the credential.\n\t * @param subject The credential subject to store in the verifiable credential.\n\t * @param options Additional options for creating the verifiable credential.\n\t * @param options.revocationIndex The bitmap revocation index of the credential, if undefined will not have revocation status.\n\t * @param options.expirationDate The date the verifiable credential is valid until.\n\t * @param options.jwtHeaderFields Additional fields to include in the JWT header when creating the verifiable credential in jwt format.\n\t * @param options.jwtPayloadFields Additional fields to include in the JWT payload when creating the verifiable credential in jwt format.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The created verifiable credential and its token.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async verifiableCredentialCreate(\n\t\tverificationMethodId: string,\n\t\tid: string | undefined,\n\t\tsubject: IJsonLdNodeObject,\n\t\toptions?: {\n\t\t\trevocationIndex?: number;\n\t\t\texpirationDate?: Date;\n\t\t\tjwtHeaderFields?: { [id: string]: string };\n\t\t\tjwtPayloadFields?: { [id: string]: string };\n\t\t},\n\t\tcontroller?: string\n\t): Promise<{\n\t\tverifiableCredential: IDidVerifiableCredential;\n\t\tjwt: string;\n\t}> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tUrn.guard(IdentityService.CLASS_NAME, nameof(verificationMethodId), verificationMethodId);\n\t\tGuards.object(IdentityService.CLASS_NAME, nameof(subject), subject);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst service = await identityConnector.createVerifiableCredential(\n\t\t\t\tcontroller,\n\t\t\t\tverificationMethodId,\n\t\t\t\tid,\n\t\t\t\tsubject,\n\t\t\t\toptions\n\t\t\t);\n\n\t\t\tawait MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VcsCreated, {\n\t\t\t\thasRevocation: Is.number(options?.revocationIndex),\n\t\t\t\thasExpiration: Is.date(options?.expirationDate)\n\t\t\t});\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialCreateFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify a verifiable credential is valid.\n\t * @param credential The credential to verify.\n\t * @returns The credential stored in the jwt and the revocation status.\n\t */\n\tpublic async verifiableCredentialVerify(credential: string | IDidVerifiableCredential): Promise<{\n\t\trevoked: boolean;\n\t\tverifiableCredential?: IDidVerifiableCredential;\n\t}> {\n\t\tif (Is.object(credential)) {\n\t\t\tGuards.objectValue<IDidVerifiableCredential>(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\tnameof(credential),\n\t\t\t\tcredential\n\t\t\t);\n\t\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(credential.issuer), credential.issuer);\n\t\t\tGuards.objectValue<IDidVerifiableCredential>(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\tnameof(credential.proof),\n\t\t\t\tcredential.proof\n\t\t\t);\n\n\t\t\ttry {\n\t\t\t\tconst identityConnector = this.getConnectorByUri(credential.issuer);\n\n\t\t\t\tconst service = await identityConnector.checkVerifiableCredential(credential);\n\n\t\t\t\tif (service.revoked) {\n\t\t\t\t\tawait MetricHelper.metricIncrement(\n\t\t\t\t\t\tthis._telemetryComponent,\n\t\t\t\t\t\tIdentityMetricIds.VcsVerificationFailed,\n\t\t\t\t\t\t{ failureReason: \"revoked\" }\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tawait MetricHelper.metricIncrement(\n\t\t\t\t\t\tthis._telemetryComponent,\n\t\t\t\t\t\tIdentityMetricIds.VcsVerified\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn service;\n\t\t\t} catch (error) {\n\t\t\t\tthrow new GeneralError(\n\t\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\t\"verifiableCredentialVerifyFailed\",\n\t\t\t\t\tundefined,\n\t\t\t\t\terror\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(credential), credential);\n\n\t\tconst jwtDecoded = await Jwt.decode(credential);\n\n\t\tconst jwtHeader = jwtDecoded.header;\n\t\tconst jwtPayload = jwtDecoded.payload;\n\t\tconst jwtSignature = jwtDecoded.signature;\n\n\t\tif (\n\t\t\tIs.undefined(jwtHeader) ||\n\t\t\tIs.undefined(jwtPayload) ||\n\t\t\tIs.undefined(jwtPayload.iss) ||\n\t\t\tIs.undefined(jwtSignature)\n\t\t) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"jwtDecodeFailed\");\n\t\t}\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(jwtPayload.iss);\n\n\t\t\tconst service = await identityConnector.checkVerifiableCredential(credential);\n\n\t\t\tif (service.revoked) {\n\t\t\t\tawait MetricHelper.metricIncrement(\n\t\t\t\t\tthis._telemetryComponent,\n\t\t\t\t\tIdentityMetricIds.VcsVerificationFailed,\n\t\t\t\t\t{ failureReason: \"revoked\" }\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tawait MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VcsVerified);\n\t\t\t}\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialVerifyFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Revoke verifiable credential.\n\t * @param issuerIdentity The id of the document to update the revocation list for.\n\t * @param credentialIndex The revocation bitmap index to revoke.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns A promise that resolves when the credential has been revoked.\n\t */\n\tpublic async verifiableCredentialRevoke(\n\t\tissuerIdentity: string,\n\t\tcredentialIndex: number,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(issuerIdentity), issuerIdentity);\n\t\tGuards.number(IdentityService.CLASS_NAME, nameof(credentialIndex), credentialIndex);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(issuerIdentity);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.revokeVerifiableCredentials(\n\t\t\t\tcontroller,\n\t\t\t\tissuerIdentity,\n\t\t\t\t[credentialIndex]\n\t\t\t);\n\n\t\t\tawait MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VcsRevoked);\n\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialRevokeFailed\",\n\t\t\t\t{ issuerIdentity, credentialIndex },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Unrevoke verifiable credential.\n\t * @param issuerIdentity The id of the document to update the revocation list for.\n\t * @param credentialIndex The revocation bitmap index to un revoke.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns A promise that resolves when the credential has been unrevoked.\n\t */\n\tpublic async verifiableCredentialUnrevoke(\n\t\tissuerIdentity: string,\n\t\tcredentialIndex: number,\n\t\tcontroller?: string\n\t): Promise<void> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(issuerIdentity), issuerIdentity);\n\t\tGuards.number(IdentityService.CLASS_NAME, nameof(credentialIndex), credentialIndex);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(issuerIdentity);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.unrevokeVerifiableCredentials(\n\t\t\t\tcontroller,\n\t\t\t\tissuerIdentity,\n\t\t\t\t[credentialIndex]\n\t\t\t);\n\n\t\t\tawait MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VcsUnrevoked);\n\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiableCredentialUnrevokeFailed\",\n\t\t\t\t{ issuerIdentity, credentialIndex },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a verifiable presentation from the supplied verifiable credentials.\n\t * @param verificationMethodId The method to associate with the presentation.\n\t * @param presentationId The id of the presentation.\n\t * @param contexts The contexts for the data stored in the verifiable credential.\n\t * @param types The types for the data stored in the verifiable credential.\n\t * @param verifiableCredentials The credentials to use for creating the presentation in jwt format.\n\t * @param options Additional options for creating the verifiable presentation.\n\t * @param options.expirationDate The date the verifiable presentation is valid until.\n\t * @param options.jwtHeaderFields Additional fields to include in the JWT header when creating the verifiable presentation in jwt format.\n\t * @param options.jwtPayloadFields\tAdditional fields to include in the JWT payload when creating the verifiable presentation in jwt format.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The created verifiable presentation and its token.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async verifiablePresentationCreate(\n\t\tverificationMethodId: string,\n\t\tpresentationId: string | undefined,\n\t\tcontexts: IJsonLdContextDefinitionRoot | undefined,\n\t\ttypes: string | string[] | undefined,\n\t\tverifiableCredentials: (string | IDidVerifiableCredential)[],\n\t\toptions?: {\n\t\t\texpirationDate?: Date;\n\t\t\tjwtHeaderFields?: { [id: string]: string };\n\t\t\tjwtPayloadFields?: { [id: string]: string };\n\t\t},\n\t\tcontroller?: string\n\t): Promise<{\n\t\tverifiablePresentation: IDidVerifiablePresentation;\n\t\tjwt: string;\n\t}> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(verificationMethodId),\n\t\t\tverificationMethodId\n\t\t);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.createVerifiablePresentation(\n\t\t\t\tcontroller,\n\t\t\t\tverificationMethodId,\n\t\t\t\tpresentationId,\n\t\t\t\tcontexts,\n\t\t\t\ttypes,\n\t\t\t\tverifiableCredentials,\n\t\t\t\toptions\n\t\t\t);\n\n\t\t\tawait MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VpsCreated, {\n\t\t\t\tcredentialCount: verifiableCredentials.length\n\t\t\t});\n\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiablePresentationCreateFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify a verifiable presentation is valid.\n\t * @param presentation The presentation to verify.\n\t * @returns The presentation stored in the jwt and the revocation status.\n\t */\n\tpublic async verifiablePresentationVerify(\n\t\tpresentation: string | IDidVerifiablePresentation\n\t): Promise<{\n\t\trevoked: boolean;\n\t\tverifiablePresentation?: IDidVerifiablePresentation;\n\t\tissuers?: IDidDocument[];\n\t}> {\n\t\tlet holder;\n\t\tif (Is.stringValue(presentation)) {\n\t\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(presentation), presentation);\n\n\t\t\tconst jwtDecoded = await Jwt.decode(presentation);\n\n\t\t\tconst jwtHeader = jwtDecoded.header;\n\t\t\tconst jwtPayload = jwtDecoded.payload;\n\t\t\tconst jwtSignature = jwtDecoded.signature;\n\n\t\t\tif (\n\t\t\t\tIs.undefined(jwtHeader) ||\n\t\t\t\tIs.undefined(jwtPayload) ||\n\t\t\t\tIs.undefined(jwtPayload.iss) ||\n\t\t\t\tIs.undefined(jwtSignature)\n\t\t\t) {\n\t\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"jwtDecodeFailed\");\n\t\t\t}\n\n\t\t\tholder = jwtPayload.iss;\n\t\t} else {\n\t\t\tholder = presentation.holder;\n\t\t}\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(holder), holder);\n\n\t\ttry {\n\t\t\tconst identityConnector = this.getConnectorByUri(holder);\n\n\t\t\tconst service = await identityConnector.checkVerifiablePresentation(presentation);\n\n\t\t\tif (service.revoked) {\n\t\t\t\tawait MetricHelper.metricIncrement(\n\t\t\t\t\tthis._telemetryComponent,\n\t\t\t\t\tIdentityMetricIds.VpsVerificationFailed,\n\t\t\t\t\t{ failureReason: \"revoked\" }\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tawait MetricHelper.metricIncrement(this._telemetryComponent, IdentityMetricIds.VpsVerified);\n\t\t\t}\n\n\t\t\treturn service;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"verifiablePresentationVerifyFailed\",\n\t\t\t\tundefined,\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Create a proof for a document with the specified verification method.\n\t * @param verificationMethodId The verification method id to use.\n\t * @param proofType The type of proof to create.\n\t * @param unsecureDocument The unsecure document to create the proof for.\n\t * @param controller The controller of the identity who can make changes.\n\t * @returns The proof.\n\t */\n\tpublic async proofCreate(\n\t\tverificationMethodId: string,\n\t\tproofType: ProofTypes,\n\t\tunsecureDocument: IJsonLdNodeObject,\n\t\tcontroller?: string\n\t): Promise<IProof> {\n\t\tGuards.stringValue(IdentityService.CLASS_NAME, nameof(controller), controller);\n\t\tGuards.stringValue(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(verificationMethodId),\n\t\t\tverificationMethodId\n\t\t);\n\t\tGuards.arrayOneOf<ProofTypes>(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(proofType),\n\t\t\tproofType,\n\t\t\tObject.values(ProofTypes)\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(unsecureDocument),\n\t\t\tunsecureDocument\n\t\t);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(verificationMethodId);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.createProof(\n\t\t\t\tcontroller,\n\t\t\t\tverificationMethodId,\n\t\t\t\tproofType,\n\t\t\t\tunsecureDocument\n\t\t\t);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tIdentityService.CLASS_NAME,\n\t\t\t\t\"proofCreateFailed\",\n\t\t\t\t{ verificationMethodId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Verify proof for a document with the specified verification method.\n\t * @param document The document to verify.\n\t * @param proof The proof to verify.\n\t * @returns True if the proof is verified.\n\t */\n\tpublic async proofVerify(document: IJsonLdNodeObject, proof: IProof): Promise<boolean> {\n\t\tGuards.object<IJsonLdNodeObject>(IdentityService.CLASS_NAME, nameof(document), document);\n\t\tGuards.object<IProof>(IdentityService.CLASS_NAME, nameof(proof), proof);\n\t\tGuards.stringValue(\n\t\t\tIdentityService.CLASS_NAME,\n\t\t\tnameof(proof.verificationMethod),\n\t\t\tproof.verificationMethod\n\t\t);\n\n\t\ttry {\n\t\t\tconst idParts = DocumentHelper.parseId(proof.verificationMethod);\n\n\t\t\tconst identityConnector = this.getConnectorByUri(idParts.id);\n\n\t\t\tconst result = await identityConnector.verifyProof(document, proof);\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"proofVerifyFailed\", undefined, error);\n\t\t}\n\t}\n\n\t/**\n\t * Get the connector from the namespace.\n\t * @param namespace The namespace for the identity.\n\t * @returns The connector.\n\t * @throws GeneralError if the connector is not found.\n\t * @internal\n\t */\n\tprivate getConnectorByNamespace(namespace?: string): IIdentityConnector {\n\t\tconst namespaceMethod = namespace ?? this._defaultNamespace;\n\n\t\tconst connector = IdentityConnectorFactory.getIfExists<IIdentityConnector>(namespaceMethod);\n\n\t\tif (Is.empty(connector)) {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"connectorNotFound\", {\n\t\t\t\tnamespace: namespaceMethod\n\t\t\t});\n\t\t}\n\n\t\treturn connector;\n\t}\n\n\t/**\n\t * Get the connector from the uri.\n\t * @param id The id of the identity in urn format.\n\t * @returns The connector.\n\t * @throws GeneralError if the namespace does not match or the connector is not found.\n\t * @internal\n\t */\n\tprivate getConnectorByUri(id: string): IIdentityConnector {\n\t\tconst idUri = Urn.fromValidString(id);\n\n\t\tif (idUri.namespaceIdentifier() !== \"did\") {\n\t\t\tthrow new GeneralError(IdentityService.CLASS_NAME, \"namespaceMismatch\", {\n\t\t\t\tnamespace: \"did\",\n\t\t\t\tid\n\t\t\t});\n\t\t}\n\n\t\treturn this.getConnectorByNamespace(idUri.namespaceMethod());\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IIdentityResolverServiceConfig.js","sourceRoot":"","sources":["../../../src/models/IIdentityResolverServiceConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the Identity Resolver Service.\n */\nexport interface IIdentityResolverServiceConfig {\n\t/**\n\t *
|
|
1
|
+
{"version":3,"file":"IIdentityResolverServiceConfig.js","sourceRoot":"","sources":["../../../src/models/IIdentityResolverServiceConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the Identity Resolver Service.\n */\nexport interface IIdentityResolverServiceConfig {\n\t/**\n\t * The default connector namespace to use for identity resolution. If not provided, the first registered connector is used.\n\t */\n\tdefaultNamespace?: string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IIdentityServiceConfig.js","sourceRoot":"","sources":["../../../src/models/IIdentityServiceConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the Identity Service.\n */\nexport interface IIdentityServiceConfig {\n\t/**\n\t *
|
|
1
|
+
{"version":3,"file":"IIdentityServiceConfig.js","sourceRoot":"","sources":["../../../src/models/IIdentityServiceConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the Identity Service.\n */\nexport interface IIdentityServiceConfig {\n\t/**\n\t * The default connector namespace to use for identity operations. If not provided, the first registered connector is used.\n\t */\n\tdefaultNamespace?: string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IIdentityServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IIdentityServiceConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IIdentityServiceConfig } from \"./IIdentityServiceConfig.js\";\n\n/**\n * Options for the identity service constructor.\n */\nexport interface IIdentityServiceConstructorOptions {\n\t/**\n\t * The configuration for the identity service.\n\t */\n\tconfig?: IIdentityServiceConfig;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"IIdentityServiceConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IIdentityServiceConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IIdentityServiceConfig } from \"./IIdentityServiceConfig.js\";\n\n/**\n * Options for the identity service constructor.\n */\nexport interface IIdentityServiceConstructorOptions {\n\t/**\n\t * The configuration for the identity service.\n\t */\n\tconfig?: IIdentityServiceConfig;\n\n\t/**\n\t * The component type for the optional telemetry component used for event metrics.\n\t */\n\ttelemetryComponentType?: string;\n}\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { generateRestRoutesIdentityProfile, tagsIdentityProfile } from "./identityProfileRoutes.js";
|
|
2
2
|
import { generateRestRoutesIdentityResolver, tagsIdentityResolver } from "./identityResolverRoutes.js";
|
|
3
3
|
import { generateRestRoutesIdentity, tagsIdentity } from "./identityRoutes.js";
|
|
4
|
+
/**
|
|
5
|
+
* REST entry points for the identity, identity resolver, and identity profile services.
|
|
6
|
+
*/
|
|
4
7
|
export const restEntryPoints = [
|
|
5
8
|
{
|
|
6
9
|
name: "identityResolver",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restEntryPoints.js","sourceRoot":"","sources":["../../src/restEntryPoints.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iCAAiC,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACpG,OAAO,EACN,kCAAkC,EAClC,oBAAoB,EACpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE/E,MAAM,CAAC,MAAM,eAAe,GAA2B;IACtD;QACC,IAAI,EAAE,kBAAkB;QACxB,gBAAgB,EAAE,UAAU;QAC5B,IAAI,EAAE,oBAAoB;QAC1B,cAAc,EAAE,kCAAkC;KAClD;IACD;QACC,IAAI,EAAE,UAAU;QAChB,gBAAgB,EAAE,UAAU;QAC5B,IAAI,EAAE,YAAY;QAClB,cAAc,EAAE,0BAA0B;KAC1C;IACD;QACC,IAAI,EAAE,iBAAiB;QACvB,gBAAgB,EAAE,kBAAkB;QACpC,IAAI,EAAE,mBAAmB;QACzB,cAAc,EAAE,iCAAiC;KACjD;CACD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IRestRouteEntryPoint } from \"@twin.org/api-models\";\nimport { generateRestRoutesIdentityProfile, tagsIdentityProfile } from \"./identityProfileRoutes.js\";\nimport {\n\tgenerateRestRoutesIdentityResolver,\n\ttagsIdentityResolver\n} from \"./identityResolverRoutes.js\";\nimport { generateRestRoutesIdentity, tagsIdentity } from \"./identityRoutes.js\";\n\nexport const restEntryPoints: IRestRouteEntryPoint[] = [\n\t{\n\t\tname: \"identityResolver\",\n\t\tdefaultBaseRoute: \"identity\",\n\t\ttags: tagsIdentityResolver,\n\t\tgenerateRoutes: generateRestRoutesIdentityResolver\n\t},\n\t{\n\t\tname: \"identity\",\n\t\tdefaultBaseRoute: \"identity\",\n\t\ttags: tagsIdentity,\n\t\tgenerateRoutes: generateRestRoutesIdentity\n\t},\n\t{\n\t\tname: \"identityProfile\",\n\t\tdefaultBaseRoute: \"identity/profile\",\n\t\ttags: tagsIdentityProfile,\n\t\tgenerateRoutes: generateRestRoutesIdentityProfile\n\t}\n];\n"]}
|
|
1
|
+
{"version":3,"file":"restEntryPoints.js","sourceRoot":"","sources":["../../src/restEntryPoints.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iCAAiC,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACpG,OAAO,EACN,kCAAkC,EAClC,oBAAoB,EACpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,0BAA0B,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAA2B;IACtD;QACC,IAAI,EAAE,kBAAkB;QACxB,gBAAgB,EAAE,UAAU;QAC5B,IAAI,EAAE,oBAAoB;QAC1B,cAAc,EAAE,kCAAkC;KAClD;IACD;QACC,IAAI,EAAE,UAAU;QAChB,gBAAgB,EAAE,UAAU;QAC5B,IAAI,EAAE,YAAY;QAClB,cAAc,EAAE,0BAA0B;KAC1C;IACD;QACC,IAAI,EAAE,iBAAiB;QACvB,gBAAgB,EAAE,kBAAkB;QACpC,IAAI,EAAE,mBAAmB;QACzB,cAAc,EAAE,iCAAiC;KACjD;CACD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IRestRouteEntryPoint } from \"@twin.org/api-models\";\nimport { generateRestRoutesIdentityProfile, tagsIdentityProfile } from \"./identityProfileRoutes.js\";\nimport {\n\tgenerateRestRoutesIdentityResolver,\n\ttagsIdentityResolver\n} from \"./identityResolverRoutes.js\";\nimport { generateRestRoutesIdentity, tagsIdentity } from \"./identityRoutes.js\";\n\n/**\n * REST entry points for the identity, identity resolver, and identity profile services.\n */\nexport const restEntryPoints: IRestRouteEntryPoint[] = [\n\t{\n\t\tname: \"identityResolver\",\n\t\tdefaultBaseRoute: \"identity\",\n\t\ttags: tagsIdentityResolver,\n\t\tgenerateRoutes: generateRestRoutesIdentityResolver\n\t},\n\t{\n\t\tname: \"identity\",\n\t\tdefaultBaseRoute: \"identity\",\n\t\ttags: tagsIdentity,\n\t\tgenerateRoutes: generateRestRoutesIdentity\n\t},\n\t{\n\t\tname: \"identityProfile\",\n\t\tdefaultBaseRoute: \"identity/profile\",\n\t\ttags: tagsIdentityProfile,\n\t\tgenerateRoutes: generateRestRoutesIdentityProfile\n\t}\n];\n"]}
|
|
@@ -24,7 +24,7 @@ export declare class IdentityProfileService<T extends IJsonLdDocument = IJsonLdD
|
|
|
24
24
|
* @param publicProfile The public profile data as JSON-LD.
|
|
25
25
|
* @param privateProfile The private profile data as JSON-LD.
|
|
26
26
|
* @param identity The identity to perform the profile operation on.
|
|
27
|
-
* @returns
|
|
27
|
+
* @returns A promise that resolves when the profile has been created.
|
|
28
28
|
*/
|
|
29
29
|
create(publicProfile?: T, privateProfile?: U, identity?: string): Promise<void>;
|
|
30
30
|
/**
|
|
@@ -51,13 +51,13 @@ export declare class IdentityProfileService<T extends IJsonLdDocument = IJsonLdD
|
|
|
51
51
|
* @param publicProfile The public profile data as JSON-LD.
|
|
52
52
|
* @param privateProfile The private profile data as JSON-LD.
|
|
53
53
|
* @param identity The identity to perform the profile operation on.
|
|
54
|
-
* @returns
|
|
54
|
+
* @returns A promise that resolves when the profile has been updated.
|
|
55
55
|
*/
|
|
56
56
|
update(publicProfile?: T, privateProfile?: U, identity?: string): Promise<void>;
|
|
57
57
|
/**
|
|
58
58
|
* Delete the profile for an identity.
|
|
59
59
|
* @param identity The identity to perform the profile operation on.
|
|
60
|
-
* @returns
|
|
60
|
+
* @returns A promise that resolves when the profile has been removed.
|
|
61
61
|
*/
|
|
62
62
|
remove(identity?: string): Promise<void>;
|
|
63
63
|
/**
|
|
@@ -5,7 +5,7 @@ import type { IIdentityResolveRequest, IIdentityResolveResponse } from "@twin.or
|
|
|
5
5
|
*/
|
|
6
6
|
export declare const tagsIdentityResolver: ITag[];
|
|
7
7
|
/**
|
|
8
|
-
* The REST routes for identity.
|
|
8
|
+
* The REST routes for identity resolution.
|
|
9
9
|
* @param baseRouteName Prefix to prepend to the paths.
|
|
10
10
|
* @param componentName The name of the component to use in the routes stored in the ComponentFactory.
|
|
11
11
|
* @returns The generated routes.
|
|
@@ -12,6 +12,7 @@ export declare class IdentityResolverService implements IIdentityResolverCompone
|
|
|
12
12
|
/**
|
|
13
13
|
* Create a new instance of IdentityResolverService.
|
|
14
14
|
* @param options The options for the service.
|
|
15
|
+
* @throws GeneralError if no connectors are registered.
|
|
15
16
|
*/
|
|
16
17
|
constructor(options?: IIdentityResolverServiceConstructorOptions);
|
|
17
18
|
/**
|