sign method

Uint8List sign(
  1. Uint8List message,
  2. Uint8List prefix
)

Sign signs the message with privateKey and returns a signature. It will throw ArumentError if privateKey.bytes.length is not PrivateKeySize.

Implementation

Uint8List sign(Uint8List message, Uint8List prefix) {
  if (keyBytes.length != 32) {
    throw ArgumentError('ed25519: bad privateKey length ${keyBytes.length}');
  }

  Uint8List messageDigest = sha512Many([prefix, message]);

  final Uint8List r = curve25519.reduce(messageDigest);
  ExtendedGroupElement R = curve25519.scalarMultiplyBase(r);
  Uint8List encodedR = R.asBytes;

  Uint8List k = sha512Many([encodedR, publicKey.bytes, message]);
  final kReduced = curve25519.reduce(k);

  final Uint8List S = curve25519.scalarMultiplyAdd(kReduced, keyBytes, r);

  var signature = Uint8List(signatureSize);
  signature.setRange(0, 32, encodedR);
  signature.setRange(32, 64, S);

  return signature;
}