deterministicSign function
deterministicSign signs a hash (which should be the result of hashing a larger message) using the private key, priv. If the hash is longer than the bit-length of the private key's curve order, the hash will be truncated to that length. It returns the signature as a pair of integers.
Implementation
Signature deterministicSign(PrivateKey priv, List<int> hash) {
var curve = priv.curve;
if ((priv.D < BigInt.one) || priv.D > curve.n - BigInt.one) {
throw ErrInvalidPriv(); //the private key must be an integer in the range 1..n-1
}
var d = intToByte(curve, priv.D);
var k0 = deterministicGetK0(curve, d, hash);
var pointR = curve.scalarBaseMul(intToByte(curve, k0));
print(pointR.X);
print(pointR.Y);
var k = getK(curve, pointR, k0); // getEvenKey
print(k);
var pointP = curve.scalarBaseMul(d);
var rX = intToByte(curve, pointR.X);
print(pointP.X.toString() +
' ' +
pointP.Y.toString() +
' ' +
rX.toString() +
' ' +
hash.toString());
var e = getE(curve, pointP, rX, hash);
print('e:' + e.toString());
e = e * priv.D;
print(e);
k = k + e;
print(k);
k = k % curve.n;
print(k);
var R = pointR.X;
var S = k;
return Signature.fromRS(R, S);
}