@helia/ipns 7.2.3 → 8.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/README.md CHANGED
@@ -40,23 +40,23 @@ With IPNSRouting routers:
40
40
  import { createHelia } from 'helia'
41
41
  import { ipns } from '@helia/ipns'
42
42
  import { unixfs } from '@helia/unixfs'
43
+ import { generateKeyPair } from '@libp2p/crypto/keys'
43
44
 
44
45
  const helia = await createHelia()
45
46
  const name = ipns(helia)
46
47
 
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)
48
+ // create a keypair to publish an IPNS name
49
+ const privateKey = await generateKeyPair('Ed25519')
50
50
 
51
51
  // store some data to publish
52
52
  const fs = unixfs(helia)
53
- const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
53
+ const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
54
54
 
55
55
  // publish the name
56
- await name.publish(peerId, cid)
56
+ await name.publish(privateKey, cid)
57
57
 
58
58
  // resolve the name
59
- const result = name.resolve(peerId)
59
+ const result = await name.resolve(privateKey.publicKey)
60
60
 
61
61
  console.info(result.cid, result.path)
62
62
  ```
@@ -70,30 +70,29 @@ value.
70
70
  import { createHelia } from 'helia'
71
71
  import { ipns } from '@helia/ipns'
72
72
  import { unixfs } from '@helia/unixfs'
73
+ import { generateKeyPair } from '@libp2p/crypto/keys'
73
74
 
74
75
  const helia = await createHelia()
75
76
  const name = ipns(helia)
76
77
 
77
- // create a public key to publish as an IPNS name
78
- const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
79
- const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
78
+ // create a keypair to publish an IPNS name
79
+ const privateKey = await generateKeyPair('Ed25519')
80
80
 
81
81
  // store some data to publish
82
82
  const fs = unixfs(helia)
83
- const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
83
+ const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
84
84
 
85
85
  // publish the name
86
- await name.publish(peerId, cid)
86
+ await name.publish(privateKey, cid)
87
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)
88
+ // create another keypair to re-publish the original record
89
+ const recursivePrivateKey = await generateKeyPair('Ed25519')
91
90
 
92
91
  // publish the recursive name
93
- await name.publish(recursivePeerId, peerId)
92
+ await name.publish(recursivePrivateKey, privateKey.publicKey)
94
93
 
95
94
  // resolve the name recursively - it resolves until a CID is found
96
- const result = name.resolve(recursivePeerId)
95
+ const result = await name.resolve(recursivePrivateKey.publicKey)
97
96
  console.info(result.cid.toString() === cid.toString()) // true
98
97
  ```
99
98
 
@@ -105,27 +104,27 @@ It is possible to publish CIDs with an associated path.
105
104
  import { createHelia } from 'helia'
106
105
  import { ipns } from '@helia/ipns'
107
106
  import { unixfs } from '@helia/unixfs'
107
+ import { generateKeyPair } from '@libp2p/crypto/keys'
108
108
 
109
109
  const helia = await createHelia()
110
110
  const name = ipns(helia)
111
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)
112
+ // create a keypair to publish an IPNS name
113
+ const privateKey = await generateKeyPair('Ed25519')
115
114
 
116
115
  // store some data to publish
117
116
  const fs = unixfs(helia)
118
- const fileCid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
117
+ const fileCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
119
118
 
120
119
  // store the file in a directory
121
- const dirCid = await fs.mkdir()
120
+ const dirCid = await fs.addDirectory()
122
121
  const finalDirCid = await fs.cp(fileCid, dirCid, '/foo.txt')
123
122
 
124
123
  // publish the name
