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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/es/contextIdHandlers/didContextIdHandler.js +34 -0
  2. package/dist/es/contextIdHandlers/didContextIdHandler.js.map +1 -0
  3. package/dist/es/factories/identityConnectorFactory.js +9 -0
  4. package/dist/es/factories/identityConnectorFactory.js.map +1 -0
  5. package/dist/es/factories/identityProfileConnectorFactory.js +9 -0
  6. package/dist/es/factories/identityProfileConnectorFactory.js.map +1 -0
  7. package/dist/es/factories/identityResolverConnectorFactory.js +9 -0
  8. package/dist/es/factories/identityResolverConnectorFactory.js.map +1 -0
  9. package/dist/es/index.js +49 -0
  10. package/dist/es/index.js.map +1 -0
  11. package/dist/es/models/IIdentityComponent.js +2 -0
  12. package/dist/es/models/IIdentityComponent.js.map +1 -0
  13. package/dist/es/models/IIdentityConnector.js +2 -0
  14. package/dist/es/models/IIdentityConnector.js.map +1 -0
  15. package/dist/es/models/IIdentityProfileComponent.js +2 -0
  16. package/dist/es/models/IIdentityProfileComponent.js.map +1 -0
  17. package/dist/es/models/IIdentityProfileConnector.js +2 -0
  18. package/dist/es/models/IIdentityProfileConnector.js.map +1 -0
  19. package/dist/es/models/IIdentityResolverComponent.js +2 -0
  20. package/dist/es/models/IIdentityResolverComponent.js.map +1 -0
  21. package/dist/es/models/IIdentityResolverConnector.js +2 -0
  22. package/dist/es/models/IIdentityResolverConnector.js.map +1 -0
  23. package/dist/es/models/api/identity/IIdentityCreateRequest.js +4 -0
  24. package/dist/es/models/api/identity/IIdentityCreateRequest.js.map +1 -0
  25. package/dist/es/models/api/identity/IIdentityCreateResponse.js +2 -0
  26. package/dist/es/models/api/identity/IIdentityCreateResponse.js.map +1 -0
  27. package/dist/es/models/api/identity/IIdentityProofCreateRequest.js +2 -0
  28. package/dist/es/models/api/identity/IIdentityProofCreateRequest.js.map +1 -0
  29. package/dist/es/models/api/identity/IIdentityProofCreateResponse.js +2 -0
  30. package/dist/es/models/api/identity/IIdentityProofCreateResponse.js.map +1 -0
  31. package/dist/es/models/api/identity/IIdentityProofVerifyRequest.js +2 -0
  32. package/dist/es/models/api/identity/IIdentityProofVerifyRequest.js.map +1 -0
  33. package/dist/es/models/api/identity/IIdentityProofVerifyResponse.js +4 -0
  34. package/dist/es/models/api/identity/IIdentityProofVerifyResponse.js.map +1 -0
  35. package/dist/es/models/api/identity/IIdentityRemoveRequest.js +4 -0
  36. package/dist/es/models/api/identity/IIdentityRemoveRequest.js.map +1 -0
  37. package/dist/es/models/api/identity/IIdentityServiceCreateRequest.js +4 -0
  38. package/dist/es/models/api/identity/IIdentityServiceCreateRequest.js.map +1 -0
  39. package/dist/es/models/api/identity/IIdentityServiceCreateResponse.js +2 -0
  40. package/dist/es/models/api/identity/IIdentityServiceCreateResponse.js.map +1 -0
  41. package/dist/es/models/api/identity/IIdentityServiceRemoveRequest.js +4 -0
  42. package/dist/es/models/api/identity/IIdentityServiceRemoveRequest.js.map +1 -0
  43. package/dist/es/models/api/identity/IIdentityVerifiableCredentialCreateRequest.js +2 -0
  44. package/dist/es/models/api/identity/IIdentityVerifiableCredentialCreateRequest.js.map +1 -0
  45. package/dist/es/models/api/identity/IIdentityVerifiableCredentialCreateResponse.js +2 -0
  46. package/dist/es/models/api/identity/IIdentityVerifiableCredentialCreateResponse.js.map +1 -0
  47. package/dist/es/models/api/identity/IIdentityVerifiableCredentialRevokeRequest.js +4 -0
  48. package/dist/es/models/api/identity/IIdentityVerifiableCredentialRevokeRequest.js.map +1 -0
  49. package/dist/es/models/api/identity/IIdentityVerifiableCredentialUnrevokeRequest.js +4 -0
  50. package/dist/es/models/api/identity/IIdentityVerifiableCredentialUnrevokeRequest.js.map +1 -0
  51. package/dist/es/models/api/identity/IIdentityVerifiableCredentialVerifyRequest.js +4 -0
  52. package/dist/es/models/api/identity/IIdentityVerifiableCredentialVerifyRequest.js.map +1 -0
  53. package/dist/es/models/api/identity/IIdentityVerifiableCredentialVerifyResponse.js +2 -0
  54. package/dist/es/models/api/identity/IIdentityVerifiableCredentialVerifyResponse.js.map +1 -0
  55. package/dist/es/models/api/identity/IIdentityVerifiablePresentationCreateRequest.js +2 -0
  56. package/dist/es/models/api/identity/IIdentityVerifiablePresentationCreateRequest.js.map +1 -0
  57. package/dist/es/models/api/identity/IIdentityVerifiablePresentationCreateResponse.js +2 -0
  58. package/dist/es/models/api/identity/IIdentityVerifiablePresentationCreateResponse.js.map +1 -0
  59. package/dist/es/models/api/identity/IIdentityVerifiablePresentationVerifyRequest.js +4 -0
  60. package/dist/es/models/api/identity/IIdentityVerifiablePresentationVerifyRequest.js.map +1 -0
  61. package/dist/es/models/api/identity/IIdentityVerifiablePresentationVerifyResponse.js +2 -0
  62. package/dist/es/models/api/identity/IIdentityVerifiablePresentationVerifyResponse.js.map +1 -0
  63. package/dist/es/models/api/identity/IIdentityVerificationMethodCreateRequest.js +2 -0
  64. package/dist/es/models/api/identity/IIdentityVerificationMethodCreateRequest.js.map +1 -0
  65. package/dist/es/models/api/identity/IIdentityVerificationMethodCreateResponse.js +2 -0
  66. package/dist/es/models/api/identity/IIdentityVerificationMethodCreateResponse.js.map +1 -0
  67. package/dist/es/models/api/identity/IIdentityVerificationMethodRemoveRequest.js +4 -0
  68. package/dist/es/models/api/identity/IIdentityVerificationMethodRemoveRequest.js.map +1 -0
  69. package/dist/es/models/api/profile/IIdentityProfileCreateRequest.js +2 -0
  70. package/dist/es/models/api/profile/IIdentityProfileCreateRequest.js.map +1 -0
  71. package/dist/es/models/api/profile/IIdentityProfileGetPublicRequest.js +4 -0
  72. package/dist/es/models/api/profile/IIdentityProfileGetPublicRequest.js.map +1 -0
  73. package/dist/es/models/api/profile/IIdentityProfileGetPublicResponse.js +2 -0
  74. package/dist/es/models/api/profile/IIdentityProfileGetPublicResponse.js.map +1 -0
  75. package/dist/es/models/api/profile/IIdentityProfileGetRequest.js +4 -0
  76. package/dist/es/models/api/profile/IIdentityProfileGetRequest.js.map +1 -0
  77. package/dist/es/models/api/profile/IIdentityProfileGetResponse.js +2 -0
  78. package/dist/es/models/api/profile/IIdentityProfileGetResponse.js.map +1 -0
  79. package/dist/es/models/api/profile/IIdentityProfileListRequest.js +4 -0
  80. package/dist/es/models/api/profile/IIdentityProfileListRequest.js.map +1 -0
  81. package/dist/es/models/api/profile/IIdentityProfileListResponse.js +2 -0
  82. package/dist/es/models/api/profile/IIdentityProfileListResponse.js.map +1 -0
  83. package/dist/es/models/api/profile/IIdentityProfileUpdateRequest.js +2 -0
  84. package/dist/es/models/api/profile/IIdentityProfileUpdateRequest.js.map +1 -0
  85. package/dist/es/models/api/resolver/IIdentityResolveRequest.js +4 -0
  86. package/dist/es/models/api/resolver/IIdentityResolveRequest.js.map +1 -0
  87. package/dist/es/models/api/resolver/IIdentityResolveResponse.js +2 -0
  88. package/dist/es/models/api/resolver/IIdentityResolveResponse.js.map +1 -0
  89. package/dist/es/types/did.js +53 -0
  90. package/dist/es/types/did.js.map +1 -0
  91. package/dist/es/utils/documentHelper.js +92 -0
  92. package/dist/es/utils/documentHelper.js.map +1 -0
  93. package/dist/es/utils/verificationHelper.js +79 -0
  94. package/dist/es/utils/verificationHelper.js.map +1 -0
  95. package/dist/types/contextIdHandlers/didContextIdHandler.d.ts +22 -0
  96. package/dist/types/factories/identityConnectorFactory.d.ts +1 -1
  97. package/dist/types/factories/identityProfileConnectorFactory.d.ts +1 -1
  98. package/dist/types/factories/identityResolverConnectorFactory.d.ts +1 -1
  99. package/dist/types/index.d.ts +46 -45
  100. package/dist/types/types/did.d.ts +28 -0
  101. package/dist/types/utils/verificationHelper.d.ts +1 -1
  102. package/docs/changelog.md +37 -0
  103. package/docs/reference/classes/{IdHelper.md → Did.md} +41 -5
  104. package/docs/reference/classes/DidContextIdHandler.md +79 -0
  105. package/docs/reference/classes/DocumentHelper.md +3 -3
  106. package/docs/reference/classes/VerificationHelper.md +2 -2
  107. package/docs/reference/index.md +2 -1
  108. package/docs/reference/interfaces/IIdentityComponent.md +4 -12
  109. package/docs/reference/interfaces/IIdentityConnector.md +4 -12
  110. package/docs/reference/interfaces/IIdentityProfileComponent.md +0 -8
  111. package/docs/reference/interfaces/IIdentityProfileConnector.md +0 -8
  112. package/docs/reference/interfaces/IIdentityResolverComponent.md +0 -8
  113. package/docs/reference/interfaces/IIdentityResolverConnector.md +0 -8
  114. package/locales/en.json +3 -2
  115. package/package.json +6 -7
  116. package/dist/cjs/index.cjs +0 -241
  117. package/dist/esm/index.mjs +0 -234
  118. package/dist/types/utils/idHelper.d.ts +0 -20
