mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge pull request #685 from bigchaindb/bug/617/support-new-cc
Added support for cryptoconditions 0.5.0
This commit is contained in:
commit
2c0ed0dc13
@ -616,7 +616,7 @@ class Bigchain(object):
|
||||
}
|
||||
|
||||
vote_data = serialize(vote)
|
||||
signature = crypto.SigningKey(self.me_private).sign(vote_data)
|
||||
signature = crypto.SigningKey(self.me_private).sign(vote_data.encode())
|
||||
|
||||
vote_signed = {
|
||||
'node_pubkey': self.me,
|
||||
|
@ -185,12 +185,13 @@ class Block(object):
|
||||
block_body = self.to_dict()
|
||||
block_serialized = serialize(block_body['block'])
|
||||
signing_key = SigningKey(signing_key)
|
||||
self.signature = signing_key.sign(block_serialized)
|
||||
self.signature = signing_key.sign(block_serialized.encode()).decode()
|
||||
return self
|
||||
|
||||
def is_signature_valid(self):
|
||||
block = self.to_dict()['block']
|
||||
block_serialized = serialize(block)
|
||||
# cc only accepts bytesting messages
|
||||
block_serialized = serialize(block).encode()
|
||||
verifying_key = VerifyingKey(block['node_pubkey'])
|
||||
try:
|
||||
# NOTE: CC throws a `ValueError` on some wrong signatures
|
||||
@ -218,8 +219,8 @@ class Block(object):
|
||||
# NOTE: CC throws a `ValueError` on some wrong signatures
|
||||
# https://github.com/bigchaindb/cryptoconditions/issues/27
|
||||
try:
|
||||
signature_valid = verifying_key.verify(block_serialized,
|
||||
signature)
|
||||
signature_valid = verifying_key\
|
||||
.verify(block_serialized.encode(), signature)
|
||||
except ValueError:
|
||||
signature_valid = False
|
||||
if signature_valid is False:
|
||||
|
@ -137,7 +137,7 @@ def verify_vote_signature(voters, signed_vote):
|
||||
return False
|
||||
|
||||
public_key = crypto.VerifyingKey(vk_base58)
|
||||
return public_key.verify(serialize(signed_vote['vote']), signature)
|
||||
return public_key.verify(serialize(signed_vote['vote']).encode(), signature)
|
||||
|
||||
|
||||
def is_genesis_block(block):
|
||||
|
4
setup.py
4
setup.py
@ -93,7 +93,7 @@ setup(
|
||||
'rethinkdb~=2.3',
|
||||
'pysha3==0.3',
|
||||
'pytz==2015.7',
|
||||
'cryptoconditions==0.4.1',
|
||||
'cryptoconditions==0.5.0',
|
||||
'statsd==3.2.1',
|
||||
'python-rapidjson==0.0.6',
|
||||
'logstats==0.2.1',
|
||||
@ -103,7 +103,7 @@ setup(
|
||||
'requests~=2.9',
|
||||
'gunicorn~=19.0',
|
||||
'multipipes~=0.1.0',
|
||||
'bigchaindb-common>=0.0.4',
|
||||
'bigchaindb-common==0.0.6',
|
||||
],
|
||||
setup_requires=['pytest-runner'],
|
||||
tests_require=tests_require,
|
||||
|
@ -47,7 +47,7 @@ class TestBigchainApi(object):
|
||||
vote = b.vote(block1.id, b.get_last_voted_block().id, True)
|
||||
vote['vote']['previous_block'] = block1.id
|
||||
vote_data = serialize(vote['vote'])
|
||||
vote['signature'] = SigningKey(b.me_private).sign(vote_data)
|
||||
vote['signature'] = SigningKey(b.me_private).sign(vote_data.encode())
|
||||
b.write_vote(vote)
|
||||
|
||||
with pytest.raises(CyclicBlockchainError):
|
||||
|
@ -33,7 +33,7 @@ def test_vote_creation_valid(b):
|
||||
assert vote['vote']['is_block_valid'] is True
|
||||
assert vote['vote']['invalid_reason'] is None
|
||||
assert vote['node_pubkey'] == b.me
|
||||
assert crypto.VerifyingKey(b.me).verify(serialize(vote['vote']),
|
||||
assert crypto.VerifyingKey(b.me).verify(serialize(vote['vote']).encode(),
|
||||
vote['signature']) is True
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ def test_vote_creation_invalid(b):
|
||||
assert vote['vote']['is_block_valid'] is False
|
||||
assert vote['vote']['invalid_reason'] is None
|
||||
assert vote['node_pubkey'] == b.me
|
||||
assert crypto.VerifyingKey(b.me).verify(serialize(vote['vote']),
|
||||
assert crypto.VerifyingKey(b.me).verify(serialize(vote['vote']).encode(),
|
||||
vote['signature']) is True
|
||||
|
||||
|
||||
@ -176,8 +176,9 @@ def test_valid_block_voting_sequential(b, monkeypatch):
|
||||
'invalid_reason': None,
|
||||
'timestamp': '1'}
|
||||
|
||||
serialized_vote = util.serialize(vote_doc['vote']).encode()
|
||||
assert vote_doc['node_pubkey'] == b.me
|
||||
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote_doc['vote']),
|
||||
assert crypto.VerifyingKey(b.me).verify(serialized_vote,
|
||||
vote_doc['signature']) is True
|
||||
|
||||
|
||||
@ -210,8 +211,9 @@ def test_valid_block_voting_multiprocessing(b, monkeypatch):
|
||||
'invalid_reason': None,
|
||||
'timestamp': '1'}
|
||||
|
||||
serialized_vote = util.serialize(vote_doc['vote']).encode()
|
||||
assert vote_doc['node_pubkey'] == b.me
|
||||
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote_doc['vote']),
|
||||
assert crypto.VerifyingKey(b.me).verify(serialized_vote,
|
||||
vote_doc['signature']) is True
|
||||
|
||||
|
||||
@ -251,8 +253,9 @@ def test_valid_block_voting_with_create_transaction(b, monkeypatch):
|
||||
'invalid_reason': None,
|
||||
'timestamp': '1'}
|
||||
|
||||
serialized_vote = util.serialize(vote_doc['vote']).encode()
|
||||
assert vote_doc['node_pubkey'] == b.me
|
||||
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote_doc['vote']),
|
||||
assert crypto.VerifyingKey(b.me).verify(serialized_vote,
|
||||
vote_doc['signature']) is True
|
||||
|
||||
|
||||
@ -305,8 +308,9 @@ def test_valid_block_voting_with_transfer_transactions(monkeypatch, b):
|
||||
'invalid_reason': None,
|
||||
'timestamp': '2'}
|
||||
|
||||
serialized_vote = util.serialize(vote_doc['vote']).encode()
|
||||
assert vote_doc['node_pubkey'] == b.me
|
||||
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote_doc['vote']),
|
||||
assert crypto.VerifyingKey(b.me).verify(serialized_vote,
|
||||
vote_doc['signature']) is True
|
||||
|
||||
vote2_rs = r.table('votes').get_all([block2.id, b.me],
|
||||
@ -319,8 +323,9 @@ def test_valid_block_voting_with_transfer_transactions(monkeypatch, b):
|
||||
'invalid_reason': None,
|
||||
'timestamp': '2'}
|
||||
|
||||
serialized_vote2 = util.serialize(vote2_doc['vote']).encode()
|
||||
assert vote2_doc['node_pubkey'] == b.me
|
||||
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote2_doc['vote']),
|
||||
assert crypto.VerifyingKey(b.me).verify(serialized_vote2,
|
||||
vote2_doc['signature']) is True
|
||||
|
||||
|
||||
@ -356,8 +361,9 @@ def test_unsigned_tx_in_block_voting(monkeypatch, b, user_vk):
|
||||
'invalid_reason': None,
|
||||
'timestamp': '1'}
|
||||
|
||||
serialized_vote = util.serialize(vote_doc['vote']).encode()
|
||||
assert vote_doc['node_pubkey'] == b.me
|
||||
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote_doc['vote']),
|
||||
assert crypto.VerifyingKey(b.me).verify(serialized_vote,
|
||||
vote_doc['signature']) is True
|
||||
|
||||
|
||||
@ -395,8 +401,9 @@ def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_vk):
|
||||
'invalid_reason': None,
|
||||
'timestamp': '1'}
|
||||
|
||||
serialized_vote = util.serialize(vote_doc['vote']).encode()
|
||||
assert vote_doc['node_pubkey'] == b.me
|
||||
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote_doc['vote']),
|
||||
assert crypto.VerifyingKey(b.me).verify(serialized_vote,
|
||||
vote_doc['signature']) is True
|
||||
|
||||
|
||||
@ -434,8 +441,9 @@ def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_vk):
|
||||
'invalid_reason': None,
|
||||
'timestamp': '1'}
|
||||
|
||||
serialized_vote = util.serialize(vote_doc['vote']).encode()
|
||||
assert vote_doc['node_pubkey'] == b.me
|
||||
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote_doc['vote']),
|
||||
assert crypto.VerifyingKey(b.me).verify(serialized_vote,
|
||||
vote_doc['signature']) is True
|
||||
|
||||
|
||||
@ -469,8 +477,9 @@ def test_invalid_block_voting(monkeypatch, b, user_vk):
|
||||
'invalid_reason': None,
|
||||
'timestamp': '1'}
|
||||
|
||||
serialized_vote = util.serialize(vote_doc['vote']).encode()
|
||||
assert vote_doc['node_pubkey'] == b.me
|
||||
assert crypto.VerifyingKey(b.me).verify(util.serialize(vote_doc['vote']),
|
||||
assert crypto.VerifyingKey(b.me).verify(serialized_vote,
|
||||
vote_doc['signature']) is True
|
||||
|
||||
|
||||
|
@ -155,11 +155,11 @@ class TestBlockModel(object):
|
||||
'node_pubkey': b.me,
|
||||
'voters': voters,
|
||||
}
|
||||
expected_block_serialized = serialize(expected_block)
|
||||
expected_block_serialized = serialize(expected_block).encode()
|
||||
expected = SigningKey(b.me_private).sign(expected_block_serialized)
|
||||
block = Block(transactions, b.me, timestamp, voters)
|
||||
block = block.sign(b.me_private)
|
||||
assert block.signature == expected
|
||||
assert block.signature == expected.decode()
|
||||
|
||||
verifying_key = VerifyingKey(b.me)
|
||||
assert verifying_key.verify(expected_block_serialized, block.signature)
|
||||
|
Loading…
x
Reference in New Issue
Block a user