helia
helia copied to clipboard
fix: @helia/* modules validate CID codec
Title
fix: @helia/* modules validate CID codec
Description
Closes: #377
@helia/* modules related to importing structured data, e.g. @helia/json; @helia/strings, check CID that is handed to .get method.
If the CID code does not match the codec of the importer then it rejects with a TypeError.
- [x] @helia/json
- [ ] @helia/strings
- [ ] @helia/dag-json
- [ ] @helia/dag-cbor
- [ ] ~~@helia/unixfs~~
Notes & open questions
Change checklist
- [ ] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation if necessary (this includes comments as well)
- [ ] I have added tests that prove my fix is effective or that my feature works
Before I finish the other modules, does this approach look ok?
Before I finish the other modules, does this approach look ok?
This looks good to me. It should be pretty straightforward
The @helia/strings.get method accepts a codec as an option. Either the option is removed (specifying a codec like raw, the current default) or validation cannot happen on the CID passed to get.
~Actually I can just check the CID.code is raw if no codec option is passed to get.~
IMO it would be best to not allow custom codecs to be passed to @helia/strings and just use 'utf8' encoding. If users are bringing their own codec then why not just interact with the blockstore directly?
Removing @helia/unixfs from todo list for this PR as it's a bit different and more involved than the other importers.
@tabcat are you still planning to work on this?
Depends on https://github.com/ipfs/helia/pull/668
I'll resolve the conflicts on that PR
I've fixed up the remaining modules.
Thanks for your patience on this one, it'll definitely help new developers!