summon-ts
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

summon-ts

TypeScript build of the Summon compiler (via wasm).

Usage

npm install summon-ts
import * as summon from 'summon-ts';

async function main() {
  await summon.init();

  // for boolean circuits: summon.compileBoolean('/src/main.ts', 8, { ... })
  // (replace 8 with your desired uint precision)
  const { circuit, diagnostics } = summon.compile('/src/main.ts', {
    // In a real project you should be able to include these as regular files,
    // but how those files find their way into this format depends on your build
    // tool.
    // Example: https://github.com/voltrevo/mpc-hello/blob/c1c8092/src/getCircuitFiles.ts

    '/src/main.ts': `
      export default function main(a: number, b: number) {
        return a + b;
      }
    `,
  });

  console.log(circuit);
  // {
  //   bristol: '...',
  //   info: { ... },
  // }

  // May include non-error diagnostics.
  // (If there are errors, summon.compile will throw instead.)
  console.log(diagnostics);
  // { './circuit/main.ts': [] }

  // See mpc-framework for doing MPC with your circuits.
  // https://github.com/voltrevo/mpc-framework
}

// When summon.compile throws, the error message will be the first error
// diagnostic. The remaining diagnostics are also available as error.diagnostics
// and the compiled circuit might also be available as .circuit.
main().catch(console.error);

When providing files to the API, you can also substitute a file reader (filePath: string) => string. Like this:

summon.compile('/full/path/to/main.ts', filePath => fs.readFileSync(filePath));

Development

Build with npm run build. This will compile the wasm subproject and also transpile typescript into javascript. Rust toolchain required.

Test with npm test.

Example Projects

Package Sidebar

Install

npm i summon-ts

Weekly Downloads

81

Version

0.4.0

License

MIT

Unpacked Size

3.48 MB

Total Files

41

Last publish

Collaborators

  • voltrevo
  • cedoor