paulmillr / noble-curves

Audited & minimal JS implementation of elliptic curve cryptography.
https://paulmillr.com/noble
MIT License
664 stars 62 forks source link

recoverPublicKey compatibility #41

Closed huckym closed 1 year ago

huckym commented 1 year ago

I am creating a signature (for an ethereum transaction) using the secp256K1 curve from this library. Checking the recovered public key from the hash and signature using this library itself always gives me the same public key I expect. All good so far,

But using the ethers library (v6.3.0) to create a signed transaction with the signature created by this library only occasionally gives the same public key. It also gives other public keys in a seemingly non-deterministic fashion (when I set extraEntropy to true). I see that the latest ethers library is still dependent on the old version "@noble/secp256k1": "1.7.1" for the public key recovery.

Are the new and old version of secp256k1 incompatible from this perspective?

paulmillr commented 1 year ago

no, they are compatible. you are doing something wrong. I can't provide any guidance without a code from your end.

huckym commented 1 year ago

Sorry, it was my incorrect assumption. Ethers library is assuming a lowS signature with the MSB of S encoding the recoveryBit in its Signature constructor

I was assuming the addRecoveryBit in this library was setting that bit but now see that it is a separate property.

paulmillr commented 1 year ago

Thanks for the sponsorship Hakim, really appreciate!

huckym commented 1 year ago

Thank you for all your wonderful open-source contributions!