import 'package:lazyxchacha/keypair.dart' as kp;
import 'package:lazyxchacha/lazyxchacha.dart';

final key = kp.KeyPair.newKeyPair();

Future<String> encrypt(String text) async {
  final lazyxchacha = LazyXChaCha.instance;
  final localKey = await key;

  final sharedKey = await localKey.sharedKey(localKey.pk);
  final ciphertext = await lazyxchacha.encrypt(text, sharedKey);

  return ciphertext;
}

Future<String> decrypt(String encrypted) async {
  final lazyXChaCha = LazyXChaCha.instance;
  final localKey = await key;

  final sharedKey = await localKey.sharedKey(localKey.pk);
  final plaintext = await lazyXChaCha.decrypt(encrypted, sharedKey);

  return plaintext;
}
