-
Notifications
You must be signed in to change notification settings - Fork 5
Single nostr client #755
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
Single nostr client #755
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the Nostr transport layer from maintaining multiple NostrClient instances (one per local identity/company) to a single multi-identity NostrClient with a shared relay pool. This architectural change reduces resource usage and simplifies the codebase while maintaining support for multiple identities.
Key changes include:
- Single
NostrClientwith internalHashMap<NodeId, Arc<Keys>>for managing multiple identity signers TransportClientApimethods now require explicitsender_node_idparameter to specify which identity to useNostrConsumernow manages a single client instead of multiple clients- Event routing logic via new
determine_recipient()function that tries decrypting with each identity for private messages
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/bcr-ebill-wasm/src/context.rs | Updates initialization to use single nostr_client instead of nostr_clients |
| crates/bcr-ebill-transport/src/nostr.rs | Core refactoring - NostrClient now manages multiple identities with shared relay pool; adds determine_recipient() for routing events |
| crates/bcr-ebill-transport/src/nostr_transport.rs | Simplified to use single client; get_node_transport() now returns the shared client; removed multi-client management logic |
| crates/bcr-ebill-transport/src/lib.rs | Updated factory functions to create single multi-identity client instead of multiple clients |
| crates/bcr-ebill-transport/src/transport_service.rs | Updated method signatures to accept sender_node_id parameter; extensive test mock updates |
| crates/bcr-ebill-transport/src/test_utils.rs | Mock trait updated with new TransportClientApi signatures including sender_node_id |
| crates/bcr-ebill-transport/src/notification_transport.rs | Updated to use single client with sender_node_id parameter |
| crates/bcr-ebill-transport/src/contact_transport.rs | Simplified transport retrieval to use shared client |
| crates/bcr-ebill-transport/src/block_transport.rs | Updated to pass sender_node_id when sending chain events |
| crates/bcr-ebill-transport/src/handler/restore.rs | Constructor updated to accept node_id parameter |
| crates/bcr-ebill-transport/src/handler/identity_chain_event_handler.rs | Handler signature updated; node_id parameter now marked as unused for public events |
| crates/bcr-ebill-transport/src/handler/company_chain_event_handler.rs | Handler signature updated; node_id parameter now marked as unused for public events |
| crates/bcr-ebill-transport/src/handler/bill_chain_event_handler.rs | Handler signature updated; node_id parameter now marked as unused for public events |
| crates/bcr-ebill-transport/src/handler/direct_message_event_processor.rs | Updated to handle multi-identity routing using determine_recipient() |
| crates/bcr-ebill-api/src/service/transport_service/transport_client.rs | Trait definition updated with new method signatures and add_identity() method |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||
zupzup
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very, very nice! LGTM 👍
- Replace panic() in get_sender_node_id() and get_sender_keys() with backward-compatible implementations returning first identity - Store BcrKeys HashMap alongside signers to enable get_sender_keys() implementation - Make signers field private (was pub(crate)) - Remove async from add_identity() (no async work needed) - Revert signer selection in send_nip04_message() to use get_default_signer() - Revert NostrConsumer changes to use get_node_id() instead of accessing signers directly - Add backward-compatible helper methods: get_node_id(), get_default_signer(), get_nostr_keys() - Update direct_message_event_processor to use public methods instead of private field access All tests pass (93 tests in bcr-ebill-transport).
- Change NostrConsumer from HashMap of clients to single Arc<NostrClient> - Implement determine_recipient() to route events to correct identity - Create single subscription with all local pubkeys - Use earliest offset across all identities for subscription - Update create_nostr_consumer() to accept single client parameter - Add test for multi-identity consumer with single client - Add temporary workaround in WASM context (to be fixed in Task 10) Part of Task 3: Nostr single relay pool refactoring All 95 tests passing
- Implement manual NIP-17 gift wrap construction using nostr::nips::nip59 - Use EventBuilder to create rumor, seal, and gift wrap with explicit signer - Remove multi-identity limitation check that blocked NIP-17 - Update test to expect success instead of failure for NIP-17 multi-identity - Improves privacy by enabling proper NIP-17 encryption for all identities All 95 tests passing
Replace HashMap<NodeId, Arc<dyn TransportClientApi>> with single Arc<dyn TransportClientApi> in NostrTransportService and update all callers: - Update NostrTransportService struct to hold single nostr_client field - Convert get_node_transport() and get_first_transport() to return Arc directly (no longer async) - Simplify add_company_client() to no-op (handled by multi-identity client) - Update connect() method to use single client - Remove all .await calls from get_node_transport()/get_first_transport() - Update all service callers: block_transport, contact_transport, notification_transport, transport_service - Fix test expectations to match new single-client architecture - Clean up unused imports (error, NostrClient, NostrConfig, tokio, get_config) All 95 tests passing.
895a19d to
c0ae749
Compare
User description
📝 Description
This replaces the multi Nostr client setup with a single Nostr client that has access to multiple Nostr signers. It has wide implications so there could be a lot of pitfalls and potential issues. I have tested a lot with both public block message and private invites and shares so there should be not impact on prominent functionality. I also tested the publishing of metadata (relays, contact, ..) and fixed all issues there. There is probably still more opportunity for cleaning up/reducing code but for now I want to keep the refactoring amount low as this is just a pre-condition.
Relates to #613
✅ Checklist
Please ensure the following tasks are completed before requesting a review:
cargo fmt.cargo clippy.🚀 Changes Made
📋 Review Guidelines
Please focus on the following while reviewing:
PR Type
Enhancement, Refactoring
Description
Replace multi-client architecture with single shared multi-identity Nostr client
Add
sender_node_idparameter to transport API methods for explicit identity routingImplement
determine_recipient()function to route events to correct identityEnable NIP-17 support for multi-identity clients via manual gift wrap construction
Simplify NostrConsumer to use single client with unified subscription management
Diagram Walkthrough
File Walkthrough
1 files
Add sender_node_id parameter to transport API methods11 files
Update to pass sender_node_id to transport methodsSimplify transport access with single clientRemove unused node_id parameter from handlerRemove unused node_id parameter from handlerRemove unused node_id parameter from handlerAccept node_id parameter instead of deriving from transportSimplify to use single shared client instead of HashMapUpdate to pass sender_node_id to transport methodsUpdate unwrap_direct_message to accept event referenceUpdate to pass sender_node_id to transport methodsUpdate context initialization for single client3 files
Implement multi-identity event routing with determine_recipientCreate single multi-identity client instead of multiple clientsRefactor NostrClient to support multiple identities with shared relaypool1 files
Update mock transport to support new API with sender_node_id