From 58cf0e145e76471e7c9f37f61e411271024f0b9a Mon Sep 17 00:00:00 2001 From: 0xtr Date: Sat, 25 Jan 2025 14:53:56 +0100 Subject: [PATCH] Upgrade nostr-sdk and fix errors --- Cargo.lock | 206 ++++++------------------------------ Cargo.toml | 2 +- src/handlers/mod.rs | 18 ++-- src/utilities/validation.rs | 117 +++++++++----------- 4 files changed, 94 insertions(+), 249 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8f78f19..08645b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -27,17 +27,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "aes" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" -dependencies = [ - "cfg-if", - "cipher", - "cpufeatures", -] - [[package]] name = "ahash" version = "0.8.11" @@ -148,9 +137,9 @@ dependencies = [ [[package]] name = "async-utility" -version = "0.2.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a349201d80b4aa18d17a34a182bdd7f8ddf845e9e57d2ea130a12e10ef1e3a47" +checksum = "a34a3b57207a7a1007832416c3e4862378c8451b4e8e093e436f48c2d3d2c151" dependencies = [ "futures-util", "gloo-timers", @@ -160,15 +149,14 @@ dependencies = [ [[package]] name = "async-wsocket" -version = "0.10.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a107e3bdbe61e8e1e1341c57241b4b2d50501127b44bd2eff13b4635ab42d35a" +checksum = "34d2efbc332d581321b37a3012c942b0555483030b5cfc1325a95c386b11e27b" dependencies = [ "async-utility", "futures", "futures-util", "js-sys", - "thiserror", "tokio", "tokio-rustls", "tokio-socks", @@ -189,12 +177,9 @@ dependencies = [ [[package]] name = "atomic-destructor" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d919cb60ba95c87ba42777e9e246c4e8d658057299b437b7512531ce0a09a23" -dependencies = [ - "tracing", -] +checksum = "ef49f5882e4b6afaac09ad239a4f8c70a24b8f2b0897edb1f706008efd109cf4" [[package]] name = "atomic-waker" @@ -210,9 +195,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "axum" -version = "0.7.5" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" +checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" dependencies = [ "async-trait", "axum-core", @@ -235,9 +220,9 @@ dependencies = [ "serde_json", "serde_path_to_error", "serde_urlencoded", - "sync_wrapper 1.0.1", + "sync_wrapper", "tokio", - "tower 0.4.13", + "tower 0.5.2", "tower-layer", "tower-service", "tracing", @@ -245,9 +230,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" dependencies = [ "async-trait", "bytes", @@ -258,7 +243,7 @@ dependencies = [ "mime", "pin-project-lite", "rustversion", - "sync_wrapper 0.1.2", + "sync_wrapper", "tower-layer", "tower-service", "tracing", @@ -498,7 +483,7 @@ dependencies = [ "tempfile", "tokio", "toml", - "tower 0.5.1", + "tower 0.5.2", "tower-http", "tracing", "tracing-subscriber", @@ -912,9 +897,9 @@ checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "gloo-timers" -version = "0.2.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994" dependencies = [ "futures-channel", "futures-core", @@ -1108,7 +1093,6 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", - "webpki-roots", ] [[package]] @@ -1277,18 +1261,6 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" -[[package]] -name = "lnurl-pay" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "536e7c782167a2d48346ca0b2677fad19eaef20f19a4ab868e4d5b96ca879def" -dependencies = [ - "bech32", - "reqwest", - "serde", - "serde_json", -] - [[package]] name = "lock_api" version = "0.4.12" @@ -1305,15 +1277,6 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" -[[package]] -name = "lru" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" -dependencies = [ - "hashbrown 0.14.5", -] - [[package]] name = "matchers" version = "0.1.0" @@ -1442,11 +1405,10 @@ dependencies = [ [[package]] name = "nostr" -version = "0.36.0" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14ad56c1d9a59f4edc46b17bc64a217b38b99baefddc0080f85ad98a0855336d" +checksum = "af7c1eebe17dd785e52e1f81149c1b50fa6ec92e4ac239840934d1ffbd4f631c" dependencies = [ - "aes", "async-trait", "base64", "bech32", @@ -1457,40 +1419,32 @@ dependencies = [ "chacha20poly1305", "getrandom", "instant", - "js-sys", "negentropy 0.3.1", "negentropy 0.4.3", "once_cell", - "reqwest", "scrypt", "serde", "serde_json", "unicode-normalization", "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", ] [[package]] name = "nostr-database" -version = "0.36.0" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1859abebf78d7d9e945b20c8faaf710c9db905adeb148035b803ae45792dbebe" +checksum = "4c175f769291b39e399905c1e1f0dcde0ea4959642db50a9a97f47fe73fac947" dependencies = [ "async-trait", - "lru", "nostr", - "thiserror", "tokio", - "tracing", ] [[package]] name = "nostr-relay-pool" -version = "0.36.0" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e39cfcb30cab86b30ca9acba89f5ccb25a4142a5dc5fcfbf3edf34b204ddd7c7" +checksum = "fc0a11b3d117d729b32efffacf7566ec6845e96e836cfab32c61b818cf90f8e4" dependencies = [ "async-utility", "async-wsocket", @@ -1499,42 +1453,24 @@ dependencies = [ "negentropy 0.4.3", "nostr", "nostr-database", - "thiserror", "tokio", - "tokio-stream", "tracing", ] [[package]] name = "nostr-sdk" -version = "0.36.0" +version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4739ed15ff81a0e474d79b38c3eb481ff5f968c1865f38ba46852daf6f6495e" +checksum = "dce4741c6b4bcb46fe5fdf6834c64b2d8aee090264319aa4749f268e20ace111" dependencies = [ "async-utility", - "atomic-destructor", - "lnurl-pay", "nostr", "nostr-database", "nostr-relay-pool", - "nostr-zapper", - "nwc", - "thiserror", "tokio", "tracing", ] -[[package]] -name = "nostr-zapper" -version = "0.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d9709ecf8050bbe4ecf0e5efda2f25b690bb1761fc504e05654621ba9e568a8" -dependencies = [ - "async-trait", - "nostr", - "thiserror", -] - [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -1592,21 +1528,6 @@ dependencies = [ "libm", ] -[[package]] -name = "nwc" -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", - "nostr-zapper", - "thiserror", - "tracing", -] - [[package]] name = "object" version = "0.36.1" @@ -1834,54 +1755,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "quinn" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b22d8e7369034b9a7132bc2008cac12f2013c8132b45e0554e6e20e2617f2156" -dependencies = [ - "bytes", - "pin-project-lite", - "quinn-proto", - "quinn-udp", - "rustc-hash", - "rustls", - "socket2", - "thiserror", - "tokio", - "tracing", -] - -[[package]] -name = "quinn-proto" -version = "0.11.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba92fb39ec7ad06ca2582c0ca834dfeadcaf06ddfc8e635c80aa7e1c05315fdd" -dependencies = [ - "bytes", - "rand", - "ring", - "rustc-hash", - "rustls", - "slab", - "thiserror", - "tinyvec", - "tracing", -] - -[[package]] -name = "quinn-udp" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" -dependencies = [ - "libc", - "once_cell", - "socket2", - "tracing", - "windows-sys 0.52.0", -] - [[package]] name = "quote" version = "1.0.36" @@ -2010,25 +1883,19 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "quinn", - "rustls", "rustls-pemfile", - "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", - "sync_wrapper 1.0.1", + "sync_wrapper", "system-configuration", "tokio", "tokio-native-tls", - "tokio-rustls", - "tokio-socks", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", "windows-registry", ] @@ -2073,12 +1940,6 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" -[[package]] -name = "rustc-hash" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" - [[package]] name = "rustix" version = "0.38.41" @@ -2633,12 +2494,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - [[package]] name = "sync_wrapper" version = "1.0.1" @@ -2876,21 +2731,22 @@ dependencies = [ "tokio", "tower-layer", "tower-service", - "tracing", ] [[package]] name = "tower" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2873938d487c3cfb9aed7546dc9f2711d867c9f90c46b889989a2cb84eba6b4f" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" dependencies = [ "futures-core", "futures-util", "pin-project-lite", - "sync_wrapper 0.1.2", + "sync_wrapper", + "tokio", "tower-layer", "tower-service", + "tracing", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 24042ba..59dbc39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ reqwest = { version = "0.12.9", features = ["json"] } tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter", "fmt"] } clap = { version = "4.5.21", features = ["derive"] } -nostr-sdk = "0.36.0" +nostr-sdk = "0.38.0" http-body-util = "0.1.2" tempfile = "3.14.0" mime2ext = "0.1.53" diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 0a1953d..47b5dff 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -850,7 +850,8 @@ mod tests { ), Tag::expiration(Timestamp::from(1643723400)), ]; - let auth_event = EventBuilder::new(Kind::Custom(1), "get".to_string(), tags) + let auth_event = EventBuilder::new(Kind::Custom(1), "get".to_string()) + .tags(tags) .sign_with_keys(&keypair) .unwrap(); @@ -1063,7 +1064,8 @@ mod tests { Tag::hashtag("list"), Tag::expiration(Timestamp::from(1643723400)), ]; - let auth_event = EventBuilder::new(Kind::Custom(1), "list".to_string(), tags) + let auth_event = EventBuilder::new(Kind::Custom(1), "list".to_string()) + .tags(tags) .sign_with_keys(&keypair) .unwrap(); @@ -1344,7 +1346,8 @@ mod tests { Tag::hashtag("delete"), Tag::expiration(Timestamp::from(1643723400)), ]; - let auth_event = EventBuilder::new(Kind::Custom(1), "delete".to_string(), tags) + let auth_event = EventBuilder::new(Kind::Custom(1), "delete".to_string()) + .tags(tags) .sign_with_keys(&keypair) .unwrap(); @@ -1385,7 +1388,8 @@ mod tests { Tag::hashtag("upload"), Tag::expiration(Timestamp::from(1643723400)), ]; - let auth_event = EventBuilder::new(Kind::Custom(1), "upload".to_string(), tags) + let auth_event = EventBuilder::new(Kind::Custom(1), "upload".to_string()) + .tags(tags) .sign_with_keys(&keypair) .unwrap(); @@ -1530,7 +1534,8 @@ mod tests { ]; // Create the auth header - let auth_event = EventBuilder::new(Kind::Custom(1), "upload".to_string(), tags) + let auth_event = EventBuilder::new(Kind::Custom(1), "upload".to_string()) + .tags(tags) .sign_with_keys(&keypair) .unwrap(); @@ -1775,7 +1780,8 @@ mod tests { } fn generate_blossom_auth_header(keys: Keys, action: String, tags: Vec) -> String { - let json_event = EventBuilder::new(Kind::Custom(24242), action, tags) + let json_event = EventBuilder::new(Kind::Custom(24242), action) + .tags(tags) .sign_with_keys(&keys) .unwrap() .as_json(); diff --git a/src/utilities/validation.rs b/src/utilities/validation.rs index 857ddb4..df11c83 100644 --- a/src/utilities/validation.rs +++ b/src/utilities/validation.rs @@ -131,7 +131,8 @@ mod tests { #[test] fn test_validate_auth_event_invalid_kind() { - let event = EventBuilder::new(Kind::TextNote, "test", vec![]) + let event = EventBuilder::new(Kind::TextNote, "test") + .tags(vec![]) .sign_with_keys(&Keys::generate()) .unwrap(); @@ -143,7 +144,8 @@ mod tests { #[test] fn test_validate_auth_event_invalid_created_at() { // Create event with invalid created_at - let event = EventBuilder::new(Kind::Custom(24242), "test", vec![]) + let event = EventBuilder::new(Kind::Custom(24242), "test") + .tags(vec![]) .custom_created_at(Timestamp::from(chrono::Utc::now().timestamp() as u64 + 100)) .sign_with_keys(&Keys::generate()) .unwrap(); @@ -156,13 +158,13 @@ mod tests { #[test] fn test_validate_auth_event_expired() { // Create event with expired expiration tag - let event = EventBuilder::new( - Kind::Custom(24242), - "test", - vec![Tag::custom(TagKind::Expiration, Some("1".to_string()))], - ) - .sign_with_keys(&Keys::generate()) - .unwrap(); + let event = EventBuilder::new(Kind::Custom(24242), "test") + .tags(vec![Tag::custom( + TagKind::Expiration, + Some("1".to_string()), + )]) + .sign_with_keys(&Keys::generate()) + .unwrap(); let result = validate_auth_event(&event, "upload"); assert!(result.is_err()); @@ -172,7 +174,8 @@ mod tests { #[test] fn test_validate_auth_event_missing_expiration_tag() { // Create event with expired expiration tag - let event = EventBuilder::new(Kind::Custom(24242), "test", vec![]) + let event = EventBuilder::new(Kind::Custom(24242), "test") + .tags(vec![]) .sign_with_keys(&Keys::generate()) .unwrap(); @@ -184,19 +187,16 @@ mod tests { #[test] fn test_validate_auth_event_incorrect_action() { // Create event with expired expiration tag - let event = EventBuilder::new( - Kind::Custom(24242), - "test", - vec![ + let event = EventBuilder::new(Kind::Custom(24242), "test") + .tags(vec![ Tag::expiration(Timestamp::from(chrono::Utc::now().timestamp() as u64)), Tag::custom( TagKind::SingleLetter(SingleLetterTag::from_char('t').unwrap()), Some("download".to_string()), ), - ], - ) - .sign_with_keys(&Keys::generate()) - .unwrap(); + ]) + .sign_with_keys(&Keys::generate()) + .unwrap(); let result = validate_auth_event(&event, "upload"); @@ -207,15 +207,12 @@ mod tests { #[test] fn test_validate_auth_event_missing_action_tag() { // Create event with expired expiration tag - let event = EventBuilder::new( - Kind::Custom(24242), - "test", - vec![Tag::expiration(Timestamp::from( + let event = EventBuilder::new(Kind::Custom(24242), "test") + .tags(vec![Tag::expiration(Timestamp::from( chrono::Utc::now().timestamp() as u64, - ))], - ) - .sign_with_keys(&Keys::generate()) - .unwrap(); + ))]) + .sign_with_keys(&Keys::generate()) + .unwrap(); let result = validate_auth_event(&event, "upload"); @@ -226,10 +223,8 @@ mod tests { #[test] fn test_validate_auth_event_valid() { // Create event with expired expiration tag - let event = EventBuilder::new( - Kind::Custom(24242), - "test", - vec![ + let event = EventBuilder::new(Kind::Custom(24242), "test") + .tags(vec![ Tag::expiration(Timestamp::from( chrono::Utc::now().timestamp() as u64 + 100000, )), @@ -237,10 +232,9 @@ mod tests { TagKind::SingleLetter(SingleLetterTag::from_char('t').unwrap()), Some("upload".to_string()), ), - ], - ) - .sign_with_keys(&Keys::generate()) - .unwrap(); + ]) + .sign_with_keys(&Keys::generate()) + .unwrap(); let result = validate_auth_event(&event, "upload"); @@ -249,7 +243,8 @@ mod tests { #[test] fn test_validate_auth_event_x_missing_filehash_tag() { - let event = EventBuilder::new(Kind::Custom(24242), "test", vec![]) + let event = EventBuilder::new(Kind::Custom(24242), "test") + .tags(vec![]) .sign_with_keys(&Keys::generate()) .unwrap(); @@ -260,16 +255,13 @@ mod tests { #[test] fn test_validate_auth_event_x_filehash_not_found() { - let event = EventBuilder::new( - Kind::Custom(24242), - "test", - vec![Tag::custom( + let event = EventBuilder::new(Kind::Custom(24242), "test") + .tags(vec![Tag::custom( TagKind::SingleLetter(SingleLetterTag::from_char('x').unwrap()), Some("other_hash".to_string()), - )], - ) - .sign_with_keys(&Keys::generate()) - .unwrap(); + )]) + .sign_with_keys(&Keys::generate()) + .unwrap(); let result = validate_auth_event_x(&event, "hash"); assert!(result.is_err()); @@ -278,16 +270,13 @@ mod tests { #[test] fn test_validate_auth_event_x_filehash_found() { - let event = EventBuilder::new( - Kind::Custom(24242), - "test", - vec![Tag::custom( + let event = EventBuilder::new(Kind::Custom(24242), "test") + .tags(vec![Tag::custom( TagKind::SingleLetter(SingleLetterTag::from_char('x').unwrap()), Some("hash".to_string()), - )], - ) - .sign_with_keys(&Keys::generate()) - .unwrap(); + )]) + .sign_with_keys(&Keys::generate()) + .unwrap(); let result = validate_auth_event_x(&event, "hash"); assert!(result.is_ok()); @@ -296,16 +285,13 @@ mod tests { #[test] fn test_validate_file_hash_invalid_hash() { - let event = EventBuilder::new( - Kind::Custom(24242), - "test", - vec![Tag::custom( + let event = EventBuilder::new(Kind::Custom(24242), "test") + .tags(vec![Tag::custom( TagKind::SingleLetter(SingleLetterTag::from_char('x').unwrap()), Some("other_hash".to_string()), - )], - ) - .sign_with_keys(&Keys::generate()) - .unwrap(); + )]) + .sign_with_keys(&Keys::generate()) + .unwrap(); let body = Bytes::from("Hello, World!"); let result = validate_file_hash(&event, &body); @@ -317,16 +303,13 @@ mod tests { fn test_validate_file_hash_valid_hash() { let body = Bytes::from("Hello, World!"); let hash = get_sha256_hash(&body); - let event = EventBuilder::new( - Kind::Custom(24242), - "test", - vec![Tag::custom( + let event = EventBuilder::new(Kind::Custom(24242), "test") + .tags(vec![Tag::custom( TagKind::SingleLetter(SingleLetterTag::from_char('x').unwrap()), Some(hash.to_string()), - )], - ) - .sign_with_keys(&Keys::generate()) - .unwrap(); + )]) + .sign_with_keys(&Keys::generate()) + .unwrap(); let result = validate_file_hash(&event, &body); assert!(result.is_ok());