@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 +41 -3
- package/dist/index.min.js +4 -4
- package/dist/src/index.d.ts +44 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +47 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/routing/helia.d.ts +20 -0
- package/dist/src/routing/helia.d.ts.map +1 -0
- package/dist/src/routing/helia.js +32 -0
- package/dist/src/routing/helia.js.map +1 -0
- package/dist/src/routing/index.d.ts +3 -3
- package/dist/src/routing/index.d.ts.map +1 -1
- package/dist/src/routing/index.js +1 -1
- package/dist/src/routing/index.js.map +1 -1
- package/package.json +3 -4
- package/src/index.ts +49 -5
- package/src/routing/helia.ts +45 -0
- package/src/routing/index.ts +3 -3
- package/dist/src/routing/libp2p.d.ts +0 -22
- package/dist/src/routing/libp2p.d.ts.map +0 -1
- package/dist/src/routing/libp2p.js +0 -32
- package/dist/src/routing/libp2p.js.map +0 -1
- package/src/routing/libp2p.ts +0 -47
package/README.md
CHANGED
|
@@ -17,20 +17,58 @@
|
|
|
17
17
|
|
|
18
18
|
IPNS operations using a Helia node
|
|
19
19
|
|
|
20
|
-
## Example -
|
|
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 {
|
|
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
|
})
|