Hello, I’m trying to run a simple addition operation on the smart contract and the decrypted result after re-encryption. However I’m having getting an error “Gateway didn’t response correctly” when I call the reencrypt method through js. Following is my code:
const getInstance = async () => {
return createInstance({
chainId: 9000,
networkUrl: “https://devnet.zama.ai/”,
gatewayUrl: “https://gateway.zama.ai”,
aclAddress: ‘0x2Fb4341027eb1d2aD8B5D9708187df8633cAFA92’,
});
};const interact = async () => {
try{
const contract = new Contract(CONTRACT_ADDRESS, abi, signer);
const instance = await getInstance();
const { publicKey, privateKey } = instance.generateKeypair();const eip712 = instance.createEIP712(publicKey, CONTRACT_ADDRESS);
const signature = await signer.signTypedData(
eip712.domain,
{ Reencrypt: eip712.types.Reencrypt },
eip712.message,
);const input = instance.createEncryptedInput(CONTRACT_ADDRESS, USER_ADDRESS); input.add16(5); input.add16(20); const encinputs = input.encrypt(); let input_proof = encinputs.inputProof; const transaction = await contract.receiveInput(encinputs.handles[0], encinputs.handles[1], input_proof); await transaction.wait(); const transaction_one = await contract.calculateSum(); await transaction_one.wait();
const enc_sum = await contract.returnSum();
try {
const dec_sum = await instance.reencrypt(
enc_sum, // the encrypted balance
privateKey, // the private key generated by the dApp
publicKey, // the public key generated by the dApp
signature, // the user’s signature of the public key
CONTRACT_ADDRESS, // The contract address where the ciphertext is
USER_ADDRESS, // The user address where the ciphertext is
);
console.log(dec_sum);
} catch(error){
console.log(error);
}
Following is the output of parameters provided to reencrypt method
sum: 99292914124165378992032534236339290868945609897006041906242294352104744092416
private key: 2000000000000000cffb2ea8a265a29ae7a665442cfc6b8e54114c37fd9addd9c512b764243cf453
public key: 2000000000000000093a6e0e58a450ecf998eafd2a19630ec0c1912cd649ea82fa0e0510dd89a328
signature: 0x7598df1c4e7487f84c995e2fe8bb0b72353a309f0319a39e3d244e694c524cab5a7d8754e59006fa0c683e7dd02ab12d124cf7a92d05b1d5ca6cb79b5c7b56b31c
Contract Address:
0xf12Ad7433FE69aaEC66A7Eff816664EE3E58E75c
User Address:
0x6E7C2603d4DabD2C9bBd15993775073C581B54c7
The documentation contains and example of generating signature using the browser but I’m using console (node js). Is there a problem with the signature or am I missing something? Thanks