@helia/ipns 10.1.0-dc9e15bc → 10.1.1-2ab3bfc6

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 +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.d.ts +9 -9
  33. package/dist/src/pb/ipns.d.ts.map +1 -1
  34. package/dist/src/pb/ipns.js +23 -9
  35. package/dist/src/pb/ipns.js.map +1 -1
  36. package/dist/src/pb/metadata.d.ts +16 -3
  37. package/dist/src/pb/metadata.d.ts.map +1 -1
  38. package/dist/src/pb/metadata.js +51 -4
  39. package/dist/src/pb/metadata.js.map +1 -1
  40. package/dist/src/routing/index.d.ts +13 -1
  41. package/dist/src/routing/index.d.ts.map +1 -1
  42. package/dist/src/routing/index.js +17 -0
  43. package/dist/src/routing/index.js.map +1 -1
  44. package/dist/src/utils.d.ts +5 -0
  45. package/dist/src/utils.d.ts.map +1 -1
  46. package/dist/src/utils.js +18 -0
  47. package/dist/src/utils.js.map +1 -1
  48. package/dist/src/validator.d.ts +6 -0
  49. package/dist/src/validator.d.ts.map +1 -1
  50. package/dist/src/validator.js +24 -14
  51. package/dist/src/validator.js.map +1 -1
  52. package/package.json +4 -4
  53. package/src/errors.ts +18 -0
  54. package/src/index.ts +145 -7
  55. package/src/ipns/publisher.ts +22 -20
  56. package/src/ipns/republisher.ts +182 -26
  57. package/src/ipns/resolver.ts +54 -36
  58. package/src/ipns.ts +20 -6
  59. package/src/local-store.ts +77 -22
  60. package/src/pb/ipns.ts +34 -18
  61. package/src/pb/metadata.proto +10 -0
  62. package/src/pb/metadata.ts +64 -7
  63. package/src/routing/index.ts +30 -1
  64. package/src/utils.ts +19 -0
  65. 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: use `import` to store the record
173
+ locally, then `republish` to broadcast it and keep it alive.
174
+
175
+ > **There should be only one republisher per IPNS key.** Multiple machines
176
+ > republishing the same key flood the routers with redundant writes.
177
+
178
+ ```TypeScript
179
+ import { createHelia } from 'helia'
180
+ import { ipns } from '@helia/ipns'
181
+ import { delegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
182
+ import { defaultLogger } from 'birnam'
183
+ import { CID } from 'multiformats/cid'
184
+
185
+ const helia = await createHelia()
186
+ const name = ipns(helia)
187
+
188
+ const ipnsName = 'k51qzi5uqu5dktsyfv7xz8h631pri4ct7osmb43nibxiojpttxzoft6hdyyzg4'
189
+ const parsedCid: CID<unknown, 114, 0 | 18, 1> = CID.parse(ipnsName)
190
+ const delegatedClient = delegatedRoutingV1HttpApiClient({
191
+ url: 'https://delegated-ipfs.dev'
192
+ })({
193
+ logger: defaultLogger()
194
+ })
195
+ const record = await delegatedClient.getIPNS(parsedCid)
196
+
197
+ // bring the record fetched from elsewhere into the local store
198
+ await name.import(parsedCid, record)
199
+
200
+ // republish the imported record and keep it alive. Throws
201
+ // RecordObsoleteError if the routing already has a newer record
202
+ 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