lian / bitcoin-ruby

bitcoin utils and protocol in ruby.
Other
922 stars 322 forks source link

Cant import private keys from bip32 #233

Closed SFzxc closed 6 years ago

SFzxc commented 6 years ago

Excuse me, but i tried in long time but i dont know how to import key from bip32 look like this Bitcoin::Key.from_bip32 is there bitcoin-ruby support this type ?!, Many thanks

azuchi commented 6 years ago

You can import BIP-32 extended public and private keys by following.

priv_key = Bitcoin::ExtKey.from_base58('xprv...') # returns Bitcoin::ExtKey object.

pub_key = Bitcoin::ExtPubkey.from_base58('xpub...') # returns Bitcoin::ExtPubkey object.
SFzxc commented 6 years ago

Thanks @azuchi -san for supporting. I tried to get private key and public by cmds master_node.node_for_path(path).private_key.to_hex c02a193bcbe56a429b66ab73e388e4ca60f814c0c2....... master_node.node_for_path(path).public_key.to_hex 03e90ab62379fd58dbc7f06b66bcacfc68bed06d622c6de540c45f360e7ceec4ce and follow your guide

priv_key = Bitcoin::ExtKey.from_base58('c02a193bcbe56a429b66ab73e388e4ca60f814c0c2.......') # returns Bitcoin::ExtKey object.

pub_key = Bitcoin::ExtPubkey.from_base58('03e90ab62379fd58dbc7f06b66bcacfc68bed06d622c6de540c45f360e7ceec4ce') # returns Bitcoin::ExtPubkey object.

It returned

ArgumentError: Value not a valid Base58 String.
.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bitcoin-ruby-0.0.13/lib/bitcoin.rb:129:in `block in base58_to_int'

i dont know is that correct xprv and xpub type or not. Looking for your advise, Arigato!

SFzxc commented 6 years ago

Sorry, my mistake, it should be master_node.node_for_path(path).to_bip32(:private), master_node.node_for_path(path).to_bip32(:public)

SFzxc commented 6 years ago

Thanks you so much @azuchi -san, i close this issue