@helia/ipns 6.0.1 → 7.0.0-b6765fe

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 (53) hide show
  1. package/dist/index.min.js +4 -4
  2. package/dist/src/dnslink.d.ts +9 -0
  3. package/dist/src/dnslink.d.ts.map +1 -0
  4. package/dist/src/dnslink.js +129 -0
  5. package/dist/src/dnslink.js.map +1 -0
  6. package/dist/src/index.d.ts +39 -23
  7. package/dist/src/index.d.ts.map +1 -1
  8. package/dist/src/index.js +18 -11
  9. package/dist/src/index.js.map +1 -1
  10. package/package.json +3 -6
  11. package/src/dnslink.ts +153 -0
  12. package/src/index.ts +64 -43
  13. package/dist/src/dns-resolvers/default.d.ts +0 -3
  14. package/dist/src/dns-resolvers/default.d.ts.map +0 -1
  15. package/dist/src/dns-resolvers/default.js +0 -8
  16. package/dist/src/dns-resolvers/default.js.map +0 -1
  17. package/dist/src/dns-resolvers/dns-json-over-https.d.ts +0 -18
  18. package/dist/src/dns-resolvers/dns-json-over-https.d.ts.map +0 -1
  19. package/dist/src/dns-resolvers/dns-json-over-https.js +0 -72
  20. package/dist/src/dns-resolvers/dns-json-over-https.js.map +0 -1
  21. package/dist/src/dns-resolvers/dns-over-https.d.ts +0 -16
  22. package/dist/src/dns-resolvers/dns-over-https.d.ts.map +0 -1
  23. package/dist/src/dns-resolvers/dns-over-https.js +0 -123
  24. package/dist/src/dns-resolvers/dns-over-https.js.map +0 -1
  25. package/dist/src/dns-resolvers/index.d.ts +0 -3
  26. package/dist/src/dns-resolvers/index.d.ts.map +0 -1
  27. package/dist/src/dns-resolvers/index.js +0 -3
  28. package/dist/src/dns-resolvers/index.js.map +0 -1
  29. package/dist/src/dns-resolvers/resolver.browser.d.ts +0 -4
  30. package/dist/src/dns-resolvers/resolver.browser.d.ts.map +0 -1
  31. package/dist/src/dns-resolvers/resolver.browser.js +0 -39
  32. package/dist/src/dns-resolvers/resolver.browser.js.map +0 -1
  33. package/dist/src/dns-resolvers/resolver.d.ts +0 -4
  34. package/dist/src/dns-resolvers/resolver.d.ts.map +0 -1
  35. package/dist/src/dns-resolvers/resolver.js +0 -21
  36. package/dist/src/dns-resolvers/resolver.js.map +0 -1
  37. package/dist/src/utils/dns.d.ts +0 -35
  38. package/dist/src/utils/dns.d.ts.map +0 -1
  39. package/dist/src/utils/dns.js +0 -80
  40. package/dist/src/utils/dns.js.map +0 -1
  41. package/dist/src/utils/tlru.d.ts +0 -15
  42. package/dist/src/utils/tlru.d.ts.map +0 -1
  43. package/dist/src/utils/tlru.js +0 -40
  44. package/dist/src/utils/tlru.js.map +0 -1
  45. package/dist/typedoc-urls.json +0 -44
  46. package/src/dns-resolvers/default.ts +0 -9
  47. package/src/dns-resolvers/dns-json-over-https.ts +0 -90
  48. package/src/dns-resolvers/dns-over-https.ts +0 -146
  49. package/src/dns-resolvers/index.ts +0 -2
  50. package/src/dns-resolvers/resolver.browser.ts +0 -50
  51. package/src/dns-resolvers/resolver.ts +0 -25
  52. package/src/utils/dns.ts +0 -127
  53. package/src/utils/tlru.ts +0 -52
package/src/index.ts CHANGED
@@ -235,13 +235,13 @@ import { ipnsSelector } from 'ipns/selector'
235
235
  import { ipnsValidator } from 'ipns/validator'
236
236
  import { CID } from 'multiformats/cid'
237
237
  import { CustomProgressEvent } from 'progress-events'
238
- import { defaultResolver } from './dns-resolvers/default.js'
238
+ import { resolveDNSLink } from './dnslink.js'
239
239
  import { helia } from './routing/helia.js'
240
240
  import { localStore, type LocalStore } from './routing/local-store.js'
241
241
  import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js'
242
- import type { DNSResponse } from './utils/dns.js'
243
242
  import type { Routing } from '@helia/interface'
