I have a Ravencoin (bitcoin fork) wallet written in python that I want to talk to an Elixir server. The wallet has a pubkey and an address (derived from the pubkey) and the ability to sign things. The server needs the ability to verify the signature - that's what I can't get to work.
I’ve tried to consult these resources but am unable to get it to work
- https://elixirforum.com/t/right-way-to-use-crypto-verify/19014
- https://github.com/ntrepid8/ex_crypto
- https://hexdocs.pm/web3x/0.6.3/Web3x.Wallet.html#verify_message?/4
- https://blog.lelonek.me/how-to-calculate-bitcoin-address-in-elixir-68939af4f0e9
- https://hexdocs.pm/curvy/Curvy.html
The last two links looked very promising. But I've been unable to verify the signature of a signed message.
For example here's how the Python side of things works:
>>> import wallet
>>> w = wallet.Wallet()
>>> w.generate()
>>> w
Wallet(
publicKey: 034e328758d422ce5c3a17c15528df1216ef0eaf845147876eea82d139755129a0
privateKey: L16mQdokXV8hVxGc8su2z9xNkavWPdGGM92B6nt2bMj8yhjTCF8Z
words: inherit daring dish like invite vehicle spy depth average cross industry cat want warm deliver foster approve buddy hand often sword arch dress photo
address: RMK1yBucDCJXjppB7bkZ4dMoZqr3ZKgztN
scripthash: 8c6a2e84bee5cbbffdb0d1188f6f8fbfd422cafcfdaecb5f6251e32d0a4accc5
balance: None
stats: None
banner: None)
>>> w.sign("message")
b'IFdGdzqI9fJJDbTASGbamHFQ7hlIT07jLALhYRhMrRY3QvKJuL2q8ojtwKsubj0EVtWJtlM8MbgmpvIaKwpjc04='
>>> w.verify("message", w.sign("message"))
True
I can then take that signature and copy it over to my elixir repl to try to to do the verification:
iex(2)> :crypto.verify(:ecdsa, :sha256, "message",
"IFdGdzqI9fJJDbTASGbamHFQ7hlIT07jLALhYRhMrRY3QvKJuL2q8ojtwKsubj0EVtWJtlM8MbgmpvIaKwpjc04=",
["034e328758d422ce5c3a17c15528df1216ef0eaf845147876eea82d139755129a0", :secp256k1])
false
Some times (like on the python wallet) the verification uses the address in place of the public_key
so I can try that too:
iex(3)> :crypto.verify(:ecdsa, :sha256, "message",
"IFdGdzqI9fJJDbTASGbamHFQ7hlIT07jLALhYRhMrRY3QvKJuL2q8ojtwKsubj0EVtWJtlM8MbgmpvIaKwpjc04=",
["RMK1yBucDCJXjppB7bkZ4dMoZqr3ZKgztN", :secp256k1])
false
So I wondered, is it a problem with strings vs byte data? Am I supposed to convert something into the right format? Or maybe it's the other arguments of verify? I'll keep looking, but do you see anything wrong with it right away?
:crypto
, to make sure you're using the correct parameters. Yes, you need to decode the key withBase.decode16!/2
and the signature withBase.decode64!/2
, but even doing so the signature doesn't verify with those parameters.