From 2990cb69fbc1508244ec8c33abafacea96321806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20=27birdy=27=20Danjou?= Date: Sat, 15 Jul 2023 21:56:40 +0200 Subject: [PATCH 1/2] add test for encrypt 0 --- src/sdk/encrypt.test.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/sdk/encrypt.test.ts b/src/sdk/encrypt.test.ts index bd3923b..09e8f3a 100644 --- a/src/sdk/encrypt.test.ts +++ b/src/sdk/encrypt.test.ts @@ -21,6 +21,16 @@ describe('encrypt8', () => { publicKey = keypair.publicKey; }); + it('encrypt/decrypt 0 8bits', async () => { + const buffer = encrypt8(0, publicKey); + const compactList = CompactFheUint8List.deserialize(buffer); + let encryptedList = compactList.expand(); + encryptedList.forEach((v: FheUint8) => { + const decrypted = v.decrypt(clientKey); + expect(decrypted).toBe(0); + }); + }); + it('encrypt/decrypt 8bits', async () => { const buffer = encrypt8(34, publicKey); const compactList = CompactFheUint8List.deserialize(buffer); @@ -31,6 +41,16 @@ describe('encrypt8', () => { }); }); + it('encrypt/decrypt 0 16bits', async () => { + const buffer = encrypt16(0, publicKey); + const compactList = CompactFheUint8List.deserialize(buffer); + let encryptedList = compactList.expand(); + encryptedList.forEach((v: FheUint8) => { + const decrypted = v.decrypt(clientKey); + expect(decrypted).toBe(0); + }); + }); + it('encrypt/decrypt 16bits', async () => { const buffer = encrypt16(434, publicKey); const compactList = CompactFheUint16List.deserialize(buffer); @@ -41,6 +61,16 @@ describe('encrypt8', () => { }); }); + it('encrypt/decrypt 0 32bits', async () => { + const buffer = encrypt32(0, publicKey); + const compactList = CompactFheUint8List.deserialize(buffer); + let encryptedList = compactList.expand(); + encryptedList.forEach((v: FheUint8) => { + const decrypted = v.decrypt(clientKey); + expect(decrypted).toBe(0); + }); + }); + it('encrypt/decrypt 32bits', async () => { const buffer = encrypt32(30210, publicKey); const compactList = CompactFheUint32List.deserialize(buffer); From 76e8998298afc237f3b79fa2b9173b157e269f5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20=27birdy=27=20Danjou?= Date: Sat, 15 Jul 2023 22:15:57 +0200 Subject: [PATCH 2/2] fix() change check of 0 number --- src/sdk/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sdk/index.ts b/src/sdk/index.ts index 5ce6dc2..523f12a 100644 --- a/src/sdk/index.ts +++ b/src/sdk/index.ts @@ -70,18 +70,18 @@ export const createInstance = async (params: FhevmInstanceParams): Promise