@helia/ipns 5.0.0 → 6.0.0-1319c61
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 +99 -13
- 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/dist/src/utils/dns.d.ts.map +1 -1
- package/dist/src/utils/dns.js +7 -6
- package/dist/src/utils/dns.js.map +1 -1
- package/package.json +15 -16
- package/src/index.ts +111 -24
- package/src/utils/dns.ts +8 -7
- package/dist/typedoc-urls.json +0 -42
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
|
-
# @helia/ipns
|
|
7
|
+
# @helia/ipns
|
|
8
8
|
|
|
9
9
|
[](https://ipfs.tech)
|
|
10
10
|
[](https://discuss.ipfs.tech)
|
|
@@ -15,13 +15,58 @@
|
|
|
15
15
|
|
|
16
16
|
# About
|
|
17
17
|
|
|
18
|
+
<!--
|
|
19
|
+
|
|
20
|
+
!IMPORTANT!
|
|
21
|
+
|
|
22
|
+
Everything in this README between "# About" and "# Install" is automatically
|
|
23
|
+
generated and will be overwritten the next time the doc generator is run.
|
|
24
|
+
|
|
25
|
+
To make changes to this section, please update the @packageDocumentation section
|
|
26
|
+
of src/index.js or src/index.ts
|
|
27
|
+
|
|
28
|
+
To experiment with formatting, please run "npm run docs" from the root of this
|
|
29
|
+
repo and examine the changes made.
|
|
30
|
+
|
|
31
|
+
-->
|
|
32
|
+
|
|
18
33
|
IPNS operations using a Helia node
|
|
19
34
|
|
|
20
35
|
## Example - Getting started
|
|
21
36
|
|
|
22
37
|
With IPNSRouting routers:
|
|
23
38
|
|
|
24
|
-
```
|
|
39
|
+
```TypeScript
|
|
40
|
+
import { createHelia } from 'helia'
|
|
41
|
+
import { ipns } from '@helia/ipns'
|
|
42
|
+
import { unixfs } from '@helia/unixfs'
|
|
43
|
+
|
|
44
|
+
const helia = await createHelia()
|
|
45
|
+
const name = ipns(helia)
|
|
46
|
+
|
|
47
|
+
// create a public key to publish as an IPNS name
|
|
48
|
+
const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
|
|
49
|
+
const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
|
|
50
|
+
|
|
51
|
+
// store some data to publish
|
|
52
|
+
const fs = unixfs(helia)
|
|
53
|
+
const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
54
|
+
|
|
55
|
+
// publish the name
|
|
56
|
+
await name.publish(peerId, cid)
|
|
57
|
+
|
|
58
|
+
// resolve the name
|
|
59
|
+
const result = name.resolve(peerId)
|
|
60
|
+
|
|
61
|
+
console.info(result.cid, result.path)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Example - Publishing a recursive record
|
|
65
|
+
|
|
66
|
+
A recursive record is a one that points to another record rather than to a
|
|
67
|
+
value.
|
|
68
|
+
|
|
69
|
+
```TypeScript
|
|
25
70
|
import { createHelia } from 'helia'
|
|
26
71
|
import { ipns } from '@helia/ipns'
|
|
27
72
|
import { unixfs } from '@helia/unixfs'
|
|
@@ -40,8 +85,49 @@ const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
|
40
85
|
// publish the name
|
|
41
86
|
await name.publish(peerId, cid)
|
|
42
87
|
|
|
88
|
+
// create another public key to re-publish the original record
|
|
89
|
+
const recursiveKeyInfo = await helia.libp2p.services.keychain.createKey('my-recursive-key')
|
|
90
|
+
const recursivePeerId = await helia.libp2p.services.keychain.exportPeerId(recursiveKeyInfo.name)
|
|
91
|
+
|
|
92
|
+
// publish the recursive name
|
|
93
|
+
await name.publish(recursivePeerId, peerId)
|
|
94
|
+
|
|
95
|
+
// resolve the name recursively - it resolves until a CID is found
|
|
96
|
+
const result = name.resolve(recursivePeerId)
|
|
97
|
+
console.info(result.cid.toString() === cid.toString()) // true
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Example - Publishing a record with a path
|
|
101
|
+
|
|
102
|
+
It is possible to publish CIDs with an associated path.
|
|
103
|
+
|
|
104
|
+
```TypeScript
|
|
105
|
+
import { createHelia } from 'helia'
|
|
106
|
+
import { ipns } from '@helia/ipns'
|
|
107
|
+
import { unixfs } from '@helia/unixfs'
|
|
108
|
+
|
|
109
|
+
const helia = await createHelia()
|
|
110
|
+
const name = ipns(helia)
|
|
111
|
+
|
|
112
|
+
// create a public key to publish as an IPNS name
|
|
113
|
+
const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
|
|
114
|
+
const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
|
|
115
|
+
|
|
116
|
+
// store some data to publish
|
|
117
|
+
const fs = unixfs(helia)
|
|
118
|
+
const fileCid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
119
|
+
|
|
120
|
+
// store the file in a directory
|
|
121
|
+
const dirCid = await fs.mkdir()
|
|
122
|
+
const finalDirCid = await fs.cp(fileCid, dirCid, '/foo.txt')
|
|
123
|
+
|
|
124
|
+
// publish the name
|
|
125
|
+
await name.publish(peerId, `/ipfs/${finalDirCid}/foo.txt)
|
|
126
|
+
|
|
43
127
|
// resolve the name
|
|
44
|
-
const
|
|
128
|
+
const result = name.resolve(peerId)
|
|
129
|
+
|
|
130
|
+
console.info(result.cid, result.path) // QmFoo.. 'foo.txt'
|
|
45
131
|
```
|
|
46
132
|
|
|
47
133
|
## Example - Using custom PubSub router
|
|
@@ -60,7 +146,7 @@ This router is only suitable for networks where IPNS updates are frequent
|
|
|
60
146
|
and multiple peers are listening on the topic(s), otherwise update messages
|
|
61
147
|
may fail to be published with "Insufficient peers" errors.
|
|
62
148
|
|
|
63
|
-
```
|
|
149
|
+
```TypeScript
|
|
64
150
|
import { createHelia, libp2pDefaults } from 'helia'
|
|
65
151
|
import { ipns } from '@helia/ipns'
|
|
66
152
|
import { pubsub } from '@helia/ipns/routing'
|
|
@@ -91,14 +177,14 @@ const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
|
91
177
|
await name.publish(peerId, cid)
|
|
92
178
|
|
|
93
179
|
// resolve the name
|
|
94
|
-
const cid = name.resolve(peerId)
|
|
180
|
+
const { cid, path } = name.resolve(peerId)
|
|
95
181
|
```
|
|
96
182
|
|
|
97
183
|
## Example - Using custom DNS over HTTPS resolvers
|
|
98
184
|
|
|
99
185
|
With default DNSResolver resolvers:
|
|
100
186
|
|
|
101
|
-
```
|
|
187
|
+
```TypeScript
|
|
102
188
|
import { createHelia } from 'helia'
|
|
103
189
|
import { ipns } from '@helia/ipns'
|
|
104
190
|
import { unixfs } from '@helia/unixfs'
|
|
@@ -111,14 +197,14 @@ const name = ipns(helia, {
|
|
|
111
197
|
]
|
|
112
198
|
})
|
|
113
199
|
|
|
114
|
-
const cid = name.resolveDns('some-domain-with-dnslink-entry.com')
|
|
200
|
+
const { cid, path } = name.resolveDns('some-domain-with-dnslink-entry.com')
|
|
115
201
|
```
|
|
116
202
|
|
|
117
203
|
## Example - Resolving a domain with a dnslink entry
|
|
118
204
|
|
|
119
205
|
Calling `resolveDns` with the `@helia/ipns` instance:
|
|
120
206
|
|
|
121
|
-
```
|
|
207
|
+
```TypeScript
|
|
122
208
|
// resolve a CID from a TXT record in a DNS zone file, using the default
|
|
123
209
|
// resolver for the current platform eg:
|
|
124
210
|
// > dig _dnslink.ipfs.io TXT
|
|
@@ -128,7 +214,7 @@ Calling `resolveDns` with the `@helia/ipns` instance:
|
|
|
128
214
|
// ;; ANSWER SECTION:
|
|
129
215
|
// _dnslink.website.ipfs.io. 60 IN TXT "dnslink=/ipfs/QmWebsite"
|
|
130
216
|
|
|
131
|
-
const cid = name.resolveDns('ipfs.io')
|
|
217
|
+
const { cid, path } = name.resolveDns('ipfs.io')
|
|
132
218
|
|
|
133
219
|
console.info(cid)
|
|
134
220
|
// QmWebsite
|
|
@@ -142,11 +228,11 @@ response which can increase browser bundle sizes.
|
|
|
142
228
|
|
|
143
229
|
If this is a concern, use the DNS-JSON-Over-HTTPS resolver instead.
|
|
144
230
|
|
|
145
|
-
```
|
|
231
|
+
```TypeScript
|
|
146
232
|
// use DNS-Over-HTTPS
|
|
147
233
|
import { dnsOverHttps } from '@helia/ipns/dns-resolvers'
|
|
148
234
|
|
|
149
|
-
const cid = name.resolveDns('ipfs.io', {
|
|
235
|
+
const { cid, path } = name.resolveDns('ipfs.io', {
|
|
150
236
|
resolvers: [
|
|
151
237
|
dnsOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
|
|
152
238
|
]
|
|
@@ -158,11 +244,11 @@ const cid = name.resolveDns('ipfs.io', {
|
|
|
158
244
|
DNS-JSON-Over-HTTPS resolvers use the RFC 8427 `application/dns-json` and can
|
|
159
245
|
result in a smaller browser bundle due to the response being plain JSON.
|
|
160
246
|
|
|
161
|
-
```
|
|
247
|
+
```TypeScript
|
|
162
248
|
// use DNS-JSON-Over-HTTPS
|
|
163
249
|
import { dnsJsonOverHttps } from '@helia/ipns/dns-resolvers'
|
|
164
250
|
|
|
165
|
-
const cid = name.resolveDns('ipfs.io', {
|
|
251
|
+
const { cid, path } = name.resolveDns('ipfs.io', {
|
|
166
252
|
resolvers: [
|
|
167
253
|
dnsJsonOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
|
|
168
254
|
]
|