Skip to content

Commit

Permalink
Merge pull request #139 from zama-ai/feature/error-cause
Browse files Browse the repository at this point in the history
feat: add error cause
  • Loading branch information
immortal-tofu authored Nov 28, 2024
2 parents 27ff020 + d1524c1 commit e159590
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 43 deletions.
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fhevmjs",
"version": "0.6.0-12",
"version": "0.6.0-13",
"description": "fhEVM SDK for blockchain using TFHE",
"main": "lib/node.js",
"types": "lib/node/node.d.ts",
Expand Down Expand Up @@ -52,9 +52,9 @@
"fetch-mock": "^11.1.3",
"keccak": "^3.0.4",
"node-tfhe": "^0.9.1",
"node-tkms": "0.9.0-rc27",
"node-tkms": "^0.9.0-rc36",
"tfhe": "^0.9.1",
"tkms": "0.9.0-rc27",
"tkms": "^0.9.0-rc36",
"wasm-feature-detect": "^1.8.0"
},
"devDependencies": {
Expand Down Expand Up @@ -87,6 +87,7 @@
"ts-loader": "^9.4.2",
"tsc-alias": "^1.8.6",
"tslib": "^2.5.3",
"typescript": "^5.7.2",
"webpack": "^5.82.1",
"webpack-cli": "^5.1.1",
"webpack-merge": "^5.9.0"
Expand Down
8 changes: 6 additions & 2 deletions src/sdk/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export const getTfheCompactPublicKey = async (
publicKeyId: config.publicKeyId,
};
} catch (e) {
throw new Error('Invalid public key (deserialization failed)');
throw new Error('Invalid public key (deserialization failed)', {
cause: e,
});
}
} else {
throw new Error('You must provide a public key with its public key ID.');
Expand Down Expand Up @@ -102,7 +104,9 @@ export const getPublicParams = async (
},
};
} catch (e) {
throw new Error('Invalid public key (deserialization failed)');
throw new Error('Invalid public key (deserialization failed)', {
cause: e,
});
}
} else {
throw new Error('You must provide a valid CRS with its CRS ID.');
Expand Down
3 changes: 1 addition & 2 deletions src/sdk/encrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ export const createEncryptedInput =
const response = await fetch(`${gateway}verify_proven_ct`, options);
json = await response.json();
} catch (e) {
console.log('verify_proven_ct failed with error', e);
throw new Error("Gateway didn't response correctly");
throw new Error("Gateway didn't response correctly", { cause: e });
}

// Note that the hex strings returned by the gateway do have have the 0x prefix
Expand Down
7 changes: 4 additions & 3 deletions src/sdk/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ export const getKeysFromGateway = async (
} else {
throw new Error('No public key available');
}
} catch (error) {
console.log('error', error);
throw new Error('Impossible to fetch public key: wrong gateway url.');
} catch (e) {
throw new Error('Impossible to fetch public key: wrong gateway url.', {
cause: e,
});
}
};
8 changes: 4 additions & 4 deletions src/sdk/reencrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ export const reencryptRequest =
pubKey = u8vec_to_cryptobox_pk(fromHexString(publicKey));
privKey = u8vec_to_cryptobox_sk(fromHexString(privateKey));
} catch (e) {
throw new Error('Invalid public or private key');
throw new Error('Invalid public or private key', { cause: e });
}

let json;
try {
const response = await fetch(`${gatewayUrl}reencrypt`, options);
json = await response.json();
} catch (e) {
throw new Error("Gateway didn't response correctly");
throw new Error("Gateway didn't response correctly", { cause: e });
}

if (json.status === 'failure') {
throw new Error("The reencryption didn't succeed");
throw new Error("The reencryption didn't succeed", { cause: json });
}

const client = new_client(kmsSignatures, userAddress, 'default');
Expand Down Expand Up @@ -109,6 +109,6 @@ export const reencryptRequest =

return bytesToBigInt(decryption);
} catch (e) {
throw new Error('An error occured during decryption');
throw new Error('An error occured during decryption', { cause: e });
}
};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"outDir": "bundle",
"declaration": false,
"target": "es5",
"lib": ["DOM", "WebWorker"],
"lib": ["es2022", "DOM", "WebWorker"],
"module": "commonjs",
"skipLibCheck": true,
"esModuleInterop": true,
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.rollup.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"rootDir": "src",
"outDir": "lib",
"declaration": true,
"target": "ES2020",
"lib": ["DOM", "WebWorker"],
"target": "ES2022",
"lib": ["es2022", "DOM", "WebWorker"],
"module": "esnext",
"skipLibCheck": true,
"esModuleInterop": true,
Expand Down

0 comments on commit e159590

Please sign in to comment.