def test_sign_message_with_a_message_of_256_chars(self): address = get_address_from_wallet(account=0, index=0) message = ''.join(['a' for _ in range(255)]) private_key = get_private_key_from_wallet(account=0, index=0)[address] signature = sign_message(message, private_key) print('Signature:', signature) assert verify_message(address=address, message=message, signature=signature)
def test_verify_message_with_testnet_address(self): if get_use_testnet() is False: print('Change configuration to use testnet to test this!!') return address = 'n2xqSGhqeQqiC6rp34NmPF8xmjQrcxLc6K' message = 'This is a test message for verification of n2xq' signature = 'H4NTp6Z3RWVndpmapw3sJ/CZd0jDS0evgQxasAN+hn3KGhoMLNvzs1Ms3nvPAqdf04XG3O6A4QmmIi70y14Lh18=' assert verify_message(address=address, message=message, signature=signature)
def test_sign_message_with_addresses_from_hot_wallet(self, index): account = 0 address = get_address_from_wallet(account=account, index=index) private_key = get_private_key_from_wallet(account=account, index=index)[address] message = 'This is a test message' print('Address:', address) print('Message:', message) signature = sign_message(message, private_key) print('Signature:', signature) assert verify_message(address=address, message=message, signature=signature)
def test_sign_message_with_uncompressed_address(self): address = '1HUBHMij46Hae75JPdWjeZ5Q7KaL7EFRSD' private_key = '5KMWWy2d3Mjc8LojNoj8Lcz9B1aWu8bRofUgGwQk959Dw5h2iyw' message = 'test message' print('Address:', address) print('Message:', message) # signature keeps changing, sign_input_message both signs and verifies signature = sign_message(message, private_key) print('Signature:', signature) assert verify_message(address=address, message=message, signature=signature)
def test_sign_message_with_compressed_address(self): address = '14dD6ygPi5WXdwwBTt1FBZK3aD8uDem1FY' private_key = 'L41XHGJA5QX43QRG3FEwPbqD5BYvy6WxUxqAMM9oQdHJ5FcRHcGk' message = 'test message' print('Address:', address) print('Message:', message) # signature keeps changing, sign_input_message both signs and verifies signature = sign_message(message, private_key) print('Signature:', signature) assert verify_message(address=address, message=message, signature=signature)
def verify_signed_message(trigger_id, **data): if not all(key in data for key in ['address', 'message', 'signature']): return { 'error': 'Request data does not contain all required keys: address, message and signature' } triggers = get_triggers() if trigger_id not in triggers: return {'error': 'Unknown trigger id: %s' % trigger_id} trigger = get_trigger(trigger_id) if trigger.trigger_type != TriggerType.SIGNEDMESSAGE: return { 'error': 'Trigger %s is not a Signedmessage trigger' % trigger.trigger_type } if trigger.address is not None and trigger.address != data['address']: return { 'error': 'Trigger %s only listens to signed messages from address %s' % (trigger.id, trigger.address) } if verify_message(address=data['address'], message=data['message'], signature=data['signature']) is True: if trigger.status == 'Active': LOG.info('Trigger %s received a verified signed message' % trigger_id) trigger.process_message( address=data['address'], message=data['message'], signature=data['signature'], data=data['data'] if 'data' in data else None, ipfs_object=data['ipfs_object'] if 'ipfs_object' in data else None) return trigger.activate() else: LOG.warning('Trigger %s received a bad signed message' % trigger_id) LOG.warning('message: %s' % data['message']) LOG.warning('address: %s' % data['address']) LOG.warning('signature: %s' % data['signature']) return {'error': 'Signature is invalid!'}
assert response['multi'] is False print('Checking SignedMessage trigger, should not activate') response = spellbook_call('check_triggers', trigger_name) assert response is None account = 0 index = 0 address = get_address_from_wallet(account=account, index=index) private_key = get_private_key_from_wallet(account=account, index=index)[address] message = 'test message' signature = sign_message(message=message, private_key=private_key) assert verify_message(address=address, message=message, signature=signature) print('%s %s' % (signature, len(signature))) print('Sending a signed message') response = spellbook_call('send_signed_message', trigger_name, address, message, signature) assert response is None response = spellbook_call('get_trigger_config', trigger_name) assert response['trigger_type'] == trigger_type assert response['triggered'] > 0 print('Sending a signed message again') response = spellbook_call('send_signed_message', trigger_name, address, message, signature)
def test_verify_message_with_wrong_signature(self): address = '14dD6ygPi5WXdwwBTt1FBZK3aD8uDem1FY' message = 'test message' signature = 'G0k+Nt1u5boTTUfLyj6x1T5flg1v9rUKGlhs/jPApaTWLHf3GVdAIOIHip6sVwXEuzQGPWIlS0VT+yryXiDaavw=' assert not verify_message(address=address, message=message, signature=signature)
def test_verify_message_with_wrong_message(self): address = '14dD6ygPi5WXdwwBTt1FBZK3aD8uDem1FY' message = 'wrong message' signature = 'IPn9bbEdNUp6+bneZqE2YJbq9Hv5aNILq9E5eZoMSF3/fBX4zjeIN6fpXfGSGPrZyKfHQ/c/kTSP+NIwmyTzMfk=' assert not verify_message(address=address, message=message, signature=signature)
def test_verify_message_with_address_and_sig_found_on_bitcointalk(self): address = '1BzFQocxr7QABTpwGz6o9Dsb6tPpBqbWZ8' message = 'This is harizen from bitcointalk.org. Today is February 1,2016.' signature = 'HyEuQEIIi5KS0dqyCaIWh6a5A3wIMFqkSEehuNa7jOUZTSyLa08czuASi5RUcj78hPI5PMNec0w6XhzflMbFNcM=' assert verify_message(address=address, message=message, signature=signature)
def test_verify_message_with_uncompressed_address_with_calculated_signature(self): address = '1HUBHMij46Hae75JPdWjeZ5Q7KaL7EFRSD' message = 'test message' signature = 'HKhuLiH76s+z1CXhbvXxYyBNp/NNfGdivPku6RVvc22fV2rRxNcuKN+8H4fjvl7JR1fq4mw6GY8ayVpz/QGNxcE=' assert verify_message(address=address, message=message, signature=signature)
def test_verify_message_with_uncompressed_address_with_given_signature(self): address = '1HUBHMij46Hae75JPdWjeZ5Q7KaL7EFRSD' message = 'test message' signature = 'G0k+Nt1u5boTTUfLyj6x1T5flg1v9rUKGlhs/jPApaTWLHf3GVdAIOIHip6sVwXEuzQGPWIlS0VT+yryXiDaavw=' assert verify_message(address=address, message=message, signature=signature)
def test_verify_message_with_compressed_address_with_another_calculated_signature(self): address = '14dD6ygPi5WXdwwBTt1FBZK3aD8uDem1FY' message = 'test message' signature = 'IHQfwue444Q4QaavxMKYsYv5kSTprtmoIf7g7eXuVNULbHBPSdjQ48mC/d05NZsjJO9Tpl+dWYqzmdbEpcKOvoQ=' assert verify_message(address=address, message=message, signature=signature)
def test_verify_message_with_compressed_address_with_calculated_signature(self): address = '14dD6ygPi5WXdwwBTt1FBZK3aD8uDem1FY' message = 'test message' signature = 'ILiJ/1XP+t+RzA5P9opUjcS1Qu2FQ+YS2bATMes/BEphEmLfEXT3aOTrHateB68tUNvUFy3Nx/53tIOD74jCpy4=' assert verify_message(address=address, message=message, signature=signature)
def test_verify_message_with_wrong_address(self): address = '1HUBHMij46Hae75JPdWjeZ5Q7KaL7EFRSD' message = 'test message' signature = 'IPn9bbEdNUp6+bneZqE2YJbq9Hv5aNILq9E5eZoMSF3/fBX4zjeIN6fpXfGSGPrZyKfHQ/c/kTSP+NIwmyTzMfk=' assert not verify_message(address=address, message=message, signature=signature)