Пример #1
0
def fulfill_threshold_signature_fulfillment(fulfillment, parsed_fulfillment, fulfillment_message, key_pairs):
    """Fulfill a cryptoconditions.ThresholdSha256Fulfillment

        Args:
            fulfillment (dict): BigchainDB fulfillment to fulfill.
            parsed_fulfillment (cryptoconditions.ThresholdSha256Fulfillment): cryptoconditions.ThresholdSha256Fulfillment instance.
            fulfillment_message (dict): message to sign.
            key_pairs (dict): dictionary of (public_key, private_key) pairs.

        Returns:
            object: fulfilled cryptoconditions.ThresholdSha256Fulfillment

        """
    parsed_fulfillment_copy = copy.deepcopy(parsed_fulfillment)
    parsed_fulfillment.subconditions = []

    for current_owner in fulfillment['current_owners']:
        try:
            subfulfillment = parsed_fulfillment_copy.get_subcondition_from_vk(current_owner)[0]
        except IndexError:
            exceptions.KeypairMismatchException('Public key {} cannot be found in the fulfillment'
                                                .format(current_owner))
        try:
            subfulfillment.sign(serialize(fulfillment_message), key_pairs[current_owner])
        except KeyError:
            raise exceptions.KeypairMismatchException('Public key {} is not a pair to any of the private keys'
                                                      .format(current_owner))
        parsed_fulfillment.add_subfulfillment(subfulfillment)

    return parsed_fulfillment
Пример #2
0
def fulfill_simple_signature_fulfillment(fulfillment, parsed_fulfillment,
                                         fulfillment_message, key_pairs):
    """Fulfill a cryptoconditions.Ed25519Fulfillment

        Args:
            fulfillment (dict): BigchainDB fulfillment to fulfill.
            parsed_fulfillment (cryptoconditions.Ed25519Fulfillment): cryptoconditions.Ed25519Fulfillment instance.
            fulfillment_message (dict): message to sign.
            key_pairs (dict): dictionary of (public_key, private_key) pairs.

        Returns:
            object: fulfilled cryptoconditions.Ed25519Fulfillment

        """
    current_owner = fulfillment['current_owners'][0]

    try:
        parsed_fulfillment.sign(serialize(fulfillment_message),
                                key_pairs[current_owner])
    except KeyError:
        raise exceptions.KeypairMismatchException(
            'Public key {} is not a pair to any of the private keys'.format(
                current_owner))

    return parsed_fulfillment