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

Function bech32_decode

test/functional/test_framework/segwit_addr.py:60–76  ·  view source on GitHub ↗

Validate a Bech32/Bech32m string, and determine HRP and data.

(bech)

Source from the content-addressed store, hash-verified

58
59
60def bech32_decode(bech):
61 """Validate a Bech32/Bech32m string, and determine HRP and data."""
62 if ((any(ord(x) < 33 or ord(x) > 126 for x in bech)) or
63 (bech.lower() != bech and bech.upper() != bech)):
64 return (None, None, None)
65 bech = bech.lower()
66 pos = bech.rfind('1')
67 if pos < 1 or pos + 7 > len(bech) or len(bech) > 90:
68 return (None, None, None)
69 if not all(x in CHARSET for x in bech[pos+1:]):
70 return (None, None, None)
71 hrp = bech[:pos]
72 data = [CHARSET.find(x) for x in bech[pos+1:]]
73 encoding = bech32_verify_checksum(hrp, data)
74 if encoding is None:
75 return (None, None, None)
76 return (encoding, hrp, data[:-6])
77
78
79def convertbits(data, frombits, tobits, pad=True):

Callers 1

decode_segwit_addressFunction · 0.70

Calls 3

ordFunction · 0.85
findMethod · 0.80
bech32_verify_checksumFunction · 0.70

Tested by

no test coverage detected