"""Validation for PLM addresses supplied by the user (withdrawal destinations). embit's `Script.from_address` accepts a well-formed bech32 address from *any* chain — a Bitcoin `bc1...` parses fine and yields a perfectly valid witness program — so parse-success alone is not a sufficient check here: a withdrawal to a `bc1...` address would build, sign and broadcast normally on PLM and land on a script nobody holds the key for. The HRP check below is what makes the destination actually PLM, and it matches what the withdrawal form already tells the user (bech32 `plm1q...` only). """ from embit import script from embit.base import EmbitError from app.wallet.plm_network import PLM_MAINNET _BECH32_PREFIX = PLM_MAINNET["bech32"] + "1" def is_valid_plm_address(address: str) -> bool: if not address.startswith(_BECH32_PREFIX): return False try: script.Script.from_address(address) except EmbitError: return False return True