lian / bitcoin-ruby

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

Support TxOut when verifying an input sig #224

Closed jakecraige closed 6 years ago

jakecraige commented 6 years ago

Support TxOut when verifying an input sig

This adds support providing a TxOut when verifying an input signature.

This is useful in one of our use cases where we need to sign a transaction but only have enough information to craft a TxOut, not a full Tx. Since that provides the same information as the Tx does, this option now supports that.

Because the duck-typing was used in a few places I extracted it out to a method than can be used in a multiple places.

Verify sig length before parsing

When verifying an incomplete multisig transaction, we end up with a list of drop_sigs like so:

["", "0E\x02!\x00\xF6#\x00\xC1\xA7\xB5l[\xD4y}\x93\xDEV\xD5\xAB\x83TT\x0FYr?J\xB3\x88\xD0=$\xD3\x127\x02 6\xAB\xED7+5V\xE3\xBB\xA0UK\xB9}\x8F\xC8Pf\xC5\x84zo\x12?\xB6\x1D]Sr\x9A\x83\xE5\x01"]

This resolves a bug where we attempted to parse it which would raise in the parse_sig method. We now reject the sig unless it's present.

zquestz commented 6 years ago

Change looks good, but can we come up with some nicer function names? script_pubkey_from_outpoint_tx_or_tx_out_or_script is rather outrageous.

jakecraige commented 6 years ago

@zquestz agreed. Any recommendations? Ideally there's be some word to shorten outpoint_tx_or_tx_out_or_script to which would help in a few places in this file.

Maybe something like outpoint_info and update the comment to describe it's available values?

zquestz commented 6 years ago

@jakecraige I like that, seems reasonable to me. Maybe output_data.

etscrivner commented 6 years ago

LGTM