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

Can parse derivation paths string format into a native format

m / purpose' / coin_type' / 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: coin_type, account, change, address_index

Transforms a derivation path string into an elixir structure

Link to this section Functions

@spec from_list(list()) :: %BitcoinLib.Key.HD.DerivationPath{
  account: term(),
  address_index: term(),
  change: term(),
  coin_type: term(),
  purpose: term(),
  type: term()
}

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,
  coin_type: :bitcoin,
  account: 5
}
Link to this function

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

View Source
@spec from_values(
  binary(),
  integer(),
  integer() | nil,
  integer() | nil,
  integer() | nil,
  integer() | nil
) :: %BitcoinLib.Key.HD.DerivationPath{
  account: term(),
  address_index: term(),
  change: term(),
  coin_type: term(),
  purpose: term(),
  type: term()
}

Retruns a %DerivationPath from a set of parameters, with these values potentially missing: coin_type, 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,
  coin_type: :bitcoin,
  account: 0,
  change: :receiving_chain,
  address_index: 0
}
@spec parse(binary()) ::
  {:ok,
   %BitcoinLib.Key.HD.DerivationPath{
     account: term(),
     address_index: term(),
     change: term(),
     coin_type: term(),
     purpose: term(),
     type: term()
   }}

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,
    coin_type: :bitcoin_testnet,
    account: 2,
    change: :change_chain,
    address_index: 4
  }
}