Skip to content

ppad-tech/base58

Repository files navigation

base58

A pure Haskell implementation of base58 and base58check encoding & decoding on strict ByteStrings.

Usage

A sample GHCi session:

  > :set -XOverloadedStrings
  >
  > -- import qualified
  > import qualified Data.ByteString.Base58 as B58
  > import qualified Data.ByteString.Base58Check as B58Check
  >
  > -- simple base58 encoding and decoding
  > let b58 = B58.encode "hello world"
  > b58
  "StV1DL6CwTryKyV"
  >
  > B58.decode b58
  Just "hello world"
  >
  > -- base58check is a versioned, checksummed format
  > let b58check = B58Check.encode "\NULhello world" -- 0x00 version byte
  > b58check
  "13vQB7B6MrGQZaxCqW9KER"
  >
  > B58Check.decode b58check
  Just "\NULhello world"

Documentation

Haddocks (API documentation, etc.) are hosted at docs.ppad.tech/base58.

Performance

The aim is best-in-class performance for pure, highly-auditable Haskell code.

Current benchmark figures on a M4 Silicon MacBook Air look like (use cabal bench to run the benchmark suite):

  benchmarking ppad-base58/base58/encode/hello world
  time                 350.2 ns   (349.9 ns .. 350.6 ns)
                       1.000 R²   (1.000 R² .. 1.000 R²)
  mean                 350.9 ns   (350.6 ns .. 351.3 ns)
  std dev              1.096 ns   (785.7 ps .. 1.603 ns)

  benchmarking ppad-base58/base58/decode/StV1DL6CwTryKyV
  time                 359.5 ns   (358.7 ns .. 360.8 ns)
                       1.000 R²   (1.000 R² .. 1.000 R²)
  mean                 362.1 ns   (361.3 ns .. 362.8 ns)
  std dev              2.779 ns   (2.415 ns .. 3.261 ns)

  benchmarking ppad-base58/base58check/encode/0x00, hello world
  time                 658.6 ns   (657.9 ns .. 659.7 ns)
                       1.000 R²   (1.000 R² .. 1.000 R²)
  mean                 660.4 ns   (659.6 ns .. 661.6 ns)
  std dev              3.131 ns   (2.370 ns .. 5.060 ns)

  benchmarking ppad-base58/base58check/decode/13vQB7B6MrGQZaxCqW9KER
  time                 698.6 ns   (698.0 ns .. 699.3 ns)
                       1.000 R²   (1.000 R² .. 1.000 R²)
  mean                 700.2 ns   (699.6 ns .. 701.0 ns)
  std dev              2.325 ns   (1.943 ns .. 2.759 ns)

You should build with the 'llvm' flag for maximum performance.

Security

This library aims at the maximum security achievable in a garbage-collected language under an optimizing compiler such as GHC, in which strict constant-timeness can be challenging to achieve.

If you discover any vulnerabilities, please disclose them via security@ppad.tech.

Development

You'll require Nix with flake support enabled. Enter a development shell with:

$ nix develop

Then do e.g.:

$ cabal repl ppad-base58

to get a REPL for the main library.

Attribution

The vectors used in the test suite for both base58 and base58check are verbatim from paulmillr's scure-base library.

About

Pure Haskell base58, base58check encoding/decoding

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published