MCPcopy Create free account
hub / github.com/ElementsProject/elements / blech32_decode

Function blech32_decode

test/functional/test_framework/liquid_addr.py:45–60  ·  view source on GitHub ↗

Validate a blech32 string, and determine HRP and data.

(bech)

Source from the content-addressed store, hash-verified

43
44
45def 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
63def convertbits(data, frombits, tobits, pad=True):

Callers 1

decodeFunction · 0.85

Calls 3

ordFunction · 0.85
blech32_verify_checksumFunction · 0.85
findMethod · 0.80

Tested by

no test coverage detected