imports from crypto

This commit is contained in:
diminator 2016-03-31 15:10:43 +02:00
parent 4138842eed
commit ce1302dd90
4 changed files with 15 additions and 23 deletions

View File

@ -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()

View File

@ -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

View File

@ -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',

View File

@ -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