sign method

List<int> sign(
  1. List<int> data,
  2. HashFunc hashMethod
)

Signs the provided data using this private key.

Implementation

List<int> sign(
  List<int> data,
  HashFunc hashMethod,
) {
  List<int> dom = List.empty();
  if (generator.curve == Curves.curveEd448) {
    dom = List<int>.from([...'SigEd448'.codeUnits, 0x00, 0x00]);
  }

  final r = BigintUtils.fromBytes(
      hashMethod()
          .update(List<int>.from([...dom, ..._extendedKey ?? [], ...data]))
          .digest(),
      byteOrder: Endian.little);
  final R = (generator * r).toBytes();

  BigInt k = BigintUtils.fromBytes(
      hashMethod()
          .update(
              List<int>.from([...dom, ...R, ...publicKey.toBytes(), ...data]))
          .digest(),
      byteOrder: Endian.little);

  k %= generator.order!;
  final s = (r + k * secret) % generator.order!;
  return List<int>.from([
    ...R,
    ...BigintUtils.toBytes(s, length: baselen, order: Endian.little)
  ]);
}