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

Commit

Permalink
Add send dm function
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Jan 23, 2024
1 parent 9a731c0 commit 8143589
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
8 changes: 4 additions & 4 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.27.0", default-features = false, features = ["nip05", "nip47", "nip57"] }
nostr-sdk = { version = "0.27.0", default-features = false, features = ["nip05", "nip47", "nip57"] }
nostr = { version = "0.27.0", default-features = false, features = ["nip04", "nip05", "nip47", "nip57"] }
nostr-sdk = { version = "0.27.0", default-features = false, features = ["nip04", "nip05", "nip47", "nip57"] }
cbc = { version = "0.1", features = ["alloc"] }
aes = { version = "0.8" }
jwt-compact = { version = "0.8.0-beta.1", features = ["es256k"] }
Expand Down Expand Up @@ -85,8 +85,8 @@ gloo-net = { version = "0.4.0" }
instant = { version = "0.1", features = ["wasm-bindgen"] }
getrandom = { version = "0.2", features = ["js"] }
# add nip07 feature for wasm32
nostr = { version = "0.27.0", default-features = false, features = ["nip05", "nip07", "nip47", "nip57"] }
nostr-sdk = { version = "0.27.0", default-features = false, features = ["nip05", "nip07", "nip47", "nip57"] }
nostr = { version = "0.27.0", default-features = false, features = ["nip04", "nip05", "nip07", "nip47", "nip57"] }
nostr-sdk = { version = "0.27.0", default-features = false, features = ["nip04", "nip05", "nip07", "nip47", "nip57"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["rt"] }
Expand Down
9 changes: 9 additions & 0 deletions mutiny-core/src/nostr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,15 @@ impl<S: MutinyStorage> NostrManager<S> {
}
}

pub async fn send_dm(
&self,
pubkey: XOnlyPublicKey,
message: String,
) -> Result<EventId, MutinyError> {
let event_id = self.client.send_direct_msg(pubkey, message, None).await?;
Ok(event_id)
}

/// Derives the client and server keys for Nostr Wallet Connect given a profile index
/// The left key is the client key and the right key is the server key
pub(crate) fn derive_nwc_keys<C: Signing>(
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.27.0", default-features = false, features = ["nip05", "nip07", "nip47", "nip57"] }
nostr = { version = "0.27.0", default-features = false, features = ["nip04", "nip05", "nip07", "nip47", "nip57"] }
wasm-logger = "0.2.0"
log = "0.4.17"
rexie = "0.5.0"
Expand Down
7 changes: 7 additions & 0 deletions mutiny-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,13 @@ impl MutinyWallet {
Ok(JsValue::from_serde(&dms)?)
}

/// Sends a DM to the given npub
pub async fn send_dm(&self, npub: String, message: String) -> Result<String, MutinyJsError> {
let npub = parse_npub(&npub)?;
let event_id = self.inner.nostr.send_dm(npub, message).await?;
Ok(event_id.to_hex())
}

/// Resets the scorer and network graph. This can be useful if you get stuck in a bad state.
#[wasm_bindgen]
pub async fn reset_router(&self) -> Result<(), MutinyJsError> {
Expand Down

0 comments on commit 8143589

Please sign in to comment.