encryptLegacy method

Future<Uint8List> encryptLegacy(
  1. Uint8List payload,
  2. PeerId recipient, {
  3. Uint8List? nonce,
})

Seals payload in the legacy unbound format: nonce ‖ box(payload). Nothing ties it to a message; the client sends encryptBound.

Implementation

Future<Uint8List> encryptLegacy(Uint8List payload, PeerId recipient, {Uint8List? nonce}) async {
  if (nonce != null && nonce.length != _nonceSize) {
    throw ArgumentError('nonce must be $_nonceSize bytes');
  }
  final box = _boxWith(await peerIdToX25519PublicKey(recipient));
  final sealed = box.encrypt(payload, nonce: nonce);
  return Uint8List.fromList(sealed.asTypedList);
}