based/src/Encoding/Base58.hs

30 lines
928 B
Haskell
Raw Normal View History

module Encoding.Base58
( enc58
, dec58
) where
import Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import Data.ByteString.UTF8 as BSU -- from utf8-string
import qualified Haskoin.Address.Base58 as B58
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.IO as T
-- dec58 :: String -> String
-- dec58 input =
-- case B58.decodeBase58 (T.pack input) of
-- Just decodedStr -> T.unpack (T.decodeUtf8 decodedStr)
-- Nothing -> "Error decoding Base58.\n"
dec58 :: B.ByteString -> B.ByteString
dec58 input = case B58.decodeBase58 (T.decodeUtf8 input) of
Just byteString -> byteString
Nothing -> BC.pack "Error: Invalid Base58 input"
-- enc58 :: String -> String
-- enc58 = T.unpack . B58.encodeBase58 . BSU.fromString
enc58 :: B.ByteString -> B.ByteString
enc58 = BC.pack . T.unpack . B58.encodeBase58