2024-11-12 16:56:05 +07:00
2024-08-06 15:46:13 +10:00
2024-09-05 12:10:58 +10:00
2024-10-16 15:10:10 +11:00
2024-08-05 14:14:03 +10:00
2024-10-16 15:10:10 +11:00
2024-10-16 15:10:10 +11:00
2024-11-12 16:56:05 +07:00
2024-08-05 14:14:03 +10:00

mpc-framework

MPC framework supporting a variety of circuit generators and backends.

In particular, emp-wasm-backend powers secure 2PC based on Authenticated Garbling and Efficient Maliciously Secure Two-Party Computation.

Usage

npm install mpc-framework emp-wasm-backend summon-ts
import * as mpcf from 'mpc-framework';
import { EmpWasmBackend } from 'emp-wasm-backend';
import * as summon from 'summon-ts';

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

  const circuit = summon.compileBoolean('/src/main.ts', 4, {
    // Depending on your build tooling, you can write this code in regular files
    // and benefit from typescript's type checking.
    '/src/main.ts': `
      export default function main(a: number, b: number) {
        return a + b;
      }
    `,
  });

  const mpcSettings = [
    {
      name: 'alice',
      inputs: ['a'],
      outputs: ['main'],
    },
    {
      name: 'bob',
      inputs: ['b'],
      outputs: ['main'],
    },
  ];

  const protocol = new mpcf.Protocol(
    circuit,
    mpcSettings,
    new EmpWasmBackend(),
  );

  function send(to: string, msg: Uint8Array) {
    // implement sending a message to the specified party
  }

  const session = protocol.join('alice', { a: 3 }, send);

  // This is just a hypothetical API for getting external messages
  onMessageReceived((from: string, msg: Uint8Array) => {
    // The important part is that you provide the messages to the session like
    // this
    session.handleMessage(from, msg);
  });

  // assume someone else joins as bob and provides { b: 5 }

  console.log(await session.output()); // { main: 5 }
}

main().catch(console.error);

See MPC Hello for a complete example in 250 sloc featuring:

  • Simple frontend
  • P2P end-to-end encrypted communication
  • Circuit code included via ordinary project files

Example Projects

Description
No description provided
Readme MIT 202 KiB
Languages
TypeScript 100%