base58

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

commit 369b408991a98ad43b8f8c68e10464ffa44949e2
parent 70dc813a0f10c820a41727dddf02af89ce93212c
Author: Jared Tobin <jared@jtobin.io>
Date:   Sat, 10 Oct 2026 15:24:32 +0400

lib: build leading ones and zeros via replicate

Diffstat:
Mlib/Data/ByteString/Base58.hs | 14++------------
1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/lib/Data/ByteString/Base58.hs b/lib/Data/ByteString/Base58.hs @@ -64,21 +64,11 @@ base58_charset = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" -- produce leading ones from leading zeros leading_ones :: BS.ByteString -> BS.ByteString -leading_ones = go mempty where - go acc bs = case BS.uncons bs of - Nothing -> acc - Just (h, t) - | h == 0 -> go (BS.cons 0x31 acc) t - | otherwise -> acc +leading_ones bs = BS.replicate (BS.length (BS.takeWhile (== 0x00) bs)) 0x31 -- produce leading zeros from leading ones leading_zeros :: BS.ByteString -> BS.ByteString -leading_zeros = go mempty where - go acc bs = case BS.uncons bs of - Nothing -> acc - Just (h, t) - | h == 0x31 -> go (BS.cons 0x00 acc) t - | otherwise -> acc +leading_zeros bs = BS.replicate (BS.length (BS.takeWhile (== 0x31) bs)) 0x00 -- to base256 unroll_base256 :: Integer -> BS.ByteString