BIP-32 hierarchical deterministic (HD) extended keys.
Supports creating master keys from a seed (or mnemonic), deriving child keys
via derivation paths (e.g. "m/44'/0'/0'/0/0"), and serializing to/from
xprv/xpub format.
Examples
iex> {:ok, master} = BSV.ExtKey.from_seed(<<0::512>>)
iex> master.depth
0
iex> child = BSV.ExtKey.derive(master, "m/44'/0'/0'")
iex> child.depth
3
Summary
Functions
Derive a child key from a derivation path.
Create a master extended key from a binary seed (16–64 bytes).
As from_seed/2 but raises on error.
Decode an xprv or xpub string into an extended key.
As from_string/1 but raises on error.
Generate a new random master extended key.
Convert an extended private key to its public counterpart (drops the private key).
Serialize an extended key to xprv/xpub string.
Types
@type derivation_path() :: String.t()
BIP-32 derivation path
@type t() :: %BSV.ExtKey{ chain_code: <<_::256>>, child_index: non_neg_integer(), depth: non_neg_integer(), fingerprint: <<_::32>>, privkey: BSV.PrivateKey.t() | nil, pubkey: BSV.PublicKey.t(), version: binary() }
Extended key
@type xprv() :: String.t()
Serialized xprv string
@type xpub() :: String.t()
Serialized xpub string
Functions
@spec derive(t(), derivation_path()) :: t()
Derive a child key from a derivation path.
Paths follow BIP-32 format: "m/44'/0'/0'/0/0" for private derivation,
"M/44'/0'/0'/0/0" for public derivation.
Hardened indices use ' suffix. Hardened public derivation is not possible.
Create a master extended key from a binary seed (16–64 bytes).
Typically the seed comes from BSV.Mnemonic.to_seed/2.
As from_seed/2 but raises on error.
Decode an xprv or xpub string into an extended key.
As from_string/1 but raises on error.
@spec new() :: t()
Generate a new random master extended key.
Convert an extended private key to its public counterpart (drops the private key).
Serialize an extended key to xprv/xpub string.