def _get_ptr_to_well_formed_pubkey_string_buffer_from_ecdsa_point(point: ecdsa.ellipticcurve.Point): assert point.curve() == curve_secp256k1 pubkey = create_string_buffer(64) public_pair_bytes = b'\4' + point.x().to_bytes(32, byteorder="big") + point.y().to_bytes(32, byteorder="big") r = _libsecp256k1.secp256k1_ec_pubkey_parse( _libsecp256k1.ctx, pubkey, public_pair_bytes, len(public_pair_bytes)) if not r: raise Exception('public key could not be parsed or is invalid') return pubkey
def negate_point(p: ecdsa.ellipticcurve.Point): return ecdsa.ellipticcurve.Point(p.curve(), p.x(), -p.y() % p.curve().p())