Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ecdsa sign would return r as a BN.js instance #3817

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

r4mmer
Copy link

@r4mmer r4mmer commented Nov 1, 2024

Description

The Q.x would return a BN without bitcore-lib's methods, this is avoided by calling getX instead which converts to the appropriate instance.

@kajoseph
Copy link
Collaborator

kajoseph commented Nov 5, 2024

Q.x is an instance of ./bn.js since ./bn.js is a monkey patch of the dependency bn.js. At the point of your change Q.x instanceof BN is true and has the monkey patched methods on it. What's your usage?

@r4mmer
Copy link
Author

r4mmer commented Dec 19, 2024

Hi @kajoseph ! Sorry for the delayed response.
We use bitcore-lib on a react-native environment and we also need some node apis so we use rn-nodeify for the patches.

The actual issue is a bit complicated, but we use the message sign to validate that the owner of the private key is sending the message.

The validation of the signed message would fail, we tracked the issue to this line this.r.toBuffer({ size: 32 }) since the buffer returned here was not 32 bytes long, after some investigation we saw that it is because r = Q.x.umod(N); is actually a bn.js instance and not a ./bn.js instance.

The actual issue is that the BN.toBuffer ignores the size argument as you can see below.
image

This makes the verify method fail since it tries to read exactly 32 bytes for the r and s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants