bsv-ex icon indicating copy to clipboard operation
bsv-ex copied to clipboard

Support for `tprv` keys

Open afomi opened this issue 5 months ago • 2 comments

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?

afomi avatar Jan 23 '24 17:01 afomi

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 avatar Feb 02 '24 17:02 libitx

Or even this would do tbh...

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

libitx avatar Feb 02 '24 17:02 libitx