sign function

SchnorrSignature sign(
  1. List<int> msg,
  2. List<int> privKey,
  3. List<int> pubKey
)

Implementation

SchnorrSignature sign(List<int> msg, List<int> privKey, List<int> pubKey) {
  BigInt prv = numbers.bytesToInt(privKey);
  DRBG drbg = getDRBG(msg);
  int len = numbers.intToBytes(params.n).length;
  var sig;

  while (sig == null) {
    var k = numbers.hexToInt(drbg.generate(len));

    var trySig = trySign(msg, k, prv, pubKey)!;
    bool res = verify(
      msg,
      trySig.r,
      trySig.s,
      pubKey,
    );
    if (res && isSignature(trySig.signature)) {
      sig = trySig;
    } else {
      sig = null;
    }
  }
  return sig;
}