isValidSchnorrSignature static method

bool isValidSchnorrSignature(
  1. List<int> signature
)

Whether signature has a valid Schnorr signature shape (r, s in range).

Accepts 64-byte (r || s) signatures; a trailing 65th byte (e.g. a recovery id) is ignored.

Implementation

static bool isValidSchnorrSignature(List<int> signature) {
  if (signature.length != CryptoSignerConst.schnorrSignatureLength &&
      signature.length != CryptoSignerConst.schnorrSignatureLength + 1) {
    return false;
  }

  try {
    Secp256k1Fp.fromBytes(signature.sublist(0, 32));
    Secp256k1Fr.fromBytes(signature.sublist(32, 64));
  } catch (_) {
    return false;
  }
  return true;
}