Ejemplo n.º 1
0
def btc_base58_check(match: regex.Match):
    text = match.groupdict().get('valu')
    try:
        base58.b58decode_check(text)
    except ValueError:
        return None, {}
    return ('btc', text), {}
Ejemplo n.º 2
0
def cardano_shelly_check(match: regex.Match):
    text = match.groupdict().get('valu')
    # Bech32 decoding
    ret = bech32.bech32_decode(text)
    if ret == (None, None):
        return None, {}
    return ('ada', text), {}
Ejemplo n.º 3
0
def fqdn_prefix_check(match: regex.Match):
    mnfo = match.groupdict()
    valu = mnfo.get('valu')
    prefix = mnfo.get('prefix')
    cbfo = {}
    if prefix is not None:
        new_valu = valu.rstrip(inverse_prefixs.get(prefix))
        if new_valu != valu:
            valu = new_valu
            cbfo['match'] = valu
    return valu, cbfo
Ejemplo n.º 4
0
def bch_check(match: regex.Match):
    text = match.groupdict().get('valu')
    # Checksum if we're mixed case or not
    prefix, body = text.split(':', 1)
    if not body.isupper() and not body.islower():
        return None, {}
    try:
        cashaddr_convert.Address._cash_string(text)
    except:
        return None, {}
    text = text.lower()
    return ('bch', text), {}
Ejemplo n.º 5
0
def eth_check(match: regex.Match):
    text = match.groupdict().get('valu')
    prefix, body = text.split('x')  # type: str, str
    # Checksum if we're mixed case or not
    if not body.isupper() and not body.islower():

        ret = ether_eip55(body)
        if ret is None or ret != text:
            return None, {}

        return ('eth', text), {}
    # any valid 0x<40 character> hex string is possibly a ETH address.
    return ('eth', text.lower()), {}
Ejemplo n.º 6
0
def cardano_byron_check(match: regex.Match):
    text = match.groupdict().get('valu')
    # Try a base58 / cbor decoding
    try:
        decoded_text = base58.b58decode(text)
        message = cbor2.loads(decoded_text)
        if len(message) != 2:
            return None, {}
        csum = message[1]
        computed_checksum = binascii.crc32(message[0].value)
        if csum == computed_checksum:
            return ('ada', text), {}
    except (ValueError, cbor2.CBORError):
        pass
    return None, {}
Ejemplo n.º 7
0
def substrate_check(match: regex.Match):
    text = match.groupdict().get('valu')
    prefix = text[0]  # str
    if prefix == '1' and substrate_ss58.is_valid_ss58_address(
            text, valid_ss58_format=0):
        # polkadot
        return ('dot', text), {}
    elif prefix.isupper() and substrate_ss58.is_valid_ss58_address(
            text, valid_ss58_format=2):
        # kusuma
        return ('ksm', text), {}
    else:
        # Do nothing with generic substrate matches
        # Generic substrate addresses are checked with valid_ss58_format=42
        return None, {}
Ejemplo n.º 8
0
def fqdn_check(match: regex.Match):
    mnfo = match.groupdict()
    valu = mnfo.get('valu')

    nval = unicodedata.normalize('NFKC', valu)
    nval = regex.sub(udots, '.', nval)
    nval = nval.strip().strip('.')

    try:
        idna.encode(nval, uts46=True).decode('utf8')
    except idna.IDNAError:
        try:
            nval.encode('idna').decode('utf8').lower()
        except UnicodeError:
            return None, {}
    return valu, {}
Ejemplo n.º 9
0
def btc_bech32_check(match: regex.Match):
    text = match.groupdict().get('valu')
    prefix, _ = text.split('1', 1)
    prefix = prefix.lower()
    if prefix == 'bc':
        bitcoin.SelectParams('mainnet')
    elif prefix == 'tb':
        bitcoin.SelectParams('testnet')
    elif prefix == 'bcrt':
        bitcoin.SelectParams('regtest')
    else:  # pragma: no cover
        raise ValueError(f'Unknown prefix {text}')
    try:
        _ = bitcoin_b32.CBech32Data(text)
    except bitcoin_b32.Bech32Error:
        return None, {}
    # The proper form of a bech32 address is lowercased. We do not want to verify
    # a mixed case form, so lowercase it prior to returning.
    return ('btc', text.lower()), {}
Ejemplo n.º 10
0
def xrp_check(match: regex.Match):
    text = match.groupdict().get('valu')
    if xrp_addresscodec.is_valid_classic_address(
            text) or xrp_addresscodec.is_valid_xaddress(text):
        return ('xrp', text), {}
    return None, {}