@helia/ipns 9.2.1-35b081c7 → 9.2.1-73a28eda
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 +12 -49
- package/dist/index.min.js +5 -16
- 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 +53 -91
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +12 -52
- 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 +18 -17
- package/src/errors.ts +40 -25
- package/src/index.ts +54 -92
- 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/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
|
|
@@ -164,47 +165,9 @@ const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
|
|
|
164
165
|
const { publicKey } = await name.publish('key-1', cid)
|
|
165
166
|
|
|
166
167
|
// 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
|
-
)
|
|
168
|
+
for await (const result of name.resolve(publicKey)) {
|
|
169
|
+
console.info(result.record.value)
|
|
170
|
+
}
|
|
208
171
|
```
|
|
209
172
|
|
|
210
173
|
# Install
|