From b8c93ab9fc9a1d7ac2d06af461bd04c299c5ba0d Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Tue, 18 Jun 2024 15:27:26 -0400 Subject: [PATCH] sdk: add `Client::unwrap_gift_wrap` method Signed-off-by: Yuki Kishimoto --- CHANGELOG.md | 1 + bindings/nostr-sdk-ffi/src/client/mod.rs | 10 ++++++++++ bindings/nostr-sdk-js/src/client/mod.rs | 16 ++++++++++++++++ crates/nostr-sdk/src/client/mod.rs | 12 ++++++++++++ 4 files changed, 39 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f831d8f22..daf7d56b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ * nostr: add `title`, `image` and `description` constructors to `Tag` ([Yuki Kishimoto]) * pool: add `SendOutput` and `SendEventOutput` structs ([Yuki Kishimoto]) * signer: add `NostrSigner::unwrap_gift_wrap` method ([Yuki Kishimoto]) +* sdk: add `Client::unwrap_gift_wrap` method ([Yuki Kishimoto]) * js(sdk): partially expose `JsRelayPool` ([Yuki Kishimoto]) * book: add some python examples ([RydalWater]) diff --git a/bindings/nostr-sdk-ffi/src/client/mod.rs b/bindings/nostr-sdk-ffi/src/client/mod.rs index b1fdfb493..cabbe6d3b 100644 --- a/bindings/nostr-sdk-ffi/src/client/mod.rs +++ b/bindings/nostr-sdk-ffi/src/client/mod.rs @@ -7,6 +7,7 @@ use std::ops::Deref; use std::sync::Arc; use std::time::Duration; +use nostr_ffi::nips::nip59::UnwrappedGift; use nostr_ffi::{ ClientMessage, Event, EventBuilder, EventId, FileMetadata, Filter, Metadata, PublicKey, Timestamp, @@ -582,6 +583,15 @@ impl Client { .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()) + } + pub async fn file_metadata( &self, description: String, diff --git a/bindings/nostr-sdk-js/src/client/mod.rs b/bindings/nostr-sdk-js/src/client/mod.rs index 0ac608756..b41232f7b 100644 --- a/bindings/nostr-sdk-js/src/client/mod.rs +++ b/bindings/nostr-sdk-js/src/client/mod.rs @@ -10,6 +10,7 @@ use nostr_js::error::{into_err, Result}; use nostr_js::event::{JsEvent, JsEventArray, JsEventBuilder, JsEventId, JsTag}; use nostr_js::key::JsPublicKey; use nostr_js::message::{JsClientMessage, JsRelayMessage}; +use nostr_js::nips::nip59::JsUnwrappedGift; use nostr_js::types::{JsContact, JsFilter, JsMetadata, JsTimestamp}; use nostr_sdk::async_utility::thread; use nostr_sdk::prelude::*; @@ -716,6 +717,21 @@ impl JsClient { .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()) + } + /// Negentropy reconciliation /// /// diff --git a/crates/nostr-sdk/src/client/mod.rs b/crates/nostr-sdk/src/client/mod.rs index 42de27e09..3c3b401dd 100644 --- a/crates/nostr-sdk/src/client/mod.rs +++ b/crates/nostr-sdk/src/client/mod.rs @@ -1503,6 +1503,18 @@ impl Client { self.send_event(gift_wrap).await } + /// Unwrap Gift Wrap event + /// + /// Internally verify the `seal` event. + /// + /// + #[inline] + #[cfg(feature = "nip59")] + pub async fn unwrap_gift_wrap(&self, gift_wrap: &Event) -> Result { + let signer: NostrSigner = self.signer().await?; + Ok(signer.unwrap_gift_wrap(gift_wrap).await?) + } + /// File metadata /// ///