SegwitAddr (bip0173 v0.2.0)
Encode and decode BIP-0173 and BIP-0350 compliant SegWit addresses.
Link to this section Summary
Types
Segregated witness program version
Functions
Decode a SegWit address.
Encode a SegWit address.
Encode a witness program into a hexadecimal ScriptPubKey.
Link to this section Types
Link to this type
segwit_version_t()
Specs
segwit_version_t() :: 0..16
Segregated witness program version
Link to this section Functions
Link to this function
decode(addr)
Specs
decode(String.t()) :: {:ok, {String.t(), segwit_version_t(), [byte()]}} | {:error, String.t()}
Decode a SegWit address.
Examples
iex> SegwitAddr.decode("bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4")
{:ok, {"bc", 0, [117, 30, 118, 232, 25, 145, 150, 212,
84, 148, 28, 69, 209, 179, 163, 35, 241, 67, 59, 214]}}
Link to this function
encode(hrp, program)
Specs
Link to this function
encode(hrp, version, program)
Specs
encode(String.t(), segwit_version_t(), [byte()]) :: String.t()
Encode a SegWit address.
Examples
iex> SegwitAddr.encode("bc", "0014751e76e8199196d454941c45d1b3a323f1433bd6")
"bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4"
iex> SegwitAddr.encode("bc", 0, [117, 30, 118, 232, 25, 145, 150, 212,
...> 84, 148, 28, 69, 209, 179, 163, 35, 241, 67, 59, 214])
"bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4"
Link to this function
to_script_pub_key(version, program)
Specs
to_script_pub_key(segwit_version_t(), [byte()]) :: String.t()
Encode a witness program into a hexadecimal ScriptPubKey.
Examples
iex> SegwitAddr.to_script_pub_key(0, [117, 30, 118, 232, 25, 145, 150,
...> 212, 84, 148, 28, 69, 209, 179, 163, 35, 241, 67, 59, 214])
"0014751e76e8199196d454941c45d1b3a323f1433bd6"