def witness_pubkey_to_p2sh_address(pubkey, main_net=True):
    pubkey = pubkey.decode("hex")
    d20 = utils.hash160(pubkey)
    witness_script = OP_0 + chr(len(d20)) + d20

    script_prefix = SCRIPT_PREFIX
    if not main_net:
        script_prefix = SCRIPT_PREFIX_TEST

    h20 = utils.hash160(witness_script)
    d21 = script_prefix + h20
    c4 = utils.checksum(d21)

    d25 = d21 + c4
    return base58.b58encode(d25)
def witness_pubkey_to_p2sh_address(pubkey):
    assert (type(pubkey) == bytes)
    assert (len(pubkey) == 33)

    pubkey = pubkey.decode('iso-8859-15')
    d20 = utils.hash160(pubkey.encode('iso-8859-15')).decode('iso-8859-15')
    witness_script = OP_0 + chr(len(d20)) + d20

    script_prefix = SCRIPT_PREFIX

    h20 = utils.hash160(
        witness_script.encode('iso-8859-15')).decode('iso-8859-15')
    d21 = script_prefix + h20
    c4 = utils.checksum(d21.encode('iso-8859-15')).decode('iso-8859-15')

    d25 = d21 + c4
    return base58.b58encode(d25.encode('iso-8859-15'))
def witness_pubkey_to_bech32_address(pubkey, main_net=True):
    pubkey = pubkey.decode("hex")
    d20 = utils.hash160(pubkey)
    witness_script = OP_0 + chr(len(d20)) + d20

    hrp = BECH32_HRP
    if not main_net:
        hrp = BECH32_HRP_TEST

    witness_script_bytes = [ord(c) for c in witness_script]
    return encode(hrp, witness_script_bytes[0], witness_script_bytes[2:])
def redeemscript_to_p2sh_address(redeem_script, main_net=True):
    redeem_script = redeem_script.decode("hex")

    script_prefix = SCRIPT_PREFIX
    if not main_net:
        script_prefix = SCRIPT_PREFIX_TEST

    h20 = utils.hash160(redeem_script)
    d21 = script_prefix + h20
    c4 = utils.checksum(d21)

    d25 = d21 + c4
    return base58.b58encode(d25)
def pubkey_to_legacy_address(pubkey, main_net=True):
    pubkey = pubkey.decode("hex")

    addr_prefix = ADDR_PREFIX
    if not main_net:
        addr_prefix = ADDR_PREFIX_TEST

    h20 = utils.hash160(pubkey)
    d21 = addr_prefix + h20
    c4 = utils.checksum(d21)

    d25 = d21 + c4
    return base58.b58encode(d25)
def witness_redeemscript_to_p2sh_address(redeemscript, main_net=True):
    redeemscript = redeemscript.decode("hex")
    d32 = utils.sha256(redeemscript)
    witness_script = OP_0 + chr(len(d32)) + d32

    script_prefix = SCRIPT_PREFIX
    if not main_net:
        script_prefix = SCRIPT_PREFIX_TEST

    h20 = utils.hash160(witness_script)
    d21 = script_prefix + h20
    c4 = utils.checksum(d21)

    d25 = d21 + c4
    return base58.b58encode(d25)
Esempio n. 7
0
    def __init__(self):
        self.keys = utils.generate_ec_key_pairs()
        self.pub_key_hash = utils.hash160(self.keys['public'])
        # self.address = utils.Base58.base58encode(hash160)

        self.waiting_txn_pool = []
        self.lock = Lock()
        self.messages = deque()

        self.database_UTXO = UTXOTrie()
        self.blockchain = Blockchain(self.database_UTXO, self)

        self.recieved_txn_ids = []
        self.proof = None
        self.run_now = True
Esempio n. 8
0
    def verify_pay_to_pubkey_hash(script_signature, pub_key_script, message):
        """
        Bitcoin version:
            out: scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
            inp: scriptSig: <digital-signature> <pubKey>
        """

        signature = script_signature[:128]
        pub_key = script_signature[128:]

        pub_hash160 = utils.hash160(pub_key)
        if not (pub_hash160.strip() == pub_key_script.strip()):
            return False

        message = str.encode(message)
        vk = VerifyingKey.from_string(bytearray.fromhex(pub_key),
                                      curve=ecdsa.SECP256k1)
        return vk.verify(bytearray.fromhex(signature), message)
Esempio n. 9
0
    def to_address(self, compressed=None):
        """Create a public address from this key.

        :param compressed: False if you want a normal uncompressed address
            (the most standard option). True if you want the compressed form.
            Note that most clients will not accept compressed addresses.
            Defaults to None, which in turn uses the self.compressed attribute.
        :type compressed: bool

        https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses
        """
        key = unhexlify(ensure_bytes(self.get_key(compressed)))
        # First get the hash160 of the key
        hash160_bytes = hash160(key)
        # Prepend the network address byte
        network_hash160_bytes = \
            chr_py2(self.network.PUBKEY_ADDRESS) + hash160_bytes
        # Return a base58 encoded address with a checksum
        return ensure_str(base58.b58encode_check(network_hash160_bytes))
Esempio n. 10
0
 def eval(self, ctx):
     d = ctx.stack.pop()
     h = utils.hash160(d)
     ctx.stack.push(h)
     return True