Skip to content

Commit

Permalink
feat: add error cause
Browse files Browse the repository at this point in the history
  • Loading branch information
immortal-tofu committed Nov 28, 2024
1 parent 27ff020 commit 17bf840
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 40 deletions.
48 changes: 24 additions & 24 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
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 17bf840

Please sign in to comment.