Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added build/7b67907a7d35820d9e78.module.wasm
Binary file not shown.
3 changes: 2 additions & 1 deletion build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<script src="script-runner.js"></script>
<script src="yarn-loader-standalone.js"></script>
<script src="script-runner.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
</head>
</html>
253,643 changes: 253,641 additions & 2 deletions build/script-runner.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions build/script-runner.js.map

Large diffs are not rendered by default.

819 changes: 819 additions & 0 deletions build/vendors-node_modules_zokrates-js_pkg_index_js.script-runner.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

89,531 changes: 89,531 additions & 0 deletions build/yarn-loader-standalone.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
"@babel/preset-stage-0": "^7.0.0",
"@babel/register": "^7.4.4",
"@ethereum-waffle/chai": "^3.4.4",
"@msgpack/msgpack": "^3.0.0-beta2",
"@remixproject/plugin": "^0.3.1",
"@remixproject/plugin-iframe": "^0.3.1",
"@semaphore-protocol/contracts": "^3.11.0",
"@semaphore-protocol/group": "^3.11.0",
"@semaphore-protocol/identity": "^3.11.0",
"@semaphore-protocol/proof": "^3.11.0",
"@yarnpkg/core": "^4.0.0-rc.51",
"@yarnpkg/plugin-node-modules": "^3.0.0-rc.9",
"@yarnpkg/plugin-npm": "^3.0.0-rc.51",
"@yarnpkg/plugin-pack": "^4.0.0-rc.51",
"@zk-kit/incremental-merkle-tree": "^1.1.0",
"babelify": "^10.0.0",
"chai": "^4.3.6",
Expand All @@ -31,16 +36,23 @@
"crypto-browserify": "^3.12.0",
"ethers": "^5.4.7",
"fast-async": "^7.0.6",
"http2": "^3.3.7",
"https-browserify": "^1.0.0",
"idb": "5.0.8",
"memfs": "^4.3.0",
"mocha": "^9.2.0",
"multihashes": "^4.0.3",
"net-browserify": "^0.2.4",
"node-polyfill-webpack-plugin": "^2.0.1",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"querystring-es3": "^0.2.1",
"snarkjs": "0.7.0",
"starknet": "^3.15.0",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"tls": "^0.0.1",
"tty-browserify": "^0.0.1",
"typescript": "^4.6.2",
"web3": "^1.5.3",
"webpack": "^5.74.0",
Expand Down
32 changes: 32 additions & 0 deletions polyfills/v8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as msgpack from "@msgpack/msgpack";
const { Buffer } = require("buffer");

export let serialize = (v) =>
Buffer.from(msgpack.encode(v, { extensionCodec }));
export let deserialize = (v) => msgpack.decode(v, { extensionCodec });

// Derived fromƒ
// https://github.com/msgpack/msgpack-javascript#extension-types
const extensionCodec = new msgpack.ExtensionCodec();
extensionCodec.register({
type: 0,
decode(value) {
return new Set(msgpack.decode(value, { extensionCodec }));
},
encode(value) {
return value instanceof Set
? msgpack.encode([...value], { extensionCodec })
: null;
},
});
extensionCodec.register({
type: 1,
decode(value) {
return new Map(msgpack.decode(value, { extensionCodec }));
},
encode(value) {
return value instanceof Map
? msgpack.encode([...value], { extensionCodec })
: null;
},
});
156 changes: 107 additions & 49 deletions src/script-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,48 @@ import "@babel/polyfill"
import * as ts from "typescript";
import { createClient } from '@remixproject/plugin-iframe'
import { PluginClient } from '@remixproject/plugin'
import * as ethersJs from 'ethers' // eslint-disable-line
import multihash from 'multihashes'
import * as web3Js from 'web3'
import Web3 from 'web3'
import { waffleChai } from "@ethereum-waffle/chai";
import * as starknet from 'starknet'
import * as zokratesJs from 'zokrates-js';
import * as circomlibjs from 'circomlibjs';
const snarkjs = require('snarkjs');
import * as zkkitIncrementalMerkleTree from '@zk-kit/incremental-merkle-tree';
import * as semaphoreProtocolProof from '@semaphore-protocol/proof'
// import * as semaphoreProtocolContracts from '@semaphore-protocol/contracts'
import * as semaphoreProtocolGroup from '@semaphore-protocol/group'
import * as semaphoreProtocolIdentity from '@semaphore-protocol/identity'
import './runWithMocha'
import * as path from 'path'
import * as hhEtherMethods from './hardhat-ethers/methods'
import { yarnLoader, yarnContext } from './yarn/yarn-loader'
const chai = require('chai')
chai.use(waffleChai)

