@helia/ipns 9.2.0 → 9.2.1-17530ed8
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 +21 -57
- package/dist/index.min.js +9 -23
- package/dist/index.min.js.map +4 -4
- package/dist/src/errors.d.ts +33 -5
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +33 -20
- package/dist/src/errors.js.map +1 -1
- package/dist/src/index.d.ts +62 -99
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +21 -60
- package/dist/src/index.js.map +1 -1
- package/dist/src/ipns/publisher.d.ts +5 -9
- package/dist/src/ipns/publisher.d.ts.map +1 -1
- package/dist/src/ipns/publisher.js +30 -22
- package/dist/src/ipns/publisher.js.map +1 -1
- package/dist/src/ipns/republisher.d.ts +3 -5
- package/dist/src/ipns/republisher.d.ts.map +1 -1
- package/dist/src/ipns/republisher.js +18 -9
- package/dist/src/ipns/republisher.js.map +1 -1
- package/dist/src/ipns/resolver.d.ts +6 -5
- package/dist/src/ipns/resolver.d.ts.map +1 -1
- package/dist/src/ipns/resolver.js +32 -78
- package/dist/src/ipns/resolver.js.map +1 -1
- package/dist/src/ipns.d.ts +6 -4
- package/dist/src/ipns.d.ts.map +1 -1
- package/dist/src/ipns.js +33 -4
- package/dist/src/ipns.js.map +1 -1
- package/dist/src/pb/ipns.d.ts +62 -0
- package/dist/src/pb/ipns.d.ts.map +1 -0
- package/dist/src/pb/ipns.js +203 -0
- package/dist/src/pb/ipns.js.map +1 -0
- package/dist/src/pb/metadata.d.ts +1 -1
- package/dist/src/pb/metadata.d.ts.map +1 -1
- package/dist/src/records.d.ts +155 -0
- package/dist/src/records.d.ts.map +1 -0
- package/dist/src/records.js +88 -0
- package/dist/src/records.js.map +1 -0
- package/dist/src/routing/pubsub.d.ts +3 -0
- package/dist/src/routing/pubsub.d.ts.map +1 -1
- package/dist/src/routing/pubsub.js +15 -10
- package/dist/src/routing/pubsub.js.map +1 -1
- package/dist/src/selector.d.ts +14 -0
- package/dist/src/selector.d.ts.map +1 -0
- package/dist/src/selector.js +47 -0
- package/dist/src/selector.js.map +1 -0
- package/dist/src/utils.d.ts +29 -2
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +308 -0
- package/dist/src/utils.js.map +1 -1
- package/dist/src/validator.d.ts +18 -0
- package/dist/src/validator.d.ts.map +1 -0
- package/dist/src/validator.js +58 -0
- package/dist/src/validator.js.map +1 -0
- package/package.json +32 -28
- package/src/errors.ts +40 -25
- package/src/index.ts +63 -100
- package/src/ipns/publisher.ts +34 -29
- package/src/ipns/republisher.ts +24 -13
- package/src/ipns/resolver.ts +40 -88
- package/src/ipns.ts +44 -7
- package/src/pb/ipns.proto +39 -0
- package/src/pb/ipns.ts +280 -0
- package/src/pb/metadata.ts +1 -1
- package/src/records.ts +273 -0
- package/src/routing/pubsub.ts +17 -10
- package/src/selector.ts +55 -0
- package/src/utils.ts +371 -2
- package/src/validator.ts +67 -0
- package/dist/typedoc-urls.json +0 -51
package/README.md
CHANGED
|
@@ -52,9 +52,9 @@ const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
|
52
52
|
const { publicKey } = await name.publish('key-1', cid)
|
|
53
53
|
|
|
54
54
|
// resolve the name
|
|
55
|
-
const result
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
for await (const result of name.resolve(publicKey)) {
|
|
56
|
+
console.info(result.record.value) // /ipfs/QmFoo
|
|
57
|
+
}
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
## Example - Publishing a recursive record
|
|
@@ -82,8 +82,9 @@ const { publicKey } = await name.publish('key-1', cid)
|
|
|
82
82
|
const { publicKey: recursivePublicKey } = await name.publish('key-2', publicKey)
|
|
83
83
|
|
|
84
84
|
// resolve the name recursively - it resolves until a CID is found
|
|
85
|
-
const result
|
|
86
|
-
console.info(result.
|
|
85
|
+
for await (const result of name.resolve(recursivePublicKey)) {
|
|
86
|
+
console.info(result.record.value) // /ipfs/QmFoo../foo.txt
|
|
87
|
+
}
|
|
87
88
|
```
|
|
88
89
|
|
|
89
90
|
## Example - Publishing a record with a path
|
|
@@ -111,9 +112,9 @@ const finalDirCid = await fs.cp(fileCid, dirCid, '/foo.txt')
|
|
|
111
112
|
const { publicKey } = await name.publish('key-1', `/ipfs/${finalDirCid}/foo.txt`)
|
|
112
113
|
|
|
113
114
|
// resolve the name
|
|
114
|
-
const result
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
for await (const result of name.resolve(publicKey)) {
|
|
116
|
+
console.info(result.record.value) // /ipfs/QmFoo../foo.txt
|
|
117
|
+
}
|
|
117
118
|
```
|
|
118
119
|
|
|
119
120
|
## Example - Using custom PubSub router
|
|
@@ -133,29 +134,30 @@ and multiple peers are listening on the topic(s), otherwise update messages
|
|
|
133
134
|
may fail to be published with "Insufficient peers" errors.
|
|
134
135
|
|
|
135
136
|
```TypeScript
|
|
136
|
-
import { createHelia, libp2pDefaults } from 'helia'
|
|
137
137
|
import { ipns } from '@helia/ipns'
|
|
138
138
|
import { pubsub } from '@helia/ipns/routing'
|
|
139
|
+
import { withLibp2p, libp2pDefaults } from '@helia/libp2p'
|
|
139
140
|
import { unixfs } from '@helia/unixfs'
|
|
140
|
-
import { floodsub } from '@libp2p/floodsub'
|
|
141
141
|
import { generateKeyPair } from '@libp2p/crypto/keys'
|
|
142
|
+
import { floodsub } from '@libp2p/floodsub'
|
|
143
|
+
import { createHelia } from 'helia'
|
|
144
|
+
import type { Helia } from '@helia/interface'
|
|
142
145
|
import type { PubSub } from '@helia/ipns/routing'
|
|
146
|
+
import type { DefaultLibp2pServices } from '@helia/libp2p'
|
|
147
|
+
import type { FloodSub } from '@libp2p/floodsub'
|
|
143
148
|
import type { Libp2p } from '@libp2p/interface'
|
|
144
|
-
import type { DefaultLibp2pServices } from 'helia'
|
|
145
149
|
|
|
146
|
-
const libp2pOptions = libp2pDefaults()
|
|
150
|
+
const libp2pOptions = libp2pDefaults() as any
|
|
147
151
|
libp2pOptions.services.pubsub = floodsub()
|
|
148
152
|
|
|
149
|
-
const helia = await
|
|
150
|
-
|
|
151
|
-
})
|
|
153
|
+
const helia = await withLibp2p<Helia, { pubsub: FloodSub }>(createHelia(), libp2pOptions).start()
|
|
154
|
+
|
|
152
155
|
const name = ipns(helia, {
|
|
153
156
|
routers: [
|
|
154
157
|
pubsub(helia)
|
|
155
158
|
]
|
|
156
159
|
})
|
|
157
160
|
|
|
158
|
-
|
|
159
161
|
// store some data to publish
|
|
160
162
|
const fs = unixfs(helia)
|
|
161
163
|
const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
@@ -164,47 +166,9 @@ const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
|
164
166
|
const { publicKey } = await name.publish('key-1', cid)
|
|
165
167
|
|
|
166
168
|
// resolve the name
|
|
167
|
-
const result
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
## Example - Republishing an existing IPNS record
|
|
171
|
-
|
|
172
|
-
It is sometimes useful to be able to republish an existing IPNS record
|
|
173
|
-
without needing the private key. This allows you to extend the availability
|
|
174
|
-
of a record that was created elsewhere.
|
|
175
|
-
|
|
176
|
-
```TypeScript
|
|
177
|
-
import { createHelia } from 'helia'
|
|
178
|
-
import { ipns, ipnsValidator } from '@helia/ipns'
|
|
179
|
-
import { delegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
|
|
180
|
-
import { CID } from 'multiformats/cid'
|
|
181
|
-
import { multihashToIPNSRoutingKey, marshalIPNSRecord } from 'ipns'
|
|
182
|
-
import { defaultLogger } from '@libp2p/logger'
|
|
183
|
-
|
|
184
|
-
const helia = await createHelia()
|
|
185
|
-
const name = ipns(helia)
|
|
186
|
-
|
|
187
|
-
const ipnsName = 'k51qzi5uqu5dktsyfv7xz8h631pri4ct7osmb43nibxiojpttxzoft6hdyyzg4'
|
|
188
|
-
const parsedCid: CID<unknown, 114, 0 | 18, 1> = CID.parse(ipnsName)
|
|
189
|
-
const delegatedClient = delegatedRoutingV1HttpApiClient({
|
|
190
|
-
url: 'https://delegated-ipfs.dev'
|
|
191
|
-
})({
|
|
192
|
-
logger: defaultLogger()
|
|
193
|
-
})
|
|
194
|
-
const record = await delegatedClient.getIPNS(parsedCid)
|
|
195
|
-
|
|
196
|
-
const routingKey = multihashToIPNSRoutingKey(parsedCid.multihash)
|
|
197
|
-
const marshaledRecord = marshalIPNSRecord(record)
|
|
198
|
-
|
|
199
|
-
// validate that they key corresponds to the record
|
|
200
|
-
await ipnsValidator(routingKey, marshaledRecord)
|
|
201
|
-
|
|
202
|
-
// publish record to routing
|
|
203
|
-
await Promise.all(
|
|
204
|
-
name.routers.map(async r => {
|
|
205
|
-
await r.put(routingKey, marshaledRecord)
|
|
206
|
-
})
|
|
207
|
-
)
|
|
169
|
+
for await (const result of name.resolve(publicKey)) {
|
|
170
|
+
console.info(result.record.value)
|
|
171
|
+
}
|
|
208
172
|
```
|
|
209
173
|
|
|
210
174
|
# Install
|