Ejemplo n.º 1
0
 def test_import_wif_network(self):
     # Make a wif for bitcoin testnet:
     testnet_key = PrivateKey(
         self.key._private_key.privkey.secret_multiplier,
         network=BitcoinTestNet)
     testnet_wif = testnet_key.export_to_wif()
     # We should be able to load it properly
     key = PrivateKey.from_wif(testnet_wif, BitcoinTestNet)
     self.assertEqual(testnet_key, key)
Ejemplo n.º 2
0
    def test_export_to_wif_compressed(self):
        compressed_wif = self.key.export_to_wif(compressed=True)
        self.assertNotEqual(compressed_wif, self.expected_key)

        pk = PrivateKey.from_wif(compressed_wif)
        self.assertEqual(pk, PrivateKey.from_wif(self.expected_wif))
        self.assertEqual(
            pk.export_to_wif(compressed=False), self.expected_wif)
        self.assertEqual(
            pk.export_to_wif(compressed=True), compressed_wif)
        self.assertEqual(pk, self.key)
Ejemplo n.º 3
0
    def test_from_master_password(self):
        password = "******"
        expected_wif = "5KJvsngHeMpm884wtkJNzQGaCErckhHJBGFsvd3VyK5qMZXj3hS"
        expected_pub_address = "1JwSSubhmg6iPtRjtyqhUYYH7bZg3Lfy1T"

        key = PrivateKey.from_master_password(password)
        self.assertEqual(key.export_to_wif(), expected_wif)
        self.assertEqual(
            key.get_public_key().to_address(), expected_pub_address)
Ejemplo n.º 4
0
 def setUpClass(cls):
     # This private key chosen from the bitcoin docs:
     # https://en.bitcoin.it/wiki/Wallet_import_format
     cls.expected_private_key = \
         b"18e14a7b6a307f426a94f8114701e7c8e774e7f9a47e2c2035db29a206321725"
     cls.private_key = PrivateKey(
         long_or_int(cls.expected_private_key, 16))
     cls.public_key = PublicKey.from_hex_key(
         "04"
         "50863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352"
         "2cd470243453a299fa9e77237716103abc11a1df38855ed6f2ee187e9c582ba6")
Ejemplo n.º 5
0
 def test_import_wif(self):
     key = PrivateKey.from_wif(self.expected_wif)
     self.assertEqual(key, self.key)
Ejemplo n.º 6
0
 def test_raw_key_hex_bytes(self):
     key = unhexlify(self.key.get_key())
     self.assertEqual(PrivateKey.from_hex_key(key), self.key)
Ejemplo n.º 7
0
 def test_raw_key_hex(self):
     exp = self.key._private_key.privkey.secret_multiplier
     self.assertEqual(PrivateKey(exp), self.key)
Ejemplo n.º 8
0
 def _test(self, network, secret, address, compressed):
     key = PrivateKey.from_wif(secret, network=network)
     self.assertEqual(key.compressed, compressed)
     self.assertEqual(address, key.get_public_key().to_address())
Ejemplo n.º 9
0
 def setUpClass(cls):
     # This private key chosen from the bitcoin docs:
     # https://en.bitcoin.it/wiki/Wallet_import_format
     cls.expected_key = \
         b"0c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d"
     cls.key = PrivateKey(long_or_int(cls.expected_key, 16))