From 4cf33e5d414e7dbd4b2439e0080be6d8ffcd6b33 Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 24 Apr 2024 15:24:42 +0000 Subject: [PATCH] it works --- .../end-to-end/src/e2e_encryption.test.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 yarn-project/end-to-end/src/e2e_encryption.test.ts diff --git a/yarn-project/end-to-end/src/e2e_encryption.test.ts b/yarn-project/end-to-end/src/e2e_encryption.test.ts new file mode 100644 index 00000000000..861a7c573c3 --- /dev/null +++ b/yarn-project/end-to-end/src/e2e_encryption.test.ts @@ -0,0 +1,41 @@ +import { type Wallet } from '@aztec/aztec.js'; +import { Aes128 } from '@aztec/circuits.js/barretenberg'; +import { TestContract } from '@aztec/noir-contracts.js'; + +import { randomBytes } from 'crypto'; + +import { setup } from './fixtures/utils.js'; + +describe('e2e_encryption', () => { + const aes128 = new Aes128(); + + let wallet: Wallet; + let teardown: () => Promise; + + let contract: TestContract; + + beforeAll(async () => { + ({ teardown, wallet } = await setup()); + contract = await TestContract.deploy(wallet).send().deployed(); + }, 25_000); + + afterAll(() => teardown()); + + it('encrypts', async () => { + const input = randomBytes(64); + const iv = randomBytes(16); + const key = randomBytes(16); + + const expectedCiphertext = aes128.encryptBufferCBC(input, iv, key); + + const logs = await contract.methods + .encrypt(Array.from(input), Array.from(iv), Array.from(key)) + .send() + .getUnencryptedLogs(); + // Each byte of encrypted data is in its own field and it's all serialized into a long buffer so we simply extract + // each 32nd byte from the buffer to get the encrypted data + const recoveredCiphertext = logs.logs[0].log.data.filter((_, i) => (i + 1) % 32 === 0); + + expect(recoveredCiphertext).toEqual(expectedCiphertext); + }); +});