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

Error: Signature without r or s #65

Closed
bolzon opened this issue Jan 7, 2016 · 3 comments
Closed

Error: Signature without r or s #65

bolzon opened this issue Jan 7, 2016 · 3 comments

Comments

@bolzon
Copy link
Contributor

bolzon commented Jan 7, 2016

I want to verify a message.
I have the message, signature and public key, but no private key.

When verifying the message, I get the error: Signature without r or s

Public key format is: '04' + X + Y
Signature format is: R + S
Both in hex.

Am I doing something wrong or is this a bug?

My code:

var msg = '...'; // hidden
var pubKey = '04e6f90994768e51c2834879841542992494b9030e1b765e766f8b60a56213fb9f91903ee24f6baaaaf6afbce3adcfbc4362c1e1e21218ed3f1be6317908db3323';
var signature = 'b32911bfd9f88ae4a0c337df2c0f254d2232a162b85ce3019c2ae7cb1f56f06b525b4813557ace1e6f2f2080e77dd49ecec49d030a4fa23854880e696e941344';

var ecdsa = new elliptic.ec('p256');
var res = ecdsa.verify(msg, signature, pubKey, 'hex'); // throws exception

I've tried to use the ec/Signature class to load this, but no success too.

Thanks.

@indutny
Copy link
Owner

indutny commented Jan 7, 2016

I'm afraid elliptic does not understand this format. Try splitting signature by halves an pass it as an object:

{ r: '...', s: '...' }

I think it should work this way!

@indutny
Copy link
Owner

indutny commented Jan 7, 2016

And if it works - would you mind helping me to fix the documentation to make it more evident?

@bolzon
Copy link
Contributor Author

bolzon commented Jan 7, 2016

Wonderful. Worked perfectly, thanks!

var pubKey = '04e6f90994768e51c2834879841542992494b9030e1b765e766f8b60a56213fb9f91903ee24f6baaaaf6afbce3adcfbc4362c1e1e21218ed3f1be6317908db3323';
var signature = 'b32911bfd9f88ae4a0c337df2c0f254d2232a162b85ce3019c2ae7cb1f56f06b525b4813557ace1e6f2f2080e77dd49ecec49d030a4fa23854880e696e941344';

var msg = '...'; // sth secret
var m = signature.match(/([a-f\d]{64})/gi);

signature = {
  r: m[0],
  s: m[1]
};

var ecdsa = new elliptic.ec('p256');
var res = ecdsa.verify(msg, signature, pubKey, 'hex');

I'll add this to the documentation.
Thanks again!

@bolzon bolzon closed this as completed Jan 22, 2016
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

No branches or pull requests

2 participants