Beispiel #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)
Beispiel #2
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)
Beispiel #3
0
 def test_keys(self):
     with open("tests/keys_test_vector.json", 'r') as f:
         vectors = json.loads(f.read())
     for vector in vectors:
         private_key = PrivateKey.from_wif(vector['private_key'],
                                           network=BitcoinMainNet)
         public_key = PublicKey.from_hex_key(vector['pubkey'],
                                             network=BitcoinMainNet)
         self.assertEqual(private_key.get_public_key(), public_key)
         self.assertEqual(public_key.to_address(), vector['address'])
 def test_keys(self):
     with open("tests/keys_test_vector.json", 'r') as f:
         vectors = json.loads(f.read())
     for vector in vectors:
         private_key = PrivateKey.from_wif(
             vector['private_key'], network=BitcoinMainNet)
         public_key = PublicKey.from_hex_key(
             vector['pubkey'], network=BitcoinMainNet)
         self.assertEqual(private_key.get_public_key(), public_key)
         self.assertEqual(public_key.to_address(), vector['address'])
Beispiel #5
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")
Beispiel #6
0
 def test_import_wif(self):
     key = PrivateKey.from_wif(self.expected_wif)
     self.assertEqual(key, self.key)
Beispiel #7
0
 def test_raw_key_hex_bytes(self):
     key = binascii.unhexlify(self.key.get_key())
     self.assertEqual(PrivateKey.from_hex_key(key), self.key)
Beispiel #8
0
 def test_raw_key_hex(self):
     exp = self.key._private_key.privkey.secret_multiplier
     self.assertEqual(PrivateKey(exp), self.key)
Beispiel #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))
Beispiel #10
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())