Ejemplo n.º 1
0
def hash160_to_p2sh_p2wpkh_addr(hash160: bytes, version: bytes) -> bytes:
    redeem_script = b'\x00\x14' + hash160  # 0x00: OP_0, 0x14: PushData
    redeem_hash = common_util.sha256(redeem_script)
    redeem_rip = common_util.ripemd160(redeem_hash)
    # Base-58 encoding with a checksum
    checksum = common_util.base58_cksum(version + redeem_rip)
    address = base58.b58encode(version + redeem_rip + checksum)
    return address
Ejemplo n.º 2
0
def pubkey_to_p2pkh_addr(pubkey: bytes, version: bytes) -> bytes:
    """ Derives legacy (p2pkh) address from pubkey """
    out1 = common_util.sha256(pubkey)
    out2 = common_util.ripemd160(out1)
    # Base-58 encoding with a checksum
    checksum = common_util.base58_cksum(version + out2)
    address = base58.b58encode(version + out2 + checksum)
    return address
def pubkey_to_p2sh_p2wpkh_addr(pubkey_compressed: bytes, version: bytes) -> bytes:
    """ Derives p2sh-segwit (p2sh p2wpkh) address from pubkey """
    pubkey_hash = common_util.sha256(pubkey_compressed)
    rip = common_util.ripemd160(pubkey_hash)
    redeem_script = b'\x00\x14' + rip  # 0x00: OP_0, 0x14: PushData
    redeem_hash = common_util.sha256(redeem_script)
    redeem_rip = common_util.ripemd160(redeem_hash)
    # Base-58 encoding with a checksum
    checksum = common_util.base58_cksum(version + redeem_rip)
    address = base58.b58encode(version + redeem_rip + checksum)
    return address
Ejemplo n.º 4
0
def hash160_to_p2pkh_addr(hash160: bytes, version: bytes) -> bytes:
    """ Derives legacy (p2pkh) address from hash160 of pubkey """
    # Base-58 encoding with a checksum
    checksum = common_util.base58_cksum(version + hash160)
    address = base58.b58encode(version + hash160 + checksum)
    return address