Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow custom registrar #3040

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dozyio
Copy link
Contributor

@dozyio dozyio commented Mar 7, 2025

Description

Allow the registrar to be overridden with a custom implementation e.g. for adding protocol middleware

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

@dozyio dozyio requested a review from a team as a code owner March 7, 2025 02:02
@@ -135,6 +135,11 @@ export class Libp2p<T extends ServiceMap = ServiceMap> extends TypedEventEmitter
// Create the Registrar
this.configureComponent('registrar', new Registrar(this.components))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this should be in an else block on L143?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially it was an if/else but found it useful to have the default implementation initialised so that it can be passed to a custom registrar. Maybe the initialisation of the default could be handled in the custom one instead?

https://github.com/dozyio/js-libp2p-middleware-registrar/blob/092687470ccd768da81d9d2044ce8ae37ce5715b/src/middleware-registry.ts#L101

@SgtPooki
Copy link
Member

Allow the registrar to be overridden with a custom implementation e.g. for adding protocol middleware

Do you have an example of how you intend this to be used? Does this just make js-libp2p more customize-able without needing changes to the repo?

@dozyio
Copy link
Contributor Author

dozyio commented Mar 12, 2025

Allow the registrar to be overridden with a custom implementation e.g. for adding protocol middleware

Do you have an example of how you intend this to be used? Does this just make js-libp2p more customize-able without needing changes to the repo?

Yes - examples here
https://github.com/dozyio/js-libp2p-middleware-registrar - adds a middleware registrar
https://github.com/dozyio/js-libp2p-middleware-evm - adds EVM auth middleware via the middleware-registrar
https://github.com/dozyio/evm-frontend-example - nextjs app using EVM middleware to wrap libp2p protocols - bit of a pain to setup at present - will add some docs later

Maybe the middleware registrar could be included in js-libp2p instead but happy for it to live outside of the tree for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants