From 6bbbfb1d99281fb334332174652fe326c43cb4e7 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Tue, 9 Apr 2024 15:42:20 -0500 Subject: [PATCH 1/2] Use more relays --- src/main.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 83718d3..bb4734d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,18 @@ const ALLOWED_LOCALHOST: &str = "http://127.0.0.1:"; const API_VERSION: &str = "v1"; +const RELAYS: [&str; 9] = [ + "wss://nostr.mutinywallet.com", + "wss://relay.mutinywallet.com", + "wss://relay.snort.social", + "wss://nos.lol", + "wss://relay.damus.io", + "wss://relay.primal.net", + "wss://nostr.wine", + "wss://nostr.zbd.gg", + "wss://relay.nos.social", +]; + #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] pub struct SignerIdentity { pub service_id: i32, @@ -116,9 +128,7 @@ async fn main() -> anyhow::Result<()> { let nostr_nsec_str = std::env::var("NSEC").expect("NSEC must be set"); let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); let nostr = nostr_sdk::Client::new(&nostr_sk); - nostr.add_relay("wss://nostr.mutinywallet.com").await?; - nostr.add_relay("wss://relay.mutinywallet.com").await?; - nostr.add_relay("wss://relay.damus.io").await?; + nostr.add_relays(RELAYS).await.expect("Failed to add relays"); nostr.connect().await; // domain From baa4c80afa1ff8a2e8dba3c525dced0610015ad3 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Tue, 9 Apr 2024 16:04:32 -0500 Subject: [PATCH 2/2] Update rust-nostr --- Cargo.lock | 316 +++++++++++++++++++++++++++++++++--------------- Cargo.toml | 4 +- src/invoice.rs | 11 +- src/lnurlp.rs | 18 +-- src/main.rs | 14 ++- src/nostr.rs | 11 +- src/register.rs | 18 +-- src/routes.rs | 7 +- 8 files changed, 268 insertions(+), 131 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b23c8c5..b74cc69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + [[package]] name = "aes" version = "0.8.4" @@ -181,9 +191,9 @@ dependencies = [ [[package]] name = "async-utility" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3716c0d3970fe92d79a8f4cda2caf91113574505dff5b18e455e549d4b078e98" +checksum = "a349201d80b4aa18d17a34a182bdd7f8ddf845e9e57d2ea130a12e10ef1e3a47" dependencies = [ "futures-util", "gloo-timers 0.2.6", @@ -191,6 +201,24 @@ dependencies = [ "wasm-bindgen-futures", ] +[[package]] +name = "async-wsocket" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d253e375ea899cb131b92a474587e217634e7ea927c24d8098eecbcad0c5c97a" +dependencies = [ + "async-utility", + "futures-util", + "thiserror", + "tokio", + "tokio-rustls 0.25.0", + "tokio-socks", + "tokio-tungstenite", + "url", + "wasm-ws", + "webpki-roots 0.26.1", +] + [[package]] name = "async_io_stream" version = "0.3.3" @@ -202,6 +230,15 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "atomic-destructor" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4653a42bf04120a1d4e92452e006b4e3af4ab4afff8fb4af0f1bbb98418adf3e" +dependencies = [ + "tracing", +] + [[package]] name = "atty" version = "0.2.14" @@ -231,7 +268,7 @@ dependencies = [ "bytes", "futures-util", "headers", - "http", + "http 0.2.11", "http-body", "hyper", "itoa", @@ -261,7 +298,7 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", + "http 0.2.11", "http-body", "mime", "rustversion", @@ -680,6 +717,19 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "chacha20poly1305" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" +dependencies = [ + "aead", + "chacha20", + "cipher", + "poly1305", + "zeroize", +] + [[package]] name = "chrono" version = "0.4.34" @@ -730,6 +780,7 @@ checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ "crypto-common", "inout", + "zeroize", ] [[package]] @@ -835,25 +886,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crossbeam-deque" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - [[package]] name = "crossbeam-utils" version = "0.8.19" @@ -873,6 +905,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", + "rand_core", "typenum", ] @@ -1706,7 +1739,7 @@ dependencies = [ "futures-core", "futures-sink", "gloo-utils", - "http", + "http 0.2.11", "js-sys", "pin-project", "serde", @@ -1776,7 +1809,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.11", "indexmap 2.2.3", "slab", "tokio", @@ -1829,7 +1862,7 @@ dependencies = [ "base64 0.21.7", "bytes", "headers-core", - "http", + "http 0.2.11", "httpdate", "mime", "sha1", @@ -1841,7 +1874,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" dependencies = [ - "http", + "http 0.2.11", ] [[package]] @@ -1912,6 +1945,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -1919,7 +1963,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.11", "pin-project-lite", ] @@ -1958,7 +2002,7 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", + "http 0.2.11", "http-body", "httparse", "httpdate", @@ -1978,7 +2022,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http", + "http 0.2.11", "hyper", "rustls 0.21.10", "tokio", @@ -2235,7 +2279,7 @@ dependencies = [ "futures-channel", "futures-util", "gloo-net", - "http", + "http 0.2.11", "jsonrpsee-core", "pin-project", "rustls-pki-types", @@ -2303,7 +2347,7 @@ version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8a07ab8da9a283b906f6735ddd17d3680158bb72259e853441d1dd0167079ec" dependencies = [ - "http", + "http 0.2.11", "jsonrpsee-client-transport", "jsonrpsee-core", "jsonrpsee-types", @@ -2457,6 +2501,18 @@ version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +[[package]] +name = "lnurl-pay" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b628658116d331c9567f6cb22415d726125ff6e328d1fb1b422b1b58afeaec21" +dependencies = [ + "bech32", + "reqwest", + "serde", + "serde_json", +] + [[package]] name = "lock_api" version = "0.4.11" @@ -2700,9 +2756,9 @@ checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" [[package]] name = "nostr" -version = "0.26.3" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc0867f528a00885212fa8b0afecebf0506db6479ea1e666a5982317892c176" +checksum = "25e4e34578e8cc2b4050c6224a0c422b23ba1e61f2602b4e320c221ac3cbbc2e" dependencies = [ "aes", "base64 0.21.7", @@ -2710,26 +2766,49 @@ dependencies = [ "bitcoin 0.30.2", "cbc", "chacha20", + "chacha20poly1305", "getrandom", "instant", + "js-sys", "negentropy", "once_cell", "reqwest", + "scrypt", "serde", "serde_json", "tracing", - "url-fork", + "unicode-normalization", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", ] [[package]] name = "nostr-database" -version = "0.26.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "569f72670f79c10437eed69325b5b10ac69a1e23c2ee45d7d5781e6ec791cbce" +checksum = "8e15ab55f96ea5e560af0c75f1d942b1064266d443d11b2afbe51ca9ad78a018" dependencies = [ "async-trait", + "lru", + "nostr", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "nostr-relay-pool" +version = "0.29.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8efc437bcf8c433887a9897dfb6f99914170f656a2a66398e737b3050c2aa34" +dependencies = [ + "async-utility", + "async-wsocket", + "atomic-destructor", "nostr", - "rayon", + "nostr-database", "thiserror", "tokio", "tracing", @@ -2737,35 +2816,45 @@ dependencies = [ [[package]] name = "nostr-sdk" -version = "0.26.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9841e31596008a221e1a909164182ceda5c37fe654a62a9c202109af4756879f" +checksum = "81ed0ab9cbc3b20d3dba99337f2e0739f052ebe32133d690e212022a06a22044" dependencies = [ "async-utility", + "lnurl-pay", "nostr", "nostr-database", - "nostr-sdk-net", - "once_cell", + "nostr-relay-pool", + "nostr-signer", + "nostr-zapper", + "nwc", "thiserror", "tokio", "tracing", ] [[package]] -name = "nostr-sdk-net" -version = "0.26.0" +name = "nostr-signer" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7eccf4d9be57b513f5ee77e1931bf2fbf02da8ca1edae1feb001558e1e23332" +checksum = "307bdc7c26887d7e65632e66872989a19892dfe9f2c6dbd9a1d3f959c5c524d5" dependencies = [ - "futures-util", + "async-utility", + "nostr", + "nostr-relay-pool", "thiserror", "tokio", - "tokio-rustls 0.24.1", - "tokio-socks", - "tokio-tungstenite", - "url-fork", - "wasm-ws", - "webpki-roots 0.25.4", +] + +[[package]] +name = "nostr-zapper" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "061d5eb00b430747a984ea9e41cd82c849832151b4263d8230c9c220dc2c62f8" +dependencies = [ + "async-trait", + "nostr", + "thiserror", ] [[package]] @@ -2817,6 +2906,20 @@ dependencies = [ "libc", ] +[[package]] +name = "nwc" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1894ffe54a1e5adf8dbb22b5a290c0748ec4a88aa07fa69c4359010edea49ed" +dependencies = [ + "async-utility", + "nostr", + "nostr-relay-pool", + "nostr-zapper", + "thiserror", + "tracing", +] + [[package]] name = "object" version = "0.32.2" @@ -2975,6 +3078,16 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest 0.10.7", + "hmac", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -3029,6 +3142,17 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "poly1305" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" +dependencies = [ + "cpufeatures", + "opaque-debug", + "universal-hash", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -3192,26 +3316,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "rayon" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -3277,7 +3381,7 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", + "http 0.2.11", "http-body", "hyper", "hyper-rustls", @@ -3470,6 +3574,15 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +[[package]] +name = "salsa20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" +dependencies = [ + "cipher", +] + [[package]] name = "schannel" version = "0.1.23" @@ -3494,6 +3607,18 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "scrypt" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0516a385866c09368f0b5bcd1caff3366aace790fcd46e2bb032697bb172fd1f" +dependencies = [ + "password-hash", + "pbkdf2", + "salsa20", + "sha2", +] + [[package]] name = "sct" version = "0.7.1" @@ -3663,6 +3788,7 @@ version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ + "indexmap 2.2.3", "itoa", "ryu", "serde", @@ -4089,17 +4215,18 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.20.1" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" dependencies = [ "futures-util", "log", - "rustls 0.21.10", + "rustls 0.22.2", + "rustls-pki-types", "tokio", - "tokio-rustls 0.24.1", + "tokio-rustls 0.25.0", "tungstenite", - "webpki-roots 0.25.4", + "webpki-roots 0.26.1", ] [[package]] @@ -4160,7 +4287,7 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "http", + "http 0.2.11", "http-body", "http-range-header", "pin-project-lite", @@ -4250,18 +4377,19 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tungstenite" -version = "0.20.1" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" dependencies = [ "byteorder", "bytes", "data-encoding", - "http", + "http 1.1.0", "httparse", "log", "rand", - "rustls 0.21.10", + "rustls 0.22.2", + "rustls-pki-types", "sha1", "thiserror", "url", @@ -4295,6 +4423,16 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + [[package]] name = "untrusted" version = "0.7.1" @@ -4319,18 +4457,6 @@ dependencies = [ "serde", ] -[[package]] -name = "url-fork" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fa3323c39b8e786154d3000b70ae9af0e9bd746c9791456da0d4a1f68ad89d6" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", - "serde", -] - [[package]] name = "utf-8" version = "0.7.6" diff --git a/Cargo.toml b/Cargo.toml index 5d19270..a3c45e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,8 +28,8 @@ url = "2.5.0" itertools = "0.12.0" hex = "0.4.3" jwt-compact = { version = "0.8.0", features = ["es256k"] } -nostr = "0.26.0" -nostr-sdk = "0.26.0" +nostr = "0.29.1" +nostr-sdk = "0.29.0" log = "0.4.20" pretty_env_logger = "0.5" secp256k1 = { version = "0.28.2", default-features = false, features = ["hashes", "alloc"] } diff --git a/src/invoice.rs b/src/invoice.rs index b015bd1..6bb5193 100644 --- a/src/invoice.rs +++ b/src/invoice.rs @@ -13,7 +13,6 @@ use itertools::Itertools; use log::{error, info}; use nostr::prelude::rand::rngs::OsRng; use nostr::prelude::rand::RngCore; -use nostr::secp256k1::XOnlyPublicKey; use nostr::Keys; use nostr::{Event, EventBuilder, JsonUtil}; use nostr_sdk::Client; @@ -146,7 +145,7 @@ async fn notify_user( let dm = nostr .send_direct_msg( - XOnlyPublicKey::from_str(&user.pubkey)?, + ::nostr::PublicKey::from_str(&user.pubkey)?, json!({ "federation_id": invoice.federation_id, "tweak_index": invoice.user_invoice_index, @@ -163,7 +162,7 @@ async fn notify_user( // Send zap if needed if let Some(zap) = zap { let request = Event::from_json(&zap.request)?; - let event = create_zap_event(request, invoice.amount as u64, nostr.keys().await)?; + let event = create_zap_event(request, invoice.amount as u64, &state.nostr_sk)?; let event_id = nostr.send_event(event).await?; info!("Broadcasted zap {event_id}!"); @@ -176,7 +175,7 @@ async fn notify_user( } /// Creates a nostr zap event with a fake invoice -fn create_zap_event(request: Event, amt_msats: u64, nsec: Keys) -> Result { +fn create_zap_event(request: Event, amt_msats: u64, nsec: &Keys) -> Result { let preimage = &mut [0u8; 32]; OsRng.fill_bytes(preimage); let invoice_hash = Sha256::hash(preimage); @@ -199,12 +198,12 @@ fn create_zap_event(request: Event, amt_msats: u64, nsec: Keys) -> Result .min_final_cltv_expiry_delta(144) .build_signed(|hash| Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key))?; - let event = EventBuilder::new_zap_receipt( + let event = EventBuilder::zap_receipt( fake_invoice.to_string(), Some(hex::encode(preimage)), request, ) - .to_event(&nsec)?; + .to_event(nsec)?; Ok(event) } diff --git a/src/lnurlp.rs b/src/lnurlp.rs index f6d5435..071949c 100644 --- a/src/lnurlp.rs +++ b/src/lnurlp.rs @@ -40,7 +40,7 @@ pub async fn well_known_lnurlp( comment_allowed: None, tag: LnurlType::PayRequest, status: LnurlStatus::Ok, - nostr_pubkey: Some(state.nostr.keys().await.public_key()), + nostr_pubkey: Some(state.nostr_sk.public_key()), allows_nostr: true, }; @@ -201,7 +201,7 @@ pub async fn verify( mod tests_integration { use fedimint_core::api::InviteCode; use nostr::prelude::{rand, ZapRequestData}; - use nostr::{key::FromSkStr, EventBuilder, Keys}; + use nostr::{EventBuilder, Keys}; use secp256k1::Secp256k1; use std::path::PathBuf; use std::sync::Arc; @@ -226,7 +226,7 @@ mod tests_integration { // nostr let nostr_nsec_str = std::env::var("NSEC").expect("FM_DB_PATH must be set"); - let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); + let nostr_sk = Keys::from_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); let nostr = nostr_sdk::Client::new(&nostr_sk); // create blind signer @@ -242,6 +242,7 @@ mod tests_integration { free_pk: free_signer.pk, paid_pk: paid_signer.pk, domain: "http://hello.com".to_string(), + nostr_sk, }; let username = "wellknownuser".to_string(); @@ -277,7 +278,7 @@ mod tests_integration { // nostr let nostr_nsec_str = std::env::var("NSEC").expect("FM_DB_PATH must be set"); - let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); + let nostr_sk = Keys::from_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); let nostr = nostr_sdk::Client::new(&nostr_sk); // create blind signer @@ -295,6 +296,7 @@ mod tests_integration { free_pk: free_signer.pk, paid_pk: paid_signer.pk, domain: "http://hello.com".to_string(), + nostr_sk, }; let invite_code = InviteCode::from_str(INVITE_CODE).unwrap(); @@ -340,7 +342,7 @@ mod tests_integration { // nostr let nostr_nsec_str = std::env::var("NSEC").expect("FM_DB_PATH must be set"); - let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); + let nostr_sk = Keys::from_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); let nostr = nostr_sdk::Client::new(&nostr_sk); // create blind signer @@ -362,6 +364,7 @@ mod tests_integration { free_pk: free_signer.pk, paid_pk: paid_signer.pk, domain: "http://hello.com".to_string(), + nostr_sk, }; let invite_code = InviteCode::from_str(INVITE_CODE).unwrap(); @@ -405,7 +408,7 @@ mod tests_integration { // nostr let nostr_nsec_str = std::env::var("NSEC").expect("FM_DB_PATH must be set"); - let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); + let nostr_sk = Keys::from_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); let nostr = nostr_sdk::Client::new(&nostr_sk); // create blind signer @@ -427,6 +430,7 @@ mod tests_integration { free_pk: free_signer.pk, paid_pk: paid_signer.pk, domain: "http://hello.com".to_string(), + nostr_sk, }; let invite_code = InviteCode::from_str(INVITE_CODE).unwrap(); @@ -447,7 +451,7 @@ mod tests_integration { let zap_request = { let data = ZapRequestData::new(pk, vec![]); - EventBuilder::new_zap_request(data) + EventBuilder::public_zap_request(data) .to_event(&Keys::generate()) .unwrap() }; diff --git a/src/main.rs b/src/main.rs index bb4734d..d1ba5b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use axum::routing::get; use axum::{extract::DefaultBodyLimit, routing::post}; use axum::{http, Extension, Router, TypedHeader}; use log::{error, info}; -use nostr_sdk::nostr::{key::FromSkStr, Keys}; +use nostr_sdk::nostr::Keys; use secp256k1::{All, Secp256k1}; use std::{path::PathBuf, str::FromStr, sync::Arc}; use tbs::{AggregatePublicKey, PubKeyPoint}; @@ -18,8 +18,7 @@ use crate::{ mint::{setup_multimint, MultiMintWrapperTrait}, routes::{ check_pubkey, check_username, health_check, lnurl_callback_route, lnurl_verify_route, - register_route, root, validate_cors, well_known_lnurlp_route, - well_known_nip5_route, + register_route, root, validate_cors, well_known_lnurlp_route, well_known_nip5_route, }, }; @@ -70,6 +69,7 @@ pub struct State { mm: Arc, pub secp: Secp256k1, pub nostr: nostr_sdk::Client, + pub nostr_sk: Keys, pub domain: String, pub free_pk: AggregatePublicKey, pub paid_pk: AggregatePublicKey, @@ -126,9 +126,12 @@ async fn main() -> anyhow::Result<()> { // nostr let nostr_nsec_str = std::env::var("NSEC").expect("NSEC must be set"); - let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); + let nostr_sk = Keys::from_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); let nostr = nostr_sdk::Client::new(&nostr_sk); - nostr.add_relays(RELAYS).await.expect("Failed to add relays"); + nostr + .add_relays(RELAYS) + .await + .expect("Failed to add relays"); nostr.connect().await; // domain @@ -143,6 +146,7 @@ async fn main() -> anyhow::Result<()> { mm, secp, nostr, + nostr_sk, domain, free_pk, paid_pk, diff --git a/src/nostr.rs b/src/nostr.rs index 12628c0..2ce237d 100644 --- a/src/nostr.rs +++ b/src/nostr.rs @@ -1,6 +1,6 @@ use axum::http::StatusCode; use axum::Json; -use nostr::prelude::XOnlyPublicKey; +use nostr::PublicKey; use serde_json::{json, Value}; use std::{collections::HashMap, str::FromStr}; @@ -9,7 +9,7 @@ use crate::State; pub fn well_known_nip5( state: &State, name: String, -) -> Result, (StatusCode, Json)> { +) -> Result, (StatusCode, Json)> { let user = state.db.get_user_by_name(name).map_err(|e| { ( StatusCode::INTERNAL_SERVER_ERROR, @@ -21,7 +21,7 @@ pub fn well_known_nip5( if let Some(user) = user { names.insert( user.name, - XOnlyPublicKey::from_str(&user.pubkey).expect("valid npub"), + PublicKey::from_str(&user.pubkey).expect("valid npub"), ); } else { return Err(( @@ -35,7 +35,7 @@ pub fn well_known_nip5( #[cfg(all(test, feature = "integration-tests"))] mod tests_integration { - use nostr::{key::FromSkStr, Keys}; + use nostr::Keys; use secp256k1::{PublicKey, Secp256k1, XOnlyPublicKey}; use std::{str::FromStr, sync::Arc}; @@ -55,7 +55,7 @@ mod tests_integration { // nostr let nostr_nsec_str = std::env::var("NSEC").expect("FM_DB_PATH must be set"); - let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); + let nostr_sk = Keys::parse(nostr_nsec_str).expect("Invalid NOSTR_SK"); let nostr = nostr_sdk::Client::new(&nostr_sk); // create blind signer @@ -71,6 +71,7 @@ mod tests_integration { free_pk: free_signer.pk, paid_pk: paid_signer.pk, domain: "http://127.0.0.1:8080".to_string(), + nostr_sk, }; let username = "wellknownuser".to_string(); diff --git a/src/register.rs b/src/register.rs index 6ff4df0..2e74570 100644 --- a/src/register.rs +++ b/src/register.rs @@ -9,7 +9,7 @@ use fedimint_core::api::InviteCode; use lazy_regex::*; use log::error; use names::Generator; -use nostr::prelude::XOnlyPublicKey; +use nostr::PublicKey; use reqwest::StatusCode; pub static ALPHANUMERIC_REGEX: Lazy = lazy_regex!("^[a-z0-9-_.]+$"); @@ -57,7 +57,7 @@ pub async fn register( if requested_paid && !is_valid_name(&req.name.clone().unwrap()) { return Err((StatusCode::BAD_REQUEST, "Unavailable".to_string())); } - XOnlyPublicKey::from_str(&req.pubkey) + PublicKey::from_str(&req.pubkey) .map_err(|_| (StatusCode::BAD_REQUEST, "Nostr Pubkey Invalid".to_string()))?; // a different signer based on paid vs free @@ -220,7 +220,7 @@ mod tests_integration { use std::{str::FromStr, sync::Arc}; use fedimint_core::{api::InviteCode, config::FederationId, PeerId}; - use nostr::{key::FromSkStr, Keys}; + use nostr::Keys; use secp256k1::Secp256k1; use tbs::{blind_message, unblind_signature, BlindingKey}; @@ -243,7 +243,7 @@ mod tests_integration { let mock_mm = Arc::new(MockMultiMintWrapperTrait::new()); let nostr_nsec_str = std::env::var("NSEC").expect("FM_DB_PATH must be set"); - let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); + let nostr_sk = Keys::from_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); let nostr = nostr_sdk::Client::new(&nostr_sk); // create blind signer @@ -258,6 +258,7 @@ mod tests_integration { free_pk: free_signer.pk, paid_pk: paid_signer.pk, domain: "http://127.0.0.1:8080".to_string(), + nostr_sk, }; let name = "veryuniquename123".to_string(); @@ -295,7 +296,7 @@ mod tests_integration { // nostr let nostr_nsec_str = std::env::var("NSEC").expect("FM_DB_PATH must be set"); - let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); + let nostr_sk = Keys::from_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); let nostr = nostr_sdk::Client::new(&nostr_sk); // create blind signer @@ -311,6 +312,7 @@ mod tests_integration { free_pk: free_signer.pk, paid_pk: paid_signer.pk, domain: "http://127.0.0.1:8080".to_string(), + nostr_sk, }; // generate valid blinded message @@ -361,7 +363,7 @@ mod tests_integration { // nostr let nostr_nsec_str = std::env::var("NSEC").expect("FM_DB_PATH must be set"); - let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); + let nostr_sk = Keys::from_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); let nostr = nostr_sdk::Client::new(&nostr_sk); // create blind signer @@ -377,6 +379,7 @@ mod tests_integration { free_pk: free_signer.pk, paid_pk: paid_signer.pk, domain: "http://127.0.0.1:8080".to_string(), + nostr_sk, }; // generate valid blinded message @@ -423,7 +426,7 @@ mod tests_integration { // nostr let nostr_nsec_str = std::env::var("NSEC").expect("FM_DB_PATH must be set"); - let nostr_sk = Keys::from_sk_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); + let nostr_sk = Keys::from_str(&nostr_nsec_str).expect("Invalid NOSTR_SK"); let nostr = nostr_sdk::Client::new(&nostr_sk); // create blind signer @@ -439,6 +442,7 @@ mod tests_integration { free_pk: free_signer.pk, paid_pk: paid_signer.pk, domain: "http://127.0.0.1:8080".to_string(), + nostr_sk, }; // generate valid blinded message diff --git a/src/routes.rs b/src/routes.rs index 8db0054..6245c33 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -13,7 +13,6 @@ use axum::{Json, TypedHeader}; use fedimint_core::Amount; use fedimint_ln_common::lightning_invoice::Bolt11Invoice; use log::{error, info}; -use nostr::prelude::XOnlyPublicKey; use serde::{de, Deserialize, Deserializer, Serialize}; use serde_json::{json, Value}; use std::{collections::HashMap, fmt::Display, str::FromStr}; @@ -59,7 +58,7 @@ pub async fn check_pubkey( validate_cors(origin)?; // check it's a valid pubkey - XOnlyPublicKey::from_str(&pubkey) + nostr::PublicKey::from_str(&pubkey) .map_err(|_| (StatusCode::BAD_REQUEST, "Nostr Pubkey Invalid".to_string()))?; match check_registered_pubkey(&state, pubkey.clone()) { @@ -117,7 +116,7 @@ pub struct UserWellKnownNip5Req { #[derive(Deserialize, Serialize, Debug, Clone)] pub struct UserWellKnownNip5Resp { - pub names: HashMap, + pub names: HashMap, } pub async fn well_known_nip5_route( @@ -169,7 +168,7 @@ pub struct LnurlWellKnownResponse { pub tag: LnurlType, pub status: LnurlStatus, #[serde(skip_serializing_if = "Option::is_none")] - pub nostr_pubkey: Option, + pub nostr_pubkey: Option, pub allows_nostr: bool, }