244
- import type { AbortOptions, PeerId } from '@libp2p/interface'
243
+ import type { AbortOptions, ComponentLogger, Logger, PeerId } from '@libp2p/interface'
244
+ import type { Answer, DNS, ResolveDnsProgressEvents } from '@multiformats/dns'
245
245
  import type { Datastore } from 'interface-datastore'
246
246
  import type { IPNSRecord } from 'ipns'
247
247
  import type { ProgressEvent, ProgressOptions } from 'progress-events'
@@ -269,10 +269,10 @@ export type RepublishProgressEvents =
269
269
  ProgressEvent<'ipns:republish:success', IPNSRecord> |
270
270
  ProgressEvent<'ipns:republish:error', { record: IPNSRecord, err: Error }>
271
271
 
272
- export type ResolveDnsLinkProgressEvents =
273
- ProgressEvent<'dnslink:cache', string> |
274
- ProgressEvent<'dnslink:query', string> |
275
- ProgressEvent<'dnslink:answer', DNSResponse>
272
+ export type ResolveDNSLinkProgressEvents =
273
+ ResolveProgressEvents |
274
+ IPNSRoutingEvents |
275
+ ResolveDnsProgressEvents
276
276
 
277
277
  export interface PublishOptions extends AbortOptions, ProgressOptions<PublishProgressEvents | IPNSRoutingEvents> {
278
278
  /**
@@ -299,35 +299,28 @@ export interface ResolveOptions extends AbortOptions, ProgressOptions<ResolvePro
299
299
  offline?: boolean
300
300
  }
301
301
 
302
- export interface ResolveDnsLinkOptions extends AbortOptions, ProgressOptions<ResolveDnsLinkProgressEvents> {
302
+ export interface ResolveDNSLinkOptions extends AbortOptions, ProgressOptions<ResolveDNSLinkProgressEvents> {
303
303
  /**
304
- * Do not use cached DNS entries (default: false)
305
- */
306
- nocache?: boolean
307
- }
308
-
309
- export interface DNSResolver {
310
- (domain: string, options?: ResolveDnsLinkOptions): Promise<string>
311
- }
312
-
313
- export interface ResolveDNSOptions extends AbortOptions, ProgressOptions<ResolveProgressEvents | IPNSRoutingEvents | ResolveDnsLinkProgressEvents> {
314
- /**
315
- * Do not query the network for the IPNS record (default: false)
304
+ * Do not query the network for the IPNS record
305
+ *
306
+ * @default false
316
307
  */
317
308
  offline?: boolean
318
309
 
319
310
  /**
320
- * Do not use cached DNS entries (default: false)
311
+ * Do not use cached DNS entries
312
+ *
313
+ * @default false
321
314
  */
322
315
  nocache?: boolean
323
316
 
324
317
  /**
325
- * These resolvers will be used to resolve the dnslink entries, if unspecified node will
326
- * fall back to the `dns` module and browsers fall back to querying google/cloudflare DoH
318
+ * When resolving DNSLink records that resolve to other DNSLink records, limit
319
+ * how many times we will recursively resolve them.
327
320
  *
328
- * @see https://github.com/ipfs/helia-ipns/pull/55#discussion_r1270096881
321
+ * @default 32
329
322
  */
330
- resolvers?: DNSResolver[]
323
+ maxRecursiveDepth?: number
331
324
  }
332
325
 
333
326
  export interface RepublishOptions extends AbortOptions, ProgressOptions<RepublishProgressEvents | IPNSRoutingEvents> {
@@ -338,10 +331,33 @@ export interface RepublishOptions extends AbortOptions, ProgressOptions<Republis
338
331
  }
339
332
 
340
333
  export interface ResolveResult {
334
+ /**
335
+ * The CID that was resolved
336
+ */
341
337
  cid: CID
338
+
339
+ /**
340
+ * Any path component that was part of the resolved record
341
+ *
342
+ * @default ""
343
+ */
342
344
  path: string
343
345
  }
344
346
 
