libitx / bsv-ex

Elixir toolset for building Bitcoin applications
https://hexdocs.pm/bsv
Apache License 2.0
28 stars 8 forks source link

Support for `tprv` keys #15

Open afomi opened 8 months ago

afomi commented 8 months ago

Noticed something when using the library on test net and wanted to run it by you, @libitx, before working on a PR.

mnemonic = BSV.Mnemonic.new(128)
seed = BSV.Mnemonic.to_seed(mnemonic)
extkey = BSV.ExtKey.from_seed!(seed)
xprv = extkey |> BSV.ExtKey.to_string
BSV.ExtKey.from_string(xprv)

raises

** (FunctionClauseError) no function clause matching in BSV.ExtKey.from_string/1

Am I missing something regarding test keys; support for tprv and tpub. Would an addition be valid?

libitx commented 8 months ago

You're not missing anything - it's a bug.

The from_string implementations need to match against trpv and tpub, maybe something like:

def from_string(<<pre::binary-4, _::binary>> = xprv) when pre in ["xprv", "tprv"] do

I'm not working on bsv projects at the moment but will accept a PR for this if you have time.

libitx commented 8 months ago

Or even this would do tbh...

def from_string(<<_ , "prv", _::binary>> = xprv) do