signHash method
Sign the SHA256 hashed data using the private key
Implementation
SteemSignature signHash(Uint8List sha256Data) {
if (sha256Data.lengthInBytes != 32 || sha256Data.isEmpty) {
throw ('buf_sha256: 32 byte buffer requred');
}
var nonce = 0;
var n = SteemKey.secp256k1.n;
var e = decodeBigInt(sha256Data);
while (true) {
_deterministicGenerateK(sha256Data, d!, e, nonce++);
var N_OVER_TWO = n >> 1;
if (_s.compareTo(N_OVER_TWO) > 0) {
_s = n - _s;
}
var sig = ECSignature(_r, _s);
var der = SteemSignature.ecSigToDER(sig);
var lenR = der.elementAt(3);
var lenS = der.elementAt(5 + lenR);
if (lenR == 32 && lenS == 32) {
var i = SteemSignature.calcPubKeyRecoveryParam(
decodeBigInt(sha256Data), sig, toPublicKey());
i += 4; // compressed
i += 27; // compact // 24 or 27 :( forcing odd-y 2nd key candidate)
return SteemSignature(i, sig.r, sig.s);
}
if (nonce % 10 == 0) {
print('WARN: $nonce attempts to find canonical signature');
}
}
}