chaintope / bitcoinrb

The implementation of the bitcoin protocol for ruby.
MIT License
62 stars 19 forks source link

Bitcoin::MessageSign.verify_message doesn't verify segwit bech32 address #64

Closed vasaf closed 1 year ago

vasaf commented 3 years ago

When using Bitcoin::MessageSign.verify_message to verify segwit bech32 (bitcoin address beginning with bc1), an error Address has no key is thrown. No issues with legacy address.

What would be the direction to have this working with the newer addresses?

Thanks 👍

azuchi commented 3 years ago

bitcoinrb currently only supports message signing using P2PKH addresses, like Bitcoin Core.

Message signing using bech32 addresses has been proposed as BIP-322, but it has not been widely adopted yet. If a Test Vector for this BIP is available, it may be implemented in bitcoinrb.

azuchi commented 1 year ago

Sorry for the delay, we can now create BIP-322 based signatures like bellow:

private_key = Bitcoin::Key.from_wif('L3VFeEujGtevx9w18HD1fhRbCH67Az2dpCymeRE1SoPK6XQtaN2k')
addr = private_key.to_p2wpkh # bc1q9vza2e8x573nczrlzms0wvx3gsqjx7vavgkx0l

signature = Bitcoin::MessageSign.sign_message(
        private_key,
        'message',
        format: Bitcoin::MessageSign::FORMAT_SIMPLE,
        address: addr)