diff --git a/bigchaindb/consensus.py b/bigchaindb/consensus.py index f039597d..277dad3e 100644 --- a/bigchaindb/consensus.py +++ b/bigchaindb/consensus.py @@ -2,7 +2,7 @@ from abc import ABCMeta, abstractmethod import bigchaindb.exceptions as exceptions from bigchaindb import util -from bigchaindb.crypto import hash_data +from bigchaindb import crypto class AbstractConsensusRules(metaclass=ABCMeta): @@ -156,7 +156,7 @@ class BaseConsensusRules(AbstractConsensusRules): transaction['transaction']['input'])) # Check hash of the transaction - calculated_hash = hash_data(util.serialize( + calculated_hash = crypto.hash_data(util.serialize( transaction['transaction'])) if calculated_hash != transaction['id']: raise exceptions.InvalidHash() @@ -185,7 +185,7 @@ class BaseConsensusRules(AbstractConsensusRules): """ # Check if current hash is correct - calculated_hash = hash_data(util.serialize(block['block'])) + calculated_hash = crypto.hash_data(util.serialize(block['block'])) if calculated_hash != block['id']: raise exceptions.InvalidHash() diff --git a/bigchaindb/crypto.py b/bigchaindb/crypto.py index 5bdc81c4..506cb00e 100644 --- a/bigchaindb/crypto.py +++ b/bigchaindb/crypto.py @@ -1,25 +1,17 @@ # Separate all crypto code so that we can easily test several implementations import sha3 -from cryptoconditions import ecdsa, ed25519 - - -signing_algorithm = 'ed25519' - -if signing_algorithm == 'ecdsa': - SigningKey = ecdsa.EcdsaSigningKey - VerifyingKey = ecdsa.EcdsaVerifyingKey - generate_key_pair = ecdsa.ecdsa_generate_key_pair - -elif signing_algorithm == 'ed25519': - SigningKey = ed25519.Ed25519SigningKey - VerifyingKey = ed25519.Ed25519VerifyingKey - generate_key_pair = ed25519.ed25519_generate_key_pair +from cryptoconditions import ed25519 def hash_data(data): """Hash the provided data using SHA3-256""" - return sha3.sha3_256(data.encode()).hexdigest() +def generate_key_pair(): + sk, pk = ed25519.ed25519_generate_key_pair() + return sk.decode(), pk.decode() + +SigningKey = ed25519.Ed25519SigningKey +VerifyingKey = ed25519.Ed25519VerifyingKey diff --git a/setup.py b/setup.py index e26dd1fd..8c170823 100644 --- a/setup.py +++ b/setup.py @@ -71,7 +71,7 @@ setup( 'rethinkdb==2.2.0.post4', 'pysha3==0.3', 'pytz==2015.7', - 'cryptoconditions==0.1.0', + 'cryptoconditions==0.1.1', 'statsd==3.2.1', 'python-rapidjson==0.0.6', 'logstats==0.2.1', diff --git a/tests/conftest.py b/tests/conftest.py index 3debae03..c5018b7e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,14 +33,14 @@ CONFIG_ED25519 = { 'name': DB_NAME }, 'keypair': { - 'private': '3wssdnSNsZYLvvQwuag5QNQnSfc5N38KV1ZeAoeHQQVe59N7vReJwXWANf5nncGxW63UzR4qHHv6DJhyLs9arJng', - 'public': '4spEuJCR6UNkS9Qyz6QwseU3ENRaypkcVgGKDeqfg8Ha' + 'private': '31Lb1ZGKTyHnmVK3LUMrAUrPNfd4sE2YyBt3UA4A25aA', + 'public': '4XYfCbabAWVUCbjTmRTFEu2sc3dFEdkse4r6X498B1s8' } } # Test user. inputs will be created for this user. Cryptography Keys -USER_PRIVATE_KEY_ED25519 = '3RZ3Kn8JbzyNwqzDwhU4dkZFFcwVkfgjhKiiqybfabxFAaANZqPemEudxTYMKfkbrHADTGCkvR7uQHSjihsXLbcM' -USER_PUBLIC_KEY_ED25519 = '2XJT5M6D3fYhvDbgcHmGMUcrGeZ9MtCWGqQZZVXghjv9' +USER_PRIVATE_KEY_ED25519 = '8eJ8q9ZQpReWyQT5aFCiwtZ5wDZC4eDnCen88p3tQ6ie' +USER_PUBLIC_KEY_ED25519 = 'JEAkEJqLbbgDRAtMm8YAjGp759Aq2qTn9eaEHUj2XePE' @pytest.fixture