@twin.org/identity-connector-universal 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 CHANGED
@@ -1,6 +1,6 @@
1
- # TWIN Identity Connector Universal
1
+ # TWIN Identity
2
2
 
3
- Identity connector implementation using Universal resolver.
3
+ The identity-connector-universal package provides DID resolution through the Universal Resolver ecosystem so applications can work with multiple DID methods in a consistent way. It is designed for interoperability-focused implementations that need standards-aligned identity resolution without coupling to a single network.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,12 +8,12 @@ Identity connector implementation using Universal resolver.
8
8
  npm install @twin.org/identity-connector-universal
9
9
  ```
10
10
 
11
- ## Testing
11
+ ## Docker
12
12
 
13
- To test the universal resolver you will need to run the docker image.
13
+ To perform testing of this component it may be necessary to launch a local instance to communicate with.
14
14
 
15
15
  ```shell
16
- docker run -d --name twin-identity-universal -e NETWORK=testnet -p 8180:8080 iotaledger/uni-resolver-driver-iota:v0.2.0-alpha
16
+ docker run -d --name twin-identity-universal -p 18180:8080 -e NETWORK=testnet iotaledger/uni-resolver-driver-iota:v0.2.0-alpha
17
17
  ```
18
18
 
19
19
  ## Examples
@@ -1 +1 @@
1
- {"version":3,"file":"IUniversalResolverResult.js","sourceRoot":"","sources":["../../../../src/models/api/IUniversalResolverResult.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 * Universal Resolver DIF resolution result\n */\nexport interface IUniversalResolverResult {\n\t/**\n\t * DID Document resolved.\n\t */\n\tdidDocument: IDidDocument;\n\n\t/**\n\t * Resolution metadata\n\t */\n\tdidResolutionMetadata: {\n\t\t/**\n\t\t * The created date of the did document.\n\t\t */\n\t\tcreated: string;\n\n\t\t/**\n\t\t * The updated date of the did document.\n\t\t */\n\t\tupdated: string;\n\t};\n\n\t/**\n\t * DID Document metadata\n\t */\n\tdidDocumentMetadata: unknown;\n}\n"]}
1
+ {"version":3,"file":"IUniversalResolverResult.js","sourceRoot":"","sources":["../../../../src/models/api/IUniversalResolverResult.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 * Result returned by a Universal Resolver DIF resolution request.\n */\nexport interface IUniversalResolverResult {\n\t/**\n\t * The resolved DID document.\n\t */\n\tdidDocument: IDidDocument;\n\n\t/**\n\t * Metadata about the resolution process.\n\t */\n\tdidResolutionMetadata: {\n\t\t/**\n\t\t * The created date of the DID document.\n\t\t */\n\t\tcreated: string;\n\n\t\t/**\n\t\t * The updated date of the DID document.\n\t\t */\n\t\tupdated: string;\n\t};\n\n\t/**\n\t * Metadata about the DID document.\n\t */\n\tdidDocumentMetadata: unknown;\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  // Copyright 2024 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
- import { GeneralError, Guards, StringHelper } from "@twin.org/core";
3
+ import { GeneralError, Guards, HealthStatus, StringHelper } from "@twin.org/core";
4
4
  import { FetchHelper, HttpMethod } from "@twin.org/web";
5
5
  /**
6
6
  * Class for performing identity operations on a universal resolver.
@@ -36,6 +36,46 @@ export class UniversalResolverConnector {
36
36
  className() {
37
37
  return UniversalResolverConnector.CLASS_NAME;
38
38
  }
39
+ /**
40
+ * Returns the health status of the component.
41
+ * @returns The health status of the component.
42
+ */
43
+ async health() {
44
+ try {
45
+ const response = await FetchHelper.fetch(UniversalResolverConnector.CLASS_NAME, `${StringHelper.trimTrailingSlashes(this._resolverEndpoint)}/1.0/identifiers/did:iota:0`, HttpMethod.GET);
46
+ const body = await response.text();
47
+ if (!body.includes("invalid method id")) {
48
+ return [
49
+ {
50
+ source: UniversalResolverConnector.CLASS_NAME,
51
+ status: HealthStatus.Error,
52
+ description: "healthDescription",
53
+ message: "resolverHealthCheckFailed",
54
+ data: { endpoint: this._resolverEndpoint }
55
+ }
56
+ ];
57
+ }
58
+ return [
59
+ {
60
+ source: UniversalResolverConnector.CLASS_NAME,
61
+ status: HealthStatus.Ok,
62
+ description: "healthDescription",
63
+ data: { endpoint: this._resolverEndpoint }
64
+ }
65
+ ];
66
+ }
67
+ catch {
68
+ return [
69
+ {
70
+ source: UniversalResolverConnector.CLASS_NAME,
71
+ status: HealthStatus.Error,
72
+ description: "healthDescription",
73
+ message: "resolverHealthCheckFailed",
74
+ data: { endpoint: this._resolverEndpoint }
75
+ }
76
+ ];
77
+ }
78
+ }
39
79
  /**
40
80
  * Resolve a document from its id.
41
81
  * @param documentId The id of the document to resolve.
@@ -1 +1 @@
1
- {"version":3,"file":"universalResolverConnector.js","sourceRoot":"","sources":["../../src/universalResolverConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAIpE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAKxD;;GAEG;AACH,MAAM,OAAO,0BAA0B;IACtC;;OAEG;IACI,MAAM,CAAU,SAAS,GAAW,WAAW,CAAC;IAEvD;;OAEG;IACI,MAAM,CAAU,UAAU,gCAAgD;IAEjF;;;OAGG;IACc,iBAAiB,CAAS;IAE3C;;;OAGG;IACH,YAAY,OAAsD;QACjE,MAAM,CAAC,MAAM,CAAC,0BAA0B,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QAC/E,MAAM,CAAC,MAAM,CACZ,0BAA0B,CAAC,UAAU,oBAErC,OAAO,CAAC,MAAM,CACd,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,0BAA0B,CAAC,UAAU,6BAErC,OAAO,CAAC,MAAM,CAAC,QAAQ,CACvB,CAAC;QAEF,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;IAClD,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,0BAA0B,CAAC,UAAU,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,eAAe,CAAC,UAAkB;QAC9C,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,SAAS,CACzC,0BAA0B,CAAC,UAAU,EACrC,GAAG,YAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,kBAAkB,CAAC,UAAU,CAAC,EAAE,EAC/G,UAAU,CAAC,GAAG,CACd,CAAC;YAEF,OAAO,MAAM,CAAC,WAAW,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,YAAY,CACrB,0BAA0B,CAAC,UAAU,EACrC,uBAAuB,EACvB,EAAE,UAAU,EAAE,EACd,KAAK,CACL,CAAC;QACH,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, StringHelper } from \"@twin.org/core\";\nimport type { IIdentityResolverConnector } from \"@twin.org/identity-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IDidDocument } from \"@twin.org/standards-w3c-did\";\nimport { FetchHelper, HttpMethod } from \"@twin.org/web\";\nimport type { IUniversalResolverResult } from \"./models/api/IUniversalResolverResult.js\";\nimport type { IUniversalResolverConnectorConfig } from \"./models/IUniversalResolverConnectorConfig.js\";\nimport type { IUniversalResolverConnectorConstructorOptions } from \"./models/IUniversalResolverConnectorConstructorOptions.js\";\n\n/**\n * Class for performing identity operations on a universal resolver.\n */\nexport class UniversalResolverConnector implements IIdentityResolverConnector {\n\t/**\n\t * The namespace supported by the identity connector.\n\t */\n\tpublic static readonly NAMESPACE: string = \"universal\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<UniversalResolverConnector>();\n\n\t/**\n\t * The url for the resolver.\n\t * @internal\n\t */\n\tprivate readonly _resolverEndpoint: string;\n\n\t/**\n\t * Create a new instance of UniversalResolverConnector.\n\t * @param options The options for the identity connector.\n\t */\n\tconstructor(options: IUniversalResolverConnectorConstructorOptions) {\n\t\tGuards.object(UniversalResolverConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.object<IUniversalResolverConnectorConfig>(\n\t\t\tUniversalResolverConnector.CLASS_NAME,\n\t\t\tnameof(options.config),\n\t\t\toptions.config\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tUniversalResolverConnector.CLASS_NAME,\n\t\t\tnameof(options.config.endpoint),\n\t\t\toptions.config.endpoint\n\t\t);\n\n\t\tthis._resolverEndpoint = options.config.endpoint;\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 UniversalResolverConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Resolve a document from its id.\n\t * @param documentId The id of the document to resolve.\n\t * @returns The resolved document.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async resolveDocument(documentId: string): Promise<IDidDocument> {\n\t\ttry {\n\t\t\tconst result = await FetchHelper.fetchJson<never, IUniversalResolverResult>(\n\t\t\t\tUniversalResolverConnector.CLASS_NAME,\n\t\t\t\t`${StringHelper.trimTrailingSlashes(this._resolverEndpoint)}/1.0/identifiers/${encodeURIComponent(documentId)}`,\n\t\t\t\tHttpMethod.GET\n\t\t\t);\n\n\t\t\treturn result.didDocument;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tUniversalResolverConnector.CLASS_NAME,\n\t\t\t\t\"resolveDocumentFailed\",\n\t\t\t\t{ documentId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"universalResolverConnector.js","sourceRoot":"","sources":["../../src/universalResolverConnector.ts"],"names":[],"mappings":"AAAA,gCAAgC;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import { GeneralError, Guards, HealthStatus, StringHelper, type IHealth } from \"@twin.org/core\";\nimport type { IIdentityResolverConnector } from \"@twin.org/identity-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IDidDocument } from \"@twin.org/standards-w3c-did\";\nimport { FetchHelper, HttpMethod } from \"@twin.org/web\";\nimport type { IUniversalResolverResult } from \"./models/api/IUniversalResolverResult.js\";\nimport type { IUniversalResolverConnectorConfig } from \"./models/IUniversalResolverConnectorConfig.js\";\nimport type { IUniversalResolverConnectorConstructorOptions } from \"./models/IUniversalResolverConnectorConstructorOptions.js\";\n\n/**\n * Class for performing identity operations on a universal resolver.\n */\nexport class UniversalResolverConnector implements IIdentityResolverConnector {\n\t/**\n\t * The namespace supported by the identity connector.\n\t */\n\tpublic static readonly NAMESPACE: string = \"universal\";\n\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<UniversalResolverConnector>();\n\n\t/**\n\t * The url for the resolver.\n\t * @internal\n\t */\n\tprivate readonly _resolverEndpoint: string;\n\n\t/**\n\t * Create a new instance of UniversalResolverConnector.\n\t * @param options The options for the identity connector.\n\t */\n\tconstructor(options: IUniversalResolverConnectorConstructorOptions) {\n\t\tGuards.object(UniversalResolverConnector.CLASS_NAME, nameof(options), options);\n\t\tGuards.object<IUniversalResolverConnectorConfig>(\n\t\t\tUniversalResolverConnector.CLASS_NAME,\n\t\t\tnameof(options.config),\n\t\t\toptions.config\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tUniversalResolverConnector.CLASS_NAME,\n\t\t\tnameof(options.config.endpoint),\n\t\t\toptions.config.endpoint\n\t\t);\n\n\t\tthis._resolverEndpoint = options.config.endpoint;\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 UniversalResolverConnector.CLASS_NAME;\n\t}\n\n\t/**\n\t * Returns the health status of the component.\n\t * @returns The health status of the component.\n\t */\n\tpublic async health(): Promise<IHealth[]> {\n\t\ttry {\n\t\t\tconst response = await FetchHelper.fetch(\n\t\t\t\tUniversalResolverConnector.CLASS_NAME,\n\t\t\t\t`${StringHelper.trimTrailingSlashes(this._resolverEndpoint)}/1.0/identifiers/did:iota:0`,\n\t\t\t\tHttpMethod.GET\n\t\t\t);\n\n\t\t\tconst body = await response.text();\n\n\t\t\tif (!body.includes(\"invalid method id\")) {\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\tsource: UniversalResolverConnector.CLASS_NAME,\n\t\t\t\t\t\tstatus: HealthStatus.Error,\n\t\t\t\t\t\tdescription: \"healthDescription\",\n\t\t\t\t\t\tmessage: \"resolverHealthCheckFailed\",\n\t\t\t\t\t\tdata: { endpoint: this._resolverEndpoint }\n\t\t\t\t\t}\n\t\t\t\t];\n\t\t\t}\n\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tsource: UniversalResolverConnector.CLASS_NAME,\n\t\t\t\t\tstatus: HealthStatus.Ok,\n\t\t\t\t\tdescription: \"healthDescription\",\n\t\t\t\t\tdata: { endpoint: this._resolverEndpoint }\n\t\t\t\t}\n\t\t\t];\n\t\t} catch {\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\tsource: UniversalResolverConnector.CLASS_NAME,\n\t\t\t\t\tstatus: HealthStatus.Error,\n\t\t\t\t\tdescription: \"healthDescription\",\n\t\t\t\t\tmessage: \"resolverHealthCheckFailed\",\n\t\t\t\t\tdata: { endpoint: this._resolverEndpoint }\n\t\t\t\t}\n\t\t\t];\n\t\t}\n\t}\n\n\t/**\n\t * Resolve a document from its id.\n\t * @param documentId The id of the document to resolve.\n\t * @returns The resolved document.\n\t * @throws NotFoundError if the id can not be resolved.\n\t */\n\tpublic async resolveDocument(documentId: string): Promise<IDidDocument> {\n\t\ttry {\n\t\t\tconst result = await FetchHelper.fetchJson<never, IUniversalResolverResult>(\n\t\t\t\tUniversalResolverConnector.CLASS_NAME,\n\t\t\t\t`${StringHelper.trimTrailingSlashes(this._resolverEndpoint)}/1.0/identifiers/${encodeURIComponent(documentId)}`,\n\t\t\t\tHttpMethod.GET\n\t\t\t);\n\n\t\t\treturn result.didDocument;\n\t\t} catch (error) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tUniversalResolverConnector.CLASS_NAME,\n\t\t\t\t\"resolveDocumentFailed\",\n\t\t\t\t{ documentId },\n\t\t\t\terror\n\t\t\t);\n\t\t}\n\t}\n}\n"]}
@@ -1,27 +1,27 @@
1
1
  import type { IDidDocument } from "@twin.org/standards-w3c-did";
2
2
  /**
3
- * Universal Resolver DIF resolution result
3
+ * Result returned by a Universal Resolver DIF resolution request.
4
4
  */
5
5
  export interface IUniversalResolverResult {
6
6
  /**
7
- * DID Document resolved.
7
+ * The resolved DID document.
8
8
  */
9
9
  didDocument: IDidDocument;
10
10
  /**
11
- * Resolution metadata
11
+ * Metadata about the resolution process.
12
12
  */
13
13
  didResolutionMetadata: {
14
14
  /**
15
- * The created date of the did document.
15
+ * The created date of the DID document.
16
16
  */
17
17
  created: string;
18
18
  /**
19
- * The updated date of the did document.
19
+ * The updated date of the DID document.
20
20
  */
21
21
  updated: string;
22
22
  };
23
23
  /**
24
- * DID Document metadata
24
+ * Metadata about the DID document.
25
25
  */
26
26
  didDocumentMetadata: unknown;
27
27
  }
@@ -1,3 +1,4 @@
1
+ import { type IHealth } from "@twin.org/core";
1
2
  import type { IIdentityResolverConnector } from "@twin.org/identity-models";
2
3
  import type { IDidDocument } from "@twin.org/standards-w3c-did";
3
4
  import type { IUniversalResolverConnectorConstructorOptions } from "./models/IUniversalResolverConnectorConstructorOptions.js";
@@ -23,6 +24,11 @@ export declare class UniversalResolverConnector implements IIdentityResolverConn
23
24
  * @returns The class name of the component.
24
25
  */
25
26
  className(): string;
27
+ /**
28
+ * Returns the health status of the component.
29
+ * @returns The health status of the component.
30
+ */
31
+ health(): Promise<IHealth[]>;
26
32
  /**
27
33
  * Resolve a document from its id.
28
34
  * @param documentId The id of the document to resolve.