@twin.org/identity-models 0.0.2-next.7 → 0.0.2-next.8

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.
@@ -118,6 +118,46 @@ class DocumentHelper {
118
118
  }
119
119
  }
120
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
+
121
161
  // Copyright 2024 IOTA Stiftung.
122
162
  // SPDX-License-Identifier: Apache-2.0.
123
163
  /**
@@ -194,6 +234,7 @@ class VerificationHelper {
194
234
  }
195
235
 
196
236
  exports.DocumentHelper = DocumentHelper;
237
+ exports.IdHelper = IdHelper;
197
238
  exports.IdentityConnectorFactory = IdentityConnectorFactory;
198
239
  exports.IdentityProfileConnectorFactory = IdentityProfileConnectorFactory;
199
240
  exports.IdentityResolverConnectorFactory = IdentityResolverConnectorFactory;
@@ -1,4 +1,4 @@
1
- import { Factory, Is, GeneralError, Guards } from '@twin.org/core';
1
+ import { Factory, Is, GeneralError, Urn, Guards } from '@twin.org/core';
2
2
  import { DidVerificationMethodType, ProofHelper } from '@twin.org/standards-w3c-did';
3
3
  import { Jwt, Jwk } from '@twin.org/web';
4
4
 
@@ -116,6 +116,46 @@ class DocumentHelper {
116
116
  }
117
117
  }
118
118
 
119
+ // Copyright 2024 IOTA Stiftung.
120
+ // SPDX-License-Identifier: Apache-2.0.
121
+ /**
122
+ * Helper methods for Ids.
123
+ */
124
+ class IdHelper {
125
+ /**
126
+ * Runtime name for the class.
127
+ */
128
+ static CLASS_NAME = "IdHelper";
129
+ /**
130
+ * Parse and id in to it's constituent parts.
131
+ * @param id The id to parse.
132
+ * @returns The parsed id.
133
+ * @throws GeneralError if the id is not valid.
134
+ */
135
+ static parseId(id) {
136
+ Urn.guard(IdHelper.CLASS_NAME, "id", id);
137
+ const didUrn = Urn.fromValidString(id);
138
+ const didParts = didUrn.parts();
139
+ if (didParts[0] !== "did") {
140
+ throw new GeneralError(IdHelper.CLASS_NAME, "invalidDocumentId", { id });
141
+ }
142
+ if (didParts.length === 3) {
143
+ return {
144
+ method: didParts[1],
145
+ id: didParts[2]
146
+ };
147
+ }
148
+ else if (didParts.length === 4) {
149
+ return {
150
+ method: didParts[1],
151
+ network: didParts[2],
152
+ id: didParts[3]
153
+ };
154
+ }
155
+ throw new GeneralError(IdHelper.CLASS_NAME, "invalidDocumentId", { id });
156
+ }
157
+ }
158
+
119
159
  // Copyright 2024 IOTA Stiftung.
120
160
  // SPDX-License-Identifier: Apache-2.0.
121
161
  /**
@@ -191,4 +231,4 @@ class VerificationHelper {
191
231
  }
192
232
  }
193
233
 
194
- export { DocumentHelper, IdentityConnectorFactory, IdentityProfileConnectorFactory, IdentityResolverConnectorFactory, VerificationHelper };
234
+ export { DocumentHelper, IdHelper, IdentityConnectorFactory, IdentityProfileConnectorFactory, IdentityResolverConnectorFactory, VerificationHelper };
@@ -41,4 +41,5 @@ export * from "./models/IIdentityProfileConnector";
41
41
  export * from "./models/IIdentityResolverComponent";
42
42
  export * from "./models/IIdentityResolverConnector";
43
43
  export * from "./utils/documentHelper";
44
+ export * from "./utils/idHelper";
44
45
  export * from "./utils/verificationHelper";
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Helper methods for Ids.
3
+ */
4
+ export declare class IdHelper {
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 parseId(id: string): {
16
+ method: string;
17
+ network?: string | undefined;
18
+ id: string;
19
+ };
20
+ }
package/docs/changelog.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @twin.org/identity-service-models - Changelog
2
2
 
3
+ ## [0.0.2-next.8](https://github.com/twinfoundation/identity/compare/identity-models-v0.0.2-next.7...identity-models-v0.0.2-next.8) (2025-09-25)
4
+
5
+
6
+ ### Features
7
+
8
+ * add idHelper class ([57c8bdb](https://github.com/twinfoundation/identity/commit/57c8bdb81efaa163b5e83f8a7f16f3764d12fd75))
9
+
3
10
  ## [0.0.2-next.7](https://github.com/twinfoundation/identity/compare/identity-models-v0.0.2-next.6...identity-models-v0.0.2-next.7) (2025-09-23)
4
11
 
5
12
 
@@ -0,0 +1,59 @@
1
+ # Class: IdHelper
2
+
3
+ Helper methods for Ids.
4
+
5
+ ## Constructors
6
+
7
+ ### Constructor
8
+
9
+ > **new IdHelper**(): `IdHelper`
10
+
11
+ #### Returns
12
+
13
+ `IdHelper`
14
+
15
+ ## Properties
16
+
17
+ ### CLASS\_NAME
18
+
19
+ > `readonly` `static` **CLASS\_NAME**: `string`
20
+
21
+ Runtime name for the class.
22
+
23
+ ## Methods
24
+
25
+ ### parseId()
26
+
27
+ > `static` **parseId**(`id`): `object`
28
+
29
+ Parse and id in to it's constituent parts.
30
+
31
+ #### Parameters
32
+
33
+ ##### id
34
+
35
+ `string`
36
+
37
+ The id to parse.
38
+
39
+ #### Returns
40
+
41
+ `object`
42
+
43
+ The parsed id.
44
+
45
+ ##### method
46
+
47
+ > **method**: `string`
48
+
49
+ ##### network?
50
+
51
+ > `optional` **network**: `string`
52
+
53
+ ##### id
54
+
55
+ > **id**: `string`
56
+
57
+ #### Throws
58
+
59
+ GeneralError if the id is not valid.
@@ -3,6 +3,7 @@
3
3
  ## Classes
4
4
 
5
5
  - [DocumentHelper](classes/DocumentHelper.md)
6
+ - [IdHelper](classes/IdHelper.md)
6
7
  - [VerificationHelper](classes/VerificationHelper.md)
7
8
 
8
9
  ## Interfaces
package/locales/en.json CHANGED
@@ -8,6 +8,9 @@
8
8
  "documentHelper": {
9
9
  "verificationMethodNotFound": "The verification method \"{methodName}\" of type \"{methodType}\" could not be found",
10
10
  "verificationMethodJwkNotFound": "The verification method \"{methodName}\" of type \"{methodType}\" is missing the JWK"
11
+ },
12
+ "idHelper": {
13
+ "invalidDocumentId": "The document id \"{id}\" is invalid"
11
14
  }
12
15
  },
13
16
  "verifiableCredentialStates": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/identity-models",
3
- "version": "0.0.2-next.7",
3
+ "version": "0.0.2-next.8",
4
4
  "description": "Models which define the structure of the contracts and connectors",
5
5
  "repository": {
6
6
  "type": "git",