Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Update rust-nostr #971

Merged
merged 1 commit into from
Jan 19, 2024
Merged
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
110 changes: 32 additions & 78 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ lightning-invoice = { git = 'https://github.com/MutinyWallet/rust-lightning.git'
lightning-rapid-gossip-sync = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
lightning-background-processor = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
lightning-transaction-sync = { git = 'https://github.com/MutinyWallet/rust-lightning.git', rev = "686a84236f54bf8d7270a5fbec07801e5281691f" }
nostr = { git = 'https://github.com/benthecarman/nostr.git', rev = "7195b8d537db5fe0612b3d94794893bc0021aa11" }
nostr-sdk = { git = 'https://github.com/benthecarman/nostr.git', rev = "7195b8d537db5fe0612b3d94794893bc0021aa11" }
4 changes: 2 additions & 2 deletions mutiny-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ futures-util = { version = "0.3", default-features = false }
reqwest = { version = "0.11", default-features = false, features = ["json"] }
async-trait = "0.1.68"
url = { version = "2.3.1", features = ["serde"] }
nostr = { version = "0.26.0", default-features = false, features = ["nip05", "nip47"] }
nostr-sdk = { version = "0.26.0", default-features = false }
nostr = { version = "0.27.0", default-features = false, features = ["nip05", "nip47", "nip57"] }
nostr-sdk = { version = "0.27.0", default-features = false }
cbc = { version = "0.1", features = ["alloc"] }
aes = { version = "0.8" }
jwt-compact = { version = "0.8.0-beta.1", features = ["es256k"] }
Expand Down
6 changes: 6 additions & 0 deletions mutiny-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,12 @@ impl From<nostr::nips::nip04::Error> for MutinyError {
}
}

impl From<nostr::nips::nip57::Error> for MutinyError {
fn from(_e: nostr::nips::nip57::Error) -> Self {
Self::NostrError
}
}

impl From<nip05::Error> for MutinyError {
fn from(e: nip05::Error) -> Self {
match e {
Expand Down
38 changes: 18 additions & 20 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ use crate::{
};
use crate::{nostr::NostrManager, utils::sleep};
use ::nostr::key::XOnlyPublicKey;
use ::nostr::{EventBuilder, JsonUtil, Keys, Kind, Tag};
use ::nostr::nips::nip57;
use ::nostr::prelude::ZapRequestData;
use ::nostr::{JsonUtil, Kind};
use async_lock::RwLock;
use bdk_chain::ConfirmationTime;
use bip39::Mnemonic;
Expand Down Expand Up @@ -1511,25 +1513,21 @@ impl<S: MutinyStorage> MutinyWallet<S> {
// if user's npub is given, do an anon zap
let (zap_request, comment) = match zap_npub {
Some(zap_npub) => {
let tags = vec![
Tag::PublicKey {
public_key: zap_npub,
relay_url: None,
alias: None,
},
Tag::Amount {
millisats: msats,
bolt11: None,
},
Tag::Lnurl(lnurl.to_string()),
Tag::Relays(vec!["wss://nostr.mutinywallet.com".into()]),
Tag::Anon { msg: comment },
];
let event = EventBuilder::new(Kind::ZapRequest, "", tags)
.to_event(&Keys::generate())?
.as_json();

(Some(event), None)
let data = ZapRequestData {
public_key: zap_npub,
relays: vec![
"wss://nostr.mutinywallet.com".into(),
"wss://relay.primal.net".into(),
],
message: comment.unwrap_or_default(),
amount: Some(msats),
lnurl: Some(lnurl.encode()),
event_id: None,
event_coordinate: None,
};
let event = nip57::anonymous_zap_request(data)?;

(Some(event.as_json()), None)
}
None => (None, comment.filter(|c| !c.is_empty())),
};
Expand Down
3 changes: 3 additions & 0 deletions mutiny-core/src/nostr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ impl<S: MutinyStorage> NostrManager<S> {
public_key: inv.pubkey,
relay_url: None,
alias: None,
uppercase: false,
};
let e_tag = Tag::Event {
event_id: inv.event_id,
Expand Down Expand Up @@ -718,6 +719,7 @@ impl<S: MutinyStorage> NostrManager<S> {
public_key: inv.pubkey,
relay_url: None,
alias: None,
uppercase: false,
};
let e_tag = Tag::Event {
event_id: inv.event_id,
Expand Down Expand Up @@ -855,6 +857,7 @@ impl<S: MutinyStorage> NostrManager<S> {
public_key: nwc.public_key,
relay_url: None,
alias: None,
uppercase: false,
};
let request_event =
EventBuilder::new(Kind::WalletConnectRequest, encrypted, [p_tag]).to_event(&secret)?;
Expand Down
5 changes: 5 additions & 0 deletions mutiny-core/src/nostr/nwc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ impl NostrWalletConnect {
public_key: event.pubkey,
relay_url: None,
alias: None,
uppercase: false,
};
let e_tag = Tag::Event {
event_id: event.id,
Expand Down Expand Up @@ -625,6 +626,7 @@ impl NostrWalletConnect {
public_key: event.pubkey,
relay_url: None,
alias: None,
uppercase: false,
};
let e_tag = Tag::Event {
event_id: event.id,
Expand Down Expand Up @@ -794,6 +796,7 @@ impl NostrWalletConnect {
public_key: event.pubkey,
relay_url: None,
alias: None,
uppercase: false,
};
let e_tag = Tag::Event {
event_id: event.id,
Expand Down Expand Up @@ -1318,6 +1321,7 @@ mod wasm_test {
public_key: uri.public_key,
relay_url: None,
alias: None,
uppercase: false,
};
EventBuilder::new(Kind::WalletConnectRequest, encrypted, [p_tag])
.to_event(&Keys::new(uri.secret))
Expand Down Expand Up @@ -1346,6 +1350,7 @@ mod wasm_test {
public_key: uri.public_key,
relay_url: None,
alias: None,
uppercase: false,
};
EventBuilder::new(Kind::WalletConnectRequest, encrypted, [p_tag])
.to_event(&Keys::new(uri.secret))
Expand Down
1 change: 1 addition & 0 deletions mutiny-core/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub fn create_nwc_request(nwc: &NostrWalletConnectURI, invoice: String) -> Event
public_key: nwc.public_key,
relay_url: None,
alias: None,
uppercase: false,
};

EventBuilder::new(Kind::WalletConnectRequest, encrypted, [p_tag])
Expand Down
2 changes: 1 addition & 1 deletion mutiny-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub(crate) fn parse_profile_metadata(data: Vec<Value>) -> HashMap<XOnlyPublicKey
.filter_map(|v| {
Event::from_value(v)
.ok()
.and_then(|e| Metadata::from_json(e.content).ok().map(|m| (e.pubkey, m)))
.and_then(|e| Metadata::from_json(&e.content).ok().map(|m| (e.pubkey, m)))
})
.collect()
}
Expand Down
2 changes: 1 addition & 1 deletion mutiny-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lightning-invoice = { version = "0.26.0" }
thiserror = "1.0"
instant = { version = "0.1", features = ["wasm-bindgen"] }
lnurl-rs = { version = "0.3.1", default-features = false }
nostr = { version = "0.26.0", default-features = false }
nostr = { version = "0.27.0", default-features = false }
wasm-logger = "0.2.0"
log = "0.4.17"
rexie = "0.5.0"
Expand Down
Loading