@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,580 @@
1
+ import { Jwk } from '@enbox/crypto';
2
+
3
+ /**
4
+ * Represents metadata related to the process of DID dereferencing.
5
+ *
6
+ * This type includes fields that provide information about the outcome of a DID dereferencing operation,
7
+ * including the content type of the returned resource and any errors that occurred during the dereferencing process.
8
+ *
9
+ * @see {@link https://www.w3.org/TR/did-core/#did-url-dereferencing-metadata | DID Core Specification, § DID URL Dereferencing Metadata}
10
+ */
11
+ export type DidDereferencingMetadata = {
12
+ /**
13
+ * The Media Type of the returned contentStream SHOULD be expressed using this property if
14
+ * dereferencing is successful.
15
+ */
16
+ contentType?: string;
17
+
18
+ /**
19
+ * The error code from the dereferencing process. This property is REQUIRED when there is an
20
+ * error in the dereferencing process. The value of this property MUST be a single keyword
21
+ * expressed as an ASCII string. The possible property values of this field SHOULD be registered
22
+ * in the {@link https://www.w3.org/TR/did-spec-registries/ | DID Specification Registries}.
23
+ * The DID Core specification defines the following common error values:
24
+ *
25
+ * - `invalidDidUrl`: The DID URL supplied to the DID URL dereferencing function does not conform
26
+ * to valid syntax.
27
+ * - `notFound`: The DID URL dereferencer was unable to find the `contentStream` resulting from
28
+ * this dereferencing request.
29
+ *
30
+ * @see {@link https://www.w3.org/TR/did-core/#did-url-dereferencing-metadata | DID Core Specification, § DID URL Dereferencing Metadata}
31
+ */
32
+ error?: string;
33
+
34
+ // Additional output metadata generated during DID Resolution.
35
+ [key: string]: any;
36
+ }
37
+
38
+ /**
39
+ * Represents the options that can be used during the process of DID dereferencing.
40
+ *
41
+ * This interface allows the caller to specify preferences and additional parameters for the DID
42
+ * dereferencing operation.
43
+ *
44
+ * @see {@link https://www.w3.org/TR/did-core/#did-url-dereferencing-options}
45
+ */
46
+ export interface DidDereferencingOptions {
47
+ /** The Media Type that the caller prefers for contentStream. */
48
+ accept?: string;
49
+
50
+ /** Additional properties used during DID dereferencing. */
51
+ [key: string]: any;
52
+ }
53
+
54
+ /**
55
+ * Represents the result of a DID dereferencing operation.
56
+ *
57
+ * This type encapsulates the outcomes of the DID URL dereferencing process, including metadata
58
+ * about the dereferencing operation, the content stream retrieved (if any), and metadata about the
59
+ * content stream.
60
+ *
61
+ * @see {@link https://www.w3.org/TR/did-core/#did-url-dereferencing | DID Core Specification, § DID URL Dereferencing}
62
+ */
63
+ export type DidDereferencingResult = {
64
+ /**
65
+ * A metadata structure consisting of values relating to the results of the DID URL dereferencing
66
+ * process. This structure is REQUIRED, and in the case of an error in the dereferencing process,
67
+ * this MUST NOT be empty. Properties defined by this specification are in 7.2.2 DID URL
68
+ * Dereferencing Metadata. If the dereferencing is not successful, this structure MUST contain an
69
+ * `error` property describing the error.
70
+ */
71
+ dereferencingMetadata: DidDereferencingMetadata;
72
+
73
+ /**
74
+ * If the `dereferencing` function was called and successful, this MUST contain a resource
75
+ * corresponding to the DID URL. The contentStream MAY be a resource such as:
76
+ * - a DID document that is serializable in one of the conformant representations
77
+ * - a Verification Method
78
+ * - a service.
79
+ * - any other resource format that can be identified via a Media Type and obtained through the
80
+ * resolution process.
81
+ *
82
+ * If the dereferencing is unsuccessful, this value MUST be empty.
83
+ */
84
+ contentStream: DidResource | null;
85
+
86
+ /**
87
+ * If the dereferencing is successful, this MUST be a metadata structure, but the structure MAY be
88
+ * empty. This structure contains metadata about the contentStream. If the contentStream is a DID
89
+ * document, this MUST be a didDocumentMetadata structure as described in DID Resolution. If the
90
+ * dereferencing is unsuccessful, this output MUST be an empty metadata structure.
91
+ */
92
+ contentMetadata: DidDocumentMetadata;
93
+ }
94
+
95
+ /**
96
+ * A set of data describing the Decentralized Identifierr (DID) subject.
97
+ *
98
+ * A DID Document contains information associated with the DID, such as cryptographic public keys
99
+ * and service endpoints, enabling trustable interactions associated with the DID subject.
100
+ *
101
+ * - Cryptographic public keys - Used by the DID subject or a DID delegate to authenticate itself
102
+ * and prove its association with the DID.
103
+ * - Service endpoints - Used to communicate or interact with the DID subject or associated
104
+ * entities. Examples include discovery, agent, social networking, file
105
+ * storage, and verifiable credential repository services.
106
+ *
107
+ * A DID Document can be retrieved by resolving a DID, as described in
108
+ * {@link https://www.w3.org/TR/did-core/#did-resolution | DID Core Specification, § DID Resolution}.
109
+ */
110
+ export interface DidDocument {
111
+ /**
112
+ * A JSON-LD context link, which provides a JSON-LD processor with the information necessary to
113
+ * interpret the DID document JSON. The default context URL is 'https://www.w3.org/ns/did/v1'.
114
+ */
115
+ '@context'?: 'https://www.w3.org/ns/did/v1' | string | (string | Record<string, any>)[];
116
+
117
+ /**
118
+ * The DID Subject to which this DID Document pertains.
119
+ *
120
+ * The `id` property is REQUIRED and must be a valid DID.
121
+ *
122
+ * @see {@link https://www.w3.org/TR/did-core/#did-subject | DID Core Specification, § DID Subject}
123
+ */
124
+ id: string;
125
+
126
+ /**
127
+ * A DID subject can have multiple identifiers for different purposes, or at different times.
128
+ * The assertion that two or more DIDs (or other types of URI) refer to the same DID subject can
129
+ * be made using the `alsoKnownAs` property.
130
+ *
131
+ * @see {@link https://www.w3.org/TR/did-core/#also-known-as | DID Core Specification, § Also Known As}
132
+ */
133
+ alsoKnownAs?: string[];
134
+
135
+ /**
136
+ * A DID controller is an entity that is authorized to make changes to a DID document. Typically,
137
+ * only the DID Subject (i.e., the value of `id` property in the DID document) is authoritative.
138
+ * However, another DID can be specified as the DID controller, and when doing so, any
139
+ * verification methods contained in the DID document for the other DID should be accepted as
140
+ * authoritative. In other words, proofs created by the controller DID should be considered
141
+ * equivalent to proofs created by the DID Subject.
142
+ *
143
+ * @see {@link https://www.w3.org/TR/did-core/#did-controller | DID Core Specification, § DID Controller}
144
+ */
145
+ controller?: string | string[];
146
+
147
+ /**
148
+ * A DID document can express verification methods, such as cryptographic public keys, which can
149
+ * be used to authenticate or authorize interactions with the DID subject or associated parties.
150
+ *
151
+ * @see {@link https://www.w3.org/TR/did-core/#verification-methods | DID Core Specification, § Verification Methods}
152
+ */
153
+ verificationMethod?: DidVerificationMethod[];
154
+
155
+ /**
156
+ * The `assertionMethod` verification relationship is used to specify how the DID subject is
157
+ * expected to express claims, such as for the purposes of issuing a Verifiable Credential.
158
+ *
159
+ * @see {@link https://www.w3.org/TR/did-core/#assertion | DID Core Specification, § Assertion}
160
+ */
161
+ assertionMethod?: (DidVerificationMethod | string)[];
162
+
163
+ /**
164
+ * The `authentication` verification relationship is used to specify how the DID subject is expected
165
+ * to be authenticated, for purposes such as logging into a website or engaging in any sort of
166
+ * challenge-response protocol.
167
+
168
+ * @see {@link https://www.w3.org/TR/did-core/#authentication | DID Core Specification, § Authentication}
169
+ */
170
+ authentication?: (DidVerificationMethod | string)[];
171
+
172
+ /**
173
+ * The `keyAgreement` verification relationship is used to specify how an entity can generate
174
+ * encryption material in order to transmit confidential information intended for the DID
175
+ * subject, such as for the purposes of establishing a secure communication channel with the
176
+ * recipient.
177
+ *
178
+ * @see {@link https://www.w3.org/TR/did-core/#key-agreement | DID Core Specification, § Key Agreement}
179
+ */
180
+ keyAgreement?: (DidVerificationMethod | string)[];
181
+
182
+ /**
183
+ * The `capabilityDelegation` verification relationship is used to specify a mechanism that might
184
+ * be used by the DID subject to delegate a cryptographic capability to another party, such as
185
+ * delegating the authority to access a specific HTTP API to a subordinate.
186
+ *
187
+ * @see {@link https://www.w3.org/TR/did-core/#capability-delegation | DID Core Specification, § Capability Delegation}
188
+ */
189
+ capabilityDelegation?: (DidVerificationMethod | string)[];
190
+
191
+ /**
192
+ * The `capabilityInvocation` verification relationship is used to specify a verification method
193
+ * that might be used by the DID subject to invoke a cryptographic capability, such as the
194
+ * authorization to update the DID Document.
195
+ */
196
+ capabilityInvocation?: (DidVerificationMethod | string)[];
197
+
198
+ /**
199
+ * Services are used in DID documents to express ways of communicating with the DID subject or
200
+ * associated entities. A service can be any type of service the DID subject wants to advertise,
201
+ * including decentralized identity management services for further discovery, authentication,
202
+ * authorization, or interaction.
203
+ *
204
+ * @see {@link https://www.w3.org/TR/did-core/#services | DID Core Specification, § Services}
205
+ */
206
+ service?: DidService[];
207
+ }
208
+
209
+ /**
210
+ * Represents metadata about the DID document resulting from a DID resolution operation.
211
+ *
212
+ * This metadata typically does not change between invocations of the `resolve` and
213
+ * `resolveRepresentation` functions unless the DID document changes, as it represents metadata
214
+ * about the DID document.
215
+ *
216
+ * @see {@link https://www.w3.org/TR/did-core/#did-document-metadata | DID Core Specification, § DID Document Metadata}
217
+ */
218
+ export interface DidDocumentMetadata {
219
+ /**
220
+ * Timestamp of the Create operation.
221
+ *
222
+ * The value of the property MUST be a string formatted as an XML Datetime normalized to
223
+ * UTC 00:00:00 and without sub-second decimal precision. For example: `2020-12-20T19:17:47Z`.
224
+ */
225
+ created?: string;
226
+
227
+ /**
228
+ * Timestamp of the last Update operation for the document version which was resolved.
229
+ *
230
+ * The value of the property MUST follow the same formatting rules as the `created` property.
231
+ * The `updated` property is omitted if an Update operation has never been performed on the DID
232
+ * document. If an `updated` property exists, it can be the same value as the `created` property
233
+ * when the difference between the two timestamps is less than one second.
234
+ */
235
+ updated?: string;
236
+
237
+ /**
238
+ * Whether the DID has been deactivated.
239
+ *
240
+ * If a DID has been deactivated, DID document metadata MUST include this property with the
241
+ * boolean value `true`. If a DID has not been deactivated, this properrty is OPTIONAL, but if
242
+ * present, MUST have the boolean value `false`.
243
+ */
244
+ deactivated?: boolean;
245
+
246
+ /**
247
+ * Version ID of the last Update operation for the document version which was resolved.
248
+ */
249
+ versionId?: string;
250
+
251
+ /**
252
+ * Timestamp of the next Update operation if the resolved document version is not the latest
253
+ * version of the document.
254
+ *
255
+ * The value of the property MUST follow the same formatting rules as the `created` property.
256
+ */
257
+ nextUpdate?: string;
258
+
259
+ /**
260
+ * Version ID of the next Update operation if the resolved document version is not the latest
261
+ * version of the document.
262
+ */
263
+ nextVersionId?: string;
264
+
265
+ /**
266
+ * A DID method can define different forms of a DID that are logically equivalent. An example is
267
+ * when a DID takes one form prior to registration in a verifiable data registry and another form
268
+ * after such registration. In this case, the DID method specification might need to express one
269
+ * or more DIDs that are logically equivalent to the resolved DID as a property of the DID
270
+ * document. This is the purpose of the `equivalentId` property.
271
+ *
272
+ * A requesting party is expected to retain the values from the id and equivalentId properties to
273
+ * ensure any subsequent interactions with any of the values they contain are correctly handled as
274
+ * logically equivalent (e.g., retain all variants in a database so an interaction with any one
275
+ * maps to the same underlying account).
276
+ *
277
+ * @see {@link https://www.w3.org/TR/did-core/#dfn-equivalentid | DID Core Specification, § DID Document Metadata}
278
+ */
279
+ equivalentId?: string[];
280
+
281
+ /**
282
+ * The `canonicalId` property is identical to the `equivalentId` property except:
283
+ * - it is associated with a single value rather than a set
284
+ * - the DID is defined to be the canonical ID for the DID subject within the scope of the
285
+ * containing DID document.
286
+ *
287
+ * A requesting party is expected to use the `canonicalId` value as its primary ID value for the
288
+ * DID subject and treat all other equivalent values as secondary aliases (e.g., update
289
+ * corresponding primary references in their systems to reflect the new canonical ID directive).
290
+ *
291
+ * @see {@link https://www.w3.org/TR/did-core/#dfn-canonicalid | DID Core Specification, § DID Document Metadata}
292
+ */
293
+ canonicalId?: string;
294
+
295
+ // Additional output metadata generated during DID Resolution.
296
+ [key: string]: any;
297
+ }
298
+
299
+ /**
300
+ * Represents metadata related to the result of a DID resolution operation.
301
+ *
302
+ * This type includes fields that provide information about the outcome of a DID resolution process,
303
+ * including the content type of the returned DID document and any errors that occurred during the
304
+ * resolution process.
305
+ *
306
+ * This metadata typically changes between invocations of the `resolve` and `resolveRepresentation`
307
+ * functions, as it represents data about the resolution process itself.
308
+ *
309
+ * @see {@link https://www.w3.org/TR/did-core/#did-resolution-metadata | DID Core Specification, § DID Resolution Metadata}
310
+ */
311
+ export type DidResolutionMetadata = {
312
+ /**
313
+ * The Media Type of the returned `didDocumentStream`.
314
+ *
315
+ * This property is REQUIRED if resolution is successful and if the `resolveRepresentation`
316
+ * function was called. This property MUST NOT be present if the `resolve` function was called.
317
+ * The value of this property MUST be an ASCII string that is the Media Type of the conformant
318
+ * representations. The caller of the `resolveRepresentation` function MUST use this value when
319
+ * determining how to parse and process the `didDocumentStream` returned by this function into the
320
+ * data model.
321
+ */
322
+ contentType?: string;
323
+
324
+ /**
325
+ * An error code indicating issues encountered during the DID Resolution or DID URL
326
+ * Dereferencing process.
327
+ *
328
+ * Defined error codes include:
329
+ * - `internalError`: An unexpected error occurred during DID Resolution or DID URL
330
+ * dereferencing process.
331
+ * - `invalidDid`: The provided DID is invalid.
332
+ * - `methodNotSupported`: The DID method specified is not supported.
333
+ * - `notFound`: The DID or DID URL does not exist.
334
+ * - `representationNotSupported`: The DID document representation is not supported.
335
+ * - Custom error codes can also be provided as strings.
336
+ *
337
+ * @see {@link https://www.w3.org/TR/did-core/#did-resolution-metadata | DID Core Specification, § DID Resolution Metadata}
338
+ * @see {@link https://www.w3.org/TR/did-spec-registries/#error | DID Specification Registries, § Error}
339
+ */
340
+ error?: string;
341
+
342
+ // Additional output metadata generated during DID Resolution.
343
+ [key: string]: any;
344
+ };
345
+
346
+ /**
347
+ * DID Resolution input metadata.
348
+ *
349
+ * The DID Core specification defines the following common properties:
350
+ * - `accept`: The Media Type that the caller prefers for the returned representation of the DID
351
+ * Document.
352
+ *
353
+ * The possible properties within this structure and their possible values are registered in the
354
+ * {@link https://www.w3.org/TR/did-spec-registries/#did-resolution-options | DID Specification Registries}.
355
+ *
356
+ * @see {@link https://www.w3.org/TR/did-core/#did-resolution-options | DID Core Specification, § DID Resolution Options}
357
+ */
358
+ export interface DidResolutionOptions {
359
+ /**
360
+ * The Media Type that the caller prefers for the returned representation of the DID Document.
361
+ *
362
+ * This property is REQUIRED if the `resolveRepresentation` function was called. This property
363
+ * MUST NOT be present if the `resolve` function was called.
364
+ *
365
+ * The value of this property MUST be an ASCII string that is the Media Type of the conformant
366
+ * representations. The caller of the `resolveRepresentation` function MUST use this value when
367
+ * determining how to parse and process the `didDocumentStream` returned by this function into the
368
+ * data model.
369
+ *
370
+ * @see {@link https://www.w3.org/TR/did-core/#did-resolution-options | DID Core Specification, § DID Resolution Options}
371
+ */
372
+ accept?: string;
373
+
374
+ // Additional properties used during DID Resolution.
375
+ [key: string]: any;
376
+ }
377
+
378
+ /**
379
+ * Represents the result of a Decentralized Identifier (DID) resolution operation.
380
+ *
381
+ * This type encapsulates the complete outcome of resolving a DID, including the resolution metadata,
382
+ * the DID document (if resolution is successful), and metadata about the DID document.
383
+ *
384
+ * @see {@link https://www.w3.org/TR/did-core/#did-resolution | DID Core Specification, § DID Resolution}
385
+ */
386
+ export type DidResolutionResult = {
387
+ /**
388
+ * A JSON-LD context link, which provides the JSON-LD processor with the information necessary to
389
+ * interpret the resolution result JSON. The default context URL is
390
+ * 'https://w3id.org/did-resolution/v1'.
391
+ */
392
+ '@context'?: 'https://w3id.org/did-resolution/v1' | string | (string | Record<string, any>)[];
393
+
394
+ /**
395
+ * A metadata structure consisting of values relating to the results of the DID resolution
396
+ * process.
397
+ *
398
+ * This structure is REQUIRED, and in the case of an error in the resolution process,
399
+ * this MUST NOT be empty. If the resolution is not successful, this structure MUST contain an
400
+ * `error` property describing the error.
401
+ *
402
+ * @see {@link https://www.w3.org/TR/did-core/#dfn-didresolutionmetadata | DID Core Specification, § DID Resolution Metadata}
403
+ */
404
+ didResolutionMetadata: DidResolutionMetadata;
405
+
406
+ /**
407
+ * The DID document resulting from the resolution process, if successful.
408
+ *
409
+ * If the `resolve` function was called and successful, this MUST contain a DID document
410
+ * corresponding to the DID. If the resolution is unsuccessful, this value MUST be empty.
411
+ *
412
+ * @see {@link https://www.w3.org/TR/did-core/#dfn-diddocument | DID Core Specification, § DID Document}
413
+ */
414
+ didDocument: DidDocument | null;
415
+
416
+ /**
417
+ * Metadata about the DID Document.
418
+ *
419
+ * This structure contains information about the DID Document like creation and update timestamps,
420
+ * deactivation status, versioning information, and other details relevant to the DID Document.
421
+ *
422
+ * @see {@link https://www.w3.org/TR/did-core/#dfn-diddocumentmetadata | DID Core Specification, § DID Document Metadata}
423
+ */
424
+ didDocumentMetadata: DidDocumentMetadata;
425
+ };
426
+
427
+ /**
428
+ * A DID Resource is either a DID Document, a DID Verification method or a DID Service
429
+ */
430
+ export type DidResource = DidDocument | DidService | DidVerificationMethod;
431
+
432
+ /**
433
+ * Services are used in DID documents to express ways of communicating with the DID subject or
434
+ * associated entities. A service can be any type of service the DID subject wants to advertise.
435
+ *
436
+ * @see {@link https://www.w3.org/TR/did-core/#services}
437
+ */
438
+ export type DidService = {
439
+ /**
440
+ * Identifier of the service.
441
+ *
442
+ * The `id` property is REQUIRED. It MUST be a URI conforming to
443
+ * {@link https://datatracker.ietf.org/doc/html/rfc3986 | RFC3986} and MUST be unique within the
444
+ * DID document.
445
+ */
446
+ id: string;
447
+
448
+ /**
449
+ * The type of service being described.
450
+ *
451
+ * The `type` property is REQUIRED. It MUST be a string. To maximize interoperability, the value
452
+ * SHOULD be registered in the
453
+ * {@link https://www.w3.org/TR/did-spec-registries/ | DID Specification Registries}. Examples of
454
+ * service types can be found in
455
+ * {@link https://www.w3.org/TR/did-spec-registries/#service-types | § Service Types}.
456
+ */
457
+ type: string;
458
+
459
+ /**
460
+ * A URI that can be used to interact with the DID service.
461
+ *
462
+ * The value of the `serviceEndpoint` property MUST be a string, an object containing key/value
463
+ * pairs, or an array composed of strings or objects. All string values MUST be valid URIs
464
+ * conforming to {@link https://datatracker.ietf.org/doc/html/rfc3986 | RFC3986}.
465
+ */
466
+ serviceEndpoint: DidServiceEndpoint | DidServiceEndpoint[];
467
+
468
+ // DID methods MAY include additional service properties.
469
+ [key: string]: any;
470
+ };
471
+
472
+ /**
473
+ * A service endpoint is a URI (Uniform Resource Identifier) that can be used to interact with the
474
+ * DID service.
475
+ *
476
+ * The value of the `serviceEndpoint` property MUST be a string or an object containing key/value
477
+ * pairs. All string values MUST be valid URIs conforming to
478
+ * {@link https://datatracker.ietf.org/doc/html/rfc3986 | RFC3986}.
479
+ *
480
+ * @see {@link https://www.w3.org/TR/did-core/#dfn-serviceendpoint | RFC3986, § 5.4 Services}
481
+ */
482
+ export type DidServiceEndpoint = string | Record<string, any>;
483
+
484
+ /**
485
+ * Represents a verification method in the context of a DID document.
486
+ *
487
+ * A verification method is a mechanism by which a DID controller can cryptographically assert proof
488
+ * of ownership or control over a DID or DID document. This can include, but is not limited to,
489
+ * cryptographic public keys or other data that can be used to authenticate or authorize actions.
490
+ *
491
+ * @see {@link https://www.w3.org/TR/did-core/#verification-methods | DID Core Specification, § Verification Methods}
492
+ */
493
+ export interface DidVerificationMethod {
494
+ /**
495
+ * The identifier of the verification method, which must be a URI.
496
+ */
497
+ id: string;
498
+
499
+ /**
500
+ * The type of the verification method.
501
+ *
502
+ * To maximize interoperability this value SHOULD be one of the valid verification method types
503
+ * registered in the {@link https://www.w3.org/TR/did-spec-registries/#verification-method-types | DID Specification Registries}.
504
+ */
505
+ type: string;
506
+
507
+ /**
508
+ * The DID of the entity that controls this verification method.
509
+ */
510
+ controller: string;
511
+
512
+ /**
513
+ * (Optional) A public key in JWK format.
514
+ *
515
+ * A JSON Web Key (JWK) that conforms to {@link https://datatracker.ietf.org/doc/html/rfc7517 | RFC 7517}.
516
+ */
517
+ publicKeyJwk?: Jwk;
518
+
519
+ /**
520
+ * (Optional) A public key in Multibase format.
521
+ *
522
+ * A multibase key that conforms to the draft
523
+ * {@link https://datatracker.ietf.org/doc/draft-multiformats-multibase/ | Multibase specification}.
524
+ */
525
+ publicKeyMultibase?: string;
526
+ }
527
+
528
+ /**
529
+ * Represents the various verification relationships defined in a DID document.
530
+ *
531
+ * These verification relationships indicate the intended usage of verification methods within a DID
532
+ * document. Each relationship signifies a different purpose or context in which a verification
533
+ * method can be used, such as authentication, assertionMethod, keyAgreement, capabilityDelegation,
534
+ * and capabilityInvocation. The array provides a standardized set of relationship names for
535
+ * consistent referencing and implementation across different DID methods.
536
+ *
537
+ * @see {@link https://www.w3.org/TR/did-core/#verification-relationships | DID Core Specification, § Verification Relationships}
538
+ */
539
+ export enum DidVerificationRelationship {
540
+ /**
541
+ * Specifies how the DID subject is expected to be authenticated. This is commonly used for
542
+ * purposes like logging into a website or participating in challenge-response protocols.
543
+ *
544
+ * @see {@link https://www.w3.org/TR/did-core/#authentication | DID Core Specification, § Authentication}
545
+ */
546
+ authentication = 'authentication',
547
+
548
+ /**
549
+ * Specifies how the DID subject is expected to express claims, such as for issuing Verifiable
550
+ * Credentials. This relationship is typically used when the DID subject is the issuer of a
551
+ * credential.
552
+ *
553
+ * @see {@link https://www.w3.org/TR/did-core/#assertion | DID Core Specification, § Assertion}
554
+ */
555
+ assertionMethod = 'assertionMethod',
556
+
557
+ /**
558
+ * Specifies how an entity can generate encryption material to communicate confidentially with the
559
+ * DID subject. Often used in scenarios requiring secure communication channels.
560
+ *
561
+ * @see {@link https://www.w3.org/TR/did-core/#key-agreement | DID Core Specification, § Key Agreement}
562
+ */
563
+ keyAgreement = 'keyAgreement',
564
+
565
+ /**
566
+ * Specifies a verification method used by the DID subject to invoke a cryptographic capability.
567
+ * This is frequently associated with authorization actions, like updating the DID Document.
568
+ *
569
+ * @see {@link https://www.w3.org/TR/did-core/#capability-invocation | DID Core Specification, § Capability Invocation}
570
+ */
571
+ capabilityInvocation = 'capabilityInvocation',
572
+
573
+ /**
574
+ * Specifies a mechanism used by the DID subject to delegate a cryptographic capability to another
575
+ * party. This can include delegating access to a specific resource or API.
576
+ *
577
+ * @see {@link https://www.w3.org/TR/did-core/#capability-delegation | DID Core Specification, § Capability Delegation}
578
+ */
579
+ capabilityDelegation = 'capabilityDelegation',
580
+ }
@@ -0,0 +1,93 @@
1
+ import type { KeyValueStore } from '@enbox/common';
2
+
3
+ import type { DidDereferencingOptions, DidDereferencingResult, DidResolutionOptions, DidResolutionResult } from './did-core.js';
4
+
5
+ /**
6
+ * Represents the interface for resolving a Decentralized Identifier (DID) to its corresponding DID
7
+ * document.
8
+ *
9
+ * The `DidResolver` interface defines a single method, `resolve`, which takes a DID URL as input
10
+ * and returns a `Promise` that resolves to a `DidResolutionResult`. This result contains the DID
11
+ * document associated with the given DID, along with metadata about the resolution process.
12
+ *
13
+ * Implementations of this interface are expected to support resolution of DIDs according to the
14
+ * specific rules and methods defined by the DID scheme in use.
15
+ *
16
+ * More information on DID URL dereferencing can be found in the
17
+ * {@link https://www.w3.org/TR/did-core/#did-resolution | DID Core specification}.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const resolutionResult = await didResolver.resolve('did:example:123456789abcdefghi');
22
+ * ```
23
+ */
24
+ export interface DidResolver {
25
+ /**
26
+ * Resolves a DID URI to a DID document and associated metadata.
27
+ *
28
+ * This function should resolve the DID URI in accordance with the relevant DID method
29
+ * specification, using the provided `options`.
30
+ *
31
+ * @param didUri - The DID URI to be resolved.
32
+ * @param options - Optional. The options used for resolving the DID.
33
+ * @returns A {@link DidResolutionResult} object containing the DID document and metadata or an
34
+ * error.
35
+ */
36
+ resolve(didUrl: string, options?: DidResolutionOptions): Promise<DidResolutionResult>;
37
+ }
38
+
39
+ /**
40
+ * Interface for cache implementations used by to store resolved DID documents.
41
+ */
42
+ export interface DidResolverCache extends KeyValueStore<string, DidResolutionResult | void> {}
43
+
44
+ /**
45
+ * Represents the interface for dereferencing a DID URL to a specific resource within a DID
46
+ * document.
47
+ *
48
+ * The `DidUrlDereferencer` interface defines a single method, `dereference`, which takes a DID URL
49
+ * as input and returns a `Promise` that resolves to a `DidDereferencingResult`. This result
50
+ * includes the dereferenced resource (if found) and metadata about the dereferencing process.
51
+ *
52
+ * Dereferencing a DID URL involves parsing the URL to identify the specific part of the DID
53
+ * document being referenced, which could be a verification method, a service endpoint, or the
54
+ * entire document itself.
55
+ *
56
+ * Implementations of this interface must adhere to the dereferencing mechanisms defined in the DID
57
+ * Core specifications, handling various components of the DID URL including the DID itself, path,
58
+ * query, and fragment.
59
+ *
60
+ * More information on DID URL dereferencing can be found in the
61
+ * {@link https://www.w3.org/TR/did-core/#did-url-dereferencing | DID Core specification}.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const dereferenceResult = await didUrlDereferencer.dereference('did:example:123456789abcdefghi#keys-1');
66
+ * ```
67
+ */
68
+ export interface DidUrlDereferencer {
69
+ /**
70
+ * Dereferences a DID (Decentralized Identifier) URL to a corresponding DID resource.
71
+ *
72
+ * This method interprets the DID URL's components, which include the DID method, method-specific
73
+ * identifier, path, query, and fragment, and retrieves the related resource as per the DID Core
74
+ * specifications.
75
+ *
76
+ * @param didUrl - The DID URL string to dereference.
77
+ * @param options - Input options to the dereference function. Optional.
78
+ * @returns a {@link DidDereferencingResult}
79
+ */
80
+ dereference(didUrl: string, options?: DidDereferencingOptions): Promise<DidDereferencingResult>;
81
+ }
82
+
83
+ /**
84
+ * A constant representing an empty DID Resolution Result. This object is used as the basis for a
85
+ * result of DID resolution and is typically augmented with additional properties by the
86
+ * DID method resolver.
87
+ */
88
+ export const EMPTY_DID_RESOLUTION_RESULT: DidResolutionResult = {
89
+ '@context' : 'https://w3id.org/did-resolution/v1',
90
+ didResolutionMetadata : {},
91
+ didDocument : null,
92
+ didDocumentMetadata : {},
93
+ };