Expand description
Mostro P2P chat protocol primitives.
Mostro reuses the NIP-59 GiftWrap envelope to carry a second, lighter
channel: direct buyer/seller chat during a trade and admin/party chat
during a dispute. Unlike protocol messages — which are addressed to a
Mostro node and use the dual identity/trade key scheme of
crate::nip59 — chat envelopes are addressed to a per-channel
shared key that both parties derive via ECDH from their trade keys.
The on-the-wire shape is intentionally simple:
Plain-text message
-> kind 1 TextNote signed by sender_trade_keys (inner)
-> NIP-44 v2 encrypt to shared_pubkey using an ephemeral key
-> kind 1059 GiftWrap with `p` = shared_pubkey, signed ephemerallyBoth parties can fetch and decrypt every wrap addressed to the shared key, and the inner event’s signature carries the real sender’s trade pubkey so each side can render the conversation correctly without exchanging extra metadata.
This module is pure protocol: it derives shared keys, builds and parses envelopes, and constructs the relay filter. It does not manage relays, subscriptions, persistence or higher-level workflows — those belong to the client.
§Quick start
use mostro_core::chat::{chat_filter, wrap_chat_message, unwrap_chat_message, SharedKey};
use nostr_sdk::prelude::*;
let alice = Keys::generate();
let bob_pubkey = Keys::generate().public_key();
let shared = SharedKey::derive(alice.secret_key(), &bob_pubkey)?;
let event = wrap_chat_message(&alice, &shared.public_key(), "hi bob").await?;
// ...publish `event` to relays, fetch incoming wraps with `chat_filter(...)`,
// then on the receiving side:
let chat = unwrap_chat_message(shared.keys(), &event).await?;
assert_eq!(chat.content, "hi bob");Structs§
- Chat
Message - A decrypted P2P chat message.
- Shared
Key - Shared key derived via ECDH between two parties’ trade keys.
Constants§
- CHAT_
DEFAULT_ LOOKBACK_ SECS - Default lookback window applied by
chat_filter(7 days).
Functions§
- chat_
filter - Create a Nostr relay filter for chat gift wraps addressed to a shared public key.
- unwrap_
chat_ message - Unwrap a Mostro P2P chat gift wrap.
- wrap_
chat_ message - Wrap a plain-text chat message into a Mostro P2P gift wrap (kind 1059).