mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-06-23 01:36:42 +02:00
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
This commit is contained in:
parent
c65d2779c9
commit
c068f04a82
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -10,8 +10,8 @@ A block has the following structure:
|
|||
"block": {
|
||||
"timestamp": "<block-creation timestamp>",
|
||||
"transactions": ["<list of transactions>"],
|
||||
"node_pubkey": "<public/verifying key of the node creating the block>",
|
||||
"voters": ["<list of federation nodes verifying keys>"]
|
||||
"node_pubkey": "<public key of the node creating the block>",
|
||||
"voters": ["<list of federation nodes public keys>"]
|
||||
},
|
||||
"signature": "<signature of block>"
|
||||
}
|
||||
|
@ -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 <https://docs.bigchaindb.com/en/latest/timestamps.html>`_.
|
||||
- ``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
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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.
|
||||
All keys are represented with the base58 encoding by default.
|
||||
|
|
|
@ -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']
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user