diff --git a/apps/remixdesktop/src/plugins/circomElectronBasePlugin.ts b/apps/remixdesktop/src/plugins/circomElectronBasePlugin.ts index ca44e710c2..cb55dbc064 100644 --- a/apps/remixdesktop/src/plugins/circomElectronBasePlugin.ts +++ b/apps/remixdesktop/src/plugins/circomElectronBasePlugin.ts @@ -1,7 +1,8 @@ import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron" import { Profile } from "@remixproject/plugin-utils" -import { circomCli, extractParentFromKey } from "../tools/circom" +import { CIRCOM_INSTALLATION_PATH, circomCli, extractParentFromKey } from "../tools/circom" import path from "path" +import { existsSync, readFileSync } from "fs" const profile: Profile = { displayName: 'circom', @@ -22,7 +23,7 @@ const clientProfile: Profile = { name: 'circom', displayName: 'circom', description: 'Circom Language Compiler', - methods: ['install', 'run',] + methods: ['install', 'run', 'getInputs'] } class CircomElectronPluginClient extends ElectronBasePluginClient { @@ -53,6 +54,23 @@ class CircomElectronPluginClient extends ElectronBasePluginClient { const depPath = path.join(wd, '.deps/https/raw.githubusercontent.com/iden3/') const outputDir = extractParentFromKey(filePath) + '/.bin' - await circomCli.run(`${filePath} -l ${depPath} -o ${outputDir}`, options) + return await circomCli.run(`${filePath} -l ${depPath} -o ${outputDir}`, options) + } + + getInputs() { + const inputsFile = extractParentFromKey(CIRCOM_INSTALLATION_PATH) + '/log_input_signals.txt' + const inputsFileExists = existsSync(inputsFile) + const signals: string[] = [] + + if (inputsFileExists) { + const inputsContent = readFileSync(inputsFile, 'utf-8') + const regexPattern = /main\.(\w+)/g + + let match + while ((match = regexPattern.exec(inputsContent)) !== null) { + signals.push(match[1]) + } + return signals + } } } \ No newline at end of file diff --git a/apps/remixdesktop/src/tools/circom.ts b/apps/remixdesktop/src/tools/circom.ts index 93d62fea51..2f616d3700 100644 --- a/apps/remixdesktop/src/tools/circom.ts +++ b/apps/remixdesktop/src/tools/circom.ts @@ -6,7 +6,7 @@ import fs, { existsSync } from 'fs' import axios from 'axios' const execAsync = promisify(exec) -const CIRCOM_INSTALLATION_PATH = getInstallationPath() +export const CIRCOM_INSTALLATION_PATH = getInstallationPath() const CIRCOM_INSTALLATION_URL = getInstallationUrl() async function downloadFile(url: string, dest: string) { @@ -83,12 +83,9 @@ export const circomCli = { }, async run (filePath: string, options?: Record) { - const cmd = `${CIRCOM_INSTALLATION_PATH} ${filePath} ${Object.keys(options || {}).map((key) => `--${key} ${options[key]}`).join(' ')}` - console.log('cmd: ', cmd) - const { stdout, stderr } = await execAsync(cmd) + const cmd = `${CIRCOM_INSTALLATION_PATH} ${filePath} ${Object.keys(options || {}).map((key) => options[key] ? `--${key} ${options[key]}` : `--${key}`).join(' ')}` - if (stderr) return console.error(stderr) - console.log(stdout) + return await execAsync(cmd) } }