Validate a blech32 string, and determine HRP and data.
(bech)
| 43 | |
| 44 | |
| 45 | def blech32_decode(bech): |
| 46 | """Validate a blech32 string, and determine HRP and data.""" |
| 47 | if ((any(ord(x) < 33 or ord(x) > 126 for x in bech)) or |
| 48 | (bech.lower() != bech and bech.upper() != bech)): |
| 49 | return (None, None) |
| 50 | bech = bech.lower() |
| 51 | pos = bech.rfind('1') |
| 52 | if pos < 1 or pos + 13 > len(bech) or len(bech) > 1000: # 7->13 90->1000 |
| 53 | return (None, None) |
| 54 | if not all(x in CHARSET for x in bech[pos+1:]): |
| 55 | return (None, None) |
| 56 | hrp = bech[:pos] |
| 57 | data = [CHARSET.find(x) for x in bech[pos+1:]] |
| 58 | if not blech32_verify_checksum(hrp, data): |
| 59 | return (None, None) |
| 60 | return (hrp, data[:-12]) # 6->12 |
| 61 | |
| 62 | |
| 63 | def convertbits(data, frombits, tobits, pad=True): |
no test coverage detected