Skip to content

Commit b8c93ab

Browse files
committed
sdk: add Client::unwrap_gift_wrap method
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
1 parent 3da5490 commit b8c93ab

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* nostr: add `title`, `image` and `description` constructors to `Tag` ([Yuki Kishimoto])
4242
* pool: add `SendOutput` and `SendEventOutput` structs ([Yuki Kishimoto])
4343
* signer: add `NostrSigner::unwrap_gift_wrap` method ([Yuki Kishimoto])
44+
* sdk: add `Client::unwrap_gift_wrap` method ([Yuki Kishimoto])
4445
* js(sdk): partially expose `JsRelayPool` ([Yuki Kishimoto])
4546
* book: add some python examples ([RydalWater])
4647

bindings/nostr-sdk-ffi/src/client/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::ops::Deref;
77
use std::sync::Arc;
88
use std::time::Duration;
99

10+
use nostr_ffi::nips::nip59::UnwrappedGift;
1011
use nostr_ffi::{
1112
ClientMessage, Event, EventBuilder, EventId, FileMetadata, Filter, Metadata, PublicKey,
1213
Timestamp,
@@ -582,6 +583,15 @@ impl Client {
582583
.into())
583584
}
584585

586+
/// Unwrap Gift Wrap event
587+
///
588+
/// Internally verify the `seal` event
589+
///
590+
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
591+
pub async fn unwrap_gift_wrap(&self, gift_wrap: &Event) -> Result<UnwrappedGift> {
592+
Ok(self.inner.unwrap_gift_wrap(gift_wrap.deref()).await?.into())
593+
}
594+
585595
pub async fn file_metadata(
586596
&self,
587597
description: String,

bindings/nostr-sdk-js/src/client/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use nostr_js::error::{into_err, Result};
1010
use nostr_js::event::{JsEvent, JsEventArray, JsEventBuilder, JsEventId, JsTag};
1111
use nostr_js::key::JsPublicKey;
1212
use nostr_js::message::{JsClientMessage, JsRelayMessage};
13+
use nostr_js::nips::nip59::JsUnwrappedGift;
1314
use nostr_js::types::{JsContact, JsFilter, JsMetadata, JsTimestamp};
1415
use nostr_sdk::async_utility::thread;
1516
use nostr_sdk::prelude::*;
@@ -716,6 +717,21 @@ impl JsClient {
716717
.map(Into::into)
717718
}
718719

720+
/// Unwrap Gift Wrap event
721+
///
722+
/// Internally verify the `seal` event
723+
///
724+
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
725+
#[wasm_bindgen(js_name = unwrapGiftWrap)]
726+
pub async fn unwrap_gift_wrap(&self, gift_wrap: &JsEvent) -> Result<JsUnwrappedGift> {
727+
Ok(self
728+
.inner
729+
.unwrap_gift_wrap(gift_wrap.deref())
730+
.await
731+
.map_err(into_err)?
732+
.into())
733+
}
734+
719735
/// Negentropy reconciliation
720736
///
721737
/// <https://github.com/hoytech/negentropy>

crates/nostr-sdk/src/client/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,18 @@ impl Client {
15031503
self.send_event(gift_wrap).await
15041504
}
15051505

1506+
/// Unwrap Gift Wrap event
1507+
///
1508+
/// Internally verify the `seal` event.
1509+
///
1510+
/// <https://github.com/nostr-protocol/nips/blob/master/59.md>
1511+
#[inline]
1512+
#[cfg(feature = "nip59")]
1513+
pub async fn unwrap_gift_wrap(&self, gift_wrap: &Event) -> Result<UnwrappedGift, Error> {
1514+
let signer: NostrSigner = self.signer().await?;
1515+
Ok(signer.unwrap_gift_wrap(gift_wrap).await?)
1516+
}
1517+
15061518
/// File metadata
15071519
///
15081520
/// <https://github.com/nostr-protocol/nips/blob/master/94.md>

0 commit comments

Comments
 (0)