noble-secp256k1
noble-secp256k1 copied to clipboard
Add isValidPublicKey?
Need to understand if it'll be used anywhere in scure/bip32, micro-signers, etc
isValidPublicKey(publicKey: Hex, type: 'ecdsa' | 'schnorr') {
const arr = ensureBytes(publicKey);
const len = arr.length;
if (type === 'ecdsa') {
if (len === 32) throw new Error('Expected non-Schnorr key');
} else if (type === 'schnorr') {
if (len !== 32) throw new Error('Expected 32-byte Schnorr key');
} else {
throw new Error('Unknown key type')
}
Point.fromHex(publicKey); // does assertValidity
return true;
},
or maybe ban schnorr in fromHex
and add new method for fromHexSchnorr
I'm migrating a project to noble ones and this function is missing, so it would be great for it to be added. In the meantime, will the code you linked above work?
Point.fromHex does all the validation you need yeah