From 5e31966ab32e3f9baafe140a730a3b5e3185ede2 Mon Sep 17 00:00:00 2001 From: Oleksandr Tkachenko Date: Fri, 26 Jul 2024 11:59:03 +0200 Subject: [PATCH] make clear that internal key in script spends can be used in tweaked key spends once IC supports tweaks --- .../src/bitcoin_wallet/p2tr_script_spend.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rust/basic_bitcoin/src/basic_bitcoin/src/bitcoin_wallet/p2tr_script_spend.rs b/rust/basic_bitcoin/src/basic_bitcoin/src/bitcoin_wallet/p2tr_script_spend.rs index 2c23147aa..f696d64f2 100644 --- a/rust/basic_bitcoin/src/basic_bitcoin/src/bitcoin_wallet/p2tr_script_spend.rs +++ b/rust/basic_bitcoin/src/basic_bitcoin/src/bitcoin_wallet/p2tr_script_spend.rs @@ -41,13 +41,17 @@ pub fn public_key_to_p2tr_script_spend_address( fn p2tr_scipt_spend_info(public_key: &[u8]) -> TaprootSpendInfo { let spend_script = p2tr_script(public_key); - let dummy_random_secp256k1 = Secp256k1::new(); - let schnorr_public_key = XOnlyPublicKey::from(PublicKey::from_slice(&public_key).unwrap()); + let secp256k1_engine = Secp256k1::new(); + // This is the key used in the *tweaked* key path spending. Currently, this + // use case is not supported on the IC. But, once the IC supports this use + // case, the addresses constructed in this way will be able to use same key + // in both script and *tweaked* key path spending. + let internal_public_key = XOnlyPublicKey::from(PublicKey::from_slice(&public_key).unwrap()); TaprootBuilder::new() .add_leaf(0, spend_script.clone()) .expect("adding leaf should work") - .finalize(&dummy_random_secp256k1, schnorr_public_key) + .finalize(&secp256k1_engine, internal_public_key) .expect("finalizing taproot builder should work") }