@@ -0,0 +1,79 @@
1
+ # Class: DidContextIdHandler
2
+
3
+ Context Id handler for testing as a DID.
4
+
5
+ ## Implements
6
+
7
+ - `IContextIdHandler`
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new DidContextIdHandler**(): `DidContextIdHandler`
14
+
15
+ #### Returns
16
+
17
+ `DidContextIdHandler`
18
+
19
+ ## Properties
20
+
21
+ ### CLASS\_NAME
22
+
23
+ > `readonly` `static` **CLASS\_NAME**: `string`
24
+
25
+ Runtime name for the class.
26
+
27
+ ## Methods
28
+
29
+ ### short()
30
+
31
+ > **short**(`value`): `string`
32
+
33
+ Get the short form of the DID which is the last part.
34
+
35
+ #### Parameters
36
+
37
+ ##### value
38
+
39
+ `string`
40
+
41
+ The full context id value.
42
+
43
+ #### Returns
44
+
45
+ `string`
46
+
47
+ Short form string.
48
+
49
+ #### Implementation of
50
+
51
+ `IContextIdHandler.short`
52
+
53
+ ***
54
+
55
+ ### guard()
56
+
57
+ > **guard**(`value`): `void`
58
+
59
+ Guard the value ensuring length.
60
+
61
+ #### Parameters
62
+
63
+ ##### value
64
+
65
+ `string`
66
+
67
+ The value to guard.
68
+
69
+ #### Returns
70
+
71
+ `void`
72
+
73
+ #### Throws
74
+
75
+ GeneralError if the value is too short.
76
+
77
+ #### Implementation of
78
+
79
+ `IContextIdHandler.guard`
@@ -48,7 +48,7 @@ The parsed document id.
48
48
 
