Skip to content

encryptForViewing()

SIP Protocol API Reference v0.7.0


SIP Protocol API Reference / encryptForViewing

encryptForViewing(data, viewingKey): EncryptedTransaction

Defined in: @sip-protocol/sdk/dist/index-BYZbDjal.d.ts:3261

Encrypt transaction data for viewing key holders

Uses XChaCha20-Poly1305 authenticated encryption with:

  • 24-byte random nonce (nonce-misuse resistant)
  • HKDF-derived encryption key
  • 16-byte authentication tag (included in ciphertext)

TransactionData

Transaction data to encrypt

ViewingKey

Viewing key for encryption

EncryptedTransaction

Encrypted transaction with nonce and key hash

const encrypted = encryptForViewing(
{ sender: '0x...', recipient: '0x...', amount: '100', timestamp: 123 },
viewingKey
)
// encrypted.ciphertext contains the encrypted data
// encrypted.nonce is needed for decryption
// encrypted.viewingKeyHash identifies which key can decrypt