@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,59 @@
1
+ import type { Jwk } from '@enbox/crypto';
2
+ import type { DidDocument, DidDocumentMetadata } from './did-core.js';
3
+ /**
4
+ * Represents metadata about a DID resulting from create, update, or deactivate operations.
5
+ */
6
+ export interface DidMetadata extends DidDocumentMetadata {
7
+ /**
8
+ * For DID methods that support publishing, the `published` property indicates whether the DID
9
+ * document has been published to the respective network.
10
+ *
11
+ * A `true` value signifies that the DID document is publicly accessible on the network (e.g.,
12
+ * Mainline DHT), allowing it to be resolved by others. A `false` value implies the DID document
13
+ * is not published, limiting its visibility to public resolution. Absence of this property
14
+ * indicates that the DID method does not support publishing.
15
+ */
16
+ published?: boolean;
17
+ }
18
+ /**
19
+ * Format to document a DID identifier, along with its associated data, which can be exported,
20
+ * saved to a file, or imported. The intent is bundle all of the necessary metadata to enable usage
21
+ * of the DID in different contexts.
22
+ */
23
+ /**
24
+ * Format that documents the key material and metadata of a Decentralized Identifier (DID) to enable
25
+ * usage of the DID in different contexts.
26
+ *
27
+ * This format is useful for exporting, saving to a file, or importing a DID across process
28
+ * boundaries or between different DID method implementations.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * // Generate a new DID.
33
+ * const did = await DidExample.create();
34
+ *
35
+ * // Export to a PortableDid.
36
+ * const portableDid = await did.export();
37
+ *
38
+ * // Instantiate a BearerDid object from a PortableDid.
39
+ * const importedDid = await DidExample.import(portableDid);
40
+ * // The `importedDid` object should be equivalent to the original `did` object.
41
+ * ```
42
+ */
43
+ export interface PortableDid {
44
+ /** {@inheritDoc Did#uri} */
45
+ uri: string;
46
+ /**
47
+ * The DID document associated with this DID.
48
+ *
49
+ * @see {@link https://www.w3.org/TR/did-core/#dfn-diddocument | DID Core Specification, § DID Document}
50
+ */
51
+ document: DidDocument;
52
+ /** {@inheritDoc DidMetadata} */
53
+ metadata: DidMetadata;
54
+ /**
55
+ * An optional array of private keys associated with the DID document's verification methods.
56
+ */
57
+ privateKeys?: Jwk[];
58
+ }
59
+ //# sourceMappingURL=portable-did.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portable-did.d.ts","sourceRoot":"","sources":["../../../src/types/portable-did.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,mBAAmB;IACtD;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;GAIG;AACH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,WAAW;IAC1B,4BAA4B;IAC5B,GAAG,EAAE,MAAM,CAAC;IAEZ;;;;OAIG;IACH,QAAQ,EAAE,WAAW,CAAC;IAEtB,gCAAgC;IAChC,QAAQ,EAAE,WAAW,CAAC;IAEtB;;OAEG;IACH,WAAW,CAAC,EAAE,GAAG,EAAE,CAAC;CACrB"}
@@ -0,0 +1,378 @@
1
+ import type { Jwk } from '@enbox/crypto';
2
+ import type { RequireOnly } from '@enbox/common';
3
+ import type { KeyWithMulticodec } from './types/multibase.js';
4
+ import { DidService, DidDocument, DidVerificationMethod, DidVerificationRelationship } from './types/did-core.js';
5
+ /**
6
+ * Represents a Decentralized Web Node (DWN) service in a DID Document.
7
+ *
8
+ * A DWN DID service is a specialized type of DID service with the `type` set to
9
+ * `DecentralizedWebNode`. It includes specific properties `enc` and `sig` that are used to identify
10
+ * the public keys that can be used to interact with the DID Subject. The values of these properties
11
+ * are strings or arrays of strings containing one or more verification method `id` values present in
12
+ * the same DID document. If the `enc` and/or `sig` properties are an array of strings, an entity
13
+ * interacting with the DID subject is expected to use the verification methods in the order they
14
+ * are listed.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const service: DwnDidService = {
19
+ * id: 'did:example:123#dwn',
20
+ * type: 'DecentralizedWebNode',
21
+ * serviceEndpoint: 'https://enbox-production.up.railway.app',
22
+ * enc: 'did:example:123#key-1',
23
+ * sig: 'did:example:123#key-2'
24
+ * }
25
+ * ```
26
+ *
27
+ * @see {@link https://identity.foundation/decentralized-web-node/spec/ | DIF Decentralized Web Node (DWN) Specification}
28
+ */
29
+ export interface DwnDidService extends DidService {
30
+ /**
31
+ * One or more verification method `id` values that can be used to encrypt information
32
+ * intended for the DID subject.
33
+ */
34
+ enc?: string | string[];
35
+ /**
36
+ * One or more verification method `id` values that will be used by the DID subject to sign data
37
+ * or by another entity to verify signatures created by the DID subject.
38
+ */
39
+ sig: string | string[];
40
+ }
41
+ /**
42
+ * Extracts the fragment part of a Decentralized Identifier (DID) verification method identifier.
43
+ *
44
+ * This function takes any input and aims to return only the fragment of a DID identifier,
45
+ * which comes after the '#' symbol in a DID string. It's designed specifically for handling
46
+ * DID verification method identifiers. The function returns undefined for non-string inputs, inputs
47
+ * that do not contain a '#', or complex data structures like objects or arrays, ensuring that only
48
+ * the fragment part of a DID string is extracted when present.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * console.log(extractDidFragment("did:example:123#key-1")); // Output: "key-1"
53
+ * console.log(extractDidFragment("did:example:123")); // Output: undefined
54
+ * console.log(extractDidFragment({ id: "did:example:123#0", type: "JsonWebKey" })); // Output: undefined
55
+ * console.log(extractDidFragment(undefined)); // Output: undefined
56
+ * ```
57
+ *
58
+ * @param input - The input to be processed. Can be of any type, but the function is designed
59
+ * to work with strings that represent DID verification method identifiers.
60
+ * @returns The fragment part of the DID identifier if the input is a string containing a '#'.
61
+ * Returns an empty string for all other inputs, including non-string types, strings
62
+ * without a '#', and complex data structures.
63
+ */
64
+ export declare function extractDidFragment(input: unknown): string | undefined;
65
+ /**
66
+ * Retrieves services from a given DID document, optionally filtered by `id` or `type`.
67
+ *
68
+ * If no `id` or `type` filters are provided, all defined services are returned.
69
+ *
70
+ * The given DID Document must adhere to the
71
+ * {@link https://www.w3.org/TR/did-core/ | W3C DID Core Specification}.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const didDocument = { ... }; // W3C DID document
76
+ * const services = getServices({ didDocument, type: 'DecentralizedWebNode' });
77
+ * ```
78
+ *
79
+ * @param params - An object containing input parameters for retrieving services.
80
+ * @param params.didDocument - The DID document from which services are retrieved.
81
+ * @param params.id - Optional. A string representing the specific service ID to match. If provided, only the service with this ID will be returned.
82
+ * @param params.type - Optional. A string representing the specific service type to match. If provided, only the service(s) of this type will be returned.
83
+ * @returns An array of services. If no matching service is found, an empty array is returned.
84
+ */
85
+ export declare function getServices({ didDocument, id, type }: {
86
+ didDocument: DidDocument;
87
+ id?: string;
88
+ type?: string;
89
+ }): DidService[];
90
+ /**
91
+ * Retrieves a verification method object from a DID document if there is a match for the given
92
+ * public key.
93
+ *
94
+ * This function searches the verification methods in a given DID document for a match with the
95
+ * provided public key (either in JWK or multibase format). If a matching verification method is
96
+ * found it is returned. If no match is found `null` is returned.
97
+ *
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * const didDocument = {
102
+ * // ... contents of a DID document ...
103
+ * };
104
+ * const publicKeyJwk = { kty: 'OKP', crv: 'Ed25519', x: '...' };
105
+ *
106
+ * const verificationMethod = await getVerificationMethodByKey({
107
+ * didDocument,
108
+ * publicKeyJwk
109
+ * });
110
+ * ```
111
+ *
112
+ * @param params - An object containing input parameters for retrieving the verification method ID.
113
+ * @param params.didDocument - The DID document to search for the verification method.
114
+ * @param params.publicKeyJwk - The public key in JSON Web Key (JWK) format to match against the verification methods in the DID document.
115
+ * @param params.publicKeyMultibase - The public key as a multibase encoded string to match against the verification methods in the DID document.
116
+ * @returns A promise that resolves with the matching verification method, or `null` if no match is found.
117
+ * @throws Throws an `Error` if the `didDocument` parameter is missing or if the `didDocument` does not contain any verification methods.
118
+ */
119
+ export declare function getVerificationMethodByKey({ didDocument, publicKeyJwk, publicKeyMultibase }: {
120
+ didDocument: DidDocument;
121
+ publicKeyJwk?: Jwk;
122
+ publicKeyMultibase?: string;
123
+ }): Promise<DidVerificationMethod | null>;
124
+ /**
125
+ * Retrieves all verification methods from a given DID document, including embedded methods.
126
+ *
127
+ * This function consolidates all verification methods into a single array for easy access and
128
+ * processing. It checks both the primary `verificationMethod` array and the individual verification
129
+ * relationship properties `authentication`, `assertionMethod`, `keyAgreement`,
130
+ * `capabilityInvocation`, and `capabilityDelegation` for embedded methods.
131
+ *
132
+ * The given DID Document must adhere to the
133
+ * {@link https://www.w3.org/TR/did-core/ | W3C DID Core Specification}.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const didDocument = { ... }; // W3C DID document
138
+ * const verificationMethods = getVerificationMethods({ didDocument });
139
+ * ```
140
+ *
141
+ * @param params - An object containing input parameters for retrieving verification methods.
142
+ * @param params.didDocument - The DID document from which verification methods are retrieved.
143
+ * @returns An array of `DidVerificationMethod`. If no verification methods are found, an empty array is returned.
144
+ * @throws Throws an `TypeError` if the `didDocument` parameter is missing.
145
+ */
146
+ export declare function getVerificationMethods({ didDocument }: {
147
+ didDocument: DidDocument;
148
+ }): DidVerificationMethod[];
149
+ /**
150
+ * Retrieves all DID verification method types from a given DID document.
151
+ *
152
+ * The given DID Document must adhere to the
153
+ * {@link https://www.w3.org/TR/did-core/ | W3C DID Core Specification}.
154
+ *
155
+ * @example
156
+ * ```ts
157
+ * const didDocument = {
158
+ * verificationMethod: [
159
+ * {
160
+ * 'id' : 'did:example:123#key-0',
161
+ * 'type' : 'Ed25519VerificationKey2018',
162
+ * 'controller' : 'did:example:123',
163
+ * 'publicKeyBase58' : '3M5RCDjPTWPkKSN3sxUmmMqHbmRPegYP1tjcKyrDbt9J'
164
+ * },
165
+ * {
166
+ * 'id' : 'did:example:123#key-1',
167
+ * 'type' : 'X25519KeyAgreementKey2019',
168
+ * 'controller' : 'did:example:123',
169
+ * 'publicKeyBase58' : 'FbQWLPRhTH95MCkQUeFYdiSoQt8zMwetqfWoxqPgaq7x'
170
+ * },
171
+ * {
172
+ * 'id' : 'did:example:123#key-3',
173
+ * 'type' : 'JsonWebKey2020',
174
+ * 'controller' : 'did:example:123',
175
+ * 'publicKeyJwk' : {
176
+ * 'kty' : 'EC',
177
+ * 'crv' : 'P-256',
178
+ * 'x' : 'Er6KSSnAjI70ObRWhlaMgqyIOQYrDJTE94ej5hybQ2M',
179
+ * 'y' : 'pPVzCOTJwgikPjuUE6UebfZySqEJ0ZtsWFpj7YSPGEk'
180
+ * }
181
+ * }
182
+ * ]
183
+ * },
184
+ * const vmTypes = getVerificationMethodTypes({ didDocument });
185
+ * console.log(vmTypes);
186
+ * // Output: ['Ed25519VerificationKey2018', 'X25519KeyAgreementKey2019', 'JsonWebKey2020']
187
+ * ```
188
+ *
189
+ * @param params - An object containing input parameters for retrieving types.
190
+ * @param params.didDocument - The DID document from which types are retrieved.
191
+ * @returns An array of types. If no types were found, an empty array is returned.
192
+ */
193
+ export declare function getVerificationMethodTypes({ didDocument }: {
194
+ didDocument: DidDocument;
195
+ }): string[];
196
+ /**
197
+ * Retrieves a list of DID verification relationships by a specific method ID from a DID document.
198
+ *
199
+ * This function examines the specified DID document to identify any verification relationships
200
+ * (e.g., `authentication`, `assertionMethod`) that reference a verification method by its method ID
201
+ * or contain an embedded verification method matching the method ID. The method ID is typically a
202
+ * fragment of a DID (e.g., `did:example:123#key-1`) that uniquely identifies a verification method
203
+ * within the DID document.
204
+ *
205
+ * The search considers both direct references to verification methods by their IDs and verification
206
+ * methods embedded within the verification relationship arrays. It returns an array of
207
+ * `DidVerificationRelationship` enums corresponding to the verification relationships that contain
208
+ * the specified method ID.
209
+ *
210
+ * @param params - An object containing input parameters for retrieving verification relationships.
211
+ * @param params.didDocument - The DID document to search for verification relationships.
212
+ * @param params.methodId - The method ID to search for within the verification relationships.
213
+ * @returns An array of `DidVerificationRelationship` enums representing the types of verification
214
+ * relationships that reference the specified method ID.
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * const didDocument: DidDocument = {
219
+ * // ...contents of a DID document...
220
+ * };
221
+ *
222
+ * const relationships = getVerificationRelationshipsById({
223
+ * didDocument,
224
+ * methodId: 'key-1'
225
+ * });
226
+ * console.log(relationships);
227
+ * // Output might include ['authentication', 'assertionMethod'] if those relationships
228
+ * // reference or contain the specified method ID.
229
+ * ```
230
+ */
231
+ export declare function getVerificationRelationshipsById({ didDocument, methodId }: {
232
+ didDocument: DidDocument;
233
+ methodId: string;
234
+ }): DidVerificationRelationship[];
235
+ /**
236
+ * Checks if a given object is a {@link DidService}.
237
+ *
238
+ * A {@link DidService} in the context of DID resources must include the properties `id`, `type`,
239
+ * and `serviceEndpoint`. The `serviceEndpoint` can be a `DidServiceEndpoint` or an array of
240
+ * `DidServiceEndpoint` objects.
241
+ *
242
+ * @example
243
+ * ```ts
244
+ * const service = {
245
+ * id: "did:example:123#service-1",
246
+ * type: "OidcService",
247
+ * serviceEndpoint: "https://example.com/oidc"
248
+ * };
249
+ *
250
+ * if (isDidService(service)) {
251
+ * console.log('The object is a DidService');
252
+ * } else {
253
+ * console.log('The object is not a DidService');
254
+ * }
255
+ * ```
256
+ *
257
+ * @param obj - The object to be checked.
258
+ * @returns `true` if `obj` is a `DidService`; otherwise, `false`.
259
+ */
260
+ export declare function isDidService(obj: unknown): obj is DidService;
261
+ /**
262
+ * Checks if a given object is a {@link DwnDidService}.
263
+ *
264
+ * A {@link DwnDidService} is defined as {@link DidService} object with a `type` of
265
+ * "DecentralizedWebNode" and `enc` and `sig` properties, where both properties are either strings
266
+ * or arrays of strings.
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * const didDocument: DidDocument = {
271
+ * id: 'did:example:123',
272
+ * verificationMethod: [
273
+ * {
274
+ * id: 'did:example:123#key-1',
275
+ * type: 'JsonWebKey2020',
276
+ * controller: 'did:example:123',
277
+ * publicKeyJwk: { ... }
278
+ * },
279
+ * {
280
+ * id: 'did:example:123#key-2',
281
+ * type: 'JsonWebKey2020',
282
+ * controller: 'did:example:123',
283
+ * publicKeyJwk: { ... }
284
+ * }
285
+ * ],
286
+ * service: [
287
+ * {
288
+ * id: 'did:example:123#dwn',
289
+ * type: 'DecentralizedWebNode',
290
+ * serviceEndpoint: 'https://enbox-production.up.railway.app',
291
+ * enc: 'did:example:123#key-1',
292
+ * sig: 'did:example:123#key-2'
293
+ * }
294
+ * ]
295
+ * };
296
+ *
297
+ * if (isDwnService(didDocument.service[0])) {
298
+ * console.log('The object is a DwnDidService');
299
+ * } else {
300
+ * console.log('The object is not a DwnDidService');
301
+ * }
302
+ * ```
303
+ *
304
+ * @see {@link https://identity.foundation/decentralized-web-node/spec/ | Decentralized Web Node (DWN) Specification}
305
+ *
306
+ * @param obj - The object to be checked.
307
+ * @returns `true` if `obj` is a DwnDidService; otherwise, `false`.
308
+ */
309
+ export declare function isDwnDidService(obj: unknown): obj is DwnDidService;
310
+ /**
311
+ * Checks if a given object is a DID Verification Method.
312
+ *
313
+ * A {@link DidVerificationMethod} in the context of DID resources must include the properties `id`,
314
+ * `type`, and `controller`.
315
+ *
316
+ * @example
317
+ * ```ts
318
+ * const resource = {
319
+ * id : "did:example:123#0",
320
+ * type : "JsonWebKey2020",
321
+ * controller : "did:example:123",
322
+ * publicKeyJwk : { ... }
323
+ * };
324
+ *
325
+ * if (isDidVerificationMethod(resource)) {
326
+ * console.log('The resource is a DidVerificationMethod');
327
+ * } else {
328
+ * console.log('The resource is not a DidVerificationMethod');
329
+ * }
330
+ * ```
331
+ *
332
+ * @param obj - The object to be checked.
333
+ * @returns `true` if `obj` is a `DidVerificationMethod`; otherwise, `false`.
334
+ */
335
+ export declare function isDidVerificationMethod(obj: unknown): obj is DidVerificationMethod;
336
+ /**
337
+ * Converts a cryptographic key to a multibase identifier.
338
+ *
339
+ * @remarks
340
+ * This method provides a way to represent a cryptographic key as a multibase identifier.
341
+ * It takes a `Uint8Array` representing the key, and either the multicodec code or multicodec name
342
+ * as input. The method first adds the multicodec prefix to the key, then encodes it into Base58
343
+ * format. Finally, it converts the Base58 encoded key into a multibase identifier.
344
+ *
345
+ * @example
346
+ * ```ts
347
+ * const key = new Uint8Array([...]); // Cryptographic key as Uint8Array
348
+ * const multibaseId = keyBytesToMultibaseId({ key, multicodecName: 'ed25519-pub' });
349
+ * ```
350
+ *
351
+ * @param params - The parameters for the conversion.
352
+ * @returns The multibase identifier as a string.
353
+ */
354
+ export declare function keyBytesToMultibaseId({ keyBytes, multicodecCode, multicodecName }: RequireOnly<KeyWithMulticodec, 'keyBytes'>): string;
355
+ /**
356
+ * Converts a multibase identifier to a cryptographic key.
357
+ *
358
+ * @remarks
359
+ * This function decodes a multibase identifier back into a cryptographic key. It first decodes the
360
+ * identifier from multibase format into Base58 format, and then converts it into a `Uint8Array`.
361
+ * Afterward, it removes the multicodec prefix, extracting the raw key data along with the
362
+ * multicodec code and name.
363
+ *
364
+ * @example
365
+ * ```ts
366
+ * const multibaseKeyId = '...'; // Multibase identifier of the key
367
+ * const { key, multicodecCode, multicodecName } = multibaseIdToKey({ multibaseKeyId });
368
+ * ```
369
+ *
370
+ * @param params - The parameters for the conversion.
371
+ * @param params.multibaseKeyId - The multibase identifier string of the key.
372
+ * @returns An object containing the key as a `Uint8Array` and its multicodec code and name.
373
+ * @throws `DidError` if the multibase identifier is invalid.
374
+ */
375
+ export declare function multibaseIdToKeyBytes({ multibaseKeyId }: {
376
+ multibaseKeyId: string;
377
+ }): Required<KeyWithMulticodec>;
378
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"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"}