Tweak a public key and return whether the result had to be negated.
(key, tweak)
| 436 | return x.to_bytes(32, 'big') |
| 437 | |
| 438 | def tweak_add_pubkey(key, tweak): |
| 439 | """Tweak a public key and return whether the result had to be negated.""" |
| 440 | |
| 441 | assert len(key) == 32 |
| 442 | assert len(tweak) == 32 |
| 443 | |
| 444 | x_coord = int.from_bytes(key, 'big') |
| 445 | if x_coord >= SECP256K1_FIELD_SIZE: |
| 446 | return None |
| 447 | P = SECP256K1.lift_x(x_coord) |
| 448 | if P is None: |
| 449 | return None |
| 450 | t = int.from_bytes(tweak, 'big') |
| 451 | if t >= SECP256K1_ORDER: |
| 452 | return None |
| 453 | Q = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, t), (P, 1)])) |
| 454 | if Q is None: |
| 455 | return None |
| 456 | return (Q[0].to_bytes(32, 'big'), not SECP256K1.has_even_y(Q)) |
| 457 | |
| 458 | def verify_schnorr(key, sig, msg): |
| 459 | """Verify a Schnorr signature (see BIP 340). |
no test coverage detected