packages feed

ppad-base58 0.1.1 → 0.2.0

raw patch · 5 files changed

+24/−33 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.ByteString.Base58Check: decode :: ByteString -> Maybe (Word8, ByteString)
+ Data.ByteString.Base58Check: decode :: ByteString -> Maybe ByteString
- Data.ByteString.Base58Check: encode :: Word8 -> ByteString -> ByteString
+ Data.ByteString.Base58Check: encode :: ByteString -> ByteString

Files

CHANGELOG view
@@ -1,5 +1,11 @@ # Changelog +- 0.2.0 (2025-02-18)+  * The base58check encode and decode functions no longer treat version+    bytes (of which there may now be several) in any special fashion.+    Version bytes should be prepended to the target string before+    encoding, and removed manually from any decoded strings.+ - 0.1.1 (2025-01-06)   * Includes a minor encoding-related performance optimisation. 
bench/Main.hs view
@@ -23,7 +23,7 @@     ]   , bgroup "base58check" [       bgroup "encode" [-        bench "0x00, hello world" $ nf (B58C.encode 0x00) "hello world"+        bench "0x00, hello world" $ nf B58C.encode "\NULhello world"       ]     , bgroup "decode" [         bench "13vQB7B6MrGQZaxCqW9KER" $
lib/Data/ByteString/Base58Check.hs view
@@ -8,10 +8,9 @@ -- -- base58check encoding and decoding of strict bytestrings. ----- base58check is a versioned, checksummed base58 encoding. A payload is--- constructed from a leading version byte and some base256 input, and--- then a checksum is computed by SHA256d-ing the payload, appending its--- first 4 bytes, and base58-encoding the result.+-- base58check is a versioned, checksummed base58 encoding. A checksum+-- is computed by SHA256d-ing a payload, appending its first 4 bytes,+-- and base58-encoding the result.  module Data.ByteString.Base58Check (     encode@@ -22,31 +21,29 @@ import qualified Crypto.Hash.SHA256 as SHA256 import qualified Data.ByteString as BS import qualified Data.ByteString.Base58 as B58-import Data.Word (Word8) --- | Encode a version byte and base256 'ByteString' as base58check.+-- | Encode a base256 'ByteString' as base58check. -----   >>> encode 0x00 "hello world"+--   >>> encode (BS.singleton 0x00 <> "hello world") --   "13vQB7B6MrGQZaxCqW9KER"-encode :: Word8 -> BS.ByteString -> BS.ByteString-encode ver dat =-  let pay = BS.cons ver dat-      kek = BS.take 4 (SHA256.hash (SHA256.hash pay))+encode :: BS.ByteString -> BS.ByteString+encode pay =+  let kek = BS.take 4 (SHA256.hash (SHA256.hash pay))   in  B58.encode (pay <> kek)  -- | Validate and decode a base58check-encoded string. Invalid --   base58check inputs will produce 'Nothing'. -- --   >>> decode "13vQB7B6MrGQZaxCqW9KER"---   Just (0,"hello world")+--   Just "\NULhello world" --   >>> decode "13uQB7B6MrGQZaxCqW9KER" -- s/v/u --   Nothing-decode :: BS.ByteString -> Maybe (Word8, BS.ByteString)+decode :: BS.ByteString -> Maybe BS.ByteString decode mb = do   bs <- B58.decode mb   let len = BS.length bs       (pay, kek) = BS.splitAt (len - 4) bs       man = BS.take 4 (SHA256.hash (SHA256.hash pay))   guard (kek == man)-  BS.uncons pay+  pure pay 
ppad-base58.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.0 name:               ppad-base58-version:            0.1.1+version:            0.2.0 synopsis:           base58 and base58check encoding/decoding. license:            MIT license-file:       LICENSE
test/Main.hs view
@@ -12,7 +12,6 @@ import qualified Data.ByteString.Base58Check as B58Check import qualified Data.Text.Encoding as TE import qualified Data.Text.IO as TIO-import Data.Word (Word8) import Test.Tasty import Test.Tasty.HUnit import qualified Test.Tasty.QuickCheck as Q@@ -53,9 +52,7 @@     ]   where     execute_valid Valid_Base58Check {..} = testCase "valid" $ do -- label-      let enc = case BS.uncons vc_payload of-            Nothing -> error "faulty"-            Just (h, t) -> B58Check.encode h t+      let enc = B58Check.encode vc_payload       assertEqual mempty enc vc_string      execute_invalid Invalid_Base58Check {..} = testCase "invalid" $ do -- label@@ -89,30 +86,21 @@   v <- Q.vectorOf l Q.arbitrary   pure (BS.pack v) -data B58C = B58C Word8 BS-  deriving (Eq, Show)- instance Q.Arbitrary BS where   arbitrary = do     b <- bytes 1024     pure (BS b) -instance Q.Arbitrary B58C where-  arbitrary = do-    w8 <- Q.arbitrary-    bs <- Q.arbitrary-    pure (B58C w8 bs)- base58_decode_inverts_encode :: BS -> Bool base58_decode_inverts_encode (BS bs) = case B58.decode (B58.encode bs) of   Nothing -> False   Just b  -> b == bs -base58check_decode_inverts_encode :: B58C -> Bool-base58check_decode_inverts_encode (B58C w8 (BS bs)) =-  case B58Check.decode (B58Check.encode w8 bs) of+base58check_decode_inverts_encode :: BS -> Bool+base58check_decode_inverts_encode (BS bs) =+  case B58Check.decode (B58Check.encode bs) of     Nothing -> False-    Just (w8', bs') -> w8 == w8' && bs == bs'+    Just b  -> b == bs  main :: IO () main = do