Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 26 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ image = { version = "0.25", features = ["jpeg", "png", "webp"] }
indexmap = "2.6.0"
log = "0.4.17"
md5 = "0.7.0"
nostr = { version = "0.37.0", default-features = false, features = ["std", "nip49"] }
nwc = "0.39.0"
nostr = { version = "0.44.0", default-features = false, features = ["std", "nip49"] }
nwc = "0.44.0"
mio = { version = "1.0.3", features = ["os-poll", "net"] }
nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "2b2e5e43c019b80b98f1db6a03a1b88ca699bfa3" }
#nostrdb = "0.6.1"
Expand Down
7 changes: 3 additions & 4 deletions crates/enostr/src/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl FullKeypair {
pub fn generate() -> Self {
let mut rng = nostr::secp256k1::rand::rngs::OsRng;
let (secret_key, _) = &nostr::SECP256K1.generate_keypair(&mut rng);
let (xopk, _) = secret_key.x_only_public_key(&nostr::SECP256K1);
let (xopk, _) = secret_key.x_only_public_key(nostr::SECP256K1);
let secret_key = nostr::SecretKey::from(*secret_key);
FullKeypair {
pubkey: Pubkey::new(xopk.serialize()),
Expand Down Expand Up @@ -160,8 +160,7 @@ impl SerializableKeypair {
pub fn to_keypair(&self, pass: &str) -> Keypair {
Keypair::new(
self.pubkey,
self.encrypted_secret_key
.and_then(|e| e.to_secret_key(pass).ok()),
self.encrypted_secret_key.and_then(|e| e.decrypt(pass).ok()),
)
}
}
Expand Down Expand Up @@ -236,7 +235,7 @@ fn parse_seckey<'a>(parser: &mut TokenParser<'a>) -> Result<SecretKey, ParseErro
let eseckey = EncryptedSecretKey::from_bech32(raw).map_err(|_| ParseError::DecodeFailed)?;

let seckey = eseckey
.to_secret_key(ESECKEY_PASS)
.decrypt(ESECKEY_PASS)
.map_err(|_| ParseError::DecodeFailed)?;

Ok(seckey)
Expand Down
2 changes: 1 addition & 1 deletion crates/enostr/src/relay/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl RelayPool {
return Ok(());
}
let relay = Relay::new(
nostr::RelayUrl::parse(url).map_err(|_| Error::InvalidRelayUrl)?,
nostr::RelayUrl::parse(&url).map_err(|_| Error::InvalidRelayUrl)?,
wakeup,
)?;
let pool_relay = PoolRelay::websocket(relay);
Expand Down
7 changes: 6 additions & 1 deletion crates/notedeck/src/note/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use enostr::{ClientMessage, NoteId, Pubkey, RelayPool};
use nostr::RelayUrl;
use nostrdb::{Note, NoteKey};
use tracing::error;

Expand Down Expand Up @@ -70,7 +71,11 @@ impl NoteContextSelection {
if note_author_is_selected_acc {
let nip19event = nostr::nips::nip19::Nip19Event::new(
nostr::event::EventId::from_byte_array(*note.id()),
pool.urls(),
)
.relays(
pool.urls()
.iter()
.filter_map(|url| RelayUrl::parse(url).ok()),
);
let Ok(bech) = nostr::nips::nip19::ToBech32::to_bech32(&nip19event) else {
return;
Expand Down
50 changes: 5 additions & 45 deletions crates/notedeck/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt::Display, sync::Arc};
use std::sync::Arc;

use nwc::{
nostr::nips::nip47::{NostrWalletConnectURI, PayInvoiceRequest, PayInvoiceResponse},
Expand Down Expand Up @@ -68,7 +68,7 @@ pub enum WalletError {
pub struct Wallet {
pub uri: String,
wallet: Arc<RwLock<NWC>>,
balance: Option<Promise<Result<u64, NwcError>>>,
balance: Option<Promise<Result<u64, nwc::Error>>>,
}

impl Clone for Wallet {
Expand Down Expand Up @@ -116,7 +116,7 @@ impl Wallet {
})
}

pub fn get_balance(&mut self) -> Option<&Result<u64, NwcError>> {
pub fn get_balance(&mut self) -> Option<&Result<u64, nwc::Error>> {
if self.balance.is_none() {
self.balance = Some(get_balance(self.wallet.clone()));
return None;
Expand All @@ -138,51 +138,11 @@ impl Wallet {
}
}

#[derive(Clone)]
pub enum NwcError {
/// NIP47 error
NIP47(String),
/// Relay
Relay(String),
/// Premature exit
PrematureExit,
/// Request timeout
Timeout,
}

impl From<nwc::Error> for NwcError {
fn from(value: nwc::Error) -> Self {
match value {
nwc::error::Error::NIP47(error) => NwcError::NIP47(error.to_string()),
nwc::error::Error::Relay(error) => NwcError::Relay(error.to_string()),
nwc::error::Error::PrematureExit => NwcError::PrematureExit,
nwc::error::Error::Timeout => NwcError::Timeout,
}
}
}

impl Display for NwcError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
NwcError::NIP47(err) => write!(f, "NIP47 error: {err}"),
NwcError::Relay(err) => write!(f, "Relay error: {err}"),
NwcError::PrematureExit => write!(f, "Premature exit"),
NwcError::Timeout => write!(f, "Request timed out"),
}
}
}

fn get_balance(nwc: Arc<RwLock<NWC>>) -> Promise<Result<u64, NwcError>> {
fn get_balance(nwc: Arc<RwLock<NWC>>) -> Promise<Result<u64, nwc::Error>> {
let (sender, promise) = Promise::new();

tokio::spawn(async move {
sender.send(
nwc.read()
.await
.get_balance()
.await
.map_err(nwc::Error::into),
);
sender.send(nwc.read().await.get_balance().await);
});

promise
Expand Down