diff options
author | joe <joe@jerkface.net> | 2014-04-15 14:28:57 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2014-04-15 14:28:57 -0400 |
commit | 86111acab0bbc4c1b2d523be1c50297f4ec8d388 (patch) | |
tree | 185ba13b4386dedf94800623c327ff7dc3fa61fc /Base58.hs | |
parent | 4d96c66f6ece8383c04543c875556d1fae9422f6 (diff) |
finished writeWalletKeys
Diffstat (limited to 'Base58.hs')
-rw-r--r-- | Base58.hs | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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 | ||
38 | base58_encode :: S.ByteString -> String | ||
39 | base58_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 | |||