MCPcopy Create free account
hub / github.com/ElementsProject/elements / compute_xonly_pubkey

Function compute_xonly_pubkey

test/functional/test_framework/key.py:406–417  ·  view source on GitHub ↗

Compute an x-only (32 byte) public key from a (32 byte) private key. This also returns whether the resulting public key was negated.

(key)

Source from the content-addressed store, hash-verified

404 return b'\x30' + bytes([4 + len(rb) + len(sb), 2, len(rb)]) + rb + bytes([2, len(sb)]) + sb
405
406def compute_xonly_pubkey(key):
407 """Compute an x-only (32 byte) public key from a (32 byte) private key.
408
409 This also returns whether the resulting public key was negated.
410 """
411
412 assert len(key) == 32
413 x = int.from_bytes(key, 'big')
414 if x == 0 or x >= SECP256K1_ORDER:
415 return (None, None)
416 P = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, x)]))
417 return (P[0].to_bytes(32, 'big'), not SECP256K1.has_even_y(P))
418
419def tweak_add_privkey(key, tweak):
420 """Tweak a private key (after negating it if needed)."""

Callers 8

create_taproot_utxoMethod · 0.90
csfs_testMethod · 0.90
create_taproot_utxoMethod · 0.90
spenders_taproot_activeFunction · 0.90
gen_test_vectorsMethod · 0.90
test_schnorrMethod · 0.85

Calls 3

affineMethod · 0.80
has_even_yMethod · 0.80
mulMethod · 0.45

Tested by 2

test_schnorrMethod · 0.68