49
49
  ##### fragment
50
50
 
51
- > **fragment**: `undefined` \| `string`
51
+ > **fragment**: `string` \| `undefined`
52
52
 
53
53
  ***
54
54
 
@@ -120,7 +120,7 @@ Error if the method is not found.
120
120
 
121
121
  ### getJwk()
122
122
 
123
- > `static` **getJwk**(`didDocument`, `methodName`, `methodType?`): `IJwk`
123
+ > `static` **getJwk**(`didDocument`, `methodName`, `methodType?`): `JWK`
124
124
 
125
125
  Gets a JWK from a DID document verification method.
126
126
 
@@ -146,7 +146,7 @@ The type of the method, defaults to verificationMethod.
146
146
 
147
147
  #### Returns
148
148
 
149
- `IJwk`
149
+ `JWK`
150
150
 
151
151
  The JWK if found.
152
152
 
@@ -32,11 +32,11 @@ Verified the JWT.
32
32
 
33
33
  ##### T
34
34
 
35
- `T` *extends* `IJwtHeader`
35
+ `T` *extends* `JWTHeaderParameters`
36
36
 
37
37
  ##### U
38
38
 
39
- `U` *extends* `IJwtPayload`
39
+ `U` *extends* `JWTPayload`
40
40
 
41
41
  #### Parameters
