feat: migrate chat to mostro-core primitives#66
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR consolidates GiftWrap and direct message handling by migrating from local NIP-44/NIP-59 implementations to ChangesGiftWrap and Direct Message Consolidation
Sequence Diagram(s)sequenceDiagram
participant App as Application Code
participant MostroChat as mostro_core::chat
participant SharedKeyDeriv as SharedKey Derivation
participant Relay as Relay Filter
rect rgba(0, 100, 200, 0.5)
note right of App: Message Sending
App->>SharedKeyDeriv: derive_shared_key_hex(counterparty_pubkey)
SharedKeyDeriv->>MostroChat: SharedKey::derive(our_keys, counterparty_key)
MostroChat-->>SharedKeyDeriv: shared_secret
SharedKeyDeriv->>SharedKeyDeriv: to_hex() for persistence
SharedKeyDeriv-->>App: shared_key_hex
end
rect rgba(100, 0, 200, 0.5)
note right of MostroChat: Message Wrapping
App->>MostroChat: wrap_chat_message(content, shared_pubkey)
MostroChat-->>App: wrapped_giftwrap_event
end
rect rgba(0, 200, 100, 0.5)
note right of Relay: Message Reception
App->>Relay: chat_filter(shared_pubkey)
Relay-->>App: filtered_giftwrap_events
App->>MostroChat: unwrap_chat_message(event)
MostroChat-->>App: (content, timestamp, sender_pubkey)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
I found one blocker before this can be approved.
Blocker
This PR intentionally migrates chat GiftWrap construction to mostro_core::chat::wrap_chat_message, and the PR description explicitly says chat GiftWraps are now sent without PoW.
That part is fine if it is the intended migration choice, but the repository documentation was not updated consistently.
docs/POW_AND_OUTBOUND_EVENTS.md still says:
- "Admin dispute chat gift wraps use the same instance-derived PoW via
send_admin_chat_message_via_shared_key"
That is no longer true after this refactor.
Before this PR, send_admin_chat_message_via_shared_key() called the local custom wrapper path that applied instance-derived PoW to the outer GiftWrap. After this PR it calls wrap_chat_message(...) directly, mostro_instance is renamed to _mostro_instance, and no PoW is applied in that path anymore.
So right now the code and docs disagree on an externally relevant behavior change.
I am treating this as a blocker, not a doc nit, because PoW policy directly affects relay acceptance and operational expectations. Anyone reading the current doc will walk away with the wrong guarantee about outbound admin chat behavior.
Please update the documentation so it clearly reflects the new semantics for chat GiftWraps in this PR.
There was a problem hiding this comment.
Re-reviewed the latest commit.
The blocker I raised is resolved now.
The documentation now clearly distinguishes the two behaviors:
- protocol DMs toward Mostro still use instance-derived PoW on the published outer GiftWrap
- shared-key chat messages are relay-scoped chat wraps and intentionally do not use PoW
That was the missing piece for this migration. The refactor itself still looks coherent, and the code/doc semantics are aligned now.
Summary
mostro_core::chat(SharedKey,wrap_chat_message,unwrap_chat_message,chat_filter).nostr_sdk::util::generate_shared_key.Notes
Summary by CodeRabbit
Documentation
Refactor