def test_leading_zeros(self): """This zero-leading x coordinate generated by: pvk = '18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725' # nopep8 from ecdsa import SECP256k1 from ecdsa.ecdsa import Public_key from bitmerchant.wallet.utils import long_to_hex pubkey = Public_key( SECP256k1.generator, SECP256k1.generator * long(pvk, 16)) for i in range(1, 10000): p = pubkey.point * i x = p.x() k = long_to_hex(x, 64) if k.startswith('0'): print(i) print(long_to_hex(p.x(), 64)) print(long_to_hex(p.y(), 64)) break """ expected_key = ensure_bytes( "04" "02cbfd5410fd04973c096a4275bf75070955ebd689f316a6fbd449980ba7b756" "c559764e5c367c03e002751aaf4ef8ec40fe97cda9b2d3f14fdd4cd244e8fcd2") public_key = PublicKey.from_hex_key(expected_key) self.assertEqual(public_key.get_key(), expected_key)
def _test_key(vector): private_key = PrivateKey.from_wif(vector['private_key'], network=BitcoinMainNet) public_key = PublicKey.from_hex_key(vector['pubkey'], network=BitcoinMainNet) assert private_key.get_public_key() == public_key assert public_key.to_address() == vector['address']
def _test_key(vector): private_key = PrivateKey.from_wif( vector['private_key'], network=BitcoinMainNet) public_key = PublicKey.from_hex_key( vector['pubkey'], network=BitcoinMainNet) assert private_key.get_public_key() == public_key assert 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'])
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")
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 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")
def test_compressed(self): compressed_key = self.public_key.get_key(compressed=True) self.assertEqual(len(compressed_key), 66) self.assertEqual( PublicKey.from_hex_key(compressed_key), self.public_key)
def test_unhexlified_key(self): key_bytes = binascii.unhexlify(self.public_key.get_key()) self.assertEqual( PublicKey.from_hex_key(key_bytes), self.public_key)
def test_compressed(self): compressed_key = self.public_key.get_key(compressed=True) self.assertEqual(len(compressed_key), 66) self.assertEqual(PublicKey.from_hex_key(compressed_key), self.public_key)
def test_unhexlified_key(self): key_bytes = unhexlify(self.public_key.get_key()) self.assertEqual(PublicKey.from_hex_key(key_bytes), self.public_key)