commit b691041032792aaafcfdf70c34e503b8b0593eff
parent f2f222199acbc13ddfadd2efaa50d2e9f0277e90
Author: Jared Tobin <jared@jtobin.io>
Date: Sat, 14 Dec 2024 05:17:07 -0330
lib: encode to lower-case only
Diffstat:
4 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
@@ -58,8 +58,7 @@ Current benchmark figures on my mid-2020 MacBook Air look like (use
## Security
-(Ignore the boilerplate -- this library is still in a pre-release state!
-Not only are there no guarantees, there aren't even any tests!)
+**NOTE** This library is still in a pre-release state!
This library aims at the maximum security achievable in a
garbage-collected language under an optimizing compiler such as GHC, in
diff --git a/lib/Data/ByteString/Bech32.hs b/lib/Data/ByteString/Bech32.hs
@@ -7,10 +7,12 @@ module Data.ByteString.Bech32 (
import Control.Monad (guard)
import qualified Data.ByteString as BS
+import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Base32 as B32
import Data.ByteString.Base32 (Encoding(..))
import qualified Data.ByteString.Builder as BSB
import qualified Data.ByteString.Builder.Extra as BE
+import qualified Data.Char as C (toLower)
-- realization for small builders
toStrict :: BSB.Builder -> BS.ByteString
@@ -44,7 +46,7 @@ encode hrp (B32.encode -> dat) = do
guard (B32.valid_hrp hrp)
let check = create_checksum hrp (B32.as_word5 dat)
res = toStrict $
- BSB.byteString hrp
+ BSB.byteString (B8.map C.toLower hrp)
<> BSB.word8 49 -- 1
<> BSB.byteString dat
<> BSB.byteString (B32.as_base32 check)
diff --git a/lib/Data/ByteString/Bech32m.hs b/lib/Data/ByteString/Bech32m.hs
@@ -7,10 +7,12 @@ module Data.ByteString.Bech32m (
import Control.Monad (guard)
import qualified Data.ByteString as BS
+import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Base32 as B32
import Data.ByteString.Base32 (Encoding(..))
import qualified Data.ByteString.Builder as BSB
import qualified Data.ByteString.Builder.Extra as BE
+import qualified Data.Char as C (toLower)
-- realization for small builders
toStrict :: BSB.Builder -> BS.ByteString
@@ -44,7 +46,7 @@ encode hrp (B32.encode -> dat) = do
guard (B32.valid_hrp hrp)
let check = create_checksum hrp (B32.as_word5 dat)
res = toStrict $
- BSB.byteString hrp
+ BSB.byteString (B8.map C.toLower hrp)
<> BSB.word8 49 -- 1
<> BSB.byteString dat
<> BSB.byteString (B32.as_base32 check)
diff --git a/test/Reference/Bech32.hs b/test/Reference/Bech32.hs
@@ -1,3 +1,5 @@
+{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-}
+
-- official BIP173 reference
-- https://github.com/sipa/bech32/tree/master/ref/haskell
module Reference.Bech32