The Taproot Tweak
Until now we went from a tweaked key that looks like
into
And from the Tagged Hashes lesson we know that
We need now the tag we use for the tweak.
The tag we use for the tweak is "TapTweak".
So our tweak becomes:
Why a tagged hash again?
Remember the reason we use a tagged hash: it lets us hash the same data in different contexts and get different results. Here we hash with the tag "TapTweak". If we hashed the same with another tag like "TapTweak2", we would get a completely different result.
So we end up with the final tweaked key :
Code
Let's do an exercise. We take an internal public key and compute the tweaked key .
Steps:
- generate a private key and its public key
- calculate the tweak
- compute
- assert
- tagged_hash needs bytes. Hash P's x-coordinate: P[0].to_bytes(32, 'big'). (This is the x-only form from the X-only Public Keys lesson.)
- Turn the digest into a scalar mod n, then Q = add(P, mul(t)).
Solution code
You may have noticed the hint: we hashed only 's x-coordinate, 32 bytes. That is not an accident. It is the x-only form we covered in X-only Public Keys.
