@helia/ipns 6.0.1 → 7.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/dist/index.min.js +4 -4
- package/dist/src/dnslink.d.ts +5 -0
- package/dist/src/dnslink.d.ts.map +1 -0
- package/dist/src/dnslink.js +123 -0
- package/dist/src/dnslink.js.map +1 -0
- package/dist/src/index.d.ts +18 -22
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +10 -9
- package/dist/src/index.js.map +1 -1
- package/dist/typedoc-urls.json +4 -10
- package/package.json +3 -6
- package/src/dnslink.ts +142 -0
- package/src/index.ts +30 -38
- package/dist/src/dns-resolvers/default.d.ts +0 -3
- package/dist/src/dns-resolvers/default.d.ts.map +0 -1
- package/dist/src/dns-resolvers/default.js +0 -8
- package/dist/src/dns-resolvers/default.js.map +0 -1
- package/dist/src/dns-resolvers/dns-json-over-https.d.ts +0 -18
- package/dist/src/dns-resolvers/dns-json-over-https.d.ts.map +0 -1
- package/dist/src/dns-resolvers/dns-json-over-https.js +0 -72
- package/dist/src/dns-resolvers/dns-json-over-https.js.map +0 -1
- package/dist/src/dns-resolvers/dns-over-https.d.ts +0 -16
- package/dist/src/dns-resolvers/dns-over-https.d.ts.map +0 -1
- package/dist/src/dns-resolvers/dns-over-https.js +0 -123
- package/dist/src/dns-resolvers/dns-over-https.js.map +0 -1
- package/dist/src/dns-resolvers/index.d.ts +0 -3
- package/dist/src/dns-resolvers/index.d.ts.map +0 -1
- package/dist/src/dns-resolvers/index.js +0 -3
- package/dist/src/dns-resolvers/index.js.map +0 -1
- package/dist/src/dns-resolvers/resolver.browser.d.ts +0 -4
- package/dist/src/dns-resolvers/resolver.browser.d.ts.map +0 -1
- package/dist/src/dns-resolvers/resolver.browser.js +0 -39
- package/dist/src/dns-resolvers/resolver.browser.js.map +0 -1
- package/dist/src/dns-resolvers/resolver.d.ts +0 -4
- package/dist/src/dns-resolvers/resolver.d.ts.map +0 -1
- package/dist/src/dns-resolvers/resolver.js +0 -21
- package/dist/src/dns-resolvers/resolver.js.map +0 -1
- package/dist/src/utils/dns.d.ts +0 -35
- package/dist/src/utils/dns.d.ts.map +0 -1
- package/dist/src/utils/dns.js +0 -80
- package/dist/src/utils/dns.js.map +0 -1
- package/dist/src/utils/tlru.d.ts +0 -15
- package/dist/src/utils/tlru.d.ts.map +0 -1
- package/dist/src/utils/tlru.js +0 -40
- package/dist/src/utils/tlru.js.map +0 -1
- package/src/dns-resolvers/default.ts +0 -9
- package/src/dns-resolvers/dns-json-over-https.ts +0 -90
- package/src/dns-resolvers/dns-over-https.ts +0 -146
- package/src/dns-resolvers/index.ts +0 -2
- package/src/dns-resolvers/resolver.browser.ts +0 -50
- package/src/dns-resolvers/resolver.ts +0 -25
- package/src/utils/dns.ts +0 -127
- package/src/utils/tlru.ts +0 -52
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Logger } from '@libp2p/interface';
|
|
2
|
+
import type { ResolveDNSLinkOptions } from './index.js';
|
|
3
|
+
import type { DNS } from '@multiformats/dns';
|
|
4
|
+
export declare function resolveDNSLink(domain: string, dns: DNS, log: Logger, options?: ResolveDNSLinkOptions): Promise<string>;
|
|
5
|
+
//# sourceMappingURL=dnslink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dnslink.d.ts","sourceRoot":"","sources":["../../src/dnslink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAI1D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAsI5C,wBAAsB,cAAc,CAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,MAAM,CAAC,CAEjI"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { CodeError } from '@libp2p/interface';
|
|
2
|
+
import { peerIdFromString } from '@libp2p/peer-id';
|
|
3
|
+
import { RecordType } from '@multiformats/dns';
|
|
4
|
+
import { CID } from 'multiformats/cid';
|
|
5
|
+
const MAX_RECURSIVE_DEPTH = 32;
|
|
6
|
+
async function recursiveResolveDnslink(domain, depth, dns, log, options = {}) {
|
|
7
|
+
if (depth === 0) {
|
|
8
|
+
throw new Error('recursion limit exceeded');
|
|
9
|
+
}
|
|
10
|
+
log('query %s for TXT and CNAME records', domain);
|
|
11
|
+
const txtRecordsResponse = await dns.query(domain, {
|
|
12
|
+
...options,
|
|
13
|
+
types: [
|
|
14
|
+
RecordType.TXT
|
|
15
|
+
]
|
|
16
|
+
});
|
|
17
|
+
// sort the TXT records to ensure deterministic processing
|
|
18
|
+
const txtRecords = txtRecordsResponse.Answer
|
|
19
|
+
.sort((a, b) => a.data.localeCompare(b.data));
|
|
20
|
+
log('found %d TXT records for %s', txtRecords.length, domain);
|
|
21
|
+
for (const answer of txtRecords) {
|
|
22
|
+
try {
|
|
23
|
+
let result = answer.data;
|
|
24
|
+
// strip leading and trailing " characters
|
|
25
|
+
if (result.startsWith('"') && result.endsWith('"')) {
|
|
26
|
+
result = result.substring(1, result.length - 1);
|
|
27
|
+
}
|
|
28
|
+
if (!result.startsWith('dnslink=')) {
|
|
29
|
+
// invalid record?
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
log('%s TXT %s', answer.name, result);
|
|
33
|
+
result = result.replace('dnslink=', '');
|
|
34
|
+
// result is now a `/ipfs/<cid>` or `/ipns/<cid>` string
|
|
35
|
+
const [, protocol, domainOrCID, ...rest] = result.split('/'); // e.g. ["", "ipfs", "<cid>"]
|
|
36
|
+
if (protocol === 'ipfs') {
|
|
37
|
+
try {
|
|
38
|
+
const cid = CID.parse(domainOrCID);
|
|
39
|
+
// if the result is a CID, we've reached the end of the recursion
|
|
40
|
+
return `/ipfs/${cid}${rest.length > 0 ? `/${rest.join('/')}` : ''}`;
|
|
41
|
+
}
|
|
42
|
+
catch { }
|
|
43
|
+
}
|
|
44
|
+
else if (protocol === 'ipns') {
|
|
45
|
+
try {
|
|
46
|
+
const peerId = peerIdFromString(domainOrCID);
|
|
47
|
+
// if the result is a PeerId, we've reached the end of the recursion
|
|
48
|
+
return `/ipns/${peerId}${rest.length > 0 ? `/${rest.join('/')}` : ''}`;
|
|
49
|
+
}
|
|
50
|
+
catch { }
|
|
51
|
+
// if the result was another IPNS domain, try to follow it
|
|
52
|
+
return await recursiveResolveDomain(domainOrCID, depth - 1, dns, log, options);
|
|
53
|
+
}
|
|
54
|
+
else if (protocol === 'dnslink') {
|
|
55
|
+
// if the result was another DNSLink domain, try to follow it
|
|
56
|
+
return await recursiveResolveDomain(domainOrCID, depth - 1, dns, log, options);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
log('unknown protocol "%s" in DNSLink record for domain: %s', protocol, domain);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
log.error('could not parse DNS link record for domain %s, %s', domain, answer.data, err);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// no dnslink records found, try CNAMEs
|
|
68
|
+
log('no DNSLink records found for %s, falling back to CNAME', domain);
|
|
69
|
+
const cnameRecordsResponse = await dns.query(domain, {
|
|
70
|
+
...options,
|
|
71
|
+
types: [
|
|
72
|
+
RecordType.CNAME
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
// sort the CNAME records to ensure deterministic processing
|
|
76
|
+
const cnameRecords = cnameRecordsResponse.Answer
|
|
77
|
+
.sort((a, b) => a.data.localeCompare(b.data));
|
|
78
|
+
log('found %d CNAME records for %s', cnameRecords.length, domain);
|
|
79
|
+
for (const cname of cnameRecords) {
|
|
80
|
+
try {
|
|
81
|
+
return await recursiveResolveDomain(cname.data, depth - 1, dns, log, options);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
log.error('domain %s cname %s had no DNSLink records', domain, cname.data, err);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
throw new CodeError(`No DNSLink records found for domain: ${domain}`, 'ERR_DNSLINK_NOT_FOUND');
|
|
88
|
+
}
|
|
89
|
+
async function recursiveResolveDomain(domain, depth, dns, log, options = {}) {
|
|
90
|
+
if (depth === 0) {
|
|
91
|
+
throw new Error('recursion limit exceeded');
|
|
92
|
+
}
|
|
93
|
+
// the DNSLink spec says records MUST be stored on the `_dnslink.` subdomain
|
|
94
|
+
// so start looking for records there, we will fall back to the bare domain
|
|
95
|
+
// if none are found
|
|
96
|
+
if (!domain.startsWith('_dnslink.')) {
|
|
97
|
+
domain = `_dnslink.${domain}`;
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
return await recursiveResolveDnslink(domain, depth, dns, log, options);
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
// If the code is not ENOTFOUND or ERR_DNSLINK_NOT_FOUND or ENODATA then throw the error
|
|
104
|
+
if (err.code !== 'ENOTFOUND' && err.code !== 'ERR_DNSLINK_NOT_FOUND' && err.code !== 'ENODATA') {
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
if (domain.startsWith('_dnslink.')) {
|
|
108
|
+
// The supplied domain contains a _dnslink component
|
|
109
|
+
// Check the non-_dnslink domain
|
|
110
|
+
domain = domain.replace('_dnslink.', '');
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// Check the _dnslink subdomain
|
|
114
|
+
domain = `_dnslink.${domain}`;
|
|
115
|
+
}
|
|
116
|
+
// If this throws then we propagate the error
|
|
117
|
+
return await recursiveResolveDnslink(domain, depth, dns, log, options);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export async function resolveDNSLink(domain, dns, log, options = {}) {
|
|
121
|
+
return recursiveResolveDomain(domain, options.maxRecursiveDepth ?? MAX_RECURSIVE_DEP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AM,CAAC;YACN,+BAA+B;YAC/B,MAAM,GAAG,YAAY,MAAM,EAAE,CAAA;QAC/B,CAAC;QAED,6CAA6C;QAC7C,OAAO,MAAM,uBAAuB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;IACxE,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAE,MAAc,EAAE,GAAQ,EAAE,GAAW,EAAE,UAAiC,EAAE;IAC9G,OAAO,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,iBAAiB,IAAI,mBAAmB,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;AAC5G,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -229,9 +229,9 @@
|
|
|
229
229
|
import { ipnsValidator } from 'ipns/validator';
|
|
230
230
|
import { CID } from 'multiformats/cid';
|
|
231
231
|
import type { IPNSRouting, IPNSRoutingEvents } from './routing/index.js';
|
|
232
|
-
import type { DNSResponse } from './utils/dns.js';
|
|
233
232
|
import type { Routing } from '@helia/interface';
|
|
234
|
-
import type { AbortOptions, PeerId } from '@libp2p/interface';
|
|
233
|
+
import type { AbortOptions, ComponentLogger, PeerId } from '@libp2p/interface';
|
|
234
|
+
import type { DNS, ResolveDnsProgressEvents } from '@multiformats/dns';
|
|
235
235
|
import type { Datastore } from 'interface-datastore';
|
|
236
236
|
import type { IPNSRecord } from 'ipns';
|
|
237
237
|
import type { ProgressEvent, ProgressOptions } from 'progress-events';
|
|
@@ -241,7 +241,7 @@ export type RepublishProgressEvents = ProgressEvent<'ipns:republish:start', unkn
|
|
|
241
241
|
record: IPNSRecord;
|
|
242
242
|
err: Error;
|
|
243
243
|
}>;
|
|
244
|
-
export type
|
|
244
|
+
export type ResolveDNSLinkProgressEvents = ResolveProgressEvents | IPNSRoutingEvents | ResolveDnsProgressEvents;
|
|
245
245
|
export interface PublishOptions extends AbortOptions, ProgressOptions<PublishProgressEvents | IPNSRoutingEvents> {
|
|
246
246
|
/**
|
|
247
247
|
* Time duration of the record in ms (default: 24hrs)
|
|
@@ -263,31 +263,26 @@ export interface ResolveOptions extends AbortOptions, ProgressOptions<ResolvePro
|
|
|
263
263
|
*/
|
|
264
264
|
offline?: boolean;
|
|
265
265
|
}
|
|
266
|
-
export interface
|
|
266
|
+
export interface ResolveDNSLinkOptions extends AbortOptions, ProgressOptions<ResolveDNSLinkProgressEvents> {
|
|
267
267
|
/**
|
|
268
|
-
* Do not
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
export interface DNSResolver {
|
|
273
|
-
(domain: string, options?: ResolveDnsLinkOptions): Promise<string>;
|
|
274
|
-
}
|
|
275
|
-
export interface ResolveDNSOptions extends AbortOptions, ProgressOptions<ResolveProgressEvents | IPNSRoutingEvents | ResolveDnsLinkProgressEvents> {
|
|
276
|
-
/**
|
|
277
|
-
* Do not query the network for the IPNS record (default: false)
|
|
268
|
+
* Do not query the network for the IPNS record
|
|
269
|
+
*
|
|
270
|
+
* @default false
|
|
278
271
|
*/
|
|
279
272
|
offline?: boolean;
|
|
280
273
|
/**
|
|
281
|
-
* Do not use cached DNS entries
|
|
274
|
+
* Do not use cached DNS entries
|
|
275
|
+
*
|
|
276
|
+
* @default false
|
|
282
277
|
*/
|
|
283
278
|
nocache?: boolean;
|
|
284
279
|
/**
|
|
285
|
-
*
|
|
286
|
-
*
|
|
280
|
+
* When resolving DNSLink records that resolve to other DNSLink records, limit
|
|
281
|
+
* how many times we will recursively resolve them.
|
|
287
282
|
*
|
|
288
|
-
* @
|
|
283
|
+
* @default 32
|
|
289
284
|
*/
|
|
290
|
-
|
|
285
|
+
maxRecursiveDepth?: number;
|
|
291
286
|
}
|
|
292
287
|
export interface RepublishOptions extends AbortOptions, ProgressOptions<RepublishProgressEvents | IPNSRoutingEvents> {
|
|
293
288
|
/**
|
|
@@ -314,7 +309,7 @@ export interface IPNS {
|
|
|
314
309
|
/**
|
|
315
310
|
* Resolve a CID from a dns-link style IPNS record
|
|
316
311
|
*/
|
|
317
|
-
|
|
312
|
+
resolveDNSLink(domain: string, options?: ResolveDNSLinkOptions): Promise<ResolveResult>;
|
|
318
313
|
/**
|
|
319
314
|
* Periodically republish all IPNS records found in the datastore
|
|
320
315
|
*/
|
|
@@ -324,12 +319,13 @@ export type { IPNSRouting } from './routing/index.js';
|
|
|
324
319
|
export interface IPNSComponents {
|
|
325
320
|
datastore: Datastore;
|
|
326
321
|
routing: Routing;
|
|
322
|
+
dns: DNS;
|
|
323
|
+
logger: ComponentLogger;
|
|
327
324
|
}
|
|
328
325
|
export interface IPNSOptions {
|
|
329
326
|
routers?: IPNSRouting[];
|
|
330
|
-
resolvers?: DNSResolver[];
|
|
331
327
|
}
|
|
332
|
-
export declare function ipns(components: IPNSComponents, { routers
|
|
328
|
+
export declare function ipns(components: IPNSComponents, { routers }?: IPNSOptions): IPNS;
|
|
333
329
|
export { ipnsValidator, type IPNSRoutingEvents };
|
|
334
330
|
export { ipnsSelector } from 'ipns/selector';
|
|
335
331
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmOG;AAOH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAKtC,OAAO,KAAK,EAAE,WAAW,EAAE,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AAM,WAAW,IAAI;IACnB;;;;OAIG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAEjG;;;OAGG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IAEtE;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IAEvF;;OAEG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAA;CAC5C;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAErD,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAA;IACpB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,eAAe,CAAA;CACxB;AA4LD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,WAAW,EAAE,CAAA;CACxB;AAED,wBAAgB,IAAI,CAAE,UAAU,EAAE,cAAc,EAAE,EAAE,OAAY,EAAE,GAAE,WAAgB,GAAG,IAAI,CAE1F;AAED,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -234,7 +234,7 @@ import { ipnsSelector } from 'ipns/selector';
|
|
|
234
234
|
import { ipnsValidator } from 'ipns/validator';
|
|
235
235
|
import { CID } from 'multiformats/cid';
|
|
236
236
|
import { CustomProgressEvent } from 'progress-events';
|
|
237
|
-
import {
|
|
237
|
+
import { resolveDNSLink } from './dnslink.js';
|
|
238
238
|
import { helia } from './routing/helia.js';
|
|
239
239
|
import { localStore } from './routing/local-store.js';
|
|
240
240
|
const log = logger('helia:ipns');
|
|
@@ -246,14 +246,16 @@ class DefaultIPNS {
|
|
|
246
246
|
routers;
|
|
247
247
|
localStore;
|
|
248
248
|
timeout;
|
|
249
|
-
|
|
250
|
-
|
|
249
|
+
dns;
|
|
250
|
+
log;
|
|
251
|
+
constructor(components, routers = []) {
|
|
251
252
|
this.routers = [
|
|
252
253
|
helia(components.routing),
|
|
253
254
|
...routers
|
|
254
255
|
];
|
|
255
256
|
this.localStore = localStore(components.datastore);
|
|
256
|
-
this.
|
|
257
|
+
this.dns = components.dns;
|
|
258
|
+
this.log = components.logger.forComponent('helia:ipns');
|
|
257
259
|
}
|
|
258
260
|
async publish(key, value, options = {}) {
|
|
259
261
|
try {
|
|
@@ -285,9 +287,8 @@ class DefaultIPNS {
|
|
|
285
287
|
const record = await this.#findIpnsRecord(routingKey, options);
|
|
286
288
|
return this.#resolve(record.value, options);
|
|
287
289
|
}
|
|
288
|
-
async
|
|
289
|
-
const
|
|
290
|
-
const dnslink = await Promise.any(resolvers.map(async (resolver) => resolver(domain, options)));
|
|
290
|
+
async resolveDNSLink(domain, options = {}) {
|
|
291
|
+
const dnslink = await resolveDNSLink(domain, this.dns, this.log, options);
|
|
291
292
|
return this.#resolve(dnslink, options);
|
|
292
293
|
}
|
|
293
294
|
republish(options = {}) {
|
|
@@ -395,8 +396,8 @@ class DefaultIPNS {
|
|
|
395
396
|
return unmarshal(record);
|
|
396
397
|
}
|
|
397
398
|
}
|
|
398
|
-
export function ipns(components, { routers = []
|
|
399
|
-
return new DefaultIPNS(components, routers
|
|
399
|
+
export function ipns(components, { routers = [] } = {}) {
|
|
400
|
+
return new DefaultIPNS(components, routers);
|
|
400
401
|
}
|
|
401
402
|
export { ipnsValidator };
|
|
402
403
|
export { ipnsSelector } from 'ipns/selector';
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE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a,EAA0B,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/typedoc-urls.json
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
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
2
|
"IPNS": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNS.html",
|
|
7
3
|
".:IPNS": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNS.html",
|
|
8
4
|
"IPNSComponents": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNSComponents.html",
|
|
@@ -13,10 +9,8 @@
|
|
|
13
9
|
".:PublishOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.PublishOptions.html",
|
|
14
10
|
"RepublishOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.RepublishOptions.html",
|
|
15
11
|
".:RepublishOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.RepublishOptions.html",
|
|
16
|
-
"
|
|
17
|
-
".:
|
|
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",
|
|
12
|
+
"ResolveDNSLinkOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveDNSLinkOptions.html",
|
|
13
|
+
".:ResolveDNSLinkOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveDNSLinkOptions.html",
|
|
20
14
|
"ResolveOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveOptions.html",
|
|
21
15
|
".:ResolveOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveOptions.html",
|
|
22
16
|
"ResolveResult": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.ResolveResult.html",
|
|
@@ -25,8 +19,8 @@
|
|
|
25
19
|
".:PublishProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.PublishProgressEvents.html",
|
|
26
20
|
"RepublishProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.RepublishProgressEvents.html",
|
|
27
21
|
".:RepublishProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.RepublishProgressEvents.html",
|
|
28
|
-
"
|
|
29
|
-
".:
|
|
22
|
+
"ResolveDNSLinkProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.ResolveDNSLinkProgressEvents.html",
|
|
23
|
+
".:ResolveDNSLinkProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.ResolveDNSLinkProgressEvents.html",
|
|
30
24
|
"ResolveProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.ResolveProgressEvents.html",
|
|
31
25
|
".:ResolveProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.index.ResolveProgressEvents.html",
|
|
32
26
|
"ipns": "https://ipfs.github.io/helia/functions/_helia_ipns.index.ipns-1.html",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/ipns",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "An implementation of IPNS for Helia",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/ipns#readme",
|
|
@@ -164,18 +164,15 @@
|
|
|
164
164
|
"release": "aegir release"
|
|
165
165
|
},
|
|
166
166
|
"dependencies": {
|
|
167
|
-
"@helia/interface": "^4.0
|
|
167
|
+
"@helia/interface": "^4.1.0",
|
|
168
168
|
"@libp2p/interface": "^1.1.4",
|
|
169
169
|
"@libp2p/kad-dht": "^12.0.8",
|
|
170
170
|
"@libp2p/logger": "^4.0.7",
|
|
171
171
|
"@libp2p/peer-id": "^4.0.7",
|
|
172
|
-
"dns
|
|
173
|
-
"dns-packet": "^5.6.1",
|
|
174
|
-
"hashlru": "^2.3.0",
|
|
172
|
+
"@multiformats/dns": "^1.0.1",
|
|
175
173
|
"interface-datastore": "^8.2.11",
|
|
176
174
|
"ipns": "^9.0.0",
|
|
177
175
|
"multiformats": "^13.1.0",
|
|
178
|
-
"p-queue": "^8.0.1",
|
|
179
176
|
"progress-events": "^1.0.0",
|
|
180
177
|
"uint8arrays": "^5.0.2"
|
|
181
178
|
},
|
package/src/dnslink.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { CodeError, type Logger } from '@libp2p/interface'
|
|
2
|
+
import { peerIdFromString } from '@libp2p/peer-id'
|
|
3
|
+
import { RecordType } from '@multiformats/dns'
|
|
4
|
+
import { CID } from 'multiformats/cid'
|
|
5
|
+
import type { ResolveDNSLinkOptions } from './index.js'
|
|
6
|
+
import type { DNS } from '@multiformats/dns'
|
|
7
|
+
|
|
8
|
+
const MAX_RECURSIVE_DEPTH = 32
|
|
9
|
+
|
|
10
|
+
async function recursiveResolveDnslink (domain: string, depth: number, dns: DNS, log: Logger, options: ResolveDNSLinkOptions = {}): Promise<string> {
|
|
11
|
+
if (depth === 0) {
|
|
12
|
+
throw new Error('recursion limit exceeded')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
log('query %s for TXT and CNAME records', domain)
|
|
16
|
+
const txtRecordsResponse = await dns.query(domain, {
|
|
17
|
+
...options,
|
|
18
|
+
types: [
|
|
19
|
+
RecordType.TXT
|
|
20
|
+
]
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
// sort the TXT records to ensure deterministic processing
|
|
24
|
+
const txtRecords = txtRecordsResponse.Answer
|
|
25
|
+
.sort((a, b) => a.data.localeCompare(b.data))
|
|
26
|
+
|
|
27
|
+
log('found %d TXT records for %s', txtRecords.length, domain)
|
|
28
|
+
|
|
29
|
+
for (const answer of txtRecords) {
|
|
30
|
+
try {
|
|
31
|
+
let result = answer.data
|
|
32
|
+
|
|
33
|
+
// strip leading and trailing " characters
|
|
34
|
+
if (result.startsWith('"') && result.endsWith('"')) {
|
|
35
|
+
result = result.substring(1, result.length - 1)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!result.startsWith('dnslink=')) {
|
|
39
|
+
// invalid record?
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
log('%s TXT %s', answer.name, result)
|
|
44
|
+
|
|
45
|
+
result = result.replace('dnslink=', '')
|
|
46
|
+
|
|
47
|
+
// result is now a `/ipfs/<cid>` or `/ipns/<cid>` string
|
|
48
|
+
const [, protocol, domainOrCID, ...rest] = result.split('/') // e.g. ["", "ipfs", "<cid>"]
|
|
49
|
+
|
|
50
|
+
if (protocol === 'ipfs') {
|
|
51
|
+
try {
|
|
52
|
+
const cid = CID.parse(domainOrCID)
|
|
53
|
+
|
|
54
|
+
// if the result is a CID, we've reached the end of the recursion
|
|
55
|
+
return `/ipfs/${cid}${rest.length > 0 ? `/${rest.join('/')}` : ''}`
|
|
56
|
+
} catch {}
|
|
57
|
+
} else if (protocol === 'ipns') {
|
|
58
|
+
try {
|
|
59
|
+
const peerId = peerIdFromString(domainOrCID)
|
|
60
|
+
|
|
61
|
+
// if the result is a PeerId, we've reached the end of the recursion
|
|
62
|
+
return `/ipns/${peerId}${rest.length > 0 ? `/${rest.join('/')}` : ''}`
|
|
63
|
+
} catch {}
|
|
64
|
+
|
|
65
|
+
// if the result was another IPNS domain, try to follow it
|
|
66
|
+
return await recursiveResolveDomain(domainOrCID, depth - 1, dns, log, options)
|
|
67
|
+
} else if (protocol === 'dnslink') {
|
|
68
|
+
// if the result was another DNSLink domain, try to follow it
|
|
69
|
+
return await recursiveResolveDomain(domainOrCID, depth - 1, dns, log, options)
|
|
70
|
+
} else {
|
|
71
|
+
log('unknown protocol "%s" in DNSLink record for domain: %s', protocol, domain)
|
|
72
|
+
continue
|
|
73
|
+
}
|
|
74
|
+
} catch (err: any) {
|
|
75
|
+
log.error('could not parse DNS link record for domain %s, %s', domain, answer.data, err)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// no dnslink records found, try CNAMEs
|
|
80
|
+
log('no DNSLink records found for %s, falling back to CNAME', domain)
|
|
81
|
+
|
|
82
|
+
const cnameRecordsResponse = await dns.query(domain, {
|
|
83
|
+
...options,
|
|
84
|
+
types: [
|
|
85
|
+
RecordType.CNAME
|
|
86
|
+
]
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// sort the CNAME records to ensure deterministic processing
|
|
90
|
+
const cnameRecords = cnameRecordsResponse.Answer
|
|
91
|
+
.sort((a, b) => a.data.localeCompare(b.data))
|
|
92
|
+
|
|
93
|
+
log('found %d CNAME records for %s', cnameRecords.length, domain)
|
|
94
|
+
|
|
95
|
+
for (const cname of cnameRecords) {
|
|
96
|
+
try {
|
|
97
|
+
return await recursiveResolveDomain(cname.data, depth - 1, dns, log, options)
|
|
98
|
+
} catch (err: any) {
|
|
99
|
+
log.error('domain %s cname %s had no DNSLink records', domain, cname.data, err)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
throw new CodeError(`No DNSLink records found for domain: ${domain}`, 'ERR_DNSLINK_NOT_FOUND')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function recursiveResolveDomain (domain: string, depth: number, dns: DNS, log: Logger, options: ResolveDNSLinkOptions = {}): Promise<string> {
|
|
107
|
+
if (depth === 0) {
|
|
108
|
+
throw new Error('recursion limit exceeded')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// the DNSLink spec says records MUST be stored on the `_dnslink.` subdomain
|
|
112
|
+
// so start looking for records there, we will fall back to the bare domain
|
|
113
|
+
// if none are found
|
|
114
|
+
if (!domain.startsWith('_dnslink.')) {
|
|
115
|
+
domain = `_dnslink.${domain}`
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
return await recursiveResolveDnslink(domain, depth, dns, log, options)
|
|
120
|
+
} catch (err: any) {
|
|
121
|
+
// If the code is not ENOTFOUND or ERR_DNSLINK_NOT_FOUND or ENODATA then throw the error
|
|
122
|
+
if (err.code !== 'ENOTFOUND' && err.code !== 'ERR_DNSLINK_NOT_FOUND' && err.code !== 'ENODATA') {
|
|
123
|
+
throw err
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (domain.startsWith('_dnslink.')) {
|
|
127
|
+
// The supplied domain contains a _dnslink component
|
|
128
|
+
// Check the non-_dnslink domain
|
|
129
|
+
domain = domain.replace('_dnslink.', '')
|
|
130
|
+
} else {
|
|
131
|
+
// Check the _dnslink subdomain
|
|
132
|
+
domain = `_dnslink.${domain}`
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// If this throws then we propagate the error
|
|
136
|
+
return await recursiveResolveDnslink(domain, depth, dns, log, options)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function resolveDNSLink (domain: string, dns: DNS, log: Logger, options: ResolveDNSLinkOptions = {}): Promise<string> {
|
|
141
|
+
return recursiveResolveDomain(domain, options.maxRecursiveDepth ?? MAX_RECURSIVE_DEPTH, dns, log, options)
|
|
142
|
+
}
|