Skip to main content

BaseTransport

Struct BaseTransport 

Source
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: EncryptionMode

The encryption policy for outgoing messages.

§is_connected: bool

Whether the transport is currently connected to relays.

Implementations§

Source§

impl BaseTransport

Source

pub async fn connect(&mut self, relay_urls: &[String]) -> Result<()>

Connect to relays.

Source

pub async fn disconnect(&mut self) -> Result<()>

Disconnect from relays.

Source

pub async fn get_public_key(&self) -> Result<PublicKey>

Get the public key of the signer.

Source

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).

Source

pub fn convert_event_to_mcp(&self, content: &str) -> Option<JsonRpcMessage>

Convert a Nostr event to an MCP message with validation.

Source

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.

Source

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.

Source

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.

Source

pub fn should_encrypt(&self, kind: u16, is_encrypted: Option<bool>) -> bool

Determine whether a message should be encrypted.

Source

pub fn create_recipient_tags(pubkey: &PublicKey) -> Vec<Tag>

Create recipient tags for targeting a specific pubkey.

Source

pub fn create_response_tags(pubkey: &PublicKey, event_id: &EventId) -> Vec<Tag>

Create response tags (recipient + correlated event).

Source

pub fn compose_outbound_tags( base_tags: &[Tag], discovery_tags: &[Tag], negotiation_tags: &[Tag], ) -> Vec<Tag>

Compose outbound event tags in canonical order: routing (p, e) -> discovery (one-shot caps) -> negotiation (pmi, persistent).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more