<blockquote>
<p>I've done the bitcoin taproot workshop a couple times now and starting to get a grip of what is going on, but I can't find where I can do the same things in the workshop's provided python libraries with bitcoin core</p>
</blockquote>
<p>I think you need to be clearer on exactly what you want to achieve. There is Taproot code in Python in the Bitcoin Core <a href="https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_taproot.py" rel="nofollow noreferrer">functional tests</a> if you want to dig a bit deeper for educational purposes in Python. But that isn't set up to be a standalone library to interact with. A Python library that does have Taproot support (and MuSig2 support) is <a href="https://github.com/buidl-bitcoin/buidl-python/blob/main/buidl/taproot.py" rel="nofollow noreferrer">buidl-python</a>. Other Python libraries like <a href="https://github.com/petertodd/python-bitcoinlib/issues/263" rel="nofollow noreferrer">python-bitcoinlib</a>, ofek's <a href="https://github.com/ofek/bit/issues/154" rel="nofollow noreferrer">bit</a> and darosior's <a href="https://github.com/darosior/python-bip380" rel="nofollow noreferrer">python-bip380</a> don't support Taproot at the time of writing (May 2023) unfortunately.</p>
<blockquote>
<p>Could bitcoin core benefit from this added functionality? Command's like tweak add, Tapleaf construction of csa, hashlock, csa hashlock delay and proper Tapscript construction?</p>
</blockquote>
<p>Bitcoin Core as a full node implementation already supports verifying any Taproot spend in C++. The Bitcoin Core wallet supports Taproot via the <code>tr()</code> descriptor again written in C++. OP_CHECKSIGADD (CSA) is supported via the <code>multi_a</code> and <code>sortedmulti_a</code> descriptors within the <code>tr()</code> descriptor. Hashlocks isn't at the time of writing (May 2023) supported within the <code>tr()</code> descriptor but there is a PR open (<a href="https://github.com/bitcoin/bitcoin/pull/27255" rel="nofollow noreferrer">PR 27255</a>) to add Taproot'd Miniscript to the Bitcoin Core wallet which would enable it.</p>
<blockquote>
<p>I can generate a new address, but how do I tweak it with the tap script?</p>
</blockquote>
<p>A note on the terminology. You tweak the internal public key, you don't tweak the address. How you tweak the internal public key is explained in the Bitcoin Optech Taproot workshop <a href="https://github.com/bitcoinops/taproot-workshop/blob/master/2.2-taptweak.ipynb" rel="nofollow noreferrer">here</a>.</p>
<blockquote>
<p>I'm also wary of generating my own keys, as the workshop says specifically not to do that. &quot;Bad randomness and no side channel protection.&quot; to loosely quote.</p>
</blockquote>
<blockquote>
<p>Right now it seems like I would have to implement these features in a separate python library, maybe by calling bindings to secp256k1 lib for safe randomness?</p>
</blockquote>
<p>If you are using signet or testnet coins you don't need to worry about bad randomness and potentially losing your coins. But note the randomness for seeds, private keys isn't generated in secp256k1, it is generated in the main Core repo (<a href="https://github.com/bitcoin/bitcoin/blob/master/src/random.cpp" rel="nofollow noreferrer">random.cpp</a>).</p>

CC BY-SA 4.0
2023-05-12T10:08:41.583Z
2023-05-12T10:24:47.613Z
2023-05-12T10:24:47.613Z
Michael Folkson
<p>I'm wondering what the workflow is for building tapscripts.
I can generate a new address, but how do I tweak it with the tap script?</p>
<p>I've done the bitcoin taproot workshop a couple times now and starting to get a grip of what is going on, but I can't find where I can do the same things in the workshop's provided python libraries with bitcoin core, I'm also wary of generating my own keys, as the workshop says specifically not to do that. &quot;Bad randomness and no side channel protection.&quot; to loosely quote.</p>
<p>Could bitcoin core benefit from this added functionality?
Command's like tweak add, Tapleaf construction of csa, hashlock, csa hashlock delay and proper Tapscript construction?</p>
<p>Right now it seems like I would have to implement these features in a separate python library, maybe by calling bindings to secp256k1 lib for safe randomness?</p>
<p>Thanks
Andrew</p>

