Example #1
0
def wif_to_key(wif):
    private_key_bytes, compressed, version = wif_to_bytes(wif)

    if version == 'main':
        if compressed:
            return PrivateKey.from_bytes(private_key_bytes)
        else:
            return PrivateKey(wif)
Example #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)
Example #3
0
 def test_invalid_network(self):
     with pytest.raises(ValueError):
         wif_to_bytes(BITCOIN_ADDRESS)
Example #4
0
 def test_compressed(self):
     assert wif_to_bytes(WALLET_FORMAT_COMPRESSED_MAIN) == (
         PRIVATE_KEY_BYTES, True, 'main')
Example #5
0
 def test_testnet(self):
     assert wif_to_bytes(WALLET_FORMAT_TEST) == (PRIVATE_KEY_BYTES, False,
                                                 'test')
Example #6
0
 def test_mainnet(self):
     assert wif_to_bytes(WALLET_FORMAT_MAIN) == (PRIVATE_KEY_BYTES, False,
                                                 'main')