347
+ export interface IPNSResolveResult extends ResolveResult {
348
+ /**
349
+ * The resolved record
350
+ */
351
+ record: IPNSRecord
352
+ }
353
+
354
+ export interface DNSLinkResolveResult extends ResolveResult {
355
+ /**
356
+ * The resolved record
357
+ */
358
+ answer: Answer
359
+ }
360
+
345
361
  export interface IPNS {
346
362
  /**
347
363
  * Creates an IPNS record signed by the passed PeerId that will resolve to the passed value
@@ -354,12 +370,12 @@ export interface IPNS {
354
370
  * Accepts a public key formatted as a libp2p PeerID and resolves the IPNS record
355
371
  * corresponding to that public key until a value is found
356
372
  */
357
- resolve(key: PeerId, options?: ResolveOptions): Promise<ResolveResult>
373
+ resolve(key: PeerId, options?: ResolveOptions): Promise<IPNSResolveResult>
358
374
 
359
375
  /**
360
376
  * Resolve a CID from a dns-link style IPNS record
361
377
  */
362
- resolveDns(domain: string, options?: ResolveDNSOptions): Promise<ResolveResult>
378
+ resolveDNSLink(domain: string, options?: ResolveDNSLinkOptions): Promise<DNSLinkResolveResult>
363
379
 
364
380
  /**
365
381
  * Periodically republish all IPNS records found in the datastore
@@ -372,21 +388,25 @@ export type { IPNSRouting } from './routing/index.js'
372
388
  export interface IPNSComponents {
373
389
  datastore: Datastore
374
390
  routing: Routing
391
+ dns: DNS
392
+ logger: ComponentLogger
375
393
  }
376
394
 
377
395
  class DefaultIPNS implements IPNS {
378
396
  private readonly routers: IPNSRouting[]
379
397
  private readonly localStore: LocalStore
380
398
  private timeout?: ReturnType<typeof setTimeout>
381
- private readonly defaultResolvers: DNSResolver[]
399
+ private readonly dns: DNS
400
+ private readonly log: Logger
382
401
 
383
- constructor (components: IPNSComponents, routers: IPNSRouting[] = [], resolvers: DNSResolver[] = []) {
402
+ constructor (components: IPNSComponents, routers: IPNSRouting[] = []) {
384
403
  this.routers = [
385
404
  helia(components.routing),
386
405
  ...routers
387
406
  ]
388
407
  this.localStore = localStore(components.datastore)
389
- this.defaultResolvers = resolvers.length > 0 ? resolvers : [defaultResolver()]
408
+ this.dns = components.dns
409
+ this.log = components.logger.forComponent('helia:ipns')
390
410
  }
391
411
 
392
412
  async publish (key: PeerId, value: CID | PeerId | string, options: PublishOptions = {}): Promise<IPNSRecord> {
@@ -419,21 +439,23 @@ class DefaultIPNS implements IPNS {
419
439
  }
420
440
  }
421
441
 
422
- async resolve (key: PeerId, options: ResolveOptions = {}): Promise<ResolveResult> {
442
+ async resolve (key: PeerId, options: ResolveOptions = {}): Promise<IPNSResolveResult> {
423
443
  const routingKey = peerIdToRoutingKey(key)
424
444
  const record = await this.#findIpnsRecord(routingKey, options)
425
445
 
426
- return this.#resolve(record.value, options)
446
+ return {
447
+ ...(await this.#resolve(record.value, options)),
448
+ record
449
+ }
427
450
  }
428
451
 
429
- async resolveDns (domain: string, options: ResolveDNSOptions = {}): Promise<ResolveResult> {
430
- const resolvers = options.resolvers ?? this.defaultResolvers
452
+ async resolveDNSLink (domain: string, options: ResolveDNSLinkOptions = {}): Promise<DNSLinkResolveResult> {
453
+ const dnslink = await resolveDNSLink(domain, this.dns, this.log, options)
431
454
 
432
- const dnslink = await Promise.any(
433
- resolvers.map(async resolver => resolver(domain, options))
434
- )
435
-
436
- return this.#resolve(dnslink, options)
455
+ return {
456
+ ...(await this.#resolve(dnslink.value, options)),
457
+ answer: dnslink.answer
458
+ }
437
459
  }
438
460
 
439
461
  republish (options: RepublishOptions = {}): void {
@@ -472,7 +494,7 @@ class DefaultIPNS implements IPNS {
472
494
  }, options.interval ?? DEFAULT_REPUBLISH_INTERVAL_MS)
473
495
  }
474
496
 
475
- async #resolve (ipfsPath: string, options: ResolveOptions = {}): Promise<ResolveResult> {
497
+ async #resolve (ipfsPath: string, options: ResolveOptions = {}): Promise<{ cid: CID, path: string }> {
476
498
  const parts = ipfsPath.split('/')
477
499
  try {
478
500
  const scheme = parts[1]
@@ -564,11 +586,10 @@ class DefaultIPNS implements IPNS {
564
586
 
565
587
  export interface IPNSOptions {
566
588
  routers?: IPNSRouting[]
567
- resolvers?: DNSResolver[]
568
589
  }
569
590
 
570
- export function ipns (components: IPNSComponents, { routers = [], resolvers = [] }: IPNSOptions = {}): IPNS {
571
- return new DefaultIPNS(components, routers, resolvers)
591
+ export function ipns (components: IPNSComponents, { routers = [] }: IPNSOptions = {}): IPNS {
592
+ return new DefaultIPNS(components, routers)
572
593
  }
573
594
 
574
595
  export { ipnsValidator, type IPNSRoutingEvents }
@@ -1,3 +0,0 @@
1
- import type { DNSResolver } from '../index.js';
2
- export declare function defaultResolver(): DNSResolver;
3
- //# sourceMappingURL=default.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../../src/dns-resolvers/default.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAyB,MAAM,aAAa,CAAA;AAErE,wBAAgB,eAAe,IAAK,WAAW,CAI9C"}
@@ -1,8 +0,0 @@
1
- import { MAX_RECURSIVE_DEPTH, recursiveResolveDnslink } from '../utils/dns.js';
2
- import resolve from './resolver.js';
3
- export function defaultResolver() {
4
- return async (domain, options = {}) => {
5
- return recursiveResolveDnslink(domain, MAX_RECURSIVE_DEPTH, resolve, options);
6
- };
7
- }
8
- //# sourceMappingURL=default.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"default.js","sourceRoot":"","sources":["../../../src/dns-resolvers/default.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAC9E,OAAO,OAAO,MAAM,eAAe,CAAA;AAGnC,MAAM,UAAU,eAAe;IAC7B,OAAO,KAAK,EAAE,MAAc,EAAE,UAAiC,EAAE,EAAmB,EAAE;QACpF,OAAO,uBAAuB,CAAC,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC/E,CAAC,CAAA;AACH,CAAC"}
@@ -1,18 +0,0 @@
1
- import type { DNSResolver } from '../index.js';
2
- /**
3
- * Uses the RFC 8427 'application/dns-json' content-type to resolve DNS queries.
4
- *
5
- * Supports and server that uses the same schema as Google's DNS over HTTPS
6
- * resolver.
7
- *
8
- * This resolver needs fewer dependencies than the regular DNS-over-HTTPS
9
- * resolver so can result in a smaller bundle size and consequently is preferred
10
- * for browser use.
11
- *
12
- * @see https://developers.cloudflare.com/1.1.1.1/encryption/dns-over-https/make-api-requests/dns-json/
13
- * @see https://github.com/curl/curl/wiki/DNS-over-HTTPS#publicly-available-servers
14
- * @see https://dnsprivacy.org/public_resolvers/
15
- * @see https://datatracker.ietf.org/doc/html/rfc8427
16
- */
17
- export declare function dnsJsonOverHttps(url: string): DNSResolver;
18
- //# sourceMappingURL=dns-json-over-https.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dns-json-over-https.d.ts","sourceRoot":"","sources":["../../../src/dns-resolvers/dns-json-over-https.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAyB,WAAW,EAAE,MAAM,aAAa,CAAA;AAOrE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAE,GAAG,EAAE,MAAM,GAAG,WAAW,CA6D1D"}
@@ -1,72 +0,0 @@
1
- /* eslint-env browser */
2
- import PQueue from 'p-queue';
3
- import { CustomProgressEvent } from 'progress-events';
4
- import { MAX_RECURSIVE_DEPTH, recursiveResolveDnslink, ipfsPathAndAnswer } from '../utils/dns.js';
5
- import { TLRU } from '../utils/tlru.js';
6
- // Avoid sending multiple queries for the same hostname by caching results
7
- const cache = new TLRU(1000);
8
- // This TTL will be used if the remote service does not return one
9
- const ttl = 60 * 1000;
10
- /**
11
- * Uses the RFC 8427 'application/dns-json' content-type to resolve DNS queries.
12
- *
13
- * Supports and server that uses the same schema as Google's DNS over HTTPS
14
- * resolver.
15
- *
16
- * This resolver needs fewer dependencies than the regular DNS-over-HTTPS
17
- * resolver so can result in a smaller bundle size and consequently is preferred
18
- * for browser use.
19
- *
20
- * @see https://developers.cloudflare.com/1.1.1.1/encryption/dns-over-https/make-api-requests/dns-json/
21
- * @see https://github.com/curl/curl/wiki/DNS-over-HTTPS#publicly-available-servers
22
- * @see https://dnsprivacy.org/public_resolvers/
23
- * @see https://datatracker.ietf.org/doc/html/rfc8427
24
- */
25
- export function dnsJsonOverHttps(url) {
26
- // browsers limit concurrent connections per host,
27
- // we don't want preload calls to exhaust the limit (~6)
28
- const httpQueue = new PQueue({ concurrency: 4 });
29
- const resolve = async (fqdn, options = {}) => {
30
- const searchParams = new URLSearchParams();
31
- searchParams.set('name', fqdn);
32
- searchParams.set('type', 'TXT');
33
- const query = searchParams.toString();
34
- // try cache first
35
- if (options.nocache !== true && cache.has(query)) {
36
- const response = cache.get(query);
37
- if (response != null) {
38
- options.onProgress?.(new CustomProgressEvent('dnslink:cache', { detail: response }));
39
- return response;
40
- }
41
- }
42
- options.onProgress?.(new CustomProgressEvent('dnslink:query', { detail: fqdn }));
43
- // query DNS-JSON over HTTPS server
44
- const response = await httpQueue.add(async () => {
45
- const res = await fetch(`${url}?${searchParams}`, {
46
- headers: {
47
- accept: 'application/dns-json'
48
- },
49
- signal: options.signal
50
- });
51
- if (res.status !== 200) {
52
- throw new Error(`Unexpected HTTP status: ${res.status} - ${res.statusText}`);
53
- }
54
- const query = new URL(res.url).search.slice(1);
55
- const json = await res.json();
56
- options.onProgress?.(new CustomProgressEvent('dnslink:answer', { detail: json }));
57
- const { ipfsPath, answer } = ipfsPathAndAnswer(fqdn, json);
58
- cache.set(query, ipfsPath, answer.TTL ?? ttl);
59
- return ipfsPath;
60
- }, {
61
- signal: options.signal
62
- });
63
- if (response == null) {
64
- throw new Error('No DNS response received');
65
- }
66
- return response;
67
- };
68
- return async (domain, options = {}) => {
69
- return recursiveResolveDnslink(domain, MAX_RECURSIVE_DEPTH, resolve, options);
70
- };
71
- }
72
- //# sourceMappingURL=dns-json-over-https.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dns-json-over-https.js","sourceRoot":"","sources":["../../../src/dns-resolvers/dns-json-over-https.ts"],"names":[],"mappings":"AAAA,wBAAwB;AAExB,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAoB,mBAAmB,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnH,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAGvC,0EAA0E;AAC1E,MAAM,KAAK,GAAG,IAAI,IAAI,CAAS,IAAI,CAAC,CAAA;AACpC,kEAAkE;AAClE,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,CAAA;AAErB;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAAE,GAAW;IAC3C,kDAAkD;IAClD,wDAAwD;IACxD,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC,CAAA;IAEhD,MAAM,OAAO,GAAG,KAAK,EAAE,IAAY,EAAE,UAAiC,EAAE,EAAmB,EAAE;QAC3F,MAAM,YAAY,GAAG,IAAI,eAAe,EAAE,CAAA;QAC1C,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAC9B,YAAY,C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E1C,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAc,gBAAgB,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;YAE9F,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;YAE1D,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,CAAA;YAE7C,OAAO,QAAQ,CAAA;QACjB,CAAC,EAAE;YACD,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC,CAAA;QAEF,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;QAC7C,CAAC;QAED,OAAO,QAAQ,CAAA;IACjB,CAAC,CAAA;IAED,OAAO,KAAK,EAAE,MAAc,EAAE,UAAiC,EAAE,EAAE,EAAE;QACnE,OAAO,uBAAuB,CAAC,MAAM,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAC/E,CAAC,CAAA;AACH,CAAC"}
@@ -1,16 +0,0 @@
1
- import type { DNSResolver } from '../index.js';
2
- /**
3
- * Uses the RFC 1035 'application/dns-message' content-type to resolve DNS
4
- * queries.
5
- *
6
- * This resolver needs more dependencies than the non-standard
7
- * DNS-JSON-over-HTTPS resolver so can result in a larger bundle size and
8
- * consequently is not preferred for browser use.
9
- *
10
- * @see https://datatracker.ietf.org/doc/html/rfc1035
11
- * @see https://developers.cloudflare.com/1.1.1.1/encryption/dns-over-https/make-api-requests/dns-wireformat/
12
- * @see https://github.com/curl/curl/wiki/DNS-over-HTTPS#publicly-available-servers
13
- * @see https://dnsprivacy.org/public_resolvers/
14
- */
15
- export declare function dnsOverHttps(url: string): DNSResolver;
16
- //# sourceMappingURL=dns-over-https.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dns-over-https.d.ts","sourceRoot":"","sources":["../../../src/dns-resolvers/dns-over-https.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAyB,WAAW,EAAE,MAAM,aAAa,CAAA;AAOrE;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAE,GAAG,EAAE,MAAM,GAAG,WAAW,CAwEtD"}
@@ -1,123 +0,0 @@
1
- /* eslint-env browser */
2
- import { Buffer } from 'buffer';
3
- import dnsPacket, {} from 'dns-packet';
4
- import { base64url } from 'multiformats/bases/base64';
5
- import PQueue from 'p-queue';
6
- import { CustomProgressEvent } from 'progress-events';
7
- import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
8
- import { MAX_RECURSIVE_DEPTH, recursiveResolveDnslink, ipfsPathAndAnswer } from '../utils/dns.js';
9
- import { TLRU } from '../utils/tlru.js';
10
- // Avoid sending multiple queries for the same hostname by caching results
11
- const cache = new TLRU(1000);
12
- // This TTL will be used if the remote service does not return one
13
- const ttl = 60 * 1000;
14
- /**
15
- * Uses the RFC 1035 'application/dns-message' content-type to resolve DNS
16
- * queries.
17
- *
18
- * This resolver needs more dependencies than the non-standard
19
- * DNS-JSON-over-HTTPS resolver so can result in a larger bundle size and
20
- * consequently is not preferred for browser use.
21
- *
22
- * @see https://datatracker.ietf.org/doc/html/rfc1035
23
- * @see https://developers.cloudflare.com/1.1.1.1/encryption/dns-over-https/make-api-requests/dns-wireformat/
24
- * @see https://github.com/curl/curl/wiki/DNS-over-HTTPS#publicly-available-servers
25
- * @see https://dnsprivacy.org/public_resolvers/
26
- */
27
- export function dnsOverHttps(url) {
28
- // browsers limit concurrent connections per host,
29
- // we don't want preload calls to exhaust the limit (~6)
30
- const httpQueue = new PQueue({ concurrency: 4 });
31
- const resolve = async (fqdn, options = {}) => {
32
- const dnsQuery = dnsPacket.encode({
33
- type: 'query',
34
- id: 0,
35
- flags: dnsPacket.RECURSION_DESIRED,
36
- questions: [{
37
- type: 'TXT',
38
- name: fqdn
39
- }]
40
- });
41
- const searchParams = new URLSearchParams();
42
- searchParams.set('dns', base64url.encode(dnsQuery).substring(1));
43
- const query = searchParams.toString();
44
- // try cache first
45
- if (options.nocache !== true && cache.has(query)) {
46
- const response = cache.get(query);
47
- if (response != null) {
48
- options.onProgress?.(new CustomProgressEvent('dnslink:cache', { detail: response }));
49
- return response;
50
- }
51
- }
52
- options.onProgress?.(new CustomProgressEvent('dnslink:query', { detail: fqdn }));
53
- // query DNS over HTTPS server
54
- const response = await httpQueue.add(async () => {
55
- const res = await fetch(`${url}?${searchParams}`, {
56
- headers: {
57
- accept: 'application/dns-message'
58
- },
59
- signal: options.signal
60
- });
61
- if (res.status !== 200) {
62
- throw new Error(`Unexpected HTTP status: ${res.status} - ${res.statusText}`);
63
- }
64
- const query = new URL(res.url).search.slice(1);
65
- const buf = await res.arrayBuffer();
66
- // map to expected response format
67
- const json = toDNSResponse(dnsPacket.decode(Buffer.from(buf)));
68
- options.onProgress?.(new CustomProgressEvent('dnslink:answer', { detail: json }));
69
- const { ipfsPath, answer } = ipfsPathAndAnswer(fqdn, json);
70
- cache.set(query, ipfsPath, answer.TTL ?? ttl);
71
- return ipfsPath;
72
- }, {
73
- signal: options.signal
74
- });
75
- if (response == null) {
76
- throw new Error('No DNS response received');
77
- }
78
- return response;
79
- };
80
- return async (domain, options = {}) => {
81
- return recursiveResolveDnslink(domain, MAX_RECURSIVE_DEPTH, resolve, options);
82
- };
83
- }
84
- function toDNSResponse(response) {
85
- const txtType = 16;
86
- return {
87
- Status: 0,
88
- TC: response.flag_tc ?? false,
89
- RD: response.flag_rd ?? false,
90
- RA: response.flag_ra ?? false,
91
- AD: response.flag_ad ?? false,
92
- CD: response.flag_cd ?? false,
93
- Question: response.questions?.map(q => ({
94
- name: q.name,
95
- type: txtType
96
- })) ?? [],
97
- Answer: response.answers?.map(a => {
98
- if (a.type !== 'TXT' || a.data.length < 1) {
99
- return {
100
- name: a.name,
101
- type: txtType,
102
- TTL: 0,
103
- data: 'invalid'
104
- };
105
- }
106
- if (!Buffer.isBuffer(a.data[0])) {
107
- return {
108
- name: a.name,
109
- type: txtType,
110
- TTL: a.ttl ?? ttl,
111
- data: String(a.data[0])
112
- };
113
- }
114
- return {
115
- name: a.name,
116
- type: txtType,
117
- TTL: a.ttl ?? ttl,
118
- data: uint8ArrayToString(a.data[0])
119
- };
120
- }) ?? []
121
- };
122
- }
123
- //# sourceMappingURL=dns-over-https.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dns-over-https.js","sourceRoot":"","sources":["../../../src/dns-resolvers/dns-over-https.ts"],"names":[],"mappings":"AAAA,wBAAwB;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,SAAS,EAAE,EAAsB,MAAM,YAAY,CAAA;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAoB,mBAAmB,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnH,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAGvC,0EAA0E;AAC1E,MAAM,KAAK,GAAG,IAAI,IAAI,CAAS,IAAI,CAAC,CAAA;AACpC,kEAAkE;AAClE,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,CAAA;AAErB;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAE,GAAW;IACvC,kDAAkD;IAClD,wDAAwD;IACxD,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC,CAAA;IAEhD,MAAM,OAAO,GAAG,KAAK,EAAE,IAAY,EAAE,UAAiC,EAAE,EAAmB,EAAE;QAC3F,MAAM,QAAQ,GA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C,GAAG,IAAI,GAAG;gBACjB,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACpC,CAAA;QACH,CAAC,CAAC,IAAI,EAAE;KACT,CAAA;AACH,CAAC"}
@@ -1,3 +0,0 @@
1
- export { dnsOverHttps } from './dns-over-https.js';
2
- export { dnsJsonOverHttps } from './dns-json-over-https.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/dns-resolvers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA"}
@@ -1,3 +0,0 @@
1
- export { dnsOverHttps } from './dns-over-https.js';
2
- export { dnsJsonOverHttps } from './dns-json-over-https.js';
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/dns-resolvers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA"}
@@ -1,4 +0,0 @@
1
- import type { DNSResolver } from '../index.js';
2
- declare const resolve: DNSResolver;
3
- export default resolve;
4
- //# sourceMappingURL=resolver.browser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.browser.d.ts","sourceRoot":"","sources":["../../../src/dns-resolvers/resolver.browser.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAW9C,QAAA,MAAM,OAAO,EAAE,WA+Bd,CAAA;AAED,eAAe,OAAO,CAAA"}
@@ -1,39 +0,0 @@
1
- import Resolver from 'dns-over-http-resolver';
2
- import PQueue from 'p-queue';
3
- import { CustomProgressEvent } from 'progress-events';
4
- import { resolveFn } from '../utils/dns.js';
5
- import { TLRU } from '../utils/tlru.js';
6
- const cache = new TLRU(1000);
7
- // We know browsers themselves cache DNS records for at least 1 minute,
8
- // which acts a provisional default ttl: https://stackoverflow.com/a/36917902/11518426
9
- const ttl = 60 * 1000;
10
- // browsers limit concurrent connections per host,
11
- // we don't want to exhaust the limit (~6)
12
- const httpQueue = new PQueue({ concurrency: 4 });
13
- const resolve = async function resolve(domain, options = {}) {
14
- const resolver = new Resolver({ maxCache: 0 });
15
- // try cache first
16
- if (options.nocache !== true && cache.has(domain)) {
17
- const response = cache.get(domain);
18
- if (response != null) {
19
- options?.onProgress?.(new CustomProgressEvent('dnslink:cache', { detail: response }));
20
- return response;
21
- }
22
- }
23
- options.onProgress?.(new CustomProgressEvent('dnslink:query', { detail: domain }));
24
- // Add the query to the queue
25
- const response = await httpQueue.add(async () => {
26
- const dnslinkRecord = await resolveFn(resolver, domain);
27
- options.onProgress?.(new CustomProgressEvent('dnslink:answer', { detail: dnslinkRecord }));
28
- cache.set(domain, dnslinkRecord, ttl);
29
- return dnslinkRecord;
30
- }, {
31
- signal: options?.signal
32
- });
33
- if (response == null) {
34
- throw new Error('No DNS response received');
35
- }
36
- return response;
37
- };
38
- export default resolve;
39
- //# sourceMappingURL=resolver.browser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.browser.js","sourceRoot":"","sources":["../../../src/dns-resolvers/resolver.browser.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,wBAAwB,CAAA;AAC7C,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAGvC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAS,IAAI,CAAC,CAAA;AACpC,uEAAuE;AACvE,sFAAsF;AACtF,MAAM,GAA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AAE,OAAO,EAAE,MAAM;KACxB,CAAC,CAAA;IAEF,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;IAC7C,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED,eAAe,OAAO,CAAA"}
@@ -1,4 +0,0 @@
1
- import type { DNSResolver } from '../index.js';
2
- declare const resolve: DNSResolver;
3
- export default resolve;
4
- //# sourceMappingURL=resolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../src/dns-resolvers/resolver.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,QAAA,MAAM,OAAO,EAAE,WAiBd,CAAA;AAED,eAAe,OAAO,CAAA"}
@@ -1,21 +0,0 @@
1
- import { Resolver } from 'dns/promises';
2
- import { CustomProgressEvent } from 'progress-events';
3
- import { resolveFn } from '../utils/dns.js';
4
- const resolve = async function resolve(domain, options = {}) {
5
- const resolver = new Resolver();
6
- const listener = () => {
7
- resolver.cancel();
8
- };
9
- options.signal?.addEventListener('abort', listener);
10
- try {
11
- options.onProgress?.(new CustomProgressEvent('dnslink:query', { detail: domain }));
12
- const dnslinkRecord = await resolveFn(resolver, domain);
13
- options.onProgress?.(new CustomProgressEvent('dnslink:answer', { detail: dnslinkRecord }));
14
- return dnslinkRecord;
15
- }
16
- finally {
17
- options.signal?.removeEventListener('abort', listener);
18
- }
19
- };
20
- export default resolve;
21
- //# sourceMappingURL=resolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../../src/dns-resolvers/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAA;AAG7D,MAAM,OAAO,GAAgB,KAAK,UAAU,OAAO,CAAE,MAAM,EAAE,OAAO,GAAG,EAAE;IACvE,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAA;IAC/B,MAAM,QAAQ,GAAG,GAAS,EAAE;QAC1B,QAAQ,CAAC,MAAM,EAAE,CAAA;IACnB,CAAC,CAAA;IAED,OAAO,CAAC,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IAEnD,IAAI,CAAC;QACH,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAS,eAAe,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;QAC1F,MAAM,aAAa,GAAG,MAAM,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QAEvD,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,mBAAmB,CAAc,gBAAgB,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC,CAAA;QACvG,OAAO,aAAa,CAAA;IACtB,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IACxD,CAAC;AACH,CAAC,CAAA;AAED,eAAe,OAAO,CAAA"}
@@ -1,35 +0,0 @@
1
- import type { DNSResolver, ResolveDnsLinkOptions } from '../index.js';
2
- export interface Question {
3
- name: string;
4
- type: number;
5
- }
6
- export interface Answer {
7
- name: string;
8
- type: number;
9
- TTL: number;
10
- data: string;
11
- }
12
- export interface DNSResponse {
13
- Status: number;
14
- TC: boolean;
15
- RD: boolean;
16
- RA: boolean;
17
- AD: boolean;
18
- CD: boolean;
19
- Question: Question[];
20
- Answer?: Answer[];
21
- }
22
- export declare const ipfsPathForAnswer: (answer: Answer) => string;
23
- export declare const ipfsPathAndAnswer: (domain: string, response: DNSResponse) => {
24
- ipfsPath: string;
25
- answer: Answer;
26
- };
27
- export declare const findDNSLinkAnswer: (domain: string, response: DNSResponse) => Answer;
28
- export declare const MAX_RECURSIVE_DEPTH = 32;
29
- export declare const recursiveResolveDnslink: (domain: string, depth: number, resolve: DNSResolver, options?: ResolveDnsLinkOptions) => Promise<string>;
30
- interface DnsResolver {
31
- resolveTxt(domain: string): Promise<string[][]>;
32
- }
33
- export declare const resolveFn: (resolver: DnsResolver, domain: string) => Promise<string>;
34
- export {};
35
- //# sourceMappingURL=dns.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dns.d.ts","sourceRoot":"","sources":["../../../src/utils/dns.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAErE,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,EAAE,EAAE,OAAO,CAAA;IACX,EAAE,EAAE,OAAO,CAAA;IACX,EAAE,EAAE,OAAO,CAAA;IACX,EAAE,EAAE,OAAO,CAAA;IACX,EAAE,EAAE,OAAO,CAAA;IACX,QAAQ,EAAE,QAAQ,EAAE,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,eAAO,MAAM,iBAAiB,WAAY,MAAM,KAAG,MAYlD,CAAA;AAED,eAAO,MAAM,iBAAiB,WAAY,MAAM,YAAY,WAAW;cAAe,MAAM;YAAU,MAAM;CAO3G,CAAA;AAED,eAAO,MAAM,iBAAiB,WAAY,MAAM,YAAY,WAAW,KAAG,MAQzE,CAAA;AAED,eAAO,MAAM,mBAAmB,KAAK,CAAA;A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