Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier Initiated #264

Merged
merged 7 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tutorials
docs
coverage
demos
.circleci
.github
.travis.yml
*.html
*.md
/dist
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 200,
"singleQuote": true,
"trailingComma": "none",
"tabWidth": 2
}
3 changes: 1 addition & 2 deletions lib/client/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var synchronization = require('./api/synchronization.js');
var protocols = require('./api/protocols.js');
var bitsProtocols = require('./api/bits.js');


module.exports = function (jiffClient) {
initialization(jiffClient);
sharing(jiffClient);
Expand All @@ -17,4 +16,4 @@ module.exports = function (jiffClient) {

protocols(jiffClient);
bitsProtocols(jiffClient);
};
};
2 changes: 1 addition & 1 deletion lib/client/api/bits.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,4 @@ module.exports = function (jiffClient) {
* @returns {promise} a (JQuery) promise to the open value of the secret
*/
jiffClient.protocols.bits.receive_open = sharing.receive_open_bits.bind(null, jiffClient);
};
};
4 changes: 2 additions & 2 deletions lib/client/api/crypto_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = function (jiffClient) {
}

// Send a request to the server
var msg = {label: label, op_id: op_id, receivers: receivers_list, threshold: threshold, Zp: Zp, params: params};
var msg = { label: label, op_id: op_id, receivers: receivers_list, threshold: threshold, Zp: Zp, params: params };
msg = jiffClient.hooks.execute_array_hooks('beforeOperation', [jiffClient, 'crypto_provider', msg], 2);
msg = JSON.stringify(msg);

