Skip to content

Commit

Permalink
sdk: deprecate NIP17 and NIP59 Client methods
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Nov 14, 2024
1 parent ab3ab7e commit cf6bb33
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 193 deletions.
87 changes: 1 addition & 86 deletions bindings/nostr-sdk-ffi/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -518,37 +517,6 @@ impl Client {
.into())
}

/// Send private direct message to all relays
///
/// <https://github.com/nostr-protocol/nips/blob/master/17.md>
pub async fn send_private_msg(
&self,
receiver: &PublicKey,
message: String,
) -> Result<SendEventOutput> {
Ok(self
.inner
.send_private_msg(**receiver, message, [])
.await?
.into())
}

/// Send private direct message to specific relays
///
/// <https://github.com/nostr-protocol/nips/blob/master/17.md>
pub async fn send_private_msg_to(
&self,
urls: Vec<String>,
receiver: &PublicKey,
message: String,
) -> Result<SendEventOutput> {
Ok(self
.inner
.send_private_msg_to(urls, **receiver, message, [])
.await?
.into())
}

/// Send a Zap!
pub async fn zap(
&self,
Expand All @@ -562,59 +530,6 @@ impl Client {
.await?)
}

/// Construct Gift Wrap and send to relays
///
/// Check `send_event` method to know how sending events works.
///
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
pub async fn gift_wrap(
&self,
receiver: &PublicKey,
rumor: Arc<EventBuilder>,
extra_tags: Vec<Arc<Tag>>,
) -> Result<SendEventOutput> {
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
///
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
pub async fn gift_wrap_to(
&self,
urls: Vec<String>,
receiver: &PublicKey,
rumor: Arc<EventBuilder>,
extra_tags: Vec<Arc<Tag>>,
) -> Result<SendEventOutput> {
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
///
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
pub async fn unwrap_gift_wrap(&self, gift_wrap: &Event) -> Result<UnwrappedGift> {
Ok(self.inner.unwrap_gift_wrap(gift_wrap.deref()).await?.into())
}

/// Handle notifications
pub async fn handle_notifications(&self, handler: Arc<dyn HandleNotification>) -> Result<()> {
Ok(self
Expand Down
97 changes: 1 addition & 96 deletions bindings/nostr-sdk-js/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -530,39 +529,6 @@ impl JsClient {
.map(|id| id.into())
}

/// Send private direct message to all relays
///
/// <https://github.com/nostr-protocol/nips/blob/master/17.md>
#[wasm_bindgen(js_name = sendPrivateMsg)]
pub async fn send_private_msg(
&self,
receiver: &JsPublicKey,
message: &str,
) -> Result<JsSendEventOutput> {
self.inner
.send_private_msg(**receiver, message, [])
.await
.map_err(into_err)
.map(Into::into)
}

/// Send private direct message to specific relays
///
/// <https://github.com/nostr-protocol/nips/blob/master/17.md>
#[wasm_bindgen(js_name = sendPrivateMsgTo)]
pub async fn send_private_msg_to(
&self,
urls: Vec<String>,
receiver: &JsPublicKey,
message: &str,
) -> Result<JsSendEventOutput> {
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,
Expand All @@ -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.
///
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
#[wasm_bindgen(js_name = giftWrap)]
pub async fn gift_wrap(
&self,
receiver: &JsPublicKey,
rumor: &JsEventBuilder,
extra_tags: Option<Vec<JsTag>>,
) -> Result<JsSendEventOutput> {
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
///
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
#[wasm_bindgen(js_name = giftWrapTo)]
pub async fn gift_wrap_to(
&self,
urls: Vec<String>,
receiver: &JsPublicKey,
rumor: &JsEventBuilder,
extra_tags: Option<Vec<JsTag>>,
) -> Result<JsSendEventOutput> {
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
///
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
#[wasm_bindgen(js_name = unwrapGiftWrap)]
pub async fn unwrap_gift_wrap(&self, gift_wrap: &JsEvent) -> Result<JsUnwrappedGift> {
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).
Expand Down
39 changes: 28 additions & 11 deletions crates/nostr-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,8 +1342,11 @@ impl Client {
/// Send private direct message to all relays
///
/// <https://github.com/nostr-protocol/nips/blob/master/17.md>
#[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<S, I>(
&self,
receiver: PublicKey,
Expand All @@ -1354,16 +1357,20 @@ impl Client {
S: Into<String>,
I: IntoIterator<Item = Tag>,
{
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
///
/// <https://github.com/nostr-protocol/nips/blob/master/17.md>
#[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<I, S, U, IT>(
&self,
urls: I,
Expand All @@ -1378,9 +1385,10 @@ impl Client {
IT: IntoIterator<Item = Tag>,
pool::Error: From<<U as TryIntoUrl>::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
Expand Down Expand Up @@ -1602,8 +1610,11 @@ impl Client {
/// Check [`Client::send_event`] to know how sending events works.
///
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
#[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<I>(
&self,
receiver: &PublicKey,
Expand All @@ -1627,8 +1638,11 @@ impl Client {
/// Construct Gift Wrap and send to specific relays
///
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
#[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<I, U, IT>(
&self,
urls: I,
Expand Down Expand Up @@ -1658,8 +1672,11 @@ impl Client {
/// Internally verify the `seal` event.
///
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
#[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<UnwrappedGift, Error> {
let signer = self.signer().await?;
Ok(UnwrappedGift::from_gift_wrap(&signer, gift_wrap).await?)
Expand Down

0 comments on commit cf6bb33

Please sign in to comment.