-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparty.js
65 lines (54 loc) · 1.63 KB
/
party.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
console.log('Command line arguments: <input> [<party count> [<computation_id> [<party id>]]]]');
// Parse command line arguments.
function parseCommandLine() {
// Read Command line arguments
const input = parseInt(process.argv[2], 10);
let party_count = process.argv[3];
if (party_count == null) {
party_count = 2;
} else {
party_count = parseInt(party_count);
}
let computation_id = process.argv[4];
if (computation_id == null) {
computation_id = 'test';
}
let party_id = process.argv[5];
if (party_id != null) {
party_id = parseInt(party_id, 10);
}
return {
input: input,
party_count: party_count,
party_id: party_id,
computation_id: computation_id
};
}
// The MPC computation
async function computation(args, jiffClient) {
// Share our secret input with the other parties.
let shares = jiffClient.share(args.input);
// Sum all secret inputs.
let sum = shares[1];
for (let i = 2; i <= jiffClient.party_count; i++) {
sum = sum.sadd(shares[i]);
}
// get the final output(s)
const output = await jiffClient.open(sum);
console.log('Output: ', output.toString());
// disconnect safetly.
jiffClient.disconnect(true, true);
}
function connect(args) {
const { JIFFClient, JIFFClientBigNumber } = require('jiff-mpc');
const jiffClient = new JIFFClient('http://localhost:8080', args.computation_id, {
autoConnect: false,
party_count: args.party_count,
party_id: args.party_id,
onConnect: computation.bind(null, args),
crypto_provider: true
});
jiffClient.apply_extension(JIFFClientBigNumber, {});
jiffClient.connect();
}
connect(parseCommandLine());