@helia/ipns 9.2.1-6f8165b5 → 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.
Files changed (65) hide show
  1. package/README.md +12 -49
  2. package/dist/index.min.js +5 -16
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/errors.d.ts +33 -5
  5. package/dist/src/errors.d.ts.map +1 -1
  6. package/dist/src/errors.js +33 -20
  7. package/dist/src/errors.js.map +1 -1
  8. package/dist/src/index.d.ts +53 -91
  9. package/dist/src/index.d.ts.map +1 -1
  10. package/dist/src/index.js +12 -52
  11. package/dist/src/index.js.map +1 -1
  12. package/dist/src/ipns/publisher.d.ts +5 -9
  13. package/dist/src/ipns/publisher.d.ts.map +1 -1
  14. package/dist/src/ipns/publisher.js +30 -26
  15. package/dist/src/ipns/publisher.js.map +1 -1
  16. package/dist/src/ipns/republisher.d.ts +3 -5
  17. package/dist/src/ipns/republisher.d.ts.map +1 -1
  18. package/dist/src/ipns/republisher.js +18 -9
  19. package/dist/src/ipns/republisher.js.map +1 -1
  20. package/dist/src/ipns/resolver.d.ts +6 -5
  21. package/dist/src/ipns/resolver.d.ts.map +1 -1
  22. package/dist/src/ipns/resolver.js +32 -79
  23. package/dist/src/ipns/resolver.js.map +1 -1
  24. package/dist/src/ipns.d.ts +6 -4
  25. package/dist/src/ipns.d.ts.map +1 -1
  26. package/dist/src/ipns.js +33 -4
  27. package/dist/src/ipns.js.map +1 -1
  28. package/dist/src/pb/ipns.d.ts +62 -0
  29. package/dist/src/pb/ipns.d.ts.map +1 -0
  30. package/dist/src/pb/ipns.js +203 -0
  31. package/dist/src/pb/ipns.js.map +1 -0
  32. package/dist/src/records.d.ts +155 -0
  33. package/dist/src/records.d.ts.map +1 -0
  34. package/dist/src/records.js +88 -0
  35. package/dist/src/records.js.map +1 -0
  36. package/dist/src/routing/pubsub.d.ts +3 -0
  37. package/dist/src/routing/pubsub.d.ts.map +1 -1
  38. package/dist/src/routing/pubsub.js +15 -11
  39. package/dist/src/routing/pubsub.js.map +1 -1
  40. package/dist/src/selector.d.ts +14 -0
  41. package/dist/src/selector.d.ts.map +1 -0
  42. package/dist/src/selector.js +47 -0
  43. package/dist/src/selector.js.map +1 -0
  44. package/dist/src/utils.d.ts +29 -2
  45. package/dist/src/utils.d.ts.map +1 -1
  46. package/dist/src/utils.js +308 -0
  47. package/dist/src/utils.js.map +1 -1
  48. package/dist/src/validator.d.ts +18 -0
  49. package/dist/src/validator.d.ts.map +1 -0
  50. package/dist/src/validator.js +58 -0
  51. package/dist/src/validator.js.map +1 -0
  52. package/package.json +9 -8
  53. package/src/errors.ts +40 -25
  54. package/src/index.ts +54 -92
  55. package/src/ipns/publisher.ts +34 -33
  56. package/src/ipns/republisher.ts +24 -13
  57. package/src/ipns/resolver.ts +40 -89
  58. package/src/ipns.ts +44 -7
  59. package/src/pb/ipns.proto +39 -0
  60. package/src/pb/ipns.ts +280 -0
  61. package/src/records.ts +273 -0
  62. package/src/routing/pubsub.ts +17 -11
  63. package/src/selector.ts +55 -0
  64. package/src/utils.ts +371 -2
  65. 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 = await name.resolve(publicKey)
56
-
57
- console.info(result.cid, result.path)
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 = await name.resolve(recursivePublicKey)
86
- console.info(result.cid.toString() === cid.toString()) // true
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 = await name.resolve(publicKey)
115
-
116
- console.info(result.cid, result.path) // QmFoo.. 'foo.txt'
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 = await name.resolve(publicKey)
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