Reuse an existing KeyPair (resuming a session) or generate a
fresh one (crypto_box.keyPair()) when omitted.
OptionalkeyPair: KeyPairReadonlysessionBridge-level client_id — the public key as a 64-character
lowercase hex string. Share with the peer during connect; treat as
semi-private (do not publish broadly).
Decrypt the nonce || ciphertext blob received from the bridge.
Throws if nacl.box.open rejects the message — wrong key, truncated
input or tampered ciphertext.
Encrypt message for receiverPublicKey using a fresh 24-byte random
nonce. Returns nonce || ciphertext as raw bytes; base64-encode this
value before placing it in the bridge POST /message body.
Implements the TON Connect session-encryption protocol on top of NaCl's
crypto_box.The protocol is symmetric: each side encrypts the messages it sends and decrypts the messages it receives. On the dApp side that means encrypting outgoing AppMessage and decrypting incoming WalletMessage; the wallet does the reverse.
Example
See
Session protocol (Session spec)