Ejemplo n.º 1
0
 def from_bytes(cls, bytestr):
     """
     :param bytestr: A private key previously encoded as hex.
     :type bytestr: ``bytes``
     :rtype: :class:`~bitsv.PrivateKeyTestnet`
     """
     return PrivateKeyTestnet(ECPrivateKey(bytestr))
Ejemplo n.º 2
0
    def __init__(self, wif=None):
        if wif:
            if isinstance(wif, str):
                private_key_bytes, compressed, version = wif_to_bytes(wif)
                self._pk = ECPrivateKey(private_key_bytes)
            elif isinstance(wif, ECPrivateKey):
                self._pk = wif
                compressed = True
            else:
                raise TypeError('Wallet Import Format must be a string.')
        else:
            self._pk = ECPrivateKey()
            compressed = True

        self._public_point = None
        self._public_key = self._pk.public_key.format(compressed=compressed)
Ejemplo n.º 3
0
 def from_bytes(cls, bytestr, network='main'):
     """
     :param bytestr: A private key previously encoded as hex.
     :type bytestr: ``bytes``
     :param network: 'main', 'test' or 'stn'
     :type network: ``str``
     :rtype: :class:`~bitsv.PrivateKey`
     """
     return PrivateKey(ECPrivateKey(bytestr), network=network)
Ejemplo n.º 4
0
def generate_key_address_pairs(prefix, counter, match,
                               queue):  # pragma: no cover

    context = Context()

    while True:
        if match.is_set():
            return

        with counter.get_lock():
            counter.value += 1

        private_key = ECPrivateKey(context=context)
        address = b58encode_check(
            b'\x00' + ripemd160_sha256(private_key.public_key.format()))

        if address.startswith(prefix):
            match.set()
            queue.put_nowait((private_key.secret, address))
            return
Ejemplo n.º 5
0
def generate_key_address_pair():  # pragma: no cover
    private_key = ECPrivateKey()
    address = public_key_to_address(private_key.public_key.format())
    return bytes_to_wif(private_key.secret), address
Ejemplo n.º 6
0
 def test_init_from_key(self):
     pk = ECPrivateKey()
     base_key = BaseKey(pk)
     assert base_key._pk == pk