@enbox/dids 0.0.4 → 0.0.6

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 (55) hide show
  1. package/dist/browser.mjs +1 -1
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/methods/did-dht-dns.js +455 -0
  4. package/dist/esm/methods/did-dht-dns.js.map +1 -0
  5. package/dist/esm/methods/did-dht-pkarr.js +168 -0
  6. package/dist/esm/methods/did-dht-pkarr.js.map +1 -0
  7. package/dist/esm/methods/did-dht-types.js +116 -0
  8. package/dist/esm/methods/did-dht-types.js.map +1 -0
  9. package/dist/esm/methods/did-dht-utils.js +143 -0
  10. package/dist/esm/methods/did-dht-utils.js.map +1 -0
  11. package/dist/esm/methods/did-dht.js +65 -842
  12. package/dist/esm/methods/did-dht.js.map +1 -1
  13. package/dist/esm/methods/did-ion-utils.js +161 -0
  14. package/dist/esm/methods/did-ion-utils.js.map +1 -0
  15. package/dist/esm/methods/did-ion.js +4 -151
  16. package/dist/esm/methods/did-ion.js.map +1 -1
  17. package/dist/esm/methods/did-key-utils.js +235 -0
  18. package/dist/esm/methods/did-key-utils.js.map +1 -0
  19. package/dist/esm/methods/did-key.js +6 -222
  20. package/dist/esm/methods/did-key.js.map +1 -1
  21. package/dist/esm/utils.js +15 -19
  22. package/dist/esm/utils.js.map +1 -1
  23. package/dist/types/methods/did-dht-dns.d.ts +114 -0
  24. package/dist/types/methods/did-dht-dns.d.ts.map +1 -0
  25. package/dist/types/methods/did-dht-pkarr.d.ts +56 -0
  26. package/dist/types/methods/did-dht-pkarr.d.ts.map +1 -0
  27. package/dist/types/methods/did-dht-types.d.ts +286 -0
  28. package/dist/types/methods/did-dht-types.d.ts.map +1 -0
  29. package/dist/types/methods/did-dht-utils.d.ts +54 -0
  30. package/dist/types/methods/did-dht-utils.d.ts.map +1 -0
  31. package/dist/types/methods/did-dht.d.ts +42 -457
  32. package/dist/types/methods/did-dht.d.ts.map +1 -1
  33. package/dist/types/methods/did-ion-utils.d.ts +86 -0
  34. package/dist/types/methods/did-ion-utils.d.ts.map +1 -0
  35. package/dist/types/methods/did-ion.d.ts +2 -82
  36. package/dist/types/methods/did-ion.d.ts.map +1 -1
  37. package/dist/types/methods/did-key-utils.d.ts +138 -0
  38. package/dist/types/methods/did-key-utils.d.ts.map +1 -0
  39. package/dist/types/methods/did-key.d.ts +3 -124
  40. package/dist/types/methods/did-key.d.ts.map +1 -1
  41. package/dist/types/utils.d.ts +25 -25
  42. package/dist/types/utils.d.ts.map +1 -1
  43. package/dist/utils.js +1 -1
  44. package/dist/utils.js.map +4 -4
  45. package/package.json +4 -4
  46. package/src/methods/did-dht-dns.ts +516 -0
  47. package/src/methods/did-dht-pkarr.ts +192 -0
  48. package/src/methods/did-dht-types.ts +316 -0
  49. package/src/methods/did-dht-utils.ts +157 -0
  50. package/src/methods/did-dht.ts +122 -1128
  51. package/src/methods/did-ion-utils.ts +186 -0
  52. package/src/methods/did-ion.ts +14 -190
  53. package/src/methods/did-key-utils.ts +258 -0
  54. package/src/methods/did-key.ts +14 -266
  55. package/src/utils.ts +31 -30
