Configuration validation
We don't perform much in the way of validation on loaded libp2p config but we really should.
Ideally each module parsing it's config would use something like superstruct to validate at creation time and fail fast with good feedback to the user as to how they can fix their broken config.
This should negate the need for PRs like https://github.com/libp2p/js-libp2p/pull/1572 as the config would have been validated in src/config.ts already.
Update
@achingbrain explored a few different options and we determined that zod is perhaps the best choice. Currently Zod is 8kb minified + zipped but based on this discussion there are a few different approaches to making Zod tree-shakeable.
Anyone who takes up this work can continue with the commits on https://github.com/libp2p/js-libp2p/pull/2133 and have look at the discussion on that PR
Re-opening this as original PR which addressed this was reverted and subsequent work has taken place on https://github.com/libp2p/js-libp2p/pull/2133
I've also updated the description
@maschad I want to work on this issue. I want to use the latest version of Zod for validation.
It's worth reading this comment - https://github.com/libp2p/js-libp2p/pull/2133#issuecomment-2164986991
At the time Zod added a massive chunk of code to browser bundles, too much for us to adopt it. The situation was supposed to improve with Zod v4 but from what I can see, that still hasn't been released.
It would be good to finally close this issue out though, I would probably use superstruct instead since it's over 10x smaller than Zod.
We can switch later if there's a pressing reason to do so.
I would start with a PR that just adds validation to the libp2p module. Other modules in the monorepo can be done as follow-ups.