Skip to content

Commit

Permalink
signer: add NostrSigner::sign_event_builder
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Feb 9, 2024
1 parent 0f8182d commit b3c12f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
13 changes: 12 additions & 1 deletion bindings/nostr-sdk-ffi/src/client/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::ops::Deref;
use std::sync::Arc;

use nostr_ffi::nips::nip44::Nip44Version;
use nostr_ffi::{Event, Keys, PublicKey, UnsignedEvent};
use nostr_ffi::{Event, EventBuilder, Keys, PublicKey, UnsignedEvent};
use nostr_sdk::{block_on, signer};
use uniffi::Object;

Expand Down Expand Up @@ -55,6 +55,17 @@ impl NostrSigner {
block_on(async move { Ok(Arc::new(self.inner.public_key().await?.into())) })
}

pub fn sign_event_builder(&self, builder: Arc<EventBuilder>) -> Result<Arc<Event>> {
block_on(async move {
Ok(Arc::new(
self.inner
.sign_event_builder(builder.as_ref().deref().clone())
.await?
.into(),
))
})
}

pub fn sign_event(&self, unsigned: Arc<UnsignedEvent>) -> Result<Arc<Event>> {
block_on(async move {
Ok(Arc::new(
Expand Down
12 changes: 11 additions & 1 deletion bindings/nostr-sdk-js/src/client/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::ops::Deref;

use nostr_js::error::{into_err, Result};
use nostr_js::event::{JsEvent, JsUnsignedEvent};
use nostr_js::event::{JsEvent, JsEventBuilder, JsUnsignedEvent};
use nostr_js::key::{JsKeys, JsPublicKey};
use nostr_js::nips::nip07::JsNip07Signer;
use nostr_js::nips::nip44::JsNIP44Version;
Expand Down Expand Up @@ -64,6 +64,16 @@ impl JsNostrSigner {
Ok(self.inner.public_key().await.map_err(into_err)?.into())
}

#[wasm_bindgen(js_name = signEventBuilder)]
pub async fn sign_event_builder(&self, builder: &JsEventBuilder) -> Result<JsEvent> {
Ok(self
.inner
.sign_event_builder(builder.deref().clone())
.await
.map_err(into_err)?
.into())
}

#[wasm_bindgen(js_name = signEvent)]
pub async fn sign_event(&self, unsigned: &JsUnsignedEvent) -> Result<JsEvent> {
Ok(self
Expand Down
7 changes: 7 additions & 0 deletions crates/nostr-signer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ impl NostrSigner {
}
}

/// Sign an [EventBuilder]
pub async fn sign_event_builder(&self, builder: EventBuilder) -> Result<Event, Error> {
let public_key: XOnlyPublicKey = self.public_key().await?;
let unsigned: UnsignedEvent = builder.to_unsigned_event(public_key);
self.sign_event(unsigned).await
}

/// Sign an [UnsignedEvent]
pub async fn sign_event(&self, unsigned: UnsignedEvent) -> Result<Event, Error> {
match self {
Expand Down

0 comments on commit b3c12f6

Please sign in to comment.