@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.
- package/LICENSE +201 -0
- package/README.md +1 -0
- package/dist/browser.js +77 -0
- package/dist/browser.js.map +7 -0
- package/dist/browser.mjs +77 -0
- package/dist/browser.mjs.map +7 -0
- package/dist/cjs/index.js +6303 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/utils.js +245 -0
- package/dist/cjs/utils.js.map +7 -0
- package/dist/esm/bearer-did.js +201 -0
- package/dist/esm/bearer-did.js.map +1 -0
- package/dist/esm/did-error.js +62 -0
- package/dist/esm/did-error.js.map +1 -0
- package/dist/esm/did.js +114 -0
- package/dist/esm/did.js.map +1 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/methods/did-dht.js +1241 -0
- package/dist/esm/methods/did-dht.js.map +1 -0
- package/dist/esm/methods/did-ion.js +570 -0
- package/dist/esm/methods/did-ion.js.map +1 -0
- package/dist/esm/methods/did-jwk.js +298 -0
- package/dist/esm/methods/did-jwk.js.map +1 -0
- package/dist/esm/methods/did-key.js +983 -0
- package/dist/esm/methods/did-key.js.map +1 -0
- package/dist/esm/methods/did-method.js +53 -0
- package/dist/esm/methods/did-method.js.map +1 -0
- package/dist/esm/methods/did-web.js +83 -0
- package/dist/esm/methods/did-web.js.map +1 -0
- package/dist/esm/resolver/resolver-cache-level.js +101 -0
- package/dist/esm/resolver/resolver-cache-level.js.map +1 -0
- package/dist/esm/resolver/resolver-cache-noop.js +24 -0
- package/dist/esm/resolver/resolver-cache-noop.js.map +1 -0
- package/dist/esm/resolver/universal-resolver.js +187 -0
- package/dist/esm/resolver/universal-resolver.js.map +1 -0
- package/dist/esm/types/did-core.js +51 -0
- package/dist/esm/types/did-core.js.map +1 -0
- package/dist/esm/types/did-resolution.js +12 -0
- package/dist/esm/types/did-resolution.js.map +1 -0
- package/dist/esm/types/multibase.js +2 -0
- package/dist/esm/types/multibase.js.map +1 -0
- package/dist/esm/types/portable-did.js +2 -0
- package/dist/esm/types/portable-did.js.map +1 -0
- package/dist/esm/utils.js +458 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/types/bearer-did.d.ts +143 -0
- package/dist/types/bearer-did.d.ts.map +1 -0
- package/dist/types/did-error.d.ts +50 -0
- package/dist/types/did-error.d.ts.map +1 -0
- package/dist/types/did.d.ts +125 -0
- package/dist/types/did.d.ts.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/methods/did-dht.d.ts +682 -0
- package/dist/types/methods/did-dht.d.ts.map +1 -0
- package/dist/types/methods/did-ion.d.ts +492 -0
- package/dist/types/methods/did-ion.d.ts.map +1 -0
- package/dist/types/methods/did-jwk.d.ts +236 -0
- package/dist/types/methods/did-jwk.d.ts.map +1 -0
- package/dist/types/methods/did-key.d.ts +499 -0
- package/dist/types/methods/did-key.d.ts.map +1 -0
- package/dist/types/methods/did-method.d.ts +238 -0
- package/dist/types/methods/did-method.d.ts.map +1 -0
- package/dist/types/methods/did-web.d.ts +37 -0
- package/dist/types/methods/did-web.d.ts.map +1 -0
- package/dist/types/resolver/resolver-cache-level.d.ts +86 -0
- package/dist/types/resolver/resolver-cache-level.d.ts.map +1 -0
- package/dist/types/resolver/resolver-cache-noop.d.ts +9 -0
- package/dist/types/resolver/resolver-cache-noop.d.ts.map +1 -0
- package/dist/types/resolver/universal-resolver.d.ts +109 -0
- package/dist/types/resolver/universal-resolver.d.ts.map +1 -0
- package/dist/types/types/did-core.d.ts +523 -0
- package/dist/types/types/did-core.d.ts.map +1 -0
- package/dist/types/types/did-resolution.d.ts +85 -0
- package/dist/types/types/did-resolution.d.ts.map +1 -0
- package/dist/types/types/multibase.d.ts +28 -0
- package/dist/types/types/multibase.d.ts.map +1 -0
- package/dist/types/types/portable-did.d.ts +59 -0
- package/dist/types/types/portable-did.d.ts.map +1 -0
- package/dist/types/utils.d.ts +378 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +7 -0
- package/package.json +116 -0
- package/src/bearer-did.ts +287 -0
- package/src/did-error.ts +75 -0
- package/src/did.ts +186 -0
- package/src/index.ts +21 -0
- package/src/methods/did-dht.ts +1637 -0
- package/src/methods/did-ion.ts +887 -0
- package/src/methods/did-jwk.ts +410 -0
- package/src/methods/did-key.ts +1248 -0
- package/src/methods/did-method.ts +276 -0
- package/src/methods/did-web.ts +96 -0
- package/src/resolver/resolver-cache-level.ts +163 -0
- package/src/resolver/resolver-cache-noop.ts +26 -0
- package/src/resolver/universal-resolver.ts +238 -0
- package/src/types/did-core.ts +580 -0
- package/src/types/did-resolution.ts +93 -0
- package/src/types/multibase.ts +29 -0
- package/src/types/portable-did.ts +64 -0
- package/src/utils.ts +532 -0
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
import type { Packet, TxtData } from '@dnsquery/dns-packet';
|
|
2
|
+
import type { Jwk, Signer, CryptoApi, KeyIdentifier, KmsExportKeyParams, KmsImportKeyParams, KeyImporterExporter, AsymmetricKeyConverter } from '@enbox/crypto';
|
|
3
|
+
import type { DidMetadata, PortableDid } from '../types/portable-did.js';
|
|
4
|
+
import type { DidCreateOptions, DidCreateVerificationMethod, DidRegistrationResult } from './did-method.js';
|
|
5
|
+
import type { DidService, DidDocument, DidResolutionResult, DidResolutionOptions, DidVerificationMethod } from '../types/did-core.js';
|
|
6
|
+
import { DidMethod } from './did-method.js';
|
|
7
|
+
import { BearerDid } from '../bearer-did.js';
|
|
8
|
+
/**
|
|
9
|
+
* Represents a BEP44 message, which is used for storing and retrieving data in the Mainline DHT
|
|
10
|
+
* network.
|
|
11
|
+
*
|
|
12
|
+
* A BEP44 message is used primarily in the context of the DID DHT method for publishing and
|
|
13
|
+
* resolving DID documents in the DHT network. This type encapsulates the data structure required
|
|
14
|
+
* for such operations in accordance with BEP44.
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://www.bittorrent.org/beps/bep_0044.html | BEP44}
|
|
17
|
+
*/
|
|
18
|
+
export interface Bep44Message {
|
|
19
|
+
/**
|
|
20
|
+
* The public key bytes of the Identity Key, which serves as the identifier in the DHT network for
|
|
21
|
+
* the corresponding BEP44 message.
|
|
22
|
+
*/
|
|
23
|
+
k: Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* The sequence number of the message, used to ensure the latest version of the data is retrieved
|
|
26
|
+
* and updated. It's a monotonically increasing number.
|
|
27
|
+
*/
|
|
28
|
+
seq: number;
|
|
29
|
+
/**
|
|
30
|
+
* The signature of the message, ensuring the authenticity and integrity of the data. It's
|
|
31
|
+
* computed over the bencoded sequence number and value.
|
|
32
|
+
*/
|
|
33
|
+
sig: Uint8Array;
|
|
34
|
+
/**
|
|
35
|
+
* The actual data being stored or retrieved from the DHT network, typically encoded in a format
|
|
36
|
+
* suitable for DNS packet representation of a DID Document.
|
|
37
|
+
*/
|
|
38
|
+
v: Uint8Array;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Options for creating a Decentralized Identifier (DID) using the DID DHT method.
|
|
42
|
+
*/
|
|
43
|
+
export interface DidDhtCreateOptions<TKms> extends DidCreateOptions<TKms> {
|
|
44
|
+
/**
|
|
45
|
+
* Optionally specify that the DID Subject is also identified by one or more other DIDs or URIs.
|
|
46
|
+
*
|
|
47
|
+
* A DID subject can have multiple identifiers for different purposes, or at different times.
|
|
48
|
+
* The assertion that two or more DIDs (or other types of URI) refer to the same DID subject can
|
|
49
|
+
* be made using the `alsoKnownAs` property.
|
|
50
|
+
*
|
|
51
|
+
* @see {@link https://www.w3.org/TR/did-core/#also-known-as | DID Core Specification, § Also Known As}
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const did = await DidDht.create({
|
|
56
|
+
* options: {
|
|
57
|
+
* alsoKnownAs: 'did:example:123'
|
|
58
|
+
* };
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
alsoKnownAs?: string[];
|
|
62
|
+
/**
|
|
63
|
+
* Optionally specify which DID (or DIDs) is authorized to make changes to the DID document.
|
|
64
|
+
*
|
|
65
|
+
* A DID controller is an entity that is authorized to make changes to a DID document. Typically,
|
|
66
|
+
* only the DID Subject (i.e., the value of `id` property in the DID document) is authoritative.
|
|
67
|
+
* However, another DID (or DIDs) can be specified as the DID controller, and when doing so, any
|
|
68
|
+
* verification methods contained in the DID document for the other DID should be accepted as
|
|
69
|
+
* authoritative. In other words, proofs created by the controller DID should be considered
|
|
70
|
+
* equivalent to proofs created by the DID Subject.
|
|
71
|
+
*
|
|
72
|
+
* @see {@link https://www.w3.org/TR/did-core/#did-controller | DID Core Specification, § DID Controller}
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* const did = await DidDht.create({
|
|
77
|
+
* options: {
|
|
78
|
+
* controller: 'did:example:123'
|
|
79
|
+
* };
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
controllers?: string | string[];
|
|
83
|
+
/**
|
|
84
|
+
* Optional. The URI of a server involved in executing DID method operations. In the context of
|
|
85
|
+
* DID creation, the endpoint is expected to be a DID DHT Gateway or Pkarr relay. If not
|
|
86
|
+
* specified, a default gateway node is used.
|
|
87
|
+
*/
|
|
88
|
+
gatewayUri?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Optional. Determines whether the created DID should be published to the DHT network.
|
|
91
|
+
*
|
|
92
|
+
* If set to `true` or omitted, the DID is publicly discoverable. If `false`, the DID is not
|
|
93
|
+
* published and cannot be resolved by others. By default, newly created DIDs are published.
|
|
94
|
+
*
|
|
95
|
+
* @see {@link https://did-dht.com | DID DHT Method Specification}
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* const did = await DidDht.create({
|
|
100
|
+
* options: {
|
|
101
|
+
* publish: false
|
|
102
|
+
* };
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
publish?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Optional. An array of service endpoints associated with the DID.
|
|
108
|
+
*
|
|
109
|
+
* Services are used in DID documents to express ways of communicating with the DID subject or
|
|
110
|
+
* associated entities. A service can be any type of service the DID subject wants to advertise,
|
|
111
|
+
* including decentralized identity management services for further discovery, authentication,
|
|
112
|
+
* authorization, or interaction.
|
|
113
|
+
*
|
|
114
|
+
* @see {@link https://www.w3.org/TR/did-core/#services | DID Core Specification, § Services}
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* const did = await DidDht.create({
|
|
119
|
+
* options: {
|
|
120
|
+
* services: [
|
|
121
|
+
* {
|
|
122
|
+
* id: 'did:dht:i9xkp8ddcbcg8jwq54ox699wuzxyifsqx4jru45zodqu453ksz6y#dwn',
|
|
123
|
+
* type: 'DecentralizedWebNode',
|
|
124
|
+
* serviceEndpoint: ['https://example.com/dwn1', 'https://example/dwn2']
|
|
125
|
+
* }
|
|
126
|
+
* ]
|
|
127
|
+
* };
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
services?: DidService[];
|
|
131
|
+
/**
|
|
132
|
+
* Optionally specify one or more registered DID DHT types to make the DID discovereable.
|
|
133
|
+
*
|
|
134
|
+
* Type indexing is an OPTIONAL feature that enables DIDs to become discoverable. DIDs that wish
|
|
135
|
+
* to be discoverable and resolveable by type can include one or more types when publishing their
|
|
136
|
+
* DID document to a DID DHT Gateway.
|
|
137
|
+
*
|
|
138
|
+
* The registered DID types are published in the {@link https://did-dht.com/registry/index.html#indexed-types | DID DHT Registry}.
|
|
139
|
+
*/
|
|
140
|
+
types?: (DidDhtRegisteredDidType | keyof typeof DidDhtRegisteredDidType)[];
|
|
141
|
+
/**
|
|
142
|
+
* Optional. An array of verification methods to be included in the DID document.
|
|
143
|
+
*
|
|
144
|
+
* By default, a newly created DID DHT document will contain a single Ed25519 verification method,
|
|
145
|
+
* also known as the {@link https://did-dht.com/#term:identity-key | Identity Key}. Additional
|
|
146
|
+
* verification methods can be added to the DID document using the `verificationMethods` property.
|
|
147
|
+
*
|
|
148
|
+
* @see {@link https://www.w3.org/TR/did-core/#verification-methods | DID Core Specification, § Verification Methods}
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* const did = await DidDht.create({
|
|
153
|
+
* options: {
|
|
154
|
+
* verificationMethods: [
|
|
155
|
+
* {
|
|
156
|
+
* algorithm: 'Ed25519',
|
|
157
|
+
* purposes: ['authentication', 'assertionMethod']
|
|
158
|
+
* },
|
|
159
|
+
* {
|
|
160
|
+
* algorithm: 'Ed25519',
|
|
161
|
+
* id: 'dwn-sig',
|
|
162
|
+
* purposes: ['authentication', 'assertionMethod']
|
|
163
|
+
* }
|
|
164
|
+
* ]
|
|
165
|
+
* };
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
verificationMethods?: DidCreateVerificationMethod<TKms>[];
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Proof to used to construct the `_prv._did.` DNS record as described in https://did-dht.com/#rotation to link a DID to a previous DID.
|
|
172
|
+
*/
|
|
173
|
+
export type PreviousDidProof = {
|
|
174
|
+
/** The previous DID. */
|
|
175
|
+
previousDid: string;
|
|
176
|
+
/** The signature signed using the private Identity Key of the previous DID in Base64URL format. */
|
|
177
|
+
signature: string;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* Represents an optional extension to a DID Document’s DNS packet representation exposed as a
|
|
181
|
+
* type index.
|
|
182
|
+
*
|
|
183
|
+
* Type indexing is an OPTIONAL feature that enables DIDs to become discoverable. DIDs that wish to
|
|
184
|
+
* be discoverable and resolveable by type can include one or more types when publishing their DID
|
|
185
|
+
* document to a DID DHT Gateway.
|
|
186
|
+
*
|
|
187
|
+
* The registered DID types are published in the {@link https://did-dht.com/registry/index.html#indexed-types | DID DHT Registry}.
|
|
188
|
+
*/
|
|
189
|
+
export declare enum DidDhtRegisteredDidType {
|
|
190
|
+
/**
|
|
191
|
+
* Type 0 is reserved for DIDs that do not wish to associate themselves with a specific type but
|
|
192
|
+
* wish to make themselves discoverable.
|
|
193
|
+
*/
|
|
194
|
+
Discoverable = 0,
|
|
195
|
+
/**
|
|
196
|
+
* Organization
|
|
197
|
+
* @see {@link https://schema.org/Organization | schema definition}
|
|
198
|
+
*/
|
|
199
|
+
Organization = 1,
|
|
200
|
+
/**
|
|
201
|
+
* Government Organization
|
|
202
|
+
* @see {@link https://schema.org/GovernmentOrganization | schema definition}
|
|
203
|
+
*/
|
|
204
|
+
Government = 2,
|
|
205
|
+
/**
|
|
206
|
+
* Corporation
|
|
207
|
+
* @see {@link https://schema.org/Corporation | schema definition}
|
|
208
|
+
*/
|
|
209
|
+
Corporation = 3,
|
|
210
|
+
/**
|
|
211
|
+
* Corporation
|
|
212
|
+
* @see {@link https://schema.org/Corporation | schema definition}
|
|
213
|
+
*/
|
|
214
|
+
LocalBusiness = 4,
|
|
215
|
+
/**
|
|
216
|
+
* Software Package
|
|
217
|
+
* @see {@link https://schema.org/SoftwareSourceCode | schema definition}
|
|
218
|
+
*/
|
|
219
|
+
SoftwarePackage = 5,
|
|
220
|
+
/**
|
|
221
|
+
* Web App
|
|
222
|
+
* @see {@link https://schema.org/WebApplication | schema definition}
|
|
223
|
+
*/
|
|
224
|
+
WebApp = 6,
|
|
225
|
+
/**
|
|
226
|
+
* Financial Institution
|
|
227
|
+
* @see {@link https://schema.org/FinancialService | schema definition}
|
|
228
|
+
*/
|
|
229
|
+
FinancialInstitution = 7
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Enumerates the types of keys that can be used in a DID DHT document.
|
|
233
|
+
*
|
|
234
|
+
* The DID DHT method supports various cryptographic key types. These key types are essential for
|
|
235
|
+
* the creation and management of DIDs and their associated cryptographic operations like signing
|
|
236
|
+
* and encryption. The registered key types are published in the DID DHT Registry and each is
|
|
237
|
+
* assigned a unique numerical value for use by client and gateway implementations.
|
|
238
|
+
*
|
|
239
|
+
* The registered key types are published in the {@link https://did-dht.com/registry/index.html#key-type-index | DID DHT Registry}.
|
|
240
|
+
*/
|
|
241
|
+
export declare enum DidDhtRegisteredKeyType {
|
|
242
|
+
/**
|
|
243
|
+
* Ed25519: A public-key signature system using the EdDSA (Edwards-curve Digital Signature
|
|
244
|
+
* Algorithm) and Curve25519.
|
|
245
|
+
*/
|
|
246
|
+
Ed25519 = 0,
|
|
247
|
+
/**
|
|
248
|
+
* secp256k1: A cryptographic curve used for digital signatures in a range of decentralized
|
|
249
|
+
* systems.
|
|
250
|
+
*/
|
|
251
|
+
secp256k1 = 1,
|
|
252
|
+
/**
|
|
253
|
+
* secp256r1: Also known as P-256 or prime256v1, this curve is used for cryptographic operations
|
|
254
|
+
* and is widely supported in various cryptographic libraries and standards.
|
|
255
|
+
*/
|
|
256
|
+
secp256r1 = 2,
|
|
257
|
+
/**
|
|
258
|
+
* X25519: A public key used for Diffie-Hellman key exchange using Curve25519.
|
|
259
|
+
*/
|
|
260
|
+
X25519 = 3
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Maps {@link https://www.w3.org/TR/did-core/#verification-relationships | DID Core Verification Relationship}
|
|
264
|
+
* values to the corresponding record name in the DNS packet representation of a DHT DID document.
|
|
265
|
+
*/
|
|
266
|
+
export declare enum DidDhtVerificationRelationship {
|
|
267
|
+
/**
|
|
268
|
+
* Specifies how the DID subject is expected to be authenticated.
|
|
269
|
+
*/
|
|
270
|
+
authentication = "auth",
|
|
271
|
+
/**
|
|
272
|
+
* Specifies how the DID subject is expected to express claims, such as for issuing Verifiable
|
|
273
|
+
* Credentials.
|
|
274
|
+
*/
|
|
275
|
+
assertionMethod = "asm",
|
|
276
|
+
/**
|
|
277
|
+
* Specifies a mechanism used by the DID subject to delegate a cryptographic capability to another
|
|
278
|
+
* party
|
|
279
|
+
*/
|
|
280
|
+
capabilityDelegation = "del",
|
|
281
|
+
/**
|
|
282
|
+
* Specifies a verification method used by the DID subject to invoke a cryptographic capability.
|
|
283
|
+
*/
|
|
284
|
+
capabilityInvocation = "inv",
|
|
285
|
+
/**
|
|
286
|
+
* Specifies how an entity can generate encryption material to communicate confidentially with the
|
|
287
|
+
* DID subject.
|
|
288
|
+
*/
|
|
289
|
+
keyAgreement = "agm"
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* The `DidDht` class provides an implementation of the `did:dht` DID method.
|
|
293
|
+
*
|
|
294
|
+
* Features:
|
|
295
|
+
* - DID Creation: Create new `did:dht` DIDs.
|
|
296
|
+
* - DID Key Management: Instantiate a DID object from an existing verification method keys or
|
|
297
|
+
* or a key in a Key Management System (KMS). If supported by the KMS, a DID's
|
|
298
|
+
* key can be exported to a portable DID format.
|
|
299
|
+
* - DID Resolution: Resolve a `did:dht` to its corresponding DID Document stored in the DHT network.
|
|
300
|
+
* - Signature Operations: Sign and verify messages using keys associated with a DID.
|
|
301
|
+
*
|
|
302
|
+
* @remarks
|
|
303
|
+
* The `did:dht` method leverages the distributed nature of the Mainline DHT network for
|
|
304
|
+
* decentralized identity management. This method allows DIDs to be resolved without relying on
|
|
305
|
+
* centralized registries or ledgers, enhancing privacy and control for users. The DID Document is
|
|
306
|
+
* stored and retrieved from the DHT network, and the method includes optional mechanisms for
|
|
307
|
+
* discovering DIDs by type.
|
|
308
|
+
*
|
|
309
|
+
* The DID URI in the `did:dht` method includes a method-specific identifier called the Identity Key
|
|
310
|
+
* which corresponds to the DID's entry in the DHT network. The Identity Key required to make
|
|
311
|
+
* changes to the DID Document since Mainline DHT nodes validate the signature of each message
|
|
312
|
+
* before storing the value in the DHT.
|
|
313
|
+
*
|
|
314
|
+
* @see {@link https://did-dht.com | DID DHT Method Specification}
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```ts
|
|
318
|
+
* // DID Creation
|
|
319
|
+
* const did = await DidDht.create();
|
|
320
|
+
*
|
|
321
|
+
* // DID Creation with a KMS
|
|
322
|
+
* const keyManager = new LocalKeyManager();
|
|
323
|
+
* const did = await DidDht.create({ keyManager });
|
|
324
|
+
*
|
|
325
|
+
* // DID Resolution
|
|
326
|
+
* const resolutionResult = await DidDht.resolve({ did: did.uri });
|
|
327
|
+
*
|
|
328
|
+
* // Signature Operations
|
|
329
|
+
* const signer = await did.getSigner();
|
|
330
|
+
* const signature = await signer.sign({ data: new TextEncoder().encode('Message') });
|
|
331
|
+
* const isValid = await signer.verify({ data: new TextEncoder().encode('Message'), signature });
|
|
332
|
+
*
|
|
333
|
+
* // Import / Export
|
|
334
|
+
*
|
|
335
|
+
* // Export a BearerDid object to the PortableDid format.
|
|
336
|
+
* const portableDid = await did.export();
|
|
337
|
+
*
|
|
338
|
+
* // Reconstruct a BearerDid object from a PortableDid
|
|
339
|
+
* const did = await DidDht.import(portableDid);
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
export declare class DidDht extends DidMethod {
|
|
343
|
+
/**
|
|
344
|
+
* Name of the DID method, as defined in the DID DHT specification.
|
|
345
|
+
*/
|
|
346
|
+
static methodName: string;
|
|
347
|
+
/**
|
|
348
|
+
* Creates a new DID using the `did:dht` method formed from a newly generated key.
|
|
349
|
+
*
|
|
350
|
+
* @remarks
|
|
351
|
+
* The DID URI is formed by z-base-32 encoding the Identity Key public key and prefixing with
|
|
352
|
+
* `did:dht:`.
|
|
353
|
+
*
|
|
354
|
+
* Notes:
|
|
355
|
+
* - If no `options` are given, by default a new Ed25519 key will be generated which serves as the
|
|
356
|
+
* Identity Key.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```ts
|
|
360
|
+
* // DID Creation
|
|
361
|
+
* const did = await DidDht.create();
|
|
362
|
+
*
|
|
363
|
+
* // DID Creation with a KMS
|
|
364
|
+
* const keyManager = new LocalKeyManager();
|
|
365
|
+
* const did = await DidDht.create({ keyManager });
|
|
366
|
+
* ```
|
|
367
|
+
*
|
|
368
|
+
* @param params - The parameters for the create operation.
|
|
369
|
+
* @param params.keyManager - Optionally specify a Key Management System (KMS) used to generate
|
|
370
|
+
* keys and sign data.
|
|
371
|
+
* @param params.options - Optional parameters that can be specified when creating a new DID.
|
|
372
|
+
* @returns A Promise resolving to a {@link BearerDid} object representing the new DID.
|
|
373
|
+
*/
|
|
374
|
+
static create<TKms extends CryptoApi | undefined = undefined>({ keyManager, options }?: {
|
|
375
|
+
keyManager?: TKms;
|
|
376
|
+
options?: DidDhtCreateOptions<TKms>;
|
|
377
|
+
}): Promise<BearerDid>;
|
|
378
|
+
/**
|
|
379
|
+
* Instantiates a {@link BearerDid} object for the DID DHT method from a given {@link PortableDid}.
|
|
380
|
+
*
|
|
381
|
+
* This method allows for the creation of a `BearerDid` object using a previously created DID's
|
|
382
|
+
* key material, DID document, and metadata.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```ts
|
|
386
|
+
* // Export an existing BearerDid to PortableDid format.
|
|
387
|
+
* const portableDid = await did.export();
|
|
388
|
+
* // Reconstruct a BearerDid object from the PortableDid.
|
|
389
|
+
* const did = await DidDht.import({ portableDid });
|
|
390
|
+
* ```
|
|
391
|
+
*
|
|
392
|
+
* @param params - The parameters for the import operation.
|
|
393
|
+
* @param params.portableDid - The PortableDid object to import.
|
|
394
|
+
* @param params.keyManager - Optionally specify an external Key Management System (KMS) used to
|
|
395
|
+
* generate keys and sign data. If not given, a new
|
|
396
|
+
* {@link LocalKeyManager} instance will be created and
|
|
397
|
+
* used.
|
|
398
|
+
* @returns A Promise resolving to a `BearerDid` object representing the DID formed from the
|
|
399
|
+
* provided PortableDid.
|
|
400
|
+
* @throws An error if the PortableDid document does not contain any verification methods, lacks
|
|
401
|
+
* an Identity Key, or the keys for any verification method are missing in the key
|
|
402
|
+
* manager.
|
|
403
|
+
*/
|
|
404
|
+
static import({ portableDid, keyManager }: {
|
|
405
|
+
keyManager?: CryptoApi & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;
|
|
406
|
+
portableDid: PortableDid;
|
|
407
|
+
}): Promise<BearerDid>;
|
|
408
|
+
/**
|
|
409
|
+
* Given the W3C DID Document of a `did:dht` DID, return the verification method that will be used
|
|
410
|
+
* for signing messages and credentials. If given, the `methodId` parameter is used to select the
|
|
411
|
+
* verification method. If not given, the Identity Key's verification method with an ID fragment
|
|
412
|
+
* of '#0' is used.
|
|
413
|
+
*
|
|
414
|
+
* @param params - The parameters for the `getSigningMethod` operation.
|
|
415
|
+
* @param params.didDocument - DID Document to get the verification method from.
|
|
416
|
+
* @param params.methodId - ID of the verification method to use for signing.
|
|
417
|
+
* @returns Verification method to use for signing.
|
|
418
|
+
*/
|
|
419
|
+
static getSigningMethod({ didDocument, methodId }: {
|
|
420
|
+
didDocument: DidDocument;
|
|
421
|
+
methodId?: string;
|
|
422
|
+
}): Promise<DidVerificationMethod>;
|
|
423
|
+
/**
|
|
424
|
+
* Publishes a DID to the DHT, making it publicly discoverable and resolvable.
|
|
425
|
+
*
|
|
426
|
+
* This method handles the publication of a DID Document associated with a `did:dht` DID to the
|
|
427
|
+
* Mainline DHT network. The publication process involves storing the DID Document in Mainline DHT
|
|
428
|
+
* via a Pkarr relay server.
|
|
429
|
+
*
|
|
430
|
+
* @remarks
|
|
431
|
+
* - This method is typically invoked automatically during the creation of a new DID unless the
|
|
432
|
+
* `publish` option is set to `false`.
|
|
433
|
+
* - For existing, unpublished DIDs, it can be used to publish the DID Document to Mainline DHT.
|
|
434
|
+
* - The method relies on the specified Pkarr relay server to interface with the DHT network.
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
* ```ts
|
|
438
|
+
* // Generate a new DID and keys but explicitly disable publishing.
|
|
439
|
+
* const did = await DidDht.create({ options: { publish: false } });
|
|
440
|
+
* // Publish the DID to the DHT.
|
|
441
|
+
* const registrationResult = await DidDht.publish({ did });
|
|
442
|
+
* // `registrationResult.didDocumentMetadata.published` is true if the DID was successfully published.
|
|
443
|
+
* ```
|
|
444
|
+
*
|
|
445
|
+
* @param params - The parameters for the `publish` operation.
|
|
446
|
+
* @param params.did - The `BearerDid` object representing the DID to be published.
|
|
447
|
+
* @param params.gatewayUri - Optional. The URI of a server involved in executing DID method
|
|
448
|
+
* operations. In the context of publishing, the endpoint is expected
|
|
449
|
+
* to be a DID DHT Gateway or Pkarr Relay. If not specified, a default
|
|
450
|
+
* gateway node is used.
|
|
451
|
+
* @returns A promise that resolves to a {@link DidRegistrationResult} object that contains
|
|
452
|
+
* the result of registering the DID with a DID DHT Gateway or Pkarr relay.
|
|
453
|
+
*/
|
|
454
|
+
static publish({ did, gatewayUri }: {
|
|
455
|
+
did: BearerDid;
|
|
456
|
+
gatewayUri?: string;
|
|
457
|
+
}): Promise<DidRegistrationResult>;
|
|
458
|
+
/**
|
|
459
|
+
* Resolves a `did:dht` identifier to its corresponding DID document.
|
|
460
|
+
*
|
|
461
|
+
* This method performs the resolution of a `did:dht` DID, retrieving its DID Document from the
|
|
462
|
+
* Mainline DHT network. The process involves querying the DHT network via a Pkarr relay server to
|
|
463
|
+
* retrieve the DID Document that corresponds to the given DID identifier.
|
|
464
|
+
*
|
|
465
|
+
* @remarks
|
|
466
|
+
* - If a `gatewayUri` option is not specified, a default Pkarr relay is used to access the DHT
|
|
467
|
+
* network.
|
|
468
|
+
* - It decodes the DID identifier and retrieves the associated DID Document and metadata.
|
|
469
|
+
* - In case of resolution failure, appropriate error information is returned.
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```ts
|
|
473
|
+
* const resolutionResult = await DidDht.resolve('did:dht:example');
|
|
474
|
+
* ```
|
|
475
|
+
*
|
|
476
|
+
* @param didUri - The DID to be resolved.
|
|
477
|
+
* @param options - Optional parameters for resolving the DID. Unused by this DID method.
|
|
478
|
+
* @returns A Promise resolving to a {@link DidResolutionResult} object representing the result of
|
|
479
|
+
* the resolution.
|
|
480
|
+
*/
|
|
481
|
+
static resolve(didUri: string, options?: DidResolutionOptions): Promise<DidResolutionResult>;
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* The `DidDhtDocument` class provides functionality for interacting with the DID document stored in
|
|
485
|
+
* Mainline DHT in support of DID DHT method create, resolve, update, and deactivate operations.
|
|
486
|
+
*
|
|
487
|
+
* This class includes methods for retrieving and publishing DID documents to and from the DHT,
|
|
488
|
+
* using DNS packet encoding and DID DHT Gateway or Pkarr Relay servers.
|
|
489
|
+
*/
|
|
490
|
+
export declare class DidDhtDocument {
|
|
491
|
+
/**
|
|
492
|
+
* Retrieves a DID document and its metadata from the DHT network.
|
|
493
|
+
*
|
|
494
|
+
* @param params - The parameters for the get operation.
|
|
495
|
+
* @param params.didUri - The DID URI containing the Identity Key.
|
|
496
|
+
* @param params.gatewayUri - The DID DHT Gateway or Pkarr Relay URI.
|
|
497
|
+
* @returns A Promise resolving to a {@link DidResolutionResult} object containing the DID
|
|
498
|
+
* document and its metadata.
|
|
499
|
+
*/
|
|
500
|
+
static get({ didUri, gatewayUri }: {
|
|
501
|
+
didUri: string;
|
|
502
|
+
gatewayUri: string;
|
|
503
|
+
}): Promise<DidResolutionResult>;
|
|
504
|
+
/**
|
|
505
|
+
* Publishes a DID document to the DHT network.
|
|
506
|
+
*
|
|
507
|
+
* @param params - The parameters to use when publishing the DID document to the DHT network.
|
|
508
|
+
* @param params.did - The DID object whose DID document will be published.
|
|
509
|
+
* @param params.gatewayUri - The DID DHT Gateway or Pkarr Relay URI.
|
|
510
|
+
* @returns A promise that resolves to a {@link DidRegistrationResult} object that contains
|
|
511
|
+
* the result of registering the DID with a DID DHT Gateway or Pkarr relay.
|
|
512
|
+
*/
|
|
513
|
+
static put({ did, gatewayUri }: {
|
|
514
|
+
did: BearerDid;
|
|
515
|
+
gatewayUri: string;
|
|
516
|
+
}): Promise<DidRegistrationResult>;
|
|
517
|
+
/**
|
|
518
|
+
* Retrieves a signed BEP44 message from a DID DHT Gateway or Pkarr Relay server.
|
|
519
|
+
*
|
|
520
|
+
* @see {@link https://github.com/Nuhvi/pkarr/blob/main/design/relays.md | Pkarr Relay design}
|
|
521
|
+
*
|
|
522
|
+
* @param params
|
|
523
|
+
* @param params.gatewayUri - The DID DHT Gateway or Pkarr Relay URI.
|
|
524
|
+
* @param params.publicKeyBytes - The public key bytes of the Identity Key, z-base-32 encoded.
|
|
525
|
+
* @returns A promise resolving to a BEP44 message containing the signed DNS packet.
|
|
526
|
+
*/
|
|
527
|
+
private static pkarrGet;
|
|
528
|
+
/**
|
|
529
|
+
* Publishes a signed BEP44 message to a DID DHT Gateway or Pkarr Relay server.
|
|
530
|
+
*
|
|
531
|
+
* @see {@link https://github.com/Nuhvi/pkarr/blob/main/design/relays.md | Pkarr Relay design}
|
|
532
|
+
*
|
|
533
|
+
* @param params - The parameters to use when publishing a signed BEP44 message to a Pkarr relay server.
|
|
534
|
+
* @param params.gatewayUri - The DID DHT Gateway or Pkarr Relay URI.
|
|
535
|
+
* @param params.bep44Message - The BEP44 message to be published, containing the signed DNS packet.
|
|
536
|
+
* @returns A promise resolving to `true` if the message was successfully published, otherwise `false`.
|
|
537
|
+
*/
|
|
538
|
+
private static pkarrPut;
|
|
539
|
+
/**
|
|
540
|
+
* Converts a DNS packet to a DID document according to the DID DHT specification.
|
|
541
|
+
*
|
|
542
|
+
* @see {@link https://did-dht.com/#dids-as-dns-records | DID DHT Specification, § DIDs as DNS Records}
|
|
543
|
+
*
|
|
544
|
+
* @param params - The parameters to use when converting a DNS packet to a DID document.
|
|
545
|
+
* @param params.didUri - The DID URI of the DID document.
|
|
546
|
+
* @param params.dnsPacket - The DNS packet to convert to a DID document.
|
|
547
|
+
* @returns A Promise resolving to a {@link DidResolutionResult} object containing the DID
|
|
548
|
+
* document and its metadata.
|
|
549
|
+
*/
|
|
550
|
+
static fromDnsPacket({ didUri, dnsPacket }: {
|
|
551
|
+
didUri: string;
|
|
552
|
+
dnsPacket: Packet;
|
|
553
|
+
}): Promise<DidResolutionResult>;
|
|
554
|
+
/**
|
|
555
|
+
* Converts a DID document to a DNS packet according to the DID DHT specification.
|
|
556
|
+
*
|
|
557
|
+
* @see {@link https://did-dht.com/#dids-as-dns-records | DID DHT Specification, § DIDs as DNS Records}
|
|
558
|
+
*
|
|
559
|
+
* @param params - The parameters to use when converting a DID document to a DNS packet.
|
|
560
|
+
* @param params.didDocument - The DID document to convert to a DNS packet.
|
|
561
|
+
* @param params.didMetadata - The DID metadata to include in the DNS packet.
|
|
562
|
+
* @param params.authoritativeGatewayUris - The URIs of the Authoritative Gateways to generate NS records from.
|
|
563
|
+
* @param params.previousDidProof - The signature proof that this DID is linked to the given previous DID.
|
|
564
|
+
* @returns A promise that resolves to a DNS packet.
|
|
565
|
+
*/
|
|
566
|
+
static toDnsPacket({ didDocument, didMetadata, authoritativeGatewayUris, previousDidProof }: {
|
|
567
|
+
didDocument: DidDocument;
|
|
568
|
+
didMetadata: DidMetadata;
|
|
569
|
+
authoritativeGatewayUris?: string[];
|
|
570
|
+
previousDidProof?: PreviousDidProof;
|
|
571
|
+
}): Promise<Packet>;
|
|
572
|
+
/**
|
|
573
|
+
* Gets the unique portion of the DID identifier after the last `:` character.
|
|
574
|
+
* e.g. `did:dht:example` -> `example`
|
|
575
|
+
*
|
|
576
|
+
* @param did - The DID to extract the unique suffix from.
|
|
577
|
+
*/
|
|
578
|
+
private static getUniqueDidSuffix;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* The `DidDhtUtils` class provides utility functions to support operations in the DID DHT method.
|
|
582
|
+
* This includes functions for creating and parsing BEP44 messages, handling identity keys, and
|
|
583
|
+
* converting between different formats and representations.
|
|
584
|
+
*/
|
|
585
|
+
export declare class DidDhtUtils {
|
|
586
|
+
/**
|
|
587
|
+
* Creates a BEP44 put message, which is used to publish a DID document to the DHT network.
|
|
588
|
+
*
|
|
589
|
+
* @param params - The parameters to use when creating the BEP44 put message
|
|
590
|
+
* @param params.dnsPacket - The DNS packet to encode in the BEP44 message.
|
|
591
|
+
* @param params.publicKeyBytes - The public key bytes of the Identity Key.
|
|
592
|
+
* @param params.signer - Signer that can sign and verify data using the Identity Key.
|
|
593
|
+
* @returns A promise that resolves to a BEP44 put message.
|
|
594
|
+
*/
|
|
595
|
+
static createBep44PutMessage({ dnsPacket, publicKeyBytes, signer }: {
|
|
596
|
+
dnsPacket: Packet;
|
|
597
|
+
publicKeyBytes: Uint8Array;
|
|
598
|
+
signer: Signer;
|
|
599
|
+
}): Promise<Bep44Message>;
|
|
600
|
+
/**
|
|
601
|
+
* Converts a DID URI to a JSON Web Key (JWK) representing the Identity Key.
|
|
602
|
+
*
|
|
603
|
+
* @param params - The parameters to use for the conversion.
|
|
604
|
+
* @param params.didUri - The DID URI containing the Identity Key.
|
|
605
|
+
* @returns A promise that resolves to a JWK representing the Identity Key.
|
|
606
|
+
*/
|
|
607
|
+
static identifierToIdentityKey({ didUri }: {
|
|
608
|
+
didUri: string;
|
|
609
|
+
}): Promise<Jwk>;
|
|
610
|
+
/**
|
|
611
|
+
* Converts a DID URI to the byte array representation of the Identity Key.
|
|
612
|
+
*
|
|
613
|
+
* @param params - The parameters to use for the conversion.
|
|
614
|
+
* @param params.didUri - The DID URI containing the Identity Key.
|
|
615
|
+
* @returns A byte array representation of the Identity Key.
|
|
616
|
+
*/
|
|
617
|
+
static identifierToIdentityKeyBytes({ didUri }: {
|
|
618
|
+
didUri: string;
|
|
619
|
+
}): Uint8Array;
|
|
620
|
+
/**
|
|
621
|
+
* Encodes a DID DHT Identity Key into a DID identifier.
|
|
622
|
+
*
|
|
623
|
+
* This method first z-base-32 encodes the Identity Key. The resulting string is prefixed with
|
|
624
|
+
* `did:dht:` to form the DID identifier.
|
|
625
|
+
*
|
|
626
|
+
* @param params - The parameters to use for the conversion.
|
|
627
|
+
* @param params.identityKey The Identity Key from which the DID identifier is computed.
|
|
628
|
+
* @returns A promise that resolves to a string containing the DID identifier.
|
|
629
|
+
*/
|
|
630
|
+
static identityKeyToIdentifier({ identityKey }: {
|
|
631
|
+
identityKey: Jwk;
|
|
632
|
+
}): Promise<string>;
|
|
633
|
+
/**
|
|
634
|
+
* Returns the appropriate key converter for the specified cryptographic curve.
|
|
635
|
+
*
|
|
636
|
+
* @param curve - The cryptographic curve to use for the key conversion.
|
|
637
|
+
* @returns An `AsymmetricKeyConverter` for the specified curve.
|
|
638
|
+
*/
|
|
639
|
+
static keyConverter(curve: string): AsymmetricKeyConverter;
|
|
640
|
+
/**
|
|
641
|
+
* Parses and verifies a BEP44 Get message, converting it to a DNS packet.
|
|
642
|
+
*
|
|
643
|
+
* @param params - The parameters to use when verifying and parsing the BEP44 Get response message.
|
|
644
|
+
* @param params.bep44Message - The BEP44 message to verify and parse.
|
|
645
|
+
* @returns A promise that resolves to a DNS packet.
|
|
646
|
+
*/
|
|
647
|
+
static parseBep44GetMessage({ bep44Message }: {
|
|
648
|
+
bep44Message: Bep44Message;
|
|
649
|
+
}): Promise<Packet>;
|
|
650
|
+
/**
|
|
651
|
+
* Decodes and parses the data value of a DNS TXT record into a key-value object.
|
|
652
|
+
*
|
|
653
|
+
* @param txtData - The data value of a DNS TXT record.
|
|
654
|
+
* @returns An object containing the key/value pairs of the TXT record data.
|
|
655
|
+
*/
|
|
656
|
+
static parseTxtDataToObject(txtData: TxtData): Record<string, string>;
|
|
657
|
+
/**
|
|
658
|
+
* Decodes and parses the data value of a DNS TXT record into a string.
|
|
659
|
+
*
|
|
660
|
+
* @param txtData - The data value of a DNS TXT record.
|
|
661
|
+
* @returns A string representation of the TXT record data.
|
|
662
|
+
*/
|
|
663
|
+
static parseTxtDataToString(txtData: TxtData): string;
|
|
664
|
+
/**
|
|
665
|
+
* Validates the proof of previous DID given.
|
|
666
|
+
*
|
|
667
|
+
* @param params - The parameters to validate the previous DID proof.
|
|
668
|
+
* @param params.newDid - The new DID that the previous DID is linking to.
|
|
669
|
+
* @param params.previousDidProof - The proof of the previous DID, containing the previous DID and signature signed by the previous DID.
|
|
670
|
+
*/
|
|
671
|
+
static validatePreviousDidProof({ newDid, previousDidProof }: {
|
|
672
|
+
newDid: string;
|
|
673
|
+
previousDidProof: PreviousDidProof;
|
|
674
|
+
}): Promise<void>;
|
|
675
|
+
/**
|
|
676
|
+
* Splits a string into chunks of length 255 if the string exceeds length 255.
|
|
677
|
+
* @param data - The string to split into chunks.
|
|
678
|
+
* @returns The original string if its length is less than or equal to 255, otherwise an array of chunked strings.
|
|
679
|
+
*/
|
|
680
|
+
static chunkDataIfNeeded(data: string): string | string[];
|
|
681
|
+
}
|
|
682
|
+
//# sourceMappingURL=did-dht.d.ts.map
|