noble-curves
noble-curves copied to clipboard
v2: recoverPublicKey should return bytes
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}`);
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.