diff --git a/common/package.json b/common/package.json index cb206776..09f5b133 100644 --- a/common/package.json +++ b/common/package.json @@ -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", @@ -19,4 +20,4 @@ "devDependencies": { "@types/node-forge": "^1.3.10" } -} \ No newline at end of file +} diff --git a/common/src/utils/csca.ts b/common/src/utils/csca.ts index 5d431035..689a99b9 100644 --- a/common/src/utils/csca.ts +++ b/common/src/utils/csca.ts @@ -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 = []; @@ -230,4 +231,24 @@ export function getTBSHash(cert: forge.pki.Certificate, hashAlgorithm: 'sha1' | } - +export const sendCSCARequest = async (inputs_csca: any): Promise => { + 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; + } +}; \ No newline at end of file diff --git a/prover/tests/modal.test.ts b/prover/tests/modal.test.ts index 55881342..85b53c1b 100644 --- a/prover/tests/modal.test.ts +++ b/prover/tests/modal.test.ts @@ -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"; @@ -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); @@ -89,25 +89,3 @@ describe('MODAL PROVER', function () { }); }); }); - -export const sendCSCARequest = async (inputs_csca: any): Promise => { - 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; - } -}; \ No newline at end of file