@enbox/dids 0.0.1

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 (104) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1 -0
  3. package/dist/browser.js +77 -0
  4. package/dist/browser.js.map +7 -0
  5. package/dist/browser.mjs +77 -0
  6. package/dist/browser.mjs.map +7 -0
  7. package/dist/cjs/index.js +6303 -0
  8. package/dist/cjs/index.js.map +7 -0
  9. package/dist/cjs/package.json +1 -0
  10. package/dist/cjs/utils.js +245 -0
  11. package/dist/cjs/utils.js.map +7 -0
  12. package/dist/esm/bearer-did.js +201 -0
  13. package/dist/esm/bearer-did.js.map +1 -0
  14. package/dist/esm/did-error.js +62 -0
  15. package/dist/esm/did-error.js.map +1 -0
  16. package/dist/esm/did.js +114 -0
  17. package/dist/esm/did.js.map +1 -0
  18. package/dist/esm/index.js +16 -0
  19. package/dist/esm/index.js.map +1 -0
  20. package/dist/esm/methods/did-dht.js +1241 -0
  21. package/dist/esm/methods/did-dht.js.map +1 -0
  22. package/dist/esm/methods/did-ion.js +570 -0
  23. package/dist/esm/methods/did-ion.js.map +1 -0
  24. package/dist/esm/methods/did-jwk.js +298 -0
  25. package/dist/esm/methods/did-jwk.js.map +1 -0
  26. package/dist/esm/methods/did-key.js +983 -0
  27. package/dist/esm/methods/did-key.js.map +1 -0
  28. package/dist/esm/methods/did-method.js +53 -0
  29. package/dist/esm/methods/did-method.js.map +1 -0
  30. package/dist/esm/methods/did-web.js +83 -0
  31. package/dist/esm/methods/did-web.js.map +1 -0
  32. package/dist/esm/resolver/resolver-cache-level.js +101 -0
  33. package/dist/esm/resolver/resolver-cache-level.js.map +1 -0
  34. package/dist/esm/resolver/resolver-cache-noop.js +24 -0
  35. package/dist/esm/resolver/resolver-cache-noop.js.map +1 -0
  36. package/dist/esm/resolver/universal-resolver.js +187 -0
  37. package/dist/esm/resolver/universal-resolver.js.map +1 -0
  38. package/dist/esm/types/did-core.js +51 -0
  39. package/dist/esm/types/did-core.js.map +1 -0
  40. package/dist/esm/types/did-resolution.js +12 -0
  41. package/dist/esm/types/did-resolution.js.map +1 -0
  42. package/dist/esm/types/multibase.js +2 -0
  43. package/dist/esm/types/multibase.js.map +1 -0
  44. package/dist/esm/types/portable-did.js +2 -0
  45. package/dist/esm/types/portable-did.js.map +1 -0
  46. package/dist/esm/utils.js +458 -0
  47. package/dist/esm/utils.js.map +1 -0
  48. package/dist/types/bearer-did.d.ts +143 -0
  49. package/dist/types/bearer-did.d.ts.map +1 -0
  50. package/dist/types/did-error.d.ts +50 -0
  51. package/dist/types/did-error.d.ts.map +1 -0
  52. package/dist/types/did.d.ts +125 -0
  53. package/dist/types/did.d.ts.map +1 -0
  54. package/dist/types/index.d.ts +18 -0
  55. package/dist/types/index.d.ts.map +1 -0
  56. package/dist/types/methods/did-dht.d.ts +682 -0
  57. package/dist/types/methods/did-dht.d.ts.map +1 -0
  58. package/dist/types/methods/did-ion.d.ts +492 -0
  59. package/dist/types/methods/did-ion.d.ts.map +1 -0
  60. package/dist/types/methods/did-jwk.d.ts +236 -0
  61. package/dist/types/methods/did-jwk.d.ts.map +1 -0
  62. package/dist/types/methods/did-key.d.ts +499 -0
  63. package/dist/types/methods/did-key.d.ts.map +1 -0
  64. package/dist/types/methods/did-method.d.ts +238 -0
  65. package/dist/types/methods/did-method.d.ts.map +1 -0
  66. package/dist/types/methods/did-web.d.ts +37 -0
  67. package/dist/types/methods/did-web.d.ts.map +1 -0
  68. package/dist/types/resolver/resolver-cache-level.d.ts +86 -0
  69. package/dist/types/resolver/resolver-cache-level.d.ts.map +1 -0
  70. package/dist/types/resolver/resolver-cache-noop.d.ts +9 -0
  71. package/dist/types/resolver/resolver-cache-noop.d.ts.map +1 -0
  72. package/dist/types/resolver/universal-resolver.d.ts +109 -0
  73. package/dist/types/resolver/universal-resolver.d.ts.map +1 -0
  74. package/dist/types/types/did-core.d.ts +523 -0
  75. package/dist/types/types/did-core.d.ts.map +1 -0
  76. package/dist/types/types/did-resolution.d.ts +85 -0
  77. package/dist/types/types/did-resolution.d.ts.map +1 -0
  78. package/dist/types/types/multibase.d.ts +28 -0
  79. package/dist/types/types/multibase.d.ts.map +1 -0
  80. package/dist/types/types/portable-did.d.ts +59 -0
  81. package/dist/types/types/portable-did.d.ts.map +1 -0
  82. package/dist/types/utils.d.ts +378 -0
  83. package/dist/types/utils.d.ts.map +1 -0
  84. package/dist/utils.js +28 -0
  85. package/dist/utils.js.map +7 -0
  86. package/package.json +116 -0
  87. package/src/bearer-did.ts +287 -0
  88. package/src/did-error.ts +75 -0
  89. package/src/did.ts +186 -0
  90. package/src/index.ts +21 -0
  91. package/src/methods/did-dht.ts +1637 -0
  92. package/src/methods/did-ion.ts +887 -0
  93. package/src/methods/did-jwk.ts +410 -0
  94. package/src/methods/did-key.ts +1248 -0
  95. package/src/methods/did-method.ts +276 -0
  96. package/src/methods/did-web.ts +96 -0
  97. package/src/resolver/resolver-cache-level.ts +163 -0
  98. package/src/resolver/resolver-cache-noop.ts +26 -0
  99. package/src/resolver/universal-resolver.ts +238 -0
  100. package/src/types/did-core.ts +580 -0
  101. package/src/types/did-resolution.ts +93 -0
  102. package/src/types/multibase.ts +29 -0
  103. package/src/types/portable-did.ts +64 -0
  104. package/src/utils.ts +532 -0