window.starknet = starknet
window.chai = chai
window.ethers = ethersJs
window.multihashes = multihash
window['zokrates-js'] = zokratesJs
window['snarkjs'] = snarkjs
window['circomlibjs'] = circomlibjs
window['@zk-kit/incremental-merkle-tree'] = zkkitIncrementalMerkleTree

window['@semaphore-protocol/proof'] = semaphoreProtocolProof
// window['@semaphore-protocol/contracts'] = semaphoreProtocolContracts
window['@semaphore-protocol/group'] = semaphoreProtocolGroup
window['@semaphore-protocol/identity'] = semaphoreProtocolIdentity

let currentStopWatch = 0

const scriptReturns = {} // keep track of modules exported values
const fileContents = {} // keep track of file content
window.require = (module) => {
if (module === 'web3') return web3Js
if (window[module]) return window[module] // library
else if ((module.endsWith('.json') || module.endsWith('.abi')) && window.__execPath__ && fileContents[window.__execPath__]) return JSON.parse(fileContents[window.__execPath__][module])
else if (window.__execPath__ && scriptReturns[window.__execPath__]) return scriptReturns[window.__execPath__][module] // module exported values
else throw new Error(`${module} module require is not supported by Remix IDE`)
window.require = (module) => {
if ((module.endsWith('.json') || module.endsWith('.abi')) && window.__execPath__ && fileContents[window.__execPath__]) return JSON.parse(fileContents[window.__execPath__][module])
else if (window.__execPath__ && scriptReturns[window.__execPath__]) {
let returns = scriptReturns[window.__execPath__][module] || scriptReturns[window.__execPath__][module + '.js'] // module exported values
if (module === 'ethers') {
// Support hardhat-ethers, See: https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html
returns.provider = new ethers.providers.Web3Provider(window.web3Provider)
for(const method in hhEtherMethods) Object.defineProperty(returns, method, { value: hhEtherMethods[method]})
}
return returns
} else {
throw new Error(`${module} module require is not supported by Remix IDE`)
}
}

class CodeExecutor extends PluginClient {
onActivation () {
this.on('filePanel', 'setWorkspace', (workspace) => {
console.log('opening a new workspace in script runner ', workspace)
yarnLoader(this)
})
}
async execute (script, filePath) {
filePath = filePath || 'scripts/script.ts'
const paths = filePath.split('/')
paths.pop()
const fromPath = paths.join('/') // get current execcution context path
const fromPath = paths.join('/') // get current execution context path
if (script) {
try {
script = ts.transpileModule(script, { moduleName: filePath, filePath,
Expand All @@ -76,16 +68,22 @@ class CodeExecutor extends PluginClient {
if (!scriptReturns[fromPath]) scriptReturns[fromPath] = {}
if (!fileContents[fromPath]) fileContents[fromPath] = {}
const { returns, content } = await this.executeFile(absolutePath)

scriptReturns[fromPath][file] = returns
fileContents[fromPath][file] = content
}

// execute the script
script = `const exports = {};
const module = { exports: {} }
script = `let exports = {};
let module = { exports: {} }
window.__execPath__ = "${fromPath}"
${script};
return exports || module.exports`
if (Object.keys(exports).length) {
return exports
} else {
return module.exports
}
`
const returns = (new Function(script))()
if (mocha.suite && ((mocha.suite.suites && mocha.suite.suites.length) || (mocha.suite.tests && mocha.suite.tests.length))) {
console.log(`RUNS ${filePath}....`)
Expand All @@ -100,18 +98,84 @@ class CodeExecutor extends PluginClient {
}
}

async _resolveRemixFileSystem(fileName) {
if (await this.call('fileManager', 'exists', fileName)) return { content: await this.call('fileManager', 'readFile', fileName) }
if (await this.call('fileManager', 'exists', fileName + '.ts')) return { content: await this.call('fileManager', 'readFile', fileName + '.ts') }
if (await this.call('fileManager', 'exists', fileName + '.js')) return { content: await this.call('fileManager', 'readFile', fileName + '.js') }
return {content: null}
}

async _resolveYarnFileSystem(fileName) {
let path = fileName.indexOf('/app/node_modules/') !== -1 ? fileName : `/app/node_modules/${fileName}`
let content
let isDirectory = false
try {
isDirectory = yarnContext.memfs.lstatSync(path).isDirectory()
} catch (e) {}

if (isDirectory) {
let main = null

// main property of package.json
const packageJson = `/app/node_modules/${fileName}/package.json`
const isFile = yarnContext.memfs.lstatSync(packageJson).isFile()
if (isFile) {
const json = JSON.parse(yarnContext.memfs.readFileSync(packageJson, { encoding: 'utf8' }))
if (json.main) main = `/app/node_modules/${fileName}/${json.main}`
}

if (!main) {
// looking for an entry point
const hasDistDirectory = yarnContext.memfs.lstatSync(`/app/node_modules/${fileName}/dist`).isDirectory()
if (hasDistDirectory) {
// dist folder
const hasDistBuild = yarnContext.memfs.lstatSync(`/app/node_modules/${fileName}/dist/${fileName}.js`).isFile()
if (hasDistBuild) main = `/app/node_modules/${fileName}/dist/${fileName}.js`
}
}

if (main) {
content = yarnContext.memfs.readFileSync(main, { encoding: 'utf8' })
return { content, path: main }
}
return { content: null}
}

let isFile = false
try {
isFile = yarnContext.memfs.lstatSync(path).isFile()
} catch (e) {}

if (isFile) {
content = yarnContext.memfs.readFileSync(path, { encoding: 'utf8' })
return { content, path }
}

if (!path.endsWith('.js')) path = path + '.js'
try {
isFile = yarnContext.memfs.lstatSync(path).isFile()
} catch (e) {}

if (isFile) {
content = yarnContext.memfs.readFileSync(path, { encoding: 'utf8' })
return { content, path }
}
return { content: null }
}

async _resolveFile (fileName) {
if (await this.call('fileManager', 'exists', fileName)) return await this.call('fileManager', 'readFile', fileName)
if (await this.call('fileManager', 'exists', fileName + '.ts')) return await this.call('fileManager', 'readFile', fileName + '.ts')
if (await this.call('fileManager', 'exists', fileName + '.js')) return await this.call('fileManager', 'readFile', fileName + '.js')
const { content, path } = await this._resolveRemixFileSystem(fileName)
if (content) return { content, path }
const ret = await this._resolveYarnFileSystem(fileName)
return ret
}

async executeFile (fileName) {
try {
if (require(fileName)) return require(fileName)
} catch (e) {}
const content = await this._resolveFile(fileName)
const returns = await this.execute(content, fileName)
const { content, path } = await this._resolveFile(fileName)
const returns = await this.execute(content, path || fileName)
return {returns, content}
}
}
Expand All @@ -131,36 +195,30 @@ window.ethereum = web3Provider

window.web3 = new Web3(window.web3Provider)

// Support hardhat-ethers, See: https://hardhat.org/plugins/nomiclabs-hardhat-ethers.html
const { ethers } = ethersJs
ethers.provider = new ethers.providers.Web3Provider(window.web3Provider)
window.hardhat = { ethers }
for(const method in hhEtherMethods) Object.defineProperty(window.hardhat.ethers, method, { value: hhEtherMethods[method]})

console.logInternal = console.log
console.log = function () {
window.remix.emit('log', {
data: Array.from(arguments).map((el) => JSON.parse(JSON.stringify(el)))
data: Array.from(arguments).map((el) => el ? JSON.parse(JSON.stringify(el)) : 'undefined')
})
}

console.infoInternal = console.info
console.info = function () {
window.remix.emit('info', {
data: Array.from(arguments).map((el) => JSON.parse(JSON.stringify(el)))
data: Array.from(arguments).map((el) => el ? JSON.parse(JSON.stringify(el)) : 'undefined')
})
}

console.warnInternal = console.warn
console.warn = function () {
window.remix.emit('warn', {
data: Array.from(arguments).map((el) => JSON.parse(JSON.stringify(el)))
data: Array.from(arguments).map((el) => el ? JSON.parse(JSON.stringify(el)) : 'undefined')
})
}

console.errorInternal = console.error
console.error = function () {
window.remix.emit('error', {
data: Array.from(arguments).map((el) => JSON.parse(JSON.stringify(el)))
data: Array.from(arguments).map((el) => el ? JSON.parse(JSON.stringify(el)) : 'undefined')
})
}
Loading