42
42
 
@@ -2,8 +2,9 @@
2
2
 
3
3
  ## Classes
4
4
 
5
+ - [DidContextIdHandler](classes/DidContextIdHandler.md)
6
+ - [Did](classes/Did.md)
5
7
  - [DocumentHelper](classes/DocumentHelper.md)
6
- - [IdHelper](classes/IdHelper.md)
7
8
  - [VerificationHelper](classes/VerificationHelper.md)
8
9
 
9
10
  ## Interfaces
@@ -6,14 +6,6 @@ Interface describing a contract which provides identity operations.
6
6
 
7
7
  - `IComponent`
8
8
 
9
- ## Indexable
10
-
11
- \[`key`: `string`\]: `any`
12
-
13
- All methods are optional, so we introduce an index signature to allow
14
- any additional properties or methods, which removes the TypeScript error where
15
- the class has no properties in common with the type.
16
-
17
9
  ## Methods
18
10
 
19
11
  ### identityCreate()
@@ -256,7 +248,7 @@ The verification method id to use.
256
248
 
257
249
  The id of the credential.
258
250
 
259
- `undefined` | `string`
251
+ `string` | `undefined`
260
252
 
261
253
  ##### subject
262
254
 
@@ -406,19 +398,19 @@ The method to associate with the presentation.
406
398
 
407
399
  The id of the presentation.
408
400
 
409
- `undefined` | `string`
401
+ `string` | `undefined`
410
402
 
411
403
  ##### contexts
412
404
 
413
405
  The contexts for the data stored in the verifiable credential.
414
406
 
415
- `undefined` | `IJsonLdContextDefinitionRoot`
407
+ `IJsonLdContextDefinitionRoot` | `undefined`
416
408
 
417
409
  ##### types
418
410
 
419
411
  The types for the data stored in the verifiable credential.
420
412
 
421
- `undefined` | `string` | `string`[]
413
+ `string` | `string`[] | `undefined`
422
414
 
423
415
  ##### verifiableCredentials
424
416
 
@@ -6,14 +6,6 @@ Interface describing an identity connector.
6
6
 
7
7
  - `IComponent`
8
8
 
