@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 @@
1
+ {"version":3,"file":"did-dht.d.ts","sourceRoot":"","sources":["../../../src/methods/did-dht.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA2B,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EACV,GAAG,EACH,MAAM,EACN,SAAS,EACT,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,eAAe,CAAC;AAOvB,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAA2B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YAAY,EAAE,EAAE;QACzD,YAAY,EAAE,YAAY,CAAC;KAC5B,GAAG,OAAO,CAAC,MAAM,CAAC;IAqBnB;;;;;OAKG;WACW,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAQ5E;;;;;OAKG;WACW,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM;IAY5D;;;;;;OAMG;WACiB,wBAAwB,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE;QACzE,MAAM,EAAE,MAAM,CAAC;QACf,gBAAgB,EAAE,gBAAgB,CAAC;KACpC,GAAG,OAAO,CAAC,IAAI,CAAC;IAWjB;;;;OAIG;WACW,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE;CAajE"}
@@ -0,0 +1,492 @@
1
+ import type { CryptoApi, Jwk, KeyIdentifier, KeyImporterExporter, KmsExportKeyParams, KmsImportKeyParams } from '@enbox/crypto';
2
+ import type { IonDocumentModel } from '@decentralized-identity/ion-sdk';
3
+ import type { PortableDid } from '../types/portable-did.js';
4
+ import type { DidCreateOptions, DidCreateVerificationMethod, DidRegistrationResult } from '../methods/did-method.js';
5
+ import type { DidService, DidDocument, DidResolutionResult, DidResolutionOptions, DidVerificationMethod, DidVerificationRelationship } from '../types/did-core.js';
6
+ import { BearerDid } from '../bearer-did.js';
7
+ import { DidMethod } from '../methods/did-method.js';
8
+ /**
9
+ * Options for creating a Decentralized Identifier (DID) using the DID ION method.
10
+ */
11
+ export interface DidIonCreateOptions<TKms> extends DidCreateOptions<TKms> {
12
+ /**
13
+ * Optional. The URI of a server involved in executing DID method operations. In the context of
14
+ * DID creation, the endpoint is expected to be a Sidetree node. If not specified, a default
15
+ * gateway node is used.
16
+ */
17
+ gatewayUri?: string;
18
+ /**
19
+ * Optional. Determines whether the created DID should be published to a Sidetree node.
20
+ *
21
+ * If set to `true` or omitted, the DID is publicly discoverable. If `false`, the DID is not
22
+ * published and cannot be resolved by others. By default, newly created DIDs are published.
23
+ *
24
+ * @see {@link https://identity.foundation/sidetree/spec/#create | Sidetree Protocol Specification, § Create}
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const did = await DidIon.create({
29
+ * options: {
30
+ * publish: false
31
+ * };
32
+ * ```
33
+ */
34
+ publish?: boolean;
35
+ /**
36
+ * Optional. An array of service endpoints associated with the DID.
37
+ *
38
+ * Services are used in DID documents to express ways of communicating with the DID subject or
39
+ * associated entities. A service can be any type of service the DID subject wants to advertise,
40
+ * including decentralized identity management services for further discovery, authentication,
41
+ * authorization, or interaction.
42
+ *
43
+ * @see {@link https://www.w3.org/TR/did-core/#services | DID Core Specification, § Services}
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const did = await DidIon.create({
48
+ * options: {
49
+ * services: [
50
+ * {
51
+ * id: 'dwn',
52
+ * type: 'DecentralizedWebNode',
53
+ * serviceEndpoint: ['https://example.com/dwn1', 'https://example/dwn2']
54
+ * }
55
+ * ]
56
+ * };
57
+ * ```
58
+ */
59
+ services?: DidService[];
60
+ /**
61
+ * Optional. An array of verification methods to be included in the DID document.
62
+ *
63
+ * By default, a newly created DID ION document will contain a single Ed25519 verification method.
64
+ * Additional verification methods can be added to the DID document using the
65
+ * `verificationMethods` property.
66
+ *
67
+ * @see {@link https://www.w3.org/TR/did-core/#verification-methods | DID Core Specification, § Verification Methods}
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const did = await DidIon.create({
72
+ * options: {
73
+ * verificationMethods: [
74
+ * {
75
+ * algorithm: 'Ed25519',
76
+ * purposes: ['authentication', 'assertionMethod']
77
+ * },
78
+ * {
79
+ * algorithm: 'Ed25519',
80
+ * id: 'dwn-sig',
81
+ * purposes: ['authentication', 'assertionMethod']
82
+ * }
83
+ * ]
84
+ * };
85
+ * ```
86
+ */
87
+ verificationMethods?: DidCreateVerificationMethod<TKms>[];
88
+ }
89
+ /**
90
+ * Represents the request model for managing DID documents within the ION network, according to the
91
+ * Sidetree protocol specification.
92
+ */
93
+ export interface DidIonCreateRequest {
94
+ /** The type of operation to perform, which is always 'create' for a Create Operation. */
95
+ type: 'create';
96
+ /** Contains properties related to the initial state of the DID document. */
97
+ suffixData: {
98
+ /** A hash of the `delta` object, representing the initial changes to the DID document. */
99
+ deltaHash: string;
100
+ /** A commitment value used for future recovery operations, hashed for security. */
101
+ recoveryCommitment: string;
102
+ };
103
+ /** Details the changes to be applied to the DID document in this operation. */
104
+ delta: {
105
+ /** A commitment value used for the next update operation, hashed for security. */
106
+ updateCommitment: string;
107
+ /** An array of patch objects specifying the modifications to apply to the DID document. */
108
+ patches: {
109
+ /** The type of modification to perform (e.g., adding or removing public keys or service
110
+ * endpoints). */
111
+ action: string;
112
+ /** The document state or partial state to apply with this patch. */
113
+ document: IonDocumentModel;
114
+ }[];
115
+ };
116
+ }
117
+ /**
118
+ * Represents a {@link DidVerificationMethod | DID verification method} in the context of DID ION
119
+ * create, update, deactivate, and resolve operations.
120
+ *
121
+ * Unlike the DID Core standard {@link DidVerificationMethod} interface, this type is specific to
122
+ * the ION method operations and only includes the `id`, `publicKeyJwk`, and `purposes` properties:
123
+ * - The `id` property is optional and specifies the identifier fragment of the verification method.
124
+ * - The `publicKeyJwk` property is required and represents the public key in JWK format.
125
+ * - The `purposes` property is required and specifies the purposes for which the verification
126
+ * method can be used.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * const verificationMethod: DidIonVerificationMethod = {
131
+ * id : 'sig',
132
+ * publicKeyJwk : {
133
+ * kty : 'OKP',
134
+ * crv : 'Ed25519',
135
+ * x : 'o40shZrsco-CfEqk6mFsXfcP94ly3Az3gm84PzAUsXo',
136
+ * kid : 'BDp0xim82GswlxnPV8TPtBdUw80wkGIF8gjFbw1x5iQ',
137
+ * },
138
+ * purposes: ['authentication', 'assertionMethod']
139
+ * };
140
+ * ```
141
+ */
142
+ export interface DidIonVerificationMethod {
143
+ /**
144
+ * Optionally specify the identifier fragment of the verification method.
145
+ *
146
+ * If not specified, the method's ID will be generated from the key's ID or thumbprint.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * const verificationMethod: DidIonVerificationMethod = {
151
+ * id: 'sig',
152
+ * ...
153
+ * };
154
+ * ```
155
+ */
156
+ id?: string;
157
+ /**
158
+ * A public key in JWK format.
159
+ *
160
+ * A JSON Web Key (JWK) that conforms to {@link https://datatracker.ietf.org/doc/html/rfc7517 | RFC 7517}.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * const verificationMethod: DidIonVerificationMethod = {
165
+ * publicKeyJwk: {
166
+ * kty : "OKP",
167
+ * crv : "X25519",
168
+ * x : "7XdJtNmJ9pV_O_3mxWdn6YjiHJ-HhNkdYQARzVU_mwY",
169
+ * kid : "xtsuKULPh6VN9fuJMRwj66cDfQyLaxuXHkMlmAe_v6I"
170
+ * },
171
+ * ...
172
+ * };
173
+ * ```
174
+ */
175
+ publicKeyJwk: Jwk;
176
+ /**
177
+ * Specify the purposes for which a verification method is intended to be used in a DID document.
178
+ *
179
+ * The `purposes` property defines the specific
180
+ * {@link DidVerificationRelationship | verification relationships} between the DID subject and
181
+ * the verification method. This enables the verification method to be utilized for distinct
182
+ * actions such as authentication, assertion, key agreement, capability delegation, and others. It
183
+ * is important for verifiers to recognize that a verification method must be associated with the
184
+ * relevant purpose in the DID document to be valid for that specific use case.
185
+ *
186
+ * @example
187
+ * ```ts
188
+ * const verificationMethod: DidIonVerificationMethod = {
189
+ * purposes: ['authentication', 'assertionMethod'],
190
+ * ...
191
+ * };
192
+ * ```
193
+ */
194
+ purposes: (DidVerificationRelationship | keyof typeof DidVerificationRelationship)[];
195
+ }
196
+ /**
197
+ * `IonPortableDid` interface extends the {@link PortableDid} interface.
198
+ *
199
+ * It represents a Decentralized Identifier (DID) that is portable and can be used across different
200
+ * domains, including the ION specific recovery and update keys.
201
+ */
202
+ export interface IonPortableDid extends PortableDid {
203
+ /** The JSON Web Key (JWK) used for recovery purposes. */
204
+ recoveryKey: Jwk;
205
+ /** The JSON Web Key (JWK) used for updating the DID. */
206
+ updateKey: Jwk;
207
+ }
208
+ /**
209
+ * Enumerates the types of keys that can be used in a DID ION document.
210
+ *
211
+ * The DID ION method supports various cryptographic key types. These key types are essential for
212
+ * the creation and management of DIDs and their associated cryptographic operations like signing
213
+ * and encryption.
214
+ */
215
+ export declare enum DidIonRegisteredKeyType {
216
+ /**
217
+ * Ed25519: A public-key signature system using the EdDSA (Edwards-curve Digital Signature
218
+ * Algorithm) and Curve25519.
219
+ */
220
+ Ed25519 = "Ed25519",
221
+ /**
222
+ * secp256k1: A cryptographic curve used for digital signatures in a range of decentralized
223
+ * systems.
224
+ */
225
+ secp256k1 = "secp256k1",
226
+ /**
227
+ * secp256r1: Also known as P-256 or prime256v1, this curve is used for cryptographic operations
228
+ * and is widely supported in various cryptographic libraries and standards.
229
+ */
230
+ secp256r1 = "secp256r1",
231
+ /**
232
+ * X25519: A Diffie-Hellman key exchange algorithm using Curve25519.
233
+ */
234
+ X25519 = "X25519"
235
+ }
236
+ /**
237
+ * The `DidIon` class provides an implementation of the `did:ion` DID method.
238
+ *
239
+ * Features:
240
+ * - DID Creation: Create new `did:ion` DIDs.
241
+ * - DID Key Management: Instantiate a DID object from an existing key in a Key Management System
242
+ * (KMS). If supported by the KMS, a DID's key can be exported to a portable
243
+ * DID format.
244
+ * - DID Resolution: Resolve a `did:ion` to its corresponding DID Document stored in the Sidetree
245
+ * network.
246
+ * - Signature Operations: Sign and verify messages using keys associated with a DID.
247
+ *
248
+ * @see {@link https://identity.foundation/sidetree/spec/ | Sidetree Protocol Specification}
249
+ * @see {@link https://github.com/decentralized-identity/ion/blob/master/docs/design.md | ION Design Document}
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * // DID Creation
254
+ * const did = await DidIon.create();
255
+ *
256
+ * // DID Creation with a KMS
257
+ * const keyManager = new LocalKeyManager();
258
+ * const did = await DidIon.create({ keyManager });
259
+ *
260
+ * // DID Resolution
261
+ * const resolutionResult = await DidIon.resolve({ did: did.uri });
262
+ *
263
+ * // Signature Operations
264
+ * const signer = await did.getSigner();
265
+ * const signature = await signer.sign({ data: new TextEncoder().encode('Message') });
266
+ * const isValid = await signer.verify({ data: new TextEncoder().encode('Message'), signature });
267
+ *
268
+ * // Key Management
269
+ *
270
+ * // Instantiate a DID object for a published DID with existing keys in a KMS
271
+ * const did = await DidIon.fromKeyManager({
272
+ * didUri: 'did:ion:EiAzB7K-xDIKc1csXo5HX2eNBoemK9feNhL3cKwfukYOug',
273
+ * keyManager
274
+ * });
275
+ *
276
+ * // Convert a DID object to a portable format
277
+ * const portableDid = await DidIon.toKeys({ did });
278
+ * ```
279
+ */
280
+ export declare class DidIon extends DidMethod {
281
+ /**
282
+ * Name of the DID method, as defined in the DID ION specification.
283
+ */
284
+ static methodName: string;
285
+ /**
286
+ * Creates a new DID using the `did:ion` method formed from a newly generated key.
287
+ *
288
+ * Notes:
289
+ * - If no `options` are given, by default a new Ed25519 key will be generated.
290
+ *
291
+ * @example
292
+ * ```ts
293
+ * // DID Creation
294
+ * const did = await DidIon.create();
295
+ *
296
+ * // DID Creation with a KMS
297
+ * const keyManager = new LocalKeyManager();
298
+ * const did = await DidIon.create({ keyManager });
299
+ * ```
300
+ *
301
+ * @param params - The parameters for the create operation.
302
+ * @param params.keyManager - Optionally specify a Key Management System (KMS) used to generate
303
+ * keys and sign data.
304
+ * @param params.options - Optional parameters that can be specified when creating a new DID.
305
+ * @returns A Promise resolving to a {@link BearerDid} object representing the new DID.
306
+ */
307
+ static create<TKms extends CryptoApi | undefined = undefined>({ keyManager, options }?: {
308
+ keyManager?: TKms;
309
+ options?: DidIonCreateOptions<TKms>;
310
+ }): Promise<BearerDid>;
311
+ /**
312
+ * Given the W3C DID Document of a `did:ion` DID, return the verification method that will be used
313
+ * for signing messages and credentials. If given, the `methodId` parameter is used to select the
314
+ * verification method. If not given, the first verification method in the authentication property
315
+ * in the DID Document is used.
316
+ *
317
+ * @param params - The parameters for the `getSigningMethod` operation.
318
+ * @param params.didDocument - DID Document to get the verification method from.
319
+ * @param params.methodId - ID of the verification method to use for signing.
320
+ * @returns Verification method to use for signing.
321
+ */
322
+ static getSigningMethod({ didDocument, methodId }: {
323
+ didDocument: DidDocument;
324
+ methodId?: string;
325
+ }): Promise<DidVerificationMethod>;
326
+ /**
327
+ * Instantiates a {@link BearerDid} object for the DID ION method from a given {@link PortableDid}.
328
+ *
329
+ * This method allows for the creation of a `BearerDid` object using a previously created DID's
330
+ * key material, DID document, and metadata.
331
+ *
332
+ * @example
333
+ * ```ts
334
+ * // Export an existing BearerDid to PortableDid format.
335
+ * const portableDid = await did.export();
336
+ * // Reconstruct a BearerDid object from the PortableDid.
337
+ * const did = await DidIon.import({ portableDid });
338
+ * ```
339
+ *
340
+ * @param params - The parameters for the import operation.
341
+ * @param params.portableDid - The PortableDid object to import.
342
+ * @param params.keyManager - Optionally specify an external Key Management System (KMS) used to
343
+ * generate keys and sign data. If not given, a new
344
+ * {@link LocalKeyManager} instance will be created and
345
+ * used.
346
+ * @returns A Promise resolving to a `BearerDid` object representing the DID formed from the
347
+ * provided PortableDid.
348
+ * @throws An error if the DID document does not contain any verification methods or the keys for
349
+ * any verification method are missing in the key manager.
350
+ */
351
+ static import({ portableDid, keyManager }: {
352
+ keyManager?: CryptoApi & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
353
+ portableDid: PortableDid;
354
+ }): Promise<BearerDid>;
355
+ /**
356
+ * Publishes a DID to a Sidetree node, making it publicly discoverable and resolvable.
357
+ *
358
+ * This method handles the publication of a DID Document associated with a `did:ion` DID to a
359
+ * Sidetree node.
360
+ *
361
+ * @remarks
362
+ * - This method is typically invoked automatically during the creation of a new DID unless the
363
+ * `publish` option is set to `false`.
364
+ * - For existing, unpublished DIDs, it can be used to publish the DID Document to a Sidetree node.
365
+ * - The method relies on the specified Sidetree node to interface with the network.
366
+ *
367
+ * @param params - The parameters for the `publish` operation.
368
+ * @param params.did - The `BearerDid` object representing the DID to be published.
369
+ * @param params.gatewayUri - Optional. The URI of a server involved in executing DID
370
+ * method operations. In the context of publishing, the
371
+ * endpoint is expected to be a Sidetree node. If not
372
+ * specified, a default node is used.
373
+ * @returns A Promise resolving to a boolean indicating whether the publication was successful.
374
+ *
375
+ * @example
376
+ * ```ts
377
+ * // Generate a new DID and keys but explicitly disable publishing.
378
+ * const did = await DidIon.create({ options: { publish: false } });
379
+ * // Publish the DID to the Sidetree network.
380
+ * const isPublished = await DidIon.publish({ did });
381
+ * // `isPublished` is true if the DID was successfully published.
382
+ * ```
383
+ */
384
+ static publish({ did, gatewayUri }: {
385
+ did: BearerDid;
386
+ gatewayUri?: string;
387
+ }): Promise<DidRegistrationResult>;
388
+ /**
389
+ * Resolves a `did:ion` identifier to its corresponding DID document.
390
+ *
391
+ * This method performs the resolution of a `did:ion` DID, retrieving its DID Document from the
392
+ * Sidetree-based DID overlay network. The process involves querying a Sidetree node to retrieve
393
+ * the DID Document that corresponds to the given DID identifier.
394
+ *
395
+ * @remarks
396
+ * - If a `gatewayUri` option is not specified, a default node is used to access the Sidetree
397
+ * network.
398
+ * - It decodes the DID identifier and retrieves the associated DID Document and metadata.
399
+ * - In case of resolution failure, appropriate error information is returned.
400
+ *
401
+ * @example
402
+ * ```ts
403
+ * const resolutionResult = await DidIon.resolve('did:ion:example');
404
+ * ```
405
+ *
406
+ * @param didUri - The DID to be resolved.
407
+ * @param options - Optional parameters for resolving the DID. Unused by this DID method.
408
+ * @returns A Promise resolving to a {@link DidResolutionResult} object representing the result of the resolution.
409
+ */
410
+ static resolve(didUri: string, options?: DidResolutionOptions): Promise<DidResolutionResult>;
411
+ }
412
+ /**
413
+ * The `DidIonUtils` class provides utility functions to support operations in the DID ION method.
414
+ */
415
+ export declare class DidIonUtils {
416
+ /**
417
+ * Appends a specified path to a base URL, ensuring proper formatting of the resulting URL.
418
+ *
419
+ * This method is useful for constructing URLs for accessing various endpoints, such as Sidetree
420
+ * nodes in the ION network. It handles the nuances of URL path concatenation, including the
421
+ * addition or removal of leading/trailing slashes, to create a well-formed URL.
422
+ *
423
+ * @param params - The parameters for URL construction.
424
+ * @param params.baseUrl - The base URL to which the path will be appended.
425
+ * @param params.path - The path to append to the base URL.
426
+ * @returns The fully constructed URL string with the path appended to the base URL.
427
+ */
428
+ static appendPathToUrl({ baseUrl, path }: {
429
+ baseUrl: string;
430
+ path: string;
431
+ }): string;
432
+ /**
433
+ * Computes the Long Form DID URI given an ION DID's recovery key, update key, services, and
434
+ * verification methods.
435
+ *
436
+ * @param params - The parameters for computing the Long Form DID URI.
437
+ * @param params.recoveryKey - The ION Recovery Key.
438
+ * @param params.updateKey - The ION Update Key.
439
+ * @param params.services - An array of services associated with the DID.
440
+ * @param params.verificationMethods - An array of verification methods associated with the DID.
441
+ * @returns A Promise resolving to the Long Form DID URI.
442
+ */
443
+ static computeLongFormDidUri({ recoveryKey, updateKey, services, verificationMethods }: {
444
+ recoveryKey: Jwk;
445
+ updateKey: Jwk;
446
+ services: DidService[];
447
+ verificationMethods: DidIonVerificationMethod[];
448
+ }): Promise<string>;
449
+ /**
450
+ * Constructs a Sidetree Create Operation request for a DID document within the ION network.
451
+ *
452
+ * This method prepares the necessary payload for submitting a Create Operation to a Sidetree
453
+ * node, encapsulating the details of the DID document, recovery key, and update key.
454
+ *
455
+ * @param params - Parameters required to construct the Create Operation request.
456
+ * @param params.ionDocument - The DID document model containing public keys and service endpoints.
457
+ * @param params.recoveryKey - The recovery public key in JWK format.
458
+ * @param params.updateKey - The update public key in JWK format.
459
+ * @returns A promise resolving to the ION Create Operation request model, ready for submission to a Sidetree node.
460
+ */
461
+ static constructCreateRequest({ ionDocument, recoveryKey, updateKey }: {
462
+ ionDocument: IonDocumentModel;
463
+ recoveryKey: Jwk;
464
+ updateKey: Jwk;
465
+ }): Promise<DidIonCreateRequest>;
466
+ /**
467
+ * Assembles an ION document model from provided services and verification methods
468
+ *
469
+ * This model serves as the foundation for a DID document in the ION network, facilitating the
470
+ * creation and management of decentralized identities. It translates service endpoints and
471
+ * public keys into a format compatible with the Sidetree protocol, ensuring the resulting DID
472
+ * document adheres to the required specifications for ION DIDs. This method is essential for
473
+ * constructing the payload needed to register or update DIDs within the ION network.
474
+ *
475
+ * @param params - The parameters containing the services and verification methods to include in the ION document.
476
+ * @param params.services - A list of service endpoints to be included in the DID document, specifying ways to interact with the DID subject.
477
+ * @param params.verificationMethods - A list of verification methods to be included, detailing the cryptographic keys and their intended uses within the DID document.
478
+ * @returns A Promise resolving to an `IonDocumentModel`, ready for use in Sidetree operations like DID creation and updates.
479
+ */
480
+ static createIonDocument({ services, verificationMethods }: {
481
+ services: DidService[];
482
+ verificationMethods: DidIonVerificationMethod[];
483
+ }): Promise<IonDocumentModel>;
484
+ /**
485
+ * Normalize the given JWK to include only specific members and in lexicographic order.
486
+ *
487
+ * @param jwk - The JWK to normalize.
488
+ * @returns The normalized JWK.
489
+ */
490
+ private static normalizeJwk;
491
+ }
492
+ //# sourceMappingURL=did-ion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did-ion.d.ts","sourceRoot":"","sources":["../../../src/methods/did-ion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,aAAa,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAChI,OAAO,KAAK,EAEV,gBAAgB,EAGjB,MAAM,iCAAiC,CAAC;AAKzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACrH,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,2BAA2B,EAC5B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAA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