salsaBoxSeal static method

BuBytes salsaBoxSeal({
  1. required List<int> peerPublicKey,
  2. required List<int> secretKey,
  3. required List<int> plainText,
  4. List<int>? nonce,
})

NaCl crypto_box seal quick call for TON Connect, routed through the active backend: X25519 + XSalsa20-Poly1305, returning NONCE || TAG || CIPHERTEXT. Generates a fresh random 24-byte nonce (web-safe Fortuna PRNG) when nonce is omitted; pass an explicit nonce for deterministic vectors/tests.

Implementation

static BuBytes salsaBoxSeal({
  required List<int> peerPublicKey,
  required List<int> secretKey,
  required List<int> plainText,
  List<int>? nonce,
}) {
  final n = nonce ?? generateRandom(length: xsalsa20Poly1305NonceSize);
  try {
    return blockchainUtils.api.aed.salsaBoxSeal(
      n,
      plainText,
      peerPublicKey: peerPublicKey,
      secretKey: secretKey,
    );
  } finally {
    if (nonce == null) {
      BinaryOps.zero(n);
    }
  }
}