calci = function(hashbuf, sig, pubkey) {
  for (var i = 0; i < 4; i++) {
    var Qprime;
    try {
      Qprime = getPublicKey(hashbuf, sig, i);
    } catch (e) {
      console.error(e);
      continue;
    }

    if (Qprime.point.eq(pubkey.point)) {
      sig.i = i;
      sig.compressed = pubkey.compressed;
      return sig;
    }
  }

  throw new Error('Unable to find valid recovery factor');
}
Attach the recovery factor i to an ECDSA signature.
@param {Buffer} hashbuf
@param {Signature} sig
@param {PulicKey} pubkey
@returns {Signature}