Skip to content
Open
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
15 changes: 14 additions & 1 deletion lwk_wasm/src/blockdata/address.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Error, Network, Script};
use crate::{Error, Network, PublicKey, Script};
use lwk_wollet::elements::{self, AddressParams};
use wasm_bindgen::prelude::*;

Expand Down Expand Up @@ -77,6 +77,14 @@ impl Address {
self.inner.is_blinded()
}

/// Return the blinding public key, if the address is confidential.
#[wasm_bindgen(js_name = blindingPubkey)]
pub fn blinding_pubkey(&self) -> Option<PublicKey> {
self.inner
.blinding_pubkey
.map(|pk| lwk_wollet::elements::bitcoin::PublicKey::new(pk).into())
}

/// Return true if the address is for mainnet.
#[wasm_bindgen(js_name = isMainnet)]
pub fn is_mainnet(&self) -> bool {
Expand Down Expand Up @@ -159,6 +167,11 @@ mod tests {

assert!(address.is_blinded());

let blinding_pk = address.blinding_pubkey().expect("confidential address");
assert_eq!(blinding_pk.to_bytes().len(), 33);

assert!(address.to_unconfidential().blinding_pubkey().is_none());

assert_eq!(
address.to_unconfidential().to_string(),
"tex1q6rz28mcfaxtmd6v789l9rrlrusdprr9p634wu8"
Expand Down