verifyWithPoint function

bool verifyWithPoint(
  1. ECPoint P,
  2. String message,
  3. String signature
)

Implementation

bool verifyWithPoint(ECPoint P, String message, String signature) {
  final List<int> bmessage = hex.decode(message, 0, 64);

  // signature = signature.padLeft(128, '0');
  final r = hex.decode(signature, 0, 64);
  final r_num = BigInt.parse(signature.substring(0, 64), radix: 16);
  final s_num = BigInt.parse(signature.substring(64, 128), radix: 16);
  if (r_num >= curveP || s_num >= secp256k1.n) {
    return false;
  }

  // not sure what these things mean
  BigInt e = getE(P, r, bmessage);
  ECPoint sG = (secp256k1.G * s_num)!;
  ECPoint eP_ = (P * e)!;
  BigInt ePy = curveP - eP_.y!.toBigInteger()!;
  ECPoint eP = secp256k1.curve.createPoint(eP_.x!.toBigInteger()!, ePy);

  // R is something important
  final ECPoint R = (sG + eP)!;
  if (R.isInfinity) {
    return false;
  }

  // now that we have R we get its coords
  final Rx = R.x!.toBigInteger()!;
  final Ry = R.y!.toBigInteger();

  // and we them in these checks which I don't understand
  if ((Rx.sign == 0 && Ry!.sign == 0) ||
      (Ry! % BigInt.two != BigInt.zero /* is odd */) ||
      (Rx != r_num)) {
    return false;
  }

  // the checks passed, it means the signature is good
  return true;
}