Ejemplo n.º 1
0
    def test_roundtrip_wif(self):
        k1 = PrivateKey.generate()
        k2 = PrivateKey.from_wif(k1.to_wif())

        assert k1.key.private_numbers().private_value == k2.key.private_numbers().private_value
        assert k1.network is k2.network
        assert k1.compressed == k2.compressed
Ejemplo n.º 2
0
    def test_roundtrip_wif(self):
        k1 = PrivateKey()
        k2 = PrivateKey.from_wif(k1.to_wif())

        assert k1.secret == k2.secret
        assert k1.network is k2.network
        assert k1.compressed == k2.compressed
Ejemplo n.º 3
0
    def test_roundtrip_wif(self):
        k1 = PrivateKey()
        k2 = PrivateKey.from_wif(k1.to_wif())

        assert k1.secret == k2.secret
        assert k1.network is k2.network
        assert k1.compressed == k2.compressed
Ejemplo n.º 4
0
    def test_from_private_key(self):
        privkey = PrivateKey.from_hex(data['privkey_hex'])
        pubkey = PublicKey.from_private_key(privkey)

        assert pubkey.network is privkey.network
        assert pubkey.compressed == privkey.compressed
        assert pubkey.pair == data['pubkey_pair']
Ejemplo n.º 5
0
    def test_from_bytes(self):

        k = PrivateKey.from_bytes(data['privkey_bin'])

        assert k.compressed is True
        assert k.network is network.default
        assert k.to_bytes() == data['privkey_bin']
Ejemplo n.º 6
0
    def test_from_private_key(self):
        privkey = PrivateKey.from_hex(data['privkey_hex'])
        pubkey  = PublicKey.from_private_key(privkey)

        assert pubkey.network is privkey.network
        assert pubkey.compressed == privkey.compressed
        assert pubkey.pair == data['pubkey_pair']
Ejemplo n.º 7
0
    def test_from_bytes(self):
        k = PrivateKey.from_bytes(data['privkey_bin'])

        assert k.to_hex() == data['privkey_hex']
        assert k.to_bytes() == data['privkey_bin']

        assert k.compressed is True
        assert k.network is networks.default
Ejemplo n.º 8
0
    def test_from_invalid_wif(self):
        too_short = encode_base58h(b'a')
        too_long = encode_base58h(b'a' * 30)

        with raises(PrivateKey.InvalidWifLength):
            PrivateKey.from_wif(too_short)
        with raises(PrivateKey.InvalidWifLength):
            PrivateKey.from_wif(too_long)

        valid = decode_base58h(PrivateKey().to_wif())

        with raises(PrivateKey.InvalidCompressionByte):
            PrivateKey.from_wif(encode_base58h(valid[:-1] + b'a'))

        with raises(PrivateKey.UnknownNetwork):
            PrivateKey.from_wif(encode_base58h(b'a' + valid[1:]))
Ejemplo n.º 9
0
    def test_bitcoind_valid_wifs(self, valid_wifs):
        for wif, secret_hex, attrs in valid_wifs:
            secret = encoding.b2i_bigendian(encoding.a2b_hex(secret_hex))
            network_ = network.testnet if attrs['isTestnet'] else network.livenet
            compressed = attrs['isCompressed']

            k = PrivateKey.from_wif(wif)

            assert k.key.private_numbers().private_value == secret
            assert k.network is network_
            assert k.compressed == compressed
Ejemplo n.º 10
0
    def test_bitcoind_valid_wifs(self, valid_wifs):
        for wif, secret_hex, attrs in valid_wifs:
            secret     = decode_int(decode_hex(secret_hex))
            network    = networks.testnet if attrs['isTestnet'] else networks.livenet
            compressed = attrs['isCompressed']

            k = PrivateKey.from_wif(wif)

            assert k.secret == secret
            assert k.network is network
            assert k.compressed == compressed
Ejemplo n.º 11
0
    def test_bitcoind_valid_wifs(self, valid_wifs):
        for wif, secret_hex, attrs in valid_wifs:
            secret = decode_int(decode_hex(secret_hex))
            network = networks.testnet if attrs[
                'isTestnet'] else networks.livenet
            compressed = attrs['isCompressed']

            k = PrivateKey.from_wif(wif)

            assert k.secret == secret
            assert k.network is network
            assert k.compressed == compressed
Ejemplo n.º 12
0
    def test_from_invalid_wif(self):
        too_short = encode_base58h('a')
        too_long  = encode_base58h('a' * 30)

        with raises(PrivateKey.InvalidWifLength): PrivateKey.from_wif(too_short)
        with raises(PrivateKey.InvalidWifLength): PrivateKey.from_wif(too_long)

        valid = decode_base58h(PrivateKey().to_wif())

        with raises(PrivateKey.InvalidCompressionByte):
            PrivateKey.from_wif(encode_base58h(valid[:-1] + 'a'))

        with raises(PrivateKey.UnknownNetwork):
            PrivateKey.from_wif(encode_base58h('a' + valid[1:]))
Ejemplo n.º 13
0
    def test_from_invalid_wif(self):
        too_short = encoding.b2a_base58check('a')

        with raises(privkey.InvalidEncoding):
            PrivateKey.from_wif(too_short)

        too_long = encoding.b2a_base58check('a' * 30)

        with raises(privkey.InvalidEncoding):
            PrivateKey.from_wif(too_long)

        valid = encoding.a2b_base58check(PrivateKey.generate().to_wif())

        with raises(privkey.InvalidEncoding):
            PrivateKey.from_wif(encoding.b2a_base58check(valid[:-1] + 'a'))

        with raises(privkey.InvalidEncoding):
            PrivateKey.from_wif(encoding.b2a_base58check('a' + valid[1:]))
