mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Merge pull request #1294 from bigchaindb/bug/1291/threshold-conditions-duplicated-pks
_sign_threshold now signs all subconditions for a public key
This commit is contained in:
commit
e97cee8c84
@ -768,8 +768,7 @@ class Transaction(object):
|
|||||||
key_pairs (dict): The keys to sign the Transaction with.
|
key_pairs (dict): The keys to sign the Transaction with.
|
||||||
"""
|
"""
|
||||||
input_ = deepcopy(input_)
|
input_ = deepcopy(input_)
|
||||||
for owner_before in input_.owners_before:
|
for owner_before in set(input_.owners_before):
|
||||||
try:
|
|
||||||
# TODO: CC should throw a KeypairMismatchException, instead of
|
# TODO: CC should throw a KeypairMismatchException, instead of
|
||||||
# our manual mapping here
|
# our manual mapping here
|
||||||
|
|
||||||
@ -780,8 +779,8 @@ class Transaction(object):
|
|||||||
# TODO FOR CC: `get_subcondition` is singular. One would not
|
# TODO FOR CC: `get_subcondition` is singular. One would not
|
||||||
# expect to get a list back.
|
# expect to get a list back.
|
||||||
ccffill = input_.fulfillment
|
ccffill = input_.fulfillment
|
||||||
subffill = ccffill.get_subcondition_from_vk(owner_before)[0]
|
subffills = ccffill.get_subcondition_from_vk(owner_before)
|
||||||
except IndexError:
|
if not subffills:
|
||||||
raise KeypairMismatchException('Public key {} cannot be found '
|
raise KeypairMismatchException('Public key {} cannot be found '
|
||||||
'in the fulfillment'
|
'in the fulfillment'
|
||||||
.format(owner_before))
|
.format(owner_before))
|
||||||
@ -794,6 +793,7 @@ class Transaction(object):
|
|||||||
|
|
||||||
# cryptoconditions makes no assumptions of the encoding of the
|
# cryptoconditions makes no assumptions of the encoding of the
|
||||||
# message to sign or verify. It only accepts bytestrings
|
# message to sign or verify. It only accepts bytestrings
|
||||||
|
for subffill in subffills:
|
||||||
subffill.sign(tx_serialized.encode(), private_key)
|
subffill.sign(tx_serialized.encode(), private_key)
|
||||||
self.inputs[index] = input_
|
self.inputs[index] = input_
|
||||||
|
|
||||||
|
@ -590,6 +590,42 @@ def test_validate_tx_threshold_create_signature(user_user2_threshold_input,
|
|||||||
validate_transaction_model(tx)
|
validate_transaction_model(tx)
|
||||||
|
|
||||||
|
|
||||||
|
def test_validate_tx_threshold_duplicated_pk(user_pub, user_priv,
|
||||||
|
asset_definition):
|
||||||
|
from copy import deepcopy
|
||||||
|
from cryptoconditions import Ed25519Fulfillment, ThresholdSha256Fulfillment
|
||||||
|
from bigchaindb.common.transaction import Input, Output, Transaction
|
||||||
|
from bigchaindb.common.crypto import PrivateKey
|
||||||
|
|
||||||
|
threshold = ThresholdSha256Fulfillment(threshold=2)
|
||||||
|
threshold.add_subfulfillment(Ed25519Fulfillment(public_key=user_pub))
|
||||||
|
threshold.add_subfulfillment(Ed25519Fulfillment(public_key=user_pub))
|
||||||
|
|
||||||
|
threshold_input = Input(threshold, [user_pub, user_pub])
|
||||||
|
threshold_output = Output(threshold, [user_pub, user_pub])
|
||||||
|
|
||||||
|
tx = Transaction(Transaction.CREATE, asset_definition,
|
||||||
|
[threshold_input], [threshold_output])
|
||||||
|
expected = deepcopy(threshold_input)
|
||||||
|
expected.fulfillment.subconditions[0]['body'].sign(str(tx).encode(),
|
||||||
|
PrivateKey(user_priv))
|
||||||
|
expected.fulfillment.subconditions[1]['body'].sign(str(tx).encode(),
|
||||||
|
PrivateKey(user_priv))
|
||||||
|
|
||||||
|
tx.sign([user_priv, user_priv])
|
||||||
|
|
||||||
|
subconditions = tx.inputs[0].fulfillment.subconditions
|
||||||
|
expected_subconditions = expected.fulfillment.subconditions
|
||||||
|
assert subconditions[0]['body'].to_dict()['signature'] == \
|
||||||
|
expected_subconditions[0]['body'].to_dict()['signature']
|
||||||
|
assert subconditions[1]['body'].to_dict()['signature'] == \
|
||||||
|
expected_subconditions[1]['body'].to_dict()['signature']
|
||||||
|
|
||||||
|
assert tx.inputs[0].to_dict()['fulfillment'] == \
|
||||||
|
expected.fulfillment.serialize_uri()
|
||||||
|
assert tx.inputs_valid() is True
|
||||||
|
|
||||||
|
|
||||||
def test_multiple_input_validation_of_transfer_tx(user_input, user_output,
|
def test_multiple_input_validation_of_transfer_tx(user_input, user_output,
|
||||||
user_priv, user2_pub,
|
user_priv, user2_pub,
|
||||||
user2_priv, user3_pub,
|
user2_priv, user3_pub,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user