9
- ## Indexable
10
-
11
- \[`key`: `string`\]: `any`
12
-
13
- All methods are optional, so we introduce an index signature to allow
14
- any additional properties or methods, which removes the TypeScript error where
15
- the class has no properties in common with the type.
16
-
17
9
  ## Methods
18
10
 
19
11
  ### createDocument()
@@ -256,7 +248,7 @@ The verification method id to use.
256
248
 
257
249
  The id of the credential.
258
250
 
259
- `undefined` | `string`
251
+ `string` | `undefined`
260
252
 
261
253
  ##### subject
262
254
 
@@ -406,19 +398,19 @@ The method to associate with the presentation.
406
398
 
407
399
  The id of the presentation.
408
400
 
409
- `undefined` | `string`
401
+ `string` | `undefined`
410
402
 
411
403
  ##### contexts
412
404
 
413
405
  The contexts for the data stored in the verifiable credential.
414
406
 
415
- `undefined` | `IJsonLdContextDefinitionRoot`
407
+ `IJsonLdContextDefinitionRoot` | `undefined`
416
408
 
417
409
  ##### types
418
410
 
419
411
  The types for the data stored in the verifiable credential.
420
412
 
421
- `undefined` | `string` | `string`[]
413
+ `string` | `string`[] | `undefined`
422
414
 
423
415
  ##### verifiableCredentials
424
416
 
@@ -16,14 +16,6 @@ Interface describing a contract which provides profile operations.
16
16
 
17
17
  `U` *extends* `IJsonLdDocument` = `IJsonLdDocument`
18
18
 
19
- ## Indexable
20
-
21
- \[`key`: `string`\]: `any`
22
-
23
- All methods are optional, so we introduce an index signature to allow
24
- any additional properties or methods, which removes the TypeScript error where
25
- the class has no properties in common with the type.
26
-
27
19
  ## Methods
28
20
 
29
21
  ### create()
@@ -16,14 +16,6 @@ Interface describing a contract which provides profile operations.
16
16
 
17
17
  `U` *extends* `IJsonLdDocument` = `IJsonLdDocument`
18
18
 
19
- ## Indexable
20
-
21
- \[`key`: `string`\]: `any`
22
-
23
- All methods are optional, so we introduce an index signature to allow
24
- any additional properties or methods, which removes the TypeScript error where
25
- the class has no properties in common with the type.
26
-
27
19
  ## Methods
28
20
 
29
21
  ### create()
@@ -6,14 +6,6 @@ Interface describing a contract which provides identity operations.
6
6
 
7
7
  - `IComponent`
8
8
 
9
- ## Indexable
10
-
11
- \[`key`: `string`\]: `any`
12
-
13
- All methods are optional, so we introduce an index signature to allow
14
- any additional properties or methods, which removes the TypeScript error where
15
- the class has no properties in common with the type.
16
-
17
9
  ## Methods
18
10
 
19
11
  ### identityResolve()
@@ -6,14 +6,6 @@ Interface describing an identity connector.
6
6
 
7
7
  - `IComponent`
8
8
 
9
- ## Indexable
10
-
11
- \[`key`: `string`\]: `any`
12
-
13
- All methods are optional, so we introduce an index signature to allow
14
- any additional properties or methods, which removes the TypeScript error where
15
- the class has no properties in common with the type.
16
-
17
9
  ## Methods
18
10
 
19
11
  ### resolveDocument()
package/locales/en.json CHANGED
@@ -8,8 +8,9 @@
8
8
  "verificationMethodNotFound": "The verification method \"{methodName}\" of type \"{methodType}\" could not be found",
9
9
  "verificationMethodJwkNotFound": "The verification method \"{methodName}\" of type \"{methodType}\" is missing the JWK"
10
10
  },
11
- "idHelper": {
12
- "invalidDocumentId": "The document id \"{id}\" is invalid"
11
+ "guard": {
12
+ "didPartsTooFew": "The DID \"{value}\" is invalid: expected at least 3 parts but got fewer",
13
+ "didInvalidStart": "The DID \"{value}\" is invalid: expected to start with 'did'"
13
14
  }
14
15
  }
