View Source BitcoinLib.Key.Address (BitcoinLib v0.2.0-pre1)

Bitcoin address management

Inspired by https://learnmeabitcoin.com/technical/public-key-hash

Link to this section Summary

Functions

Convert public key hash into a P2PKH Bitcoin address.

Extracts the public key hash from an address, and make sure the checkum is ok

Link to this section Functions

Link to this function

from_public_key_hash(public_key_hash, address_type \\ :p2sh, network \\ :mainnet)

View Source
@spec from_public_key_hash(binary(), :p2pkh | :p2sh, :mainnet | :testnet) ::
  bitstring()

Convert public key hash into a P2PKH Bitcoin address.

Details can be found here: https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses

examples

Examples

iex> <<0x6ae201797de3fa7d1d95510f50c1a9c50ce4cc36::160>> ...> |> BitcoinLib.Key.Address.from_public_key_hash(:p2pkh) "1Ak9NVPmwCHEpsSWvM6cNRC7dsYniRmwMG"

Link to this function

to_public_key_hash(address)

View Source
@spec to_public_key_hash(binary()) :: {:ok, <<_::160>>, atom()} | {:error, binary()}

Extracts the public key hash from an address, and make sure the checkum is ok

examples

Examples

iex> address = "mwYKDe7uJcgqyVHJAPURddeZvM5zBVQj5L" ...> BitcoinLib.Key.Address.to_public_key_hash(address)