Closed mahdiyari closed 4 months ago
This issue originally happened to me using noble-secp256k1
so I used this library instead as part of debugging.
Am I doing something wrong?
yes: you are using buffer instead of uint8array
why are you using rv.r.toString(16)? we have perfectly fine toCompact and toDER methods
why are you using isCanonicalSignature if we have lowS option in verify
why are you passing R as third recovery argument to Signature constructor?
why are you passing R as third recovery argument to Signature constructor?
that's not R, that's recovery. Bad naming. I did remove Buffer and used hex string and still the same issue.
yeah you are still using tostring(16)
I did merge r + s together then I separate them later. The code doesn't seem wrong to me as the values before merge and after separation were identical. The code works but it fails sometimes. That's why it got me.
I can't reproduce the issue without using Buffer and not using tostring(16).
Thanks. Much appreciate it.
tostring 16 creates unpadded hex, so 000123 would become 0123, kudos
tostring 16 creates unpadded hex, so 000123 would become 0123, kudos
It all makes sense now. Thanks again. :pray:
This issue is weird as it happens randomly. The public key retrieved from the signature doesn't match the original public key. And it happens randomly. I did write the following snippet to reproduce the issue.
The
for
at the end breaks whenever the public keys are not matched. You can logi
too and it happens very early. Tested on node v20, v18, v16Sometimes it will throw
Error: Cannot find square root
Am I doing something wrong?