@helia/ipns 4.0.0-3477b27 → 4.0.0-5a87bbd

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
@@ -17,20 +17,58 @@
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'
27
+ import { unixfs } from '@helia/unixfs'
28
+
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 } from 'helia'
65
+ import { ipns } from '@helia/ipns'
66
+ import { pubsub } from '@helia/ipns/routing'
28
67
  import { unixfs } from '@helia/unixfs'
29
68
 
30
69
  const helia = await createHelia()
31
70
  const name = ipns(helia, {
32
71
  routers: [
33
- libp2p(helia),
34
72
  pubsub(helia)
35
73
  ]
36
74
  })