@helia/ipns 2.0.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +110 -0
- package/dist/index.min.js +24 -24
- package/dist/src/dns-resolvers/default.d.ts +3 -0
- package/dist/src/dns-resolvers/default.d.ts.map +1 -0
- package/dist/src/dns-resolvers/default.js +8 -0
- package/dist/src/dns-resolvers/default.js.map +1 -0
- package/dist/src/dns-resolvers/dns-json-over-https.d.ts +18 -0
- package/dist/src/dns-resolvers/dns-json-over-https.d.ts.map +1 -0
- package/dist/src/dns-resolvers/dns-json-over-https.js +72 -0
- package/dist/src/dns-resolvers/dns-json-over-https.js.map +1 -0
- package/dist/src/dns-resolvers/dns-over-https.d.ts +16 -0
- package/dist/src/dns-resolvers/dns-over-https.d.ts.map +1 -0
- package/dist/src/dns-resolvers/dns-over-https.js +123 -0
- package/dist/src/dns-resolvers/dns-over-https.js.map +1 -0
- package/dist/src/dns-resolvers/index.d.ts +3 -0
- package/dist/src/dns-resolvers/index.d.ts.map +1 -0
- package/dist/src/dns-resolvers/index.js +3 -0
- package/dist/src/dns-resolvers/index.js.map +1 -0
- package/dist/src/dns-resolvers/resolver.browser.d.ts +4 -0
- package/dist/src/dns-resolvers/resolver.browser.d.ts.map +1 -0
- package/dist/src/dns-resolvers/resolver.browser.js +39 -0
- package/dist/src/dns-resolvers/resolver.browser.js.map +1 -0
- package/dist/src/dns-resolvers/resolver.d.ts +4 -0
- package/dist/src/dns-resolvers/resolver.d.ts.map +1 -0
- package/dist/src/dns-resolvers/resolver.js +21 -0
- package/dist/src/dns-resolvers/resolver.js.map +1 -0
- package/dist/src/index.d.ts +102 -9
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +82 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/routing/dht.js.map +1 -1
- package/dist/src/routing/local-store.js.map +1 -1
- package/dist/src/routing/pubsub.js.map +1 -1
- package/dist/src/utils/dns.d.ts +35 -0
- package/dist/src/utils/dns.d.ts.map +1 -0
- package/dist/src/utils/dns.js +79 -0
- package/dist/src/utils/dns.js.map +1 -0
- package/dist/src/utils/tlru.js.map +1 -1
- package/dist/typedoc-urls.json +8 -0
- package/package.json +13 -4
- package/src/dns-resolvers/default.ts +9 -0
- package/src/dns-resolvers/dns-json-over-https.ts +90 -0
- package/src/dns-resolvers/dns-over-https.ts +146 -0
- package/src/dns-resolvers/index.ts +2 -0
- package/src/dns-resolvers/resolver.browser.ts +50 -0
- package/src/dns-resolvers/resolver.ts +25 -0
- package/src/index.ts +121 -13
- package/src/utils/dns.ts +126 -0
- package/dist/src/utils/resolve-dns-link.browser.d.ts +0 -6
- package/dist/src/utils/resolve-dns-link.browser.d.ts.map +0 -1
- package/dist/src/utils/resolve-dns-link.browser.js +0 -46
- package/dist/src/utils/resolve-dns-link.browser.js.map +0 -1
- package/dist/src/utils/resolve-dns-link.d.ts +0 -3
- package/dist/src/utils/resolve-dns-link.d.ts.map +0 -1
- package/dist/src/utils/resolve-dns-link.js +0 -54
- package/dist/src/utils/resolve-dns-link.js.map +0 -1
- package/src/utils/resolve-dns-link.browser.ts +0 -61
- package/src/utils/resolve-dns-link.ts +0 -65
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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AAM;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"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,123 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dns-over-https.js","sourceRoot":"","sources":["../../../src/dns-resolvers/dns-over-https.ts"],"names":[],"mappings":"AAAA,wBAAwB;AAExB,OAAO,EAAE,MA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|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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;AAErB,kDAAkD;AAClD,0CAA0C;AAC1C,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC,CAAA;AAEhD,MAAM,OAAO,GAAgB,KAAK,UAAU,OAAO,CAAE,MAAM,EAAE,OAAO,GAAG,EAAE;IACvE,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAA;IAC9C,kBAAkB;IAClB,IAA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KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,QAAA,MAAM,OAAO,EAAE,WAiBd,CAAA;AAED,eAAe,OAAO,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -5,16 +5,20 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
*
|
|
8
|
+
* With {@link IPNSRouting} routers:
|
|
9
|
+
*
|
|
8
10
|
* ```typescript
|
|
9
11
|
* import { createHelia } from 'helia'
|
|
10
12
|
* import { dht, pubsub } from '@helia/ipns/routing'
|
|
11
13
|
* import { unixfs } from '@helia/unixfs'
|
|
12
14
|
*
|
|
13
15
|
* const helia = await createHelia()
|
|
14
|
-
* const name = ipns(helia,
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* const name = ipns(helia, {
|
|
17
|
+
* routers: [
|
|
18
|
+
* dht(helia),
|
|
19
|
+
* pubsub(helia)
|
|
20
|
+
* ]
|
|
21
|
+
* })
|
|
18
22
|
*
|
|
19
23
|
* // create a public key to publish as an IPNS name
|
|
20
24
|
* const keyInfo = await helia.libp2p.keychain.createKey('my-key')
|
|
@@ -33,18 +37,82 @@
|
|
|
33
37
|
*
|
|
34
38
|
* @example
|
|
35
39
|
*
|
|
40
|
+
* With default {@link DNSResolver} resolvers:
|
|
41
|
+
*
|
|
36
42
|
* ```typescript
|
|
37
|
-
*
|
|
38
|
-
*
|
|
43
|
+
* import { createHelia } from 'helia'
|
|
44
|
+
* import { dht, pubsub } from '@helia/ipns/routing'
|
|
45
|
+
* import { unixfs } from '@helia/unixfs'
|
|
46
|
+
*
|
|
47
|
+
* const helia = await createHelia()
|
|
48
|
+
* const name = ipns(helia, {
|
|
49
|
+
* resolvers: [
|
|
50
|
+
* dnsOverHttps('https://private-dns-server.me/dns-query'),
|
|
51
|
+
* ]
|
|
52
|
+
* })
|
|
53
|
+
*
|
|
54
|
+
* const cid = name.resolveDns('some-domain-with-dnslink-entry.com')
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
*
|
|
59
|
+
* Calling `resolveDns` with the `@helia/ipns` instance:
|
|
60
|
+
*
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // resolve a CID from a TXT record in a DNS zone file, using the default
|
|
63
|
+
* // resolver for the current platform eg:
|
|
64
|
+
* // > dig _dnslink.ipfs.io TXT
|
|
65
|
+
* // ;; ANSWER SECTION:
|
|
66
|
+
* // _dnslink.ipfs.io. 60 IN TXT "dnslink=/ipns/website.ipfs.io"
|
|
67
|
+
* // > dig _dnslink.website.ipfs.io TXT
|
|
39
68
|
* // ;; ANSWER SECTION:
|
|
40
|
-
* // ipfs.io.
|
|
69
|
+
* // _dnslink.website.ipfs.io. 60 IN TXT "dnslink=/ipfs/QmWebsite"
|
|
41
70
|
*
|
|
42
71
|
* const cid = name.resolveDns('ipfs.io')
|
|
72
|
+
*
|
|
73
|
+
* console.info(cid)
|
|
74
|
+
* // QmWebsite
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
*
|
|
79
|
+
* This example uses the Mozilla provided RFC 1035 DNS over HTTPS service. This
|
|
80
|
+
* uses binary DNS records so requires extra dependencies to process the
|
|
81
|
+
* response which can increase browser bundle sizes.
|
|
82
|
+
*
|
|
83
|
+
* If this is a concern, use the DNS-JSON-Over-HTTPS resolver instead.
|
|
84
|
+
*
|
|
85
|
+
* ```typescript
|
|
86
|
+
* // use DNS-Over-HTTPS
|
|
87
|
+
* import { dnsOverHttps } from '@helia/ipns/dns-resolvers'
|
|
88
|
+
*
|
|
89
|
+
* const cid = name.resolveDns('ipfs.io', {
|
|
90
|
+
* resolvers: [
|
|
91
|
+
* dnsOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
|
|
92
|
+
* ]
|
|
93
|
+
* })
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
*
|
|
98
|
+
* DNS-JSON-Over-HTTPS resolvers use the RFC 8427 `application/dns-json` and can
|
|
99
|
+
* result in a smaller browser bundle due to the response being plain JSON.
|
|
100
|
+
*
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // use DNS-JSON-Over-HTTPS
|
|
103
|
+
* import { dnsJsonOverHttps } from '@helia/ipns/dns-resolvers'
|
|
104
|
+
*
|
|
105
|
+
* const cid = name.resolveDns('ipfs.io', {
|
|
106
|
+
* resolvers: [
|
|
107
|
+
* dnsJsonOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
|
|
108
|
+
* ]
|
|
109
|
+
* })
|
|
43
110
|
* ```
|
|
44
111
|
*/
|
|
45
112
|
import { ipnsValidator } from 'ipns/validator';
|
|
46
113
|
import { CID } from 'multiformats/cid';
|
|
47
114
|
import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js';
|
|
115
|
+
import type { DNSResponse } from './utils/dns.js';
|
|
48
116
|
import type { AbortOptions } from '@libp2p/interface';
|
|
49
117
|
import type { PeerId } from '@libp2p/interface/peer-id';
|
|
50
118
|
import type { Datastore } from 'interface-datastore';
|
|
@@ -56,6 +124,7 @@ export type RepublishProgressEvents = ProgressEvent<'ipns:republish:start', unkn
|
|
|
56
124
|
record: IPNSRecord;
|
|
57
125
|
err: Error;
|
|
58
126
|
}>;
|
|
127
|
+
export type ResolveDnsLinkProgressEvents = ProgressEvent<'dnslink:cache', string> | ProgressEvent<'dnslink:query', string> | ProgressEvent<'dnslink:answer', DNSResponse>;
|
|
59
128
|
export interface PublishOptions extends AbortOptions, ProgressOptions<PublishProgressEvents | IPNSRoutingEvents> {
|
|
60
129
|
/**
|
|
61
130
|
* Time duration of the record in ms (default: 24hrs)
|
|
@@ -77,11 +146,31 @@ export interface ResolveOptions extends AbortOptions, ProgressOptions<ResolvePro
|
|
|
77
146
|
*/
|
|
78
147
|
offline?: boolean;
|
|
79
148
|
}
|
|
80
|
-
export interface
|
|
149
|
+
export interface ResolveDnsLinkOptions extends AbortOptions, ProgressOptions<ResolveDnsLinkProgressEvents> {
|
|
150
|
+
/**
|
|
151
|
+
* Do not use cached DNS entries (default: false)
|
|
152
|
+
*/
|
|
153
|
+
nocache?: boolean;
|
|
154
|
+
}
|
|
155
|
+
export interface DNSResolver {
|
|
156
|
+
(domain: string, options?: ResolveDnsLinkOptions): Promise<string>;
|
|
157
|
+
}
|
|
158
|
+
export interface ResolveDNSOptions extends AbortOptions, ProgressOptions<ResolveProgressEvents | IPNSRoutingEvents | ResolveDnsLinkProgressEvents> {
|
|
159
|
+
/**
|
|
160
|
+
* Do not query the network for the IPNS record (default: false)
|
|
161
|
+
*/
|
|
162
|
+
offline?: boolean;
|
|
81
163
|
/**
|
|
82
164
|
* Do not use cached DNS entries (default: false)
|
|
83
165
|
*/
|
|
84
166
|
nocache?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* These resolvers will be used to resolve the dnslink entries, if unspecified node will
|
|
169
|
+
* fall back to the `dns` module and browsers fall back to querying google/cloudflare DoH
|
|
170
|
+
*
|
|
171
|
+
* @see https://github.com/ipfs/helia-ipns/pull/55#discussion_r1270096881
|
|
172
|
+
*/
|
|
173
|
+
resolvers?: DNSResolver[];
|
|
85
174
|
}
|
|
86
175
|
export interface RepublishOptions extends AbortOptions, ProgressOptions<RepublishProgressEvents | IPNSRoutingEvents> {
|
|
87
176
|
/**
|
|
@@ -114,7 +203,11 @@ export type { IPNSRouting } from './routing/index.js';
|
|
|
114
203
|
export interface IPNSComponents {
|
|
115
204
|
datastore: Datastore;
|
|
116
205
|
}
|
|
117
|
-
export
|
|
206
|
+
export interface IPNSOptions {
|
|
207
|
+
routers?: IPNSRouting[];
|
|
208
|
+
resolvers?: DNSResolver[];
|
|
209
|
+
}
|
|
210
|
+
export declare function ipns(components: IPNSComponents, { routers, resolvers }: IPNSOptions): IPNS;
|
|
118
211
|
export { ipnsValidator };
|
|
119
212
|
export { ipnsSelector } from 'ipns/selector';
|
|
120
213
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8GG;AAOH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAItC,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,U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