signHash method

AMAXSignature signHash(
  1. Uint8List sha256Data
)

Sign the SHA256 hashed data using the private key

Implementation

AMAXSignature signHash(Uint8List sha256Data) {
  int nonce = 0;
  BigInt n = AMAXKey.secp256k1.n;
  BigInt e = decodeBigIntWithSign(1, sha256Data);

  while (true) {
    _deterministicGenerateK(sha256Data, this.d!, e, nonce++);
    var N_OVER_TWO = n >> 1;
    if (_s.compareTo(N_OVER_TWO) > 0) {
      _s = n - _s;
    }
    ECSignature sig = ECSignature(_r, _s);

    Uint8List der = AMAXSignature.ecSigToDER(sig);

    int lenR = der.elementAt(3);
    int lenS = der.elementAt(5 + lenR);
    if (lenR == 32 && lenS == 32) {
      int i = AMAXSignature.calcPubKeyRecoveryParam(decodeBigIntWithSign(1, sha256Data), sig, this.toAMAXPublicKey());
      i += 4; // compressed
      i += 27; // compact  //  24 or 27 :( forcing odd-y 2nd key candidate)
      return AMAXSignature(i, sig.r, sig.s);
    }
  }
}