1
0

bech32: around 5% speedup for bech32_decode

useful for lnaddr.lndecode
This commit is contained in:
SomberNight
2021-02-28 16:53:21 +01:00
parent d7597d96d0
commit b83f7159a9

View File

@@ -23,6 +23,7 @@
CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
_CHARSET_INVERSE = {x: CHARSET.find(x) for x in CHARSET}
def bech32_polymod(values):
@@ -72,7 +73,7 @@ def bech32_decode(bech, ignore_long_length=False):
if not all(x in CHARSET for x in bech[pos+1:]):
return (None, None)
hrp = bech[:pos]
data = [CHARSET.find(x) for x in bech[pos+1:]]
data = [_CHARSET_INVERSE[x] for x in bech[pos+1:]]
if not bech32_verify_checksum(hrp, data):
return (None, None)
return (hrp, data[:-6])