summaryrefslogtreecommitdiff
path: root/Base58.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-04-15 14:28:57 -0400
committerjoe <joe@jerkface.net>2014-04-15 14:28:57 -0400
commit86111acab0bbc4c1b2d523be1c50297f4ec8d388 (patch)
tree185ba13b4386dedf94800623c327ff7dc3fa61fc /Base58.hs
parent4d96c66f6ece8383c04543c875556d1fae9422f6 (diff)
finished writeWalletKeys
Diffstat (limited to 'Base58.hs')
-rw-r--r--Base58.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/Base58.hs b/Base58.hs
index 26f1cb2..8adf60d 100644
--- a/Base58.hs
+++ b/Base58.hs
@@ -35,3 +35,18 @@ base58_decode str = do
35 guard (hash_result==expected_hash) 35 guard (hash_result==expected_hash)
36 return (network_id,payload) 36 return (network_id,payload)
37 37
38base58_encode :: S.ByteString -> String
39base58_encode hash = replicate zcount '1' ++ map (base58chars !!) (reverse rdigits)
40 where
41 zcount = S.length . S.takeWhile (==0) $ hash
42 cksum = S.take 4 . SHA256.hash . SHA256.hash $ hash
43 n = foldl' (\a b->a*256+b) 0 . map asInteger $ concatMap S.unpack [hash, cksum]
44 asInteger x = fromIntegral x :: Integer
45 rdigits = unfoldr getdigit n
46 where
47 getdigit d = do
48 guard (d/=0)
49 let (q,b) = d `divMod` 58
50 return (fromIntegral b,q)
51
52