How to use the blockcypher.utils.uses_only_hash_chars function in blockcypher

To help you get started, we’ve selected a few blockcypher examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blockcypher / blockcypher-python / test_blockcypher.py View on Github external
def test_generate_single_addr(self):
        for coin_symbol in ('btc', 'btc-testnet', 'doge', 'dash', 'ltc', 'bcy'):
            response_dict = generate_new_address(
                    coin_symbol=coin_symbol,
                    api_key=BC_API_KEY,
                    )
            assert is_valid_address(response_dict['address']), response_dict
            assert uses_only_hash_chars(response_dict['private']), response_dict
            assert uses_only_hash_chars(response_dict['public']), response_dict
            assert 'wif' in response_dict, response_dict
github blockcypher / bcwallet / bcwallet / bcwallet.py View on Github external
if sys.stdin.isatty():
        wallet = args.wallet
        verbose_print('Wallet imported from args')
    else:
        wallet = sys.stdin.readline().strip()
        sys.stdin = open('/dev/tty')
        verbose_print('Wallet imported from pipe')
    verbose_print('wallet %s' % wallet)

    if args.bc_api_key:
        global BLOCKCYPHER_API_KEY
        BLOCKCYPHER_API_KEY = args.bc_api_key
        verbose_print('API Key: %s' % BLOCKCYPHER_API_KEY)
        # Crude check
        if not uses_only_hash_chars(BLOCKCYPHER_API_KEY):
            puts(colored.red('Invalid API Key: %s\n' % BLOCKCYPHER_API_KEY))
            sys.exit()

    puts("\nWelcome to bcwallet!")

    puts("\nHere's what makes bcwallet unique:")
    with indent(2):
        for bullet_point, description in EXPLAINER_COPY:
            puts('-%s: %s' % (bullet_point, description))
    puts()

    if wallet:
        network = guess_network_from_mkey(wallet)
        if network:
            # check if valid mkey
            try:
github blockcypher / bcwallet / bcwallet / bcwallet.py View on Github external
if sys.stdin.isatty():
        wallet = args.wallet
        verbose_print('Wallet imported from args')
    else:
        wallet = sys.stdin.readline().strip()
        sys.stdin = open('/dev/tty')
        verbose_print('Wallet imported from pipe')
    verbose_print('wallet %s' % wallet)

    if args.bc_api_key:
        global BLOCKCYPHER_API_KEY
        BLOCKCYPHER_API_KEY = args.bc_api_key
        verbose_print('API Key: %s' % BLOCKCYPHER_API_KEY)
        # Crude check
        if not uses_only_hash_chars(BLOCKCYPHER_API_KEY):
            puts(colored.red('Invalid API Key: %s\n' % BLOCKCYPHER_API_KEY))
            sys.exit()

    puts("\nWelcome to bcwallet!")

    puts("\nHere's what makes bcwallet unique:")
    with indent(2):
        for bullet_point, description in EXPLAINER_COPY:
            puts('-%s: %s' % (bullet_point, description))
    puts()

    if wallet:
        network = guess_network_from_mkey(wallet)
        if network:
            # check if valid mkey
            try:
github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
inputs_cleaned = []
    for input_obj in inputs:
        # `input` is a reserved word
        if 'address' in input_obj:
            address = input_obj['address']
            assert is_valid_address_for_coinsymbol(
                    b58_address=address,
                    coin_symbol=coin_symbol,
                    ), address
            inputs_cleaned.append({
                'addresses': [address, ],
                })
        elif 'pubkeys' in input_obj and input_obj.get('script_type', '').startswith('multisig-'):
            for pubkey in input_obj['pubkeys']:
                # TODO: better pubkey test
                assert uses_only_hash_chars(pubkey), pubkey
            inputs_cleaned.append({
                'addresses': input_obj['pubkeys'],
                'script_type': input_obj['script_type'],
                })
        elif 'wallet_name' in input_obj and 'wallet_token' in input_obj:
            # good behavior
            inputs_cleaned.append(input_obj)
        else:
            raise Exception('Invalid Input: %s' % input_obj)

    outputs_cleaned = []
    sweep_funds = False
    for output in outputs:
        clean_output = {}
        assert 'value' in output, output
        assert isinstance(output['value'], int), output['value']
github blockcypher / blockcypher-python / blockcypher / api.py View on Github external
def generate_multisig_address(pubkey_list, script_type='multisig-2-of-3', coin_symbol='btc', api_key=None):

    assert api_key, 'api_key required'

    for pubkey in pubkey_list:
        assert uses_only_hash_chars(pubkey), pubkey

    err_msg = '%s incompatible with %s' % (script_type, pubkey_list)
    assert(len(pubkey_list) == int(script_type[-1])), err_msg

    url = make_url(coin_symbol, 'addrs')
    params = {'token': api_key}
    data = {
        'pubkeys': pubkey_list,
        'script_type': script_type,
            }

    r = requests.post(url, json=data, params=params, verify=True, timeout=TIMEOUT_IN_SECONDS)
    return get_valid_json(r)
github blockcypher / explorer / transactions / forms.py View on Github external
def clean(self):
        encoding_is_hex = self.cleaned_data.get('encoding_is_hex')
        data_to_embed = self.cleaned_data.get('data_to_embed')

        if not data_to_embed:
            return self.cleaned_data

        if encoding_is_hex:
            if not uses_only_hash_chars(data_to_embed):
                msg = _('Sorry, that string contains non-hex characters. Uncheck "Data is Hexadecimal" to instead embed the data as a string.')
                raise forms.ValidationError(msg)

        return self.cleaned_data