Skip to content

Commit

Permalink
Merge pull request #18 from zama-ai/test/add-test-for-0
Browse files Browse the repository at this point in the history
Fix and test 0
  • Loading branch information
immortal-tofu authored Jul 15, 2023
2 parents 364b91d + 76e8998 commit dd39986
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
30 changes: 30 additions & 0 deletions src/sdk/encrypt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ export const createInstance = async (params: FhevmInstanceParams): Promise<Fhevm
return {
// Parameters
encrypt8(value) {
if (!value) throw new Error('Missing value');
if (value == null) throw new Error('Missing value');
if (typeof value !== 'number') throw new Error('Value must be a number');
return encrypt8(value, tfheCompactPublicKey);
},
encrypt16(value) {
if (!value) throw new Error('Missing value');
if (value == null) throw new Error('Missing value');
if (typeof value !== 'number') throw new Error('Value must be a number');
return encrypt16(value, tfheCompactPublicKey);
},

encrypt32(value) {
if (!value) throw new Error('Missing value');
if (value == null) throw new Error('Missing value');
if (typeof value !== 'number') throw new Error('Value must be a number');
return encrypt32(value, tfheCompactPublicKey);
},
Expand Down

0 comments on commit dd39986

Please sign in to comment.