Example #1
0
def sign_ed25519(transaction, private_keys):
    from cryptoconditions import Ed25519Sha256
    from cryptoconditions.crypto import Ed25519VerifyingKey

    for index, _input in enumerate(transaction.inputs):
        receiver = _input.owners_before[0]
        transaction.inputs[index].fulfillment = Ed25519Sha256(
            public_key=Ed25519VerifyingKey(receiver).encode('bytes'))

    private_keys = [private_keys
                    ] if not isinstance(private_keys, list) else private_keys
    return transaction.sign(private_keys).to_dict()
Example #2
0
def prepare_transfer_ed25519_simple(transaction, receiver, metadata=None):
    from cryptoconditions import Ed25519Fulfillment
    from cryptoconditions.crypto import Ed25519VerifyingKey

    return prepare_transfer(
        inputs=[{
            'tx': transaction,
            'output': 0
        }],
        outputs=[{
            'condition':
            Ed25519Fulfillment(public_key=Ed25519VerifyingKey(receiver)),
            'public_keys': [receiver],
            'amount':
            1
        }],
        metadata=metadata)
# instead of transfering to a simple public key we can craft
# custom cryptoconditions using thresholds, signatures, hashlocks, ...
# this example is a multisig between
#
#             bob     secret/hashlock
#      carly     \   /
#           \     and
#            \   /
#             and
#              |
#              o
#
#  the cryptocondition is added as an output
condition = ThresholdSha256Fulfillment(threshold=2)
condition.add_subfulfillment(
    Ed25519Fulfillment(public_key=Ed25519VerifyingKey(carly.public_key)))
subfulfillment = ThresholdSha256Fulfillment(threshold=2)
subfulfillment.add_subcondition(
    PreimageSha256Fulfillment(preimage=b'secret').condition)
subfulfillment.add_subfulfillment(
    Ed25519Fulfillment(public_key=Ed25519VerifyingKey(bob.public_key)))
condition.add_subfulfillment(subfulfillment)

# create the transfer transaction with the custom condition
tx_transfer_custom_condition = prepare_transfer(
    inputs=[{
        'tx': tx_create_alice_divisible_signed,
        'output': 0
    }],
    outputs=[
        {