sign method

  1. @override
Uint8List sign(
  1. Uint8List privateKey,
  2. Uint8List message, {
  3. Uint8List? context,
  4. Uint8List? coins,
})
inherited

Implementation

@override
Uint8List sign(
  Uint8List privateKey,
  Uint8List message, {
  Uint8List? context,
  Uint8List? coins,
}) {
  final sig = calloc<ffi.Uint8>(_params.signatureBytes);
  final siglen = calloc<ffi.Size>();
  final m = calloc<ffi.Uint8>(message.length);
  m.asTypedList(message.length).setAll(0, message);
  final sk = calloc<ffi.Uint8>(privateKey.length);
  sk.asTypedList(privateKey.length).setAll(0, privateKey);

  final ctx = _toNativeBuffer(context);
  try {
    final result = _params.sign(
      sig,
      siglen,
      m,
      message.length,
      ctx,
      context?.length ?? 0,
      sk,
    );
    if (result != 0) {
      throw MLDSAKeyPairGenerationException(result);
    }
    return Uint8List.fromList(sig.asTypedList(_params.signatureBytes));
  } finally {
    calloc.free(sig);
    calloc.free(siglen);
    calloc.free(m);
    calloc.free(sk);
    _freeNativeBuffer(ctx);
  }
}