@helia/ipns 5.0.0 → 6.0.0-8a5bc6f
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 +83 -12
- package/dist/index.min.js +4 -4
- package/dist/src/index.d.ts +91 -16
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +99 -15
- package/dist/src/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +111 -24
- package/dist/typedoc-urls.json +0 -42
package/dist/src/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* With {@link IPNSRouting} routers:
|
|
9
9
|
*
|
|
10
|
-
* ```
|
|
10
|
+
* ```TypeScript
|
|
11
11
|
* import { createHelia } from 'helia'
|
|
12
12
|
* import { ipns } from '@helia/ipns'
|
|
13
13
|
* import { unixfs } from '@helia/unixfs'
|
|
@@ -27,7 +27,78 @@
|
|
|
27
27
|
* await name.publish(peerId, cid)
|
|
28
28
|
*
|
|
29
29
|
* // resolve the name
|
|
30
|
-
* const
|
|
30
|
+
* const result = name.resolve(peerId)
|
|
31
|
+
*
|
|
32
|
+
* console.info(result.cid, result.path)
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Publishing a recursive record
|
|
36
|
+
*
|
|
37
|
+
* A recursive record is a one that points to another record rather than to a
|
|
38
|
+
* value.
|
|
39
|
+
*
|
|
40
|
+
* ```TypeScript
|
|
41
|
+
* import { createHelia } from 'helia'
|
|
42
|
+
* import { ipns } from '@helia/ipns'
|
|
43
|
+
* import { unixfs } from '@helia/unixfs'
|
|
44
|
+
*
|
|
45
|
+
* const helia = await createHelia()
|
|
46
|
+
* const name = ipns(helia)
|
|
47
|
+
*
|
|
48
|
+
* // create a public key to publish as an IPNS name
|
|
49
|
+
* const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
|
|
50
|
+
* const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
|
|
51
|
+
*
|
|
52
|
+
* // store some data to publish
|
|
53
|
+
* const fs = unixfs(helia)
|
|
54
|
+
* const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
55
|
+
*
|
|
56
|
+
* // publish the name
|
|
57
|
+
* await name.publish(peerId, cid)
|
|
58
|
+
*
|
|
59
|
+
* // create another public key to re-publish the original record
|
|
60
|
+
* const recursiveKeyInfo = await helia.libp2p.services.keychain.createKey('my-recursive-key')
|
|
61
|
+
* const recursivePeerId = await helia.libp2p.services.keychain.exportPeerId(recursiveKeyInfo.name)
|
|
62
|
+
*
|
|
63
|
+
* // publish the recursive name
|
|
64
|
+
* await name.publish(recursivePeerId, peerId)
|
|
65
|
+
*
|
|
66
|
+
* // resolve the name recursively - it resolves until a CID is found
|
|
67
|
+
* const result = name.resolve(recursivePeerId)
|
|
68
|
+
* console.info(result.cid.toString() === cid.toString()) // true
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example Publishing a record with a path
|
|
72
|
+
*
|
|
73
|
+
* It is possible to publish CIDs with an associated path.
|
|
74
|
+
*
|
|
75
|
+
* ```TypeScript
|
|
76
|
+
* import { createHelia } from 'helia'
|
|
77
|
+
* import { ipns } from '@helia/ipns'
|
|
78
|
+
* import { unixfs } from '@helia/unixfs'
|
|
79
|
+
*
|
|
80
|
+
* const helia = await createHelia()
|
|
81
|
+
* const name = ipns(helia)
|
|
82
|
+
*
|
|
83
|
+
* // create a public key to publish as an IPNS name
|
|
84
|
+
* const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
|
|
85
|
+
* const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
|
|
86
|
+
*
|
|
87
|
+
* // store some data to publish
|
|
88
|
+
* const fs = unixfs(helia)
|
|
89
|
+
* const fileCid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
90
|
+
*
|
|
91
|
+
* // store the file in a directory
|
|
92
|
+
* const dirCid = await fs.mkdir()
|
|
93
|
+
* const finalDirCid = await fs.cp(fileCid, dirCid, '/foo.txt')
|
|
94
|
+
*
|
|
95
|
+
* // publish the name
|
|
96
|
+
* await name.publish(peerId, `/ipfs/${finalDirCid}/foo.txt)
|
|
97
|
+
*
|
|
98
|
+
* // resolve the name
|
|
99
|
+
* const result = name.resolve(peerId)
|
|
100
|
+
*
|
|
101
|
+
* console.info(result.cid, result.path) // QmFoo.. 'foo.txt'
|
|
31
102
|
* ```
|
|
32
103
|
*
|
|
33
104
|
* @example Using custom PubSub router
|
|
@@ -46,7 +117,7 @@
|
|
|
46
117
|
* and multiple peers are listening on the topic(s), otherwise update messages
|
|
47
118
|
* may fail to be published with "Insufficient peers" errors.
|
|
48
119
|
*
|
|
49
|
-
* ```
|
|
120
|
+
* ```TypeScript
|
|
50
121
|
* import { createHelia, libp2pDefaults } from 'helia'
|
|
51
122
|
* import { ipns } from '@helia/ipns'
|
|
52
123
|
* import { pubsub } from '@helia/ipns/routing'
|
|
@@ -77,14 +148,14 @@
|
|
|
77
148
|
* await name.publish(peerId, cid)
|
|
78
149
|
*
|
|
79
150
|
* // resolve the name
|
|
80
|
-
* const cid = name.resolve(peerId)
|
|
151
|
+
* const { cid, path } = name.resolve(peerId)
|
|
81
152
|
* ```
|
|
82
153
|
*
|
|
83
154
|
* @example Using custom DNS over HTTPS resolvers
|
|
84
155
|
*
|
|
85
156
|
* With default {@link DNSResolver} resolvers:
|
|
86
157
|
*
|
|
87
|
-
* ```
|
|
158
|
+
* ```TypeScript
|
|
88
159
|
* import { createHelia } from 'helia'
|
|
89
160
|
* import { ipns } from '@helia/ipns'
|
|
90
161
|
* import { unixfs } from '@helia/unixfs'
|
|
@@ -97,14 +168,14 @@
|
|
|
97
168
|
* ]
|
|
98
169
|
* })
|
|
99
170
|
*
|
|
100
|
-
* const cid = name.resolveDns('some-domain-with-dnslink-entry.com')
|
|
171
|
+
* const { cid, path } = name.resolveDns('some-domain-with-dnslink-entry.com')
|
|
101
172
|
* ```
|
|
102
173
|
*
|
|
103
174
|
* @example Resolving a domain with a dnslink entry
|
|
104
175
|
*
|
|
105
176
|
* Calling `resolveDns` with the `@helia/ipns` instance:
|
|
106
177
|
*
|
|
107
|
-
* ```
|
|
178
|
+
* ```TypeScript
|
|
108
179
|
* // resolve a CID from a TXT record in a DNS zone file, using the default
|
|
109
180
|
* // resolver for the current platform eg:
|
|
110
181
|
* // > dig _dnslink.ipfs.io TXT
|
|
@@ -114,7 +185,7 @@
|
|
|
114
185
|
* // ;; ANSWER SECTION:
|
|
115
186
|
* // _dnslink.website.ipfs.io. 60 IN TXT "dnslink=/ipfs/QmWebsite"
|
|
116
187
|
*
|
|
117
|
-
* const cid = name.resolveDns('ipfs.io')
|
|
188
|
+
* const { cid, path } = name.resolveDns('ipfs.io')
|
|
118
189
|
*
|
|
119
190
|
* console.info(cid)
|
|
120
191
|
* // QmWebsite
|
|
@@ -128,11 +199,11 @@
|
|
|
128
199
|
*
|
|
129
200
|
* If this is a concern, use the DNS-JSON-Over-HTTPS resolver instead.
|
|
130
201
|
*
|
|
131
|
-
* ```
|
|
202
|
+
* ```TypeScript
|
|
132
203
|
* // use DNS-Over-HTTPS
|
|
133
204
|
* import { dnsOverHttps } from '@helia/ipns/dns-resolvers'
|
|
134
205
|
*
|
|
135
|
-
* const cid = name.resolveDns('ipfs.io', {
|
|
206
|
+
* const { cid, path } = name.resolveDns('ipfs.io', {
|
|
136
207
|
* resolvers: [
|
|
137
208
|
* dnsOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
|
|
138
209
|
* ]
|
|
@@ -144,11 +215,11 @@
|
|
|
144
215
|
* DNS-JSON-Over-HTTPS resolvers use the RFC 8427 `application/dns-json` and can
|
|
145
216
|
* result in a smaller browser bundle due to the response being plain JSON.
|
|
146
217
|
*
|
|
147
|
-
* ```
|
|
218
|
+
* ```TypeScript
|
|
148
219
|
* // use DNS-JSON-Over-HTTPS
|
|
149
220
|
* import { dnsJsonOverHttps } from '@helia/ipns/dns-resolvers'
|
|
150
221
|
*
|
|
151
|
-
* const cid = name.resolveDns('ipfs.io', {
|
|
222
|
+
* const { cid, path } = name.resolveDns('ipfs.io', {
|
|
152
223
|
* resolvers: [
|
|
153
224
|
* dnsJsonOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
|
|
154
225
|
* ]
|
|
@@ -224,22 +295,26 @@ export interface RepublishOptions extends AbortOptions, ProgressOptions<Republis
|
|
|
224
295
|
*/
|
|
225
296
|
interval?: number;
|
|
226
297
|
}
|
|
298
|
+
export interface ResolveResult {
|
|
299
|
+
cid: CID;
|
|
300
|
+
path: string;
|
|
301
|
+
}
|
|
227
302
|
export interface IPNS {
|
|
228
303
|
/**
|
|
229
304
|
* Creates an IPNS record signed by the passed PeerId that will resolve to the passed value
|
|
230
305
|
*
|
|
231
306
|
* If the value is a PeerId, a recursive IPNS record will be created.
|
|
232
307
|
*/
|
|
233
|
-
publish(key: PeerId, value: CID | PeerId, options?: PublishOptions): Promise<IPNSRecord>;
|
|
308
|
+
publish(key: PeerId, value: CID | PeerId | string, options?: PublishOptions): Promise<IPNSRecord>;
|
|
234
309
|
/**
|
|
235
310
|
* Accepts a public key formatted as a libp2p PeerID and resolves the IPNS record
|
|
236
311
|
* corresponding to that public key until a value is found
|
|
237
312
|
*/
|
|
238
|
-
resolve(key: PeerId, options?: ResolveOptions): Promise<
|
|
313
|
+
resolve(key: PeerId, options?: ResolveOptions): Promise<ResolveResult>;
|
|
239
314
|
/**
|
|
240
315
|
* Resolve a CID from a dns-link style IPNS record
|
|
241
316
|
*/
|
|
242
|
-
resolveDns(domain: string, options?: ResolveDNSOptions): Promise<
|
|
317
|
+
resolveDns(domain: string, options?: ResolveDNSOptions): Promise<ResolveResult>;
|
|
243
318
|
/**
|
|
244
319
|
* Periodically republish all IPNS records found in the datastore
|
|
245
320
|
*/
|
|
@@ -255,6 +330,6 @@ export interface IPNSOptions {
|
|
|
255
330
|
resolvers?: DNSResolver[];
|
|
256
331
|
}
|
|
257
332
|
export declare function ipns(components: IPNSComponents, { routers, resolvers }?: IPNSOptions): IPNS;
|
|
258
|
-
export { ipnsValidator };
|
|
333
|
+
export { ipnsValidator, type IPNSRoutingEvents };
|
|
259
334
|
export { ipnsSelector } from 'ipns/selector';
|
|
260
335
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmOG;AAOH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAKtC,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAUrE,MAAM,MAAM,qBAAqB,GAC/B,aA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M,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,WAAW,EAAE,CAAA;IACvB,SAAS,CAAC,EAAE,WAAW,EAAE,CAAA;CAC1B;AAED,wBAAgB,IAAI,CAAE,UAAU,EAAE,cAAc,EAAE,EAAE,OAAY,EAAE,SAAc,EAAE,GAAE,WAAgB,GAAG,IAAI,CAE1G;AAED,OAAO,EAAE,aAAa,EAAE,KAAK,iBAAiB,EAAE,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*
|
|
8
8
|
* With {@link IPNSRouting} routers:
|
|
9
9
|
*
|
|
10
|
-
* ```
|
|
10
|
+
* ```TypeScript
|
|
11
11
|
* import { createHelia } from 'helia'
|
|
12
12
|
* import { ipns } from '@helia/ipns'
|
|
13
13
|
* import { unixfs } from '@helia/unixfs'
|
|
@@ -27,7 +27,78 @@
|
|
|
27
27
|
* await name.publish(peerId, cid)
|
|
28
28
|
*
|
|
29
29
|
* // resolve the name
|
|
30
|
-
* const
|
|
30
|
+
* const result = name.resolve(peerId)
|
|
31
|
+
*
|
|
32
|
+
* console.info(result.cid, result.path)
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Publishing a recursive record
|
|
36
|
+
*
|
|
37
|
+
* A recursive record is a one that points to another record rather than to a
|
|
38
|
+
* value.
|
|
39
|
+
*
|
|
40
|
+
* ```TypeScript
|
|
41
|
+
* import { createHelia } from 'helia'
|
|
42
|
+
* import { ipns } from '@helia/ipns'
|
|
43
|
+
* import { unixfs } from '@helia/unixfs'
|
|
44
|
+
*
|
|
45
|
+
* const helia = await createHelia()
|
|
46
|
+
* const name = ipns(helia)
|
|
47
|
+
*
|
|
48
|
+
* // create a public key to publish as an IPNS name
|
|
49
|
+
* const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
|
|
50
|
+
* const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
|
|
51
|
+
*
|
|
52
|
+
* // store some data to publish
|
|
53
|
+
* const fs = unixfs(helia)
|
|
54
|
+
* const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
55
|
+
*
|
|
56
|
+
* // publish the name
|
|
57
|
+
* await name.publish(peerId, cid)
|
|
58
|
+
*
|
|
59
|
+
* // create another public key to re-publish the original record
|
|
60
|
+
* const recursiveKeyInfo = await helia.libp2p.services.keychain.createKey('my-recursive-key')
|
|
61
|
+
* const recursivePeerId = await helia.libp2p.services.keychain.exportPeerId(recursiveKeyInfo.name)
|
|
62
|
+
*
|
|
63
|
+
* // publish the recursive name
|
|
64
|
+
* await name.publish(recursivePeerId, peerId)
|
|
65
|
+
*
|
|
66
|
+
* // resolve the name recursively - it resolves until a CID is found
|
|
67
|
+
* const result = name.resolve(recursivePeerId)
|
|
68
|
+
* console.info(result.cid.toString() === cid.toString()) // true
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example Publishing a record with a path
|
|
72
|
+
*
|
|
73
|
+
* It is possible to publish CIDs with an associated path.
|
|
74
|
+
*
|
|
75
|
+
* ```TypeScript
|
|
76
|
+
* import { createHelia } from 'helia'
|
|
77
|
+
* import { ipns } from '@helia/ipns'
|
|
78
|
+
* import { unixfs } from '@helia/unixfs'
|
|
79
|
+
*
|
|
80
|
+
* const helia = await createHelia()
|
|
81
|
+
* const name = ipns(helia)
|
|
82
|
+
*
|
|
83
|
+
* // create a public key to publish as an IPNS name
|
|
84
|
+
* const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
|
|
85
|
+
* const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
|
|
86
|
+
*
|
|
87
|
+
* // store some data to publish
|
|
88
|
+
* const fs = unixfs(helia)
|
|
89
|
+
* const fileCid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
90
|
+
*
|
|
91
|
+
* // store the file in a directory
|
|
92
|
+
* const dirCid = await fs.mkdir()
|
|
93
|
+
* const finalDirCid = await fs.cp(fileCid, dirCid, '/foo.txt')
|
|
94
|
+
*
|
|
95
|
+
* // publish the name
|
|
96
|
+
* await name.publish(peerId, `/ipfs/${finalDirCid}/foo.txt)
|
|
97
|
+
*
|
|
98
|
+
* // resolve the name
|
|
99
|
+
* const result = name.resolve(peerId)
|
|
100
|
+
*
|
|
101
|
+
* console.info(result.cid, result.path) // QmFoo.. 'foo.txt'
|
|
31
102
|
* ```
|
|
32
103
|
*
|
|
33
104
|
* @example Using custom PubSub router
|
|
@@ -46,7 +117,7 @@
|
|
|
46
117
|
* and multiple peers are listening on the topic(s), otherwise update messages
|
|
47
118
|
* may fail to be published with "Insufficient peers" errors.
|
|
48
119
|
*
|
|
49
|
-
* ```
|
|
120
|
+
* ```TypeScript
|
|
50
121
|
* import { createHelia, libp2pDefaults } from 'helia'
|
|
51
122
|
* import { ipns } from '@helia/ipns'
|
|
52
123
|
* import { pubsub } from '@helia/ipns/routing'
|
|
@@ -77,14 +148,14 @@
|
|
|
77
148
|
* await name.publish(peerId, cid)
|
|
78
149
|
*
|
|
79
150
|
* // resolve the name
|
|
80
|
-
* const cid = name.resolve(peerId)
|
|
151
|
+
* const { cid, path } = name.resolve(peerId)
|
|
81
152
|
* ```
|
|
82
153
|
*
|
|
83
154
|
* @example Using custom DNS over HTTPS resolvers
|
|
84
155
|
*
|
|
85
156
|
* With default {@link DNSResolver} resolvers:
|
|
86
157
|
*
|
|
87
|
-
* ```
|
|
158
|
+
* ```TypeScript
|
|
88
159
|
* import { createHelia } from 'helia'
|
|
89
160
|
* import { ipns } from '@helia/ipns'
|
|
90
161
|
* import { unixfs } from '@helia/unixfs'
|
|
@@ -97,14 +168,14 @@
|
|
|
97
168
|
* ]
|
|
98
169
|
* })
|
|
99
170
|
*
|
|
100
|
-
* const cid = name.resolveDns('some-domain-with-dnslink-entry.com')
|
|
171
|
+
* const { cid, path } = name.resolveDns('some-domain-with-dnslink-entry.com')
|
|
101
172
|
* ```
|
|
102
173
|
*
|
|
103
174
|
* @example Resolving a domain with a dnslink entry
|
|
104
175
|
*
|
|
105
176
|
* Calling `resolveDns` with the `@helia/ipns` instance:
|
|
106
177
|
*
|
|
107
|
-
* ```
|
|
178
|
+
* ```TypeScript
|
|
108
179
|
* // resolve a CID from a TXT record in a DNS zone file, using the default
|
|
109
180
|
* // resolver for the current platform eg:
|
|
110
181
|
* // > dig _dnslink.ipfs.io TXT
|
|
@@ -114,7 +185,7 @@
|
|
|
114
185
|
* // ;; ANSWER SECTION:
|
|
115
186
|
* // _dnslink.website.ipfs.io. 60 IN TXT "dnslink=/ipfs/QmWebsite"
|
|
116
187
|
*
|
|
117
|
-
* const cid = name.resolveDns('ipfs.io')
|
|
188
|
+
* const { cid, path } = name.resolveDns('ipfs.io')
|
|
118
189
|
*
|
|
119
190
|
* console.info(cid)
|
|
120
191
|
* // QmWebsite
|
|
@@ -128,11 +199,11 @@
|
|
|
128
199
|
*
|
|
129
200
|
* If this is a concern, use the DNS-JSON-Over-HTTPS resolver instead.
|
|
130
201
|
*
|
|
131
|
-
* ```
|
|
202
|
+
* ```TypeScript
|
|
132
203
|
* // use DNS-Over-HTTPS
|
|
133
204
|
* import { dnsOverHttps } from '@helia/ipns/dns-resolvers'
|
|
134
205
|
*
|
|
135
|
-
* const cid = name.resolveDns('ipfs.io', {
|
|
206
|
+
* const { cid, path } = name.resolveDns('ipfs.io', {
|
|
136
207
|
* resolvers: [
|
|
137
208
|
* dnsOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
|
|
138
209
|
* ]
|
|
@@ -144,11 +215,11 @@
|
|
|
144
215
|
* DNS-JSON-Over-HTTPS resolvers use the RFC 8427 `application/dns-json` and can
|
|
145
216
|
* result in a smaller browser bundle due to the response being plain JSON.
|
|
146
217
|
*
|
|
147
|
-
* ```
|
|
218
|
+
* ```TypeScript
|
|
148
219
|
* // use DNS-JSON-Over-HTTPS
|
|
149
220
|
* import { dnsJsonOverHttps } from '@helia/ipns/dns-resolvers'
|
|
150
221
|
*
|
|
151
|
-
* const cid = name.resolveDns('ipfs.io', {
|
|
222
|
+
* const { cid, path } = name.resolveDns('ipfs.io', {
|
|
152
223
|
* resolvers: [
|
|
153
224
|
* dnsJsonOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
|
|
154
225
|
* ]
|
|
@@ -249,15 +320,28 @@ class DefaultIPNS {
|
|
|
249
320
|
}
|
|
250
321
|
async #resolve(ipfsPath, options = {}) {
|
|
251
322
|
const parts = ipfsPath.split('/');
|
|
252
|
-
|
|
323
|
+
try {
|
|
253
324
|
const scheme = parts[1];
|
|
254
325
|
if (scheme === 'ipns') {
|
|
255
|
-
|
|
326
|
+
const { cid } = await this.resolve(peerIdFromString(parts[2]), options);
|
|
327
|
+
const path = parts.slice(3).join('/');
|
|
328
|
+
return {
|
|
329
|
+
cid,
|
|
330
|
+
path
|
|
331
|
+
};
|
|
256
332
|
}
|
|
257
333
|
else if (scheme === 'ipfs') {
|
|
258
|
-
|
|
334
|
+
const cid = CID.parse(parts[2]);
|
|
335
|
+
const path = parts.slice(3).join('/');
|
|
336
|
+
return {
|
|
337
|
+
cid,
|
|
338
|
+
path
|
|
339
|
+
};
|
|
259
340
|
}
|
|
260
341
|
}
|
|
342
|
+
catch (err) {
|
|
343
|
+
log.error('error parsing ipfs path', err);
|
|
344
|
+
}
|
|
261
345
|
log.error('invalid ipfs path %s', ipfsPath);
|
|
262
346
|
throw new Error('Invalid value');
|
|
263
347
|
}
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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C,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;AAOD,MAAM,UAAU,IAAI,CAAE,UAA0B,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,SAAS,GAAG,EAAE,KAAkB,EAAE;IAClG,OAAO,IAAI,WAAW,CAAC,UAAU,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;AACxD,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": "6.0.0-8a5bc6f",
|
|
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,7 +164,7 @@
|
|
|
164
164
|
"release": "aegir release"
|
|
165
165
|
},
|
|
166
166
|
"dependencies": {
|
|
167
|
-
"@helia/interface": "
|
|
167
|
+
"@helia/interface": "4.0.0-8a5bc6f",
|
|
168
168
|
"@libp2p/interface": "^1.1.1",
|
|
169
169
|
"@libp2p/kad-dht": "^12.0.2",
|
|
170
170
|
"@libp2p/logger": "^4.0.4",
|