From 30f1a3efa9265b1403a7aa68fffbd65291face3d Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 11 Nov 2024 13:08:35 +0000 Subject: 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. --- Cargo.lock | 73 ++++++++++++++++++++++----------------- Cargo.toml | 10 +++--- src/bin/git_remote_nostr/push.rs | 11 +++--- src/bin/ngit/sub_commands/init.rs | 17 +++++---- src/lib/client.rs | 46 +++++++++++++----------- src/lib/git_events.rs | 13 ++++--- src/lib/login/mod.rs | 47 +++++++++++++------------ src/lib/repo_ref.rs | 3 +- test_utils/Cargo.toml | 8 ++--- test_utils/src/lib.rs | 25 +++++++------- tests/ngit_login.rs | 6 ++-- 11 files changed, 139 insertions(+), 120 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b20b60a..43c8978 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -325,8 +325,9 @@ dependencies = [ [[package]] name = "async-wsocket" -version = "0.9.0" -source = "git+https://github.com/shadowylab/async-wsocket?rev=4d6a5b1780e65dc657ac36e5990a97c10feef072#4d6a5b1780e65dc657ac36e5990a97c10feef072" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a107e3bdbe61e8e1e1341c57241b4b2d50501127b44bd2eff13b4635ab42d35a" dependencies = [ "async-utility", "futures", @@ -1793,10 +1794,10 @@ dependencies = [ "keyring", "mockall", "nostr", + "nostr-connect", "nostr-database", "nostr-lmdb", "nostr-sdk", - "nostr-signer", "once_cell", "passwords", "qrcode", @@ -1842,10 +1843,12 @@ checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" [[package]] name = "nostr" -version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14ad56c1d9a59f4edc46b17bc64a217b38b99baefddc0080f85ad98a0855336d" dependencies = [ "aes", + "async-trait", "base64", "bech32", "bip39", @@ -1870,10 +1873,26 @@ dependencies = [ "web-sys", ] +[[package]] +name = "nostr-connect" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29d2a145eecf951c5461fdb72a064142b422f882760542c855bc1eca02516afb" +dependencies = [ + "async-trait", + "async-utility", + "nostr", + "nostr-relay-pool", + "thiserror", + "tokio", + "tracing", +] + [[package]] name = "nostr-database" -version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1859abebf78d7d9e945b20c8faaf710c9db905adeb148035b803ae45792dbebe" dependencies = [ "async-trait", "flatbuffers", @@ -1886,8 +1905,9 @@ dependencies = [ [[package]] name = "nostr-lmdb" -version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "964cd83b0fa821cd09e3cf02287a3581d7deb26c9cb6d03990936b3f0228ba84" dependencies = [ "heed", "nostr", @@ -1899,8 +1919,9 @@ dependencies = [ [[package]] name = "nostr-relay-pool" -version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e39cfcb30cab86b30ca9acba89f5ccb25a4142a5dc5fcfbf3edf34b204ddd7c7" dependencies = [ "async-utility", "async-wsocket", @@ -1917,8 +1938,9 @@ dependencies = [ [[package]] name = "nostr-sdk" -version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4739ed15ff81a0e474d79b38c3eb481ff5f968c1865f38ba46852daf6f6495e" dependencies = [ "async-utility", "atomic-destructor", @@ -1926,7 +1948,6 @@ dependencies = [ "nostr", "nostr-database", "nostr-relay-pool", - "nostr-signer", "nostr-zapper", "nwc", "thiserror", @@ -1934,23 +1955,11 @@ dependencies = [ "tracing", ] -[[package]] -name = "nostr-signer" -version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" -dependencies = [ - "async-utility", - "nostr", - "nostr-relay-pool", - "thiserror", - "tokio", - "tracing", -] - [[package]] name = "nostr-zapper" -version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d9709ecf8050bbe4ecf0e5efda2f25b690bb1761fc504e05654621ba9e568a8" dependencies = [ "async-trait", "nostr", @@ -2038,9 +2047,11 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "nwc" -version = "0.35.0" -source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5f98bcaf232b3ec48e018792ca7bc2b90e7520d001a07b8218a9e76a03fda2" dependencies = [ + "async-trait", "async-utility", "nostr", "nostr-relay-pool", diff --git a/Cargo.toml b/Cargo.toml index ed99aea..afd4086 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,11 +24,10 @@ futures = "0.3.28" git2 = "0.19.0" indicatif = "0.17.7" keyring = "2.0.5" -nostr = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } -nostr-database = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } -nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } -nostr-signer = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } -nostr-lmdb = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } +nostr = "0.36.0" +nostr-database = "0.36.0" +nostr-sdk = "0.36.0" +nostr-lmdb = "0.36.0" passwords = "3.1.13" qrcode = { version = "0.14.1", default-features = false } scrypt = "0.11.0" @@ -38,6 +37,7 @@ serde_yaml = "0.9.27" tokio = "1.33.0" urlencoding = "2.1.3" zeroize = "1.6.0" +nostr-connect = "0.36.0" [dev-dependencies] assert_cmd = "2.0.12" diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 8fc8349..91c901a 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs @@ -29,9 +29,8 @@ use ngit::{ }; use nostr::nips::nip10::Marker; use nostr_sdk::{ - hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, Kind, PublicKey, Tag, + hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, Kind, NostrSigner, PublicKey, Tag, }; -use nostr_signer::NostrSigner; use repo_ref::RepoRef; use repo_state::RepoState; @@ -876,7 +875,7 @@ async fn get_merged_status_events( repo_ref: &RepoRef, git_repo: &Repo, remote_nostr_url: &str, - signer: &NostrSigner, + signer: &Arc, refspecs_to_git_server: &Vec, ) -> Result> { let mut events = vec![]; @@ -952,7 +951,7 @@ async fn get_merged_status_events( } async fn create_merge_status( - signer: &NostrSigner, + signer: &Arc, repo_ref: &RepoRef, proposal: &Event, revision: &Option, @@ -1194,14 +1193,14 @@ trait BuildRepoState { async fn build( identifier: String, state: HashMap, - signer: &NostrSigner, + signer: &Arc, ) -> Result; } impl BuildRepoState for RepoState { async fn build( identifier: String, state: HashMap, - signer: &NostrSigner, + signer: &Arc, ) -> Result { let mut tags = vec![Tag::identifier(identifier.clone())]; for (name, value) in &state { diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 1d6d0e9..aa43106 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs @@ -215,7 +215,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { let mut maintainers_string = if !args.other_maintainers.is_empty() { [args.other_maintainers.clone()].concat().join(" ") } else if repo_ref.is_none() && repo_config_result.is_err() { - signer.public_key().await?.to_bech32()? + signer.get_public_key().await?.to_bech32()? } else { let maintainers = if let Ok(config) = &repo_config_result { config.maintainers.clone() @@ -228,7 +228,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { .collect() } else { //unreachable - vec![signer.public_key().await?.to_bech32()?] + vec![signer.get_public_key().await?.to_bech32()?] }; // add current user if not present if maintainers.iter().any(|m| { @@ -240,15 +240,18 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { }) { maintainers.join(" ") } else { - [maintainers, vec![signer.public_key().await?.to_bech32()?]] - .concat() - .join(" ") + [ + maintainers, + vec![signer.get_public_key().await?.to_bech32()?], + ] + .concat() + .join(" ") } }; 'outer: loop { if !dont_ask && signer - .public_key() + .get_public_key() .await? .to_bech32()? .eq(&maintainers_string) @@ -302,7 +305,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { } // add current user incase removed if !maintainers.iter().any(|m| user_ref.public_key.eq(m)) { - maintainers.push(signer.public_key().await?); + maintainers.push(signer.get_public_key().await?); } break maintainers; } 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::{ fmt::{Display, Write}, fs::create_dir_all, path::Path, + sync::Arc, time::Duration, }; @@ -61,7 +62,7 @@ pub struct Client { pub trait Connect { fn default() -> Self; fn new(opts: Params) -> Self; - async fn set_signer(&mut self, signer: NostrSigner); + async fn set_signer(&mut self, signer: Arc); async fn connect(&self, relay_url: &Url) -> Result<()>; async fn disconnect(&self) -> Result<()>; fn get_fallback_relays(&self) -> &Vec; @@ -167,8 +168,8 @@ impl Connect for Client { } } - async fn set_signer(&mut self, signer: NostrSigner) { - self.client.set_signer(Some(signer)).await; + async fn set_signer(&mut self, signer: Arc) { + self.client.set_signer(signer).await; } async fn connect(&self, relay_url: &Url) -> Result<()> { @@ -660,29 +661,32 @@ fn get_dedup_events(relay_results: Vec>>) -> Vec dedup_events } -pub async fn sign_event(event_builder: EventBuilder, signer: &NostrSigner) -> Result { - if signer.r#type().eq(&nostr_signer::NostrSignerType::NIP46) { - let term = console::Term::stderr(); - term.write_line("signing event with remote signer...")?; - let event = signer - .sign_event_builder(event_builder) - .await - .context("failed to sign event")?; - term.clear_last_lines(1)?; - Ok(event) - } else { - signer - .sign_event_builder(event_builder) - .await - .context("failed to sign event") - } +pub async fn sign_event( + event_builder: EventBuilder, + signer: &Arc, +) -> Result { + // if signer.type_id().().eq(&nostr_signer::NostrSignerType::NIP46) { + let term = console::Term::stderr(); + term.write_line("signing event with remote signer...")?; + let event = signer + .sign_event(event_builder.build(signer.get_public_key().await?)) + .await + .context("failed to sign event")?; + term.clear_last_lines(1)?; + Ok(event) + // } else { + // signer + // .sign_event(event_builder.build(signer.get_public_key().await?)) + // .await + // .context("failed to sign event") + // } } -pub async fn fetch_public_key(signer: &NostrSigner) -> Result { +pub async fn fetch_public_key(signer: &Arc) -> Result { let term = console::Term::stderr(); term.write_line("fetching npub from remote signer...")?; let public_key = signer - .public_key() + .get_public_key() .await .context("failed to get npub from remote signer")?; term.clear_last_lines(1)?; diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index 2adc205..29c4cf2 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs @@ -1,12 +1,11 @@ -use std::str::FromStr; +use std::{str::FromStr, sync::Arc}; use anyhow::{bail, Context, Result}; use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; use nostr_sdk::{ - hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, FromBech32, Kind, PublicKey, Tag, - TagKind, TagStandard, UncheckedUrl, + hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, FromBech32, Kind, NostrSigner, + PublicKey, Tag, TagKind, TagStandard, UncheckedUrl, }; -use nostr_signer::NostrSigner; use crate::{ cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, @@ -86,7 +85,7 @@ pub async fn generate_patch_event( root_commit: &Sha1Hash, commit: &Sha1Hash, thread_event_id: Option, - signer: &nostr_sdk::NostrSigner, + signer: &Arc, repo_ref: &RepoRef, parent_patch_event_id: Option, series_count: Option<(u64, u64)>, @@ -309,7 +308,7 @@ pub async fn generate_cover_letter_and_patch_events( cover_letter_title_description: Option<(String, String)>, git_repo: &Repo, commits: &[Sha1Hash], - signer: &NostrSigner, + signer: &Arc, repo_ref: &RepoRef, root_proposal_id: &Option, mentions: &[nostr::Tag], @@ -624,7 +623,7 @@ mod tests { Tag::hashtag("root"), ], ) - .to_event(&nostr::Keys::generate())?) + .sign_with_keys(&nostr::Keys::generate())?) } #[test] diff --git a/src/lib/login/mod.rs b/src/lib/login/mod.rs index d774426..148b9d7 100644 --- a/src/lib/login/mod.rs +++ b/src/lib/login/mod.rs @@ -7,11 +7,11 @@ use nostr::{ nips::{nip05, nip46::NostrConnectURI}, PublicKey, }; +use nostr_connect::client::NostrConnect; use nostr_sdk::{ Alphabet, FromBech32, JsonUtil, Keys, Kind, NostrSigner, SingleLetterTag, Timestamp, ToBech32, Url, }; -use nostr_signer::Nip46Signer; use qrcode::QrCode; use tokio::sync::{oneshot, Mutex}; @@ -45,7 +45,7 @@ pub async fn launch( #[cfg(not(test))] client: Option<&Client>, change_user: bool, silent: bool, -) -> Result<(NostrSigner, UserRef)> { +) -> Result<(Arc, UserRef)> { if let Ok(signer) = match get_signer_without_prompts( git_repo, bunker_uri, @@ -86,7 +86,7 @@ pub async fn launch( .password(PromptPasswordParms::default().with_prompt("password")) .context("failed to get password input from interactor.password")?; if let Ok(keys) = get_keys_with_password(git_repo, &password) { - break Ok(NostrSigner::Keys(keys)); + break Ok(Arc::new(keys) as Arc); } eprintln!("incorrect password"); } @@ -101,7 +101,7 @@ pub async fn launch( // get user ref let user_ref = get_user_details( &signer - .public_key() + .get_public_key() .await .context("cannot get public key from signer")?, client, @@ -139,15 +139,13 @@ async fn get_signer_without_prompts( nsec: &Option, password: &Option, save_local: bool, -) -> Result { +) -> Result> { if let Some(nsec) = nsec { - Ok(NostrSigner::Keys(get_keys_from_nsec( + Ok(Arc::new(get_keys_from_nsec( git_repo, nsec, password, save_local, )?)) } else if let Some(password) = password { - Ok(NostrSigner::Keys(get_keys_with_password( - git_repo, password, - )?)) + Ok(Arc::new(get_keys_with_password(git_repo, password)?)) } else if let Some(bunker_uri) = bunker_uri { if let Some(bunker_app_key) = bunker_app_key { let signer = get_nip46_signer_from_uri_and_key(bunker_uri, bunker_app_key) @@ -156,7 +154,7 @@ async fn get_signer_without_prompts( if save_local { save_to_git_config( git_repo, - &signer.public_key().await?.to_bech32()?, + &signer.get_public_key().await?.to_bech32()?, &None, &Some((bunker_uri.to_string(),bunker_app_key.to_string())), false, @@ -286,11 +284,14 @@ fn get_keys_with_password(git_repo: &Repo, password: &str) -> Result Result { +async fn get_nip46_signer_from_uri_and_key( + uri: &str, + app_key: &str, +) -> Result> { let term = console::Term::stderr(); term.write_line("connecting to remote signer...")?; let uri = NostrConnectURI::parse(uri)?; - let signer = NostrSigner::nip46(Nip46Signer::new( + let signer = Arc::new(NostrConnect::new( uri, nostr::Keys::from_str(app_key).context("invalid app key")?, Duration::from_secs(10 * 60), @@ -302,7 +303,7 @@ async fn get_nip46_signer_from_uri_and_key(uri: &str, app_key: &str) -> Result Result { +) -> Result> { if let Ok(local_nsec) = &git_repo .get_git_config_item("nostr.nsec", Some(false)) .context("failed get local git config")? @@ -311,7 +312,7 @@ async fn get_signer_with_git_config_nsec_or_bunker_without_prompts( if local_nsec.contains("ncryptsec") { bail!("git global config item nostr.nsec is an ncryptsec") } - Ok(NostrSigner::Keys( + Ok(Arc::new( nostr::Keys::from_str(local_nsec).context("invalid nsec parameter")?, )) } else if let Ok((uri, app_key)) = get_git_config_bunker_uri_and_app_key(git_repo, Some(false)) @@ -325,7 +326,7 @@ async fn get_signer_with_git_config_nsec_or_bunker_without_prompts( if global_nsec.contains("ncryptsec") { bail!("git global config item nostr.nsec is an ncryptsec") } - Ok(NostrSigner::Keys( + Ok(Arc::new( nostr::Keys::from_str(global_nsec).context("invalid nsec parameter")?, )) } else if let Ok((uri, app_key)) = get_git_config_bunker_uri_and_app_key(git_repo, Some(true)) { @@ -358,7 +359,7 @@ async fn fresh_login( #[cfg(test)] client: Option<&MockConnect>, #[cfg(not(test))] client: Option<&Client>, always_save: bool, -) -> Result<(NostrSigner, UserRef)> { +) -> Result<(Arc, UserRef)> { let app_key = Keys::generate(); let app_key_secret = app_key.secret_key().to_secret_hex(); let relays = if let Some(client) = client { @@ -403,13 +404,13 @@ async fn fresh_login( if offline { return; } - if let Ok(nip46_signer) = Nip46Signer::new( + if let Ok(nostr_connect) = NostrConnect::new( nostr_connect_url.clone(), app_key.clone(), Duration::from_secs(10 * 60), None, ) { - let signer = NostrSigner::nip46(nip46_signer); + let signer: Arc = Arc::new(nostr_connect); if let Ok(pub_key) = fetch_public_key(&signer).await { let mut printer_locked = printer_clone.lock().await; printer_locked.clear_all(); @@ -437,7 +438,7 @@ async fn fresh_login( let (signer, public_key) = { if let Ok(Some((signer, public_key))) = rx.await { let bunker_url = NostrConnectURI::Bunker { - signer_public_key: public_key, + remote_signer_public_key: public_key, relays: relays.clone(), secret: None, }; @@ -455,7 +456,7 @@ async fn fresh_login( let mut public_key: Option = None; // prompt for nsec let mut prompt = "login with nsec / bunker url / nostr address"; - let signer = loop { + let signer: Arc = loop { let input = Interactor::default() .input(PromptInputParms::default().with_prompt(prompt)) .context("failed to get nsec input from interactor")?; @@ -463,7 +464,7 @@ async fn fresh_login( if let Err(error) = save_keys(git_repo, &keys, always_save) { eprintln!("{error}"); } - break NostrSigner::Keys(keys); + break Arc::new(keys); } let uri = if let Ok(uri) = NostrConnectURI::parse(&input) { uri @@ -501,7 +502,7 @@ async fn fresh_login( let public_key = if let Some(public_key) = public_key { public_key } else { - signer.public_key().await? + signer.get_public_key().await? }; (signer, public_key) } @@ -561,7 +562,7 @@ pub async fn fetch_nip46_uri_from_nip05(nip05: &str) -> Result bail!("nip05 provider isn't configured for remote login") } Ok(NostrConnectURI::Bunker { - signer_public_key: profile.public_key, + remote_signer_public_key: profile.public_key, relays: profile.nip46, secret: None, }) diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index 9bee641..8b48824 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs @@ -3,6 +3,7 @@ use std::{ fs::File, io::BufReader, str::FromStr, + sync::Arc, }; use anyhow::{bail, Context, Result}; @@ -116,7 +117,7 @@ impl TryFrom for RepoRef { } impl RepoRef { - pub async fn to_event(&self, signer: &NostrSigner) -> Result { + pub async fn to_event(&self, signer: &Arc) -> Result { sign_event( nostr_sdk::EventBuilder::new( nostr::event::Kind::GitRepoAnnouncement, diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml index f4e0c7e..5f88d8d 100644 --- a/test_utils/Cargo.toml +++ b/test_utils/Cargo.toml @@ -10,10 +10,10 @@ dialoguer = "0.10.4" directories = "5.0.1" futures = "0.3.28" git2 = "0.19.0" -nostr = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } -nostr-database = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } -nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } -nostr-lmdb = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } +nostr = "0.36.0" +nostr-database = "0.36.0" +nostr-sdk = "0.36.0" +nostr-lmdb = "0.36.0" once_cell = "1.18.0" rand = "0.8" rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 96558ef..ac17f80 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs @@ -2,6 +2,7 @@ use std::{ ffi::OsStr, path::{Path, PathBuf}, str::FromStr, + sync::Arc, time::Duration, }; @@ -35,16 +36,16 @@ pub static TEST_KEY_1_ENCRYPTED_WEAK: &str = "ncryptsec1qg835almhlrmyxqtqeva44d5 pub static TEST_KEY_1_KEYS: Lazy = Lazy::new(|| nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap()); -pub static TEST_KEY_1_SIGNER: Lazy = - Lazy::new(|| NostrSigner::Keys(nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap())); +pub static TEST_KEY_1_SIGNER: Lazy> = + Lazy::new(|| Arc::new(nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap())); -pub fn generate_test_key_1_signer() -> NostrSigner { - NostrSigner::Keys(nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap()) +pub fn generate_test_key_1_signer() -> Arc { + Arc::new(nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap()) } pub fn generate_test_key_1_metadata_event(name: &str) -> nostr::Event { nostr::event::EventBuilder::metadata(&nostr::Metadata::new().name(name)) - .to_event(&TEST_KEY_1_KEYS) + .sign_with_keys(&TEST_KEY_1_KEYS) .unwrap() } @@ -58,7 +59,7 @@ pub fn generate_test_key_1_metadata_event_old(name: &str) -> nostr::Event { pub fn generate_test_key_1_kind_event(kind: Kind) -> nostr::Event { nostr::event::EventBuilder::new(kind, "", []) - .to_event(&TEST_KEY_1_KEYS) + .sign_with_keys(&TEST_KEY_1_KEYS) .unwrap() } @@ -81,7 +82,7 @@ pub fn generate_test_key_1_relay_list_event() -> nostr::Event { }), ], ) - .to_event(&TEST_KEY_1_KEYS) + .sign_with_keys(&TEST_KEY_1_KEYS) .unwrap() } @@ -100,7 +101,7 @@ pub fn generate_test_key_1_relay_list_event_same_as_fallback() -> nostr::Event { }), ], ) - .to_event(&TEST_KEY_1_KEYS) + .sign_with_keys(&TEST_KEY_1_KEYS) .unwrap() } @@ -117,7 +118,7 @@ pub static TEST_KEY_2_KEYS: Lazy = pub fn generate_test_key_2_metadata_event(name: &str) -> nostr::Event { nostr::event::EventBuilder::metadata(&nostr::Metadata::new().name(name)) - .to_event(&TEST_KEY_2_KEYS) + .sign_with_keys(&TEST_KEY_2_KEYS) .unwrap() } @@ -134,7 +135,7 @@ pub fn make_event_old_or_change_user( ) -> nostr::Event { let mut unsigned = nostr::event::EventBuilder::new(event.kind, event.content.clone(), event.tags.clone()) - .to_unsigned_event(keys.public_key()); + .build(keys.public_key()); unsigned.created_at = nostr::types::Timestamp::from(nostr::types::Timestamp::now().as_u64() - how_old_in_secs); @@ -146,7 +147,7 @@ pub fn make_event_old_or_change_user( &unsigned.content, )); - unsigned.sign(keys).unwrap() + unsigned.sign_with_keys(keys).unwrap() } pub fn generate_repo_ref_event() -> nostr::Event { @@ -196,7 +197,7 @@ pub fn generate_repo_ref_event_with_git_server(git_servers: Vec) -> nost ), ], ) - .to_event(&TEST_KEY_1_KEYS) + .sign_with_keys(&TEST_KEY_1_KEYS) .unwrap() } diff --git a/tests/ngit_login.rs b/tests/ngit_login.rs index 477b25b..9b467b3 100644 --- a/tests/ngit_login.rs +++ b/tests/ngit_login.rs @@ -191,7 +191,7 @@ mod with_relays { nostr::event::EventBuilder::metadata( &nostr::Metadata::new().display_name("fred"), ) - .to_event(&TEST_KEY_1_KEYS) + .sign_with_keys(&TEST_KEY_1_KEYS) .unwrap(), generate_test_key_1_relay_list_event_same_as_fallback(), ], @@ -229,7 +229,7 @@ mod with_relays { &nostr::Metadata::new() .custom_field("displayName", "fred"), ) - .to_event(&TEST_KEY_1_KEYS) + .sign_with_keys(&TEST_KEY_1_KEYS) .unwrap(), generate_test_key_1_relay_list_event_same_as_fallback(), ], @@ -254,7 +254,7 @@ mod with_relays { nostr::event::EventBuilder::metadata( &nostr::Metadata::new().about("other info in metadata"), ) - .to_event(&TEST_KEY_1_KEYS) + .sign_with_keys(&TEST_KEY_1_KEYS) .unwrap(), generate_test_key_1_relay_list_event_same_as_fallback(), ], -- cgit v1.2.3