コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
def sign_message(**data):
    if not all(key in data for key in ['address', 'message']):
        return {
            'success':
            False,
            'error':
            'Request data does not contain all required keys: address, message'
        }

    address = data['address']
    message = data['message']

    if not valid_address(address=address):
        return {'success': False, 'error': 'Invalid address: %s' % address}

    if len(message) > 255:
        return {
            'success': False,
            'error':
            'Message is too long, can not be longer than 255 characters.'
        }

    account, index = find_address_in_wallet(address=address)
    if account is None or index is None:
        private_key = find_single_address_in_wallet(address=address)

        if private_key is None:
            return {
                'success': False,
                'error': 'Address %s not found in hot wallet' % address
            }
    else:
        private_key = get_private_key_from_wallet(account=account,
                                                  index=index)[address]

    try:
        signature = sign_and_verify(private_key=private_key,
                                    address=address,
                                    message=message)
    except Exception as ex:
        return {'success': False, 'error': 'Unable to sign message: %s' % ex}

    return {
        'success': True,
        'signature': signature,
        'address': address,
        'message': message
    }
コード例 #4
0
# Check if address is valid
if not valid_address(args.address):
    print('Invalid address: %s' % args.address)
    sys.exit(1)

data = {'address': args.address}

# Find the private key of the address in the hot wallet
account, index = find_address_in_wallet(
    address=data['address'], accounts=100
)  # Todo find better way to specify number of accounts to search
if account is None or index is None:
    print('Can not find address in wallet!')
    sys.exit(1)
else:
    private_key = get_private_key_from_wallet(account=account,
                                              index=index)[data['address']]

# If the message argument is the name of an existing file, then the real message is the contents of that file
if os.path.isfile(args.message):
    with open(args.message, 'r') as input_file:
        data['message'] = input_file.read()
else:
    data['message'] = args.message

# The Bitcoin Signed Message can not be longer than 256 characters, if it is longer, put the message on IPFS and sign the hash instead
if len(data['message']) >= 256:
    # # Check if IPFS node is running
    # try:
    #     ipfs = ipfsapi.connect(get_ipfs_api_host(), get_ipfs_api_port())
    # except Exception as ex:
    #     print('IPFS node is not running: %s' % ex)
コード例 #5
0
assert response is None

response = spellbook_call('get_trigger_config', trigger_name)
assert response['trigger_type'] == trigger_type
assert response['triggered'] == 0
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