import { randomBytes } from 'crypto'; import { keyPairFromSeed } from '@ton/crypto'; import { encryptContent, decryptContent } from './crypto'; import { client, getKeypair, getWallet } from '../toolchain'; import { WalletContractV4 } from '@ton/ton'; describe('Crypto functions', () => { test('encrypt and decrypt content', async () => { const sender = await getKeypair(); const recipient = keyPairFromSeed(randomBytes(32)); const originalContent = 'Secret message'; const encrypted = await encryptContent(sender.secretKey, recipient.publicKey, originalContent); const decrypted = await decryptContent(recipient.secretKey, sender.publicKey, encrypted); expect(decrypted).toBe(originalContent); }); test('decrypt with wrong key fails', async () => { const senderSeed = Buffer.from(randomBytes(32)); const recipientSeed = Buffer.from(randomBytes(32)); const wrongRecipientSeed = Buffer.from(randomBytes(32)); const sender = keyPairFromSeed(senderSeed); const recipient = await getKeypair(); const wrongRecipient = keyPairFromSeed(wrongRecipientSeed); const originalContent = 'Secret message'; const encrypted = await encryptContent(sender.secretKey, recipient.publicKey, originalContent); await expect(decryptContent(wrongRecipient.secretKey, sender.publicKey, encrypted)).rejects.toThrow(); }); });