Skip to content

Commit

Permalink
sdk: add Client::unwrap_gift_wrap method
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Jun 18, 2024
1 parent 3da5490 commit b8c93ab
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
10 changes: 10 additions & 0 deletions bindings/nostr-sdk-ffi/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -582,6 +583,15 @@ impl Client {
.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())
}

pub async fn file_metadata(
&self,
description: String,
Expand Down
16 changes: 16 additions & 0 deletions bindings/nostr-sdk-js/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -716,6 +717,21 @@ impl JsClient {
.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())
}

/// Negentropy reconciliation
///
/// <https://github.com/hoytech/negentropy>
Expand Down
12 changes: 12 additions & 0 deletions crates/nostr-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,18 @@ impl Client {
self.send_event(gift_wrap).await
}

/// Unwrap Gift Wrap event
///
/// Internally verify the `seal` event.
///
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
#[inline]
#[cfg(feature = "nip59")]
pub async fn unwrap_gift_wrap(&self, gift_wrap: &Event) -> Result<UnwrappedGift, Error> {
let signer: NostrSigner = self.signer().await?;
Ok(signer.unwrap_gift_wrap(gift_wrap).await?)
}

/// File metadata
///
/// <https://github.com/nostr-protocol/nips/blob/master/94.md>
Expand Down

0 comments on commit b8c93ab

Please sign in to comment.