@helia/ipns 4.0.0 → 5.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
@@ -8,8 +8,8 @@
8
8
 
9
9
  [![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
10
10
  [![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
11
- [![codecov](https://img.shields.io/codecov/c/github/ipfs/helia-ipns.svg?style=flat-square)](https://codecov.io/gh/ipfs/helia-ipns)
12
- [![CI](https://img.shields.io/github/actions/workflow/status/ipfs/helia-ipns/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/helia-ipns/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
11
+ [![codecov](https://img.shields.io/codecov/c/github/ipfs/helia.svg?style=flat-square)](https://codecov.io/gh/ipfs/helia)
12
+ [![CI](https://img.shields.io/github/actions/workflow/status/ipfs/helia/main.yml?branch=main\&style=flat-square)](https://github.com/ipfs/helia/actions/workflows/main.yml?query=branch%3Amain)
13
13
 
14
14
  > An implementation of IPNS for Helia
15
15
 
@@ -17,20 +17,64 @@
17
17
 
18
18
  IPNS operations using a Helia node
19
19
 
20
- ## Example - Using libp2p and pubsub routers
20
+ ## Example - Getting started
21
21
 
22
22
  With IPNSRouting routers:
23
23
 
24
24
  ```typescript
25
25
  import { createHelia } from 'helia'
26
26
  import { ipns } from '@helia/ipns'
27
- import { libp2p, pubsub } from '@helia/ipns/routing'
28
27
  import { unixfs } from '@helia/unixfs'
29
28
 
30
29
  const helia = await createHelia()
30
+ const name = ipns(helia)
31
+
32
+ // create a public key to publish as an IPNS name
33
+ const keyInfo = await helia.libp2p.services.keychain.createKey('my-key')
34
+ const peerId = await helia.libp2p.services.keychain.exportPeerId(keyInfo.name)
35
+
36
+ // store some data to publish
37
+ const fs = unixfs(helia)
38
+ const cid = await fs.add(Uint8Array.from([0, 1, 2, 3, 4]))
39
+
40
+ // publish the name
41
+ await name.publish(peerId, cid)
42
+
43
+ // resolve the name
44
+ const cid = name.resolve(peerId)
45
+ ```
46
+
47
+ ## Example - Using custom PubSub router
48
+
49
+ Additional IPNS routers can be configured - these enable alternative means to
50
+ publish and resolve IPNS names.
51
+
52
+ One example is the PubSub router - this requires an instance of Helia with
53
+ libp2p PubSub configured.
54
+
55
+ It works by subscribing to a pubsub topic for each IPNS name that we try to
56
+ resolve. Updated IPNS records are shared on these topics so an update must
57
+ occur before the name is resolvable.
58
+
59
+ This router is only suitable for networks where IPNS updates are frequent
60
+ and multiple peers are listening on the topic(s), otherwise update messages
61
+ may fail to be published with "Insufficient peers" errors.
62
+
63
+ ```typescript
64
+ import { createHelia, libp2pDefaults } from 'helia'
65
+ import { ipns } from '@helia/ipns'
66
+ import { pubsub } from '@helia/ipns/routing'
67
+ import { unixfs } from '@helia/unixfs'
68
+ import { gossipsub } from '@chainsafe/libp2p-gossipsub'
69
+
70
+ const libp2pOptions = libp2pDefaults()
71
+ libp2pOptions.services.pubsub = gossipsub()
72
+
73
+ const helia = await createHelia({
74
+ libp2p: libp2pOptions
75
+ })
31
76
  const name = ipns(helia, {
32
77
  routers: [
33
- libp2p(helia),
34
78
  pubsub(helia)
35
79
  ]
36
80
  })
@@ -141,7 +185,7 @@ Loading this module through a script tag will make it's exports available as `He
141
185
 
142
186
  # API Docs
143
187
 
144
- - <https://ipfs.github.io/helia-ipns/modules/_helia_ipns.html>
188
+ - <https://ipfs.github.io/helia/modules/_helia_ipns.html>
145
189
 
146
190
  # License
147
191
 
@@ -152,7 +196,7 @@ Licensed under either of
152
196
 
153
197
  # Contribute
154
198
 
155
- Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia-ipns/issues).
199
+ Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia/issues).
156
200
 
157
201
  Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.
158
202