CC BY-SA 4.0
2022-11-09T16:43:41.673Z
Are you seeking to do this with real money? I'd recommend not to and do this with signet or testnet coins if it is just for educational purposes. Then you don't need to worry about bad randomness, side channel protection. In the functional tests of Bitcoin Core there is some Taproot functionality in Python. https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_taproot.py
Michael Folkson
CC BY-SA 4.0
2022-11-09T22:34:27.093Z
Yea I would be only doing this on signet. Thanks
Kaizen
<bitcoin-core><python><taproot><functional-test>
How can I tweak a private key in bitcoin core
Kaizen
# How can I tweak a private key in bitcoin core

(Asked by: username_0 on 2022-11-09)

I'm wondering what the workflow is for building tapscripts.
I can generate a new address, but how do I tweak it with the tap script?

I've done the bitcoin taproot workshop a couple times now and starting to get a grip of what is going on, but I can't find where I can do the same things in the workshop's provided python libraries with bitcoin core, I'm also wary of generating my own keys, as the workshop says specifically not to do that. "Bad randomness and no side channel protection." to loosely quote.

Could bitcoin core benefit from this added functionality?
Command's like tweak add, Tapleaf construction of csa, hashlock, csa hashlock delay and proper Tapscript construction?

Right now it seems like I would have to implement these features in a separate python library, maybe by calling bindings to secp256k1 lib for safe randomness?

Thanks
Andrew

**Tags:** bitcoin-core, python, taproot, functional-test

> **Comments:**
> **username_1**: Are you seeking to do this with real money? I'd recommend not to and do this with signet or testnet coins if it is just for educational purposes. Then you don't need to worry about bad randomness, side channel protection. In the functional tests of Bitcoin Core there is some Taproot functionality in Python. https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_taproot.py  
> **username_0**: Yea I would be only doing this on signet. Thanks  

---

## 1 answers

### Answer by username_1 on 2023-05-12. Score: 0

> I've done the bitcoin taproot workshop a couple times now and starting to get a grip of what is going on, but I can't find where I can do the same things in the workshop's provided python libraries with bitcoin core

I think you need to be clearer on exactly what you want to achieve. There is Taproot code in Python in the Bitcoin Core [functional tests](https://github.com/bitcoin/bitcoin/blob/master/test/functional/feature_taproot.py) if you want to dig a bit deeper for educational purposes in Python. But that isn't set up to be a standalone library to interact with. A Python library that does have Taproot support (and MuSig2 support) is [buidl-python](https://github.com/buidl-bitcoin/buidl-python/blob/main/buidl/taproot.py). Other Python libraries like [python-bitcoinlib](https://github.com/petertodd/python-bitcoinlib/issues/263), ofek's [bit](https://github.com/ofek/bit/issues/154) and darosior's [python-bip380](https://github.com/darosior/python-bip380) don't support Taproot at the time of writing (May 2023) unfortunately.

> Could bitcoin core benefit from this added functionality? Command's like tweak add, Tapleaf construction of csa, hashlock, csa hashlock delay and proper Tapscript construction?

Bitcoin Core as a full node implementation already supports verifying any Taproot spend in C++. The Bitcoin Core wallet supports Taproot via the `tr()` descriptor again written in C++. OP\_CHECKSIGADD (CSA) is supported via the `multi_a` and `sortedmulti_a` descriptors within the `tr()` descriptor. Hashlocks isn't at the time of writing (May 2023) supported within the `tr()` descriptor but there is a PR open ([PR 27255](https://github.com/bitcoin/bitcoin/pull/27255)) to add Taproot'd Miniscript to the Bitcoin Core wallet which would enable it.

> I can generate a new address, but how do I tweak it with the tap script?

A note on the terminology. You tweak the internal public key, you don't tweak the address. How you tweak the internal public key is explained in the Bitcoin Optech Taproot workshop [here](https://github.com/bitcoinops/taproot-workshop/blob/master/2.2-taptweak.ipynb).

> I'm also wary of generating my own keys, as the workshop says specifically not to do that. "Bad randomness and no side channel protection." to loosely quote.

> Right now it seems like I would have to implement these features in a separate python library, maybe by calling bindings to secp256k1 lib for safe randomness?

If you are using signet or testnet coins you don't need to worry about bad randomness and potentially losing your coins. But note the randomness for seeds, private keys isn't generated in secp256k1, it is generated in the main Core repo ([random.cpp](https://github.com/bitcoin/bitcoin/blob/master/src/random.cpp)).


---

