etscrivner / rbsecp256k1

Compiled Ruby wrapper around libsecp256k1 for secp256k1 ECDSA.
The Unlicense
19 stars 13 forks source link

sign_schnorr(): Remove 32 byte restriction on the message to be signed #80

Open rickhull opened 6 months ago

rickhull commented 6 months ago

https://bips.xyz/340#changelog

Allow messages of arbitrary size

Test case:

require 'rbsecp256k1'

context = Secp256k1::Context.create
kp = context.generate_key_pair

baby_bear = 'baby bear'
mama_bear = 'mama bear'.ljust(32, ' ')
papa_bear = 'papa bear' * 99

p context.sign_schnorr(kp, mama_bear)
p context.sign_schnorr(kp, baby_bear)
p context.sign_schnorr(kp, papa_bear)

Result:

#<Secp256k1::SchnorrSignature:0x00007f5fd41abd38>
/home/rwh/.local/share/gem/ruby/3.3.0/gems/rbsecp256k1-6.0.0/lib/rbsecp256k1/context.rb:33:in `sign_schnorr_custom': schnorr signing message must be 32-bytes in length (Secp256k1::Error)
        from /home/rwh/.local/share/gem/ruby/3.3.0/gems/rbsecp256k1-6.0.0/lib/rbsecp256k1/context.rb:33:in `sign_schnorr'
        from test_case.rb:11:in `<main>'
etscrivner commented 6 months ago

Will give this a look next week as I have time, but initially this should be a quick fix.