BSV-ex v0.2.0 BSV.Address View Source

Module for calculating any Bitcoin public or private key's address.

A Bitcoin address is calculated by hashing the public key with both the SHA-256 and then RIPEMD alogrithms. The hash is then Base58Check encoded, resulting in the Bitcoin address.

Link to this section Summary

Types

t()

Extended Private Key

Functions

Returns a Bitcoin address from the given public key.

Returns a Bitcoin address struct from the given address string.

Returns a Base58Check encoded string from the given Bitcoin address struct.

Link to this section Types

Link to this type

t()

View Source
t() :: %BSV.Address{hash: binary(), network: atom(), version_number: term()}

Extended Private Key

Link to this section Functions

Link to this function

from_public_key(public_key, options \\ [])

View Source

Returns a Bitcoin address from the given public key.

Examples

iex> address = BSV.Crypto.ECDSA.PrivateKey.from_sequence(BSV.Test.ecdsa_key)
...> |> BSV.KeyPair.from_ecdsa_key
...> |> BSV.Address.from_public_key
iex> address.__struct__ == BSV.Address
true
Link to this function

from_string(address)

View Source
from_string(binary()) :: BSV.Address.t()

Returns a Bitcoin address struct from the given address string.

Examples

iex> BSV.Address.from_string("15KgnG69mTbtkx73vNDNUdrWuDhnmfCxsf")
%BSV.Address{
  network: :main,
  hash: <<47, 105, 50, 137, 102, 179, 60, 141, 131, 76, 2, 71, 24, 254, 231, 1, 101, 139, 55, 71>>
}
Link to this function

to_string(address)

View Source
to_string(BSV.Address.t()) :: String.t()

Returns a Base58Check encoded string from the given Bitcoin address struct.

Examples

iex> BSV.Test.bsv_keys
...> |> BSV.KeyPair.from_ecdsa_key
...> |> BSV.Address.from_public_key
...> |> BSV.Address.to_string
"15KgnG69mTbtkx73vNDNUdrWuDhnmfCxsf"

iex> BSV.Test.bsv_keys
...> |> BSV.KeyPair.from_ecdsa_key(compressed: false)
...> |> BSV.Address.from_public_key
...> |> BSV.Address.to_string
"13qKCNCBSgcis1TGBgCr2D9qz9iywiYrYd"

iex> BSV.Test.bsv_keys
...> |> BSV.KeyPair.from_ecdsa_key
...> |> BSV.Address.from_public_key(network: :test)
...> |> BSV.Address.to_string
"mjqe5KB8aV39Y4afdwBkJZ4qmDJViTNDLQ"