noble-secp256k1 icon indicating copy to clipboard operation
noble-secp256k1 copied to clipboard

Add isValidPublicKey?

Open paulmillr opened this issue 2 years ago • 1 comments

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;
  },

paulmillr avatar Sep 10 '22 14:09 paulmillr

or maybe ban schnorr in fromHex and add new method for fromHexSchnorr

paulmillr avatar Sep 11 '22 15:09 paulmillr

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?

tre-dev avatar Dec 21 '22 18:12 tre-dev

Point.fromHex does all the validation you need yeah

paulmillr avatar Dec 21 '22 18:12 paulmillr