15
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/identity-models",
3
- "version": "0.0.2-next.9",
3
+ "version": "0.0.3-next.2",
4
4
  "description": "Models which define the structure of the contracts and connectors",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,6 +14,7 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
+ "@twin.org/context": "next",
17
18
  "@twin.org/core": "next",
18
19
  "@twin.org/data-core": "next",
19
20
  "@twin.org/data-json-ld": "next",
@@ -21,20 +22,18 @@
21
22
  "@twin.org/standards-w3c-did": "next",
22
23
  "@twin.org/web": "next"
23
24
  },
24
- "main": "./dist/cjs/index.cjs",
25
- "module": "./dist/esm/index.mjs",
25
+ "main": "./dist/es/index.js",
26
26
  "types": "./dist/types/index.d.ts",
27
27
  "exports": {
28
28
  ".": {
29
29
  "types": "./dist/types/index.d.ts",
30
- "require": "./dist/cjs/index.cjs",
31
- "import": "./dist/esm/index.mjs"
30
+ "import": "./dist/es/index.js",
31
+ "default": "./dist/es/index.js"
32
32
  },
33
33
  "./locales/*.json": "./locales/*.json"
34
34
  },
35
35
  "files": [
36
- "dist/cjs",
37
- "dist/esm",
36
+ "dist/es",
38
37
  "dist/types",
39
38
  "locales",
40
39
  "docs"
@@ -1,241 +0,0 @@
1
- 'use strict';
2
-
3
- var core = require('@twin.org/core');
4
- var standardsW3cDid = require('@twin.org/standards-w3c-did');
5
- var web = require('@twin.org/web');
6
-
7
- // Copyright 2024 IOTA Stiftung.
8
- // SPDX-License-Identifier: Apache-2.0.
9
- /**
10
- * Factory for creating identity connectors.
11
- */
12
- // eslint-disable-next-line @typescript-eslint/naming-convention
13
- const IdentityConnectorFactory = core.Factory.createFactory("identity-connector");
14
-
15
- // Copyright 2024 IOTA Stiftung.
16
- // SPDX-License-Identifier: Apache-2.0.
17
- /**
18
- * Factory for creating identity profile connectors.
19
- */
20
- // eslint-disable-next-line @typescript-eslint/naming-convention
21
- const IdentityProfileConnectorFactory = core.Factory.createFactory("identity-profile-connector");
22
-
23
- // Copyright 2024 IOTA Stiftung.
24
- // SPDX-License-Identifier: Apache-2.0.
25
- /**
26
- * Factory for creating identity resolver connectors.
27
- */
28
- // eslint-disable-next-line @typescript-eslint/naming-convention
29
- const IdentityResolverConnectorFactory = core.Factory.createFactory("identity-resolver-connector");
30
-
31
- // Copyright 2024 IOTA Stiftung.
32
- // SPDX-License-Identifier: Apache-2.0.
33
- /**
34
- * Helper methods for documents.
35
- */
36
- class DocumentHelper {
37
- /**
38
- * Runtime name for the class.
39
- */
40
- static CLASS_NAME = "DocumentHelper";
41
- /**
42
- * Parse the document id into its parts.
43
- * @param documentId The full document id.
44
- * @returns The parsed document id.
45
- */
46
- static parseId(documentId) {
47
- if (!core.Is.stringValue(documentId)) {
48
- return {
49
- id: "",
50
- fragment: ""
51
- };
52
- }
53
- const fragmentIndex = documentId.indexOf("#");
54
- return {
55
- id: fragmentIndex === -1 ? documentId : documentId.slice(0, fragmentIndex),
56
- fragment: fragmentIndex === -1 ? undefined : documentId.slice(fragmentIndex + 1)
57
- };
58
- }
59
- /**
60
- * Join the document id parts.
61
- * @param documentId The document id.
62
- * @param fragment The fragment part for the identifier.
63
- * @returns The full id.
64
- */
65
- static joinId(documentId, fragment) {
66
- if (!core.Is.stringValue(documentId)) {
67
- return "";
68
- }
69
- let fullId = documentId;
70
- if (core.Is.stringValue(fragment)) {
71
- if (fragment.startsWith(documentId)) {
72
- fragment = fragment.slice(documentId.length);
73
- }
74
- if (fragment.startsWith("#")) {
75
- fullId += fragment;
76
- }
77
- else {
78
- fullId += `#${fragment}`;
79
- }
80
- }
81
- return fullId;
82
- }
83
- /**
84
- * Get a verification method from a DID document.
85
- * @param didDocument The DID Document to get the method from.
86
- * @param methodName The name of the method to get the JWK from.
87
- * @param methodType The type of the method, defaults to verificationMethod.
88
- * @returns The verification method if found.
89
- * @throws Error if the method is not found.
90
- */
91
- static getVerificationMethod(didDocument, methodName, methodType) {
92
- const verificationMethod = didDocument[methodType ?? standardsW3cDid.DidVerificationMethodType.VerificationMethod]?.find(vm => core.Is.object(vm) && vm.id === methodName);
93
- if (core.Is.object(verificationMethod)) {
94
- return verificationMethod;
95
- }
96
- throw new core.GeneralError(DocumentHelper.CLASS_NAME, "verificationMethodNotFound", {
97
- methodName,
98
- methodType
99
- });
100
- }
101
- /**
102
- * Gets a JWK from a DID document verification method.
103
- * @param didDocument The DID Document to get the method from.
104
- * @param methodName The name of the method to get the JWK from.
105
- * @param methodType The type of the method, defaults to verificationMethod.
106
- * @returns The JWK if found.
107
- * @throws Error if the method is not found.
108
- */
109
- static getJwk(didDocument, methodName, methodType) {
110
- const verificationMethod = DocumentHelper.getVerificationMethod(didDocument, methodName, methodType);
111
- if (core.Is.object(verificationMethod) && core.Is.object(verificationMethod.publicKeyJwk)) {
112
- return verificationMethod.publicKeyJwk;
113
- }
114
- throw new core.GeneralError(DocumentHelper.CLASS_NAME, "verificationMethodJwkNotFound", {
115
- methodName,
116
- methodType
117
- });
118
- }
119
- }
120
-
121
- // Copyright 2024 IOTA Stiftung.
122
- // SPDX-License-Identifier: Apache-2.0.
123
- /**
124
- * Helper methods for Ids.
125
- */
126
- class IdHelper {
127
- /**
128
- * Runtime name for the class.
129
- */
130
- static CLASS_NAME = "IdHelper";
131
- /**
132
- * Parse and id in to it's constituent parts.
133
- * @param id The id to parse.
134
- * @returns The parsed id.
135
- * @throws GeneralError if the id is not valid.
136
- */
137
- static parseId(id) {
138
- core.Urn.guard(IdHelper.CLASS_NAME, "id", id);
139
- const didUrn = core.Urn.fromValidString(id);
140
- const didParts = didUrn.parts();
141
- if (didParts[0] !== "did") {
142
- throw new core.GeneralError(IdHelper.CLASS_NAME, "invalidDocumentId", { id });
143
- }
144
- if (didParts.length === 3) {
145
- return {
146
- method: didParts[1],
147
- id: didParts[2]
148
- };
149
- }
150
- else if (didParts.length === 4) {
151
- return {
152
- method: didParts[1],
153
- network: didParts[2],
154
- id: didParts[3]
155
- };
156
- }
157
- throw new core.GeneralError(IdHelper.CLASS_NAME, "invalidDocumentId", { id });
158
- }
159
- }
160
-
161
- // Copyright 2024 IOTA Stiftung.
162
- // SPDX-License-Identifier: Apache-2.0.
163
- /**
164
- * Helper methods for verification.
165
- */
166
- class VerificationHelper {
167
- /**
168
- * Runtime name for the class.
169
- */
170
- static CLASS_NAME = "VerificationHelper";
171
- /**
172
- * Verified the JWT.
173
- * @param resolver The resolver to use for finding the document.
174
- * @param jwt The token to verify.
175
- * @returns The decoded payload.
176
- */
177
- static async verifyJwt(resolver, jwt) {
178
- core.Guards.object(VerificationHelper.CLASS_NAME, "resolver", resolver);
179
- core.Guards.string(VerificationHelper.CLASS_NAME, "jwt", jwt);
180
- const jwtDecoded = await web.Jwt.decode(jwt);
181
- const jwtHeader = jwtDecoded.header;
182
- const jwtPayload = jwtDecoded.payload;
183
- const jwtSignature = jwtDecoded.signature;
184
- if (!core.Is.object(jwtHeader) || !core.Is.object(jwtPayload) || !core.Is.uint8Array(jwtSignature)) {
185
- throw new core.GeneralError(VerificationHelper.CLASS_NAME, "jwtDecodeFailed");
186
- }
187
- const iss = jwtHeader?.iss;
188
- const kid = jwtHeader?.kid;
189
- core.Guards.stringValue(VerificationHelper.CLASS_NAME, "iss", iss);
190
- core.Guards.stringValue(VerificationHelper.CLASS_NAME, "kid", kid);
191
- const didDocument = await resolver.identityResolve(iss);
192
- const jwk = DocumentHelper.getJwk(didDocument, kid);
193
- const publicKey = await web.Jwk.toCryptoKey(jwk);
194
- return web.Jwt.verify(jwt, publicKey);
195
- }
196
- /**
197
- * Verified the proof for the document e.g. verifiable credential.
198
- * @param resolver The resolver to use for finding the document.
199
- * @param secureDocument The secure document to verify.
200
- * @returns True if the verification is successful.
201
- */
202
- static async verifyProof(resolver, secureDocument) {
203
- core.Guards.object(VerificationHelper.CLASS_NAME, "resolver", resolver);
204
- core.Guards.object(VerificationHelper.CLASS_NAME, "secureDocument", secureDocument);
205
- core.Guards.object(VerificationHelper.CLASS_NAME, "secureDocument.proof", secureDocument.proof);
206
- const proofList = core.Is.array(secureDocument.proof)
207
- ? secureDocument.proof
208
- : [secureDocument.proof];
209
- const documentCache = {};
210
- for (const proof of proofList) {
211
- if (!core.Is.stringValue(proof?.verificationMethod)) {
212
- throw new core.GeneralError(VerificationHelper.CLASS_NAME, "proofMissingVerificationMethod");
213
- }
214
- const proofVerificationMethod = DocumentHelper.parseId(proof.verificationMethod);
215
- if (!core.Is.stringValue(proofVerificationMethod.fragment)) {
216
- throw new core.GeneralError(VerificationHelper.CLASS_NAME, "proofMissingVerificationMethod");
217
- }
218
- let document;
219
- if (documentCache[proofVerificationMethod.id]) {
220
- document = documentCache[proofVerificationMethod.id];
221
- }
222
- else {
223
- document = await resolver.identityResolve(proofVerificationMethod.id);
224
- documentCache[proofVerificationMethod.id] = document;
225
- }
226
- const verificationJwk = await DocumentHelper.getJwk(document, proofVerificationMethod.id);
227
- const verified = standardsW3cDid.ProofHelper.verifyProof(secureDocument, proof, verificationJwk);
228
- if (!verified) {
229
- return false;
230
- }
231
- }
232
- return true;
233
- }
234
- }
235
-
236
- exports.DocumentHelper = DocumentHelper;
237
- exports.IdHelper = IdHelper;
238
- exports.IdentityConnectorFactory = IdentityConnectorFactory;
239
- exports.IdentityProfileConnectorFactory = IdentityProfileConnectorFactory;
240
- exports.IdentityResolverConnectorFactory = IdentityResolverConnectorFactory;
241
- exports.VerificationHelper = VerificationHelper;