diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-11 13:08:35 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-11-11 13:08:35 +0000 |
| commit | 30f1a3efa9265b1403a7aa68fffbd65291face3d (patch) | |
| tree | 335ceb627f6ae4a81a74b2bbae3f8cf1a2da2f41 /src/lib/client.rs | |
| parent | f08ee98ab7e19d4e42ffa85aa619f012441fbe47 (diff) | |
chore: bump rust-nostr v0.36
bump all rust-nostr packages to latest issued version.
there have been some breaking changes to nip46 and this applies
these changes.
Diffstat (limited to 'src/lib/client.rs')
| -rw-r--r-- | src/lib/client.rs | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs index 44ac0cb..d8c5f6d 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs | |||
| @@ -15,6 +15,7 @@ use std::{ | |||
| 15 | fmt::{Display, Write}, | 15 | fmt::{Display, Write}, |
| 16 | fs::create_dir_all, | 16 | fs::create_dir_all, |
| 17 | path::Path, | 17 | path::Path, |
| 18 | sync::Arc, | ||
| 18 | time::Duration, | 19 | time::Duration, |
| 19 | }; | 20 | }; |
| 20 | 21 | ||
| @@ -61,7 +62,7 @@ pub struct Client { | |||
| 61 | pub trait Connect { | 62 | pub trait Connect { |
| 62 | fn default() -> Self; | 63 | fn default() -> Self; |
| 63 | fn new(opts: Params) -> Self; | 64 | fn new(opts: Params) -> Self; |
| 64 | async fn set_signer(&mut self, signer: NostrSigner); | 65 | async fn set_signer(&mut self, signer: Arc<dyn NostrSigner>); |
| 65 | async fn connect(&self, relay_url: &Url) -> Result<()>; | 66 | async fn connect(&self, relay_url: &Url) -> Result<()>; |
| 66 | async fn disconnect(&self) -> Result<()>; | 67 | async fn disconnect(&self) -> Result<()>; |
| 67 | fn get_fallback_relays(&self) -> &Vec<String>; | 68 | fn get_fallback_relays(&self) -> &Vec<String>; |
| @@ -167,8 +168,8 @@ impl Connect for Client { | |||
| 167 | } | 168 | } |
| 168 | } | 169 | } |
| 169 | 170 | ||
| 170 | async fn set_signer(&mut self, signer: NostrSigner) { | 171 | async fn set_signer(&mut self, signer: Arc<dyn NostrSigner>) { |
| 171 | self.client.set_signer(Some(signer)).await; | 172 | self.client.set_signer(signer).await; |
| 172 | } | 173 | } |
| 173 | 174 | ||
| 174 | async fn connect(&self, relay_url: &Url) -> Result<()> { | 175 | async fn connect(&self, relay_url: &Url) -> Result<()> { |
| @@ -660,29 +661,32 @@ fn get_dedup_events(relay_results: Vec<Result<Vec<nostr::Event>>>) -> Vec<Event> | |||
| 660 | dedup_events | 661 | dedup_events |
| 661 | } | 662 | } |
| 662 | 663 | ||
| 663 | pub async fn sign_event(event_builder: EventBuilder, signer: &NostrSigner) -> Result<nostr::Event> { | 664 | pub async fn sign_event( |
| 664 | if signer.r#type().eq(&nostr_signer::NostrSignerType::NIP46) { | 665 | event_builder: EventBuilder, |
| 665 | let term = console::Term::stderr(); | 666 | signer: &Arc<dyn NostrSigner>, |
| 666 | term.write_line("signing event with remote signer...")?; | 667 | ) -> Result<nostr::Event> { |
| 667 | let event = signer | 668 | // if signer.type_id().().eq(&nostr_signer::NostrSignerType::NIP46) { |
| 668 | .sign_event_builder(event_builder) | 669 | let term = console::Term::stderr(); |
| 669 | .await | 670 | term.write_line("signing event with remote signer...")?; |
| 670 | .context("failed to sign event")?; | 671 | let event = signer |
| 671 | term.clear_last_lines(1)?; | 672 | .sign_event(event_builder.build(signer.get_public_key().await?)) |
| 672 | Ok(event) | 673 | .await |
| 673 | } else { | 674 | .context("failed to sign event")?; |
| 674 | signer | 675 | term.clear_last_lines(1)?; |
| 675 | .sign_event_builder(event_builder) | 676 | Ok(event) |
| 676 | .await | 677 | // } else { |
| 677 | .context("failed to sign event") | 678 | // signer |
| 678 | } | 679 | // .sign_event(event_builder.build(signer.get_public_key().await?)) |
| 680 | // .await | ||
| 681 | // .context("failed to sign event") | ||
| 682 | // } | ||
| 679 | } | 683 | } |
| 680 | 684 | ||
| 681 | pub async fn fetch_public_key(signer: &NostrSigner) -> Result<nostr::PublicKey> { | 685 | pub async fn fetch_public_key(signer: &Arc<dyn NostrSigner>) -> Result<nostr::PublicKey> { |
| 682 | let term = console::Term::stderr(); | 686 | let term = console::Term::stderr(); |
| 683 | term.write_line("fetching npub from remote signer...")?; | 687 | term.write_line("fetching npub from remote signer...")?; |
| 684 | let public_key = signer | 688 | let public_key = signer |
| 685 | .public_key() | 689 | .get_public_key() |
| 686 | .await | 690 | .await |
| 687 | .context("failed to get npub from remote signer")?; | 691 | .context("failed to get npub from remote signer")?; |
| 688 | term.clear_last_lines(1)?; | 692 | term.clear_last_lines(1)?; |