Skip to content

Commit a6fca2b

Browse files
committed
nostr: add neg_open method
1 parent 0037c28 commit a6fca2b

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

Cargo.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/nostr/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ std = [
2525
"bitcoin/rand-std",
2626
"bip39?/std",
2727
"chacha20?/std",
28+
"negentropy/std",
2829
"serde/std",
2930
"serde_json/std",
3031
"tracing/std",
@@ -55,6 +56,7 @@ bip39 = { version = "2.0", default-features = false, optional = true }
5556
bitcoin = { version = "0.30", default-features = false, features = ["rand", "serde"] }
5657
cbc = { version = "0.1", optional = true }
5758
chacha20 = { version = "0.9", optional = true }
59+
negentropy = { git = "https://github.com/yukibtc/rust-negentropy", rev = "62a65db938c7088d521980d3fc1e1593713a899d", default-features = false }
5860
nostr-ots = { version = "0.2", optional = true }
5961
once_cell = { workspace = true, optional = true }
6062
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls-webpki-roots", "socks"], optional = true }

crates/nostr/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub use bitcoin;
3131
pub use bitcoin::bech32;
3232
pub use bitcoin::hashes;
3333
pub use bitcoin::secp256k1;
34+
pub use negentropy;
3435
pub use serde_json;
3536
pub use url_fork::{self as url, Url};
3637

crates/nostr/src/message/client.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use alloc::string::{String, ToString};
99
use alloc::vec::Vec;
1010

1111
use bitcoin::secp256k1::{Secp256k1, Verification};
12+
use negentropy::{Bytes, Negentropy};
1213
#[cfg(feature = "std")]
1314
use serde::{Deserialize, Deserializer};
1415
use serde::{Serialize, Serializer};
@@ -122,6 +123,21 @@ impl ClientMessage {
122123
Self::Auth(Box::new(event))
123124
}
124125

126+
/// Create new `NEG-OPEN` message
127+
pub fn neg_open(
128+
negentropy: &mut Negentropy,
129+
subscription_id: &SubscriptionId,
130+
filter: Filter,
131+
) -> Result<Self, negentropy::Error> {
132+
let initial_message: Bytes = negentropy.initiate()?;
133+
Ok(Self::NegOpen {
134+
subscription_id: subscription_id.clone(),
135+
filter: Box::new(filter),
136+
id_size: negentropy.id_size() as u8,
137+
initial_message: initial_message.to_hex(),
138+
})
139+
}
140+
125141
/// Check if is an `EVENT` message
126142
pub fn is_event(&self) -> bool {
127143
matches!(self, ClientMessage::Event(_))

crates/nostr/src/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub use bitcoin::bech32::*;
1313
pub use bitcoin::hashes::*;
1414
pub use bitcoin::secp256k1::*;
1515
pub use bitcoin::*;
16+
pub use negentropy::*;
1617
pub use serde_json::*;
1718
pub use url_fork::*;
1819

0 commit comments

Comments
 (0)