OXIESEC PANEL
- Current Dir:
/
/
opt
/
alt
/
python311
/
lib
/
python3.11
/
site-packages
/
validators
Server IP: 2a02:4780:11:1594:0:ef5:22d7:a
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
01/09/2025 02:18:04 AM
rwxr-xr-x
📄
__init__.py
1.86 KB
05/14/2024 03:18:23 PM
rw-r--r--
📁
__pycache__
-
05/14/2024 03:18:23 PM
rwxr-xr-x
📄
_extremes.py
1.01 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
_tld.txt
9.4 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
between.py
2.39 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
btc_address.py
1.62 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
card.py
5.63 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
country.py
14.57 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
cron.py
2.23 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
domain.py
2.4 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
email.py
2.72 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
encoding.py
1.34 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
finance.py
3.22 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
hashes.py
3.21 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
hostname.py
4.05 KB
05/14/2024 03:18:23 PM
rw-r--r--
📁
i18n
-
05/14/2024 03:18:23 PM
rwxr-xr-x
📄
iban.py
1.05 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
ip_address.py
4.34 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
length.py
1.45 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
mac_address.py
865 bytes
05/14/2024 03:18:23 PM
rw-r--r--
📄
py.typed
0 bytes
05/14/2024 03:18:23 PM
rw-r--r--
📄
slug.py
750 bytes
05/14/2024 03:18:23 PM
rw-r--r--
📄
uri.py
1.78 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
url.py
7.23 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
utils.py
3.1 KB
05/14/2024 03:18:23 PM
rw-r--r--
📄
uuid.py
1.04 KB
05/14/2024 03:18:23 PM
rw-r--r--
Editing: btc_address.py
Close
"""BTC Address.""" # standard from hashlib import sha256 import re # local from .utils import validator def _decode_base58(addr: str): """Decode base58.""" alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" return sum((58**enm) * alphabet.index(idx) for enm, idx in enumerate(addr[::-1])) def _validate_old_btc_address(addr: str): """Validate P2PKH and P2SH type address.""" if len(addr) not in range(25, 35): return False decoded_bytes = _decode_base58(addr).to_bytes(25, "big") header, checksum = decoded_bytes[:-4], decoded_bytes[-4:] return checksum == sha256(sha256(header).digest()).digest()[:4] @validator def btc_address(value: str, /): """Return whether or not given value is a valid bitcoin address. Full validation is implemented for P2PKH and P2SH addresses. For segwit addresses a regexp is used to provide a reasonable estimate on whether the address is valid. Examples: >>> btc_address('3Cwgr2g7vsi1bXDUkpEnVoRLA9w4FZfC69') # Output: True >>> btc_address('1BvBMsEYstWetqTFn5Au4m4GFg7xJaNVN2') # Output: ValidationError(func=btc_address, args=...) Args: value: Bitcoin address string to validate. Returns: (Literal[True]): If `value` is a valid bitcoin address. (ValidationError): If `value` is an invalid bitcoin address. """ if not value: return False return ( # segwit pattern re.compile(r"^(bc|tc)[0-3][02-9ac-hj-np-z]{14,74}$").match(value) if value[:2] in ("bc", "tb") else _validate_old_btc_address(value) )