@helia/ipns 8.2.4 → 9.0.0-4d51f16d
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 +31 -135
- package/dist/index.min.js +11 -11
- package/dist/index.min.js.map +4 -4
- package/dist/src/constants.d.ts +17 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +19 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/errors.d.ts +0 -4
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +0 -7
- package/dist/src/errors.js.map +1 -1
- package/dist/src/index.d.ts +131 -207
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +49 -416
- package/dist/src/index.js.map +1 -1
- package/dist/src/ipns/publisher.d.ts +29 -0
- package/dist/src/ipns/publisher.d.ts.map +1 -0
- package/dist/src/ipns/publisher.js +73 -0
- package/dist/src/ipns/publisher.js.map +1 -0
- package/dist/src/ipns/republisher.d.ts +30 -0
- package/dist/src/ipns/republisher.d.ts.map +1 -0
- package/dist/src/ipns/republisher.js +112 -0
- package/dist/src/ipns/republisher.js.map +1 -0
- package/dist/src/ipns/resolver.d.ts +26 -0
- package/dist/src/ipns/resolver.d.ts.map +1 -0
- package/dist/src/ipns/resolver.js +165 -0
- package/dist/src/ipns/resolver.js.map +1 -0
- package/dist/src/ipns.d.ts +20 -0
- package/dist/src/ipns.d.ts.map +1 -0
- package/dist/src/ipns.js +70 -0
- package/dist/src/ipns.js.map +1 -0
- package/dist/src/local-store.d.ts +42 -0
- package/dist/src/local-store.d.ts.map +1 -0
- package/dist/src/local-store.js +119 -0
- package/dist/src/local-store.js.map +1 -0
- package/dist/src/pb/metadata.d.ts +12 -0
- package/dist/src/pb/metadata.d.ts.map +1 -0
- package/dist/src/pb/metadata.js +57 -0
- package/dist/src/pb/metadata.js.map +1 -0
- package/dist/src/routing/index.d.ts +5 -3
- package/dist/src/routing/index.d.ts.map +1 -1
- package/dist/src/routing/index.js.map +1 -1
- package/dist/src/routing/local-store.d.ts +4 -19
- package/dist/src/routing/local-store.d.ts.map +1 -1
- package/dist/src/routing/local-store.js +7 -62
- package/dist/src/routing/local-store.js.map +1 -1
- package/dist/src/routing/pubsub.d.ts +21 -1
- package/dist/src/routing/pubsub.d.ts.map +1 -1
- package/dist/src/routing/pubsub.js +2 -2
- package/dist/src/routing/pubsub.js.map +1 -1
- package/dist/src/utils.d.ts +24 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +56 -0
- package/dist/src/utils.js.map +1 -1
- package/package.json +21 -23
- package/src/constants.ts +24 -0
- package/src/errors.ts +0 -9
- package/src/index.ts +154 -548
- package/src/ipns/publisher.ts +97 -0
- package/src/ipns/republisher.ts +144 -0
- package/src/ipns/resolver.ts +217 -0
- package/src/ipns.ts +87 -0
- package/src/local-store.ts +162 -0
- package/src/pb/metadata.proto +9 -0
- package/src/pb/metadata.ts +74 -0
- package/src/routing/index.ts +5 -4
- package/src/routing/local-store.ts +9 -87
- package/src/routing/pubsub.ts +28 -4
- package/src/utils.ts +70 -0
- package/dist/src/dnslink.d.ts +0 -9
- package/dist/src/dnslink.d.ts.map +0 -1
- package/dist/src/dnslink.js +0 -138
- package/dist/src/dnslink.js.map +0 -1
- package/dist/typedoc-urls.json +0 -48
- package/src/dnslink.ts +0 -163
package/dist/typedoc-urls.json
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"DNSLinkResolveResult": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.DNSLinkResolveResult.html",
|
|
3
|
-
".:DNSLinkResolveResult": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.DNSLinkResolveResult.html",
|
|
4
|
-
"IPNS": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNS.html",
|
|
5
|
-
".:IPNS": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNS.html",
|
|
6
|
-
"IPNSComponents": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNSComponents.html",
|
|
7
|
-
".:IPNSComponents": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNSComponents.html",
|
|
8
|
-
"IPNSOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNSOptions.html",
|
|
9
|
-
".:IPNSOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNSOptions.html",
|
|
10
|
-
"IPNSResolveResult": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNSResolveResult.html",
|
|
11
|
-
".:IPNSResolveResult": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.IPNSResolveResult.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
|
-
"RepublishRecordOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.RepublishRecordOptions.html",
|
|
17
|
-
".:RepublishRecordOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.index.RepublishRecordOptions.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.html",
|
|
33
|
-
".:ipns": "https://ipfs.github.io/helia/functions/_helia_ipns.index.ipns.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
|
-
"PubsubRoutingComponents": "https://ipfs.github.io/helia/interfaces/_helia_ipns.routing.PubsubRoutingComponents.html",
|
|
39
|
-
"PutOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.routing.PutOptions.html",
|
|
40
|
-
"./routing:PutOptions": "https://ipfs.github.io/helia/interfaces/_helia_ipns.routing.PutOptions.html",
|
|
41
|
-
"DatastoreProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.routing.DatastoreProgressEvents.html",
|
|
42
|
-
"HeliaRoutingProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.routing.HeliaRoutingProgressEvents.html",
|
|
43
|
-
"IPNSRoutingEvents": "https://ipfs.github.io/helia/types/_helia_ipns.routing.IPNSRoutingEvents.html",
|
|
44
|
-
"./routing:IPNSRoutingEvents": "https://ipfs.github.io/helia/types/_helia_ipns.routing.IPNSRoutingEvents.html",
|
|
45
|
-
"PubSubProgressEvents": "https://ipfs.github.io/helia/types/_helia_ipns.routing.PubSubProgressEvents.html",
|
|
46
|
-
"helia": "https://ipfs.github.io/helia/functions/_helia_ipns.routing.helia.html",
|
|
47
|
-
"pubsub": "https://ipfs.github.io/helia/functions/_helia_ipns.routing.pubsub.html"
|
|
48
|
-
}
|
package/src/dnslink.ts
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { } from '@libp2p/interface'
|
|
2
|
-
import { peerIdFromCID, peerIdFromString } from '@libp2p/peer-id'
|
|
3
|
-
import { RecordType } from '@multiformats/dns'
|
|
4
|
-
import { CID } from 'multiformats/cid'
|
|
5
|
-
import { DNSLinkNotFoundError } from './errors.js'
|
|
6
|
-
import type { ResolveDNSLinkOptions } from './index.js'
|
|
7
|
-
import type { Logger, PeerId } from '@libp2p/interface'
|
|
8
|
-
import type { Answer, DNS } from '@multiformats/dns'
|
|
9
|
-
|
|
10
|
-
const MAX_RECURSIVE_DEPTH = 32
|
|
11
|
-
|
|
12
|
-
export interface DNSLinkResult {
|
|
13
|
-
answer: Answer
|
|
14
|
-
value: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function recursiveResolveDnslink (domain: string, depth: number, dns: DNS, log: Logger, options: ResolveDNSLinkOptions = {}): Promise<DNSLinkResult> {
|
|
18
|
-
if (depth === 0) {
|
|
19
|
-
throw new Error('recursion limit exceeded')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
log('query %s for TXT and CNAME records', domain)
|
|
23
|
-
const txtRecordsResponse = await dns.query(domain, {
|
|
24
|
-
...options,
|
|
25
|
-
types: [
|
|
26
|
-
RecordType.TXT
|
|
27
|
-
]
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
// sort the TXT records to ensure deterministic processing
|
|
31
|
-
const txtRecords = (txtRecordsResponse?.Answer ?? [])
|
|
32
|
-
.sort((a, b) => a.data.localeCompare(b.data))
|
|
33
|
-
|
|
34
|
-
log('found %d TXT records for %s', txtRecords.length, domain)
|
|
35
|
-
|
|
36
|
-
for (const answer of txtRecords) {
|
|
37
|
-
try {
|
|
38
|
-
let result = answer.data
|
|
39
|
-
|
|
40
|
-
// strip leading and trailing " characters
|
|
41
|
-
if (result.startsWith('"') && result.endsWith('"')) {
|
|
42
|
-
result = result.substring(1, result.length - 1)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (!result.startsWith('dnslink=')) {
|
|
46
|
-
// invalid record?
|
|
47
|
-
continue
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
log('%s TXT %s', answer.name, result)
|
|
51
|
-
|
|
52
|
-
result = result.replace('dnslink=', '')
|
|
53
|
-
|
|
54
|
-
// result is now a `/ipfs/<cid>` or `/ipns/<cid>` string
|
|
55
|
-
const [, protocol, domainOrCID, ...rest] = result.split('/') // e.g. ["", "ipfs", "<cid>"]
|
|
56
|
-
|
|
57
|
-
if (protocol === 'ipfs') {
|
|
58
|
-
try {
|
|
59
|
-
const cid = CID.parse(domainOrCID)
|
|
60
|
-
|
|
61
|
-
// if the result is a CID, we've reached the end of the recursion
|
|
62
|
-
return {
|
|
63
|
-
value: `/ipfs/${cid}${rest.length > 0 ? `/${rest.join('/')}` : ''}`,
|
|
64
|
-
answer
|
|
65
|
-
}
|
|
66
|
-
} catch {}
|
|
67
|
-
} else if (protocol === 'ipns') {
|
|
68
|
-
try {
|
|
69
|
-
let peerId: PeerId
|
|
70
|
-
|
|
71
|
-
// eslint-disable-next-line max-depth
|
|
72
|
-
if (domainOrCID.charAt(0) === '1' || domainOrCID.charAt(0) === 'Q') {
|
|
73
|
-
peerId = peerIdFromString(domainOrCID)
|
|
74
|
-
} else {
|
|
75
|
-
// try parsing as a CID
|
|
76
|
-
peerId = peerIdFromCID(CID.parse(domainOrCID))
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// if the result is a PeerId, we've reached the end of the recursion
|
|
80
|
-
return {
|
|
81
|
-
value: `/ipns/${peerId}${rest.length > 0 ? `/${rest.join('/')}` : ''}`,
|
|
82
|
-
answer
|
|
83
|
-
}
|
|
84
|
-
} catch {}
|
|
85
|
-
|
|
86
|
-
// if the result was another IPNS domain, try to follow it
|
|
87
|
-
return await recursiveResolveDomain(domainOrCID, depth - 1, dns, log, options)
|
|
88
|
-
} else if (protocol === 'dnslink') {
|
|
89
|
-
// if the result was another DNSLink domain, try to follow it
|
|
90
|
-
return await recursiveResolveDomain(domainOrCID, depth - 1, dns, log, options)
|
|
91
|
-
} else {
|
|
92
|
-
log('unknown protocol "%s" in DNSLink record for domain: %s', protocol, domain)
|
|
93
|
-
continue
|
|
94
|
-
}
|
|
95
|
-
} catch (err: any) {
|
|
96
|
-
log.error('could not parse DNS link record for domain %s, %s', domain, answer.data, err)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// no dnslink records found, try CNAMEs
|
|
101
|
-
log('no DNSLink records found for %s, falling back to CNAME', domain)
|
|
102
|
-
|
|
103
|
-
const cnameRecordsResponse = await dns.query(domain, {
|
|
104
|
-
...options,
|
|
105
|
-
types: [
|
|
106
|
-
RecordType.CNAME
|
|
107
|
-
]
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
// sort the CNAME records to ensure deterministic processing
|
|
111
|
-
const cnameRecords = (cnameRecordsResponse?.Answer ?? [])
|
|
112
|
-
.sort((a, b) => a.data.localeCompare(b.data))
|
|
113
|
-
|
|
114
|
-
log('found %d CNAME records for %s', cnameRecords.length, domain)
|
|
115
|
-
|
|
116
|
-
for (const cname of cnameRecords) {
|
|
117
|
-
try {
|
|
118
|
-
return await recursiveResolveDomain(cname.data, depth - 1, dns, log, options)
|
|
119
|
-
} catch (err: any) {
|
|
120
|
-
log.error('domain %s cname %s had no DNSLink records', domain, cname.data, err)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
throw new DNSLinkNotFoundError(`No DNSLink records found for domain: ${domain}`)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async function recursiveResolveDomain (domain: string, depth: number, dns: DNS, log: Logger, options: ResolveDNSLinkOptions = {}): Promise<DNSLinkResult> {
|
|
128
|
-
if (depth === 0) {
|
|
129
|
-
throw new Error('recursion limit exceeded')
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// the DNSLink spec says records MUST be stored on the `_dnslink.` subdomain
|
|
133
|
-
// so start looking for records there, we will fall back to the bare domain
|
|
134
|
-
// if none are found
|
|
135
|
-
if (!domain.startsWith('_dnslink.')) {
|
|
136
|
-
domain = `_dnslink.${domain}`
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
try {
|
|
140
|
-
return await recursiveResolveDnslink(domain, depth, dns, log, options)
|
|
141
|
-
} catch (err: any) {
|
|
142
|
-
// If the code is not ENOTFOUND or ERR_DNSLINK_NOT_FOUND or ENODATA then throw the error
|
|
143
|
-
if (err.code !== 'ENOTFOUND' && err.code !== 'ENODATA' && err.name !== 'DNSLinkNotFoundError' && err.name !== 'NotFoundError') {
|
|
144
|
-
throw err
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (domain.startsWith('_dnslink.')) {
|
|
148
|
-
// The supplied domain contains a _dnslink component
|
|
149
|
-
// Check the non-_dnslink domain
|
|
150
|
-
domain = domain.replace('_dnslink.', '')
|
|
151
|
-
} else {
|
|
152
|
-
// Check the _dnslink subdomain
|
|
153
|
-
domain = `_dnslink.${domain}`
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// If this throws then we propagate the error
|
|
157
|
-
return recursiveResolveDnslink(domain, depth, dns, log, options)
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export async function resolveDNSLink (domain: string, dns: DNS, log: Logger, options: ResolveDNSLinkOptions = {}): Promise<DNSLinkResult> {
|
|
162
|
-
return recursiveResolveDomain(domain, options.maxRecursiveDepth ?? MAX_RECURSIVE_DEPTH, dns, log, options)
|
|
163
|
-
}
|