base58

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

README.md (3482B)


      1 # base58
      2 
      3 [![](https://img.shields.io/hackage/v/ppad-base58?color=blue)](https://hackage.haskell.org/package/ppad-base58)
      4 ![](https://img.shields.io/badge/license-MIT-brightgreen)
      5 [![](https://img.shields.io/badge/haddock-base58-lightblue)](https://docs.ppad.tech/base58)
      6 
      7 A pure Haskell implementation of base58 and base58check encoding &
      8 decoding on strict ByteStrings.
      9 
     10 ## Usage
     11 
     12 A sample GHCi session:
     13 
     14 ```
     15   > :set -XOverloadedStrings
     16   >
     17   > -- import qualified
     18   > import qualified Data.ByteString.Base58 as B58
     19   > import qualified Data.ByteString.Base58Check as B58Check
     20   >
     21   > -- simple base58 encoding and decoding
     22   > let b58 = B58.encode "hello world"
     23   > b58
     24   "StV1DL6CwTryKyV"
     25   >
     26   > B58.decode b58
     27   Just "hello world"
     28   >
     29   > -- base58check is a versioned, checksummed format
     30   > let b58check = B58Check.encode "\NULhello world" -- 0x00 version byte
     31   > b58check
     32   "13vQB7B6MrGQZaxCqW9KER"
     33   >
     34   > B58Check.decode b58check
     35   Just "\NULhello world"
     36 ```
     37 
     38 ## Documentation
     39 
     40 Haddocks (API documentation, etc.) are hosted at
     41 [docs.ppad.tech/base58](https://docs.ppad.tech/base58).
     42 
     43 ## Performance
     44 
     45 The aim is best-in-class performance for pure, highly-auditable Haskell
     46 code.
     47 
     48 Current benchmark figures on a M4 Silicon MacBook Air look like (use
     49 `cabal bench` to run the benchmark suite):
     50 
     51 ```
     52   benchmarking ppad-base58/base58/encode/hello world
     53   time                 350.3 ns   (349.2 ns .. 352.0 ns)
     54                        0.999 R²   (0.997 R² .. 1.000 R²)
     55   mean                 353.0 ns   (351.9 ns .. 354.9 ns)
     56   std dev              4.705 ns   (3.411 ns .. 7.449 ns)
     57   variance introduced by outliers: 13% (moderately inflated)
     58 
     59   benchmarking ppad-base58/base58/decode/StV1DL6CwTryKyV
     60   time                 377.7 ns   (373.7 ns .. 380.7 ns)
     61                        0.999 R²   (0.999 R² .. 1.000 R²)
     62   mean                 379.4 ns   (376.8 ns .. 381.8 ns)
     63   std dev              9.020 ns   (7.823 ns .. 10.76 ns)
     64   variance introduced by outliers: 32% (moderately inflated)
     65 
     66   benchmarking ppad-base58/base58check/encode/0x00, hello world
     67   time                 1.197 μs   (1.195 μs .. 1.200 μs)
     68                        1.000 R²   (1.000 R² .. 1.000 R²)
     69   mean                 1.200 μs   (1.198 μs .. 1.202 μs)
     70   std dev              7.256 ns   (6.187 ns .. 8.819 ns)
     71 
     72   benchmarking ppad-base58/base58check/decode/13vQB7B6MrGQZaxCqW9KER
     73   time                 1.222 μs   (1.218 μs .. 1.225 μs)
     74                        1.000 R²   (1.000 R² .. 1.000 R²)
     75   mean                 1.220 μs   (1.217 μs .. 1.223 μs)
     76   std dev              9.566 ns   (8.250 ns .. 11.28 ns)
     77 ```
     78 
     79 You should build with the 'llvm' flag for maximum performance.
     80 
     81 ## Security
     82 
     83 This library aims at the maximum security achievable in a
     84 garbage-collected language under an optimizing compiler such as GHC, in
     85 which strict constant-timeness can be challenging to achieve.
     86 
     87 If you discover any vulnerabilities, please disclose them via
     88 security@ppad.tech.
     89 
     90 ## Development
     91 
     92 You'll require [Nix][nixos] with [flake][flake] support enabled. Enter a
     93 development shell with:
     94 
     95 ```
     96 $ nix develop
     97 ```
     98 
     99 Then do e.g.:
    100 
    101 ```
    102 $ cabal repl ppad-base58
    103 ```
    104 
    105 to get a REPL for the main library.
    106 
    107 ## Attribution
    108 
    109 The vectors used in the test suite for both base58
    110 and base58check are verbatim from paulmillr's
    111 [scure-base](https://github.com/paulmillr/scure-base) library.
    112 
    113 [nixos]: https://nixos.org/
    114 [flake]: https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html