Skip to content

Latest commit

 

History

History
40 lines (32 loc) · 1.42 KB

README.md

File metadata and controls

40 lines (32 loc) · 1.42 KB

Base58

Build Status Coverage Status artistic

Usage

The library can encode regular (small) integers:

let str =  (encode_int 123456) in
assert(str = "CGy")

as well as the big integers provided by the Ocaml standard library:

(encode_big_int (Big_int.power_int_positive_int 2 100))
assert(str = "2ki7xkQVuB8dLGWonW");

The decoding function outputs an Ocaml Num that will be an int when possible and a Big_int otherwise.

assert((decode "6hN7hS") = (Int 3471844090));
assert((Big_int.eq_big_int (decode "2ki7xkQVuB8dLGWonW")  
  (Big_int.power_int_positive_int 2 100)))

By default Base58 will encode using the Flickr alphabet. Alternatively, you can use the bitcoin alphabet as well.

let str = (encode_int ~alphabet:bitcoin_alphabet 0x2466CA) in 
assert(str = "DEAD")

For more examples see the tests in t/*.ml.

License

Artistic License 2.0