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

Function tweak_add_privkey

test/functional/test_framework/key.py:419–436  ·  view source on GitHub ↗

Tweak a private key (after negating it if needed).

(key, tweak)

Source from the content-addressed store, hash-verified

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)."""
421
422 assert len(key) == 32
423 assert len(tweak) == 32
424
425 x = int.from_bytes(key, 'big')
426 if x == 0 or x >= SECP256K1_ORDER:
427 return None
428 if not SECP256K1.has_even_y(SECP256K1.mul([(SECP256K1_G, x)])):
429 x = SECP256K1_ORDER - x
430 t = int.from_bytes(tweak, 'big')
431 if t >= SECP256K1_ORDER:
432 return None
433 x = (x + t) % SECP256K1_ORDER
434 if x == 0:
435 return None
436 return x.to_bytes(32, 'big')
437
438def tweak_add_pubkey(key, tweak):
439 """Tweak a public key and return whether the result had to be negated."""

Callers 3

pegin_testMethod · 0.90
issuance_testMethod · 0.90
default_key_tweakedFunction · 0.90

Calls 2

has_even_yMethod · 0.80
mulMethod · 0.45

Tested by

no test coverage detected