Skip to content

Commit afb6a11

Browse files
committed
Extract compute pubkey from compute script pubkey
Split get_silentpayment_script_pubkey into two functions. Adds a distinct function to compute a silentpayment pubkey. Helps other implementations utilising this crate by exposing more low level functions.
1 parent adf8153 commit afb6a11

File tree

1 file changed

+21
-5
lines changed
  • silentpayments/src/receive

1 file changed

+21
-5
lines changed

silentpayments/src/receive/mod.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,26 @@ pub fn get_silentpayment_script_pubkey(
213213
derivation_order: u32,
214214
maybe_label_point: Option<&PublicKey>,
215215
) -> ScriptBuf {
216+
let p_k = get_silentpayment_pubkey(
217+
spend_pk,
218+
ecdh_shared_secret,
219+
derivation_order,
220+
maybe_label_point,
221+
);
222+
223+
let (x_only_key, _) = p_k.x_only_public_key();
224+
225+
let assumed_tweaked_pk = TweakedPublicKey::dangerous_assume_tweaked(x_only_key);
226+
227+
ScriptBuf::new_p2tr_tweaked(assumed_tweaked_pk)
228+
}
229+
230+
pub fn get_silentpayment_pubkey(
231+
spend_pk: &PublicKey,
232+
ecdh_shared_secret: &PublicKey,
233+
derivation_order: u32,
234+
maybe_label_point: Option<&PublicKey>,
235+
) -> PublicKey {
216236
let secp = Secp256k1::new();
217237

218238
let t_k = get_shared_secret(*ecdh_shared_secret, derivation_order);
@@ -231,11 +251,7 @@ pub fn get_silentpayment_script_pubkey(
231251
P_k
232252
};
233253

234-
let (x_only_key, _) = P_k.x_only_public_key();
235-
236-
let assumed_tweaked_pk = TweakedPublicKey::dangerous_assume_tweaked(x_only_key);
237-
238-
ScriptBuf::new_p2tr_tweaked(assumed_tweaked_pk)
254+
P_k
239255
}
240256

241257
pub fn compute_tweak_data(

0 commit comments

Comments
 (0)