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

Commit ed1135b

Browse files
committed
export npub to hexpub function
1 parent 77ec5fa commit ed1135b

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

mutiny-wasm/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::models::*;
1818
use crate::utils::sleep;
1919
use bip39::Mnemonic;
2020
use bitcoin::consensus::deserialize;
21-
use bitcoin::hashes::hex::FromHex;
21+
use bitcoin::hashes::hex::{FromHex, ToHex};
2222
use bitcoin::hashes::sha256;
2323
use bitcoin::secp256k1::PublicKey;
2424
use bitcoin::util::bip32::ExtendedPrivKey;
@@ -1523,6 +1523,13 @@ impl MutinyWallet {
15231523
pub fn convert_sats_to_btc(sats: u64) -> f64 {
15241524
bitcoin::Amount::from_sat(sats).to_btc()
15251525
}
1526+
1527+
/// Convert an npub string to a hex string
1528+
#[wasm_bindgen]
1529+
pub async fn npub_to_hexpub(npub: String) -> Result<String, MutinyJsError> {
1530+
let npub = XOnlyPublicKey::from_bech32(npub)?;
1531+
Ok(npub.to_hex())
1532+
}
15261533
}
15271534

15281535
#[cfg(test)]

0 commit comments

Comments
 (0)