@helia/ipns 10.1.1 → 10.2.0

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 (63) hide show
  1. package/README.md +40 -0
  2. package/dist/index.min.js +5 -5
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/errors.d.ts +11 -0
  5. package/dist/src/errors.d.ts.map +1 -1
  6. package/dist/src/errors.js +13 -0
  7. package/dist/src/errors.js.map +1 -1
  8. package/dist/src/index.d.ts +136 -7
  9. package/dist/src/index.d.ts.map +1 -1
  10. package/dist/src/index.js +41 -0
  11. package/dist/src/index.js.map +1 -1
  12. package/dist/src/ipns/publisher.d.ts +3 -3
  13. package/dist/src/ipns/publisher.d.ts.map +1 -1
  14. package/dist/src/ipns/publisher.js +17 -18
  15. package/dist/src/ipns/publisher.js.map +1 -1
  16. package/dist/src/ipns/republisher.d.ts +6 -1
  17. package/dist/src/ipns/republisher.d.ts.map +1 -1
  18. package/dist/src/ipns/republisher.js +157 -24
  19. package/dist/src/ipns/republisher.js.map +1 -1
  20. package/dist/src/ipns/resolver.d.ts +13 -1
  21. package/dist/src/ipns/resolver.d.ts.map +1 -1
  22. package/dist/src/ipns/resolver.js +40 -31
  23. package/dist/src/ipns/resolver.js.map +1 -1
  24. package/dist/src/ipns.d.ts +6 -3
  25. package/dist/src/ipns.d.ts.map +1 -1
  26. package/dist/src/ipns.js +12 -3
  27. package/dist/src/ipns.js.map +1 -1
  28. package/dist/src/local-store.d.ts +5 -0
  29. package/dist/src/local-store.d.ts.map +1 -1
  30. package/dist/src/local-store.js +68 -23
  31. package/dist/src/local-store.js.map +1 -1
  32. package/dist/src/pb/ipns.js +1 -1
  33. package/dist/src/pb/metadata.d.ts +14 -1
  34. package/dist/src/pb/metadata.d.ts.map +1 -1
  35. package/dist/src/pb/metadata.js +36 -3
  36. package/dist/src/pb/metadata.js.map +1 -1
  37. package/dist/src/routing/index.d.ts +13 -1
  38. package/dist/src/routing/index.d.ts.map +1 -1
  39. package/dist/src/routing/index.js +17 -0
  40. package/dist/src/routing/index.js.map +1 -1
  41. package/dist/src/utils.d.ts +5 -0
  42. package/dist/src/utils.d.ts.map +1 -1
  43. package/dist/src/utils.js +18 -0
  44. package/dist/src/utils.js.map +1 -1
  45. package/dist/src/validator.d.ts +6 -0
  46. package/dist/src/validator.d.ts.map +1 -1
  47. package/dist/src/validator.js +24 -14
  48. package/dist/src/validator.js.map +1 -1
  49. package/dist/typedoc-urls.json +23 -1
  50. package/package.json +3 -3
  51. package/src/errors.ts +18 -0
  52. package/src/index.ts +145 -7
  53. package/src/ipns/publisher.ts +22 -20
  54. package/src/ipns/republisher.ts +182 -26
  55. package/src/ipns/resolver.ts +54 -36
  56. package/src/ipns.ts +20 -6
  57. package/src/local-store.ts +77 -22
  58. package/src/pb/ipns.ts +1 -1
  59. package/src/pb/metadata.proto +10 -0
  60. package/src/pb/metadata.ts +45 -4
  61. package/src/routing/index.ts +30 -1
  62. package/src/utils.ts +19 -0
  63. package/src/validator.ts +30 -18
package/README.md CHANGED
@@ -165,6 +165,46 @@ for await (const result of name.resolve(publicKey)) {
165
165
  }
166
166
  ```
167
167
 
168
+ ## Example - Republishing an existing IPNS record
169
+
170
+ It is sometimes useful to be able to republish an existing IPNS record
171
+ without needing the private key. This allows you to extend the availability
172
+ of a record that was created elsewhere.
173
+
174
+ There should be only one republisher per IPNS key. Multiple machines
175
+ republishing the same key flood the routers with redundant writes.
176
+
177
+ ```TypeScript
178
+ import { createHelia } from 'helia'
179
+ import { ipns } from '@helia/ipns'
180
+ import { delegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
181
+ import { defaultLogger } from 'birnam'
182
+ import { CID } from 'multiformats/cid'
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
+ // import the record into the local store (validates and stores it locally,
197
+ // but does not publish it to the routers)
198
+ await name.import(parsedCid, record)
199
+
200
+ // start republishing it; throws RecordObsoleteError if the routers
201
+ // already have a newer record for this key
202
+ const { record: latestRecord } = await name.republish(parsedCid)
203
+
204
+ // stop republishing a key
205
+ await name.unpublish(parsedCid)
206
+ ```
207
+
168
208
  # Install
169
209
 
170
210
  ```console