ExBech32 (ExBech32 v0.1.0)

Nif for Bech32 format encoding and decoding.

It uses https://github.com/rust-bitcoin/rust-bech32 rust library

Link to this section Summary

Functions

Decodes bech32 decoded string

Encodes into Bech32 format

Link to this section Functions

Link to this function

decode(encoded)

Specs

decode(String.t()) :: {:ok, {String.t(), binary(), atom()}} | {:error, atom()}

Decodes bech32 decoded string

Examples

iex> ExBech32.decode("bech321qqqsyrhqy2a")
{:ok, {"bech32", <<0, 1, 2>>, :bech32}}

iex> ExBech32.decode("bech32m1qqqsyy9kzpq")
{:ok, {"bech32m", <<0, 1, 2>>, :bech32m}}
Link to this function

encode(hrp, data, variant \\ :bech32)

Specs

encode(String.t(), binary(), atom()) :: {:ok, String.t()} | {:error, atom()}

Encodes into Bech32 format

It accepts the following three paramters:

  • human-readable part
  • data to be encoded
  • bech32 variant. it can be :bech32 (BIP-0173) or :bech32m (BIP-0350)

Examples

iex> ExBech32.encode("bech32", <<0, 1, 2>>)
{:ok, "bech321qqqsyrhqy2a"}

iex> ExBech32.encode("bech32m", <<0, 1, 2>>, :bech32m)
{:ok, "bech32m1qqqsyy9kzpq"}