pub struct BaseTransport {
pub relay_pool: Arc<dyn RelayPoolTrait>,
pub encryption_mode: EncryptionMode,
pub is_connected: bool,
}Expand description
Shared transport logic for both client and server.
Handles relay connectivity, event signing/publishing, encryption decisions,
and MCP message validation. Used internally by NostrClientTransport
and NostrServerTransport.
Fields§
§relay_pool: Arc<dyn RelayPoolTrait>The relay pool for publishing and subscribing to Nostr events.
encryption_mode: EncryptionModeThe encryption policy for outgoing messages.
is_connected: boolWhether the transport is currently connected to relays.
Implementations§
Source§impl BaseTransport
impl BaseTransport
Sourcepub async fn disconnect(&mut self) -> Result<()>
pub async fn disconnect(&mut self) -> Result<()>
Disconnect from relays.
Sourcepub async fn get_public_key(&self) -> Result<PublicKey>
pub async fn get_public_key(&self) -> Result<PublicKey>
Get the public key of the signer.
Sourcepub async fn subscribe_for_pubkey(&self, pubkey: &PublicKey) -> Result<()>
pub async fn subscribe_for_pubkey(&self, pubkey: &PublicKey) -> Result<()>
Subscribe to events targeting a pubkey (both regular and encrypted).
Uses three filters: one for ephemeral ContextVM messages (kind 25910) and two for NIP-59 gift wraps (kinds 1059 and 21059).
Sourcepub fn convert_event_to_mcp(&self, content: &str) -> Option<JsonRpcMessage>
pub fn convert_event_to_mcp(&self, content: &str) -> Option<JsonRpcMessage>
Convert a Nostr event to an MCP message with validation.
Sourcepub async fn create_signed_event(
&self,
message: &JsonRpcMessage,
kind: u16,
tags: Vec<Tag>,
) -> Result<Event>
pub async fn create_signed_event( &self, message: &JsonRpcMessage, kind: u16, tags: Vec<Tag>, ) -> Result<Event>
Create a signed Nostr event for an MCP message.
Sourcepub async fn prepare_mcp_message(
&self,
message: &JsonRpcMessage,
recipient: &PublicKey,
kind: u16,
tags: Vec<Tag>,
is_encrypted: Option<bool>,
gift_wrap_kind: Option<u16>,
) -> Result<(EventId, Event)>
pub async fn prepare_mcp_message( &self, message: &JsonRpcMessage, recipient: &PublicKey, kind: u16, tags: Vec<Tag>, is_encrypted: Option<bool>, gift_wrap_kind: Option<u16>, ) -> Result<(EventId, Event)>
Prepare an MCP message for publishing without actually publishing it.
Signs (and optionally gift-wraps) the event, returning the inner signed event ID together with the final event that should be published to relays.
Sourcepub async fn send_mcp_message(
&self,
message: &JsonRpcMessage,
recipient: &PublicKey,
kind: u16,
tags: Vec<Tag>,
is_encrypted: Option<bool>,
gift_wrap_kind: Option<u16>,
) -> Result<EventId>
pub async fn send_mcp_message( &self, message: &JsonRpcMessage, recipient: &PublicKey, kind: u16, tags: Vec<Tag>, is_encrypted: Option<bool>, gift_wrap_kind: Option<u16>, ) -> Result<EventId>
Send an MCP message to a recipient, optionally encrypting.
Returns the signed MCP event ID. When encrypted, this is the inner signed event ID.
Sourcepub fn should_encrypt(&self, kind: u16, is_encrypted: Option<bool>) -> bool
pub fn should_encrypt(&self, kind: u16, is_encrypted: Option<bool>) -> bool
Determine whether a message should be encrypted.
Create recipient tags for targeting a specific pubkey.
Create response tags (recipient + correlated event).
Compose outbound event tags in canonical order: routing (p, e) -> discovery (one-shot caps) -> negotiation (pmi, persistent).
Auto Trait Implementations§
impl Freeze for BaseTransport
impl !RefUnwindSafe for BaseTransport
impl Send for BaseTransport
impl Sync for BaseTransport
impl Unpin for BaseTransport
impl UnsafeUnpin for BaseTransport
impl !UnwindSafe for BaseTransport
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more