bech32

Pure Haskell bech32, bech32m encoding/decoding (docs.ppad.tech/bech32).
git clone git://git.ppad.tech/bech32.git
Log | Files | Refs | README | LICENSE

commit 33d120c4c4b89c1188dae7c6d48e501d3d8ab32f
parent 29a151d14f42b71b0bf8d6cd38ccf222bce5e7a8
Author: Jared Tobin <jared@jtobin.io>
Date:   Tue,  7 Jan 2025 12:05:29 -0330

lib: remove 'primitive' dependency

Diffstat:
Mlib/Data/ByteString/Bech32/Internal.hs | 15++++++++++-----
Mppad-bech32.cabal | 1-
2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/Data/ByteString/Bech32/Internal.hs b/lib/Data/ByteString/Bech32/Internal.hs @@ -1,6 +1,7 @@ {-# OPTIONS_HADDOCK hide, prune #-} {-# LANGUAGE BangPatterns #-} {-# LANGUAGE BinaryLiterals #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ViewPatterns #-} @@ -20,7 +21,6 @@ import qualified Data.ByteString.Builder as BSB import qualified Data.ByteString.Builder.Extra as BE import qualified Data.ByteString.Internal as BI import qualified Data.ByteString.Unsafe as BU -import qualified Data.Primitive.PrimArray as PA import Data.Word (Word32) fi :: (Integral a, Num b) => a -> b @@ -52,8 +52,14 @@ as_base32 = BS.map (BS.index bech32_charset . fi) polymod :: BS.ByteString -> Word32 polymod = BS.foldl' alg 1 where - generator = PA.primArrayFromListN 5 - [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3] + generator :: Int -> Word32 + generator = \case + 0 -> 0x3b6a57b2 + 1 -> 0x26508e6d + 2 -> 0x1ea119fa + 3 -> 0x3d4233dd + 4 -> 0x2a1462b3 + _ -> error "ppad-bech32: internal error (please report this as a bug!)" alg !chk v = let !b = chk `B.shiftR` 25 @@ -63,8 +69,7 @@ polymod = BS.foldl' alg 1 where loop_gen i b !chk | i > 4 = chk | otherwise = - let sor | B.testBit (b `B.shiftR` i) 0 = - PA.indexPrimArray generator i + let sor | B.testBit (b `B.shiftR` i) 0 = generator i | otherwise = 0 in loop_gen (succ i) b (chk `B.xor` sor) diff --git a/ppad-bech32.cabal b/ppad-bech32.cabal @@ -31,7 +31,6 @@ library build-depends: base >= 4.9 && < 5 , bytestring >= 0.9 && < 0.13 - , primitive >= 0.8 && < 0.10 test-suite bech32-tests type: exitcode-stdio-1.0