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)
| 404 | return b'\x30' + bytes([4 + len(rb) + len(sb), 2, len(rb)]) + rb + bytes([2, len(sb)]) + sb |
| 405 | |
| 406 | def 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 | |
| 419 | def tweak_add_privkey(key, tweak): |
| 420 | """Tweak a private key (after negating it if needed).""" |