Tezex.Crypto.Base58Check (tezex v6.0.0)

Copy Markdown View Source

Base58Check encoding/decoding utils

Summary

Functions

Decodes the given string.

Decodes a Base58Check string and verifies its checksum. Returns the prefix and the payload, without the checksum.

Prepends prefix to payload, computes its checksum (double sha256) and encodes in Base58.

Functions

decode58(encoded)

decode58!(encoded)

@spec decode58!(binary()) :: binary()

Decodes the given string.

Examples

iex> decode58!("1")
<<0>>
iex> decode58!("z")
<<57>>
iex> decode58!("Jf")
:binary.encode_unsigned(1024)
iex> decode58!("BukQL")
:binary.encode_unsigned(123_456_789)

decode58check!(encoded)

@spec decode58check!(binary()) :: binary()

See Base58Check.decode58check!/1.

decode_check(encoded)

@spec decode_check(binary()) :: {:ok, binary()} | :error

Decodes a Base58Check string and verifies its checksum. Returns the prefix and the payload, without the checksum.

Examples

iex> decode_check("tz3bPFa6mGv8m4Ppn7w5KSDyAbEPwbJNpC9p")
{:ok, <<6, 161, 164, 165, 37, 29, 103, 204, 101, 232, 200, 87, 148, 178, 91, 43, 72, 191, 252, 190, 134, 75, 170>>}
iex> decode_check("tz3bPFa6mGv8m4Ppn7w5KSDyAbEPwbJNpC9q")
:error

encode(payload, prefix)

@spec encode(binary(), binary()) :: nonempty_binary()

Prepends prefix to payload, computes its checksum (double sha256) and encodes in Base58.

Examples

iex> encode(<<165, 37, 29, 103, 204, 101, 232, 200, 87, 148, 178, 91, 43, 72, 191, 252, 190, 134, 75, 170>>, <<6, 161, 164>>)
"tz3bPFa6mGv8m4Ppn7w5KSDyAbEPwbJNpC9p"