Ejemplo n.º 14
0
    def test_from_wif_test_uncompress(self):
        k = PrivateKey.from_wif(data['wif']['test_uncompress'])

        assert k.compressed is False
        assert k.network is networks.testnet
        assert k.to_wif() == data['wif']['test_uncompress']
Ejemplo n.º 15
0
    def test_from_wif_test_compress(self):
        k = PrivateKey.from_wif(data['wif']['test_compress'])

        assert k.compressed is True
        assert k.network is networks.testnet
        assert k.to_wif() == data['wif']['test_compress']
Ejemplo n.º 16
0
    def test_from_invalid_secret_exponent(self, invalid_exponents):

        for exponent in invalid_exponents:
            with raises(privkey.InvalidExponent):
                PrivateKey.from_secret_exponent(exponent)
Ejemplo n.º 17
0
 def test_invalid_secret(self):
     with raises(PrivateKey.InvalidSecret):
         PrivateKey(-1)
     with raises(PrivateKey.InvalidSecret):
         PrivateKey(10**100)
Ejemplo n.º 18
0
 def test_to_pubkey_compressed(self):
     k = PrivateKey.from_wif(data['wif']['live_uncompress'])
     assert k.to_public_key().to_hex() == data['pubkey']['uncompress_hex']
Ejemplo n.º 19
0
 def test_to_pubkey_compressed(self):
     k = PrivateKey.from_wif(data['wif']['live_uncompress'])
     assert k.to_public_key().to_hex() == data['pubkey']['uncompress_hex']
Ejemplo n.º 20
0
 def test_bitcoind_invalid_wifs(self, invalid_wifs):
     for invalid_wif in invalid_wifs:
         with raises(PrivateKey.Error):
             PrivateKey.from_wif(invalid_wif)
Ejemplo n.º 21
0
    def test_from_wif_live_uncompress(self):
        k = PrivateKey.from_wif(data['wif']['live_uncompress'])

        assert k.compressed is False
        assert k.network is networks.livenet
        assert k.to_wif() == data['wif']['live_uncompress']
Ejemplo n.º 22
0
    def test_from_invalid_bytes(self):
        with raises(privkey.InvalidEncoding):
            PrivateKey.from_bytes('a')

        with raises(privkey.InvalidEncoding):
            PrivateKey.from_bytes('a' * 33)
Ejemplo n.º 23
0
    def test_generate_random_keys(self):

        k1 = PrivateKey.generate()
        k2 = PrivateKey.generate()
        assert k1.key.private_numbers() != k2.key.private_numbers()
Ejemplo n.º 24
0
 def test_bitcoind_invalid_wifs(self, invalid_wifs):
     for invalid_wif in invalid_wifs:
         with raises(PrivateKey.Error):
             PrivateKey.from_wif(invalid_wif)
Ejemplo n.º 25
0
 def test_to_address_test_uncompressed(self):
     k = PrivateKey.from_wif(data['wif']['test_uncompress'])
     assert k.to_address().to_string() == data['address']['test_uncompress']
Ejemplo n.º 26
0
 def test_to_address_test_uncompressed(self):
     k = PrivateKey.from_wif(data['wif']['test_uncompress'])
     assert k.to_address().to_string() == data['address']['test_uncompress']
Ejemplo n.º 27
0
 def test_from_invalid_hex(self):
     with raises(PrivateKey.InvalidHex):
         PrivateKey.from_hex('a')
     with raises(PrivateKey.InvalidHex):
         PrivateKey.from_hex('a@')
Ejemplo n.º 28
0
 def test_from_random(self):
     k1, k2 = PrivateKey(), PrivateKey()
     assert k1.secret != k2.secret
Ejemplo n.º 29
0
    def test_from_invalid_bytes(self):
        with raises(PrivateKey.InvalidBinaryLength):
            PrivateKey.from_bytes('a')

        with raises(PrivateKey.InvalidBinaryLength):
            PrivateKey.from_bytes('a' * 33)
Ejemplo n.º 30
0
 def test_invalid_network(self):
     with raises(PrivateKey.UnknownNetwork):
         PrivateKey(network=-1)
Ejemplo n.º 31
0
    def test_from_secret_exponent(self, valid_exponents):

        for exponent in valid_exponents:
            k = PrivateKey.from_secret_exponent(exponent)
            assert k.key.private_numbers().private_value == exponent
Ejemplo n.º 32
0
 def test_from_invalid_hex(self):
     with raises(PrivateKey.InvalidHex): PrivateKey.from_hex('a')
     with raises(PrivateKey.InvalidHex): PrivateKey.from_hex('a@')
Ejemplo n.º 33
0
    def test_from_invalid_bytes(self):
        with raises(PrivateKey.InvalidBinaryLength):
            PrivateKey.from_bytes('a')

        with raises(PrivateKey.InvalidBinaryLength):
            PrivateKey.from_bytes('a' * 33)
Ejemplo n.º 34
0
    def test_from_wif_live_compress(self):
        k = PrivateKey.from_wif(data['wif']['live_compress'])

        assert k.compressed is True
        assert k.network is networks.livenet
        assert k.to_wif() == data['wif']['live_compress']
Ejemplo n.º 35
0
 def test_bitcoind_invalid_wifs(self, invalid_wifs):
     for invalid_wif in invalid_wifs:
         with raises(privkey.InvalidEncoding):
             PrivateKey.from_wif(invalid_wif)