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

v2: recoverPublicKey should return bytes #60

Open
rube-de opened this issue Jun 25, 2023 · 1 comment
Open

v2: recoverPublicKey should return bytes #60

rube-de opened this issue Jun 25, 2023 · 1 comment

Comments

@rube-de
Copy link

rube-de commented Jun 25, 2023

I tried to run the example from the README to recover the public key from a signature
sig.recoverPublicKey(msg) === pub; // public key recovery
which results actually as false.

I saw in the test the secp256k1.getPublicKey(priv); gets wrapped into a Point object
const publicKey = Point.fromHex(secp.getPublicKey(privateKey)).toHex(false);
which isn't that expected using the library.

I would expect to get an Uint8Array back when calling sig.recoverPublicKey(msg)

Test code:

const { secp256k1 } = require("@noble/curves/secp256k1");

const priv = secp256k1.utils.randomPrivateKey();
const pub = secp256k1.getPublicKey(priv);
console.log(`pub: ${pub}`);
const msg = new Uint8Array(32).fill(1);
const sig = secp256k1.sign(msg, priv);
const isValid = secp256k1.verify(sig, msg, pub) === true;
console.log(`isValid: ${isValid}`);
const recoverPub = sig.recoverPublicKey(msg);
console.log(`recoverPub: ${recoverPub}`);
const isRecoverValid = sig.recoverPublicKey(msg) === pub;
console.log(`isRecoverValid: ${isRecoverValid}`);
@paulmillr
Copy link
Owner

I kinda agree, but we're stuck with the current type for a long time, until next major version. Which will probably need re-audit, etc.

Updating docs seems like a nice idea.

@paulmillr paulmillr changed the title Unexpected return type for sig.recoverPublicKey(msg) v2: recoverPublicKey should return bytes or hex Nov 10, 2023
@paulmillr paulmillr changed the title v2: recoverPublicKey should return bytes or hex v2: recoverPublicKey should return bytes Nov 10, 2023
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