I'm trying to write a sign function in Ruby for Ethereum using secp256k1.
I have access to this sign_compact function which seems to be for Bitcoin:
https://github.com/lian/bitcoin-ruby/blob/master/lib/bitcoin/ffi/secp256k1.rb#L207-L232
I'm trying to use this to sign for Ethereum but there seems to be some steps missing. Specifically, something to do with the head, r-value and s-value. Someone seems to be doing this properly using OpenSSL instead of secp256k1 here:
https://github.com/se3000/ruby-eth/blob/master/lib/eth/open_ssl.rb#L58-L97
The lines that seem to be different are:
if signature.get_array_of_pointer(0, 2).all?{|i| BN_num_bits(i) <= 256 }
4.times{|i|
head = [ Eth.v_base + i ].pack("C")
if public_key_hex == recover_public_key_from_signature(hash, [head, r, s].join, i, pubkey_compressed)
rec_id = i; break
end
}
end
How would I go about using the secp256k1 sign_compact function to sign Ethereum messages? Is there something I need to change for the signature? Or is there somewhere to find the protocol for this?