recoverPubKey static method

ECPoint? recoverPubKey(
  1. BigInt e,
  2. ECSignature ecSig,
  3. int i
)

Recovery AMAX public key from ECSignature

Implementation

static ECPoint? recoverPubKey(BigInt e, ECSignature ecSig, int i) {
  BigInt n = AMAXKey.secp256k1.n;
  ECPoint G = AMAXKey.secp256k1.G;

  BigInt r = ecSig.r;
  BigInt s = ecSig.s;

  // A set LSB signifies that the y-coordinate is odd
  int isYOdd = i & 1;

  // The more significant bit specifies whether we should use the
  // first or second candidate key.
  int isSecondKey = i >> 1;

  // 1.1 Let x = r + jn
  BigInt x = isSecondKey > 0 ? r + n : r;
  ECPoint R = AMAXKey.secp256k1.curve.decompressPoint(isYOdd, x);
  ECPoint nR = (R * n)!;
  if (!nR.isInfinity) {
    throw 'nR is not a valid curve point';
  }

  BigInt eNeg = (-e) % n;
  BigInt rInv = r.modInverse(n);

  ECPoint? Q = multiplyTwo(R, s, G, eNeg)! * rInv;
  return Q;
}