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 | |
| 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.
| -rw-r--r-- | Cargo.lock | 73 | ||||
| -rw-r--r-- | Cargo.toml | 10 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 11 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 17 | ||||
| -rw-r--r-- | src/lib/client.rs | 46 | ||||
| -rw-r--r-- | src/lib/git_events.rs | 13 | ||||
| -rw-r--r-- | src/lib/login/mod.rs | 47 | ||||
| -rw-r--r-- | src/lib/repo_ref.rs | 3 | ||||
| -rw-r--r-- | test_utils/Cargo.toml | 8 | ||||
| -rw-r--r-- | test_utils/src/lib.rs | 25 | ||||
| -rw-r--r-- | tests/ngit_login.rs | 6 |
11 files changed, 139 insertions, 120 deletions
| @@ -325,8 +325,9 @@ dependencies = [ | |||
| 325 | 325 | ||
| 326 | [[package]] | 326 | [[package]] |
| 327 | name = "async-wsocket" | 327 | name = "async-wsocket" |
| 328 | version = "0.9.0" | 328 | version = "0.10.0" |
| 329 | source = "git+https://github.com/shadowylab/async-wsocket?rev=4d6a5b1780e65dc657ac36e5990a97c10feef072#4d6a5b1780e65dc657ac36e5990a97c10feef072" | 329 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 330 | checksum = "a107e3bdbe61e8e1e1341c57241b4b2d50501127b44bd2eff13b4635ab42d35a" | ||
| 330 | dependencies = [ | 331 | dependencies = [ |
| 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]] |
| 1844 | name = "nostr" | 1845 | name = "nostr" |
| 1845 | version = "0.35.0" | 1846 | version = "0.36.0" |
| 1846 | source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" | 1847 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1848 | checksum = "14ad56c1d9a59f4edc46b17bc64a217b38b99baefddc0080f85ad98a0855336d" | ||
| 1847 | dependencies = [ | 1849 | dependencies = [ |
| 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]] |
| 1877 | name = "nostr-connect" | ||
| 1878 | version = "0.36.0" | ||
| 1879 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 1880 | checksum = "29d2a145eecf951c5461fdb72a064142b422f882760542c855bc1eca02516afb" | ||
| 1881 | dependencies = [ | ||
| 1882 | "async-trait", | ||
| 1883 | "async-utility", | ||
| 1884 | "nostr", | ||
| 1885 | "nostr-relay-pool", | ||
| 1886 | "thiserror", | ||
| 1887 | "tokio", | ||
| 1888 | "tracing", | ||
| 1889 | ] | ||
| 1890 | |||
| 1891 | [[package]] | ||
| 1874 | name = "nostr-database" | 1892 | name = "nostr-database" |
| 1875 | version = "0.35.0" | 1893 | version = "0.36.0" |
| 1876 | source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" | 1894 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1895 | checksum = "1859abebf78d7d9e945b20c8faaf710c9db905adeb148035b803ae45792dbebe" | ||
| 1877 | dependencies = [ | 1896 | dependencies = [ |
| 1878 | "async-trait", | 1897 | "async-trait", |
| 1879 | "flatbuffers", | 1898 | "flatbuffers", |
| @@ -1886,8 +1905,9 @@ dependencies = [ | |||
| 1886 | 1905 | ||
| 1887 | [[package]] | 1906 | [[package]] |
| 1888 | name = "nostr-lmdb" | 1907 | name = "nostr-lmdb" |
| 1889 | version = "0.35.0" | 1908 | version = "0.36.0" |
| 1890 | source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" | 1909 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1910 | checksum = "964cd83b0fa821cd09e3cf02287a3581d7deb26c9cb6d03990936b3f0228ba84" | ||
| 1891 | dependencies = [ | 1911 | dependencies = [ |
| 1892 | "heed", | 1912 | "heed", |
| 1893 | "nostr", | 1913 | "nostr", |
| @@ -1899,8 +1919,9 @@ dependencies = [ | |||
| 1899 | 1919 | ||
| 1900 | [[package]] | 1920 | [[package]] |
| 1901 | name = "nostr-relay-pool" | 1921 | name = "nostr-relay-pool" |
| 1902 | version = "0.35.0" | 1922 | version = "0.36.0" |
| 1903 | source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" | 1923 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1924 | checksum = "e39cfcb30cab86b30ca9acba89f5ccb25a4142a5dc5fcfbf3edf34b204ddd7c7" | ||
| 1904 | dependencies = [ | 1925 | dependencies = [ |
| 1905 | "async-utility", | 1926 | "async-utility", |
| 1906 | "async-wsocket", | 1927 | "async-wsocket", |
| @@ -1917,8 +1938,9 @@ dependencies = [ | |||
| 1917 | 1938 | ||
| 1918 | [[package]] | 1939 | [[package]] |
| 1919 | name = "nostr-sdk" | 1940 | name = "nostr-sdk" |
| 1920 | version = "0.35.0" | 1941 | version = "0.36.0" |
| 1921 | source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" | 1942 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1943 | checksum = "e4739ed15ff81a0e474d79b38c3eb481ff5f968c1865f38ba46852daf6f6495e" | ||
| 1922 | dependencies = [ | 1944 | dependencies = [ |
| 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]] |
| 1938 | name = "nostr-signer" | ||
| 1939 | version = "0.35.0" | ||
| 1940 | source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" | ||
| 1941 | dependencies = [ | ||
| 1942 | "async-utility", | ||
| 1943 | "nostr", | ||
| 1944 | "nostr-relay-pool", | ||
| 1945 | "thiserror", | ||
| 1946 | "tokio", | ||
| 1947 | "tracing", | ||
| 1948 | ] | ||
| 1949 | |||
| 1950 | [[package]] | ||
| 1951 | name = "nostr-zapper" | 1959 | name = "nostr-zapper" |
| 1952 | version = "0.35.0" | 1960 | version = "0.36.0" |
| 1953 | source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" | 1961 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 1962 | checksum = "9d9709ecf8050bbe4ecf0e5efda2f25b690bb1761fc504e05654621ba9e568a8" | ||
| 1954 | dependencies = [ | 1963 | dependencies = [ |
| 1955 | "async-trait", | 1964 | "async-trait", |
| 1956 | "nostr", | 1965 | "nostr", |
| @@ -2038,9 +2047,11 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" | |||
| 2038 | 2047 | ||
| 2039 | [[package]] | 2048 | [[package]] |
| 2040 | name = "nwc" | 2049 | name = "nwc" |
| 2041 | version = "0.35.0" | 2050 | version = "0.36.0" |
| 2042 | source = "git+https://github.com/rust-nostr/nostr?rev=ede2a91#ede2a91ef7d3738b36a03243697fbd20efd335a1" | 2051 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2052 | checksum = "1b5f98bcaf232b3ec48e018792ca7bc2b90e7520d001a07b8218a9e76a03fda2" | ||
| 2043 | dependencies = [ | 2053 | dependencies = [ |
| 2054 | "async-trait", | ||
| 2044 | "async-utility", | 2055 | "async-utility", |
| 2045 | "nostr", | 2056 | "nostr", |
| 2046 | "nostr-relay-pool", | 2057 | "nostr-relay-pool", |
| @@ -24,11 +24,10 @@ futures = "0.3.28" | |||
| 24 | git2 = "0.19.0" | 24 | git2 = "0.19.0" |
| 25 | indicatif = "0.17.7" | 25 | indicatif = "0.17.7" |
| 26 | keyring = "2.0.5" | 26 | keyring = "2.0.5" |
| 27 | nostr = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } | 27 | nostr = "0.36.0" |
| 28 | nostr-database = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } | 28 | nostr-database = "0.36.0" |
| 29 | nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } | 29 | nostr-sdk = "0.36.0" |
| 30 | nostr-signer = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } | 30 | nostr-lmdb = "0.36.0" |
| 31 | nostr-lmdb = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } | ||
| 32 | passwords = "3.1.13" | 31 | passwords = "3.1.13" |
| 33 | qrcode = { version = "0.14.1", default-features = false } | 32 | qrcode = { version = "0.14.1", default-features = false } |
| 34 | scrypt = "0.11.0" | 33 | scrypt = "0.11.0" |
| @@ -38,6 +37,7 @@ serde_yaml = "0.9.27" | |||
| 38 | tokio = "1.33.0" | 37 | tokio = "1.33.0" |
| 39 | urlencoding = "2.1.3" | 38 | urlencoding = "2.1.3" |
| 40 | zeroize = "1.6.0" | 39 | zeroize = "1.6.0" |
| 40 | nostr-connect = "0.36.0" | ||
| 41 | 41 | ||
| 42 | [dev-dependencies] | 42 | [dev-dependencies] |
| 43 | assert_cmd = "2.0.12" | 43 | 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::{ | |||
| 29 | }; | 29 | }; |
| 30 | use nostr::nips::nip10::Marker; | 30 | use nostr::nips::nip10::Marker; |
| 31 | use nostr_sdk::{ | 31 | use 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 | }; |
| 34 | use nostr_signer::NostrSigner; | ||
| 35 | use repo_ref::RepoRef; | 34 | use repo_ref::RepoRef; |
| 36 | use repo_state::RepoState; | 35 | use repo_state::RepoState; |
| 37 | 36 | ||
| @@ -876,7 +875,7 @@ async fn get_merged_status_events( | |||
| 876 | repo_ref: &RepoRef, | 875 | repo_ref: &RepoRef, |
| 877 | git_repo: &Repo, | 876 | git_repo: &Repo, |
| 878 | remote_nostr_url: &str, | 877 | remote_nostr_url: &str, |
| 879 | signer: &NostrSigner, | 878 | signer: &Arc<dyn NostrSigner>, |
| 880 | refspecs_to_git_server: &Vec<String>, | 879 | refspecs_to_git_server: &Vec<String>, |
| 881 | ) -> Result<Vec<Event>> { | 880 | ) -> Result<Vec<Event>> { |
| 882 | let mut events = vec![]; | 881 | let mut events = vec![]; |
| @@ -952,7 +951,7 @@ async fn get_merged_status_events( | |||
| 952 | } | 951 | } |
| 953 | 952 | ||
| 954 | async fn create_merge_status( | 953 | async fn create_merge_status( |
| 955 | signer: &NostrSigner, | 954 | signer: &Arc<dyn NostrSigner>, |
| 956 | repo_ref: &RepoRef, | 955 | repo_ref: &RepoRef, |
| 957 | proposal: &Event, | 956 | proposal: &Event, |
| 958 | revision: &Option<Event>, | 957 | revision: &Option<Event>, |
| @@ -1194,14 +1193,14 @@ trait BuildRepoState { | |||
| 1194 | async fn build( | 1193 | async fn build( |
| 1195 | identifier: String, | 1194 | identifier: String, |
| 1196 | state: HashMap<String, String>, | 1195 | state: HashMap<String, String>, |
| 1197 | signer: &NostrSigner, | 1196 | signer: &Arc<dyn NostrSigner>, |
| 1198 | ) -> Result<RepoState>; | 1197 | ) -> Result<RepoState>; |
| 1199 | } | 1198 | } |
| 1200 | impl BuildRepoState for RepoState { | 1199 | impl BuildRepoState for RepoState { |
| 1201 | async fn build( | 1200 | async fn build( |
| 1202 | identifier: String, | 1201 | identifier: String, |
| 1203 | state: HashMap<String, String>, | 1202 | state: HashMap<String, String>, |
| 1204 | signer: &NostrSigner, | 1203 | signer: &Arc<dyn NostrSigner>, |
| 1205 | ) -> Result<RepoState> { | 1204 | ) -> Result<RepoState> { |
| 1206 | let mut tags = vec![Tag::identifier(identifier.clone())]; | 1205 | let mut tags = vec![Tag::identifier(identifier.clone())]; |
| 1207 | for (name, value) in &state { | 1206 | 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<()> { | |||
| 215 | let mut maintainers_string = if !args.other_maintainers.is_empty() { | 215 | let mut maintainers_string = if !args.other_maintainers.is_empty() { |
| 216 | [args.other_maintainers.clone()].concat().join(" ") | 216 | [args.other_maintainers.clone()].concat().join(" ") |
| 217 | } else if repo_ref.is_none() && repo_config_result.is_err() { | 217 | } else if repo_ref.is_none() && repo_config_result.is_err() { |
| 218 | signer.public_key().await?.to_bech32()? | 218 | signer.get_public_key().await?.to_bech32()? |
| 219 | } else { | 219 | } else { |
| 220 | let maintainers = if let Ok(config) = &repo_config_result { | 220 | let maintainers = if let Ok(config) = &repo_config_result { |
| 221 | config.maintainers.clone() | 221 | config.maintainers.clone() |
| @@ -228,7 +228,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 228 | .collect() | 228 | .collect() |
| 229 | } else { | 229 | } else { |
| 230 | //unreachable | 230 | //unreachable |
| 231 | vec![signer.public_key().await?.to_bech32()?] | 231 | vec![signer.get_public_key().await?.to_bech32()?] |
| 232 | }; | 232 | }; |
| 233 | // add current user if not present | 233 | // add current user if not present |
| 234 | if maintainers.iter().any(|m| { | 234 | if maintainers.iter().any(|m| { |
| @@ -240,15 +240,18 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 240 | }) { | 240 | }) { |
| 241 | maintainers.join(" ") | 241 | maintainers.join(" ") |
| 242 | } else { | 242 | } else { |
| 243 | [maintainers, vec![signer.public_key().await?.to_bech32()?]] | 243 | [ |
| 244 | .concat() | 244 | maintainers, |
| 245 | .join(" ") | 245 | vec![signer.get_public_key().await?.to_bech32()?], |
| 246 | ] | ||
| 247 | .concat() | ||
| 248 | .join(" ") | ||
| 246 | } | 249 | } |
| 247 | }; | 250 | }; |
| 248 | 'outer: loop { | 251 | 'outer: loop { |
| 249 | if !dont_ask | 252 | if !dont_ask |
| 250 | && signer | 253 | && signer |
| 251 | .public_key() | 254 | .get_public_key() |
| 252 | .await? | 255 | .await? |
| 253 | .to_bech32()? | 256 | .to_bech32()? |
| 254 | .eq(&maintainers_string) | 257 | .eq(&maintainers_string) |
| @@ -302,7 +305,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 302 | } | 305 | } |
| 303 | // add current user incase removed | 306 | // add current user incase removed |
| 304 | if !maintainers.iter().any(|m| user_ref.public_key.eq(m)) { | 307 | if !maintainers.iter().any(|m| user_ref.public_key.eq(m)) { |
| 305 | maintainers.push(signer.public_key().await?); | 308 | maintainers.push(signer.get_public_key().await?); |
| 306 | } | 309 | } |
| 307 | break maintainers; | 310 | break maintainers; |
| 308 | } | 311 | } |
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)?; |
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 @@ | |||
| 1 | use std::str::FromStr; | 1 | use std::{str::FromStr, sync::Arc}; |
| 2 | 2 | ||
| 3 | use anyhow::{bail, Context, Result}; | 3 | use anyhow::{bail, Context, Result}; |
| 4 | use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; | 4 | use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; |
| 5 | use nostr_sdk::{ | 5 | use 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 | }; |
| 9 | use nostr_signer::NostrSigner; | ||
| 10 | 9 | ||
| 11 | use crate::{ | 10 | use 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 | }; |
| 10 | use nostr_connect::client::NostrConnect; | ||
| 10 | use nostr_sdk::{ | 11 | use 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 | }; |
| 14 | use nostr_signer::Nip46Signer; | ||
| 15 | use qrcode::QrCode; | 15 | use qrcode::QrCode; |
| 16 | use tokio::sync::{oneshot, Mutex}; | 16 | use 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 | ||
| 289 | async fn get_nip46_signer_from_uri_and_key(uri: &str, app_key: &str) -> Result<NostrSigner> { | 287 | async 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 | ||
| 303 | async fn get_signer_with_git_config_nsec_or_bunker_without_prompts( | 304 | async 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 | ||
| 8 | use anyhow::{bail, Context, Result}; | 9 | use anyhow::{bail, Context, Result}; |
| @@ -116,7 +117,7 @@ impl TryFrom<nostr::Event> for RepoRef { | |||
| 116 | } | 117 | } |
| 117 | 118 | ||
| 118 | impl RepoRef { | 119 | impl 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" | |||
| 10 | directories = "5.0.1" | 10 | directories = "5.0.1" |
| 11 | futures = "0.3.28" | 11 | futures = "0.3.28" |
| 12 | git2 = "0.19.0" | 12 | git2 = "0.19.0" |
| 13 | nostr = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } | 13 | nostr = "0.36.0" |
| 14 | nostr-database = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } | 14 | nostr-database = "0.36.0" |
| 15 | nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } | 15 | nostr-sdk = "0.36.0" |
| 16 | nostr-lmdb = { git = "https://github.com/rust-nostr/nostr", rev = "ede2a91" } | 16 | nostr-lmdb = "0.36.0" |
| 17 | once_cell = "1.18.0" | 17 | once_cell = "1.18.0" |
| 18 | rand = "0.8" | 18 | rand = "0.8" |
| 19 | rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } | 19 | 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::{ | |||
| 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 | |||
| 35 | pub static TEST_KEY_1_KEYS: Lazy<nostr::Keys> = | 36 | pub 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 | ||
| 38 | pub static TEST_KEY_1_SIGNER: Lazy<NostrSigner> = | 39 | pub 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 | ||
| 41 | pub fn generate_test_key_1_signer() -> NostrSigner { | 42 | pub 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 | ||
| 45 | pub fn generate_test_key_1_metadata_event(name: &str) -> nostr::Event { | 46 | pub 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 | ||
| 59 | pub fn generate_test_key_1_kind_event(kind: Kind) -> nostr::Event { | 60 | pub 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 | ||
| 118 | pub fn generate_test_key_2_metadata_event(name: &str) -> nostr::Event { | 119 | pub 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 | ||
| 152 | pub fn generate_repo_ref_event() -> nostr::Event { | 153 | pub 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 | ], |