def convert_dash_xpub(xpub, dest_prefix: str): if dest_prefix != xpub[0:4]: if dest_prefix == 'xpub': raw = Base58.check_decode(xpub) raw = bytes.fromhex('0488b21e') + raw[4:] xpub = Base58.check_encode(raw) elif dest_prefix == 'drkp': raw = Base58.check_decode(xpub) raw = bytes.fromhex('02fe52cc') + raw[4:] xpub = Base58.check_encode(raw) return xpub
def xpub_to_hash(xpub: str): xpub_raw = Base58.check_decode(xpub) if xpub_raw[0:4] in (b'\x02\xfe\x52\xcc', b'\x04\x88\xb2\x1e'): # remove xpub prefix xpub_raw = xpub_raw[4:] xpub_hash = bitcoin.bin_sha256(xpub_raw) xpub_hash = base64.b64encode(xpub_hash) return xpub_hash
def xpub_to_hash(xpub: str): xpub_raw = Base58.check_decode(xpub) if xpub_raw[0:4] in (b'\x03\xe2\x5d\x7e'): # remove ppub prefix xpub_raw = xpub_raw[4:] xpub_hash = bitcoin.bin_sha256(xpub_raw) xpub_hash = base64.b64encode(xpub_hash) return xpub_hash
def xpub_to_pk(xpub): """ Derive a compressed public key from an xpub. :param xpub: Base58 encoded xpub. :return: Hex string compressed public key. """ # Last 33 bytes of xpub are the compressed public key return xpub_bytes_to_field_bytes(Base58.check_decode(xpub), 'key').hex()