parent
b5b8ddb5fd
commit
f6d1a7049a
@ -1,6 +0,0 @@ |
|||||||
import { Dispatch } from "react" |
|
||||||
import { Action } from "../types" |
|
||||||
|
|
||||||
export const dispatchCheckRemixd = (status: boolean) => (dispatch: Dispatch<Action<'SET_REMIXD_CONNECTION_STATUS'>>) => { |
|
||||||
dispatch({ type: 'SET_REMIXD_CONNECTION_STATUS', payload: status }) |
|
||||||
} |
|
@ -1 +0,0 @@ |
|||||||
import { Dispatch } from 'react' |
|
@ -1,31 +1,16 @@ |
|||||||
import React, { useEffect, useReducer, useState } from 'react' |
import React, { useEffect } from 'react' |
||||||
import { RenderIf, RenderIfNot } from '@remix-ui/helper' |
|
||||||
import { Alert, Button, Tabs, Tab } from 'react-bootstrap' |
|
||||||
|
|
||||||
import { AppContext } from './contexts' |
|
||||||
import { appInitialState, appReducer } from './reducers' |
|
||||||
import { CircomPluginClient } from './services/circomPluginClient' |
import { CircomPluginClient } from './services/circomPluginClient' |
||||||
|
|
||||||
function App() { |
function App() { |
||||||
const [appState, dispatch] = useReducer(appReducer, appInitialState) |
|
||||||
const [plugin, setPlugin] = useState<CircomPluginClient>(null) |
|
||||||
|
|
||||||
useEffect(() => { |
useEffect(() => { |
||||||
const plugin = new CircomPluginClient() |
new CircomPluginClient() |
||||||
|
|
||||||
setPlugin(plugin) |
|
||||||
}, []) |
}, []) |
||||||
|
|
||||||
const value = { |
|
||||||
appState, |
|
||||||
dispatch |
|
||||||
} |
|
||||||
|
|
||||||
return ( |
return ( |
||||||
<AppContext.Provider value={value}> |
<div className="App"> |
||||||
<div className="App"> |
</div> |
||||||
</div> |
|
||||||
</AppContext.Provider> |
|
||||||
) |
) |
||||||
} |
} |
||||||
|
|
||||||
|
@ -1,30 +0,0 @@ |
|||||||
// const compile = () => {
|
|
||||||
// const currentFile = api.currentFile
|
|
||||||
|
|
||||||
// if (currentFile.endsWith('.circom')) return compileCircuit()
|
|
||||||
// if (!isSolFileSelected()) return
|
|
||||||
// _setCompilerVersionFromPragma(currentFile)
|
|
||||||
// let externalCompType
|
|
||||||
// if (hhCompilation) externalCompType = 'hardhat'
|
|
||||||
// else if (truffleCompilation) externalCompType = 'truffle'
|
|
||||||
// compileTabLogic.runCompiler(externalCompType)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const compileAndRun = () => {
|
|
||||||
// const currentFile = api.currentFile
|
|
||||||
|
|
||||||
// if (currentFile.endsWith('.circom')) return compileCircuit()
|
|
||||||
// if (!isSolFileSelected()) return
|
|
||||||
// _setCompilerVersionFromPragma(currentFile)
|
|
||||||
// let externalCompType
|
|
||||||
// if (hhCompilation) externalCompType = 'hardhat'
|
|
||||||
// else if (truffleCompilation) externalCompType = 'truffle'
|
|
||||||
// api.runScriptAfterCompilation(currentFile)
|
|
||||||
// compileTabLogic.runCompiler(externalCompType)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const compileCircuit = () => {
|
|
||||||
// const currentFile = api.currentFile
|
|
||||||
|
|
||||||
// console.log('Compiling circuit ' + currentFile)
|
|
||||||
// }
|
|
@ -1,4 +0,0 @@ |
|||||||
import { createContext } from 'react' |
|
||||||
import { IAppContext } from '../types' |
|
||||||
|
|
||||||
export const AppContext = createContext<IAppContext>({} as IAppContext) |
|
@ -1,18 +0,0 @@ |
|||||||
import { Actions, AppState } from "../types" |
|
||||||
|
|
||||||
export const appInitialState: AppState = { |
|
||||||
isRemixdConnected: null |
|
||||||
} |
|
||||||
|
|
||||||
export const appReducer = (state = appInitialState, action: Actions): AppState => { |
|
||||||
switch (action.type) { |
|
||||||
case 'SET_REMIXD_CONNECTION_STATUS': |
|
||||||
return { |
|
||||||
...state, |
|
||||||
isRemixdConnected: action.payload |
|
||||||
} |
|
||||||
|
|
||||||
default: |
|
||||||
throw new Error() |
|
||||||
} |
|
||||||
} |
|
@ -1,108 +1,137 @@ |
|||||||
import { PluginClient } from '@remixproject/plugin' |
import { PluginClient } from '@remixproject/plugin' |
||||||
import { createClient } from '@remixproject/plugin-webview' |
import { createClient } from '@remixproject/plugin-webview' |
||||||
import { parse_circuit_browser, main_browser } from 'apps/circuit-compiler/pkg/circom' |
|
||||||
import { generate_witness } from 'apps/circuit-compiler/pkg/generate_witness' |
|
||||||
import EventManager from 'events' |
import EventManager from 'events' |
||||||
|
import pathModule from 'path' |
||||||
const pathModule = require('path') |
import { parse } from 'circom_wasm' |
||||||
|
|
||||||
export class CircomPluginClient extends PluginClient { |
export class CircomPluginClient extends PluginClient { |
||||||
private connected: boolean |
public internalEvents: EventManager |
||||||
public internalEvents: EventManager |
|
||||||
|
constructor() { |
||||||
constructor() { |
super() |
||||||
super() |
createClient(this) |
||||||
createClient(this) |
this.internalEvents = new EventManager() |
||||||
this.internalEvents = new EventManager() |
this.methods = ["init", "parse"] |
||||||
this.methods = ["init", "compile"] |
this.onload() |
||||||
this.onload() |
} |
||||||
} |
|
||||||
|
init (): void { |
||||||
init (): void { |
console.log('initializing circom plugin...') |
||||||
console.log('initializing circom plugin...') |
} |
||||||
|
|
||||||
|
onActivation(): void { |
||||||
|
// @ts-ignore
|
||||||
|
this.on('editor', 'contentChanged', (path: string, fileContent) => { |
||||||
|
if (path.endsWith('.circom')) { |
||||||
|
this.parse(path, fileContent) |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
async parse (path: string, fileContent: string): Promise<void> { |
||||||
|
let buildFiles = { |
||||||
|
[path]: fileContent |
||||||
} |
} |
||||||
|
|
||||||
async compile (path: string) { |
buildFiles = await this.resolveDependencies(path, fileContent, buildFiles) |
||||||
const fileContent = await this.call('fileManager', 'readFile', path) |
const parsedOutput = parse(path, buildFiles) |
||||||
let buildFiles = { |
|
||||||
[path]: fileContent |
|
||||||
} |
|
||||||
|
|
||||||
buildFiles = await this.resolveDependencies(path, fileContent, buildFiles) |
|
||||||
const compilationResult = main_browser(path, buildFiles, { prime: "bn128" }) |
|
||||||
|
|
||||||
console.log('compilation result: ' + compilationResult) |
try { |
||||||
|
const result = JSON.parse(parsedOutput) |
||||||
|
const markers = [] |
||||||
|
|
||||||
generate_witness(compilationResult, '{ "a": "3", "b": "11" }') |
for (const report of result) { |
||||||
generate_witness(compilationResult, '{ "a": "5", "b": "77" }') |
for (const label in report.labels) { |
||||||
} |
if (report.labels[label].file_id === '0') { |
||||||
|
// @ts-ignore
|
||||||
async parse (path: string) { |
const startPosition: { lineNumber: number, column: number } = await this.call('editor', 'getPositionAt', report.labels[label].range.start) |
||||||
const fileContent = await this.call('fileManager', 'readFile', path) |
// @ts-ignore
|
||||||
let buildFiles = { |
const endPosition: { lineNumber: number, column: number } = await this.call('editor', 'getPositionAt', report.labels[label].range.end) |
||||||
[path]: fileContent |
|
||||||
|
|
||||||
|
console.log('startPosition: ', startPosition) |
||||||
|
console.log('endPosition: ', endPosition) |
||||||
|
markers.push({ |
||||||
|
message: report.message, |
||||||
|
severity: report.type.toLowerCase(), |
||||||
|
position: { |
||||||
|
start: { |
||||||
|
line: startPosition.lineNumber, |
||||||
|
column: startPosition.column |
||||||
|
}, |
||||||
|
end: { |
||||||
|
line: endPosition.lineNumber, |
||||||
|
column: endPosition.column |
||||||
|
} |
||||||
|
}, |
||||||
|
file: path |
||||||
|
}) |
||||||
|
} |
||||||
} |
} |
||||||
|
} |
||||||
buildFiles = await this.resolveDependencies(path, fileContent, buildFiles) |
// @ts-ignore
|
||||||
const parsingResult = parse_circuit_browser(path, buildFiles, { prime: "bn128" }) |
await this.call('editor', 'addErrorMarker', markers) |
||||||
|
} catch (e) { |
||||||
console.log('parsing result: ' + parsingResult) |
// @ts-ignore
|
||||||
|
await this.call('editor', 'clearErrorMarkers', [path]) |
||||||
|
console.log(parsedOutput) |
||||||
} |
} |
||||||
|
} |
||||||
async resolveDependencies (filePath: string, fileContent: string, output = {}, depPath: string = '', blackPath: string[] = []) { |
|
||||||
const includes = (fileContent.match(/include ['"].*['"]/g) || []).map(include => include.replace(/include ['"]/g, '').replace(/['"]/g, '')) |
async resolveDependencies (filePath: string, fileContent: string, output = {}, depPath: string = '', blackPath: string[] = []): Promise<Record<string, string>> { |
||||||
|
const includes = (fileContent.match(/include ['"].*['"]/g) || []).map(include => include.replace(/include ['"]/g, '').replace(/['"]/g, '')) |
||||||
await Promise.all(includes.map(async include => { |
|
||||||
// fix for endless recursive includes
|
await Promise.all(includes.map(async include => { |
||||||
if (blackPath.includes(include)) return |
// fix for endless recursive includes
|
||||||
let dependencyContent = '' |
if (blackPath.includes(include)) return |
||||||
let path = include |
let dependencyContent = '' |
||||||
// @ts-ignore
|
let path = include |
||||||
const pathExists = await this.call('fileManager', 'exists', path) |
// @ts-ignore
|
||||||
|
const pathExists = await this.call('fileManager', 'exists', path) |
||||||
if (pathExists) { |
|
||||||
dependencyContent = await this.call('fileManager', 'readFile', path) |
if (pathExists) { |
||||||
} else { |
dependencyContent = await this.call('fileManager', 'readFile', path) |
||||||
let relativePath = pathModule.resolve(filePath.slice(0, filePath.lastIndexOf('/')), include) |
} else { |
||||||
if (relativePath.indexOf('/') === 0) relativePath = relativePath.slice(1) |
let relativePath = pathModule.resolve(filePath.slice(0, filePath.lastIndexOf('/')), include) |
||||||
// @ts-ignore
|
if (relativePath.indexOf('/') === 0) relativePath = relativePath.slice(1) |
||||||
const relativePathExists = await this.call('fileManager', 'exists', relativePath) |
// @ts-ignore
|
||||||
|
const relativePathExists = await this.call('fileManager', 'exists', relativePath) |
||||||
if (relativePathExists) { |
|
||||||
dependencyContent = await this.call('fileManager', 'readFile', relativePath) |
if (relativePathExists) { |
||||||
} else { |
dependencyContent = await this.call('fileManager', 'readFile', relativePath) |
||||||
if (depPath) { |
} else { |
||||||
path = pathModule.resolve(depPath.slice(0, depPath.lastIndexOf('/')), include) |
if (depPath) { |
||||||
if (path.indexOf('/') === 0) path = path.slice(1) |
path = pathModule.resolve(depPath.slice(0, depPath.lastIndexOf('/')), include) |
||||||
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) |
if (path.indexOf('/') === 0) path = path.slice(1) |
||||||
} else { |
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) |
||||||
if (include.startsWith('circomlib')) { |
} else { |
||||||
const splitInclude = include.split('/') |
if (include.startsWith('circomlib')) { |
||||||
const version = splitInclude[1].match(/v[0-9]+.[0-9]+.[0-9]+/g) |
const splitInclude = include.split('/') |
||||||
|
const version = splitInclude[1].match(/v[0-9]+.[0-9]+.[0-9]+/g) |
||||||
|
|
||||||
if (version && version[0]) { |
if (version && version[0]) { |
||||||
path = `https://raw.githubusercontent.com/iden3/circomlib/${version[0]}/circuits/${splitInclude.slice(2).join('/')}` |
path = `https://raw.githubusercontent.com/iden3/circomlib/${version[0]}/circuits/${splitInclude.slice(2).join('/')}` |
||||||
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) |
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) |
||||||
} else { |
} else { |
||||||
path = `https://raw.githubusercontent.com/iden3/circomlib/master/circuits/${splitInclude.slice(1).join('/')}` |
path = `https://raw.githubusercontent.com/iden3/circomlib/master/circuits/${splitInclude.slice(1).join('/')}` |
||||||
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) |
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) |
||||||
} |
} |
||||||
} else { |
|
||||||
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
const dependencyIncludes = (dependencyContent.match(/include ['"].*['"]/g) || []).map(include => include.replace(/include ['"]/g, '').replace(/['"]/g, '')) |
|
||||||
|
|
||||||
blackPath.push(include) |
|
||||||
if (dependencyIncludes.length > 0) { |
|
||||||
await this.resolveDependencies(filePath, dependencyContent, output, path, blackPath) |
|
||||||
output[include] = dependencyContent |
|
||||||
} else { |
} else { |
||||||
output[include] = dependencyContent |
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null) |
||||||
} |
} |
||||||
})) |
} |
||||||
return output |
} |
||||||
} |
} |
||||||
|
const dependencyIncludes = (dependencyContent.match(/include ['"].*['"]/g) || []).map(include => include.replace(/include ['"]/g, '').replace(/['"]/g, '')) |
||||||
|
|
||||||
|
blackPath.push(include) |
||||||
|
if (dependencyIncludes.length > 0) { |
||||||
|
await this.resolveDependencies(filePath, dependencyContent, output, path, blackPath) |
||||||
|
output[include] = dependencyContent |
||||||
|
} else { |
||||||
|
output[include] = dependencyContent |
||||||
|
} |
||||||
|
})) |
||||||
|
return output |
||||||
|
} |
||||||
} |
} |
||||||
|
@ -1,22 +0,0 @@ |
|||||||
import { Dispatch } from "react" |
|
||||||
|
|
||||||
export interface IAppContext { |
|
||||||
appState: AppState, |
|
||||||
dispatch: Dispatch<any> |
|
||||||
} |
|
||||||
|
|
||||||
export interface ActionPayloadTypes { |
|
||||||
SET_REMIXD_CONNECTION_STATUS: boolean |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
export interface Action <T extends keyof ActionPayloadTypes> { |
|
||||||
type: T |
|
||||||
payload: ActionPayloadTypes[T] |
|
||||||
} |
|
||||||
|
|
||||||
export type Actions = { [A in keyof ActionPayloadTypes]: Action<A> }[keyof ActionPayloadTypes] |
|
||||||
|
|
||||||
export interface AppState { |
|
||||||
isRemixdConnected: boolean |
|
||||||
} |
|
Before Width: | Height: | Size: 1.7 KiB |
Loading…
Reference in new issue