125
- await name.publish(peerId, `/ipfs/${finalDirCid}/foo.txt)
124
+ await name.publish(privateKey, `/ipfs/${finalDirCid}/foo.txt`)
126
125
 
127
126
  // resolve the name
128
- const result = name.resolve(peerId)
127
+ const result = await name.resolve(privateKey.publicKey)
129
128
 
130
129
  console.info(result.cid, result.path) // QmFoo.. 'foo.txt'
131
130
  ```
@@ -152,11 +151,14 @@ import { ipns } from '@helia/ipns'
152
151
  import { pubsub } from '@helia/ipns/routing'
153
152
  import { unixfs } from '@helia/unixfs'
154
153
  import { gossipsub } from '@chainsafe/libp2p-gossipsub'
154
+ import { generateKeyPair } from '@libp2p/crypto/keys'
155
+ import type { Libp2p, PubSub } from '@libp2p/interface'
156
+ import type { DefaultLibp2pServices } from 'helia'
155
157
 
156
158
  const libp2pOptions = libp2pDefaults()
157
159
  libp2pOptions.services.pubsub = gossipsub()
158
160
 
159
- const helia = await createHelia({
161
+ const helia = await createHelia<Libp2p<DefaultLibp2pServices & { pubsub: PubSub }>>({
160
162
  libp2p: libp2pOptions
161
163
  })
162
164
  const name = ipns(helia, {
@@ -165,44 +167,50 @@ const name = ipns(helia, {
165
167
  ]
166
168
  })
167
169
 
168
- // create a public key to publish as an IPNS name
169
- const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
170
- const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
170
+ // create a keypair to publish an IPNS name
171
+ const privateKey = await generateKeyPair('Ed25519')
171
172
 
172
173
  // store some data to publish
173
174
  const fs = unixfs(helia)
174
- const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
175
+ const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
175
176
 
176
177
  // publish the name
177
- await name.publish(peerId, cid)
178
+ await name.publish(privateKey, cid)
178
179
 
179
180
  // resolve the name
180
- const { cid, path } = name.resolve(peerId)
181
+ const result = await name.resolve(privateKey.publicKey)
181
182
  ```
182
183
 
183
184
  ## Example - Using custom DNS over HTTPS resolvers
184
185
 
185
- With default DNSResolver resolvers:
186
+ To use custom resolvers, configure Helia's `dns` option:
186
187
 
187
188
  ```TypeScript
188
189
  import { createHelia } from 'helia'
189
190
  import { ipns } from '@helia/ipns'
190
- import { unixfs } from '@helia/unixfs'
191
- import { dnsOverHttps } from '@helia/ipns/dns-resolvers'
192
-
193
- const helia = await createHelia()
194
- const name = ipns(helia, {
195
- resolvers: [
196
- dnsOverHttps('https://private-dns-server.me/dns-query'),
191
+ import { dns } from '@multiformats/dns'
192
+ import { dnsOverHttps } from '@multiformats/dns/resolvers'
193
+ import { helia } from '@helia/ipns/routing'
194
+
195
+ const node = await createHelia({
196
+ dns: dns({
197
+ resolvers: {
198
+ '.': dnsOverHttps('https://private-dns-server.me/dns-query')
199
+ }
200
+ })
201
+ })
202
+ const name = ipns(node, {
203
+ routers: [
204
+ helia(node.routing)
197
205
  ]
198
206
  })
199
207
 
200
- const { cid, path } = name.resolveDns('some-domain-with-dnslink-entry.com')
208
+ const result = name.resolveDNSLink('some-domain-with-dnslink-entry.com')
201
209
  ```
202
210
 
203
211
  ## Example - Resolving a domain with a dnslink entry
204
212
 
205
- Calling `resolveDns` with the `@helia/ipns` instance:
213
+ Calling `resolveDNSLink` with the `@helia/ipns` instance:
206
214
 
207
215
  ```TypeScript
208
216
  // resolve a CID from a TXT record in a DNS zone file, using the default
@@ -214,10 +222,16 @@ Calling `resolveDns` with the `@helia/ipns` instance:
214
222
  // ;; ANSWER SECTION:
215
223
  // _dnslink.website.ipfs.io. 60 IN TXT "dnslink=/ipfs/QmWebsite"
216
224
 
217
- const { cid, path } = name.resolveDns('ipfs.io')
225
+ import { createHelia } from 'helia'
226
+ import { ipns } from '@helia/ipns'
227
+
228
+ const node = await createHelia()
229
+ const name = ipns(node)
218
230
 
219
- console.info(cid)
220
- // QmWebsite
231
+ const { answer } = await name.resolveDNSLink('ipfs.io')
232
+
233
+ console.info(answer)
234
+ // { data: '/ipfs/QmWebsite' }
221
235
  ```
222
236
 
223
237
  ## Example - Using DNS-Over-HTTPS
@@ -229,14 +243,21 @@ response which can increase browser bundle sizes.
229
243
  If this is a concern, use the DNS-JSON-Over-HTTPS resolver instead.
230
244
 
231
245
  ```TypeScript
232
- // use DNS-Over-HTTPS
233
- import { dnsOverHttps } from '@helia/ipns/dns-resolvers'
234
-
235
- const { cid, path } = name.resolveDns('ipfs.io', {
236
- resolvers: [
237
- dnsOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
238
- ]
246
+ import { createHelia } from 'helia'
247
+ import { ipns } from '@helia/ipns'
248
+ import { dns } from '@multiformats/dns'
249
+ import { dnsOverHttps } from '@multiformats/dns/resolvers'
250
+
251
+ const node = await createHelia({
252
+ dns: dns({
253
+ resolvers: {
254
+ '.': dnsOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
255
+ }
256
+ })
239
257
  })
258
+ const name = ipns(node)
259
+
260
+ const result = await name.resolveDNSLink('ipfs.io')
240
261
  ```
241
262
 
242
263
  ## Example - Using DNS-JSON-Over-HTTPS
@@ -245,14 +266,21 @@ DNS-JSON-Over-HTTPS resolvers use the RFC 8427 `application/dns-json` and can
245
266
  result in a smaller browser bundle due to the response being plain JSON.
246
267
 
247
268
  ```TypeScript
248
- // use DNS-JSON-Over-HTTPS
249
- import { dnsJsonOverHttps } from '@helia/ipns/dns-resolvers'
250
-
251
- const { cid, path } = name.resolveDns('ipfs.io', {
252
- resolvers: [
253
- dnsJsonOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
254
- ]
269
+ import { createHelia } from 'helia'
270
+ import { ipns } from '@helia/ipns'
271
+ import { dns } from '@multiformats/dns'
272
+ import { dnsJsonOverHttps } from '@multiformats/dns/resolvers'
273
+
274
+ const node = await createHelia({
275
+ dns: dns({
276
+ resolvers: {
277
+ '.': dnsJsonOverHttps('https://mozilla.cloudflare-dns.com/dns-query')
278
+ }
279
+ })
255
280
  })
281
+ const name = ipns(node)
282
+
283
+ const result = await name.resolveDNSLink('ipfs.io')
256
284
  ```
257
285
 
258
286
  # Install