mirror of
https://github.com/bitcoin/bips.git
synced 2025-03-04 11:08:05 +01:00
Replace taproot_tweak_pubkey assertion with exception and add it to taproot_tweak_seckey too
This commit is contained in:
parent
afa5519ade
commit
d112f5b035
1 changed files with 4 additions and 1 deletions
|
@ -187,7 +187,8 @@ For any byte string <code>h</code> it holds that <code>taproot_tweak_pubkey(pubk
|
||||||
<source lang="python">
|
<source lang="python">
|
||||||
def taproot_tweak_pubkey(pubkey, h):
|
def taproot_tweak_pubkey(pubkey, h):
|
||||||
t = int_from_bytes(tagged_hash("TapTweak", pubkey + h))
|
t = int_from_bytes(tagged_hash("TapTweak", pubkey + h))
|
||||||
assert t < SECP256K1_ORDER
|
if t >= SECP256K1_ORDER:
|
||||||
|
raise ValueError
|
||||||
Q = point_mul(point(pubkey), t)
|
Q = point_mul(point(pubkey), t)
|
||||||
return bytes_from_int(x(Q)), is_quad(y(Q))
|
return bytes_from_int(x(Q)), is_quad(y(Q))
|
||||||
|
|
||||||
|
@ -195,6 +196,8 @@ def taproot_tweak_seckey(seckey0, h):
|
||||||
P = point_mul(G, int_from_bytes(seckey0))
|
P = point_mul(G, int_from_bytes(seckey0))
|
||||||
seckey = SECP256K1_ORDER - seckey0 if not is_quad(y(R)) else seckey
|
seckey = SECP256K1_ORDER - seckey0 if not is_quad(y(R)) else seckey
|
||||||
t = int_from_bytes(tagged_hash("TapTweak", bytes_from_int(x(P)) + h))
|
t = int_from_bytes(tagged_hash("TapTweak", bytes_from_int(x(P)) + h))
|
||||||
|
if t >= SECP256K1_ORDER:
|
||||||
|
raise ValueError
|
||||||
return (seckey + t) % SECP256K1_ORDER
|
return (seckey + t) % SECP256K1_ORDER
|
||||||
</source>
|
</source>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue