Skip to content

Commit

Permalink
refactor sendModalRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
remicolin committed Jul 19, 2024
1 parent 8ae73c0 commit 69c3aac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
3 changes: 2 additions & 1 deletion common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"@zk-kit/imt": "https://gitpkg.now.sh/0xturboblitz/zk-kit/packages/imt?6d417675",
"@zk-kit/lean-imt": "^2.0.1",
"asn1.js": "^5.4.1",
"axios": "^1.7.2",
"elliptic": "^6.5.5",
"fs": "^0.0.1-security",
"js-sha1": "^0.7.0",
Expand All @@ -19,4 +20,4 @@
"devDependencies": {
"@types/node-forge": "^1.3.10"
}
}
}
25 changes: 23 additions & 2 deletions common/src/utils/csca.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { sha1Pad, sha256Pad } from "./shaPad";
import * as forge from "node-forge";
import { splitToWords } from "./utils";
import { CSCA_AKI_MODULUS, CSCA_TREE_DEPTH } from "../constants/constants";
import { CSCA_AKI_MODULUS, CSCA_TREE_DEPTH, MODAL_SERVER_ADDRESS } from "../constants/constants";
import { poseidon16, poseidon2, poseidon4 } from "poseidon-lite";
import { IMT } from "@zk-kit/imt";
import serialized_csca_tree from "../../pubkeys/serialized_csca_tree.json"
import { createHash } from "crypto";
import axios from "axios";

export function findStartIndex(modulus: string, messagePadded: Uint8Array): number {
const modulusNumArray = [];
Expand Down Expand Up @@ -230,4 +231,24 @@ export function getTBSHash(cert: forge.pki.Certificate, hashAlgorithm: 'sha1' |
}



export const sendCSCARequest = async (inputs_csca: any): Promise<any> => {
try {
const response = await axios.post(MODAL_SERVER_ADDRESS, inputs_csca, {
headers: {
'Content-Type': 'application/json'
}
});
return response.data;
} catch (error) {
if (axios.isAxiosError(error)) {
console.error('Axios error:', error.message);
if (error.response) {
console.error('Response data:', error.response.data);
console.error('Response status:', error.response.status);
}
} else {
console.error('Unexpected error:', error);
}
throw error;
}
};
26 changes: 2 additions & 24 deletions prover/tests/modal.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCSCAInputs } from "../../common/src/utils/csca";
import { getCSCAInputs, sendCSCARequest } from "../../common/src/utils/csca";
import { mock_csca_sha256_rsa_4096, mock_dsc_sha256_rsa_4096, mock_csca_sha1_rsa_4096, mock_dsc_sha1_rsa_4096 } from "../../common/src/constants/mockCertificates";
import forge from "node-forge";
import { MODAL_SERVER_ADDRESS } from "../../common/src/constants/constants";
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('MODAL PROVER', function () {
"signature_algorithm": "sha1_rsa",
"inputs": circuitInputs
}
//console.log(JSON.stringify(inputs));
console.log(JSON.stringify(inputs));

console.log('\x1b[34msending request to modal server\x1b[0m');
const response = await sendCSCARequest(inputs);
Expand All @@ -89,25 +89,3 @@ describe('MODAL PROVER', function () {
});
});
});

export const sendCSCARequest = async (inputs_csca: any): Promise<any> => {
try {
const response = await axios.post(MODAL_SERVER_ADDRESS, inputs_csca, {
headers: {
'Content-Type': 'application/json'
}
});
return response.data;
} catch (error) {
if (axios.isAxiosError(error)) {
console.error('Axios error:', error.message);
if (error.response) {
console.error('Response data:', error.response.data);
console.error('Response status:', error.response.status);
}
} else {
console.error('Unexpected error:', error);
}
throw error;
}
};

0 comments on commit 69c3aac

Please sign in to comment.