diff --git a/bindings/nostr-sdk-ffi/src/client/mod.rs b/bindings/nostr-sdk-ffi/src/client/mod.rs index 75a691ec7..6eec4261f 100644 --- a/bindings/nostr-sdk-ffi/src/client/mod.rs +++ b/bindings/nostr-sdk-ffi/src/client/mod.rs @@ -23,9 +23,8 @@ use crate::database::events::Events; use crate::error::Result; use crate::pool::result::{Output, ReconciliationOutput, SendEventOutput, SubscribeOutput}; use crate::pool::RelayPool; -use crate::protocol::nips::nip59::UnwrappedGift; use crate::protocol::signer::{NostrSigner, NostrSignerFFI2Rust, NostrSignerRust2FFI}; -use crate::protocol::{ClientMessage, Event, EventBuilder, Filter, Metadata, PublicKey, Tag}; +use crate::protocol::{ClientMessage, Event, EventBuilder, Filter, Metadata, PublicKey}; use crate::relay::options::{SubscribeAutoCloseOptions, SyncOptions}; use crate::relay::RelayFiltering; use crate::{HandleNotification, NostrDatabase, Relay}; @@ -518,37 +517,6 @@ impl Client { .into()) } - /// Send private direct message to all relays - /// - /// - pub async fn send_private_msg( - &self, - receiver: &PublicKey, - message: String, - ) -> Result { - Ok(self - .inner - .send_private_msg(**receiver, message, []) - .await? - .into()) - } - - /// Send private direct message to specific relays - /// - /// - pub async fn send_private_msg_to( - &self, - urls: Vec, - receiver: &PublicKey, - message: String, - ) -> Result { - Ok(self - .inner - .send_private_msg_to(urls, **receiver, message, []) - .await? - .into()) - } - /// Send a Zap! pub async fn zap( &self, @@ -562,59 +530,6 @@ impl Client { .await?) } - /// Construct Gift Wrap and send to relays - /// - /// Check `send_event` method to know how sending events works. - /// - /// - pub async fn gift_wrap( - &self, - receiver: &PublicKey, - rumor: Arc, - extra_tags: Vec>, - ) -> Result { - Ok(self - .inner - .gift_wrap( - receiver.deref(), - rumor.as_ref().deref().clone(), - extra_tags.into_iter().map(|t| t.as_ref().deref().clone()), - ) - .await? - .into()) - } - - /// Construct Gift Wrap and send to specific relays - /// - /// - pub async fn gift_wrap_to( - &self, - urls: Vec, - receiver: &PublicKey, - rumor: Arc, - extra_tags: Vec>, - ) -> Result { - Ok(self - .inner - .gift_wrap_to( - urls, - receiver.deref(), - rumor.as_ref().deref().clone(), - extra_tags.into_iter().map(|t| t.as_ref().deref().clone()), - ) - .await? - .into()) - } - - /// Unwrap Gift Wrap event - /// - /// Internally verify the `seal` event - /// - /// - pub async fn unwrap_gift_wrap(&self, gift_wrap: &Event) -> Result { - Ok(self.inner.unwrap_gift_wrap(gift_wrap.deref()).await?.into()) - } - /// Handle notifications pub async fn handle_notifications(&self, handler: Arc) -> Result<()> { Ok(self diff --git a/bindings/nostr-sdk-js/src/client/mod.rs b/bindings/nostr-sdk-js/src/client/mod.rs index 384393ac4..e40810363 100644 --- a/bindings/nostr-sdk-js/src/client/mod.rs +++ b/bindings/nostr-sdk-js/src/client/mod.rs @@ -22,10 +22,9 @@ use crate::duration::JsDuration; use crate::error::{into_err, Result}; use crate::pool::result::{JsOutput, JsReconciliationOutput, JsSendEventOutput, JsSubscribeOutput}; use crate::pool::JsRelayPool; -use crate::protocol::event::{JsEvent, JsEventBuilder, JsTag}; +use crate::protocol::event::{JsEvent, JsEventBuilder}; use crate::protocol::key::JsPublicKey; use crate::protocol::message::{JsClientMessage, JsRelayMessage}; -use crate::protocol::nips::nip59::JsUnwrappedGift; use crate::protocol::types::{JsFilter, JsMetadata}; use crate::relay::filtering::JsRelayFiltering; use crate::relay::options::{JsSubscribeAutoCloseOptions, JsSyncOptions}; @@ -530,39 +529,6 @@ impl JsClient { .map(|id| id.into()) } - /// Send private direct message to all relays - /// - /// - #[wasm_bindgen(js_name = sendPrivateMsg)] - pub async fn send_private_msg( - &self, - receiver: &JsPublicKey, - message: &str, - ) -> Result { - self.inner - .send_private_msg(**receiver, message, []) - .await - .map_err(into_err) - .map(Into::into) - } - - /// Send private direct message to specific relays - /// - /// - #[wasm_bindgen(js_name = sendPrivateMsgTo)] - pub async fn send_private_msg_to( - &self, - urls: Vec, - receiver: &JsPublicKey, - message: &str, - ) -> Result { - self.inner - .send_private_msg_to(urls, **receiver, message, []) - .await - .map_err(into_err) - .map(Into::into) - } - /// Send a Zap! pub async fn zap( &self, @@ -576,67 +542,6 @@ impl JsClient { .map_err(into_err) } - /// Construct Gift Wrap and send to relays - /// - /// Check `sendEvent` method to know how sending events works. - /// - /// - #[wasm_bindgen(js_name = giftWrap)] - pub async fn gift_wrap( - &self, - receiver: &JsPublicKey, - rumor: &JsEventBuilder, - extra_tags: Option>, - ) -> Result { - self.inner - .gift_wrap( - receiver.deref(), - rumor.deref().clone(), - extra_tags.unwrap_or_default().into_iter().map(|t| t.inner), - ) - .await - .map_err(into_err) - .map(Into::into) - } - - /// Construct Gift Wrap and send to specific relays - /// - /// - #[wasm_bindgen(js_name = giftWrapTo)] - pub async fn gift_wrap_to( - &self, - urls: Vec, - receiver: &JsPublicKey, - rumor: &JsEventBuilder, - extra_tags: Option>, - ) -> Result { - self.inner - .gift_wrap_to( - urls, - receiver.deref(), - rumor.deref().clone(), - extra_tags.unwrap_or_default().into_iter().map(|t| t.inner), - ) - .await - .map_err(into_err) - .map(Into::into) - } - - /// Unwrap Gift Wrap event - /// - /// Internally verify the `seal` event - /// - /// - #[wasm_bindgen(js_name = unwrapGiftWrap)] - pub async fn unwrap_gift_wrap(&self, gift_wrap: &JsEvent) -> Result { - Ok(self - .inner - .unwrap_gift_wrap(gift_wrap.deref()) - .await - .map_err(into_err)? - .into()) - } - /// Handle notifications /// /// **This method spawn a thread**, so ensure to keep up the app after calling this (if needed). diff --git a/crates/nostr-sdk/examples/bot.rs b/crates/nostr-sdk/examples/bot.rs index 2ba51433b..414cfbb03 100644 --- a/crates/nostr-sdk/examples/bot.rs +++ b/crates/nostr-sdk/examples/bot.rs @@ -39,7 +39,7 @@ async fn main() -> Result<()> { .handle_notifications(|notification| async { if let RelayPoolNotification::Event { event, .. } = notification { if event.kind == Kind::GiftWrap { - match client.unwrap_gift_wrap(&event).await { + match UnwrappedGift::from_gift_wrap(&keys, &event).await { Ok(UnwrappedGift { rumor, sender }) => { if rumor.kind == Kind::PrivateDirectMessage { let content: String = match rumor.content.as_str() { diff --git a/crates/nostr-sdk/examples/tor.rs b/crates/nostr-sdk/examples/tor.rs index 55e7ef0bb..523dbff46 100644 --- a/crates/nostr-sdk/examples/tor.rs +++ b/crates/nostr-sdk/examples/tor.rs @@ -37,7 +37,8 @@ async fn main() -> Result<()> { .handle_notifications(|notification| async { if let RelayPoolNotification::Event { event, .. } = notification { if event.kind == Kind::GiftWrap { - let UnwrappedGift { rumor, .. } = client.unwrap_gift_wrap(&event).await?; + let UnwrappedGift { rumor, .. } = + UnwrappedGift::from_gift_wrap(&keys, &event).await?; println!("Rumor: {}", rumor.as_json()); } else { println!("{:?}", event); diff --git a/crates/nostr-sdk/src/client/mod.rs b/crates/nostr-sdk/src/client/mod.rs index d059f2010..51f8f4442 100644 --- a/crates/nostr-sdk/src/client/mod.rs +++ b/crates/nostr-sdk/src/client/mod.rs @@ -1342,8 +1342,11 @@ impl Client { /// Send private direct message to all relays /// /// - #[inline] #[cfg(feature = "nip59")] + #[deprecated( + since = "0.37.0", + note = "Use the `EventBuilder` in conjunction with `Client::send_event` or similar method." + )] pub async fn send_private_msg( &self, receiver: PublicKey, @@ -1354,16 +1357,20 @@ impl Client { S: Into, I: IntoIterator, { - let rumor: EventBuilder = - EventBuilder::private_msg_rumor(receiver, message, rumor_extra_tags); - self.gift_wrap(&receiver, rumor, []).await + let signer = self.signer().await?; + let event: Event = + EventBuilder::private_msg(&signer, receiver, message, rumor_extra_tags).await?; + self.send_event(event).await } /// Send private direct message to specific relays /// /// - #[inline] #[cfg(feature = "nip59")] + #[deprecated( + since = "0.37.0", + note = "Use the `EventBuilder` in conjunction with `Client::send_event` or similar method." + )] pub async fn send_private_msg_to( &self, urls: I, @@ -1378,9 +1385,10 @@ impl Client { IT: IntoIterator, pool::Error: From<::Err>, { - let rumor: EventBuilder = - EventBuilder::private_msg_rumor(receiver, message, rumor_extra_tags); - self.gift_wrap_to(urls, &receiver, rumor, []).await + let signer = self.signer().await?; + let event: Event = + EventBuilder::private_msg(&signer, receiver, message, rumor_extra_tags).await?; + self.send_event_to(urls, event).await } /// Repost @@ -1602,8 +1610,11 @@ impl Client { /// Check [`Client::send_event`] to know how sending events works. /// /// - #[inline] #[cfg(feature = "nip59")] + #[deprecated( + since = "0.37.0", + note = "Use the `EventBuilder` in conjunction with `Client::send_event` or similar method." + )] pub async fn gift_wrap( &self, receiver: &PublicKey, @@ -1627,8 +1638,11 @@ impl Client { /// Construct Gift Wrap and send to specific relays /// /// - #[inline] #[cfg(feature = "nip59")] + #[deprecated( + since = "0.37.0", + note = "Use the `EventBuilder` in conjunction with `Client::send_event` or similar method." + )] pub async fn gift_wrap_to( &self, urls: I, @@ -1658,8 +1672,11 @@ impl Client { /// Internally verify the `seal` event. /// /// - #[inline] #[cfg(feature = "nip59")] + #[deprecated( + since = "0.37.0", + note = "Use `UnwrappedGift::from_gift_wrap` instead." + )] pub async fn unwrap_gift_wrap(&self, gift_wrap: &Event) -> Result { let signer = self.signer().await?; Ok(UnwrappedGift::from_gift_wrap(&signer, gift_wrap).await?)