View Source BitcoinLib.Key.HD.DerivationPath (BitcoinLib v0.4.7)

Can parse derivation paths string format into a native format

m / purpose' / network' / account' / change / address_index

Inspired by

https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki https://learnmeabitcoin.com/technical/derivation-paths

Link to this section Summary

Functions

Turns a list of path values into a %DerivationPath{}

Retruns a %DerivationPath from a set of parameters, with these values potentially missing: network, account, change, address_index

Transforms a derivation path string into an elixir structure

Link to this section Types

@type t() :: BitcoinLib.Key.HD.DerivationPath

Link to this section Functions

@spec from_list(list()) :: t()

Turns a list of path values into a %DerivationPath{}

examples

Examples

iex> ["m", 0x80000054, 0x80000000, 0x80000005]
...> |> BitcoinLib.Key.HD.DerivationPath.from_list
%BitcoinLib.Key.HD.DerivationPath{
  type: :private,
  purpose: :bip84,
  network: :mainnet,
  account: 5
}
Link to this function

from_values(type, purpose, network \\ nil, account \\ nil, change \\ nil, address_index \\ nil)

View Source
@spec from_values(
  binary(),
  integer(),
  integer() | nil,
  integer() | nil,
  integer() | nil,
  integer() | nil
) :: t()

Retruns a %DerivationPath from a set of parameters, with these values potentially missing: network, account, change, address_index

examples

Examples

iex> BitcoinLib.Key.HD.DerivationPath.from_values("M", 0x80000054, 0x80000000, 0x80000000, 0, 0)
%BitcoinLib.Key.HD.DerivationPath{
  type: :public,
  purpose: :bip84,
  network: :mainnet,
  account: 0,
  change: :receiving_chain,
  address_index: 0
}
@spec parse(binary()) :: {:ok, t()}

Transforms a derivation path string into an elixir structure

examples

Examples

iex> "m / 44' / 1' / 2' / 1 / 4"
...> |> BitcoinLib.Key.HD.DerivationPath.parse()
{ :ok,
  %BitcoinLib.Key.HD.DerivationPath{
    type: :private,
    purpose: :bip44,
    network: :testnet,
    account: 2,
    change: :change_chain,
    address_index: 4
  }
}