diff --git a/README.md b/README.md index dbad28a..78453c5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ This is a template repository designed to be the hello-world of It's a minimal web app where users can make 1-to-1 connections with each other and compute the larger of two numbers. -## Usage +Hosted on github pages: https://voltrevo.github.io/mpc-hello/. + +## Running Locally ```sh npm install diff --git a/src/circuit/isLarger.ts b/src/circuit/isLarger.ts new file mode 100644 index 0000000..3c47ef8 --- /dev/null +++ b/src/circuit/isLarger.ts @@ -0,0 +1,3 @@ +export default function isLarger(a: number, b: number): boolean { + return a > b; +} diff --git a/src/circuit/main.ts b/src/circuit/main.ts new file mode 100644 index 0000000..9d84473 --- /dev/null +++ b/src/circuit/main.ts @@ -0,0 +1,7 @@ +// This obviously doesn't need to be a separate file, but it's here to +// demonstrate that you can split up your summon code like this. +import isLarger from './isLarger.ts'; + +export default function main(a: number, b: number) { + return isLarger(a, b) ? a : b; +} diff --git a/src/generateProtocol.ts b/src/generateProtocol.ts index 0f301bf..1b37c79 100644 --- a/src/generateProtocol.ts +++ b/src/generateProtocol.ts @@ -1,17 +1,16 @@ import * as summon from 'summon-ts'; import { Protocol } from 'mpc-framework'; import { EmpWasmBackend } from 'emp-wasm-backend'; +import getCircuitFiles from './getCircuitFiles'; export default async function generateProtocol() { await summon.init(); - const circuit = summon.compileBoolean('/src/main.ts', 16, { - '/src/main.ts': ` - export default function main(a: number, b: number) { - return a > b ? a : b; - } - `, - }); + const circuit = summon.compileBoolean( + 'circuit/main.ts', + 16, + await getCircuitFiles(), + ); const mpcSettings = [ { diff --git a/src/getCircuitFiles.ts b/src/getCircuitFiles.ts new file mode 100644 index 0000000..8ac3078 --- /dev/null +++ b/src/getCircuitFiles.ts @@ -0,0 +1,11 @@ +const files = import.meta.glob('./circuit/**/*.ts', { query: '?raw', import: 'default' }); + +export default async function getCircuitFiles() { + const circuitFiles: Record = {}; + + for (const [path, get] of Object.entries(files)) { + circuitFiles[path.slice(2)] = (await get()) as string; + } + + return circuitFiles; +} diff --git a/tsconfig.json b/tsconfig.json index a7fc6fb..4e8b2e5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,10 +2,16 @@ "compilerOptions": { "target": "ES2020", "useDefineForClassFields": true, - "lib": ["ES2020", "DOM", "DOM.Iterable"], + "lib": [ + "ES2020", + "DOM", + "DOM.Iterable" + ], "module": "ESNext", "skipLibCheck": true, - + "types": [ + "vite/client" + ], /* Bundler mode */ "moduleResolution": "bundler", "allowImportingTsExtensions": true, @@ -13,13 +19,18 @@ "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", - /* Linting */ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true }, - "include": ["src"], - "references": [{ "path": "./tsconfig.node.json" }] -} + "include": [ + "src" + ], + "references": [ + { + "path": "./tsconfig.node.json" + } + ] +} \ No newline at end of file