recoverFromSignature method

Uint8List? recoverFromSignature(
  1. int recId,
  2. ECSignature sig,
  3. Uint8List msg, [
  4. bool encoded = false,
])

Implementation

Uint8List? recoverFromSignature(int recId, ECSignature sig, Uint8List msg, [bool encoded = false]) {
  final n = _ecDomainParams.n;
  final i = BigInt.from(recId ~/ 2);
  final x = sig.r + (i * n);

  final prime = BigInt.parse(
    'fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f',
    radix: 16,
  );
  if (x.compareTo(prime) >= 0) return null;

  final R = _decompressKey(x, (recId & 1) == 1);
  if (!(R * n)!.isInfinity) return null;

  final e = decodeBigIntToUnsigned(msg);

  final eInv = (BigInt.zero - e) % n;
  final rInv = sig.r.modInverse(n);
  final srInv = (rInv * sig.s) % n;
  final eInvrInv = (rInv * eInv) % n;

  final q = (_ecDomainParams.G * eInvrInv)! + (R * srInv);

  final bytes = q!.getEncoded(encoded);
  return bytes;
}