sign method
Signs the provided data using this private key.
Implementation
List<int> sign(List<int> data, HashFunc hashMethod) {
final order = generator.order;
if (order == null) {
throw ArgumentException.invalidOperationArguments(
"sign",
reason: "Invalid curve generator.",
);
}
List<int> dom = List.empty();
if (generator.curve == Curves.curveEd448) {
dom = [...'SigEd448'.codeUnits, 0x00, 0x00];
}
final r = BigintUtils.fromBytes(
hashMethod().update([...dom, ...extendedKey, ...data]).digest(),
byteOrder: Endian.little,
);
final R = (generator * r).toBytes();
BigInt k = BigintUtils.fromBytes(
hashMethod().update([
...dom,
...R,
...publicKey.toBytes(),
...data,
]).digest(),
byteOrder: Endian.little,
);
k %= order;
final s = (r + k * secret) % order;
final signature = [
...R,
...BigintUtils.toBytes(s, length: baselen, order: Endian.little),
];
if (publicKey.verify(data, signature, hashMethod)) {
return signature;
}
throw CryptoSignException.signatureVerificationFailed;
}