commit a5e139e300d32a4e4b845d0d83d48c4a4da3bdb4
parent 0c0ea70378b00100f5c89c85ff857d4df779d484
Author: Jared Tobin <jared@jtobin.io>
Date: Fri, 3 Jan 2025 21:18:35 -0330
lib: enforce lowercase hrp
Diffstat:
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/Data/ByteString/Bech32.hs b/lib/Data/ByteString/Bech32.hs
@@ -48,11 +48,11 @@ encode
:: BS.ByteString -- ^ base256-encoded human-readable part
-> BS.ByteString -- ^ base256-encoded data part
-> Maybe BS.ByteString -- ^ bech32-encoded bytestring
-encode hrp (B32.encode -> dat) = do
+encode (B8.map C.toLower -> hrp) (B32.encode -> dat) = do
guard (BI.valid_hrp hrp)
let check = create_checksum hrp (BI.as_word5 dat)
res = toStrict $
- BSB.byteString (B8.map C.toLower hrp)
+ BSB.byteString hrp
<> BSB.word8 49 -- 1
<> BSB.byteString dat
<> BSB.byteString (BI.as_base32 check)
diff --git a/lib/Data/ByteString/Bech32m.hs b/lib/Data/ByteString/Bech32m.hs
@@ -49,11 +49,11 @@ encode
:: BS.ByteString -- ^ base256-encoded human-readable part
-> BS.ByteString -- ^ base256-encoded data part
-> Maybe BS.ByteString -- ^ bech32m-encoded bytestring
-encode hrp (B32.encode -> dat) = do
+encode (B8.map C.toLower -> hrp) (B32.encode -> dat) = do
guard (BI.valid_hrp hrp)
let check = create_checksum hrp (BI.as_word5 dat)
res = toStrict $
- BSB.byteString (B8.map C.toLower hrp)
+ BSB.byteString hrp
<> BSB.word8 49 -- 1
<> BSB.byteString dat
<> BSB.byteString (BI.as_base32 check)