OXIESEC PANEL
- Current Dir:
/
/
opt
/
alt
/
python37
/
lib
/
python3.7
/
site-packages
/
validators
Server IP: 2a02:4780:11:1084:0:327f:3464:10
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
09/05/2025 09:36:16 AM
rwxr-xr-x
📄
__init__.py
1.08 KB
06/05/2022 05:11:31 PM
rw-r--r--
📁
__pycache__
-
03/16/2023 12:57:03 PM
rwxr-xr-x
📄
between.py
1.54 KB
10/10/2015 06:47:54 AM
rw-r--r--
📄
btc_address.py
1.49 KB
12/18/2020 10:22:34 AM
rw-r--r--
📄
card.py
4.28 KB
05/07/2020 12:32:08 PM
rw-r--r--
📄
domain.py
1.29 KB
10/05/2021 06:21:42 AM
rw-r--r--
📄
email.py
1.93 KB
04/02/2020 01:03:56 PM
rw-r--r--
📄
extremes.py
991 bytes
08/30/2016 02:58:11 PM
rw-r--r--
📄
hashes.py
2.44 KB
06/03/2017 02:07:19 PM
rw-r--r--
📁
i18n
-
03/16/2023 12:57:03 PM
rwxr-xr-x
📄
iban.py
1.14 KB
05/09/2016 03:06:26 PM
rw-r--r--
📄
ip_address.py
3.99 KB
06/05/2022 05:04:06 PM
rw-r--r--
📄
length.py
970 bytes
10/10/2015 06:47:54 AM
rw-r--r--
📄
mac_address.py
836 bytes
10/10/2015 06:47:54 AM
rw-r--r--
📄
slug.py
529 bytes
10/10/2015 06:47:54 AM
rw-r--r--
📄
truthy.py
876 bytes
10/05/2021 06:21:42 AM
rw-r--r--
📄
url.py
4.82 KB
06/05/2022 05:11:01 PM
rw-r--r--
📄
utils.py
1.97 KB
10/05/2021 06:21:42 AM
rw-r--r--
📄
uuid.py
970 bytes
09/03/2020 07:35:41 AM
rw-r--r--
Editing: btc_address.py
Close
import re from hashlib import sha256 from .utils import validator segwit_pattern = re.compile( r'^(bc|tc)[0-3][02-9ac-hj-np-z]{14,74}$') def validate_segwit_address(addr): return segwit_pattern.match(addr) def decode_base58(addr): alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" return sum([ (58 ** e) * alphabet.index(i) for e, i in enumerate(addr[::-1]) ]) def validate_old_btc_address(addr): "Validate P2PKH and P2SH type address" if not len(addr) in range(25, 35): return False decoded_bytes = decode_base58(addr).to_bytes(25, "big") header = decoded_bytes[:-4] checksum = decoded_bytes[-4:] return checksum == sha256(sha256(header).digest()).digest()[:4] @validator def btc_address(value): """ Return whether or not given value is a valid bitcoin address. If the value is valid bitcoin address this function returns ``True``, otherwise :class:`~validators.utils.ValidationFailure`. 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') True :param value: Bitcoin address string to validate """ if not value or not isinstance(value, str): return False if value[:2] in ("bc", "tb"): return validate_segwit_address(value) return validate_old_btc_address(value)