From 722a553fcce2753c449cd747d8966d8b2e3afdf4 Mon Sep 17 00:00:00 2001 From: Evan Date: Fri, 8 May 2026 19:28:48 -0700 Subject: [PATCH] wasm: expose Address.blindingPubkey() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an accessor for the blinding public key of a confidential Address. Returns Option; None for unconfidential addresses. The underlying elements::Address exposes blinding_pubkey as a public field — this just bridges it to JS via the existing PublicKey newtype. Building a confidential PSET output to a known recipient requires their blinding pubkey; without this, JS callers either re-implement segwit/SLIP-77 decoding or work around it. --- lwk_wasm/src/blockdata/address.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lwk_wasm/src/blockdata/address.rs b/lwk_wasm/src/blockdata/address.rs index 1720c2e9d..467a32318 100644 --- a/lwk_wasm/src/blockdata/address.rs +++ b/lwk_wasm/src/blockdata/address.rs @@ -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::*; @@ -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 { + 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 { @@ -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"