Expand All @@ -53,4 +53,4 @@ module.exports = function (jiffClient) {
jiffClient.socket.safe_emit('crypto_provider', msg);
return result;
};
};
};
8 changes: 4 additions & 4 deletions lib/client/api/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function (jiffClient) {
* @param {boolean} [encrypt=true] - if true, messages will be encrypted
*/
jiffClient.emit = function (tag, receivers, message, encrypt) {
if (typeof(message) !== 'string') {
if (typeof message !== 'string') {
throw new Error('Emit: message must be a string');
}

Expand All @@ -27,7 +27,7 @@ module.exports = function (jiffClient) {
continue;
}

var message_to_send = {tag: tag, party_id: receivers[p], message: message, encrypted: encrypt};
var message_to_send = { tag: tag, party_id: receivers[p], message: message, encrypted: encrypt };
message_to_send = jiffClient.hooks.execute_array_hooks('beforeOperation', [jiffClient, 'custom', message_to_send], 2);

if (message_to_send['encrypted'] !== false) {
Expand All @@ -40,7 +40,7 @@ module.exports = function (jiffClient) {

// receive our own message if specified
if (receivers.indexOf(jiffClient.id) > -1) {
jiffClient.handlers.receive_custom({tag: tag, party_id: jiffClient.id, message: message, encrypted: false});
jiffClient.handlers.receive_custom({ tag: tag, party_id: jiffClient.id, message: message, encrypted: false });
}
};

Expand Down Expand Up @@ -80,4 +80,4 @@ module.exports = function (jiffClient) {
jiffClient.remove_listener = function (tag) {
delete jiffClient.listeners[tag];
};
};
};
4 changes: 2 additions & 2 deletions lib/client/api/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function (jiffClient) {
wait_for_initialization = true;
}

jiffClient.wait_callbacks.push({parties: parties, callback: callback, initialization: wait_for_initialization});
jiffClient.wait_callbacks.push({ parties: parties, callback: callback, initialization: wait_for_initialization });
jiffClient.execute_wait_callbacks(); // See if the callback can be executed immediately
};

Expand Down Expand Up @@ -65,4 +65,4 @@ module.exports = function (jiffClient) {
var msg = jiffClient.hooks.execute_array_hooks('beforeOperation', [jiffClient, 'free', {}], 2);
jiffClient.socket.safe_emit('free', JSON.stringify(msg));
};
};
};
2 changes: 1 addition & 1 deletion lib/client/api/protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ module.exports = function (jiffClient) {
* - The promise is consumed and a new promise is returned by <jiff_instance>.preprocessing that is resolved after this returned promise (and all other promise generated by that .preprocessing call) are resolved
*/
jiffClient.protocols.rejection_sampling = sampling.bind(null, jiffClient);
};
};
8 changes: 4 additions & 4 deletions lib/client/api/sharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ module.exports = function (jiffClient) {
jiffClient.share = function (secret, threshold, receivers_list, senders_list, Zp, share_id) {
// type check to confirm the secret to be shared is a number
// for fixed-point extension it should allow non-ints
if (secret != null && (typeof(secret) !== 'number' || Math.floor(secret) !== secret || secret < 0)) {
throw new Error('secret \'' + secret + '\' must be a non-negative whole number');
if (secret != null && (typeof secret !== 'number' || Math.floor(secret) !== secret || secret < 0)) {
throw new Error("secret '" + secret + "' must be a non-negative whole number");
}
if (secret != null && (secret >= (Zp == null ? jiffClient.Zp : Zp))) {
throw new Error('secret \'' + secret + '\' must fit inside Zp');
if (secret != null && secret >= (Zp == null ? jiffClient.Zp : Zp)) {
throw new Error("secret '" + secret + "' must fit inside Zp");
}
return jiffClient.internal_share(secret, threshold, receivers_list, senders_list, Zp, share_id);
};
Expand Down
4 changes: 2 additions & 2 deletions lib/client/api/synchronization.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function (jiffClient) {
*/
jiffClient.start_barrier = function () {
openBarriers++;
currentBarrierId = (currentBarrierId + 1 % maxBarrierId);
currentBarrierId = currentBarrierId + (1 % maxBarrierId);
jiffClient.barriers[currentBarrierId] = [];
return currentBarrierId;
};
Expand Down Expand Up @@ -59,4 +59,4 @@ module.exports = function (jiffClient) {
delete jiffClient.barriers[barrier_id];
return promise;
};
};
};
11 changes: 5 additions & 6 deletions lib/client/arch/counters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Manages op_id counters and generation
module.exports = function (jiffClient) {

/**
* Resets all the counters for op_ids
* @method counters.reset
Expand Down Expand Up @@ -59,7 +58,7 @@
if (jiffClient.counters.op_count[label] == null) {
jiffClient.counters.op_count[label] = 0;
}
return label + ':' + (jiffClient.counters.op_count[label]++);
return label + ':' + jiffClient.counters.op_count[label]++;

Check warning on line 61 in lib/client/arch/counters.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/arch/counters.js#L61

Generic Object Injection Sink
};

/**
Expand All @@ -80,7 +79,7 @@
if (jiffClient.counters.op_count[label] == null) {
jiffClient.counters.op_count[label] = 0;
}
return label + ':' + (jiffClient.counters.op_count[label]++);
return label + ':' + jiffClient.counters.op_count[label]++;
};

/**
Expand All @@ -99,7 +98,7 @@
if (jiffClient.counters.op_count_preprocessing[label] == null) {
jiffClient.counters.op_count_preprocessing[label] = 0;
}
return label + ':' + (jiffClient.counters.op_count_preprocessing[label]++);
return label + ':' + jiffClient.counters.op_count_preprocessing[label]++;

Check warning on line 101 in lib/client/arch/counters.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/client/arch/counters.js#L101

Generic Object Injection Sink
};

/**
Expand All @@ -120,6 +119,6 @@
if (jiffClient.counters.op_count_preprocessing[label] == null) {
jiffClient.counters.op_count_preprocessing[label] = 0;
}
return label + ':' + (jiffClient.counters.op_count_preprocessing[label]++);
return label + ':' + jiffClient.counters.op_count_preprocessing[label]++;
};
};
};
2 changes: 1 addition & 1 deletion lib/client/arch/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ module.exports = function (JIFFClient) {
* @param {object} [options={}] - the options passed by the user to the newly applied extension.
*/
JIFFClient.prototype.extension_applied = function (name, options) {};
};
};
10 changes: 5 additions & 5 deletions lib/client/arch/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function Hooks(jiffClient) {

// avoid sharing aliases to the same array
for (hook in Hooks.prototype) {
if (Hooks.prototype.hasOwnProperty(hook) && typeof(Hooks.prototype[hook].length) === 'number' && Hooks.prototype[hook].slice) {
if (Hooks.prototype.hasOwnProperty(hook) && typeof Hooks.prototype[hook].length === 'number' && Hooks.prototype[hook].slice) {
this[hook] = Hooks.prototype[hook].slice();
}
}
Expand Down Expand Up @@ -65,9 +65,9 @@ Hooks.prototype.decryptSign = function (jiffClient, cipher) {
Hooks.prototype.generateKeyPair = function (jiffClient) {
if (jiffClient.sodium_ !== false) {
var key = jiffClient.sodium_.crypto_box_keypair(); // this party's public and secret key
return { public_key: key.publicKey, secret_key: key.privateKey }
return { public_key: key.publicKey, secret_key: key.privateKey };
} else {
return { public_key: '', secret_key: ''};
return { public_key: '', secret_key: '' };
}
};

Expand Down Expand Up @@ -122,12 +122,12 @@ Hooks.prototype.afterOperation = [
*/
Hooks.prototype.execute_array_hooks = function (hook_name, params, acc_index) {
var arr = this.jiffClient.hooks[hook_name];
arr = (arr == null ? [] : arr);
arr = arr == null ? [] : arr;

for (var i = 0; i < arr.length; i++) {
params[acc_index] = arr[i].apply(this.jiffClient, params);
}
return params[acc_index];
};

module.exports = Hooks;
module.exports = Hooks;
2 changes: 1 addition & 1 deletion lib/client/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ module.exports = function (jiffClient) {
shareHandlers(jiffClient);
customHandlers(jiffClient);
cryptoProviderHandlers(jiffClient);
};
};
2 changes: 1 addition & 1 deletion lib/client/handlers/crypto_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ module.exports = function (jiffClient) {
jiffClient.deferreds[op_id].resolve(result);
delete jiffClient.deferreds[op_id];
};
};
};
6 changes: 3 additions & 3 deletions lib/client/handlers/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = function (jiffClient) {
jiffClient.custom_messages_mailbox[tag] = stored_messages;
}

stored_messages.push({sender_id: sender_id, message: message});
stored_messages.push({ sender_id: sender_id, message: message });
}
}
};
};
};
2 changes: 1 addition & 1 deletion lib/client/handlers/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ module.exports = function (jiffClient) {
}
}
};
};
};
6 changes: 3 additions & 3 deletions lib/client/handlers/sharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = function (jiffClient) {
}

