Skip to content

Commit

Permalink
protocols/arrays/open.js done
Browse files Browse the repository at this point in the history
  • Loading branch information
Snafkin547 committed May 24, 2024
1 parent 71bb3af commit b2b46da
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 95 deletions.
10 changes: 6 additions & 4 deletions lib/client/protocols/arrays/api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const share = require('./share.js');
const open = require('./open.js');
const ArrayOpen = require('./open.js');
const util = require('./util.js');

arrayOpen = new ArrayOpen();

Check failure on line 5 in lib/client/protocols/arrays/api.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/protocols/arrays/api.js#L5

'arrayOpen' is not defined.

module.exports = {
jiff_share_array: share.share_array,
jiff_share_2D_array: share.share_2D_array,
Expand All @@ -11,7 +13,7 @@ module.exports = {

jiff_skeleton_of: util.skeleton_of,

jiff_open_array: open.open_array,
jiff_open_ND_array: open.open_ND_array,
jiff_receive_open_ND_array: open.receive_open_ND_array
jiff_open_array: arrayOpen.open_array,

Check failure on line 16 in lib/client/protocols/arrays/api.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/protocols/arrays/api.js#L16

'arrayOpen' is not defined.
jiff_open_ND_array: arrayOpen.open_ND_array,

Check failure on line 17 in lib/client/protocols/arrays/api.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/protocols/arrays/api.js#L17

'arrayOpen' is not defined.
jiff_receive_open_ND_array: arrayOpen.receive_open_ND_array

Check failure on line 18 in lib/client/protocols/arrays/api.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/protocols/arrays/api.js#L18

'arrayOpen' is not defined.
};
180 changes: 89 additions & 91 deletions lib/client/protocols/arrays/open.js
Original file line number Diff line number Diff line change
@@ -1,115 +1,113 @@
const open_array = function (jiff, shares, parties, op_ids) {
// A base operation id is provided to use for all opens.
if (typeof op_ids === 'string' || typeof op_ids === 'number') {
const tmp = { s1: op_ids };
for (let i = 1; i <= jiff.party_count; i++) {
tmp[i] = op_ids;
class ArrayOpen {
open_array(jiff, shares, parties, op_ids) {
// A base operation id is provided to use for all opens.
if (typeof op_ids === 'string' || typeof op_ids === 'number') {
const tmp = { s1: op_ids };
for (let i = 1; i <= jiff.party_count; i++) {
tmp[i] = op_ids;
}
op_ids = tmp;
}
op_ids = tmp;
}

return open_ND_array(jiff, shares, parties, null, op_ids);
};
return open_ND_array(jiff, shares, parties, null, op_ids);

Check failure on line 12 in lib/client/protocols/arrays/open.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/protocols/arrays/open.js#L12

'open_ND_array' is not defined.
}

const open_ND_array = function (jiff, shares, receivers_list, senders_list, op_ids) {
if (senders_list == null) {
senders_list = [];
for (let i = 1; i <= jiff.party_count; i++) {
senders_list.push(i);
}
if (receivers_list == null) {
receivers_list = Array.from(senders_list);
open_ND_array(jiff, shares, receivers_list, senders_list, op_ids) {
if (senders_list == null) {
senders_list = [];
for (let i = 1; i <= jiff.party_count; i++) {
senders_list.push(i);
}
if (receivers_list == null) {
receivers_list = Array.from(senders_list);
}
}
}
const is_sending = senders_list.indexOf(jiff.id) > -1;
const is_sending = senders_list.indexOf(jiff.id) > -1;

// Compute operation id
/*
*if (op_ids == null) {
* op_ids = jiff.counters.gen_op_id('open_ND_array', receivers_list.concat(senders_list));
*}
*/
// Compute operation id
/*
*if (op_ids == null) {
* op_ids = jiff.counters.gen_op_id('open_ND_array', receivers_list.concat(senders_list));
*}
*/

const final_deferred = new jiff.helpers.Deferred();
const final_promise = final_deferred.promise;
const resolve_open = function (shares) {
final_deferred.resolve(
(function __open_ND_array(shares, parties, op_ids) {
if (typeof shares.length === 'undefined') {
return jiff.internal_open(shares, parties);
} else if (shares.length === 0) {
return Promise.resolve([]);
} else {
const promised_array = [];
for (let i = 0; i < shares.length; i++) {
promised_array.push(__open_ND_array(shares[i], parties, op_ids + ':' + i));
const final_deferred = new jiff.helpers.Deferred();
const final_promise = final_deferred.promise;
function resolve_open(shares) {
final_deferred.resolve(
(function __open_ND_array(shares, parties, op_ids) {
if (typeof shares.length === 'undefined') {
return jiff.internal_open(shares, parties);
} else if (shares.length === 0) {
return Promise.resolve([]);
} else {
const promised_array = [];
for (let i = 0; i < shares.length; i++) {
promised_array.push(__open_ND_array(shares[i], parties, op_ids + ':' + i));
}
return Promise.all(promised_array);
}
return Promise.all(promised_array);
}
})(shares, receivers_list, op_ids)
);
};

if (is_sending) {
// Must emit the skeleton for any parties that are not holders but are receiving the open
const skeleton = (function __unwipe(nd_array, replace) {
if (!(typeof nd_array.length === 'undefined') || nd_array.length === 0) {
const unwiped_array = [];
for (let k = 0; k < nd_array.length; k++) {
unwiped_array.push(__unwipe(nd_array[k], replace));
}
return unwiped_array;
}
return replace;
})(shares, null);
jiff.emit(op_ids + 'skeleton', receivers_list, JSON.stringify(skeleton));
})(shares, receivers_list, op_ids)
);
}

resolve_open(shares);
} else {
// Populate skeleton with imitation shares
const revive_shares = function (skeleton) {
const share = new jiff.SecretShare({}, senders_list, senders_list.length, jiff.Zp);
return (function __unwipe(nd_array, replace) {
if (nd_array != null && !(typeof nd_array.length === 'undefined' && nd_array.length > 0)) {
if (is_sending) {
// Must emit the skeleton for any parties that are not holders but are receiving the open
const skeleton = (function __unwipe(nd_array, replace) {
if (!(typeof nd_array.length === 'undefined') || nd_array.length === 0) {
const unwiped_array = [];
for (let k = 0; k < nd_array.length; k++) {
unwiped_array.push(__unwipe(nd_array[k], replace));
}
return unwiped_array;
}
return replace;
})(skeleton, share);
};
})(shares, null);
jiff.emit(op_ids + 'skeleton', receivers_list, JSON.stringify(skeleton));

// If this party is not a sender, then the variable `shares` may be a skeleton
if (shares != null) {
// Use existing shares as skeleton to revive
shares = revive_shares(shares);
resolve_open(shares);
} else {
// Receive skeleton from senders
jiff.listen(op_ids + 'skeleton', function (sender, skeleton) {
jiff.remove_listener(op_ids + 'skeleton'); // This doesn't seem to work

if (typeof skeleton === 'string') {
skeleton = JSON.parse(skeleton);
}
// Populate skeleton with imitation shares
const revive_shares = function (skeleton) {
const share = new jiff.SecretShare({}, senders_list, senders_list.length, jiff.Zp);
return (function __unwipe(nd_array, replace) {
if (nd_array != null && !(typeof nd_array.length === 'undefined' && nd_array.length > 0)) {
const unwiped_array = [];
for (let k = 0; k < nd_array.length; k++) {
unwiped_array.push(__unwipe(nd_array[k], replace));
}
return unwiped_array;
}
return replace;
})(skeleton, share);
};

shares = revive_shares(skeleton);
// If this party is not a sender, then the variable `shares` may be a skeleton
if (shares != null) {
// Use existing shares as skeleton to revive
shares = revive_shares(shares);
resolve_open(shares);
});
} else {
// Receive skeleton from senders
jiff.listen(op_ids + 'skeleton', function (sender, skeleton) {
jiff.remove_listener(op_ids + 'skeleton'); // This doesn't seem to work

if (typeof skeleton === 'string') {
skeleton = JSON.parse(skeleton);
}

shares = revive_shares(skeleton);
resolve_open(shares);
});
}
}
}

return final_promise;
};
return final_promise;
}

const receive_open_ND_array = function (jiff, receivers_list, senders_list, threshold, Zp, op_ids) {
return open_ND_array(jiff, null, receivers_list, senders_list, op_ids);
};
receive_open_ND_array(jiff, receivers_list, senders_list, threshold, Zp, op_ids) {
return open_ND_array(jiff, null, receivers_list, senders_list, op_ids);

Check failure on line 109 in lib/client/protocols/arrays/open.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/protocols/arrays/open.js#L109

'open_ND_array' is not defined.
}
}

module.exports = {
open_array: open_array,
open_ND_array: open_ND_array,
receive_open_ND_array: receive_open_ND_array
};
module.exports = ArrayOpen;

0 comments on commit b2b46da

Please sign in to comment.