Пример #1
0
    def P2WPKHAddress(self):
        "Return P2WPKH segwit address"
        pk_bytes = self.PublicKey()
        assert len(pk_bytes) == 33 and (pk_bytes.startswith(b"\x02") or pk_bytes.startswith(b"\x03")), \
            "Only compressed public keys are compatible with p2sh-p2wpkh addresses. " \
            "See https://github.com/bitcoin/bips/blob/master/bip-0049.mediawiki."
        from btcpy.structs.address import P2wpkhAddress
        from btcpy.structs.crypto import PublicKey

        pk = PublicKey(pk_bytes)
        pk_hash = pk.hash()

        return str(P2wpkhAddress(pk_hash, 0, mainnet=not self.testnet))
Пример #2
0
def get_hexPubkey(decPubkey):
    pubk = PublicKey(
        bytearray([0x04]) + decPubkey.get_x().to_bytes(32, 'big') +
        decPubkey.get_y().to_bytes(32, 'big'))
    pubk = pubk.compress()
    return pubk