@@ -0,0 +1,238 @@
1
+ import type { CryptoApi, LocalKeyManager, InferKeyGeneratorAlgorithm } from '@enbox/crypto';
2
+ import type { BearerDid } from '../bearer-did.js';
3
+ import type { DidMetadata } from '../types/portable-did.js';
4
+ import type { DidDocument, DidResolutionResult, DidResolutionOptions, DidVerificationMethod } from '../types/did-core.js';
5
+ import { DidVerificationRelationship } from '../types/did-core.js';
6
+ /**
7
+ * Represents options during the creation of a Decentralized Identifier (DID).
8
+ *
9
+ * Implementations of this interface may contain properties and methods that provide specific
10
+ * options or metadata during the DID creation processes following specific DID method
11
+ * specifications.
12
+ */
13
+ export interface DidCreateOptions<TKms> {
14
+ /**
15
+ * Optional. An array of verification methods to be included in the DID document.
16
+ */
17
+ verificationMethods?: DidCreateVerificationMethod<TKms>[];
18
+ }
19
+ /**
20
+ * Options for additional verification methods added to the DID Document during the creation of a
21
+ * new Decentralized Identifier (DID).
22
+ */
23
+ export interface DidCreateVerificationMethod<TKms> extends Pick<Partial<DidVerificationMethod>, 'controller' | 'id' | 'type'> {
24
+ /**
25
+ * The name of the cryptographic algorithm to be used for key generation.
26
+ *
27
+ * Examples might include `Ed25519` and `ES256K` but will vary depending on the DID method
28
+ * specification and the key management system in use.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const verificationMethod: DidCreateVerificationMethod = {
33
+ * algorithm: 'Ed25519'
34
+ * };
35
+ * ```
36
+ */
37
+ algorithm: TKms extends CryptoApi ? InferKeyGeneratorAlgorithm<TKms> : InferKeyGeneratorAlgorithm<LocalKeyManager>;
38
+ /**
39
+ * Optionally specify the purposes for which a verification method is intended to be used in a DID
40
+ * document.
41
+ *
42
+ * The `purposes` property defines the specific
43
+ * {@link DidVerificationRelationship | verification relationships} between the DID subject and
44
+ * the verification method. This enables the verification method to be utilized for distinct
45
+ * actions such as authentication, assertion, key agreement, capability delegation, and others. It
46
+ * is important for verifiers to recognize that a verification method must be associated with the
47
+ * relevant purpose in the DID document to be valid for that specific use case.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * const verificationMethod: DidCreateVerificationMethod = {
52
+ * algorithm: 'Ed25519',
53
+ * controller: 'did:example:1234',
54
+ * purposes: ['authentication', 'assertionMethod']
55
+ * };
56
+ * ```
57
+ */
58
+ purposes?: (DidVerificationRelationship | keyof typeof DidVerificationRelationship)[];
59
+ }
60
+ /**
61
+ * Defines the API for a specific DID method. It includes functionalities for creating and resolving
62
+ * DIDs.
63
+ *
64
+ * @typeparam T - The type of the DID instance associated with this method.
65
+ * @typeparam O - The type of the options used for creating the DID.
66
+ */
67
+ export interface DidMethodApi<TKms extends CryptoApi | undefined = CryptoApi, TDid extends BearerDid = BearerDid, TOptions extends DidCreateOptions<TKms> = DidCreateOptions<TKms>> extends DidMethodResolver {
68
+ /**
69
+ * The name of the DID method.
70
+ *
71
+ * For example, in the DID `did:example:123456`, "example" would be the method name.
72
+ */
73
+ methodName: string;
74
+ new (): DidMethod;
75
+ /**
76
+ * Creates a new DID.
77
+ *
78
+ * This function should generate a new DID in accordance with the DID method specification being
79
+ * implemented, using the provided `keyManager`, and optionally, any provided `options`.
80
+ *
81
+ * @param params - The parameters used to create the DID.
82
+ * @param params.keyManager - Optional. The cryptographic API used for key management.
83
+ * @param params.options - Optional. The options used for creating the DID.
84
+ * @returns A promise that resolves to the newly created DID instance.
85
+ */
86
+ create(params: {
87
+ keyManager?: TKms;
88
+ options?: TOptions;
89
+ }): Promise<TDid>;
90
+ /**
91
+ * Given a DID Document, return the verification method that will be used for signing messages and
92
+ * credentials.
93
+ *
94
+ * If given, the `methodId` parameter is used to select the verification method. If not given, a
95
+ * DID method specific approach is taken to selecting the verification method to return.
96
+ *
97
+ * @param params - The parameters for the `getSigningMethod` operation.
98
+ * @param params.didDocument - DID Document to get the verification method from.
99
+ * @param params.methodId - ID of the verification method to use for signing.
100
+ * @returns A promise that resolves to the erification method to use for signing.
101
+ */
102
+ getSigningMethod(params: {
103
+ didDocument: DidDocument;
104
+ methodId?: string;
105
+ }): Promise<DidVerificationMethod>;
106
+ }
107
+ /**
108
+ * Defines the interface for resolving a DID using a specific DID method.
109
+ *
110
+ * A DID resolver takes a DID URI as input and returns a {@link DidResolutionResult} object.
111
+ *
112
+ * @property {string} methodName - The name of the DID method.
113
+ * @method resolve - Asynchronous method to resolve a DID URI. Takes the DID URI and optional resolution options.
114
+ */
115
+ export interface DidMethodResolver {
116
+ /**
117
+ * The name of the DID method.
118
+ *
119
+ * For example, in the DID `did:example:123456`, "example" would be the method name.
120
+ */
121
+ methodName: string;
122
+ new (): DidMethod;
123
+ /**
124
+ * Resolves a DID URI.
125
+ *
126
+ * This function should resolve the DID URI in accordance with the DID method specification being
127
+ * implemented, using the provided `options`.
128
+ *
129
+ * @param didUri - The DID URI to be resolved.
130
+ * @param options - Optional. The options used for resolving the DID.
131
+ * @returns A {@link DidResolutionResult} object containing the DID document and metadata or an error.
132
+ */
133
+ resolve(didUri: string, options?: DidResolutionOptions): Promise<DidResolutionResult>;
134
+ }
135
+ /**
136
+ * Represents the result of a Decentralized Identifier (DID) registration operation.
137
+ *
138
+ * This type encapsulates the complete outcome of registering a DID, including the registration
139
+ * metadata, the DID document (if registration is successful), and metadata about the DID document.
140
+ */
141
+ export interface DidRegistrationResult {
142
+ /**
143
+ * The DID document resulting from the registration process, if successful.
144
+ *
145
+ * If the registration operation was successful, this MUST contain a DID document
146
+ * corresponding to the DID. If the registration is unsuccessful, this value MUST be empty.
147
+ *
148
+ * @see {@link https://www.w3.org/TR/did-core/#dfn-diddocument | DID Core Specification, § DID Document}
149
+ */
150
+ didDocument: DidDocument | null;
151
+ /**
152
+ * Metadata about the DID Document.
153
+ *
154
+ * This structure contains information about the DID Document like creation and update timestamps,
155
+ * deactivation status, versioning information, and other details relevant to the DID Document.
156
+ *
157
+ * @see {@link https://www.w3.org/TR/did-core/#dfn-diddocumentmetadata | DID Core Specification, § DID Document Metadata}
158
+ */
159
+ didDocumentMetadata: DidMetadata;
160
+ /**
161
+ * A metadata structure consisting of values relating to the results of the DID registration
162
+ * process.
163
+ *
164
+ * This structure is REQUIRED, and in the case of an error in the registration process,
165
+ * this MUST NOT be empty. If the registration is not successful, this structure MUST contain an
166
+ * `error` property describing the error.
167
+ */
168
+ didRegistrationMetadata: DidRegistrationMetadata;
169
+ }
170
+ /**
171
+ * Represents metadata related to the result of a DID registration operation.
172
+ *
173
+ * This type includes fields that provide information about the outcome of a DID registration
174
+ * process (e.g., create, update, deactivate), including any errors that occurred.
175
+ *
176
+ * This metadata typically changes between invocations of the `create`, `update`, and `deactivate`
177
+ * functions, as it represents data about the registration process itself.
178
+ */
179
+ export type DidRegistrationMetadata = {
180
+ /**
181
+ * An error code indicating issues encountered during the DID registration process.
182
+ *
183
+ * While the DID Core specification does not define a specific set of error codes for the result
184
+ * returned by the `create`, `update`, or `deactivate` functions, it is recommended to use the
185
+ * error codes defined in the DID Specification Registries for
186
+ * {@link https://www.w3.org/TR/did-spec-registries/#error | DID Resolution Metadata }.
187
+ *
188
+ * Recommended error codes include:
189
+ * - `internalError`: An unexpected error occurred during DID registration process.
190
+ * - `invalidDid`: The provided DID is invalid.
191
+ * - `invalidDidDocument`: The provided DID document does not conform to valid syntax.
192
+ * - `invalidDidDocumentLength`: The byte length of the provided DID document does not match the expected value.
193
+ * - `invalidSignature`: Verification of a signature failed.
194
+ * - `methodNotSupported`: The DID method specified is not supported.
195
+ * - Custom error codes can also be provided as strings.
196
+ */
197
+ error?: string;
198
+ [key: string]: any;
199
+ };
200
+ /**
201
+ * Base abstraction for all Decentralized Identifier (DID) method implementations.
202
+ *
203
+ * This base class serves as a foundational structure upon which specific DID methods
204
+ * can be implemented. Subclasses should furnish particular method and data models adherent
205
+ * to various DID methods, taking care to adhere to the
206
+ * {@link https://www.w3.org/TR/did-core/ | W3C DID Core specification} and the
207
+ * respective DID method specifications.
208
+ */
209
+ export declare class DidMethod {
210
+ /**
211
+ * MUST be implemented by all DID method implementations that extend {@link DidMethod}.
212
+ *
213
+ * Given the W3C DID Document of a DID, return the verification method that will be used for
214
+ * signing messages and credentials. If given, the `methodId` parameter is used to select the
215
+ * verification method. If not given, each DID method implementation will select a default
216
+ * verification method from the DID Document.
217
+ *
218
+ * @param _params - The parameters for the `getSigningMethod` operation.
219
+ * @param _params.didDocument - DID Document to get the verification method from.
220
+ * @param _params.methodId - ID of the verification method to use for signing.
221
+ * @returns Verification method to use for signing.
222
+ */
223
+ static getSigningMethod(_params: {
224
+ didDocument: DidDocument;
225
+ methodId?: string;
226
+ }): Promise<DidVerificationMethod | undefined>;
227
+ /**
228
+ * MUST be implemented by all DID method implementations that extend {@link DidMethod}.
229
+ *
230
+ * Resolves a DID URI to a DID Document.
231
+ *
232
+ * @param _didUri - The DID to be resolved.
233
+ * @param _options - Optional parameters for resolving the DID.
234
+ * @returns A Promise resolving to a {@link DidResolutionResult} object representing the result of the resolution.
235
+ */
236
+ static resolve(_didUri: string, _options?: DidResolutionOptions): Promise<DidResolutionResult>;
237
+ }
238
+ //# sourceMappingURL=did-method.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did-method.d.ts","sourceRoot":"","sources":["../../../src/methods/did-method.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,37 @@
1
+ import type { DidResolutionOptions, DidResolutionResult } from '../types/did-core.js';
2
+ import { DidMethod } from './did-method.js';
3
+ /**
4
+ * The `DidWeb` class provides an implementation of the `did:web` DID method.
5
+ *
6
+ * Features:
7
+ * - DID Resolution: Resolve a `did:web` to its corresponding DID Document.
8
+ *
9
+ * @remarks
10
+ * The `did:web` method uses a web domain's existing reputation and aims to integrate decentralized
11
+ * identities with the existing web infrastructure to drive adoption. It leverages familiar web
12
+ * security models and domain ownership to provide accessible, interoperable digital identity
13
+ * management.
14
+ *
15
+ * @see {@link https://w3c-ccg.github.io/did-method-web/ | DID Web Specification}
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * // DID Resolution
20
+ * const resolutionResult = await DidWeb.resolve({ did: did.uri });
21
+ * ```
22
+ */
23
+ export declare class DidWeb extends DidMethod {
24
+ /**
25
+ * Name of the DID method, as defined in the DID Web specification.
26
+ */
27
+ static methodName: string;
28
+ /**
29
+ * Resolves a `did:web` identifier to a DID Document.
30
+ *
31
+ * @param didUri - The DID to be resolved.
32
+ * @param _options - Optional parameters for resolving the DID. Unused by this DID method.
33
+ * @returns A Promise resolving to a {@link DidResolutionResult} object representing the result of the resolution.
34
+ */
35
+ static resolve(didUri: string, _options?: DidResolutionOptions): Promise<DidResolutionResult>;
36
+ }
37
+ //# sourceMappingURL=did-web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did-web.d.ts","sourceRoot":"","sources":["../../../src/methods/did-web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAGnG,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,MAAO,SAAQ,SAAS;IAEnC;;OAEG;IACH,OAAc,UAAU,SAAS;IAEjC;;;;;;OAMG;WACiB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAuD3G"}
@@ -0,0 +1,86 @@
1
+ import type { AbstractLevel } from 'abstract-level';
2
+ import type { DidResolutionResult } from '../types/did-core.js';
3
+ import type { DidResolverCache } from '../types/did-resolution.js';
4
+ /**
5
+ * Configuration parameters for creating a LevelDB-based cache for DID resolution results.
6
+ *
7
+ * Allows customization of the underlying database instance, storage location, and cache
8
+ * time-to-live (TTL) settings.
9
+ */
10
+ export type DidResolverCacheLevelParams = {
11
+ /**
12
+ * Optional. An instance of `AbstractLevel` to use as the database. If not provided, a new
13
+ * LevelDB instance will be created at the specified `location`.
14
+ */
15
+ db?: AbstractLevel<string | Buffer | Uint8Array, string, string>;
16
+ /**
17
+ * Optional. The file system path or IndexedDB name where the LevelDB store will be created.
18
+ * Defaults to 'DATA/DID_RESOLVERCACHE' if not specified.
19
+ */
20
+ location?: string;
21
+ /**
22
+ * Optional. The time-to-live for cache entries, expressed as a string (e.g., '1h', '15m').
23
+ * Determines how long a cache entry should remain valid before being considered expired. Defaults
24
+ * to '15m' if not specified.
25
+ */
26
+ ttl?: string;
27
+ };
28
+ /**
29
+ * A Level-based cache implementation for storing and retrieving DID resolution results.
30
+ *
31
+ * This cache uses LevelDB for storage, allowing data persistence across process restarts or
32
+ * browser refreshes. It's suitable for both Node.js and browser environments.
33
+ *
34
+ * @remarks
35
+ * The LevelDB cache keeps data in memory for fast access and also writes to the filesystem in
36
+ * Node.js or indexedDB in browsers. Time-to-live (TTL) for cache entries is configurable.
37
+ *
38
+ * @example
39
+ * ```
40
+ * const cache = new DidResolverCacheLevel({ ttl: '15m' });
41
+ * ```
42
+ */
43
+ export declare class DidResolverCacheLevel implements DidResolverCache {
44
+ /** The underlying LevelDB store used for caching. */
45
+ protected cache: AbstractLevel<string | Uint8Array | Buffer, string, string>;
46
+ /** The time-to-live for cache entries in milliseconds. */
47
+ protected ttl: number;
48
+ constructor({ db, location, ttl }?: DidResolverCacheLevelParams);
49
+ /**
50
+ * Retrieves a DID resolution result from the cache.
51
+ *
52
+ * If the cached item has exceeded its TTL, it's scheduled for deletion and undefined is returned.
53
+ *
54
+ * @param did - The DID string used as the key for retrieving the cached result.
55
+ * @returns The cached DID resolution result or undefined if not found or expired.
56
+ */
57
+ get(did: string): Promise<DidResolutionResult | void>;
58
+ /**
59
+ * Stores a DID resolution result in the cache with a TTL.
60
+ *
61
+ * @param did - The DID string used as the key for storing the result.
62
+ * @param value - The DID resolution result to be cached.
63
+ * @returns A promise that resolves when the operation is complete.
64
+ */
65
+ set(did: string, value: DidResolutionResult): Promise<void>;
66
+ /**
67
+ * Deletes a DID resolution result from the cache.
68
+ *
69
+ * @param did - The DID string used as the key for deletion.
70
+ * @returns A promise that resolves when the operation is complete.
71
+ */
72
+ delete(did: string): Promise<void>;
73
+ /**
74
+ * Clears all entries from the cache.
75
+ *
76
+ * @returns A promise that resolves when the operation is complete.
77
+ */
78
+ clear(): Promise<void>;
79
+ /**
80
+ * Closes the underlying LevelDB store.
81
+ *
82
+ * @returns A promise that resolves when the store is closed.
83
+ */
84
+ close(): Promise<void>;
85
+ }
86
+ //# sourceMappingURL=resolver-cache-level.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver-cache-level.d.ts","sourceRoot":"","sources":["../../../src/resolver/resolver-cache-level.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAKpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;;OAGG;IACH,EAAE,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,MAAM,GAAG,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjE;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAA;AAyBD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,qBAAsB,YAAW,gBAAgB;IAC5D,qDAAqD;IACrD,SAAS,CAAC,KAAK,8DAAC;IAEhB,0DAA0D;IAC1D,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC;gBAEV,EACV,EAAE,EACF,QAAmC,EACnC,GAAW,EACZ,GAAE,2BAAgC;IAKnC;;;;;;;OAOG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAwB3D;;;;;;OAMG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3D;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGvB"}
@@ -0,0 +1,9 @@
1
+ import type { DidResolverCache } from '../types/did-resolution.js';
2
+ /**
3
+ * No-op cache that is used as the default cache for did-resolver.
4
+ *
5
+ * The motivation behind using a no-op cache as the default stems from the desire to maximize the
6
+ * potential for this library to be used in as many JS runtimes as possible.
7
+ */
8
+ export declare const DidResolverCacheNoop: DidResolverCache;
9
+ //# sourceMappingURL=resolver-cache-noop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver-cache-noop.d.ts","sourceRoot":"","sources":["../../../src/resolver/resolver-cache-noop.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,gBAgBlC,CAAC"}
@@ -0,0 +1,109 @@
1
+ import type { DidMethodResolver } from '../methods/did-method.js';
2
+ import type { DidResolver, DidResolverCache, DidUrlDereferencer } from '../types/did-resolution.js';
3
+ import type { DidDereferencingOptions, DidDereferencingResult, DidResolutionOptions, DidResolutionResult } from '../types/did-core.js';
4
+ /**
5
+ * Parameters for configuring the `UniversalResolver` class, which is responsible for resolving
6
+ * decentralized identifiers (DIDs) to their corresponding DID documents.
7
+ *
8
+ * This type specifies the essential components required by the `UniversalResolver` to perform
9
+ * DID resolution and dereferencing. It includes an array of `DidMethodResolver` instances,
10
+ * each capable of resolving DIDs for a specific method, and optionally, a cache for storing
11
+ * resolved DID documents to improve resolution efficiency.
12
+ */
13
+ export type UniversalResolverParams = {
14
+ /**
15
+ * An array of `DidMethodResolver` instances.
16
+ *
17
+ * Each resolver in this array is designed to handle a specific DID method, enabling the
18
+ * `DidResolver` to support multiple DID methods simultaneously.
19
+ */
20
+ didResolvers: DidMethodResolver[];
21
+ /**
22
+ * An optional `DidResolverCache` instance used for caching resolved DID documents.
23
+ *
24
+ * Providing a cache implementation can significantly enhance resolution performance by avoiding
25
+ * redundant resolutions for previously resolved DIDs. If omitted, a no-operation cache is used,
26
+ * which effectively disables caching.
27
+ */
28
+ cache?: DidResolverCache;
29
+ };
30
+ /**
31
+ * The `DidResolver` class provides mechanisms for resolving Decentralized Identifiers (DIDs) to
32
+ * their corresponding DID documents.
33
+ *
34
+ * The class is designed to handle various DID methods by utilizing an array of `DidMethodResolver`
35
+ * instances, each responsible for a specific DID method.
36
+ *
37
+ * Providing a cache implementation can significantly enhance resolution performance by avoiding
38
+ * redundant resolutions for previously resolved DIDs. If omitted, a no-operation cache is used,
39
+ * which effectively disables caching.
40
+ *
41
+ * Usage:
42
+ * - Construct the `DidResolver` with an array of `DidMethodResolver` instances and an optional cache.
43
+ * - Use `resolve` to resolve a DID to its DID Resolution Result.
44
+ * - Use `dereference` to extract specific resources from a DID URL, like service endpoints or verification methods.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * const resolver = new DidResolver({
49
+ * didResolvers: [<array of DidMethodResolver instances>],
50
+ * cache: new DidResolverCacheNoop()
51
+ * });
52
+ *
53
+ * const resolutionResult = await resolver.resolve('did:example:123456');
54
+ * const dereferenceResult = await resolver.dereference({ didUri: 'did:example:123456#key-1' });
55
+ * ```
56
+ */
57
+ export declare class UniversalResolver implements DidResolver, DidUrlDereferencer {
58
+ /**
59
+ * A cache for storing resolved DID documents.
60
+ */
61
+ protected cache: DidResolverCache;
62
+ /**
63
+ * A map to store method resolvers against method names.
64
+ */
65
+ private didResolvers;
66
+ /**
67
+ * Constructs a new `DidResolver`.
68
+ *
69
+ * @param params - The parameters for constructing the `DidResolver`.
70
+ */
71
+ constructor({ cache, didResolvers }: UniversalResolverParams);
72
+ /**
73
+ * Resolves a DID to a DID Resolution Result.
74
+ *
75
+ * If the DID Resolution Result is present in the cache, it returns the cached result. Otherwise,
76
+ * it uses the appropriate method resolver to resolve the DID, stores the resolution result in the
77
+ * cache, and returns the resolultion result.
78
+ *
79
+ * @param didUri - The DID or DID URL to resolve.
80
+ * @returns A promise that resolves to the DID Resolution Result.
81
+ */
82
+ resolve(didUri: string, options?: DidResolutionOptions): Promise<DidResolutionResult>;
83
+ /**
84
+ * Dereferences a DID (Decentralized Identifier) URL to a corresponding DID resource.
85
+ *
86
+ * This method interprets the DID URL's components, which include the DID method, method-specific
87
+ * identifier, path, query, and fragment, and retrieves the related resource as per the DID Core
88
+ * specifications.
89
+ *
90
+ * The dereferencing process involves resolving the DID contained in the DID URL to a DID document,
91
+ * and then extracting the specific part of the document identified by the fragment in the DID URL.
92
+ * If no fragment is specified, the entire DID document is returned.
93
+ *
94
+ * This method supports resolution of different components within a DID document such as service
95
+ * endpoints and verification methods, based on their IDs. It accommodates both full and
96
+ * DID URLs as specified in the DID Core specification.
97
+ *
98
+ * More information on DID URL dereferencing can be found in the
99
+ * {@link https://www.w3.org/TR/did-core/#did-url-dereferencing | DID Core specification}.
100
+ *
101
+ * TODO: This is a partial implementation and does not fully implement DID URL dereferencing. (https://github.com/TBD54566975/web5-js/issues/387)
102
+ *
103
+ * @param didUrl - The DID URL string to dereference.
104
+ * @param [_options] - Input options to the dereference function. Optional.
105
+ * @returns a {@link DidDereferencingResult}
106
+ */
107
+ dereference(didUrl: string, _options?: DidDereferencingOptions): Promise<DidDereferencingResult>;
108
+ }
109
+ //# sourceMappingURL=universal-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"universal-resolver.d.ts","sourceRoot":"","sources":["../../../src/resolver/universal-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACpG,OAAO,KAAK,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,mBAAmB,EAAe,MAAM,sBAAsB,CAAC;AAOpJ;;;;;;;;GAQG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;;;OAKG;IACH,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAElC;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC;CAC1B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,iBAAkB,YAAW,WAAW,EAAE,kBAAkB;IACvE;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,gBAAgB,CAAC;IAElC;;OAEG;IACH,OAAO,CAAC,YAAY,CAA6C;IAEjE;;;;OAIG;gBACS,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,uBAAuB;IAQ5D;;;;;;;;;OASG;IACU,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAuClG;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACG,WAAW,CACf,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,uBAAuB,GACjC,OAAO,CAAC,sBAAsB,CAAC;CAyEnC"}