def wif(self, compressed=False) -> str: from btctools import base58, sha256 from btctools.network import network extended = network('wif') + self.bytes() + (b'\x01' if compressed else b'') hashed = sha256(sha256(extended)) checksum = hashed[:4] return base58.encode(extended + checksum)
def legacy_address(pub_or_script: Union[bytes, PublicKey], version_byte: bytes) -> str: """https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses""" bts = pub_or_script.encode(compressed=False) if isinstance( pub_or_script, PublicKey) else pub_or_script hashed = hash160(bts) payload = version_byte + hashed checksum = sha256(sha256(payload))[:4] address = payload + checksum return base58.encode(address)
def legacy_address(data, version_byte=b'\x00'): ripemd160_pub = hash160(data) payload = version_byte + ripemd160_pub checksum = sha256(sha256(payload))[:4] address = base58.encode(payload + checksum) print('address:', address)
def encode(self): data = self.serialize() assert len(data) == 78 checksum = sha256(sha256(data))[:4] return base58.encode(data + checksum)
def hashed_payload_to_address(payload): checksum = sha256(sha256(payload))[:4] address = payload + checksum return base58.encode(address)
def encode(self): return base58.encode(self.serialize())