diff --git a/Cargo.lock b/Cargo.lock index 78c7da7..edf307f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,6 +82,15 @@ version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" +[[package]] +name = "ar_archive_writer" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c269894b6fe5e9d7ada0cf69b5bf847ff35bc25fc271f08e1d080fce80339a" +dependencies = [ + "object", +] + [[package]] name = "arbitrary" version = "1.4.2" @@ -1157,7 +1166,7 @@ dependencies = [ [[package]] name = "collections" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "indexmap", "rustc-hash 2.1.1", @@ -1597,7 +1606,7 @@ dependencies = [ [[package]] name = "derive_refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "proc-macro2", "quote", @@ -2494,7 +2503,7 @@ dependencies = [ [[package]] name = "gpui" version = "0.2.2" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "anyhow", "as-raw-xcb-connection", @@ -2589,7 +2598,7 @@ dependencies = [ [[package]] name = "gpui_macros" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -2600,7 +2609,7 @@ dependencies = [ [[package]] name = "gpui_tokio" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "anyhow", "gpui", @@ -2829,7 +2838,7 @@ dependencies = [ [[package]] name = "http_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "anyhow", "async-compression", @@ -2854,7 +2863,7 @@ dependencies = [ [[package]] name = "http_client_tls" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "rustls", "rustls-platform-verifier", @@ -3333,9 +3342,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.81" +version = "0.3.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" +checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65" dependencies = [ "once_cell", "wasm-bindgen", @@ -3672,7 +3681,7 @@ dependencies = [ [[package]] name = "media" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "anyhow", "bindgen 0.71.1", @@ -3789,9 +3798,9 @@ dependencies = [ [[package]] name = "moxcms" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692af879e4d9383c0fd9dec15524af6b6977c8bf1c6b278a4526d5341347c574" +checksum = "0fbdd3d7436f8b5e892b8b7ea114271ff0fa00bc5acae845d53b07d498616ef6" dependencies = [ "num-traits", "pxfm", @@ -3928,7 +3937,7 @@ dependencies = [ [[package]] name = "nostr" version = "0.43.0" -source = "git+https://github.com/rust-nostr/nostr#806c46e33b49b35cf93d4d892999384f554ecd98" +source = "git+https://github.com/rust-nostr/nostr#4e08f80aa578c7f65802d1c307252a5be9aef8a7" dependencies = [ "aes", "base64", @@ -3952,7 +3961,7 @@ dependencies = [ [[package]] name = "nostr-connect" version = "0.43.0" -source = "git+https://github.com/rust-nostr/nostr#806c46e33b49b35cf93d4d892999384f554ecd98" +source = "git+https://github.com/rust-nostr/nostr#4e08f80aa578c7f65802d1c307252a5be9aef8a7" dependencies = [ "async-utility", "nostr", @@ -3964,7 +3973,7 @@ dependencies = [ [[package]] name = "nostr-database" version = "0.43.0" -source = "git+https://github.com/rust-nostr/nostr#806c46e33b49b35cf93d4d892999384f554ecd98" +source = "git+https://github.com/rust-nostr/nostr#4e08f80aa578c7f65802d1c307252a5be9aef8a7" dependencies = [ "flatbuffers", "lru", @@ -3975,7 +3984,7 @@ dependencies = [ [[package]] name = "nostr-lmdb" version = "0.43.0" -source = "git+https://github.com/rust-nostr/nostr#806c46e33b49b35cf93d4d892999384f554ecd98" +source = "git+https://github.com/rust-nostr/nostr#4e08f80aa578c7f65802d1c307252a5be9aef8a7" dependencies = [ "async-utility", "flume", @@ -3989,7 +3998,7 @@ dependencies = [ [[package]] name = "nostr-relay-pool" version = "0.43.0" -source = "git+https://github.com/rust-nostr/nostr#806c46e33b49b35cf93d4d892999384f554ecd98" +source = "git+https://github.com/rust-nostr/nostr#4e08f80aa578c7f65802d1c307252a5be9aef8a7" dependencies = [ "async-utility", "async-wsocket", @@ -4006,7 +4015,7 @@ dependencies = [ [[package]] name = "nostr-sdk" version = "0.43.0" -source = "git+https://github.com/rust-nostr/nostr#806c46e33b49b35cf93d4d892999384f554ecd98" +source = "git+https://github.com/rust-nostr/nostr#4e08f80aa578c7f65802d1c307252a5be9aef8a7" dependencies = [ "async-utility", "nostr", @@ -4280,6 +4289,15 @@ dependencies = [ "objc", ] +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.21.3" @@ -4514,7 +4532,7 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "perf" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "collections", "serde", @@ -4787,10 +4805,11 @@ dependencies = [ [[package]] name = "psm" -version = "0.1.27" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e66fcd288453b748497d8fb18bccc83a16b0518e3906d4b8df0a8d42d93dbb1c" +checksum = "d11f2fedc3b7dafdc2851bc52f277377c5473d378859be234bc7ebb593144d01" dependencies = [ + "ar_archive_writer", "cc", ] @@ -5130,7 +5149,7 @@ dependencies = [ [[package]] name = "refineable" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "derive_refineable", ] @@ -5237,7 +5256,7 @@ dependencies = [ [[package]] name = "reqwest_client" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "anyhow", "bytes", @@ -5291,12 +5310,11 @@ dependencies = [ [[package]] name = "rope" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "arrayvec", "log", "rayon", - "regex", "sum_tree", "unicode-segmentation", "util", @@ -5758,7 +5776,7 @@ checksum = "16c2f82143577edb4921b71ede051dac62ca3c16084e918bf7b40c96ae10eb33" [[package]] name = "semantic_version" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "anyhow", "serde", @@ -6204,7 +6222,7 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "sum_tree" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "arrayvec", "log", @@ -7240,7 +7258,7 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "util" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "anyhow", "async-fs", @@ -7275,7 +7293,7 @@ dependencies = [ [[package]] name = "util_macros" version = "0.1.0" -source = "git+https://github.com/zed-industries/zed#f503c65924fff9799b359b6c83994b2eaf7af7c8" +source = "git+https://github.com/zed-industries/zed#8a01e483396eec940e9af72ce8f900bb98381a4f" dependencies = [ "perf", "quote", @@ -7434,9 +7452,9 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" +checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60" dependencies = [ "cfg-if", "once_cell", @@ -7445,25 +7463,11 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" -dependencies = [ - "bumpalo", - "log", - "proc-macro2", - "quote", - "syn 2.0.108", - "wasm-bindgen-shared", -] - [[package]] name = "wasm-bindgen-futures" -version = "0.4.54" +version = "0.4.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e038d41e478cc73bae0ff9b36c60cff1c98b8f38f8d7e8061e79ee63608ac5c" +checksum = "551f88106c6d5e7ccc7cd9a16f312dd3b5d36ea8b4954304657d5dfba115d4a0" dependencies = [ "cfg-if", "js-sys", @@ -7474,9 +7478,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" +checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -7484,22 +7488,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" +checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc" dependencies = [ + "bumpalo", "proc-macro2", "quote", "syn 2.0.108", - "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" +checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76" dependencies = [ "unicode-ident", ] @@ -7616,9 +7620,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.81" +version = "0.3.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120" +checksum = "3a1f95c0d03a47f4ae1f7a64643a6bb97465d9b740f0fa8f90ea33915c99a9a1" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/crates/registry/src/room.rs b/crates/registry/src/room.rs index 2aad0cd..a55b1d6 100644 --- a/crates/registry/src/room.rs +++ b/crates/registry/src/room.rs @@ -549,9 +549,10 @@ impl Room { let receiver = Self::select_receiver(&signer_kind, member, encryption)?; let rumor = rumor.clone(); + let tags = vec![Tag::public_key(member)]; // Construct the gift wrap event - let event = EventBuilder::gift_wrap(&signer, &receiver, rumor, []).await?; + let event = EventBuilder::gift_wrap(&signer, &receiver, rumor, tags).await?; // Send the gift wrap event to the messaging relays match client.send_event_to(urls, &event).await { @@ -593,9 +594,10 @@ impl Room { let receiver = Self::select_receiver(&signer_kind, user_pubkey, encryption_pubkey)?; let rumor = rumor.clone(); + let tags = vec![Tag::public_key(user_pubkey)]; // Construct the gift-wrapped event - let event = EventBuilder::gift_wrap(&signer, &receiver, rumor, []).await?; + let event = EventBuilder::gift_wrap(&signer, &receiver, rumor, tags).await?; // Only send a backup message to current user if sent successfully to others if opts.backup() && reports.iter().all(|r| r.is_sent_success()) { diff --git a/crates/states/src/constants.rs b/crates/states/src/constants.rs index 355283a..8f1908b 100644 --- a/crates/states/src/constants.rs +++ b/crates/states/src/constants.rs @@ -4,6 +4,7 @@ pub const APP_PUBKEY: &str = "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZX pub const APP_UPDATER_ENDPOINT: &str = "https://coop-updater.reya.su/"; pub const SETTINGS_IDENTIFIER: &str = "coop:settings"; +pub const INBOX_SUB_ID: &str = "inbox"; /// Bootstrap Relays. pub const BOOTSTRAP_RELAYS: [&str; 5] = [ diff --git a/crates/states/src/state/mod.rs b/crates/states/src/state/mod.rs index d865677..f6f33ac 100644 --- a/crates/states/src/state/mod.rs +++ b/crates/states/src/state/mod.rs @@ -10,13 +10,13 @@ use nostr_lmdb::NostrLMDB; use nostr_sdk::prelude::*; use smol::lock::RwLock; -use crate::app_name; use crate::constants::{ BOOTSTRAP_RELAYS, METADATA_BATCH_LIMIT, METADATA_BATCH_TIMEOUT, QUERY_TIMEOUT, SEARCH_RELAYS, }; use crate::paths::config_dir; use crate::state::ingester::Ingester; use crate::state::tracker::EventTracker; +use crate::{app_name, INBOX_SUB_ID}; mod device; mod ingester; @@ -345,7 +345,7 @@ impl AppState { } } RelayMessage::EndOfStoredEvents(subscription_id) => { - if subscription_id.as_ref() == &SubscriptionId::new("inbox") { + if subscription_id.as_ref() == &SubscriptionId::new(INBOX_SUB_ID) { self.signal .send(SignalKind::GiftWrapStatus(UnwrappingStatus::Processing)) .await; @@ -687,8 +687,8 @@ impl AppState { // Send the announcement event to the relays self.client.send_event(&event).await?; - // Re-subscribes to gift wrap events - self.resubscribe_messages().await?; + // Resubscribe to gift wrap events that include the encryption public key + self.get_messages_with_encryption(public_key).await?; Ok(()) } @@ -698,14 +698,16 @@ impl AppState { /// NIP-4e: https://github.com/nostr-protocol/nips/blob/per-device-keys/4e.md pub async fn load_encryption_keys(&self, announcement: &Announcement) -> Result<(), Error> { let keys = self.get_keys("encryption").await?; + let public_key = announcement.public_key(); // Check if the encryption keys match the announcement - if announcement.public_key() == keys.public_key() { + if public_key == keys.public_key() { + // Update encryption keys let mut device = self.device.write().await; device.set_encryption(keys); - // Re-subscribes to gift wrap events - self.resubscribe_messages().await?; + // Resubscribe to gift wrap events that include the encryption public key + self.get_messages_with_encryption(public_key).await?; Ok(()) } else { @@ -751,15 +753,17 @@ impl AppState { let secret = SecretKey::from_hex(&decrypted)?; let keys = Keys::new(secret); + let public_key = keys.public_key(); // No longer need to hold the reader for device drop(device); + // Update encryption keys let mut device = self.device.write().await; device.set_encryption(keys); - // Re-subscribes to gift wrap events - self.resubscribe_messages().await?; + // Resubscribe to gift wrap events that include the encryption public key + self.get_messages_with_encryption(public_key).await?; } None => { // Construct encryption keys request event @@ -812,16 +816,19 @@ impl AppState { // Decrypt the payload using the client keys let decrypted = client_key.nip44_decrypt(&public_key, payload).await?; let secret = SecretKey::parse(&decrypted)?; + let keys = Keys::new(secret); + let public_key = keys.public_key(); // No longer need to hold the reader for device drop(device); + // Update encryption keys let mut device = self.device.write().await; device.set_encryption(keys); - // Re-subscribes to gift wrap events - self.resubscribe_messages().await?; + // Resubscribe to gift wrap events that include the encryption public key + self.get_messages_with_encryption(public_key).await?; Ok(()) } @@ -938,7 +945,7 @@ impl AppState { public_key: PublicKey, urls: &[RelayUrl], ) -> Result<(), Error> { - let id = SubscriptionId::new("inbox"); + let id = SubscriptionId::new(INBOX_SUB_ID); let filter = Filter::new().kind(Kind::GiftWrap).pubkey(public_key); // Ensure user's have at least one relay @@ -960,6 +967,29 @@ impl AppState { Ok(()) } + /// Resubscribes to gift wrap events that include the encryption public key + pub async fn get_messages_with_encryption(&self, encryption: PublicKey) -> Result<(), Error> { + let signer = self.client.signer().await?; + let public_key = signer.get_public_key().await?; + let urls = self.messaging_relays(public_key).await; + + let id = SubscriptionId::new(INBOX_SUB_ID); + + let filter = Filter::new() + .kind(Kind::GiftWrap) + .pubkeys(vec![public_key, encryption]); + + // Unsubscribe the previous subscription + self.client.unsubscribe(&id).await; + + // Subscribe to gift wrap events + self.client + .subscribe_with_id_to(&urls, id, filter, None) + .await?; + + Ok(()) + } + /// Gets messaging relays for public key pub async fn messaging_relays(&self, public_key: PublicKey) -> Vec { let mut relay_urls = vec![]; @@ -986,26 +1016,6 @@ impl AppState { relay_urls } - /// Re-subscribes to gift wrap events - pub async fn resubscribe_messages(&self) -> Result<(), Error> { - let signer = self.client.signer().await?; - let public_key = signer.get_public_key().await?; - let urls = self.messaging_relays(public_key).await; - - let filter = Filter::new().kind(Kind::GiftWrap).pubkey(public_key); - let id = SubscriptionId::new("inbox"); - - // Unsubscribe the previous subscription - self.client.unsubscribe(&id).await; - - // Subscribe to gift wrap events - self.client - .subscribe_with_id_to(&urls, id, filter, None) - .await?; - - Ok(()) - } - /// Stores an unwrapped event in local database with reference to original async fn set_rumor(&self, id: EventId, rumor: &UnsignedEvent) -> Result<(), Error> { let rumor_id = rumor.id.context("Rumor is missing an event id")?; @@ -1077,12 +1087,12 @@ impl AppState { // Try to unwrap with the available signer let unwrapped = self.try_unwrap_gift_wrap(gift_wrap).await?; - let sender = unwrapped.sender; + //let sender = unwrapped.sender; let mut rumor_unsigned = unwrapped.rumor; - if !self.verify_sender(sender, &rumor_unsigned).await { - return Err(anyhow!("Invalid rumor")); - }; + //if !self.verify_rumor_sender(sender, &rumor_unsigned) { + // return Err(anyhow!("Cannot verify the sender")); + //}; // Generate event id for the rumor if it doesn't have one rumor_unsigned.ensure_id(); @@ -1098,7 +1108,7 @@ impl AppState { // Helper method to try unwrapping with different signers async fn try_unwrap_gift_wrap(&self, gift_wrap: &Event) -> Result { - // Try to unwrap with the device's encryption keys first + // Try to unwrap with the encryption key first // NIP-4e: https://github.com/nostr-protocol/nips/blob/per-device-keys/4e.md if let Some(signer) = self.device.read().await.encryption.as_ref() { match UnwrappedGift::from_gift_wrap(signer, gift_wrap).await { @@ -1152,22 +1162,8 @@ impl AppState { } /// Verify that the sender of a rumor is the same as the sender of the event. - async fn verify_sender(&self, sender: PublicKey, rumor: &UnsignedEvent) -> bool { - // If we have encryption keys, verify the sender matches the device's public key - if let Some(keys) = self.device.read().await.encryption.as_ref() { - if let Ok(public_key) = keys.get_public_key().await { - let status = public_key == sender; - // Only return if the status is true - // else fallback to basic sender verification - if status { - return status; - } else { - return rumor.pubkey == sender; - } - } - } - - // Fall back to basic sender verification + #[allow(dead_code)] + fn verify_rumor_sender(&self, sender: PublicKey, rumor: &UnsignedEvent) -> bool { rumor.pubkey == sender }