Skip to content

Commit a8298d9

Browse files
Accept uniformly uppercase SegWit addresses
Normalize only uniformly cased ASCII SegWit strings, retaining rejection of mixed case and leaving legacy Base58 validation unchanged.
1 parent 22786cc commit a8298d9

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎src/validators/crypto_addresses/btc_address.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ def btc_address(value: str, /):
4848
if not value:
4949
return False
5050

51-
return (
52-
# segwit pattern
53-
re.compile(r"^(bc|tb)[0-3][02-9ac-hj-np-z]{14,74}$").fullmatch(value)
54-
if value[:2] in ("bc", "tb")
55-
else _validate_old_btc_address(value)
56-
)
51+
if value[:2].lower() in ("bc", "tb"):
52+
# BIP 173 allows uniform upper/lowercase, but never mixed case.
53+
if not value.isascii() or not (value.islower() or value.isupper()):
54+
return False
55+
return re.fullmatch(r"(bc|tb)[0-3][02-9ac-hj-np-z]{14,74}", value.lower())
56+
57+
return _validate_old_btc_address(value)

0 commit comments

Comments
 (0)