コード例 #1
0
 def get_monitor_request(self, partner_address: Address,
                         balance_proof: BalanceProof, reward_amount: int,
                         monitor_address: Address) -> MonitorRequest:
     """Get monitor request message for a given balance proof."""
     monitor_request = MonitorRequest(balance_proof,
                                      reward_proof_signature=None,
                                      reward_amount=reward_amount,
                                      monitor_address=monitor_address)
     monitor_request.reward_proof_signature = encode_hex(
         sign_data(self.privkey, monitor_request.serialize_reward_proof()))
     non_closing_data = balance_proof.serialize_bin() + decode_hex(
         balance_proof.signature)
     monitor_request.non_closing_signature = encode_hex(
         sign_data(self.privkey, non_closing_data))
     return monitor_request
コード例 #2
0
    def f():
        balance_proof = get_random_bp()
        privkey = get_random_privkey()
        privkey_non_closing = get_random_privkey()
        balance_proof.signature = encode_hex(
            sign_data(privkey, balance_proof.serialize_bin()))
        non_closing_signature = encode_hex(
            sign_data(privkey_non_closing, balance_proof.serialize_bin()))

        monitor_request = MonitorRequest(balance_proof,
                                         non_closing_signature,
                                         reward_amount=random.randint(
                                             0, UINT192_MAX),
                                         monitor_address=get_random_address())
        monitor_request.reward_proof_signature = encode_hex(
            sign_data(privkey, monitor_request.serialize_reward_proof()))
        return monitor_request
コード例 #3
0
 def f():
     bp = get_random_bp()
     privkey = get_random_privkey()
     bp.signature = encode_hex(sign_data(privkey, bp.serialize_bin()))
     mr = MonitorRequest(
         bp.channel_id,
         bp.nonce,
         bp.transferred_amount,
         bp.locksroot,
         bp.extra_hash,
         bp.signature,
         reward_sender_address=get_random_address(),
         reward_amount=random.randint(0, UINT192_MAX),
         token_network_address=get_random_address(),
         chain_id=random.randint(0, UINT256_MAX),
         monitor_address=get_random_address()
     )
     mr.reward_proof_signature = encode_hex(sign_data(privkey, mr.serialize_reward_proof()))
     return mr
コード例 #4
0
ファイル: test_messages.py プロジェクト: mat7ias/raiden-libs
def test_monitor_request(get_random_bp, get_random_privkey,
                         get_random_address):
    balance_proof = get_random_bp()
    client_privkey = get_random_privkey()
    reward_sender_privkey = get_random_privkey()
    balance_proof.signature = encode_hex(
        sign_data(client_privkey, balance_proof.serialize_bin()))
    monitor_request = MonitorRequest(
        balance_proof,
        non_closing_signature=balance_proof.signature,
        reward_proof_signature='',
        reward_amount=1,
        monitor_address=get_random_address(),
    )
    monitor_request.reward_proof_signature = encode_hex(
        sign_data(
            reward_sender_privkey,
            monitor_request.serialize_reward_proof(),
        ), )

    serialized = monitor_request.serialize_data()
    monitor_request_verify = MonitorRequest.deserialize(serialized)
    balance_proof_verify = monitor_request_verify.balance_proof
    assert is_same_address(monitor_request_verify.monitor_address,
                           monitor_request.monitor_address)
    assert is_same_address(
        monitor_request_verify.reward_proof_signer,
        monitor_request.reward_proof_signer,
    )
    assert is_same_address(
        monitor_request.reward_proof_signer,
        private_key_to_address(reward_sender_privkey),
    )
    assert monitor_request_verify.non_closing_signature == monitor_request.non_closing_signature
    assert monitor_request_verify.reward_amount == monitor_request.reward_amount
    assert is_same_address(
        balance_proof_verify.token_network_address,
        balance_proof.token_network_address,
    )
    assert balance_proof_verify.chain_id == balance_proof.chain_id
    assert balance_proof_verify.channel_identifier == balance_proof.channel_identifier
    assert balance_proof_verify.nonce == balance_proof.nonce
コード例 #5
0
    def f(
        user=None,
        reward_amount=0,
        bad_key_for_bp=False,
        bad_key_for_non_closing=False,
    ):
        if user == 0:
            privkey = keys[0]
            privkey_non_closing = keys[1]
        else:
            privkey = keys[1]
            privkey_non_closing = keys[0]
        balance_proof = BalanceProof(
            channel_id,
            token_network_address,
            balance_hash=encode_hex(sha3(balance_hash_data.encode())),
        )
        balance_proof.signature = encode_hex(
            eth_sign(
                privkey if not bad_key_for_bp else keys[2],
                balance_proof.serialize_bin(),
            ))
        non_closing_signature = encode_hex(
            eth_sign(
                privkey_non_closing
                if not bad_key_for_non_closing else keys[2],
                balance_proof.serialize_bin(
                    msg_type=MessageTypeId.BALANCE_PROOF_UPDATE) +
                decode_hex(balance_proof.signature),
            ))

        monitor_request = MonitorRequest(
            balance_proof,
            non_closing_signature,
            reward_amount=reward_amount,
            monitor_address=get_random_address(),
        )
        monitor_request.reward_proof_signature = encode_hex(
            eth_sign(privkey, monitor_request.serialize_reward_proof()), )
        return monitor_request