lian / bitcoin-ruby

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

undefined method `dsa_sign_asn1' #317

Closed deflexor closed 2 years ago

deflexor commented 2 years ago

Hi, geeting this error when try to create transaction as in examples/generate_tx.rb

``Undefined methoddsa_sign_asn1' for # Backtrace:
.../versions/2.6.3/lib/ruby/gems/2.6.0/bundler/gems/bitcoin-ruby-f9b817c946b3/lib/bitcoin.rb:379:in `block in sign_data'

azuchi commented 2 years ago

dsa_sign_asn1 is a method of OpenSSL::PKey::EC. The error seems to be calling dsa_sign_asn1 for Bitcoin::Key.

In the sample, the

key = Bitcoin.open_key("9b2f08ebc186d435ffc1d10f3627f05ce4b983b72c76b0aee4fcce99e57b0342")

with Bitcoin.sign_data as the argument. This key is OpenSSL::PKey::EC. Are you accidentally passing Bitcoin::Key?

deflexor commented 2 years ago

I passing key this way:

key = Bitcoin::Key.generate
// save key to file
save_string_to_file(key.to_base58)
recovered_key = Bitcoin::Key.from_base58(read_string_from_file)

So this recovered_key is what i'm passing.

azuchi commented 2 years ago

Bitcoin::Key.from_base58 returns Bitcoin::Key itself, so you need to use recovered_key.sing(data) instead of Bitcoin.sign_data(recovered_key, data).

deflexor commented 2 years ago

Oh, thank you, that worked.