verify function
Implementation
bool verify(List<int> msg, BigInt? sigR, BigInt? sigS, List<int> key) {
bool isZero(BigInt test) =>
test.compareTo(BigInt.from(0)) != 0 ? false : true;
bool isGteCurve(BigInt test) => test.compareTo(params.n) > 1 ? true : false;
var sig = new SchnorrSignature(sigR, sigS);
if (isZero(sig.s!) || isZero(sig.r!)) {
throw 'Invalid signature';
}
if (sig.s!.isNegative || sig.r!.isNegative) {
throw 'Invalid signature';
}
if (isGteCurve(sig.s!) || isGteCurve(sig.r!)) {
throw 'Invalid signature';
}
ECPoint kpub = params.curve.decodePoint(key)!;
///
/// if (!curve.validate(kpub)) {
/// throw new Error('Invalid public key')
/// }
///
ECPoint l = (kpub * (sig.r))!;
ECPoint? r = params.G * (sig.s);
ECPoint Q = (l + r)!;
if (Q.isInfinity) {
throw 'Invalid intermediate point.';
}
BigInt compressedQ = numbers.bytesToInt(Q.getEncoded());
BigInt r1 = hash(compressedQ, key, msg) % (params.n);
if (isZero(r1)) {
throw 'Invalid hash.';
}
return r1 == sig.r;
}