@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 @@
1
+ {"version":3,"file":"IIdentityProfileUpdateRequest.js","sourceRoot":"","sources":["../../../../../src/models/api/profile/IIdentityProfileUpdateRequest.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonLdDocument } from \"@twin.org/data-json-ld\";\n\n/**\n * Request to update an identity profile.\n */\nexport interface IIdentityProfileUpdateRequest {\n\t/**\n\t * The data for the request.\n\t */\n\tbody: {\n\t\t/**\n\t\t * The public profile data.\n\t\t */\n\t\tpublicProfile?: IJsonLdDocument;\n\n\t\t/**\n\t\t * The private profile data.\n\t\t */\n\t\tprivateProfile?: IJsonLdDocument;\n\t};\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IIdentityResolveRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IIdentityResolveRequest.js","sourceRoot":"","sources":["../../../../../src/models/api/resolver/IIdentityResolveRequest.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Resolve an identity.\n */\nexport interface IIdentityResolveRequest {\n\t/**\n\t * The path parameters.\n\t */\n\tpathParams: {\n\t\t/**\n\t\t * The identity to resolve.\n\t\t */\n\t\tidentity: string;\n\t};\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IIdentityResolveResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IIdentityResolveResponse.js","sourceRoot":"","sources":["../../../../../src/models/api/resolver/IIdentityResolveResponse.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IDidDocument } from \"@twin.org/standards-w3c-did\";\n\n/**\n * Response to resolving an identity.\n */\nexport interface IIdentityResolveResponse {\n\t/**\n\t * The response payload.\n\t */\n\tbody: IDidDocument;\n}\n"]}
@@ -0,0 +1,53 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { GuardError, Urn } from "@twin.org/core";
4
+ /**
5
+ * Helper methods for Ids.
6
+ */
7
+ export class Did {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ static CLASS_NAME = "Did";
12
+ /**
13
+ * Parse and id in to it's constituent parts.
14
+ * @param id The id to parse.
15
+ * @returns The parsed id.
16
+ * @throws GeneralError if the id is not valid.
17
+ */
18
+ static parse(id) {
19
+ Did.guard(Did.CLASS_NAME, "id", id);
20
+ const didUrn = Urn.fromValidString(id);
21
+ const didParts = didUrn.parts();
22
+ if (didParts.length === 3) {
23
+ return {
24
+ method: didParts[1],
25
+ id: didParts[2]
26
+ };
27
+ }
28
+ return {
29
+ method: didParts[1],
30
+ network: didParts[2],
31
+ id: didParts[didParts.length - 1]
32
+ };
33
+ }
34
+ /**
35
+ * Guard a string as a DID.
36
+ * @param source The source of the error.
37
+ * @param property The name of the property.
38
+ * @param value The urn to parse.
39
+ * @throws GuardError If the value does not match the assertion.
40
+ */
41
+ static guard(source, property, value) {
42
+ Urn.guard(Did.CLASS_NAME, "value", value);
43
+ const urn = Urn.fromValidString(value);
44
+ const parts = urn.parts();
45
+ if (parts.length < 3) {
46
+ throw new GuardError(Did.CLASS_NAME, "guard.didPartsTooFew", "value", value);
47
+ }
48
+ if (parts[0] !== "did") {
49
+ throw new GuardError(Did.CLASS_NAME, "guard.didInvalidStart", "value", value);
50
+ }
51
+ }
52
+ }
53
+ //# sourceMappingURL=did.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did.js","sourceRoot":"","sources":["../../../src/types/did.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAGjD;;GAEG;AACH,MAAM,OAAO,GAAG;IACf;;OAEG;IACI,MAAM,CAAU,UAAU,SAAyB;IAE1D;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,EAAU;QAK7B,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,QAAc,EAAE,CAAC,CAAC;QAE1C,MAAM,MAAM,GAAG,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QACvC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QAEhC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO;gBACN,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;gBACnB,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;aACf,CAAC;QACH,CAAC;QACD,OAAO;YACN,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;YACnB,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;YACpB,EAAE,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;SACjC,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,MAAc,EAAE,QAAgB,EAAE,KAAc;QACnE,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,WAAiB,KAAK,CAAC,CAAC;QAChD,MAAM,GAAG,GAAG,GAAG,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACvC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;QAE1B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,sBAAsB,WAAiB,KAAK,CAAC,CAAC;QACpF,CAAC;QAED,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC;YACxB,MAAM,IAAI,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,uBAAuB,WAAiB,KAAK,CAAC,CAAC;QACrF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GuardError, Urn } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\n\n/**\n * Helper methods for Ids.\n */\nexport class Did {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<Did>();\n\n\t/**\n\t * Parse and id in to it's constituent parts.\n\t * @param id The id to parse.\n\t * @returns The parsed id.\n\t * @throws GeneralError if the id is not valid.\n\t */\n\tpublic static parse(id: string): {\n\t\tmethod: string;\n\t\tnetwork?: string | undefined;\n\t\tid: string;\n\t} {\n\t\tDid.guard(Did.CLASS_NAME, nameof(id), id);\n\n\t\tconst didUrn = Urn.fromValidString(id);\n\t\tconst didParts = didUrn.parts();\n\n\t\tif (didParts.length === 3) {\n\t\t\treturn {\n\t\t\t\tmethod: didParts[1],\n\t\t\t\tid: didParts[2]\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tmethod: didParts[1],\n\t\t\tnetwork: didParts[2],\n\t\t\tid: didParts[didParts.length - 1]\n\t\t};\n\t}\n\n\t/**\n\t * Guard a string as a DID.\n\t * @param source The source of the error.\n\t * @param property The name of the property.\n\t * @param value The urn to parse.\n\t * @throws GuardError If the value does not match the assertion.\n\t */\n\tpublic static guard(source: string, property: string, value: unknown): asserts value is string {\n\t\tUrn.guard(Did.CLASS_NAME, nameof(value), value);\n\t\tconst urn = Urn.fromValidString(value);\n\t\tconst parts = urn.parts();\n\n\t\tif (parts.length < 3) {\n\t\t\tthrow new GuardError(Did.CLASS_NAME, \"guard.didPartsTooFew\", nameof(value), value);\n\t\t}\n\n\t\tif (parts[0] !== \"did\") {\n\t\t\tthrow new GuardError(Did.CLASS_NAME, \"guard.didInvalidStart\", nameof(value), value);\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,92 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { GeneralError, Is } from "@twin.org/core";
4
+ import { DidVerificationMethodType } from "@twin.org/standards-w3c-did";
5
+ /**
6
+ * Helper methods for documents.
7
+ */
8
+ export class DocumentHelper {
9
+ /**
10
+ * Runtime name for the class.
11
+ */
12
+ static CLASS_NAME = "DocumentHelper";
13
+ /**
14
+ * Parse the document id into its parts.
15
+ * @param documentId The full document id.
16
+ * @returns The parsed document id.
17
+ */
18
+ static parseId(documentId) {
19
+ if (!Is.stringValue(documentId)) {
20
+ return {
21
+ id: "",
22
+ fragment: ""
23
+ };
24
+ }
25
+ const fragmentIndex = documentId.indexOf("#");
26
+ return {
27
+ id: fragmentIndex === -1 ? documentId : documentId.slice(0, fragmentIndex),
28
+ fragment: fragmentIndex === -1 ? undefined : documentId.slice(fragmentIndex + 1)
29
+ };
30
+ }
31
+ /**
32
+ * Join the document id parts.
33
+ * @param documentId The document id.
34
+ * @param fragment The fragment part for the identifier.
35
+ * @returns The full id.
36
+ */
37
+ static joinId(documentId, fragment) {
38
+ if (!Is.stringValue(documentId)) {
39
+ return "";
40
+ }
41
+ let fullId = documentId;
42
+ if (Is.stringValue(fragment)) {
43
+ if (fragment.startsWith(documentId)) {
44
+ fragment = fragment.slice(documentId.length);
45
+ }
46
+ if (fragment.startsWith("#")) {
47
+ fullId += fragment;
48
+ }
49
+ else {
50
+ fullId += `#${fragment}`;
51
+ }
52
+ }
53
+ return fullId;
54
+ }
55
+ /**
56
+ * Get a verification method from a DID document.
57
+ * @param didDocument The DID Document to get the method from.
58
+ * @param methodName The name of the method to get the JWK from.
59
+ * @param methodType The type of the method, defaults to verificationMethod.
60
+ * @returns The verification method if found.
61
+ * @throws Error if the method is not found.
62
+ */
63
+ static getVerificationMethod(didDocument, methodName, methodType) {
64
+ const verificationMethod = didDocument[methodType ?? DidVerificationMethodType.VerificationMethod]?.find(vm => Is.object(vm) && vm.id === methodName);
65
+ if (Is.object(verificationMethod)) {
66
+ return verificationMethod;
67
+ }
68
+ throw new GeneralError(DocumentHelper.CLASS_NAME, "verificationMethodNotFound", {
69
+ methodName,
70
+ methodType
71
+ });
72
+ }
73
+ /**
74
+ * Gets a JWK from a DID document verification method.
75
+ * @param didDocument The DID Document to get the method from.
76
+ * @param methodName The name of the method to get the JWK from.
77
+ * @param methodType The type of the method, defaults to verificationMethod.
78
+ * @returns The JWK if found.
79
+ * @throws Error if the method is not found.
80
+ */
81
+ static getJwk(didDocument, methodName, methodType) {
82
+ const verificationMethod = DocumentHelper.getVerificationMethod(didDocument, methodName, methodType);
83
+ if (Is.object(verificationMethod) && Is.object(verificationMethod.publicKeyJwk)) {
84
+ return verificationMethod.publicKeyJwk;
85
+ }
86
+ throw new GeneralError(DocumentHelper.CLASS_NAME, "verificationMethodJwkNotFound", {
87
+ methodName,
88
+ methodType
89
+ });
90
+ }
91
+ }
92
+ //# sourceMappingURL=documentHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentHelper.js","sourceRoot":"","sources":["../../../src/utils/documentHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EACN,yBAAyB,EAGzB,MAAM,6BAA6B,CAAC;AAGrC;;GAE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ACF,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,qBAAqB,CAClC,WAAyB,EACzB,UAAkB,EAClB,UAAsC;QAEtC,MAAM,kBAAkB,GAAG,WAAW,CACrC,UAAU,IAAI,yBAAyB,CAAC,kBAAkB,CAC1D,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC;QAErD,IAAI,EAAE,CAAC,MAAM,CAAiC,kBAAkB,CAAC,EAAE,CAAC;YACnE,OAAO,kBAAkB,CAAC;QAC3B,CAAC;QACD,MAAM,IAAI,YAAY,CAAC,cAAc,CAAC,UAAU,EAAE,4BAA4B,EAAE;YAC/E,UAAU;YACV,UAAU;SACV,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,MAAM,CACnB,WAAyB,EACzB,UAAkB,EAClB,UAAsC;QAEtC,MAAM,kBAAkB,GAAG,cAAc,CAAC,qBAAqB,CAC9D,WAAW,EACX,UAAU,EACV,UAAU,CACV,CAAC;QAEF,IAAI,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC;YACjF,OAAO,kBAAkB,CAAC,YAAY,CAAC;QACxC,CAAC;QAED,MAAM,IAAI,YAAY,CAAC,cAAc,CAAC,UAAU,EAAE,+BAA+B,EAAE;YAClF,UAAU;YACV,UAAU;SACV,CAAC,CAAC;IACJ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Is } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tDidVerificationMethodType,\n\ttype IDidDocumentVerificationMethod,\n\ttype IDidDocument\n} from \"@twin.org/standards-w3c-did\";\nimport type { IJwk } from \"@twin.org/web\";\n\n/**\n * Helper methods for documents.\n */\nexport class DocumentHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DocumentHelper>();\n\n\t/**\n\t * Parse the document id into its parts.\n\t * @param documentId The full document id.\n\t * @returns The parsed document id.\n\t */\n\tpublic static parseId(documentId: string): {\n\t\tid: string;\n\t\tfragment: string | undefined;\n\t} {\n\t\tif (!Is.stringValue(documentId)) {\n\t\t\treturn {\n\t\t\t\tid: \"\",\n\t\t\t\tfragment: \"\"\n\t\t\t};\n\t\t}\n\n\t\tconst fragmentIndex = documentId.indexOf(\"#\");\n\n\t\treturn {\n\t\t\tid: fragmentIndex === -1 ? documentId : documentId.slice(0, fragmentIndex),\n\t\t\tfragment: fragmentIndex === -1 ? undefined : documentId.slice(fragmentIndex + 1)\n\t\t};\n\t}\n\n\t/**\n\t * Join the document id parts.\n\t * @param documentId The document id.\n\t * @param fragment The fragment part for the identifier.\n\t * @returns The full id.\n\t */\n\tpublic static joinId(documentId: string, fragment?: string): string {\n\t\tif (!Is.stringValue(documentId)) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\tlet fullId = documentId;\n\n\t\tif (Is.stringValue(fragment)) {\n\t\t\tif (fragment.startsWith(documentId)) {\n\t\t\t\tfragment = fragment.slice(documentId.length);\n\t\t\t}\n\t\t\tif (fragment.startsWith(\"#\")) {\n\t\t\t\tfullId += fragment;\n\t\t\t} else {\n\t\t\t\tfullId += `#${fragment}`;\n\t\t\t}\n\t\t}\n\n\t\treturn fullId;\n\t}\n\n\t/**\n\t * Get a verification method from a DID document.\n\t * @param didDocument The DID Document to get the method from.\n\t * @param methodName The name of the method to get the JWK from.\n\t * @param methodType The type of the method, defaults to verificationMethod.\n\t * @returns The verification method if found.\n\t * @throws Error if the method is not found.\n\t */\n\tpublic static getVerificationMethod(\n\t\tdidDocument: IDidDocument,\n\t\tmethodName: string,\n\t\tmethodType?: DidVerificationMethodType\n\t): IDidDocumentVerificationMethod {\n\t\tconst verificationMethod = didDocument[\n\t\t\tmethodType ?? DidVerificationMethodType.VerificationMethod\n\t\t]?.find(vm => Is.object(vm) && vm.id === methodName);\n\n\t\tif (Is.object<IDidDocumentVerificationMethod>(verificationMethod)) {\n\t\t\treturn verificationMethod;\n\t\t}\n\t\tthrow new GeneralError(DocumentHelper.CLASS_NAME, \"verificationMethodNotFound\", {\n\t\t\tmethodName,\n\t\t\tmethodType\n\t\t});\n\t}\n\n\t/**\n\t * Gets a JWK from a DID document verification method.\n\t * @param didDocument The DID Document to get the method from.\n\t * @param methodName The name of the method to get the JWK from.\n\t * @param methodType The type of the method, defaults to verificationMethod.\n\t * @returns The JWK if found.\n\t * @throws Error if the method is not found.\n\t */\n\tpublic static getJwk(\n\t\tdidDocument: IDidDocument,\n\t\tmethodName: string,\n\t\tmethodType?: DidVerificationMethodType\n\t): IJwk {\n\t\tconst verificationMethod = DocumentHelper.getVerificationMethod(\n\t\t\tdidDocument,\n\t\t\tmethodName,\n\t\t\tmethodType\n\t\t);\n\n\t\tif (Is.object(verificationMethod) && Is.object(verificationMethod.publicKeyJwk)) {\n\t\t\treturn verificationMethod.publicKeyJwk;\n\t\t}\n\n\t\tthrow new GeneralError(DocumentHelper.CLASS_NAME, \"verificationMethodJwkNotFound\", {\n\t\t\tmethodName,\n\t\t\tmethodType\n\t\t});\n\t}\n}\n"]}
@@ -0,0 +1,79 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { GeneralError, Guards, Is } from "@twin.org/core";
4
+ import { ProofHelper } from "@twin.org/standards-w3c-did";
5
+ import { Jwk, Jwt } from "@twin.org/web";
6
+ import { DocumentHelper } from "./documentHelper.js";
7
+ /**
8
+ * Helper methods for verification.
9
+ */
10
+ export class VerificationHelper {
11
+ /**
12
+ * Runtime name for the class.
13
+ */
14
+ static CLASS_NAME = "VerificationHelper";
15
+ /**
16
+ * Verified the JWT.
17
+ * @param resolver The resolver to use for finding the document.
18
+ * @param jwt The token to verify.
19
+ * @returns The decoded payload.
20
+ */
21
+ static async verifyJwt(resolver, jwt) {
22
+ Guards.object(VerificationHelper.CLASS_NAME, "resolver", resolver);
23
+ Guards.string(VerificationHelper.CLASS_NAME, "jwt", jwt);
24
+ const jwtDecoded = await Jwt.decode(jwt);
25
+ const jwtHeader = jwtDecoded.header;
26
+ const jwtPayload = jwtDecoded.payload;
27
+ const jwtSignature = jwtDecoded.signature;
28
+ if (!Is.object(jwtHeader) || !Is.object(jwtPayload) || !Is.uint8Array(jwtSignature)) {
29
+ throw new GeneralError(VerificationHelper.CLASS_NAME, "jwtDecodeFailed");
30
+ }
31
+ const iss = jwtHeader?.iss;
32
+ const kid = jwtHeader?.kid;
33
+ Guards.stringValue(VerificationHelper.CLASS_NAME, "iss", iss);
34
+ Guards.stringValue(VerificationHelper.CLASS_NAME, "kid", kid);
35
+ const didDocument = await resolver.identityResolve(iss);
36
+ const jwk = DocumentHelper.getJwk(didDocument, kid);
37
+ const publicKey = await Jwk.toCryptoKey(jwk);
38
+ return Jwt.verify(jwt, publicKey);
39
+ }
40
+ /**
41
+ * Verified the proof for the document e.g. verifiable credential.
42
+ * @param resolver The resolver to use for finding the document.
43
+ * @param secureDocument The secure document to verify.
44
+ * @returns True if the verification is successful.
45
+ */
46
+ static async verifyProof(resolver, secureDocument) {
47
+ Guards.object(VerificationHelper.CLASS_NAME, "resolver", resolver);
48
+ Guards.object(VerificationHelper.CLASS_NAME, "secureDocument", secureDocument);
49
+ Guards.object(VerificationHelper.CLASS_NAME, "secureDocument.proof", secureDocument.proof);
50
+ const proofList = Is.array(secureDocument.proof)
51
+ ? secureDocument.proof
52
+ : [secureDocument.proof];
53
+ const documentCache = {};
54
+ for (const proof of proofList) {
55
+ if (!Is.stringValue(proof?.verificationMethod)) {
56
+ throw new GeneralError(VerificationHelper.CLASS_NAME, "proofMissingVerificationMethod");
57
+ }
58
+ const proofVerificationMethod = DocumentHelper.parseId(proof.verificationMethod);
59
+ if (!Is.stringValue(proofVerificationMethod.fragment)) {
60
+ throw new GeneralError(VerificationHelper.CLASS_NAME, "proofMissingVerificationMethod");
61
+ }
62
+ let document;
63
+ if (documentCache[proofVerificationMethod.id]) {
64
+ document = documentCache[proofVerificationMethod.id];
65
+ }
66
+ else {
67
+ document = await resolver.identityResolve(proofVerificationMethod.id);
68
+ documentCache[proofVerificationMethod.id] = document;
69
+ }
70
+ const verificationJwk = DocumentHelper.getJwk(document, proofVerificationMethod.id);
71
+ const verified = await ProofHelper.verifyProof(secureDocument, proof, verificationJwk);
72
+ if (!verified) {
73
+ return false;
74
+ }
75
+ }
76
+ return true;
77
+ }
78
+ }
79
+ //# sourceMappingURL=verificationHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verificationHelper.js","sourceRoot":"","sources":["../../../src/utils/verificationHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAG1D,OAAO,EAAE,WAAW,EAAkC,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAAE,GAAG,EAAE,GAAG,EAAqC,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC9B;;OAEG;IACI,MAAM,CAAU,UAAU,wBAAwC;IAEzE;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,SAAS,CAC5B,QAAoC,EACpC,GAAW;QAKX,MAAM,CAAC,MAAM,CACZ,kBAAkB,CAAC,UAAU,cAE7B,QAAQ,CACR,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,UAAU,SAAe,GAAG,CAAC,CAAC;QAE/D,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,MAAM,CAAO,GAAG,CAAC,CAAC;QAE/C,MAAM,SA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EvF,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACf,OAAO,KAAK,CAAC;YACd,CAAC;QACF,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Is } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { ProofHelper, type IDidDocument, type IProof } from \"@twin.org/standards-w3c-did\";\nimport { Jwk, Jwt, type IJwtHeader, type IJwtPayload } from \"@twin.org/web\";\nimport { DocumentHelper } from \"./documentHelper.js\";\nimport type { IIdentityResolverComponent } from \"../models/IIdentityResolverComponent.js\";\n\n/**\n * Helper methods for verification.\n */\nexport class VerificationHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<VerificationHelper>();\n\n\t/**\n\t * Verified the JWT.\n\t * @param resolver The resolver to use for finding the document.\n\t * @param jwt The token to verify.\n\t * @returns The decoded payload.\n\t */\n\tpublic static async verifyJwt<T extends IJwtHeader, U extends IJwtPayload>(\n\t\tresolver: IIdentityResolverComponent,\n\t\tjwt: string\n\t): Promise<{\n\t\theader: T;\n\t\tpayload: U;\n\t}> {\n\t\tGuards.object<IIdentityResolverComponent>(\n\t\t\tVerificationHelper.CLASS_NAME,\n\t\t\tnameof(resolver),\n\t\t\tresolver\n\t\t);\n\t\tGuards.string(VerificationHelper.CLASS_NAME, nameof(jwt), jwt);\n\n\t\tconst jwtDecoded = await Jwt.decode<T, U>(jwt);\n\n\t\tconst jwtHeader = jwtDecoded.header;\n\t\tconst jwtPayload = jwtDecoded.payload;\n\t\tconst jwtSignature = jwtDecoded.signature;\n\n\t\tif (!Is.object(jwtHeader) || !Is.object(jwtPayload) || !Is.uint8Array(jwtSignature)) {\n\t\t\tthrow new GeneralError(VerificationHelper.CLASS_NAME, \"jwtDecodeFailed\");\n\t\t}\n\n\t\tconst iss = jwtHeader?.iss;\n\t\tconst kid = jwtHeader?.kid;\n\n\t\tGuards.stringValue(VerificationHelper.CLASS_NAME, nameof(iss), iss);\n\t\tGuards.stringValue(VerificationHelper.CLASS_NAME, nameof(kid), kid);\n\n\t\tconst didDocument = await resolver.identityResolve(iss);\n\n\t\tconst jwk = DocumentHelper.getJwk(didDocument, kid);\n\n\t\tconst publicKey = await Jwk.toCryptoKey(jwk);\n\n\t\treturn Jwt.verify(jwt, publicKey);\n\t}\n\n\t/**\n\t * Verified the proof for the document e.g. verifiable credential.\n\t * @param resolver The resolver to use for finding the document.\n\t * @param secureDocument The secure document to verify.\n\t * @returns True if the verification is successful.\n\t */\n\tpublic static async verifyProof(\n\t\tresolver: IIdentityResolverComponent,\n\t\tsecureDocument: IJsonLdNodeObject\n\t): Promise<boolean> {\n\t\tGuards.object<IIdentityResolverComponent>(\n\t\t\tVerificationHelper.CLASS_NAME,\n\t\t\tnameof(resolver),\n\t\t\tresolver\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tVerificationHelper.CLASS_NAME,\n\t\t\tnameof(secureDocument),\n\t\t\tsecureDocument\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tVerificationHelper.CLASS_NAME,\n\t\t\tnameof(secureDocument.proof),\n\t\t\tsecureDocument.proof\n\t\t);\n\n\t\tconst proofList = Is.array<IProof>(secureDocument.proof)\n\t\t\t? secureDocument.proof\n\t\t\t: [secureDocument.proof];\n\n\t\tconst documentCache: { [key: string]: IDidDocument } = {};\n\n\t\tfor (const proof of proofList as IProof[]) {\n\t\t\tif (!Is.stringValue(proof?.verificationMethod)) {\n\t\t\t\tthrow new GeneralError(VerificationHelper.CLASS_NAME, \"proofMissingVerificationMethod\");\n\t\t\t}\n\n\t\t\tconst proofVerificationMethod = DocumentHelper.parseId(proof.verificationMethod);\n\t\t\tif (!Is.stringValue(proofVerificationMethod.fragment)) {\n\t\t\t\tthrow new GeneralError(VerificationHelper.CLASS_NAME, \"proofMissingVerificationMethod\");\n\t\t\t}\n\n\t\t\tlet document: IDidDocument;\n\n\t\t\tif (documentCache[proofVerificationMethod.id]) {\n\t\t\t\tdocument = documentCache[proofVerificationMethod.id];\n\t\t\t} else {\n\t\t\t\tdocument = await resolver.identityResolve(proofVerificationMethod.id);\n\t\t\t\tdocumentCache[proofVerificationMethod.id] = document;\n\t\t\t}\n\n\t\t\tconst verificationJwk = DocumentHelper.getJwk(document, proofVerificationMethod.id);\n\n\t\t\tconst verified = await ProofHelper.verifyProof(secureDocument, proof, verificationJwk);\n\n\t\t\tif (!verified) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import type { IContextIdHandler } from "@twin.org/context";
2
+ /**
3
+ * Context Id handler for testing as a DID.
4
+ */
5
+ export declare class DidContextIdHandler implements IContextIdHandler {
6
+ /**
7
+ * Runtime name for the class.
8
+ */
9
+ static readonly CLASS_NAME: string;
10
+ /**
11
+ * Get the short form of the DID which is the last part.
12
+ * @param value The full context id value.
13
+ * @returns Short form string.
14
+ */
15
+ short(value: string): string;
16
+ /**
17
+ * Guard the value ensuring length.
18
+ * @param value The value to guard.
19
+ * @throws GeneralError if the value is too short.
20
+ */
21
+ guard(value: string): void;
22
+ }
@@ -1,5 +1,5 @@
1
1
  import { Factory } from "@twin.org/core";
2
- import type { IIdentityConnector } from "../models/IIdentityConnector";
2
+ import type { IIdentityConnector } from "../models/IIdentityConnector.js";
3
3
  /**
4
4
  * Factory for creating identity connectors.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  import { Factory } from "@twin.org/core";
2
- import type { IIdentityProfileConnector } from "../models/IIdentityProfileConnector";
2
+ import type { IIdentityProfileConnector } from "../models/IIdentityProfileConnector.js";
3
3
  /**
4
4
  * Factory for creating identity profile connectors.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  import { Factory } from "@twin.org/core";
2
- import type { IIdentityResolverConnector } from "../models/IIdentityResolverConnector";
2
+ import type { IIdentityResolverConnector } from "../models/IIdentityResolverConnector.js";
3
3
  /**
4
4
  * Factory for creating identity resolver connectors.
5
5
  */
@@ -1,45 +1,46 @@
1
- export * from "./factories/identityConnectorFactory";
2
- export * from "./factories/identityProfileConnectorFactory";
3
- export * from "./factories/identityResolverConnectorFactory";
4
- export * from "./models/api/identity/IIdentityCreateRequest";
5
- export * from "./models/api/identity/IIdentityCreateResponse";
6
- export * from "./models/api/identity/IIdentityProofCreateRequest";
7
- export * from "./models/api/identity/IIdentityProofCreateResponse";
8
- export * from "./models/api/identity/IIdentityProofVerifyRequest";
9
- export * from "./models/api/identity/IIdentityProofVerifyResponse";
10
- export * from "./models/api/identity/IIdentityRemoveRequest";
11
- export * from "./models/api/identity/IIdentityServiceCreateRequest";
12
- export * from "./models/api/identity/IIdentityServiceCreateResponse";
13
- export * from "./models/api/identity/IIdentityServiceRemoveRequest";
14
- export * from "./models/api/identity/IIdentityVerifiableCredentialCreateRequest";
15
- export * from "./models/api/identity/IIdentityVerifiableCredentialCreateResponse";
16
- export * from "./models/api/identity/IIdentityVerifiableCredentialRevokeRequest";
17
- export * from "./models/api/identity/IIdentityVerifiableCredentialUnrevokeRequest";
18
- export * from "./models/api/identity/IIdentityVerifiableCredentialVerifyRequest";
19
- export * from "./models/api/identity/IIdentityVerifiableCredentialVerifyResponse";
20
- export * from "./models/api/identity/IIdentityVerifiablePresentationCreateRequest";
21
- export * from "./models/api/identity/IIdentityVerifiablePresentationCreateResponse";
22
- export * from "./models/api/identity/IIdentityVerifiablePresentationVerifyRequest";
23
- export * from "./models/api/identity/IIdentityVerifiablePresentationVerifyResponse";
24
- export * from "./models/api/identity/IIdentityVerificationMethodCreateRequest";
25
- export * from "./models/api/identity/IIdentityVerificationMethodCreateResponse";
26
- export * from "./models/api/identity/IIdentityVerificationMethodRemoveRequest";
27
- export * from "./models/api/profile/IIdentityProfileCreateRequest";
28
- export * from "./models/api/profile/IIdentityProfileGetPublicRequest";
29
- export * from "./models/api/profile/IIdentityProfileGetPublicResponse";
30
- export * from "./models/api/profile/IIdentityProfileGetRequest";
31
- export * from "./models/api/profile/IIdentityProfileGetResponse";
32
- export * from "./models/api/profile/IIdentityProfileListRequest";
33
- export * from "./models/api/profile/IIdentityProfileListResponse";
34
- export * from "./models/api/profile/IIdentityProfileUpdateRequest";
35
- export * from "./models/api/resolver/IIdentityResolveRequest";
36
- export * from "./models/api/resolver/IIdentityResolveResponse";
37
- export * from "./models/IIdentityComponent";
38
- export * from "./models/IIdentityConnector";
39
- export * from "./models/IIdentityProfileComponent";
40
- export * from "./models/IIdentityProfileConnector";
41
- export * from "./models/IIdentityResolverComponent";
42
- export * from "./models/IIdentityResolverConnector";
43
- export * from "./utils/documentHelper";
44
- export * from "./utils/idHelper";
45
- export * from "./utils/verificationHelper";
1
+ export * from "./contextIdHandlers/didContextIdHandler.js";
2
+ export * from "./factories/identityConnectorFactory.js";
3
+ export * from "./factories/identityProfileConnectorFactory.js";
4
+ export * from "./factories/identityResolverConnectorFactory.js";
5
+ export * from "./models/api/identity/IIdentityCreateRequest.js";
6
+ export * from "./models/api/identity/IIdentityCreateResponse.js";
7
+ export * from "./models/api/identity/IIdentityProofCreateRequest.js";
8
+ export * from "./models/api/identity/IIdentityProofCreateResponse.js";
9
+ export * from "./models/api/identity/IIdentityProofVerifyRequest.js";
10
+ export * from "./models/api/identity/IIdentityProofVerifyResponse.js";
11
+ export * from "./models/api/identity/IIdentityRemoveRequest.js";
12
+ export * from "./models/api/identity/IIdentityServiceCreateRequest.js";
13
+ export * from "./models/api/identity/IIdentityServiceCreateResponse.js";
14
+ export * from "./models/api/identity/IIdentityServiceRemoveRequest.js";
15
+ export * from "./models/api/identity/IIdentityVerifiableCredentialCreateRequest.js";
16
+ export * from "./models/api/identity/IIdentityVerifiableCredentialCreateResponse.js";
17
+ export * from "./models/api/identity/IIdentityVerifiableCredentialRevokeRequest.js";
18
+ export * from "./models/api/identity/IIdentityVerifiableCredentialUnrevokeRequest.js";
19
+ export * from "./models/api/identity/IIdentityVerifiableCredentialVerifyRequest.js";
20
+ export * from "./models/api/identity/IIdentityVerifiableCredentialVerifyResponse.js";
21
+ export * from "./models/api/identity/IIdentityVerifiablePresentationCreateRequest.js";
22
+ export * from "./models/api/identity/IIdentityVerifiablePresentationCreateResponse.js";
23
+ export * from "./models/api/identity/IIdentityVerifiablePresentationVerifyRequest.js";
24
+ export * from "./models/api/identity/IIdentityVerifiablePresentationVerifyResponse.js";
25
+ export * from "./models/api/identity/IIdentityVerificationMethodCreateRequest.js";
26
+ export * from "./models/api/identity/IIdentityVerificationMethodCreateResponse.js";
27
+ export * from "./models/api/identity/IIdentityVerificationMethodRemoveRequest.js";
28
+ export * from "./models/api/profile/IIdentityProfileCreateRequest.js";
29
+ export * from "./models/api/profile/IIdentityProfileGetPublicRequest.js";
30
+ export * from "./models/api/profile/IIdentityProfileGetPublicResponse.js";
31
+ export * from "./models/api/profile/IIdentityProfileGetRequest.js";
32
+ export * from "./models/api/profile/IIdentityProfileGetResponse.js";
33
+ export * from "./models/api/profile/IIdentityProfileListRequest.js";
34
+ export * from "./models/api/profile/IIdentityProfileListResponse.js";
35
+ export * from "./models/api/profile/IIdentityProfileUpdateRequest.js";
36
+ export * from "./models/api/resolver/IIdentityResolveRequest.js";
37
+ export * from "./models/api/resolver/IIdentityResolveResponse.js";
38
+ export * from "./models/IIdentityComponent.js";
39
+ export * from "./models/IIdentityConnector.js";
40
+ export * from "./models/IIdentityProfileComponent.js";
41
+ export * from "./models/IIdentityProfileConnector.js";
42
+ export * from "./models/IIdentityResolverComponent.js";
43
+ export * from "./models/IIdentityResolverConnector.js";
44
+ export * from "./types/did.js";
45
+ export * from "./utils/documentHelper.js";
46
+ export * from "./utils/verificationHelper.js";
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Helper methods for Ids.
3
+ */
4
+ export declare class Did {
5
+ /**
6
+ * Runtime name for the class.
7
+ */
8
+ static readonly CLASS_NAME: string;
9
+ /**
10
+ * Parse and id in to it's constituent parts.
11
+ * @param id The id to parse.
12
+ * @returns The parsed id.
13
+ * @throws GeneralError if the id is not valid.
14
+ */
15
+ static parse(id: string): {
16
+ method: string;
17
+ network?: string | undefined;
18
+ id: string;
19
+ };
20
+ /**
21
+ * Guard a string as a DID.
22
+ * @param source The source of the error.
23
+ * @param property The name of the property.
24
+ * @param value The urn to parse.
25
+ * @throws GuardError If the value does not match the assertion.
26
+ */
27
+ static guard(source: string, property: string, value: unknown): asserts value is string;
28
+ }
@@ -1,6 +1,6 @@
1
1
  import type { IJsonLdNodeObject } from "@twin.org/data-json-ld";
2
2
  import { type IJwtHeader, type IJwtPayload } from "@twin.org/web";
3
- import type { IIdentityResolverComponent } from "../models/IIdentityResolverComponent";
3
+ import type { IIdentityResolverComponent } from "../models/IIdentityResolverComponent.js";
4
4
  /**
5
5
  * Helper methods for verification.
6
6
  */
package/docs/changelog.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # @twin.org/identity-service-models - Changelog
2
2
 
3
+ ## [0.0.3-next.2](https://github.com/twinfoundation/identity/compare/identity-models-v0.0.3-next.1...identity-models-v0.0.3-next.2) (2025-11-14)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * use base64Url for tenant id short form so it doesn't include slash ([53b9e27](https://github.com/twinfoundation/identity/commit/53b9e27351f20e2689734581c252a23527657926))
9
+
10
+ ## [0.0.3-next.1](https://github.com/twinfoundation/identity/compare/identity-models-v0.0.3-next.0...identity-models-v0.0.3-next.1) (2025-11-11)
11
+
12
+
13
+ ### Features
14
+
15
+ * add context id features ([#62](https://github.com/twinfoundation/identity/issues/62)) ([e02ecca](https://github.com/twinfoundation/identity/commit/e02ecca9c45a849104bfbf7bc18a1f44e6eea8a1))
16
+ * add expiration date option to vc creation ([73e05e1](https://github.com/twinfoundation/identity/commit/73e05e1ae61112c7e056889969751f4ff82d9f29))
17
+ * add identity remove ([eebc13f](https://github.com/twinfoundation/identity/commit/eebc13f4c2cd994d2d9cce4da2128fb346c80ba7))
18
+ * add idHelper class ([57c8bdb](https://github.com/twinfoundation/identity/commit/57c8bdb81efaa163b5e83f8a7f16f3764d12fd75))
19
+ * add validate-locales ([04d74b4](https://github.com/twinfoundation/identity/commit/04d74b4d1ebe42672e8ca75a7bdb8e3556afd0be))
20
+ * eslint migration to flat config ([fd6246d](https://github.com/twinfoundation/identity/commit/fd6246d566280b6d5d10a108eb1e92c4b510f2f2))
21
+ * identity key separator use slash ([1319d0d](https://github.com/twinfoundation/identity/commit/1319d0d07164a36b3ec279e6421b8835ffefc3d3))
22
+ * update framework core ([c824497](https://github.com/twinfoundation/identity/commit/c82449709af0215eb7af496cf687c93fb30b5ae0))
23
+ * use shared store mechanism ([#27](https://github.com/twinfoundation/identity/issues/27)) ([ce41f3f](https://github.com/twinfoundation/identity/commit/ce41f3fc3da1b206ec06da7ea5b2c968f788804d))
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * Import path and bump version ([#21](https://github.com/twinfoundation/identity/issues/21)) ([ccea845](https://github.com/twinfoundation/identity/commit/ccea845bf32562267280bc1b3dde1c9af1a00360))
29
+ * Install sdk-wasm ([#20](https://github.com/twinfoundation/identity/issues/20)) ([75ec14e](https://github.com/twinfoundation/identity/commit/75ec14e072f8c219863a1c028a3b0783802086e9))
30
+ * query params force coercion ([d9347d2](https://github.com/twinfoundation/identity/commit/d9347d29d4a9cc58759f30f5d8526de864ea7522))
31
+ * Use resolver component ([#22](https://github.com/twinfoundation/identity/issues/22)) ([d0b3a32](https://github.com/twinfoundation/identity/commit/d0b3a321c7f9f966d397a880d752e9f2c0a98a27))
32
+
33
+ ## [0.0.2-next.10](https://github.com/twinfoundation/identity/compare/identity-models-v0.0.2-next.9...identity-models-v0.0.2-next.10) (2025-10-27)
34
+
35
+
36
+ ### Miscellaneous Chores
37
+
38
+ * **identity-models:** Synchronize repo versions
39
+
3
40
  ## [0.0.2-next.9](https://github.com/twinfoundation/identity/compare/identity-models-v0.0.2-next.8...identity-models-v0.0.2-next.9) (2025-10-09)
4
41
 
5
42
 
@@ -1,4 +1,4 @@
1
- # Class: IdHelper
1
+ # Class: Did
2
2
 
3
3
  Helper methods for Ids.
4
4
 
@@ -6,11 +6,11 @@ Helper methods for Ids.
6
6
 
7
7
  ### Constructor
8
8
 
9
- > **new IdHelper**(): `IdHelper`
9
+ > **new Did**(): `Did`
10
10
 
11
11
  #### Returns
12
12
 
13
- `IdHelper`
13
+ `Did`
14
14
 
15
15
  ## Properties
16
16
 
@@ -22,9 +22,9 @@ Runtime name for the class.
22
22
 
23
23
  ## Methods
24
24
 
25
- ### parseId()
25
+ ### parse()
26
26
 
27
- > `static` **parseId**(`id`): `object`
27
+ > `static` **parse**(`id`): `object`
28
28
 
29
29
  Parse and id in to it's constituent parts.
30
30
 
@@ -57,3 +57,39 @@ The parsed id.
57
57
  #### Throws
58
58
 
59
59
  GeneralError if the id is not valid.
60
+
61
+ ***
62
+
63
+ ### guard()
64
+
65
+ > `static` **guard**(`source`, `property`, `value`): `asserts value is string`
66
+
67
+ Guard a string as a DID.
68
+
69
+ #### Parameters
70
+
71
+ ##### source
72
+
73
+ `string`
74
+
75
+ The source of the error.
76
+
77
+ ##### property
78
+
79
+ `string`
80
+
81
+ The name of the property.
82
+
83
+ ##### value
84
+
85
+ `unknown`
86
+
87
+ The urn to parse.
88
+
89
+ #### Returns
90
+
91
+ `asserts value is string`
92
+
93
+ #### Throws
94
+
95
+ GuardError If the value does not match the assertion.