ExBase58 (ex_base58 v0.2.0)
Base58 encoding and decoding.
Every function in this module accepts additonal optional parameter - alphabet. Default alphabet is :bitcoin
.
It uses https://github.com/mycorrhiza/bs58-rs rust library
Link to this section Summary
Functions
Decodes from Base58 format
Decodes from Base58Check format
Encodes binary into Base58 format.
Encodes binary into Base58Check format
Link to this section Types
Link to this type
alphabet()
Specs
alphabet() :: :bitcoin | :monero | :ripple | :flickr
Link to this section Functions
Link to this function
decode(encoded, alphabet \\ :bitcoin)
Specs
Decodes from Base58 format
examples
Examples
iex> ExBase58.decode("c4oi")
{:ok, "hey"}
iex> ExBase58.decode("Cn8eVZg")
{:ok, "hello"}
iex> ExBase58.decode("U83eVZg", :ripple)
{:ok, "hello"}
iex> ExBase58.decode("cM8DuyF", :flickr)
{:ok, "hello"}
iex> ExBase58.decode("Hello")
{:error, :decode_error}
iex> ExBase58.decode("cM8DuyF", :meow)
{:error, :invalid_alphabet}
iex> ExBase58.decode("2gsG")
{:ok, <<5, 6, 7>>}
Link to this function
decode_check(binary, version, alphabet \\ :bitcoin)
Specs
decode_check(binary(), non_neg_integer(), alphabet()) :: {:ok, binary()} | {:error, atom()}
Decodes from Base58Check format
examples
Examples
iex> ExBase58.decode_check("1GZVwCXwyKVRPTViubJDVKVhVvcaEoX5cN", 0)
{:ok, <<170, 175, 89, 206, 129, 197, 74, 82, 170, 144, 47, 81, 120, 199, 251, 203, 167, 32, 54, 7>>}
iex> ExBase58.decode_check("mw5TEFcvnLvgAZyLdAGbKEi2MvDHF1HXJX", 111)
{:ok, <<170, 175, 89, 206, 129, 197, 74, 82, 170, 144, 47, 81, 120, 199, 251, 203, 167, 32, 54, 7>>}
iex> ExBase58.decode_check("mAnTNEcv8LvgwZyLdwGbKN5pMvDHErHXJX", 111, :ripple)
{:ok, <<170, 175, 89, 206, 129, 197, 74, 82, 170, 144, 47, 81, 120, 199, 251, 203, 167, 32, 54, 7>>}
Link to this function
encode(binary, alphabet \\ :bitcoin)
Specs
Encodes binary into Base58 format.
examples
Examples
iex> ExBase58.encode("hello")
{:ok, "Cn8eVZg"}
iex> ExBase58.encode("hello", :monero)
{:ok, "Cn8eVZg"}
iex> ExBase58.encode("hello", :ripple)
{:ok, "U83eVZg"}
iex> ExBase58.encode("hello", :flickr)
{:ok, "cM8DuyF"}
iex> ExBase58.encode("hello", :meow)
{:error, :invalid_alphabet}
iex> ExBase58.encode(<<5, 6, 7>>)
{:ok, "2gsG"}
Link to this function
encode_check(binary, version, alphabet \\ :bitcoin)
Specs
encode_check(binary(), non_neg_integer(), alphabet()) :: {:ok, binary()} | {:error, atom()}
Encodes binary into Base58Check format
examples
Examples
iex> ExBase58.encode_check(<<170, 175, 89, 206, 129, 197, 74, 82, 170, 144, 47, 81, 120, 199, 251, 203, 167, 32, 54, 7>>, 0)
{:ok, "1GZVwCXwyKVRPTViubJDVKVhVvcaEoX5cN"}
iex> ExBase58.encode_check(<<170, 175, 89, 206, 129, 197, 74, 82, 170, 144, 47, 81, 120, 199, 251, 203, 167, 32, 54, 7>>, 111)
{:ok, "mw5TEFcvnLvgAZyLdAGbKEi2MvDHF1HXJX"}
iex> ExBase58.encode_check(<<170, 175, 89, 206, 129, 197, 74, 82, 170, 144, 47, 81, 120, 199, 251, 203, 167, 32, 54, 7>>, 111, :ripple)
{:ok, "mAnTNEcv8LvgwZyLdwGbKN5pMvDHErHXJX"}