// Accumulate received shares
jiffClient.deferreds[op_id].shares.push({value: share, sender_id: sender_id, Zp: Zp});
jiffClient.deferreds[op_id].shares.push({ value: share, sender_id: sender_id, Zp: Zp });

// Resolve when ready
if (jiffClient.deferreds[op_id].shares.length === jiffClient.deferreds[op_id].threshold) {
Expand All @@ -73,5 +73,5 @@ module.exports = function (jiffClient) {
if (jiffClient.deferreds[op_id] != null && jiffClient.deferreds[op_id].deferred === 'CLEAN' && jiffClient.deferreds[op_id].shares.length === jiffClient.deferreds[op_id].total) {
delete jiffClient.deferreds[op_id];
}
}
};
};
};
20 changes: 10 additions & 10 deletions lib/client/preprocessing/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ module.exports = function (jiffClient) {

// Create preprocessing tasks
var task = {
dependent_op : dependent_op,
count : count,
threshold : threshold,
receivers_list : receivers_list,
compute_list : compute_list,
Zp : Zp,
id_list : id_list,
id : null,
params : params,
protocols : protocols,
dependent_op: dependent_op,
count: count,
threshold: threshold,
receivers_list: receivers_list,
compute_list: compute_list,
Zp: Zp,
id_list: id_list,
id: null,
params: params,
protocols: protocols,
deferred: new jiffClient.helpers.Deferred()
};

Expand Down
Loading
Loading