upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-11-11 13:08:35 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-11-11 22:09:21 +0000
commit694325fa25e281b1a4c9d7f275f1a8e0f1ad7abf (patch)
tree3351c9e1fb1057bb61fb3fe74291b3462b17c054
parent35ad07180e418931dd499f799d704672d27ff35b (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.
-rw-r--r--Cargo.lock73
-rw-r--r--Cargo.toml10
-rw-r--r--src/bin/git_remote_nostr/push.rs11
-rw-r--r--src/bin/ngit/sub_commands/init.rs15
-rw-r--r--src/lib/client.rs46
-rw-r--r--src/lib/git_events.rs13
-rw-r--r--src/lib/login/mod.rs47
-rw-r--r--src/lib/repo_ref.rs3
-rw-r--r--test_utils/Cargo.toml8
-rw-r--r--test_utils/src/lib.rs25
-rw-r--r--tests/ngit_login.rs6
11 files changed, 138 insertions, 119 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b20b60a..43c8978 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -325,8 +325,9 @@ dependencies = [
325 325
326[[package]] 326[[package]]
327name = "async-wsocket" 327name = "async-wsocket"
328version = "0.9.0" 328version = "0.10.0"
329source = "git+https://github.com/shadowylab/async-wsocket?rev=4d6a5b1780e65dc657ac36e5990a97c10feef072#4d6a5b1780e65dc657ac36e5990a97c10feef072" 329source = "registry+https://github.com/rust-lang/crates.io-index"
330checksum = "a107e3bdbe61e8e1e1341c57241b4b2d50501127b44bd2eff13b4635ab42d35a"
330dependencies = [ 331dependencies = [
331 "async-utility", 332 "async-utility",
332 "futures", 333 "futures",
@@ -1793,10 +1794,10 @@ dependencies = [
1793 "keyring", 1794 "keyring",
1794 "mockall", 1795 "mockall",
1795 "nostr", 1796 "nostr",
1797 "nostr-connect",
1796 "nostr-database", 1798 "nostr-database",
1797 "nostr-lmdb", 1799 "nostr-lmdb",
1798 "nostr-sdk", 1800 "nostr-sdk",
1799 "nostr-signer",
1800 "once_cell", 1801 "once_cell",
1801 "passwords", 1802 "passwords",
1802 "qrcode", 1803 "qrcode",
@@ -1842,10 +1843,12 @@ checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
1842 1843
1843[[package]] 1844[[package]]
1844name = "nostr" 1845name = "nostr"
1845version = "0.35.0" 1846version = "0.36.0"
1846source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" 1847source = "registry+https://github.com/rust-lang/crates.io-index"
1848checksum = "14ad56c1d9a59f4edc46b17bc64a217b38b99baefddc0080f85ad98a0855336d"
1847dependencies = [ 1849dependencies = [
1848 "aes", 1850 "aes",
1851 "async-trait",
1849 "base64", 1852 "base64",
1850 "bech32", 1853 "bech32",
1851 "bip39", 1854 "bip39",
@@ -1871,9 +1874,25 @@ dependencies = [
1871] 1874]
1872 1875
1873[[package]] 1876[[package]]
1877name = "nostr-connect"
1878version = "0.36.0"
1879source = "registry+https://github.com/rust-lang/crates.io-index"
1880checksum = "29d2a145eecf951c5461fdb72a064142b422f882760542c855bc1eca02516afb"
1881dependencies = [
1882 "async-trait",
1883 "async-utility",
1884 "nostr",
1885 "nostr-relay-pool",
1886 "thiserror",
1887 "tokio",
1888 "tracing",
1889]
1890
1891[[package]]
1874name = "nostr-database" 1892name = "nostr-database"
1875version = "0.35.0" 1893version = "0.36.0"
1876source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" 1894source = "registry+https://github.com/rust-lang/crates.io-index"
1895checksum = "1859abebf78d7d9e945b20c8faaf710c9db905adeb148035b803ae45792dbebe"
1877dependencies = [ 1896dependencies = [
1878 "async-trait", 1897 "async-trait",
1879 "flatbuffers", 1898 "flatbuffers",
@@ -1886,8 +1905,9 @@ dependencies = [
1886 1905
1887[[package]] 1906[[package]]
1888name = "nostr-lmdb" 1907name = "nostr-lmdb"
1889version = "0.35.0" 1908version = "0.36.0"
1890source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" 1909source = "registry+https://github.com/rust-lang/crates.io-index"
1910checksum = "964cd83b0fa821cd09e3cf02287a3581d7deb26c9cb6d03990936b3f0228ba84"
1891dependencies = [ 1911dependencies = [
1892 "heed", 1912 "heed",
1893 "nostr", 1913 "nostr",
@@ -1899,8 +1919,9 @@ dependencies = [
1899 1919
1900[[package]] 1920[[package]]
1901name = "nostr-relay-pool" 1921name = "nostr-relay-pool"
1902version = "0.35.0" 1922version = "0.36.0"
1903source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" 1923source = "registry+https://github.com/rust-lang/crates.io-index"
1924checksum = "e39cfcb30cab86b30ca9acba89f5ccb25a4142a5dc5fcfbf3edf34b204ddd7c7"
1904dependencies = [ 1925dependencies = [
1905 "async-utility", 1926 "async-utility",
1906 "async-wsocket", 1927 "async-wsocket",
@@ -1917,8 +1938,9 @@ dependencies = [
1917 1938
1918[[package]] 1939[[package]]
1919name = "nostr-sdk" 1940name = "nostr-sdk"
1920version = "0.35.0" 1941version = "0.36.0"
1921source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" 1942source = "registry+https://github.com/rust-lang/crates.io-index"
1943checksum = "e4739ed15ff81a0e474d79b38c3eb481ff5f968c1865f38ba46852daf6f6495e"
1922dependencies = [ 1944dependencies = [
1923 "async-utility", 1945 "async-utility",
1924 "atomic-destructor", 1946 "atomic-destructor",
@@ -1926,7 +1948,6 @@ dependencies = [
1926 "nostr", 1948 "nostr",
1927 "nostr-database", 1949 "nostr-database",
1928 "nostr-relay-pool", 1950 "nostr-relay-pool",
1929 "nostr-signer",
1930 "nostr-zapper", 1951 "nostr-zapper",
1931 "nwc", 1952 "nwc",
1932 "thiserror", 1953 "thiserror",
@@ -1935,22 +1956,10 @@ dependencies = [
1935] 1956]
1936 1957
1937[[package]] 1958[[package]]
1938name = "nostr-signer"
1939version = "0.35.0"
1940source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1"
1941dependencies = [
1942 "async-utility",
1943 "nostr",
1944 "nostr-relay-pool",
1945 "thiserror",
1946 "tokio",
1947 "tracing",
1948]
1949
1950[[package]]
1951name = "nostr-zapper" 1959name = "nostr-zapper"
1952version = "0.35.0" 1960version = "0.36.0"
1953source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" 1961source = "registry+https://github.com/rust-lang/crates.io-index"
1962checksum = "9d9709ecf8050bbe4ecf0e5efda2f25b690bb1761fc504e05654621ba9e568a8"
1954dependencies = [ 1963dependencies = [
1955 "async-trait", 1964 "async-trait",
1956 "nostr", 1965 "nostr",
@@ -2038,9 +2047,11 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
2038 2047
2039[[package]] 2048[[package]]
2040name = "nwc" 2049name = "nwc"
2041version = "0.35.0" 2050version = "0.36.0"
2042source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" 2051source = "registry+https://github.com/rust-lang/crates.io-index"
2052checksum = "1b5f98bcaf232b3ec48e018792ca7bc2b90e7520d001a07b8218a9e76a03fda2"
2043dependencies = [ 2053dependencies = [
2054 "async-trait",
2044 "async-utility", 2055 "async-utility",
2045 "nostr", 2056 "nostr",
2046 "nostr-relay-pool", 2057 "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"
24git2 = "0.19.0" 24git2 = "0.19.0"
25indicatif = "0.17.7" 25indicatif = "0.17.7"
26keyring = "2.0.5" 26keyring = "2.0.5"
27nostr = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } 27nostr = "0.36.0"
28nostr-database = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } 28nostr-database = "0.36.0"
29nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } 29nostr-sdk = "0.36.0"
30nostr-signer = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } 30nostr-lmdb = "0.36.0"
31nostr-lmdb = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" }
32passwords = "3.1.13" 31passwords = "3.1.13"
33qrcode = { version = "0.14.1", default-features = false } 32qrcode = { version = "0.14.1", default-features = false }
34scrypt = "0.11.0" 33scrypt = "0.11.0"
@@ -38,6 +37,7 @@ serde_yaml = "0.9.27"
38tokio = "1.33.0" 37tokio = "1.33.0"
39urlencoding = "2.1.3" 38urlencoding = "2.1.3"
40zeroize = "1.6.0" 39zeroize = "1.6.0"
40nostr-connect = "0.36.0"
41 41
42[dev-dependencies] 42[dev-dependencies]
43assert_cmd = "2.0.12" 43assert_cmd = "2.0.12"
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs
index db86c04..c57e21f 100644
--- a/src/bin/git_remote_nostr/push.rs
+++ b/src/bin/git_remote_nostr/push.rs
@@ -29,9 +29,8 @@ use ngit::{
29}; 29};
30use nostr::nips::nip10::Marker; 30use nostr::nips::nip10::Marker;
31use nostr_sdk::{ 31use nostr_sdk::{
32 hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, Kind, PublicKey, Tag, 32 hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, Kind, NostrSigner, PublicKey, Tag,
33}; 33};
34use nostr_signer::NostrSigner;
35use repo_ref::RepoRef; 34use repo_ref::RepoRef;
36use repo_state::RepoState; 35use repo_state::RepoState;
37 36
@@ -868,7 +867,7 @@ async fn get_merged_status_events(
868 repo_ref: &RepoRef, 867 repo_ref: &RepoRef,
869 git_repo: &Repo, 868 git_repo: &Repo,
870 remote_nostr_url: &str, 869 remote_nostr_url: &str,
871 signer: &NostrSigner, 870 signer: &Arc<dyn NostrSigner>,
872 refspecs_to_git_server: &Vec<String>, 871 refspecs_to_git_server: &Vec<String>,
873) -> Result<Vec<Event>> { 872) -> Result<Vec<Event>> {
874 let mut events = vec![]; 873 let mut events = vec![];
@@ -944,7 +943,7 @@ async fn get_merged_status_events(
944} 943}
945 944
946async fn create_merge_status( 945async fn create_merge_status(
947 signer: &NostrSigner, 946 signer: &Arc<dyn NostrSigner>,
948 repo_ref: &RepoRef, 947 repo_ref: &RepoRef,
949 proposal: &Event, 948 proposal: &Event,
950 revision: &Option<Event>, 949 revision: &Option<Event>,
@@ -1186,14 +1185,14 @@ trait BuildRepoState {
1186 async fn build( 1185 async fn build(
1187 identifier: String, 1186 identifier: String,
1188 state: HashMap<String, String>, 1187 state: HashMap<String, String>,
1189 signer: &NostrSigner, 1188 signer: &Arc<dyn NostrSigner>,
1190 ) -> Result<RepoState>; 1189 ) -> Result<RepoState>;
1191} 1190}
1192impl BuildRepoState for RepoState { 1191impl BuildRepoState for RepoState {
1193 async fn build( 1192 async fn build(
1194 identifier: String, 1193 identifier: String,
1195 state: HashMap<String, String>, 1194 state: HashMap<String, String>,
1196 signer: &NostrSigner, 1195 signer: &Arc<dyn NostrSigner>,
1197 ) -> Result<RepoState> { 1196 ) -> Result<RepoState> {
1198 let mut tags = vec![Tag::identifier(identifier.clone())]; 1197 let mut tags = vec![Tag::identifier(identifier.clone())];
1199 for (name, value) in &state { 1198 for (name, value) in &state {
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs
index 8f9ff0d..50b8b3c 100644
--- a/src/bin/ngit/sub_commands/init.rs
+++ b/src/bin/ngit/sub_commands/init.rs
@@ -212,7 +212,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
212 let mut maintainers_string = if !args.other_maintainers.is_empty() { 212 let mut maintainers_string = if !args.other_maintainers.is_empty() {
213 [args.other_maintainers.clone()].concat().join(" ") 213 [args.other_maintainers.clone()].concat().join(" ")
214 } else if repo_ref.is_none() && repo_config_result.is_err() { 214 } else if repo_ref.is_none() && repo_config_result.is_err() {
215 signer.public_key().await?.to_bech32()? 215 signer.get_public_key().await?.to_bech32()?
216 } else { 216 } else {
217 let maintainers = if let Ok(config) = &repo_config_result { 217 let maintainers = if let Ok(config) = &repo_config_result {
218 config.maintainers.clone() 218 config.maintainers.clone()
@@ -225,7 +225,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
225 .collect() 225 .collect()
226 } else { 226 } else {
227 //unreachable 227 //unreachable
228 vec![signer.public_key().await?.to_bech32()?] 228 vec![signer.get_public_key().await?.to_bech32()?]
229 }; 229 };
230 // add current user if not present 230 // add current user if not present
231 if maintainers.iter().any(|m| { 231 if maintainers.iter().any(|m| {
@@ -237,9 +237,12 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
237 }) { 237 }) {
238 maintainers.join(" ") 238 maintainers.join(" ")
239 } else { 239 } else {
240 [maintainers, vec![signer.public_key().await?.to_bech32()?]] 240 [
241 .concat() 241 maintainers,
242 .join(" ") 242 vec![signer.get_public_key().await?.to_bech32()?],
243 ]
244 .concat()
245 .join(" ")
243 } 246 }
244 }; 247 };
245 'outer: loop { 248 'outer: loop {
@@ -263,7 +266,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
263 } 266 }
264 // add current user incase removed 267 // add current user incase removed
265 if !maintainers.iter().any(|m| user_ref.public_key.eq(m)) { 268 if !maintainers.iter().any(|m| user_ref.public_key.eq(m)) {
266 maintainers.push(signer.public_key().await?); 269 maintainers.push(signer.get_public_key().await?);
267 } 270 }
268 break maintainers; 271 break maintainers;
269 } 272 }
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 {
61pub trait Connect { 62pub 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
663pub async fn sign_event(event_builder: EventBuilder, signer: &NostrSigner) -> Result<nostr::Event> { 664pub 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
681pub async fn fetch_public_key(signer: &NostrSigner) -> Result<nostr::PublicKey> { 685pub 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)?;
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 @@
1use std::str::FromStr; 1use std::{str::FromStr, sync::Arc};
2 2
3use anyhow::{bail, Context, Result}; 3use anyhow::{bail, Context, Result};
4use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; 4use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19};
5use nostr_sdk::{ 5use nostr_sdk::{
6 hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, FromBech32, Kind, PublicKey, Tag, 6 hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, FromBech32, Kind, NostrSigner,
7 TagKind, TagStandard, UncheckedUrl, 7 PublicKey, Tag, TagKind, TagStandard, UncheckedUrl,
8}; 8};
9use nostr_signer::NostrSigner;
10 9
11use crate::{ 10use crate::{
12 cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, 11 cli_interactor::{Interactor, InteractorPrompt, PromptInputParms},
@@ -86,7 +85,7 @@ pub async fn generate_patch_event(
86 root_commit: &Sha1Hash, 85 root_commit: &Sha1Hash,
87 commit: &Sha1Hash, 86 commit: &Sha1Hash,
88 thread_event_id: Option<nostr::EventId>, 87 thread_event_id: Option<nostr::EventId>,
89 signer: &nostr_sdk::NostrSigner, 88 signer: &Arc<dyn NostrSigner>,
90 repo_ref: &RepoRef, 89 repo_ref: &RepoRef,
91 parent_patch_event_id: Option<nostr::EventId>, 90 parent_patch_event_id: Option<nostr::EventId>,
92 series_count: Option<(u64, u64)>, 91 series_count: Option<(u64, u64)>,
@@ -309,7 +308,7 @@ pub async fn generate_cover_letter_and_patch_events(
309 cover_letter_title_description: Option<(String, String)>, 308 cover_letter_title_description: Option<(String, String)>,
310 git_repo: &Repo, 309 git_repo: &Repo,
311 commits: &[Sha1Hash], 310 commits: &[Sha1Hash],
312 signer: &NostrSigner, 311 signer: &Arc<dyn NostrSigner>,
313 repo_ref: &RepoRef, 312 repo_ref: &RepoRef,
314 root_proposal_id: &Option<String>, 313 root_proposal_id: &Option<String>,
315 mentions: &[nostr::Tag], 314 mentions: &[nostr::Tag],
@@ -624,7 +623,7 @@ mod tests {
624 Tag::hashtag("root"), 623 Tag::hashtag("root"),
625 ], 624 ],
626 ) 625 )
627 .to_event(&nostr::Keys::generate())?) 626 .sign_with_keys(&nostr::Keys::generate())?)
628 } 627 }
629 628
630 #[test] 629 #[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::{
7 nips::{nip05, nip46::NostrConnectURI}, 7 nips::{nip05, nip46::NostrConnectURI},
8 PublicKey, 8 PublicKey,
9}; 9};
10use nostr_connect::client::NostrConnect;
10use nostr_sdk::{ 11use nostr_sdk::{
11 Alphabet, FromBech32, JsonUtil, Keys, Kind, NostrSigner, SingleLetterTag, Timestamp, ToBech32, 12 Alphabet, FromBech32, JsonUtil, Keys, Kind, NostrSigner, SingleLetterTag, Timestamp, ToBech32,
12 Url, 13 Url,
13}; 14};
14use nostr_signer::Nip46Signer;
15use qrcode::QrCode; 15use qrcode::QrCode;
16use tokio::sync::{oneshot, Mutex}; 16use tokio::sync::{oneshot, Mutex};
17 17
@@ -45,7 +45,7 @@ pub async fn launch(
45 #[cfg(not(test))] client: Option<&Client>, 45 #[cfg(not(test))] client: Option<&Client>,
46 change_user: bool, 46 change_user: bool,
47 silent: bool, 47 silent: bool,
48) -> Result<(NostrSigner, UserRef)> { 48) -> Result<(Arc<dyn NostrSigner>, UserRef)> {
49 if let Ok(signer) = match get_signer_without_prompts( 49 if let Ok(signer) = match get_signer_without_prompts(
50 git_repo, 50 git_repo,
51 bunker_uri, 51 bunker_uri,
@@ -86,7 +86,7 @@ pub async fn launch(
86 .password(PromptPasswordParms::default().with_prompt("password")) 86 .password(PromptPasswordParms::default().with_prompt("password"))
87 .context("failed to get password input from interactor.password")?; 87 .context("failed to get password input from interactor.password")?;
88 if let Ok(keys) = get_keys_with_password(git_repo, &password) { 88 if let Ok(keys) = get_keys_with_password(git_repo, &password) {
89 break Ok(NostrSigner::Keys(keys)); 89 break Ok(Arc::new(keys) as Arc<dyn NostrSigner>);
90 } 90 }
91 eprintln!("incorrect password"); 91 eprintln!("incorrect password");
92 } 92 }
@@ -101,7 +101,7 @@ pub async fn launch(
101 // get user ref 101 // get user ref
102 let user_ref = get_user_details( 102 let user_ref = get_user_details(
103 &signer 103 &signer
104 .public_key() 104 .get_public_key()
105 .await 105 .await
106 .context("cannot get public key from signer")?, 106 .context("cannot get public key from signer")?,
107 client, 107 client,
@@ -139,15 +139,13 @@ async fn get_signer_without_prompts(
139 nsec: &Option<String>, 139 nsec: &Option<String>,
140 password: &Option<String>, 140 password: &Option<String>,
141 save_local: bool, 141 save_local: bool,
142) -> Result<NostrSigner> { 142) -> Result<Arc<dyn NostrSigner>> {
143 if let Some(nsec) = nsec { 143 if let Some(nsec) = nsec {
144 Ok(NostrSigner::Keys(get_keys_from_nsec( 144 Ok(Arc::new(get_keys_from_nsec(
145 git_repo, nsec, password, save_local, 145 git_repo, nsec, password, save_local,
146 )?)) 146 )?))
147 } else if let Some(password) = password { 147 } else if let Some(password) = password {
148 Ok(NostrSigner::Keys(get_keys_with_password( 148 Ok(Arc::new(get_keys_with_password(git_repo, password)?))
149 git_repo, password,
150 )?))
151 } else if let Some(bunker_uri) = bunker_uri { 149 } else if let Some(bunker_uri) = bunker_uri {
152 if let Some(bunker_app_key) = bunker_app_key { 150 if let Some(bunker_app_key) = bunker_app_key {
153 let signer = get_nip46_signer_from_uri_and_key(bunker_uri, bunker_app_key) 151 let signer = get_nip46_signer_from_uri_and_key(bunker_uri, bunker_app_key)
@@ -156,7 +154,7 @@ async fn get_signer_without_prompts(
156 if save_local { 154 if save_local {
157 save_to_git_config( 155 save_to_git_config(
158 git_repo, 156 git_repo,
159 &signer.public_key().await?.to_bech32()?, 157 &signer.get_public_key().await?.to_bech32()?,
160 &None, 158 &None,
161 &Some((bunker_uri.to_string(),bunker_app_key.to_string())), 159 &Some((bunker_uri.to_string(),bunker_app_key.to_string())),
162 false, 160 false,
@@ -286,11 +284,14 @@ fn get_keys_with_password(git_repo: &Repo, password: &str) -> Result<nostr::Keys
286 .context("failed to decrypt stored nsec key with provided password") 284 .context("failed to decrypt stored nsec key with provided password")
287} 285}
288 286
289async fn get_nip46_signer_from_uri_and_key(uri: &str, app_key: &str) -> Result<NostrSigner> { 287async fn get_nip46_signer_from_uri_and_key(
288 uri: &str,
289 app_key: &str,
290) -> Result<Arc<dyn NostrSigner>> {
290 let term = console::Term::stderr(); 291 let term = console::Term::stderr();
291 term.write_line("connecting to remote signer...")?; 292 term.write_line("connecting to remote signer...")?;
292 let uri = NostrConnectURI::parse(uri)?; 293 let uri = NostrConnectURI::parse(uri)?;
293 let signer = NostrSigner::nip46(Nip46Signer::new( 294 let signer = Arc::new(NostrConnect::new(
294 uri, 295 uri,
295 nostr::Keys::from_str(app_key).context("invalid app key")?, 296 nostr::Keys::from_str(app_key).context("invalid app key")?,
296 Duration::from_secs(10 * 60), 297 Duration::from_secs(10 * 60),
@@ -302,7 +303,7 @@ async fn get_nip46_signer_from_uri_and_key(uri: &str, app_key: &str) -> Result<N
302 303
303async fn get_signer_with_git_config_nsec_or_bunker_without_prompts( 304async fn get_signer_with_git_config_nsec_or_bunker_without_prompts(
304 git_repo: &Repo, 305 git_repo: &Repo,
305) -> Result<NostrSigner> { 306) -> Result<Arc<dyn NostrSigner>> {
306 if let Ok(local_nsec) = &git_repo 307 if let Ok(local_nsec) = &git_repo
307 .get_git_config_item("nostr.nsec", Some(false)) 308 .get_git_config_item("nostr.nsec", Some(false))
308 .context("failed get local git config")? 309 .context("failed get local git config")?
@@ -311,7 +312,7 @@ async fn get_signer_with_git_config_nsec_or_bunker_without_prompts(
311 if local_nsec.contains("ncryptsec") { 312 if local_nsec.contains("ncryptsec") {
312 bail!("git global config item nostr.nsec is an ncryptsec") 313 bail!("git global config item nostr.nsec is an ncryptsec")
313 } 314 }
314 Ok(NostrSigner::Keys( 315 Ok(Arc::new(
315 nostr::Keys::from_str(local_nsec).context("invalid nsec parameter")?, 316 nostr::Keys::from_str(local_nsec).context("invalid nsec parameter")?,
316 )) 317 ))
317 } else if let Ok((uri, app_key)) = get_git_config_bunker_uri_and_app_key(git_repo, Some(false)) 318 } 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(
325 if global_nsec.contains("ncryptsec") { 326 if global_nsec.contains("ncryptsec") {
326 bail!("git global config item nostr.nsec is an ncryptsec") 327 bail!("git global config item nostr.nsec is an ncryptsec")
327 } 328 }
328 Ok(NostrSigner::Keys( 329 Ok(Arc::new(
329 nostr::Keys::from_str(global_nsec).context("invalid nsec parameter")?, 330 nostr::Keys::from_str(global_nsec).context("invalid nsec parameter")?,
330 )) 331 ))
331 } else if let Ok((uri, app_key)) = get_git_config_bunker_uri_and_app_key(git_repo, Some(true)) { 332 } 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(
358 #[cfg(test)] client: Option<&MockConnect>, 359 #[cfg(test)] client: Option<&MockConnect>,
359 #[cfg(not(test))] client: Option<&Client>, 360 #[cfg(not(test))] client: Option<&Client>,
360 always_save: bool, 361 always_save: bool,
361) -> Result<(NostrSigner, UserRef)> { 362) -> Result<(Arc<dyn NostrSigner>, UserRef)> {
362 let app_key = Keys::generate(); 363 let app_key = Keys::generate();
363 let app_key_secret = app_key.secret_key().to_secret_hex(); 364 let app_key_secret = app_key.secret_key().to_secret_hex();
364 let relays = if let Some(client) = client { 365 let relays = if let Some(client) = client {
@@ -403,13 +404,13 @@ async fn fresh_login(
403 if offline { 404 if offline {
404 return; 405 return;
405 } 406 }
406 if let Ok(nip46_signer) = Nip46Signer::new( 407 if let Ok(nostr_connect) = NostrConnect::new(
407 nostr_connect_url.clone(), 408 nostr_connect_url.clone(),
408 app_key.clone(), 409 app_key.clone(),
409 Duration::from_secs(10 * 60), 410 Duration::from_secs(10 * 60),
410 None, 411 None,
411 ) { 412 ) {
412 let signer = NostrSigner::nip46(nip46_signer); 413 let signer: Arc<dyn NostrSigner> = Arc::new(nostr_connect);
413 if let Ok(pub_key) = fetch_public_key(&signer).await { 414 if let Ok(pub_key) = fetch_public_key(&signer).await {
414 let mut printer_locked = printer_clone.lock().await; 415 let mut printer_locked = printer_clone.lock().await;
415 printer_locked.clear_all(); 416 printer_locked.clear_all();
@@ -437,7 +438,7 @@ async fn fresh_login(
437 let (signer, public_key) = { 438 let (signer, public_key) = {
438 if let Ok(Some((signer, public_key))) = rx.await { 439 if let Ok(Some((signer, public_key))) = rx.await {
439 let bunker_url = NostrConnectURI::Bunker { 440 let bunker_url = NostrConnectURI::Bunker {
440 signer_public_key: public_key, 441 remote_signer_public_key: public_key,
441 relays: relays.clone(), 442 relays: relays.clone(),
442 secret: None, 443 secret: None,
443 }; 444 };
@@ -455,7 +456,7 @@ async fn fresh_login(
455 let mut public_key: Option<PublicKey> = None; 456 let mut public_key: Option<PublicKey> = None;
456 // prompt for nsec 457 // prompt for nsec
457 let mut prompt = "login with nsec / bunker url / nostr address"; 458 let mut prompt = "login with nsec / bunker url / nostr address";
458 let signer = loop { 459 let signer: Arc<dyn NostrSigner> = loop {
459 let input = Interactor::default() 460 let input = Interactor::default()
460 .input(PromptInputParms::default().with_prompt(prompt)) 461 .input(PromptInputParms::default().with_prompt(prompt))
461 .context("failed to get nsec input from interactor")?; 462 .context("failed to get nsec input from interactor")?;
@@ -463,7 +464,7 @@ async fn fresh_login(
463 if let Err(error) = save_keys(git_repo, &keys, always_save) { 464 if let Err(error) = save_keys(git_repo, &keys, always_save) {
464 eprintln!("{error}"); 465 eprintln!("{error}");
465 } 466 }
466 break NostrSigner::Keys(keys); 467 break Arc::new(keys);
467 } 468 }
468 let uri = if let Ok(uri) = NostrConnectURI::parse(&input) { 469 let uri = if let Ok(uri) = NostrConnectURI::parse(&input) {
469 uri 470 uri
@@ -501,7 +502,7 @@ async fn fresh_login(
501 let public_key = if let Some(public_key) = public_key { 502 let public_key = if let Some(public_key) = public_key {
502 public_key 503 public_key
503 } else { 504 } else {
504 signer.public_key().await? 505 signer.get_public_key().await?
505 }; 506 };
506 (signer, public_key) 507 (signer, public_key)
507 } 508 }
@@ -561,7 +562,7 @@ pub async fn fetch_nip46_uri_from_nip05(nip05: &str) -> Result<NostrConnectURI>
561 bail!("nip05 provider isn't configured for remote login") 562 bail!("nip05 provider isn't configured for remote login")
562 } 563 }
563 Ok(NostrConnectURI::Bunker { 564 Ok(NostrConnectURI::Bunker {
564 signer_public_key: profile.public_key, 565 remote_signer_public_key: profile.public_key,
565 relays: profile.nip46, 566 relays: profile.nip46,
566 secret: None, 567 secret: None,
567 }) 568 })
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::{
3 fs::File, 3 fs::File,
4 io::BufReader, 4 io::BufReader,
5 str::FromStr, 5 str::FromStr,
6 sync::Arc,
6}; 7};
7 8
8use anyhow::{bail, Context, Result}; 9use anyhow::{bail, Context, Result};
@@ -116,7 +117,7 @@ impl TryFrom<nostr::Event> for RepoRef {
116} 117}
117 118
118impl RepoRef { 119impl RepoRef {
119 pub async fn to_event(&self, signer: &NostrSigner) -> Result<nostr::Event> { 120 pub async fn to_event(&self, signer: &Arc<dyn NostrSigner>) -> Result<nostr::Event> {
120 sign_event( 121 sign_event(
121 nostr_sdk::EventBuilder::new( 122 nostr_sdk::EventBuilder::new(
122 nostr::event::Kind::GitRepoAnnouncement, 123 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"
10directories = "5.0.1" 10directories = "5.0.1"
11futures = "0.3.28" 11futures = "0.3.28"
12git2 = "0.19.0" 12git2 = "0.19.0"
13nostr = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } 13nostr = "0.36.0"
14nostr-database = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } 14nostr-database = "0.36.0"
15nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } 15nostr-sdk = "0.36.0"
16nostr-lmdb = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } 16nostr-lmdb = "0.36.0"
17once_cell = "1.18.0" 17once_cell = "1.18.0"
18rand = "0.8" 18rand = "0.8"
19rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } 19rexpect = { 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::{
2 ffi::OsStr, 2 ffi::OsStr,
3 path::{Path, PathBuf}, 3 path::{Path, PathBuf},
4 str::FromStr, 4 str::FromStr,
5 sync::Arc,
5 time::Duration, 6 time::Duration,
6}; 7};
7 8
@@ -35,16 +36,16 @@ pub static TEST_KEY_1_ENCRYPTED_WEAK: &str = "ncryptsec1qg835almhlrmyxqtqeva44d5
35pub static TEST_KEY_1_KEYS: Lazy<nostr::Keys> = 36pub static TEST_KEY_1_KEYS: Lazy<nostr::Keys> =
36 Lazy::new(|| nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap()); 37 Lazy::new(|| nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap());
37 38
38pub static TEST_KEY_1_SIGNER: Lazy<NostrSigner> = 39pub static TEST_KEY_1_SIGNER: Lazy<Arc<dyn NostrSigner>> =
39 Lazy::new(|| NostrSigner::Keys(nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap())); 40 Lazy::new(|| Arc::new(nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap()));
40 41
41pub fn generate_test_key_1_signer() -> NostrSigner { 42pub fn generate_test_key_1_signer() -> Arc<dyn NostrSigner> {
42 NostrSigner::Keys(nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap()) 43 Arc::new(nostr::Keys::from_str(TEST_KEY_1_NSEC).unwrap())
43} 44}
44 45
45pub fn generate_test_key_1_metadata_event(name: &str) -> nostr::Event { 46pub fn generate_test_key_1_metadata_event(name: &str) -> nostr::Event {
46 nostr::event::EventBuilder::metadata(&nostr::Metadata::new().name(name)) 47 nostr::event::EventBuilder::metadata(&nostr::Metadata::new().name(name))
47 .to_event(&TEST_KEY_1_KEYS) 48 .sign_with_keys(&TEST_KEY_1_KEYS)
48 .unwrap() 49 .unwrap()
49} 50}
50 51
@@ -58,7 +59,7 @@ pub fn generate_test_key_1_metadata_event_old(name: &str) -> nostr::Event {
58 59
59pub fn generate_test_key_1_kind_event(kind: Kind) -> nostr::Event { 60pub fn generate_test_key_1_kind_event(kind: Kind) -> nostr::Event {
60 nostr::event::EventBuilder::new(kind, "", []) 61 nostr::event::EventBuilder::new(kind, "", [])
61 .to_event(&TEST_KEY_1_KEYS) 62 .sign_with_keys(&TEST_KEY_1_KEYS)
62 .unwrap() 63 .unwrap()
63} 64}
64 65
@@ -81,7 +82,7 @@ pub fn generate_test_key_1_relay_list_event() -> nostr::Event {
81 }), 82 }),
82 ], 83 ],
83 ) 84 )
84 .to_event(&TEST_KEY_1_KEYS) 85 .sign_with_keys(&TEST_KEY_1_KEYS)
85 .unwrap() 86 .unwrap()
86} 87}
87 88
@@ -100,7 +101,7 @@ pub fn generate_test_key_1_relay_list_event_same_as_fallback() -> nostr::Event {
100 }), 101 }),
101 ], 102 ],
102 ) 103 )
103 .to_event(&TEST_KEY_1_KEYS) 104 .sign_with_keys(&TEST_KEY_1_KEYS)
104 .unwrap() 105 .unwrap()
105} 106}
106 107
@@ -117,7 +118,7 @@ pub static TEST_KEY_2_KEYS: Lazy<nostr::Keys> =
117 118
118pub fn generate_test_key_2_metadata_event(name: &str) -> nostr::Event { 119pub fn generate_test_key_2_metadata_event(name: &str) -> nostr::Event {
119 nostr::event::EventBuilder::metadata(&nostr::Metadata::new().name(name)) 120 nostr::event::EventBuilder::metadata(&nostr::Metadata::new().name(name))
120 .to_event(&TEST_KEY_2_KEYS) 121 .sign_with_keys(&TEST_KEY_2_KEYS)
121 .unwrap() 122 .unwrap()
122} 123}
123 124
@@ -134,7 +135,7 @@ pub fn make_event_old_or_change_user(
134) -> nostr::Event { 135) -> nostr::Event {
135 let mut unsigned = 136 let mut unsigned =
136 nostr::event::EventBuilder::new(event.kind, event.content.clone(), event.tags.clone()) 137 nostr::event::EventBuilder::new(event.kind, event.content.clone(), event.tags.clone())
137 .to_unsigned_event(keys.public_key()); 138 .build(keys.public_key());
138 139
139 unsigned.created_at = 140 unsigned.created_at =
140 nostr::types::Timestamp::from(nostr::types::Timestamp::now().as_u64() - how_old_in_secs); 141 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(
146 &unsigned.content, 147 &unsigned.content,
147 )); 148 ));
148 149
149 unsigned.sign(keys).unwrap() 150 unsigned.sign_with_keys(keys).unwrap()
150} 151}
151 152
152pub fn generate_repo_ref_event() -> nostr::Event { 153pub fn generate_repo_ref_event() -> nostr::Event {
@@ -196,7 +197,7 @@ pub fn generate_repo_ref_event_with_git_server(git_servers: Vec<String>) -> nost
196 ), 197 ),
197 ], 198 ],
198 ) 199 )
199 .to_event(&TEST_KEY_1_KEYS) 200 .sign_with_keys(&TEST_KEY_1_KEYS)
200 .unwrap() 201 .unwrap()
201} 202}
202 203
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 {
191 nostr::event::EventBuilder::metadata( 191 nostr::event::EventBuilder::metadata(
192 &nostr::Metadata::new().display_name("fred"), 192 &nostr::Metadata::new().display_name("fred"),
193 ) 193 )
194 .to_event(&TEST_KEY_1_KEYS) 194 .sign_with_keys(&TEST_KEY_1_KEYS)
195 .unwrap(), 195 .unwrap(),
196 generate_test_key_1_relay_list_event_same_as_fallback(), 196 generate_test_key_1_relay_list_event_same_as_fallback(),
197 ], 197 ],
@@ -229,7 +229,7 @@ mod with_relays {
229 &nostr::Metadata::new() 229 &nostr::Metadata::new()
230 .custom_field("displayName", "fred"), 230 .custom_field("displayName", "fred"),
231 ) 231 )
232 .to_event(&TEST_KEY_1_KEYS) 232 .sign_with_keys(&TEST_KEY_1_KEYS)
233 .unwrap(), 233 .unwrap(),
234 generate_test_key_1_relay_list_event_same_as_fallback(), 234 generate_test_key_1_relay_list_event_same_as_fallback(),
235 ], 235 ],
@@ -254,7 +254,7 @@ mod with_relays {
254 nostr::event::EventBuilder::metadata( 254 nostr::event::EventBuilder::metadata(
255 &nostr::Metadata::new().about("other info in metadata"), 255 &nostr::Metadata::new().about("other info in metadata"),
256 ) 256 )
257 .to_event(&TEST_KEY_1_KEYS) 257 .sign_with_keys(&TEST_KEY_1_KEYS)
258 .unwrap(), 258 .unwrap(),
259 generate_test_key_1_relay_list_event_same_as_fallback(), 259 generate_test_key_1_relay_list_event_same_as_fallback(),
260 ], 260 ],