@@ -0,0 +1,455 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { AUTHORITATIVE_ANSWER } from '@dnsquery/dns-packet';
22
+ import { computeJwkThumbprint } from '@enbox/crypto';
23
+ import { Convert } from '@enbox/common';
24
+ import { DidVerificationRelationship } from '../types/did-core.js';
25
+ import { extractDidFragment } from '../utils.js';
26
+ import { DidDhtRegisteredDidType, DidDhtRegisteredKeyType, DidDhtVerificationRelationship } from './did-dht-types.js';
27
+ import { DidError, DidErrorCode } from '../did-error.js';
28
+ import { keyConverter, validatePreviousDidProof } from './did-dht-utils.js';
29
+ /**
30
+ * The version of the DID DHT specification that is implemented by this library.
31
+ */
32
+ export const DID_DHT_SPECIFICATION_VERSION = 0;
33
+ /**
34
+ * The default TTL for DNS records published to the DHT network.
35
+ *
36
+ * The recommended TTL value is 7200 seconds (2 hours) since it matches the default TTL for
37
+ * Mainline DHT records.
38
+ */
39
+ export const DNS_RECORD_TTL = 7200;
40
+ /**
41
+ * Character used to separate distinct elements or entries in the DNS packet representation
42
+ * of a DID Document.
43
+ */
44
+ export const PROPERTY_SEPARATOR = ';';
45
+ /**
46
+ * Character used to separate distinct values within a single element or entry in the DNS packet
47
+ * representation of a DID Document.
48
+ */
49
+ export const VALUE_SEPARATOR = ',';
50
+ /**
51
+ * Private helper that maps algorithm identifiers to their corresponding DID DHT
52
+ * {@link DidDhtRegisteredKeyType | registered key type}.
53
+ */
54
+ export const AlgorithmToKeyTypeMap = {
55
+ Ed25519: DidDhtRegisteredKeyType.Ed25519,
56
+ ES256K: DidDhtRegisteredKeyType.secp256k1,
57
+ ES256: DidDhtRegisteredKeyType.secp256r1,
58
+ 'P-256': DidDhtRegisteredKeyType.secp256r1,
59
+ secp256k1: DidDhtRegisteredKeyType.secp256k1,
60
+ secp256r1: DidDhtRegisteredKeyType.secp256r1,
61
+ X25519: DidDhtRegisteredKeyType.X25519,
62
+ };
63
+ /**
64
+ * Private helper that maps DID DHT registered key types to their corresponding default algorithm identifiers.
65
+ */
66
+ export const KeyTypeToDefaultAlgorithmMap = {
67
+ [DidDhtRegisteredKeyType.Ed25519]: 'EdDSA',
68
+ [DidDhtRegisteredKeyType.secp256k1]: 'ES256K',
69
+ [DidDhtRegisteredKeyType.secp256r1]: 'ES256',
70
+ [DidDhtRegisteredKeyType.X25519]: 'ECDH-ES+A256KW',
71
+ };
72
+ /**
73
+ * Creates a TXT DNS answer record with the given name and data, using the standard DNS_RECORD_TTL.
74
+ *
75
+ * @param name - The DNS record name.
76
+ * @param data - The TXT record data (string or string array).
77
+ * @returns A TxtAnswer record.
78
+ */
79
+ export function createTxtRecord(name, data) {
80
+ return {
81
+ type: 'TXT',
82
+ name,
83
+ ttl: DNS_RECORD_TTL,
84
+ data,
85
+ };
86
+ }
87
+ /**
88
+ * Decodes and parses the data value of a DNS TXT record into a string.
89
+ *
90
+ * @param txtData - The data value of a DNS TXT record.
91
+ * @returns A string representation of the TXT record data.
92
+ */
93
+ export function parseTxtDataToString(txtData) {
94
+ if (typeof txtData === 'string') {
95
+ return txtData;
96
+ }
97
+ else if (txtData instanceof Uint8Array) {
98
+ return Convert.uint8Array(txtData).toString();
99
+ }
100
+ else if (Array.isArray(txtData)) {
101
+ return txtData.map((item) => parseTxtDataToString(item)).join('');
102
+ }
103
+ else {
104
+ throw new DidError(DidErrorCode.InternalError, 'Pkarr returned DNS TXT record with invalid data type');
105
+ }
106
+ }
107
+ /**
108
+ * Decodes and parses the data value of a DNS TXT record into a key-value object.
109
+ *
110
+ * @param txtData - The data value of a DNS TXT record.
111
+ * @returns An object containing the key/value pairs of the TXT record data.
112
+ */
113
+ export function parseTxtDataToObject(txtData) {
114
+ return parseTxtDataToString(txtData).split(PROPERTY_SEPARATOR).reduce((acc, pair) => {
115
+ const [key, value] = pair.split('=');
116
+ acc[key] = value;
117
+ return acc;
118
+ }, {});
119
+ }
120
+ /**
121
+ * Splits a string into chunks of length 255 if the string exceeds length 255.
122
+ *
123
+ * @param data - The string to split into chunks.
124
+ * @returns The original string if its length is less than or equal to 255, otherwise an array of chunked strings.
125
+ */
126
+ export function chunkDataIfNeeded(data) {
127
+ if (data.length <= 255) {
128
+ return data;
129
+ }
130
+ // Split the data into chunks of 255 characters.
131
+ const chunks = [];
132
+ for (let i = 0; i < data.length; i += 255) {
133
+ chunks.push(data.slice(i, i + 255)); // end index is ignored if it exceeds the length of the string
134
+ }
135
+ return chunks;
136
+ }
137
+ /**
138
+ * Converts a DNS packet to a DID document according to the DID DHT specification.
139
+ *
140
+ * @see {@link https://did-dht.com/#dids-as-dns-records | DID DHT Specification, § DIDs as DNS Records}
141
+ *
142
+ * @param params - The parameters to use when converting a DNS packet to a DID document.
143
+ * @param params.didUri - The DID URI of the DID document.
144
+ * @param params.dnsPacket - The DNS packet to convert to a DID document.
145
+ * @returns A Promise resolving to an object containing the DID document and its metadata.
146
+ */
147
+ export function fromDnsPacket(_a) {
148
+ return __awaiter(this, arguments, void 0, function* ({ didUri, dnsPacket }) {
149
+ var _b, _c, _d;
150
+ // Begin constructing the DID Document.
151
+ const didDocument = { id: didUri };
152
+ // Since the DID document is being retrieved from the DHT, it is considered published.
153
+ const didDocumentMetadata = {
154
+ published: true
155
+ };
156
+ const idLookup = new Map();
157
+ for (const answer of (_b = dnsPacket === null || dnsPacket === void 0 ? void 0 : dnsPacket.answers) !== null && _b !== void 0 ? _b : []) {
158
+ // DID DHT properties are ONLY present in DNS TXT records.
159
+ if (answer.type !== 'TXT') {
160
+ continue;
161
+ }
162
+ // Get the DID DHT record identifier (e.g., k0, aka, did, etc.) from the DNS resource name.
163
+ const dnsRecordId = answer.name.split('.')[0].substring(1);
164
+ switch (true) {
165
+ // Process an also known as record.
166
+ case dnsRecordId.startsWith('aka'): {
167
+ // Decode the DNS TXT record data value to a string.
168
+ const data = parseTxtDataToString(answer.data);
169
+ // Add the 'alsoKnownAs' property to the DID document.
170
+ didDocument.alsoKnownAs = data.split(VALUE_SEPARATOR);
171
+ break;
172
+ }
173
+ // Process a controller record.
174
+ case dnsRecordId.startsWith('cnt'): {
175
+ // Decode the DNS TXT record data value to a string.
176
+ const data = parseTxtDataToString(answer.data);
177
+ // Add the 'controller' property to the DID document.
178
+ didDocument.controller = data.includes(VALUE_SEPARATOR) ? data.split(VALUE_SEPARATOR) : data;
179
+ break;
180
+ }
181
+ // Process verification methods.
182
+ case dnsRecordId.startsWith('k'): {
183
+ // Get the key type (t), Base64URL-encoded public key (k), algorithm (a), and
184
+ // optionally, controller (c) or Verification Method ID (id) from the decoded TXT record data.
185
+ const { id, t, k, c, a: parsedAlg } = parseTxtDataToObject(answer.data);
186
+ // Convert the public key from Base64URL format to a byte array.
187
+ const publicKeyBytes = Convert.base64Url(k).toUint8Array();
188
+ // Use the key type integer to look up the cryptographic curve name.
189
+ const namedCurve = DidDhtRegisteredKeyType[Number(t)];
190
+ // Convert the public key from a byte array to JWK format.
191
+ const publicKey = yield keyConverter(namedCurve).bytesToPublicKey({ publicKeyBytes });
192
+ publicKey.alg = parsedAlg || KeyTypeToDefaultAlgorithmMap[Number(t)];
193
+ // TODO: when this is complete https://github.com/enboxorg/enbox/issues/638 then we can add this back and
194
+ // update the test vectors kid back to '0'
195
+ // if(dnsRecordId === 'k0') {
196
+ // publicKey.kid = '0';
197
+ // }
198
+ // Determine the Verification Method ID: '0' for the identity key,
199
+ // the id from the TXT Data Object, or the JWK thumbprint if an explicity Verification Method ID not defined.
200
+ const vmId = dnsRecordId === 'k0' ? '0' : id !== undefined ? id : yield computeJwkThumbprint({ jwk: publicKey });
201
+ // Initialize the `verificationMethod` array if it does not already exist.
202
+ (_c = didDocument.verificationMethod) !== null && _c !== void 0 ? _c : (didDocument.verificationMethod = []);
203
+ // Prepend the DID URI to the ID fragment to form the full verification method ID.
204
+ const methodId = `${didUri}#${vmId}`;
205
+ // Add the verification method to the DID document.
206
+ didDocument.verificationMethod.push({
207
+ id: methodId,
208
+ type: 'JsonWebKey',
209
+ controller: c !== null && c !== void 0 ? c : didUri,
210
+ publicKeyJwk: publicKey,
211
+ });
212
+ // Add a mapping from the DNS record ID (e.g., 'k0', 'k1', etc.) to the verification
213
+ // method ID (e.g., 'did:dht:...#0', etc.).
214
+ idLookup.set(dnsRecordId, methodId);
215
+ break;
216
+ }
217
+ // Process services.
218
+ case dnsRecordId.startsWith('s'): {
219
+ // Get the service ID fragment (id), type (t), service endpoint (se), and optionally,
220
+ // other properties from the decoded TXT record data.
221
+ const _e = parseTxtDataToObject(answer.data), { id, t, se } = _e, customProperties = __rest(_e, ["id", "t", "se"]);
222
+ // if multi-values: 'a,b,c' -> ['a', 'b', 'c'], if single-value: 'a' -> ['a']
223
+ // NOTE: The service endpoint technically can either be a string or an array of strings,
224
+ // we enforce an array for single-value to simplify verification of vector 3 in the spec: https://did-dht.com/#vector-3
225
+ const serviceEndpoint = se.includes(VALUE_SEPARATOR) ? se.split(VALUE_SEPARATOR) : [se];
226
+ // Convert custom property values to either a string or an array of strings.
227
+ const serviceProperties = Object.fromEntries(Object.entries(customProperties).map(([k, v]) => [k, v.includes(VALUE_SEPARATOR) ? v.split(VALUE_SEPARATOR) : v]));
228
+ // Initialize the `service` array if it does not already exist.
229
+ (_d = didDocument.service) !== null && _d !== void 0 ? _d : (didDocument.service = []);
230
+ didDocument.service.push(Object.assign(Object.assign({}, serviceProperties), { id: `${didUri}#${id}`, type: t, serviceEndpoint }));
231
+ break;
232
+ }
233
+ // Process DID DHT types.
234
+ case dnsRecordId.startsWith('typ'): {
235
+ // Decode the DNS TXT record data value to an object.
236
+ const { id: types } = parseTxtDataToObject(answer.data);
237
+ // Add the DID DHT Registered DID Types represented as numbers to DID metadata.
238
+ didDocumentMetadata.types = types.split(VALUE_SEPARATOR).map((typeInteger) => Number(typeInteger));
239
+ break;
240
+ }
241
+ // Process root record.
242
+ case dnsRecordId.startsWith('did'): {
243
+ // Helper function that maps verification relationship values to verification method IDs.
244
+ const recordIdsToMethodIds = (data) => data
245
+ .split(VALUE_SEPARATOR)
246
+ .map((dnsRecordId) => idLookup.get(dnsRecordId))
247
+ .filter((id) => typeof id === 'string');
248
+ // Decode the DNS TXT record data and destructure verification relationship properties.
249
+ const { auth, asm, del, inv, agm } = parseTxtDataToObject(answer.data);
250
+ // Add the verification relationships, if any, to the DID document.
251
+ if (auth) {
252
+ didDocument.authentication = recordIdsToMethodIds(auth);
253
+ }
254
+ if (asm) {
255
+ didDocument.assertionMethod = recordIdsToMethodIds(asm);
256
+ }
257
+ if (del) {
258
+ didDocument.capabilityDelegation = recordIdsToMethodIds(del);
259
+ }
260
+ if (inv) {
261
+ didDocument.capabilityInvocation = recordIdsToMethodIds(inv);
262
+ }
263
+ if (agm) {
264
+ didDocument.keyAgreement = recordIdsToMethodIds(agm);
265
+ }
266
+ break;
267
+ }
268
+ }
269
+ }
270
+ return { didDocument, didDocumentMetadata, didResolutionMetadata: {} };
271
+ });
272
+ }
273
+ /**
274
+ * Converts a DID document to a DNS packet according to the DID DHT specification.
275
+ *
276
+ * @see {@link https://did-dht.com/#dids-as-dns-records | DID DHT Specification, § DIDs as DNS Records}
277
+ *
278
+ * @param params - The parameters to use when converting a DID document to a DNS packet.
279
+ * @param params.didDocument - The DID document to convert to a DNS packet.
280
+ * @param params.didMetadata - The DID metadata to include in the DNS packet.
281
+ * @param params.authoritativeGatewayUris - The URIs of the Authoritative Gateways to generate NS records from.
282
+ * @param params.previousDidProof - The signature proof that this DID is linked to the given previous DID.
283
+ * @returns A promise that resolves to a DNS packet.
284
+ */
285
+ export function toDnsPacket(_a) {
286
+ return __awaiter(this, arguments, void 0, function* ({ didDocument, didMetadata, authoritativeGatewayUris, previousDidProof }) {
287
+ var _b, _c, _d, _e, _f;
288
+ const txtRecords = [];
289
+ const nsRecords = [];
290
+ const idLookup = new Map();
291
+ const serviceIds = [];
292
+ const verificationMethodIds = [];
293
+ // Add `_prv._did.` TXT record if previous DID proof is provided and valid.
294
+ if (previousDidProof !== undefined) {
295
+ const { signature, previousDid } = previousDidProof;
296
+ yield validatePreviousDidProof({
297
+ newDid: didDocument.id,
298
+ previousDidProof
299
+ });
300
+ txtRecords.push({
301
+ type: 'TXT',
302
+ name: '_prv._did.',
303
+ ttl: DNS_RECORD_TTL,
304
+ data: `id=${previousDid};s=${signature}`
305
+ });
306
+ }
307
+ // Add DNS TXT records if the DID document contains an `alsoKnownAs` property.
308
+ if (didDocument.alsoKnownAs) {
309
+ txtRecords.push({
310
+ type: 'TXT',
311
+ name: '_aka._did.',
312
+ ttl: DNS_RECORD_TTL,
313
+ data: didDocument.alsoKnownAs.join(VALUE_SEPARATOR)
314
+ });
315
+ }
316
+ // Add DNS TXT records if the DID document contains a `controller` property.
317
+ if (didDocument.controller) {
318
+ const controller = Array.isArray(didDocument.controller)
319
+ ? didDocument.controller.join(VALUE_SEPARATOR)
320
+ : didDocument.controller;
321
+ txtRecords.push({
322
+ type: 'TXT',
323
+ name: '_cnt._did.',
324
+ ttl: DNS_RECORD_TTL,
325
+ data: controller
326
+ });
327
+ }
328
+ // Add DNS TXT records for each verification method.
329
+ for (const [index, verificationMethod] of (_c = (_b = didDocument.verificationMethod) === null || _b === void 0 ? void 0 : _b.entries()) !== null && _c !== void 0 ? _c : []) {
330
+ const dnsRecordId = `k${index}`;
331
+ verificationMethodIds.push(dnsRecordId);
332
+ const methodId = verificationMethod.id.split('#').pop(); // Remove fragment prefix, if any.
333
+ idLookup.set(methodId, dnsRecordId);
334
+ const publicKey = verificationMethod.publicKeyJwk;
335
+ if (!((publicKey === null || publicKey === void 0 ? void 0 : publicKey.crv) && publicKey.crv in AlgorithmToKeyTypeMap)) {
336
+ throw new DidError(DidErrorCode.InvalidPublicKeyType, `Verification method '${verificationMethod.id}' contains an unsupported key type: ${(_d = publicKey === null || publicKey === void 0 ? void 0 : publicKey.crv) !== null && _d !== void 0 ? _d : 'undefined'}`);
337
+ }
338
+ // Use the public key's `crv` property to get the DID DHT key type.
339
+ const keyType = DidDhtRegisteredKeyType[publicKey.crv];
340
+ // Convert the public key from JWK format to a byte array.
341
+ const publicKeyBytes = yield keyConverter(publicKey.crv).publicKeyToBytes({ publicKey });
342
+ // Convert the public key from a byte array to Base64URL format.
343
+ const publicKeyBase64Url = Convert.uint8Array(publicKeyBytes).toBase64Url();
344
+ // Define the data for the DNS TXT record.
345
+ const txtData = [`t=${keyType}`, `k=${publicKeyBase64Url}`];
346
+ // if the methodId is not the identity key or a thumbprint, explicity define the id within the DNS TXT record.
347
+ // otherwise the id can be inferred from the thumbprint.
348
+ if (methodId !== '0' && (yield computeJwkThumbprint({ jwk: publicKey })) !== methodId) {
349
+ txtData.unshift(`id=${methodId}`);
350
+ }
351
+ // Only set the algorithm property (`a`) if it differs from the default algorithm for the key type.
352
+ if (publicKey.alg !== KeyTypeToDefaultAlgorithmMap[keyType]) {
353
+ txtData.push(`a=${publicKey.alg}`);
354
+ }
355
+ // Add the controller property, if set to a value other than the Identity Key (DID Subject).
356
+ if (verificationMethod.controller !== didDocument.id) {
357
+ txtData.push(`c=${verificationMethod.controller}`);
358
+ }
359
+ // Add a TXT record for the verification method.
360
+ txtRecords.push({
361
+ type: 'TXT',
362
+ name: `_${dnsRecordId}._did.`,
363
+ ttl: DNS_RECORD_TTL,
364
+ data: txtData.join(PROPERTY_SEPARATOR)
365
+ });
366
+ }
367
+ // Add DNS TXT records for each service.
368
+ (_e = didDocument.service) === null || _e === void 0 ? void 0 : _e.forEach((service, index) => {
369
+ const dnsRecordId = `s${index}`;
370
+ serviceIds.push(dnsRecordId);
371
+ let { id, type: t, serviceEndpoint: se } = service, customProperties = __rest(service, ["id", "type", "serviceEndpoint"]);
372
+ id = extractDidFragment(id);
373
+ se = Array.isArray(se) ? se.join(',') : se;
374
+ // Define the data for the DNS TXT record.
375
+ const txtData = Object.entries(Object.assign({ id, t, se }, customProperties)).map(([key, value]) => `${key}=${value}`);
376
+ const txtDataString = txtData.join(PROPERTY_SEPARATOR);
377
+ const data = chunkDataIfNeeded(txtDataString);
378
+ // Add a TXT record for the verification method.
379
+ txtRecords.push({
380
+ type: 'TXT',
381
+ name: `_${dnsRecordId}._did.`,
382
+ ttl: DNS_RECORD_TTL,
383
+ data
384
+ });
385
+ });
386
+ // Initialize the root DNS TXT record with the DID DHT specification version.
387
+ const rootRecord = [`v=${DID_DHT_SPECIFICATION_VERSION}`];
388
+ // Add verification methods to the root record.
389
+ if (verificationMethodIds.length) {
390
+ rootRecord.push(`vm=${verificationMethodIds.join(VALUE_SEPARATOR)}`);
391
+ }
392
+ // Add verification relationships to the root record.
393
+ Object.keys(DidVerificationRelationship).forEach((relationship) => {
394
+ var _a;
395
+ // Collect the verification method IDs for the given relationship.
396
+ const dnsRecordIds = (_a = didDocument[relationship]) === null || _a === void 0 ? void 0 : _a.map((id) => idLookup.get(id.split('#').pop()));
397
+ // If the relationship includes verification methods, add them to the root record.
398
+ if (dnsRecordIds) {
399
+ const recordName = DidDhtVerificationRelationship[relationship];
400
+ rootRecord.push(`${recordName}=${dnsRecordIds.join(VALUE_SEPARATOR)}`);
401
+ }
402
+ });
403
+ // Add services to the root record.
404
+ if (serviceIds.length) {
405
+ rootRecord.push(`svc=${serviceIds.join(VALUE_SEPARATOR)}`);
406
+ }
407
+ // If defined, add a DNS TXT record for each registered DID type.
408
+ if ((_f = didMetadata.types) === null || _f === void 0 ? void 0 : _f.length) {
409
+ // DID types can be specified as either a string or a number, so we need to normalize the
410
+ // values to integers.
411
+ const types = didMetadata.types;
412
+ const typeIntegers = types.map((type) => typeof type === 'string' ? DidDhtRegisteredDidType[type] : type);
413
+ txtRecords.push({
414
+ type: 'TXT',
415
+ name: '_typ._did.',
416
+ ttl: DNS_RECORD_TTL,
417
+ data: `id=${typeIntegers.join(VALUE_SEPARATOR)}`
418
+ });
419
+ }
420
+ // Add a DNS TXT record for the root record.
421
+ txtRecords.push({
422
+ type: 'TXT',
423
+ name: '_did.' + getUniqueDidSuffix(didDocument.id) + '.', // name of a Root Record MUST end in `<ID>.`
424
+ ttl: DNS_RECORD_TTL,
425
+ data: rootRecord.join(PROPERTY_SEPARATOR)
426
+ });
427
+ // Add an NS record for each authoritative gateway URI.
428
+ for (const gatewayUri of authoritativeGatewayUris || []) {
429
+ nsRecords.push({
430
+ type: 'NS',
431
+ name: '_did.' + getUniqueDidSuffix(didDocument.id) + '.', // name of an NS record a authoritative gateway MUST end in `<ID>.`
432
+ ttl: DNS_RECORD_TTL,
433
+ data: gatewayUri + '.'
434
+ });
435
+ }
436
+ // Create a DNS response packet with the authoritative answer flag set.
437
+ const dnsPacket = {
438
+ id: 0,
439
+ type: 'response',
440
+ flags: AUTHORITATIVE_ANSWER,
441
+ answers: [...txtRecords, ...nsRecords]
442
+ };
443
+ return dnsPacket;
444
+ });
445
+ }
446
+ /**
447
+ * Gets the unique portion of the DID identifier after the last `:` character.
448
+ * e.g. `did:dht:example` -> `example`
449
+ *
450
+ * @param did - The DID to extract the unique suffix from.
451
+ */
452
+ function getUniqueDidSuffix(did) {
453
+ return did.split(':')[2];
454
+ }
455
+ //# sourceMappingURL=did-dht-dns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did-dht-dns.js","sourceRoot":"","sources":["../../../src/methods/did-dht-dns.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AACtH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,YAAY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,GAAG,SAAS,CAAC;SACxC,CAAC;QAEF,OAAO,SAAS,CAAC;IACnB,CAAC;CAAA;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,GAAW;IACrC,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,168 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import bencode from 'bencode';
11
+ import { Convert } from '@enbox/common';
12
+ import { Ed25519 } from '@enbox/crypto';
13
+ import { DidError, DidErrorCode } from '../did-error.js';
14
+ import { decode as dnsPacketDecode, encode as dnsPacketEncode } from '@dnsquery/dns-packet';
15
+ /**
16
+ * Constructs a Pkarr URL from public key bytes and a gateway URI.
17
+ *
18
+ * @param publicKeyBytes - The public key bytes to z-base-32 encode.
19
+ * @param gatewayUri - The gateway URI to use as the base URL.
20
+ * @returns The full Pkarr URL.
21
+ */
22
+ function pkarrUrl(publicKeyBytes, gatewayUri) {
23
+ const identifier = Convert.uint8Array(publicKeyBytes).toBase32Z();
24
+ return new URL(identifier, gatewayUri).href;
25
+ }
26
+ /**
27
+ * Retrieves a signed BEP44 message from a DID DHT Gateway or Pkarr Relay server.
28
+ *
29
+ * @see {@link https://github.com/Nuhvi/pkarr/blob/main/design/relays.md | Pkarr Relay design}
30
+ *
31
+ * @param params - The parameters for the get operation.
32
+ * @param params.gatewayUri - The DID DHT Gateway or Pkarr Relay URI.
33
+ * @param params.publicKeyBytes - The public key bytes of the Identity Key, z-base-32 encoded.
34
+ * @returns A promise resolving to a BEP44 message containing the signed DNS packet.
35
+ */
36
+ export function pkarrGet(_a) {
37
+ return __awaiter(this, arguments, void 0, function* ({ gatewayUri, publicKeyBytes }) {
38
+ // The identifier (key in the DHT) is the z-base-32 encoding of the Identity Key.
39
+ const identifier = Convert.uint8Array(publicKeyBytes).toBase32Z();
40
+ // Concatenate the gateway URI with the identifier to form the full URL.
41
+ const url = pkarrUrl(publicKeyBytes, gatewayUri);
42
+ // Transmit the Get request to the DID DHT Gateway or Pkarr Relay and get the response.
43
+ let response;
44
+ try {
45
+ response = yield fetch(url, { method: 'GET' });
46
+ if (!response.ok) {
47
+ throw new DidError(DidErrorCode.NotFound, `Pkarr record not found for: ${identifier}`);
48
+ }
49
+ }
50
+ catch (error) {
51
+ if (error instanceof DidError) {
52
+ throw error;
53
+ }
54
+ throw new DidError(DidErrorCode.InternalError, `Failed to fetch Pkarr record: ${error.message}`);
55
+ }
56
+ // Read the Fetch Response stream into a byte array.
57
+ const messageBytes = yield response.arrayBuffer();
58
+ if (!messageBytes) {
59
+ throw new DidError(DidErrorCode.NotFound, `Pkarr record not found for: ${identifier}`);
60
+ }
61
+ if (messageBytes.byteLength < 72) {
62
+ throw new DidError(DidErrorCode.InvalidDidDocumentLength, `Pkarr response must be at least 72 bytes but got: ${messageBytes.byteLength}`);
63
+ }
64
+ if (messageBytes.byteLength > 1072) {
65
+ throw new DidError(DidErrorCode.InvalidDidDocumentLength, `Pkarr response exceeds 1000 byte limit: ${messageBytes.byteLength}`);
66
+ }
67
+ // Decode the BEP44 message from the byte array.
68
+ const bep44Message = {
69
+ k: publicKeyBytes,
70
+ seq: Number(new DataView(messageBytes).getBigUint64(64)),
71
+ sig: new Uint8Array(messageBytes, 0, 64),
72
+ v: new Uint8Array(messageBytes, 72)
73
+ };
74
+ return bep44Message;
75
+ });
76
+ }
77
+ /**
78
+ * Publishes a signed BEP44 message to a DID DHT Gateway or Pkarr Relay server.
79
+ *
80
+ * @see {@link https://github.com/Nuhvi/pkarr/blob/main/design/relays.md | Pkarr Relay design}
81
+ *
82
+ * @param params - The parameters to use when publishing a signed BEP44 message to a Pkarr relay server.
83
+ * @param params.gatewayUri - The DID DHT Gateway or Pkarr Relay URI.
84
+ * @param params.bep44Message - The BEP44 message to be published, containing the signed DNS packet.
85
+ * @returns A promise resolving to `true` if the message was successfully published, otherwise `false`.
86
+ */
87
+ export function pkarrPut(_a) {
88
+ return __awaiter(this, arguments, void 0, function* ({ gatewayUri, bep44Message }) {
89
+ // The identifier (key in the DHT) is the z-base-32 encoding of the Identity Key.
90
+ const identifier = Convert.uint8Array(bep44Message.k).toBase32Z();
91
+ // Concatenate the gateway URI with the identifier to form the full URL.
92
+ const url = pkarrUrl(bep44Message.k, gatewayUri);
93
+ // Construct the body of the request according to the Pkarr relay specification.
94
+ const body = new Uint8Array(bep44Message.v.length + 72);
95
+ body.set(bep44Message.sig, 0);
96
+ new DataView(body.buffer).setBigUint64(bep44Message.sig.length, BigInt(bep44Message.seq));
97
+ body.set(bep44Message.v, bep44Message.sig.length + 8);
98
+ // Transmit the Put request to the Pkarr relay and get the response.
99
+ let response;
100
+ try {
101
+ response = yield fetch(url, {
102
+ method: 'PUT',
103
+ headers: { 'Content-Type': 'application/octet-stream' },
104
+ body
105
+ });
106
+ }
107
+ catch (error) {
108
+ throw new DidError(DidErrorCode.InternalError, `Failed to put Pkarr record for identifier ${identifier}: ${error.message}`);
109
+ }
110
+ // Return `true` if the DHT request was successful, otherwise return `false`.
111
+ return response.ok;
112
+ });
113
+ }
114
+ /**
115
+ * Creates a BEP44 put message, which is used to publish a DID document to the DHT network.
116
+ *
117
+ * @param params - The parameters to use when creating the BEP44 put message.
118
+ * @param params.dnsPacket - The DNS packet to encode in the BEP44 message.
119
+ * @param params.publicKeyBytes - The public key bytes of the Identity Key.
120
+ * @param params.signer - Signer that can sign and verify data using the Identity Key.
121
+ * @returns A promise that resolves to a BEP44 put message.
122
+ */
123
+ export function createBep44PutMessage(_a) {
124
+ return __awaiter(this, arguments, void 0, function* ({ dnsPacket, publicKeyBytes, signer }) {
125
+ // BEP44 requires that the sequence number be a monotoically increasing integer, so we use the
126
+ // current time in seconds since Unix epoch as a simple solution. Higher precision is not
127
+ // recommended since DID DHT documents are not expected to change frequently and there are
128
+ // small differences in system clocks that can cause issues if multiple clients are publishing
129
+ // updates to the same DID document.
130
+ const sequenceNumber = Math.ceil(Date.now() / 1000);
131
+ // Encode the DNS packet into a byte array containing a UDP payload.
132
+ const encodedDnsPacket = dnsPacketEncode(dnsPacket);
133
+ // Encode the sequence and DNS byte array to bencode format.
134
+ const bencodedData = bencode.encode({ seq: sequenceNumber, v: encodedDnsPacket }).subarray(1, -1);
135
+ if (bencodedData.length > 1000) {
136
+ throw new DidError(DidErrorCode.InvalidDidDocumentLength, `DNS packet exceeds the 1000 byte maximum size: ${bencodedData.length} bytes`);
137
+ }
138
+ // Sign the BEP44 message.
139
+ const signature = yield signer.sign({ data: bencodedData });
140
+ return { k: publicKeyBytes, seq: sequenceNumber, sig: signature, v: encodedDnsPacket };
141
+ });
142
+ }
143
+ /**
144
+ * Parses and verifies a BEP44 Get message, converting it to a DNS packet.
145
+ *
146
+ * @param params - The parameters to use when verifying and parsing the BEP44 Get response message.
147
+ * @param params.bep44Message - The BEP44 message to verify and parse.
148
+ * @returns A promise that resolves to a DNS packet.
149
+ */
150
+ export function parseBep44GetMessage(_a) {
151
+ return __awaiter(this, arguments, void 0, function* ({ bep44Message }) {
152
+ // Convert the public key byte array to JWK format.
153
+ const publicKey = yield Ed25519.bytesToPublicKey({ publicKeyBytes: bep44Message.k });
154
+ // Encode the sequence and DNS byte array to bencode format.
155
+ const bencodedData = bencode.encode({ seq: bep44Message.seq, v: bep44Message.v }).subarray(1, -1);
156
+ // Verify the signature of the BEP44 message.
157
+ const isValid = yield Ed25519.verify({
158
+ key: publicKey,
159
+ signature: bep44Message.sig,
160
+ data: bencodedData
161
+ });
162
+ if (!isValid) {
163
+ throw new DidError(DidErrorCode.InvalidSignature, `Invalid signature for DHT BEP44 message`);
164
+ }
165
+ return dnsPacketDecode(bep44Message.v);
166
+ });
167
+ }
168
+ //# sourceMappingURL=did-dht-pkarr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did-dht-pkarr.js","sourceRoot":"","sources":["../../../src/methods/did-dht-pkarr.ts"],"names":[],"mappings":";;;;;;;;;AAKA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5F;;;;;;GAMG;AACH,SAAS,QAAQ,CAAC,cAA0B,EAAE,UAAkB;IAC9D,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,SAAS,EAAE,CAAC;IAClE,OAAO,IAAI,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC;AAC9C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAgB,QAAQ;yDAAC,EAAE,UAAU,EAAE,cAAc,EAG1D;QACC,iFAAiF;QACjF,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,SAAS,EAAE,CAAC;QAElE,wEAAwE;QACxE,MAAM,GAAG,GAAG,QAAQ,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QAEjD,uFAAuF;QACvF,IAAI,QAAkB,CAAC;QACvB,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;YAE/C,IAAI,CAAC,QAAQ,CAAC,EAAE,E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