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 point_to_public_key(point: ecdsa.ellipticcurve.Point) -> NumberAsHex: if point.y() & 1: public_key = b'03' + b'%064x' % point.x() else: public_key = b'02' + b'%064x' % point.x() return NumberAsHex(public_key)
def do_aos_hashstep(self, p: ecdsa.ellipticcurve.Point, msg: bytes): hasher = hashlib.sha256() hasher.update(p.x().to_bytes(32, "big")) hasher.update(p.y().to_bytes(32, "big")) hasher.update(msg) return int.from_bytes(hasher.digest(), "big")
def hash_point(p: ecdsa.ellipticcurve.Point): h = hashlib.sha256() h.update(p.x().to_bytes(32, "big")) h.update(p.y().to_bytes(32, "big")) return h.digest()
def negate_point(p: ecdsa.ellipticcurve.Point): return ecdsa.ellipticcurve.Point(p.curve(), p.x(), -p.y() % p.curve().p())