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

Add util function for hodl invoice detection #980

Merged
merged 1 commit into from
Jan 23, 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
13 changes: 6 additions & 7 deletions mutiny-core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,11 @@ pub fn get_monitor_version(bytes: &[u8]) -> u64 {
u64::from_be_bytes(bytes[2..10].try_into().unwrap())
}

#[cfg(not(test))]
pub const HODL_INVOICE_NODES: [&str; 1] =
["031b301307574bbe9b9ac7b79cbe1700e31e544513eae0b5d7497483083f99e581"];

#[cfg(test)]
pub const HODL_INVOICE_NODES: [&str; 2] = [
/// Nodes that give hodl invoices, we want to warn users against this.
pub const HODL_INVOICE_NODES: [&str; 5] = [
"0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", // pubkey of ONE_KEY
"031b301307574bbe9b9ac7b79cbe1700e31e544513eae0b5d7497483083f99e581",
"031b301307574bbe9b9ac7b79cbe1700e31e544513eae0b5d7497483083f99e581", // ZeusPay
"02187352cc4b1856b9604e0a79e1bc9b301be7e0c14acbbb8c29f7051d507127d7", // Robosats
"0282eb467bc073833a039940392592bf10cf338a830ba4e392c1667d7697654c7e", // Robosats
"037ff12b6a4e4bcb4b944b6d20af08cdff61b3461c1dff0d00a88697414d891bc7", // Robosats
];
8 changes: 8 additions & 0 deletions mutiny-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,14 @@ impl MutinyWallet {
let npub = parse_npub_or_nip05(&npub).await?;
Ok(npub.to_bech32().expect("bech32"))
}

/// If the invoice is from a node that gives hodl invoices
#[wasm_bindgen]
pub async fn is_potential_hodl_invoice(invoice: String) -> Result<bool, MutinyJsError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Don't we already warn users when paying zeus that it is a hodl invoice? Something is already doing that logic somewhere based on the list of pubkeys.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the front end we only warn for lightning address by checking for @zuespay.com

let invoice = Bolt11Invoice::from_str(&invoice)?;
Ok(mutiny_core::utils::HODL_INVOICE_NODES
.contains(&invoice.recover_payee_pub_key().to_hex().as_str()))
}
}

#[cfg(test)]
Expand Down
Loading