Skip to content

Commit

Permalink
Helper function now cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
Snafkin547 committed May 29, 2024
1 parent 1906ea2 commit ebd1199
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 64 deletions.
123 changes: 60 additions & 63 deletions lib/client/util/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,41 +51,10 @@ function Deferred() {
*/

class Helpers {
constructor(jiffClient) {
this.jiffClient = jiffClient;
}
createDeferred() {
return new Deferred();
}

/**
* Correct Mod instead of javascript's remainder (%).
* @memberof helpers
* @method
* @param {number} x - the number.
* @param {number} y - the mod.
* @return {number} x mod y.
*/
mod = helpers.mod;

/**
* Ceil of a number.
* @memberof helpers
* @method
* @param {number} x - the number to ceil.
* @return {number} ceil of x.
*/
ceil = Math.ceil;

/**
* Floor of a number
* @memberof helpers
* @method
* @param {number} x - the number to floor.
* @return {number} floor of x.
*/
floor = Math.floor;

/**
* Fast Exponentiation Mod
* @memberof helpers
Expand Down Expand Up @@ -181,38 +150,6 @@ class Helpers {
return s1.Zp === s2.Zp;
}

/**
* Generate a random integer between 0 and max-1 [inclusive].
* Modify this to change the source of randomness and how it is generated.
* @method
* @memberof helpers
* @param {number} max - the maximum number.
* @return {number} the random number.
*/
random = helpers.random;

/**
* Get the party number from the given party_id, the number is used to compute/open shares.
* If party id was a number (regular party), that number is returned,
* If party id refers to the ith server, then party_count + i is returned (i > 0).
* @method
* @memberof helpers
* @param {number|string} party_id - the party id from which to compute the number.
* @return {number} the party number (> 0).
*/
get_party_number = helpers.get_party_number;

/**
* Transforms the given number to an array of bits (numbers).
* Lower indices in the returned array corresponding to less significant bits.
* @memberof helpers
* @method
* @param {number} number - the number to transform to binary
* @param {length} [length=ceil(log2(number))] - if provided, then the given array will be padded with zeros to the length.
* @return {number[]} the array of bits.
*/
number_to_bits = helpers.number_to_bits;

/**
* Transforms the given array of bits to a number.
* @memberof helpers
Expand Down Expand Up @@ -288,4 +225,64 @@ class Helpers {
}
}

/**
* Correct Mod instead of javascript's remainder (%).
* @memberof helpers
* @method
* @param {number} x - the number.
* @param {number} y - the mod.
* @return {number} x mod y.
*/
Helpers.prototype.mod = helpers.mod;

/**
* Ceil of a number.
* @memberof helpers
* @method
* @param {number} x - the number to ceil.
* @return {number} ceil of x.
*/
Helpers.prototype.ceil = Math.ceil;

/**
* Floor of a number
* @memberof helpers
* @method
* @param {number} x - the number to floor.
* @return {number} floor of x.
*/
Helpers.prototype.floor = Math.floor;

/**
* Generate a random integer between 0 and max-1 [inclusive].
* Modify this to change the source of randomness and how it is generated.
* @method
* @memberof helpers
* @param {number} max - the maximum number.
* @return {number} the random number.
*/
Helpers.prototype.random = helpers.random;

/**
* Get the party number from the given party_id, the number is used to compute/open shares.
* If party id was a number (regular party), that number is returned,
* If party id refers to the ith server, then party_count + i is returned (i > 0).
* @method
* @memberof helpers
* @param {number|string} party_id - the party id from which to compute the number.
* @return {number} the party number (> 0).
*/
Helpers.prototype.get_party_number = helpers.get_party_number;

/**
* Transforms the given number to an array of bits (numbers).
* Lower indices in the returned array corresponding to less significant bits.
* @memberof helpers
* @method
* @param {number} number - the number to transform to binary
* @param {length} [length=ceil(log2(number))] - if provided, then the given array will be padded with zeros to the length.
* @return {number[]} the array of bits.
*/
Helpers.prototype.number_to_bits = helpers.number_to_bits;

module.exports = Helpers;
5 changes: 4 additions & 1 deletion lib/jiff-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ function JIFFClient(hostname, computation_id, options) {
* Helper functions [DO NOT MODIFY UNLESS YOU KNOW WHAT YOU ARE DOING].
* @type {!helpers}
*/
this.helpers = new Helpers(this);
this.helpers = {};
Object.getOwnPropertyNames(Helpers.prototype).forEach((method) => {
this.helpers[method] = Helpers.prototype[method];

Check warning on line 161 in lib/jiff-client.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/jiff-client.js#L161

Generic Object Injection Sink
});

/**
* Shallow copy of the options passed to the constructor.
Expand Down

0 comments on commit ebd1199

Please sign in to comment.