@helia/ipns 6.0.1 → 7.0.0-b6765fe
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +4 -4
- package/dist/src/dnslink.d.ts +9 -0
- package/dist/src/dnslink.d.ts.map +1 -0
- package/dist/src/dnslink.js +129 -0
- package/dist/src/dnslink.js.map +1 -0
- package/dist/src/index.d.ts +39 -23
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +18 -11
- package/dist/src/index.js.map +1 -1
- package/package.json +3 -6
- package/src/dnslink.ts +153 -0
- package/src/index.ts +64 -43
- 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/dist/typedoc-urls.json +0 -44
- 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,9 @@
|
|
|
1
|
+
import { type Logger } from '@libp2p/interface';
|
|
2
|
+
import type { ResolveDNSLinkOptions } from './index.js';
|
|
3
|
+
import type { Answer, DNS } from '@multiformats/dns';
|
|
4
|
+
export interface DNSLinkResult {
|
|
5
|
+
answer: Answer;
|
|
6
|
+
value: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function resolveDNSLink(domain: string, dns: DNS, log: Logger, options?: ResolveDNSLinkOptions): Promise<DNSLinkResult>;
|
|
9
|
+
//# 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,MAAM,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAIpD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;CACd;AA0ID,wBAAsB,cAAc,CAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,aAAa,CAAC,CAExI"}
|
|
@@ -0,0 +1,129 @@
|
|
|
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 {
|
|
41
|
+
value: `/ipfs/${cid}${rest.length > 0 ? `/${rest.join('/')}` : ''}`,
|
|
42
|
+
answer
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch { }
|
|
46
|
+
}
|
|
47
|
+
else if (protocol === 'ipns') {
|
|
48
|
+
try {
|
|
49
|
+
const peerId = peerIdFromString(domainOrCID);
|
|
50
|
+
// if the result is a PeerId, we've reached the end of the recursion
|
|
51
|
+
return {
|
|
52
|
+
value: `/ipns/${peerId}${rest.length > 0 ? `/${rest.join('/')}` : ''}`,
|
|
53
|
+
answer
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch { }
|
|
57
|
+
// if the result was another IPNS domain, try to follow it
|
|
58
|
+
return await recursiveResolveDomain(domainOrCID, depth - 1, dns, log, options);
|
|
59
|
+
}
|
|
60
|
+
else if (protocol === 'dnslink') {
|
|
61
|
+
// if the result was another DNSLink domain, try to follow it
|
|
62
|
+
return await recursiveResolveDomain(domainOrCID, depth - 1, dns, log, options);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
log('unknown protocol "%s" in DNSLink record for domain: %s', protocol, domain);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
log.error('could not parse DNS link record for domain %s, %s', domain, answer.data, err);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// no dnslink records found, try CNAMEs
|
|
74
|
+
log('no DNSLink records found for %s, falling back to CNAME', domain);
|
|
75
|
+
const cnameRecordsResponse = await dns.query(domain, {
|
|
76
|
+
...options,
|
|
77
|
+
types: [
|
|
78
|
+
RecordType.CNAME
|
|
79
|
+
]
|
|
80
|
+
});
|
|
81
|
+
// sort the CNAME records to ensure deterministic processing
|
|
82
|
+
const cnameRecords = cnameRecordsResponse.Answer
|
|
83
|
+
.sort((a, b) => a.data.localeCompare(b.data));
|
|
84
|
+
log('found %d CNAME records for %s', cnameRecords.length, domain);
|
|
85
|
+
for (const cname of cnameRecords) {
|
|
86
|
+
try {
|
|
87
|
+
return await recursiveResolveDomain(cname.data, depth - 1, dns, log, options);
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
log.error('domain %s cname %s had no DNSLink records', domain, cname.data, err);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
throw new CodeError(`No DNSLink records found for domain: ${domain}`, 'ERR_DNSLINK_NOT_FOUND');
|
|
94
|
+
}
|
|
95
|
+
async function recursiveResolveDomain(domain, depth, dns, log, options = {}) {
|
|
96
|
+
if (depth === 0) {
|
|
97
|
+
throw new Error('recursion limit exceeded');
|
|
98
|
+
}
|
|
99
|
+
// the DNSLink spec says records MUST be stored on the `_dnslink.` subdomain
|
|
100
|
+
// so start looking for records there, we will fall back to the bare domain
|
|
101
|
+
// if none are found
|
|
102
|
+
if (!domain.startsWith('_dnslink.')) {
|
|
103
|
+
domain = `_dnslink.${domain}`;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
return await recursiveResolveDnslink(domain, depth, dns, log, options);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
// If the code is not ENOTFOUND or ERR_DNSLINK_NOT_FOUND or ENODATA then throw the error
|
|
110
|
+
if (err.code !== 'ENOTFOUND' && err.code !== 'ERR_DNSLINK_NOT_FOUND' && err.code !== 'ENODATA') {
|
|
111
|
+
throw err;
|
|
112
|
+
}
|
|
113
|
+
if (domain.startsWith('_dnslink.')) {
|
|
114
|
+
// The supplied domain contains a _dnslink component
|
|
115
|
+
// Check the non-_dnslink domain
|
|
116
|
+
domain = domain.replace('_dnslink.', '');
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
// Check the _dnslink subdomain
|
|
120
|
+
domain = `_dnslink.${domain}`;
|
|
121
|
+
}
|
|
122
|
+
// If this throws then we propagate the error
|
|
123
|
+
return await recursiveResolveDnslink(domain, depth, dns, log, options);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export async function resolveDNSLink(domain, dns, log, options = {}) {
|
|
127
|
+
return recursiveResolveDomain(domain, options.maxRecursiveDepth ?? MAX_RECURSIVE_DEPTH, dns, log, options);
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=dnslink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dnslink.js","sourceRoot":"","sources":["../../src/dnslink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAe,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAItC,MAAM,mBAAmB,GAAG,EAAE,CAAA;AAO9B,KAAK,UAAU,uBAAuB,CAAE,MAAc,EAAE,KAAa,EAAE,GAAQ,EAAE,GAAW,EAAE,UAAiC,EAAE;IAC/H,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;IAC7C,CAAC;IAED,GAAG,CAAC,oCAAoC,EAAE,MAAM,CAAC,CAAA;IACjD,MAAM,kBAAkB,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE;QACjD,GAAG,OAAO;QACV,KAAK,EAAE;YACL,UAAU,CAAC,GAAG;SACf;KACF,CAAC,CAAA;IAEF,0DAA0D;IAC1D,MAAM,UAAU,GAAG,kBAAkB,CAAC,MAAM;SACzC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC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,EAAE,CAAC;QAClB,wFAAwF;QACxF,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,IAAI,GAAG,CAAC,IAAI,KAAK,uBAAuB,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC/F,MAAM,GAAG,CAAA;QACX,CAAC;QAED,IAAI,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YACnC,oDAAoD;YACpD,gCAAgC;YAChC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;QAC1C,CAAC;aAAM,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 { Answer, 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
|
/**
|
|
@@ -296,9 +291,29 @@ export interface RepublishOptions extends AbortOptions, ProgressOptions<Republis
|
|
|
296
291
|
interval?: number;
|
|
297
292
|
}
|
|
298
293
|
export interface ResolveResult {
|
|
294
|
+
/**
|
|
295
|
+
* The CID that was resolved
|
|
296
|
+
*/
|
|
299
297
|
cid: CID;
|
|
298
|
+
/**
|
|
299
|
+
* Any path component that was part of the resolved record
|
|
300
|
+
*
|
|
301
|
+
* @default ""
|
|
302
|
+
*/
|
|
300
303
|
path: string;
|
|
301
304
|
}
|
|
305
|
+
export interface IPNSResolveResult extends ResolveResult {
|
|
306
|
+
/**
|
|
307
|
+
* The resolved record
|
|
308
|
+
*/
|
|
309
|
+
record: IPNSRecord;
|
|
310
|
+
}
|
|
311
|
+
export interface DNSLinkResolveResult extends ResolveResult {
|
|
312
|
+
/**
|
|
313
|
+
* The resolved record
|
|
314
|
+
*/
|
|
315
|
+
answer: Answer;
|
|
316
|
+
}
|
|
302
317
|
export interface IPNS {
|
|
303
318
|
/**
|
|
304
319
|
* Creates an IPNS record signed by the passed PeerId that will resolve to the passed value
|
|
@@ -310,11 +325,11 @@ export interface IPNS {
|
|
|
310
325
|
* Accepts a public key formatted as a libp2p PeerID and resolves the IPNS record
|
|
311
326
|
* corresponding to that public key until a value is found
|
|
312
327
|
*/
|
|
313
|
-
resolve(key: PeerId, options?: ResolveOptions): Promise<
|
|
328
|
+
resolve(key: PeerId, options?: ResolveOptions): Promise<IPNSResolveResult>;
|
|
314
329
|
/**
|
|
315
330
|
* Resolve a CID from a dns-link style IPNS record
|
|
316
331
|
*/
|
|
317
|
-
|
|
332
|
+
resolveDNSLink(domain: string, options?: ResolveDNSLinkOptions): Promise<DNSLinkResolveResult>;
|
|
318
333
|
/**
|
|
319
334
|
* Periodically republish all IPNS records found in the datastore
|
|
320
335
|
*/
|
|
@@ -324,12 +339,13 @@ export type { IPNSRouting } from './routing/index.js';
|
|
|
324
339
|
export interface IPNSComponents {
|
|
325
340
|
datastore: Datastore;
|
|
326
341
|
routing: Routing;
|
|
342
|
+
dns: DNS;
|
|
343
|
+
logger: ComponentLogger;
|
|
327
344
|
}
|
|
328
345
|
export interface IPNSOptions {
|
|
329
346
|
routers?: IPNSRouting[];
|
|
330
|
-
resolvers?: DNSResolver[];
|
|
331
347
|
}
|
|
332
|
-
export declare function ipns(components: IPNSComponents, { routers
|
|
348
|
+
export declare function ipns(components: IPNSComponents, { routers }?: IPNSOptions): IPNS;
|
|
333
349
|
export { ipnsValidator, type IPNSRoutingEvents };
|
|
334
350
|
export { ipnsSelector } from 'ipns/selector';
|
|
335
351
|
//# 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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HANGED
|
@@ -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 {
|
|
@@ -283,12 +285,17 @@ class DefaultIPNS {
|
|
|
283
285
|
async resolve(key, options = {}) {
|
|
284
286
|
const routingKey = peerIdToRoutingKey(key);
|
|
285
287
|
const record = await this.#findIpnsRecord(routingKey, options);
|
|
286
|
-
return
|
|
288
|
+
return {
|
|
289
|
+
...(await this.#resolve(record.value, options)),
|
|
290
|
+
record
|
|
291
|
+
};
|
|
287
292
|
}
|
|
288
|
-
async
|
|
289
|
-
const
|
|
290
|
-
|
|
291
|
-
|
|
293
|
+
async resolveDNSLink(domain, options = {}) {
|
|
294
|
+
const dnslink = await resolveDNSLink(domain, this.dns, this.log, options);
|
|
295
|
+
return {
|
|
296
|
+
...(await this.#resolve(dnslink.value, options)),
|
|
297
|
+
answer: dnslink.answer
|
|
298
|
+
};
|
|
292
299
|
}
|
|
293
300
|
republish(options = {}) {
|
|
294
301
|
if (this.timeout != null) {
|
|
@@ -395,8 +402,8 @@ class DefaultIPNS {
|
|
|
395
402
|
return unmarshal(record);
|
|
396
403
|
}
|
|
397
404
|
}
|
|
398
|
-
export function ipns(components, { routers = []
|
|
399
|
-
return new DefaultIPNS(components, routers
|
|
405
|
+
export function ipns(components, { routers = [] } = {}) {
|
|
406
|
+
return new DefaultIPNS(components, routers);
|
|
400
407
|
}
|
|
401
408
|
export { ipnsValidator };
|
|
402
409
|
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":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AC,CAAC,KAAK,UAAU,EAAE,+BAA+B,CAAC,CAAA;YACvL,CAAC;YAED,MAAM,IAAI,SAAS,CAAC,uCAAuC,EAAE,eAAe,CAAC,CAAA;QAC/E,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;QAEzD,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;QAEtD,OAAO,SAAS,CAAC,MAAM,CAAC,CAAA;IAC1B,CAAC;CACF;AAMD,MAAM,UAAU,IAAI,CAAE,UAA0B,EAAE,EAAE,OAAO,GAAG,EAAE,KAAkB,EAAE;IAClF,OAAO,IAAI,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAA;AAC7C,CAAC;AAED,OAAO,EAAE,aAAa,EAA0B,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/ipns",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-b6765fe",
|
|
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": "
|
|
167
|
+
"@helia/interface": "4.1.0-b6765fe",
|
|
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,153 @@
|
|
|
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 { Answer, DNS } from '@multiformats/dns'
|
|
7
|
+
|
|
8
|
+
const MAX_RECURSIVE_DEPTH = 32
|
|
9
|
+
|
|
10
|
+
export interface DNSLinkResult {
|
|
11
|
+
answer: Answer
|
|
12
|
+
value: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function recursiveResolveDnslink (domain: string, depth: number, dns: DNS, log: Logger, options: ResolveDNSLinkOptions = {}): Promise<DNSLinkResult> {
|
|
16
|
+
if (depth === 0) {
|
|
17
|
+
throw new Error('recursion limit exceeded')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
log('query %s for TXT and CNAME records', domain)
|
|
21
|
+
const txtRecordsResponse = await dns.query(domain, {
|
|
22
|
+
...options,
|
|
23
|
+
types: [
|
|
24
|
+
RecordType.TXT
|
|
25
|
+
]
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// sort the TXT records to ensure deterministic processing
|
|
29
|
+
const txtRecords = txtRecordsResponse.Answer
|
|
30
|
+
.sort((a, b) => a.data.localeCompare(b.data))
|
|
31
|
+
|
|
32
|
+
log('found %d TXT records for %s', txtRecords.length, domain)
|
|
33
|
+
|
|
34
|
+
for (const answer of txtRecords) {
|
|
35
|
+
try {
|
|
36
|
+
let result = answer.data
|
|
37
|
+
|
|
38
|
+
// strip leading and trailing " characters
|
|
39
|
+
if (result.startsWith('"') && result.endsWith('"')) {
|
|
40
|
+
result = result.substring(1, result.length - 1)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!result.startsWith('dnslink=')) {
|
|
44
|
+
// invalid record?
|
|
45
|
+
continue
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
log('%s TXT %s', answer.name, result)
|
|
49
|
+
|
|
50
|
+
result = result.replace('dnslink=', '')
|
|
51
|
+
|
|
52
|
+
// result is now a `/ipfs/<cid>` or `/ipns/<cid>` string
|
|
53
|
+
const [, protocol, domainOrCID, ...rest] = result.split('/') // e.g. ["", "ipfs", "<cid>"]
|
|
54
|
+
|
|
55
|
+
if (protocol === 'ipfs') {
|
|
56
|
+
try {
|
|
57
|
+
const cid = CID.parse(domainOrCID)
|
|
58
|
+
|
|
59
|
+
// if the result is a CID, we've reached the end of the recursion
|
|
60
|
+
return {
|
|
61
|
+
value: `/ipfs/${cid}${rest.length > 0 ? `/${rest.join('/')}` : ''}`,
|
|
62
|
+
answer
|
|
63
|
+
}
|
|
64
|
+
} catch {}
|
|
65
|
+
} else if (protocol === 'ipns') {
|
|
66
|
+
try {
|
|
67
|
+
const peerId = peerIdFromString(domainOrCID)
|
|
68
|
+
|
|
69
|
+
// if the result is a PeerId, we've reached the end of the recursion
|
|
70
|
+
return {
|
|
71
|
+
value: `/ipns/${peerId}${rest.length > 0 ? `/${rest.join('/')}` : ''}`,
|
|
72
|
+
answer
|
|
73
|
+
}
|
|
74
|
+
} catch {}
|
|
75
|
+
|
|
76
|
+
// if the result was another IPNS domain, try to follow it
|
|
77
|
+
return await recursiveResolveDomain(domainOrCID, depth - 1, dns, log, options)
|
|
78
|
+
} else if (protocol === 'dnslink') {
|
|
79
|
+
// if the result was another DNSLink domain, try to follow it
|
|
80
|
+
return await recursiveResolveDomain(domainOrCID, depth - 1, dns, log, options)
|
|
81
|
+
} else {
|
|
82
|
+
log('unknown protocol "%s" in DNSLink record for domain: %s', protocol, domain)
|
|
83
|
+
continue
|
|
84
|
+
}
|
|
85
|
+
} catch (err: any) {
|
|
86
|
+
log.error('could not parse DNS link record for domain %s, %s', domain, answer.data, err)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// no dnslink records found, try CNAMEs
|
|
91
|
+
log('no DNSLink records found for %s, falling back to CNAME', domain)
|
|
92
|
+
|
|
93
|
+
const cnameRecordsResponse = await dns.query(domain, {
|
|
94
|
+
...options,
|
|
95
|
+
types: [
|
|
96
|
+
RecordType.CNAME
|
|
97
|
+
]
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
// sort the CNAME records to ensure deterministic processing
|
|
101
|
+
const cnameRecords = cnameRecordsResponse.Answer
|
|
102
|
+
.sort((a, b) => a.data.localeCompare(b.data))
|
|
103
|
+
|
|
104
|
+
log('found %d CNAME records for %s', cnameRecords.length, domain)
|
|
105
|
+
|
|
106
|
+
for (const cname of cnameRecords) {
|
|
107
|
+
try {
|
|
108
|
+
return await recursiveResolveDomain(cname.data, depth - 1, dns, log, options)
|
|
109
|
+
} catch (err: any) {
|
|
110
|
+
log.error('domain %s cname %s had no DNSLink records', domain, cname.data, err)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
throw new CodeError(`No DNSLink records found for domain: ${domain}`, 'ERR_DNSLINK_NOT_FOUND')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function recursiveResolveDomain (domain: string, depth: number, dns: DNS, log: Logger, options: ResolveDNSLinkOptions = {}): Promise<DNSLinkResult> {
|
|
118
|
+
if (depth === 0) {
|
|
119
|
+
throw new Error('recursion limit exceeded')
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// the DNSLink spec says records MUST be stored on the `_dnslink.` subdomain
|
|
123
|
+
// so start looking for records there, we will fall back to the bare domain
|
|
124
|
+
// if none are found
|
|
125
|
+
if (!domain.startsWith('_dnslink.')) {
|
|
126
|
+
domain = `_dnslink.${domain}`
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
return await recursiveResolveDnslink(domain, depth, dns, log, options)
|
|
131
|
+
} catch (err: any) {
|
|
132
|
+
// If the code is not ENOTFOUND or ERR_DNSLINK_NOT_FOUND or ENODATA then throw the error
|
|
133
|
+
if (err.code !== 'ENOTFOUND' && err.code !== 'ERR_DNSLINK_NOT_FOUND' && err.code !== 'ENODATA') {
|
|
134
|
+
throw err
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (domain.startsWith('_dnslink.')) {
|
|
138
|
+
// The supplied domain contains a _dnslink component
|
|
139
|
+
// Check the non-_dnslink domain
|
|
140
|
+
domain = domain.replace('_dnslink.', '')
|
|
141
|
+
} else {
|
|
142
|
+
// Check the _dnslink subdomain
|
|
143
|
+
domain = `_dnslink.${domain}`
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// If this throws then we propagate the error
|
|
147
|
+
return await recursiveResolveDnslink(domain, depth, dns, log, options)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function resolveDNSLink (domain: string, dns: DNS, log: Logger, options: ResolveDNSLinkOptions = {}): Promise<DNSLinkResult> {
|
|
152
|
+
return recursiveResolveDomain(domain, options.maxRecursiveDepth ?? MAX_RECURSIVE_DEPTH, dns, log, options)
|
|
153
|
+
}
|