@helia/ipns 6.0.1 → 7.0.0-ecf5394

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 +5 -0
  3. package/dist/src/dnslink.d.ts.map +1 -0
  4. package/dist/src/dnslink.js +123 -0
  5. package/dist/src/dnslink.js.map +1 -0
  6. package/dist/src/index.d.ts +18 -22
  7. package/dist/src/index.d.ts.map +1 -1
  8. package/dist/src/index.js +10 -9
  9. package/dist/src/index.js.map +1 -1
  10. package/package.json +3 -6
  11. package/src/dnslink.ts +142 -0
  12. package/src/index.ts +30 -38
  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
@@ -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,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,C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AAI,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,GAAG,SAAS,CAAC,MAAM,CAAC;YAChC,IA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AE,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,GAAG,GAAG,EAAE,GAAG,IAAI,CAAA;AAEr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AAA;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;AAErC,eAAO,MAAM,uBAAuB,WAAkB,MAAM,SAAS,MAAM,WAAW,WAAW,YAAW,qBAAqB,KAAQ,QAAQ,MAAM,CA0CtJ,CAAA;AAED,UAAU,WAAW;IACnB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;CAChD;AAGD,eAAO,MAAM,SAAS,aAAoB,WAAW,UAAU,MAAM,KAAG,QAAQ,MAAM,CAerF,CAAA"}
@@ -1,80 +0,0 @@
1
- import { CodeError } from '@libp2p/interface';
2
- import { CID } from 'multiformats/cid';
3
- export const ipfsPathForAnswer = (answer) => {
4
- let data = answer.data;
5
- if (data.startsWith('"')) {
6
- data = data.substring(1);
7
- }
8
- if (data.endsWith('"')) {
9
- data = data.substring(0, data.length - 1);
10
- }
11
- return data.replace('dnslink=', '');
12
- };
13
- export const ipfsPathAndAnswer = (domain, response) => {
14
- const answer = findDNSLinkAnswer(domain, response);
15
- return {
16
- ipfsPath: ipfsPathForAnswer(answer),
17
- answer
18
- };
19
- };
20
- export const findDNSLinkAnswer = (domain, response) => {
21
- const answer = response.Answer?.filter(a => a.data.includes('dnslink=/ipfs') || a.data.includes('dnslink=/ipns')).pop();
22
- if (answer == null) {
23
- throw new CodeError(`No dnslink records found for domain: ${domain}`, 'ERR_DNSLINK_NOT_FOUND');
24
- }
25
- return answer;
26
- };
27
- export const MAX_RECURSIVE_DEPTH = 32;
28
- export const recursiveResolveDnslink = async (domain, depth, resolve, options = {}) => {
29
- if (depth === 0) {
30
- throw new Error('recursion limit exceeded');
31
- }
32
- let dnslinkRecord;
33
- try {
34
- dnslinkRecord = await resolve(domain, options);
35
- }
36
- catch (err) {
37
- // If the code is not ENOTFOUND or ERR_DNSLINK_NOT_FOUND or ENODATA then throw the error
38
- if (err.code !== 'ENOTFOUND' && err.code !== 'ERR_DNSLINK_NOT_FOUND' && err.code !== 'ENODATA') {
39
- throw err;
40
- }
41
- if (domain.startsWith('_dnslink.')) {
42
- // The supplied domain contains a _dnslink component
43
- // Check the non-_dnslink domain
44
- domain = domain.replace('_dnslink.', '');
45
- }
46
- else {
47
- // Check the _dnslink subdomain
48
- domain = `_dnslink.${domain}`;
49
- }
50
- // If this throws then we propagate the error
51
- dnslinkRecord = await resolve(domain, options);
52
- }
53
- const result = dnslinkRecord.replace('dnslink=', '');
54
- // result is now a `/ipfs/<cid>` or `/ipns/<cid>` string
55
- const domainOrCID = result.split('/')[2]; // e.g. ["", "ipfs", "<cid>"]
56
- try {
57
- CID.parse(domainOrCID);
58
- // if the result is a CID, or depth is 1, we've reached the end of the recursion
59
- // if depth is 1, another recursive call will be made, but it would throw.
60
- // we could return if depth is 1 and allow users to handle, but that may be a breaking change
61
- return result;
62
- }
63
- catch { }
64
- return recursiveResolveDnslink(domainOrCID, depth - 1, resolve, options);
65
- };
66
- const DNSLINK_REGEX = /^dnslink=.+$/;
67
- export const resolveFn = async (resolver, domain) => {
68
- const records = await resolver.resolveTxt(domain);
69
- const dnslinkRecords = records.flat()
70
- .filter(record => DNSLINK_REGEX.test(record));
71
- // we now have dns text entries as an array of strings
72
- // only records passing the DNSLINK_REGEX text are included
73
- // TODO: support multiple dnslink records
74
- const dnslinkRecord = dnslinkRecords[0];
75
- if (dnslinkRecord == null) {
76
- throw new CodeError(`No dnslink records found for domain: ${domain}`, 'ERR_DNSLINK_NOT_FOUND');
77
- }
78
- return dnslinkRecord;
79
- };
80
- //# sourceMappingURL=dns.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dns.js","sourceRoot":"","sources":["../../../src/utils/dns.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AA0BtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAU,EAAE;IAC1D,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;IAEtB,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,C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CAAA;AAMD,MAAM,aAAa,GAAG,cAAc,CAAA;AACpC,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,QAAqB,EAAE,MAAc,EAAmB,EAAE;IACxF,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IACjD,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,EAAE;SAClC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;IAE/C,sDAAsD;IACtD,2DAA2D;IAC3D,yCAAyC;IACzC,MAAM,aAAa,GAAG,cAAc,CAAC,CAAC,CAAC,CAAA;IAEvC,IAAI,aAAa,IAAI,IAAI,EAAE,CAAC;QAC1B,MAAM,IAAI,SAAS,CAAC,wCAAwC,MAAM,EAAE,EAAE,uBAAuB,CAAC,CAAA;IAChG,CAAC;IAED,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA"}
@@ -1,15 +0,0 @@
1
- /**
2
- * Time Aware Least Recent Used Cache
3
- *
4
- * @see https://arxiv.org/pdf/1801.00390
5
- */
6
- export declare class TLRU<T> {
7
- private readonly lru;
8
- constructor(maxSize: number);
9
- get(key: string): T | undefined;
10
- set(key: string, value: T, ttl: number): void;
11
- has(key: string): boolean;
12
- remove(key: string): void;
13
- clear(): void;
14
- }
15
- //# sourceMappingURL=tlru.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tlru.d.ts","sourceRoot":"","sources":["../../../src/utils/tlru.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,qBAAa,IAAI,CAAC,CAAC;IACjB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAA4B;gBAEnC,OAAO,EAAE,MAAM;IAI5B,GAAG,CAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAgBhC,GAAG,CAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAI9C,GAAG,CAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAU1B,MAAM,CAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAI1B,KAAK,IAAK,IAAI;CAGf"}
@@ -1,40 +0,0 @@
1
- import hashlru from 'hashlru';
2
- /**
3
- * Time Aware Least Recent Used Cache
4
- *
5
- * @see https://arxiv.org/pdf/1801.00390
6
- */
7
- export class TLRU {
8
- lru;
9
- constructor(maxSize) {
10
- this.lru = hashlru(maxSize);
11
- }
12
- get(key) {
13
- const value = this.lru.get(key);
14
- if (value != null) {
15
- if (value.expire != null && value.expire < Date.now()) {
16
- this.lru.remove(key);
17
- return undefined;
18
- }
19
- return value.value;
20
- }
21
- return undefined;
22
- }
23
- set(key, value, ttl) {
24
- this.lru.set(key, { value, expire: Date.now() + ttl });
25
- }
26
- has(key) {
27
- const value = this.get(key);
28
- if (value != null) {
29
- return true;
30
- }
31
- return false;
32
- }
33
- remove(key) {
34
- this.lru.remove(key);
35
- }
36
- clear() {
37
- this.lru.clear();
38
- }
39
- }
40
- //# sourceMappingURL=tlru.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tlru.js","sourceRoot":"","sources":["../../../src/utils/tlru.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAE7B;;;;GAIG;AACH,MAAM,OAAO,IAAI;IACE,GAAG,CAA4B;IAEhD,YAAa,OAAe;QAC1B,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7B,CAAC;IAED,GAAG,CAAE,GAAW;QACd,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAE/B,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;gBACtD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;gBAEpB,OAAO,SAAS,CAAA;YAClB,CAAC;YAED,OAAO,KAAK,CAAC,KAAK,CAAA;QACpB,CAAC;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,GAAG,CAAE,GAAW,EAAE,KAAQ,EAAE,GAAW;QACrC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC,CAAA;IACxD,CAAC;IAED,GAAG,CAAE,GAAW;QACd,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAE3B,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,CAAE,GAAW;QACjB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IAClB,CAAC;CACF"}
@@ -1,44 +0,0 @@
1
- {
2
- "dnsJsonOverHttps": "https://ipfs.github.io/helia/functions/_helia_ipns.dns_resolvers.dnsJsonOverHttps.html",
3
- "dnsOverHttps": "https://ipfs.github.io/helia/functions/_helia_ipns.dns_resolvers.dnsOverHttps.html",
4
- "DNSResolver": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.DNSResolver.html",
5
- ".:DNSResolver": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.DNSResolver.html",
6
- "IPNS": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNS.html",
7
- ".:IPNS": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNS.html",
8
- "IPNSComponents": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNSComponents.html",
9
- ".:IPNSComponents": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNSComponents.html",
10
- "IPNSOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNSOptions.html",
11
- ".:IPNSOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNSOptions.html",
12
- "PublishOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.PublishOptions.html",
13
- ".:PublishOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.PublishOptions.html",
14
- "RepublishOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.RepublishOptions.html",
15
- ".:RepublishOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.RepublishOptions.html",
16
- "ResolveDNSOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveDNSOptions.html",
17
- ".:ResolveDNSOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveDNSOptions.html",
18
- "ResolveDnsLinkOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveDnsLinkOptions.html",
19
- ".:ResolveDnsLinkOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveDnsLinkOptions.html",
20
- "ResolveOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveOptions.html",
21
- ".:ResolveOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveOptions.html",
22
- "ResolveResult": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveResult.html",
23
- ".:ResolveResult": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveResult.html",
24
- "PublishProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.PublishProgressEvents.html",
25
- ".:PublishProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.PublishProgressEvents.html",
26
- "RepublishProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.RepublishProgressEvents.html",
27
- ".:RepublishProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.RepublishProgressEvents.html",
28
- "ResolveDnsLinkProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.ResolveDnsLinkProgressEvents.html",
29
- ".:ResolveDnsLinkProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.ResolveDnsLinkProgressEvents.html",
30
- "ResolveProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.ResolveProgressEvents.html",
31
- ".:ResolveProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.ResolveProgressEvents.html",
32
- "ipns": "https://ipfs.github.io/helia/functions/_helia_ipns.index.ipns-1.html",
33
- ".:ipns": "https://ipfs.github.io/helia/functions/_helia_ipns.index.ipns-1.html",
34
- "GetOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.routing.GetOptions.html",
35
- "./routing:GetOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.routing.GetOptions.html",
36
- "IPNSRouting": "https://ipfs.github.io/helia/interfaces/_helia_ipns.routing.IPNSRouting.html",
37
- "./routing:IPNSRouting": "https://ipfs.github.io/helia/interfaces/_helia_ipns.routing.IPNSRouting.html",
38
- "PutOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.routing.PutOptions.html",
39
- "./routing:PutOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.routing.PutOptions.html",
40
- "IPNSRoutingEvents": "https://ipfs.github.io/helia/types/_helia_ipns.routing.IPNSRoutingEvents.html",
41
- "./routing:IPNSRoutingEvents": "https://ipfs.github.io/helia/types/_helia_ipns.routing.IPNSRoutingEvents.html",
42
- "helia": "https://ipfs.github.io/helia/functions/_helia_ipns.routing.helia.html",
43
- "pubsub": "https://ipfs.github.io/helia/functions/_helia_ipns.routing.pubsub.html"
44
- }