From c068f04a82d4cbe6a7b0d80cd04314fc2b107ee9 Mon Sep 17 00:00:00 2001 From: Rodolphe Marques Date: Thu, 10 Nov 2016 17:01:06 +0100 Subject: [PATCH] Replaced VerifyingKey with PublicKey Replaced SigningKey with PrivateKey Replaced all occurences of signing key with private key Replaced all occurences of verifying key with public key --- bigchaindb/common/crypto.py | 4 +- bigchaindb/common/transaction.py | 6 +- bigchaindb/core.py | 2 +- bigchaindb/models.py | 16 +++--- bigchaindb/util.py | 2 +- deploy-cluster-aws/write_keypairs_file.py | 4 +- docs/root/source/data-models/block-model.rst | 10 ++-- docs/root/source/transaction-concepts.md | 57 ++++++++++++++----- docs/server/source/appendices/cryptography.md | 24 ++++++-- tests/common/test_transaction.py | 20 +++---- tests/conftest.py | 8 +-- tests/db/test_bigchain_api.py | 8 +-- .../doc/run_doc_python_server_api_examples.py | 8 +-- tests/pipelines/test_vote.py | 22 +++---- tests/test_models.py | 8 +-- 15 files changed, 120 insertions(+), 79 deletions(-) diff --git a/bigchaindb/common/crypto.py b/bigchaindb/common/crypto.py index e440f81d..a0b5a71d 100644 --- a/bigchaindb/common/crypto.py +++ b/bigchaindb/common/crypto.py @@ -14,5 +14,5 @@ def generate_key_pair(): private_key, public_key = crypto.ed25519_generate_key_pair() return private_key.decode(), public_key.decode() -SigningKey = crypto.Ed25519SigningKey -VerifyingKey = crypto.Ed25519VerifyingKey +PrivateKey = crypto.Ed25519SigningKey +PublicKey = crypto.Ed25519VerifyingKey diff --git a/bigchaindb/common/transaction.py b/bigchaindb/common/transaction.py index c1857d23..c55ab83e 100644 --- a/bigchaindb/common/transaction.py +++ b/bigchaindb/common/transaction.py @@ -7,7 +7,7 @@ from cryptoconditions import (Fulfillment as CCFulfillment, PreimageSha256Fulfillment) from cryptoconditions.exceptions import ParsingError -from bigchaindb.common.crypto import SigningKey, hash_data +from bigchaindb.common.crypto import PrivateKey, hash_data from bigchaindb.common.exceptions import (KeypairMismatchException, InvalidHash, InvalidSignature) from bigchaindb.common.util import serialize, gen_timestamp @@ -865,8 +865,8 @@ class Transaction(object): # to decode to convert the bytestring into a python str return public_key.decode() - key_pairs = {gen_public_key(SigningKey(private_key)): - SigningKey(private_key) for private_key in private_keys} + key_pairs = {gen_public_key(PrivateKey(private_key)): + PrivateKey(private_key) for private_key in private_keys} zippedIO = enumerate(zip(self.fulfillments, self.conditions)) for index, (fulfillment, condition) in zippedIO: diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 5a007eab..4df29dd1 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -567,7 +567,7 @@ class Bigchain(object): } vote_data = serialize(vote) - signature = crypto.SigningKey(self.me_private).sign(vote_data.encode()) + signature = crypto.PrivateKey(self.me_private).sign(vote_data.encode()) vote_signed = { 'node_pubkey': self.me, diff --git a/bigchaindb/models.py b/bigchaindb/models.py index 6471b075..5aa697cb 100644 --- a/bigchaindb/models.py +++ b/bigchaindb/models.py @@ -1,4 +1,4 @@ -from bigchaindb.common.crypto import hash_data, VerifyingKey, SigningKey +from bigchaindb.common.crypto import hash_data, PublicKey, PrivateKey from bigchaindb.common.exceptions import (InvalidHash, InvalidSignature, OperationError, DoubleSpend, TransactionDoesNotExist, @@ -181,22 +181,22 @@ class Block(object): return self - def sign(self, signing_key): + def sign(self, private_key): block_body = self.to_dict() block_serialized = serialize(block_body['block']) - signing_key = SigningKey(signing_key) - self.signature = signing_key.sign(block_serialized.encode()).decode() + private_key = PrivateKey(private_key) + self.signature = private_key.sign(block_serialized.encode()).decode() return self def is_signature_valid(self): block = self.to_dict()['block'] # cc only accepts bytesting messages block_serialized = serialize(block).encode() - verifying_key = VerifyingKey(block['node_pubkey']) + public_key = PublicKey(block['node_pubkey']) try: # NOTE: CC throws a `ValueError` on some wrong signatures # https://github.com/bigchaindb/cryptoconditions/issues/27 - return verifying_key.verify(block_serialized, self.signature) + return public_key.verify(block_serialized, self.signature) except (ValueError, AttributeError): return False @@ -205,7 +205,7 @@ class Block(object): block = block_body['block'] block_serialized = serialize(block) block_id = hash_data(block_serialized) - verifying_key = VerifyingKey(block['node_pubkey']) + public_key = PublicKey(block['node_pubkey']) try: signature = block_body['signature'] @@ -219,7 +219,7 @@ class Block(object): # NOTE: CC throws a `ValueError` on some wrong signatures # https://github.com/bigchaindb/cryptoconditions/issues/27 try: - signature_valid = verifying_key\ + signature_valid = public_key\ .verify(block_serialized.encode(), signature) except ValueError: signature_valid = False diff --git a/bigchaindb/util.py b/bigchaindb/util.py index 272c7d67..61d3a218 100644 --- a/bigchaindb/util.py +++ b/bigchaindb/util.py @@ -136,7 +136,7 @@ def verify_vote_signature(voters, signed_vote): if vk_base58 not in voters: return False - public_key = crypto.VerifyingKey(vk_base58) + public_key = crypto.PublicKey(vk_base58) return public_key.verify(serialize(signed_vote['vote']).encode(), signature) diff --git a/deploy-cluster-aws/write_keypairs_file.py b/deploy-cluster-aws/write_keypairs_file.py index da4fc1b1..d2fda508 100644 --- a/deploy-cluster-aws/write_keypairs_file.py +++ b/deploy-cluster-aws/write_keypairs_file.py @@ -10,8 +10,8 @@ Using the list in other Python scripts: # in a Python 2 script: from keypairs import keypairs_list # keypairs_list is a list of (sk, pk) tuples - # sk = signing key (private key) - # pk = verifying key (public key) + # sk = private key + # pk = public key """ import argparse diff --git a/docs/root/source/data-models/block-model.rst b/docs/root/source/data-models/block-model.rst index c5eb623f..94808426 100644 --- a/docs/root/source/data-models/block-model.rst +++ b/docs/root/source/data-models/block-model.rst @@ -10,8 +10,8 @@ A block has the following structure: "block": { "timestamp": "", "transactions": [""], - "node_pubkey": "", - "voters": [""] + "node_pubkey": "", + "voters": [""] }, "signature": "" } @@ -22,12 +22,12 @@ A block has the following structure: - ``block``: - ``timestamp``: The Unix time when the block was created. It's provided by the node that created the block. See `the page about timestamps `_. - ``transactions``: A list of the transactions included in the block. - - ``node_pubkey``: The public/verifying key of the node that created the block. - - ``voters``: A list of the verifying keys of federation nodes at the time the block was created. + - ``node_pubkey``: The public key of the node that created the block. + - ``voters``: A list of the public keys of federation nodes at the time the block was created. It's the list of federation nodes which can cast a vote on this block. This list can change from block to block, as nodes join and leave the federation. -- ``signature``: Cryptographic signature of the block by the node that created the block. (To create the signature, the node serializes the block contents and signs that with its signing key.) +- ``signature``: Cryptographic signature of the block by the node that created the block. (To create the signature, the node serializes the block contents and signs it with its private key.) Working with Blocks diff --git a/docs/root/source/transaction-concepts.md b/docs/root/source/transaction-concepts.md index 541cd886..bc81e2b9 100644 --- a/docs/root/source/transaction-concepts.md +++ b/docs/root/source/transaction-concepts.md @@ -1,29 +1,58 @@ # Transaction Concepts -In BigchainDB, _Transactions_ are used to register, issue, create or transfer things (e.g. assets). +In BigchainDB, _Transactions_ are used to register, issue, create or transfer +things (e.g. assets). -Transactions are the most basic kind of record stored by BigchainDB. There are two kinds: creation transactions and transfer transactions. +Transactions are the most basic kind of record stored by BigchainDB. There are +two kinds: creation transactions and transfer transactions. -A _creation transaction_ can be used to register, issue, create or otherwise initiate the history of a single thing (or asset) in BigchainDB. For example, one might register an identity or a creative work. The things are often called "assets" but they might not be literal assets. +A _creation transaction_ can be used to register, issue, create or otherwise +initiate the history of a single thing (or asset) in BigchainDB. For example, +one might register an identity or a creative work. The things are often called +"assets" but they might not be literal assets. -Currently, BigchainDB only supports indivisible assets. You can't split an asset apart into multiple assets, nor can you combine several assets together into one. [Issue #129](https://github.com/bigchaindb/bigchaindb/issues/129) is an enhancement proposal to support divisible assets. +Currently, BigchainDB only supports indivisible assets. You can't split an +asset apart into multiple assets, nor can you combine several assets together +into one. [Issue #129](https://github.com/bigchaindb/bigchaindb/issues/129) is +an enhancement proposal to support divisible assets. -A creation transaction also establishes the conditions that must be met to transfer the asset. For example, there may be a condition that any transfer must be signed (cryptographically) by the signing/private key associated with a given verifying/public key. More sophisticated conditions are possible. BigchainDB's conditions are based on the crypto-conditions of the [Interledger Protocol (ILP)](https://interledger.org/). +A creation transaction also establishes the conditions that must be met to +transfer the asset. For example, there may be a condition that any transfer +must be signed (cryptographically) by the private key associated with a +given public key. More sophisticated conditions are possible. +BigchainDB's conditions are based on the crypto-conditions of the [Interledger +Protocol (ILP)](https://interledger.org/). -A _transfer transaction_ can transfer an asset by fulfilling the current conditions on the asset. It can also specify new transfer conditions. +A _transfer transaction_ can transfer an asset by fulfilling the current +conditions on the asset. It can also specify new transfer conditions. -Today, every transaction contains one fulfillment-condition pair. The fulfillment in a transfer transaction must fulfill a condition in a previous transaction. +Today, every transaction contains one fulfillment-condition pair. The +fulfillment in a transfer transaction must fulfill a condition in a previous +transaction. -When a node is asked to check if a transaction is valid, it checks several things. Some things it checks are: +When a node is asked to check if a transaction is valid, it checks several +things. Some things it checks are: -* Are all the fulfillments valid? (Do they correctly satisfy the conditions they claim to satisfy?) +* Are all the fulfillments valid? (Do they correctly satisfy the conditions + they claim to satisfy?) * If it's a creation transaction, is the asset valid? * If it's a transfer transaction: * Is it trying to fulfill a condition in a nonexistent transaction? - * Is it trying to fulfill a condition that's not in a valid transaction? (It's okay if the condition is in a transaction in an invalid block; those transactions are ignored. Transactions in the backlog or undecided blocks are not ignored.) - * Is it trying to fulfill a condition that has already been fulfilled, or that some other pending transaction (in the backlog or an undecided block) also aims to fulfill? - * Is the asset ID in the transaction the same as the asset ID in all transactions whose conditions are being fulfilled? + * Is it trying to fulfill a condition that's not in a valid transaction? + (It's okay if the condition is in a transaction in an invalid block; those + transactions are ignored. Transactions in the backlog or undecided blocks + are not ignored.) + * Is it trying to fulfill a condition that has already been fulfilled, or + that some other pending transaction (in the backlog or an undecided block) + also aims to fulfill? + * Is the asset ID in the transaction the same as the asset ID in all + transactions whose conditions are being fulfilled? -If you're curious about the details of transaction validation, the code is in the `validate` method of the `Transaction` class, in `bigchaindb/models.py` (at the time of writing). +If you're curious about the details of transaction validation, the code is in +the `validate` method of the `Transaction` class, in `bigchaindb/models.py` (at +the time of writing). -Note: The check to see if the transaction ID is equal to the hash of the transaction body is actually done whenever the transaction is converted from a Python dict to a Transaction object, which must be done before the `validate` method can be called (since it's called on a Transaction object). +Note: The check to see if the transaction ID is equal to the hash of the +transaction body is actually done whenever the transaction is converted from a +Python dict to a Transaction object, which must be done before the `validate` +method can be called (since it's called on a Transaction object). diff --git a/docs/server/source/appendices/cryptography.md b/docs/server/source/appendices/cryptography.md index 48865939..3c0a9297 100644 --- a/docs/server/source/appendices/cryptography.md +++ b/docs/server/source/appendices/cryptography.md @@ -1,12 +1,16 @@ # Cryptography -The section documents the cryptographic algorithms and Python implementations that we use. +The section documents the cryptographic algorithms and Python implementations +that we use. -Before hashing or computing the signature of a JSON document, we serialize it as described in [the section on JSON serialization](json-serialization.html). +Before hashing or computing the signature of a JSON document, we serialize it +as described in [the section on JSON serialization](json-serialization.html). ## Hashes -We compute hashes using the SHA3-256 algorithm and [pysha3](https://bitbucket.org/tiran/pykeccak) as the Python implementation. We store the hex-encoded hash in the database. For example: +We compute hashes using the SHA3-256 algorithm and +[pysha3](https://bitbucket.org/tiran/pykeccak) as the Python implementation. We +store the hex-encoded hash in the database. For example: ```python import hashlib @@ -19,8 +23,16 @@ tx_hash = hashlib.sha3_256(data).hexdigest() ## Signature Algorithm and Keys -BigchainDB uses the [Ed25519](https://ed25519.cr.yp.to/) public-key signature system for generating its public/private key pairs (also called verifying/signing keys). Ed25519 is an instance of the [Edwards-curve Digital Signature Algorithm (EdDSA)](https://en.wikipedia.org/wiki/EdDSA). As of April 2016, EdDSA was in ["Internet-Draft" status with the IETF](https://tools.ietf.org/html/draft-irtf-cfrg-eddsa-05) but was [already widely used](https://ianix.com/pub/ed25519-deployment.html). +BigchainDB uses the [Ed25519](https://ed25519.cr.yp.to/) public-key signature +system for generating its public/private key pairs. Ed25519 is an instance of +the [Edwards-curve Digital Signature Algorithm +(EdDSA)](https://en.wikipedia.org/wiki/EdDSA). As of April 2016, EdDSA was in +["Internet-Draft" status with the +IETF](https://tools.ietf.org/html/draft-irtf-cfrg-eddsa-05) but was [already +widely used](https://ianix.com/pub/ed25519-deployment.html). -BigchainDB uses the the [ed25519](https://github.com/warner/python-ed25519) Python package, overloaded by the [cryptoconditions library](https://github.com/bigchaindb/cryptoconditions). +BigchainDB uses the the [ed25519](https://github.com/warner/python-ed25519) +Python package, overloaded by the [cryptoconditions +library](https://github.com/bigchaindb/cryptoconditions). -All keys are represented with the base58 encoding by default. \ No newline at end of file +All keys are represented with the base58 encoding by default. diff --git a/tests/common/test_transaction.py b/tests/common/test_transaction.py index 5f2d58fb..1a59d08b 100644 --- a/tests/common/test_transaction.py +++ b/tests/common/test_transaction.py @@ -553,12 +553,12 @@ def test_sign_with_invalid_parameters(utx, user_priv): def test_validate_tx_simple_create_signature(user_ffill, user_cond, user_priv): from copy import deepcopy - from bigchaindb.common.crypto import SigningKey + from bigchaindb.common.crypto import PrivateKey from bigchaindb.common.transaction import Transaction, Asset tx = Transaction(Transaction.CREATE, Asset(), [user_ffill], [user_cond]) expected = deepcopy(user_cond) - expected.fulfillment.sign(str(tx).encode(), SigningKey(user_priv)) + expected.fulfillment.sign(str(tx).encode(), PrivateKey(user_priv)) tx.sign([user_priv]) assert tx.fulfillments[0].to_dict()['fulfillment'] == \ @@ -611,7 +611,7 @@ def test_validate_fulfillment_with_invalid_parameters(utx): def test_validate_multiple_fulfillments(user_ffill, user_cond, user_priv): from copy import deepcopy - from bigchaindb.common.crypto import SigningKey + from bigchaindb.common.crypto import PrivateKey from bigchaindb.common.transaction import Transaction, Asset tx = Transaction(Transaction.CREATE, Asset(), @@ -627,10 +627,10 @@ def test_validate_multiple_fulfillments(user_ffill, user_cond, user_priv): expected_first_bytes = str(expected_first).encode() expected_first.fulfillments[0].fulfillment.sign(expected_first_bytes, - SigningKey(user_priv)) + PrivateKey(user_priv)) expected_second_bytes = str(expected_second).encode() expected_second.fulfillments[0].fulfillment.sign(expected_second_bytes, - SigningKey(user_priv)) + PrivateKey(user_priv)) tx.sign([user_priv]) assert tx.fulfillments[0].to_dict()['fulfillment'] == \ @@ -648,16 +648,16 @@ def test_validate_tx_threshold_create_signature(user_user2_threshold_ffill, user2_priv): from copy import deepcopy - from bigchaindb.common.crypto import SigningKey + from bigchaindb.common.crypto import PrivateKey from bigchaindb.common.transaction import Transaction, Asset tx = Transaction(Transaction.CREATE, Asset(), [user_user2_threshold_ffill], [user_user2_threshold_cond]) expected = deepcopy(user_user2_threshold_cond) expected.fulfillment.subconditions[0]['body'].sign(str(tx).encode(), - SigningKey(user_priv)) + PrivateKey(user_priv)) expected.fulfillment.subconditions[1]['body'].sign(str(tx).encode(), - SigningKey(user2_priv)) + PrivateKey(user2_priv)) tx.sign([user_priv, user2_priv]) assert tx.fulfillments[0].to_dict()['fulfillment'] == \ @@ -965,7 +965,7 @@ def test_conditions_to_inputs(tx): def test_create_transfer_transaction_single_io(tx, user_pub, user2_pub, user2_cond, user_priv, data_id): from copy import deepcopy - from bigchaindb.common.crypto import SigningKey + from bigchaindb.common.crypto import PrivateKey from bigchaindb.common.transaction import Transaction, Asset from bigchaindb.common.util import serialize @@ -1004,7 +1004,7 @@ def test_create_transfer_transaction_single_io(tx, user_pub, user2_pub, expected['id'] = transfer_tx['id'] expected['transaction']['timestamp'] = transfer_tx_body['timestamp'] expected_input.fulfillment.sign(serialize(expected).encode(), - SigningKey(user_priv)) + PrivateKey(user_priv)) expected_ffill = expected_input.fulfillment.serialize_uri() transfer_ffill = transfer_tx_body['fulfillments'][0]['fulfillment'] diff --git a/tests/conftest.py b/tests/conftest.py index 58178b7f..784d11fc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -25,8 +25,8 @@ CONFIG = { } # Test user. inputs will be created for this user. Cryptography Keys -USER_SIGNING_KEY = '8eJ8q9ZQpReWyQT5aFCiwtZ5wDZC4eDnCen88p3tQ6ie' -USER_VERIFYING_KEY = 'JEAkEJqLbbgDRAtMm8YAjGp759Aq2qTn9eaEHUj2XePE' +USER_PRIVATE_KEY = '8eJ8q9ZQpReWyQT5aFCiwtZ5wDZC4eDnCen88p3tQ6ie' +USER_PUBLIC_KEY = 'JEAkEJqLbbgDRAtMm8YAjGp759Aq2qTn9eaEHUj2XePE' # We need this function to avoid loading an existing @@ -54,12 +54,12 @@ def node_config(): @pytest.fixture def user_sk(): - return USER_SIGNING_KEY + return USER_PRIVATE_KEY @pytest.fixture def user_vk(): - return USER_VERIFYING_KEY + return USER_PUBLIC_KEY @pytest.fixture diff --git a/tests/db/test_bigchain_api.py b/tests/db/test_bigchain_api.py index a6b76eb4..7f08303d 100644 --- a/tests/db/test_bigchain_api.py +++ b/tests/db/test_bigchain_api.py @@ -30,7 +30,7 @@ def dummy_block(): class TestBigchainApi(object): def test_get_last_voted_block_cyclic_blockchain(self, b, monkeypatch): - from bigchaindb.common.crypto import SigningKey + from bigchaindb.common.crypto import PrivateKey from bigchaindb.common.exceptions import CyclicBlockchainError from bigchaindb.common.util import serialize from bigchaindb.models import Transaction @@ -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.encode()) + vote['signature'] = PrivateKey(b.me_private).sign(vote_data.encode()) b.write_vote(vote) with pytest.raises(CyclicBlockchainError): @@ -734,7 +734,7 @@ class TestBlockValidation(object): # skipped block_data = util.serialize_block(block) block_hash = crypto.hash_data(block_data) - block_signature = crypto.SigningKey(b.me_private).sign(block_data) + block_signature = crypto.PrivateKey(b.me_private).sign(block_data) block = { 'id': block_hash, @@ -758,7 +758,7 @@ class TestBlockValidation(object): block = dummy_block() # replace the block signature with an invalid one - block.signature = crypto.SigningKey(b.me_private).sign(b'wrongdata') + block.signature = crypto.PrivateKey(b.me_private).sign(b'wrongdata') # check that validate_block raises an InvalidSignature exception with pytest.raises(InvalidSignature): diff --git a/tests/doc/run_doc_python_server_api_examples.py b/tests/doc/run_doc_python_server_api_examples.py index a7bf89d5..3a2818ae 100644 --- a/tests/doc/run_doc_python_server_api_examples.py +++ b/tests/doc/run_doc_python_server_api_examples.py @@ -229,9 +229,9 @@ threshold_tx_fulfillment_message = util.get_fulfillment_message(threshold_tx_tra threshold_fulfillment.subconditions = [] # sign and add the subconditions until threshold of 2 is reached -subfulfillment1.sign(threshold_tx_fulfillment_message, crypto.SigningKey(thresholduser1_priv)) +subfulfillment1.sign(threshold_tx_fulfillment_message, crypto.PrivateKey(thresholduser1_priv)) threshold_fulfillment.add_subfulfillment(subfulfillment1) -subfulfillment2.sign(threshold_tx_fulfillment_message, crypto.SigningKey(thresholduser2_priv)) +subfulfillment2.sign(threshold_tx_fulfillment_message, crypto.PrivateKey(thresholduser2_priv)) threshold_fulfillment.add_subfulfillment(subfulfillment2) # Add remaining (unfulfilled) fulfillment as a condition @@ -436,7 +436,7 @@ escrow_fulfillment.subconditions = [] # fulfill execute branch fulfillment_execute = cc.ThresholdSha256Fulfillment(threshold=2) -subfulfillment_testuser1.sign(tx_escrow_execute_fulfillment_message, crypto.SigningKey(testuser1_priv)) +subfulfillment_testuser1.sign(tx_escrow_execute_fulfillment_message, crypto.PrivateKey(testuser1_priv)) fulfillment_execute.add_subfulfillment(subfulfillment_testuser1) fulfillment_execute.add_subfulfillment(subfulfillment_timeout) escrow_fulfillment.add_subfulfillment(fulfillment_execute) @@ -476,7 +476,7 @@ escrow_fulfillment.add_subcondition(condition_execute.condition) # Fulfill abort branch fulfillment_abort = cc.ThresholdSha256Fulfillment(threshold=2) -subfulfillment_testuser2.sign(tx_escrow_abort_fulfillment_message, crypto.SigningKey(testuser2_priv)) +subfulfillment_testuser2.sign(tx_escrow_abort_fulfillment_message, crypto.PrivateKey(testuser2_priv)) fulfillment_abort.add_subfulfillment(subfulfillment_testuser2) fulfillment_abort.add_subfulfillment(subfulfillment_timeout_inverted) escrow_fulfillment.add_subfulfillment(fulfillment_abort) diff --git a/tests/pipelines/test_vote.py b/tests/pipelines/test_vote.py index 5bd0eb52..8465bab7 100644 --- a/tests/pipelines/test_vote.py +++ b/tests/pipelines/test_vote.py @@ -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']).encode(), + assert crypto.PublicKey(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']).encode(), + assert crypto.PublicKey(b.me).verify(serialize(vote['vote']).encode(), vote['signature']) is True @@ -177,7 +177,7 @@ def test_valid_block_voting_sequential(b, monkeypatch): serialized_vote = util.serialize(vote_doc['vote']).encode() assert vote_doc['node_pubkey'] == b.me - assert crypto.VerifyingKey(b.me).verify(serialized_vote, + assert crypto.PublicKey(b.me).verify(serialized_vote, vote_doc['signature']) is True @@ -211,7 +211,7 @@ def test_valid_block_voting_multiprocessing(b, monkeypatch): serialized_vote = util.serialize(vote_doc['vote']).encode() assert vote_doc['node_pubkey'] == b.me - assert crypto.VerifyingKey(b.me).verify(serialized_vote, + assert crypto.PublicKey(b.me).verify(serialized_vote, vote_doc['signature']) is True @@ -252,7 +252,7 @@ def test_valid_block_voting_with_create_transaction(b, monkeypatch): serialized_vote = util.serialize(vote_doc['vote']).encode() assert vote_doc['node_pubkey'] == b.me - assert crypto.VerifyingKey(b.me).verify(serialized_vote, + assert crypto.PublicKey(b.me).verify(serialized_vote, vote_doc['signature']) is True @@ -306,7 +306,7 @@ def test_valid_block_voting_with_transfer_transactions(monkeypatch, b): serialized_vote = util.serialize(vote_doc['vote']).encode() assert vote_doc['node_pubkey'] == b.me - assert crypto.VerifyingKey(b.me).verify(serialized_vote, + assert crypto.PublicKey(b.me).verify(serialized_vote, vote_doc['signature']) is True vote2_rs = b.connection.run(r.table('votes').get_all([block2.id, b.me], index='block_and_voter')) @@ -320,7 +320,7 @@ def test_valid_block_voting_with_transfer_transactions(monkeypatch, b): serialized_vote2 = util.serialize(vote2_doc['vote']).encode() assert vote2_doc['node_pubkey'] == b.me - assert crypto.VerifyingKey(b.me).verify(serialized_vote2, + assert crypto.PublicKey(b.me).verify(serialized_vote2, vote2_doc['signature']) is True @@ -357,7 +357,7 @@ def test_unsigned_tx_in_block_voting(monkeypatch, b, user_vk): serialized_vote = util.serialize(vote_doc['vote']).encode() assert vote_doc['node_pubkey'] == b.me - assert crypto.VerifyingKey(b.me).verify(serialized_vote, + assert crypto.PublicKey(b.me).verify(serialized_vote, vote_doc['signature']) is True @@ -396,7 +396,7 @@ def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_vk): serialized_vote = util.serialize(vote_doc['vote']).encode() assert vote_doc['node_pubkey'] == b.me - assert crypto.VerifyingKey(b.me).verify(serialized_vote, + assert crypto.PublicKey(b.me).verify(serialized_vote, vote_doc['signature']) is True @@ -435,7 +435,7 @@ def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_vk): serialized_vote = util.serialize(vote_doc['vote']).encode() assert vote_doc['node_pubkey'] == b.me - assert crypto.VerifyingKey(b.me).verify(serialized_vote, + assert crypto.PublicKey(b.me).verify(serialized_vote, vote_doc['signature']) is True @@ -470,7 +470,7 @@ def test_invalid_block_voting(monkeypatch, b, user_vk): serialized_vote = util.serialize(vote_doc['vote']).encode() assert vote_doc['node_pubkey'] == b.me - assert crypto.VerifyingKey(b.me).verify(serialized_vote, + assert crypto.PublicKey(b.me).verify(serialized_vote, vote_doc['signature']) is True diff --git a/tests/test_models.py b/tests/test_models.py index 5033aebb..afde33fb 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -142,7 +142,7 @@ class TestBlockModel(object): assert Block(transactions) == Block(transactions) def test_sign_block(self, b): - from bigchaindb.common.crypto import SigningKey, VerifyingKey + from bigchaindb.common.crypto import PrivateKey, PublicKey from bigchaindb.common.util import gen_timestamp, serialize from bigchaindb.models import Block, Transaction @@ -156,13 +156,13 @@ class TestBlockModel(object): 'voters': voters, } expected_block_serialized = serialize(expected_block).encode() - expected = SigningKey(b.me_private).sign(expected_block_serialized) + expected = PrivateKey(b.me_private).sign(expected_block_serialized) block = Block(transactions, b.me, timestamp, voters) block = block.sign(b.me_private) assert block.signature == expected.decode() - verifying_key = VerifyingKey(b.me) - assert verifying_key.verify(expected_block_serialized, block.signature) + public_key = PublicKey(b.me) + assert public_key.verify(expected_block_serialized, block.signature) def test_validate_already_voted_on_block(self, b, monkeypatch): from unittest.mock import Mock