Skip to content

Commit

Permalink
Merge pull request #79 from zama-ai/fix/send
Browse files Browse the repository at this point in the history
fix: send function for coprocessor
  • Loading branch information
immortal-tofu authored Jun 26, 2024
2 parents a109fb9 + f891715 commit f804765
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 52 deletions.
103 changes: 52 additions & 51 deletions src/sdk/encrypt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,54 +190,55 @@ describe('encrypt', () => {
});
});

// describe('encryptWithCoprocessor', () => {
// let publicKey: TfheCompactPublicKey;
// const coprocessorNode = 'http://127.0.0.1:8745';

// beforeAll(async () => {
// const pkeyOptions = {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/json',
// },
// body: JSON.stringify({
// method: "eth_getPublicFhevmKey",
// params: [],
// id: 1,
// jsonrpc: "2.0",
// }),
// };
// const pkeyRes = await fetchJSONRPC(
// coprocessorNode,
// pkeyOptions,
// );

// publicKey = TfheCompactPublicKey.deserialize(fromHexString(pkeyRes.publicKey));
// });

// it('encrypt with coprocessor', async () => {
// // encrypted inputs, we pass coprocessor node url
// const input = createEncryptedInput(publicKey, coprocessorNode)(
// '0x8ba1f109551bd432803012645ac136ddd64dba72',
// '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80',
// );
// // add inputs
// input.addBool(BigInt(0));
// input.add4(2);
// input.add8(BigInt(43));
// input.add16(BigInt(87));
// input.add32(BigInt(2339389323));
// input.add64(BigInt(23393893233));
// //input.add128(BigInt(233938932390)); // 128 bits not supported yet in coprocessor
// input.addAddress('0xa5e1defb98EFe38EBb2D958CEe052410247F4c80');

// // send to the coprocessor
// const res = await input.send();
// // receive handlesList, callerAddress, contractAddress and EIP712 signature
// expect(res.handlesList).toBeDefined();
// expect(res.handlesList.length).toBe(7);
// expect(res.callerAddress).toBe('0xa5e1defb98EFe38EBb2D958CEe052410247F4c80');
// expect(res.contractAddress).toBe('0x8ba1f109551bD432803012645Ac136ddd64DBA72');
// expect(res.signature).toBeDefined();
// });
// });
/*
describe('encryptWithCoprocessor', () => {
let publicKey: TfheCompactPublicKey;
const coprocessorNode = 'http://127.0.0.1:8645';
beforeAll(async () => {
const pkeyOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
method: 'eth_getPublicFhevmKey',
params: [],
id: 1,
jsonrpc: '2.0',
}),
};
const pkeyRes = await fetchJSONRPC(coprocessorNode, pkeyOptions);
publicKey = TfheCompactPublicKey.deserialize(
fromHexString(pkeyRes.publicKey),
);
});
it('encrypt with coprocessor', async () => {
// encrypted inputs, we pass coprocessor node url
const input = createEncryptedInput(publicKey, coprocessorNode)(
'0x8ba1f109551bd432803012645ac136ddd64dba72',
'0xa5e1defb98EFe38EBb2D958CEe052410247F4c80',
);
// add inputs
input.addBool(BigInt(0));
input.add4(2);
input.add8(BigInt(43));
input.add16(BigInt(87));
input.add32(BigInt(2339389323));
input.add64(BigInt(23393893233));
//input.add128(BigInt(233938932390)); // 128 bits not supported yet in coprocessor
input.addAddress('0xa5e1defb98EFe38EBb2D958CEe052410247F4c80');
//send to the coprocessor
const res = await input.send();
//receive handlesList, callerAddress, contractAddress and EIP712 signature
expect(res.handles).toBeDefined();
expect(res.handles.length).toBe(7);
//expect(res.callerAddress).toBe('0xa5e1defb98EFe38EBb2D958CEe052410247F4c80');
//expect(res.contractAddress).toBe('0x8ba1f109551bD432803012645Ac136ddd64DBA72');
expect(res.inputProof).toBeDefined();
});
});
*/
2 changes: 1 addition & 1 deletion src/sdk/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export const createEncryptedInput =
const resJson = await fetchJSONRPC(coprocessorUrl, options);
const inputProof = convertToInputProof(resJson);
return {
handles: resJson.handles.map((handle: string) =>
handles: resJson.handlesList.map((handle: string) =>
fromHexString(handle),
),
inputProof: fromHexString(inputProof),
Expand Down

0 comments on commit f804765

Please sign in to comment.