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.
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