diff --git a/lib/client/protocols/booleans/boolean.js b/lib/client/protocols/booleans/boolean.js index 367e1a476..a588aa02b 100644 --- a/lib/client/protocols/booleans/boolean.js +++ b/lib/client/protocols/booleans/boolean.js @@ -1,5 +1,5 @@ // Generic version of operations -module.exports = function (SecretShare) { +class Booleans { /** * bitwise-XOR with a constant (BOTH BITS). * @method cxor_bit @@ -8,7 +8,7 @@ module.exports = function (SecretShare) { * @memberof module:jiff-client~JIFFClient#SecretShare * @instance */ - SecretShare.prototype.cxor_bit = function (cst) { + cxor_bit(cst) { if (!this.isConstant(cst)) { throw new Error('parameter should be a number (^)'); } @@ -17,7 +17,7 @@ module.exports = function (SecretShare) { } return this.icadd(cst).issub(this.icmult(cst).icmult(2)); - }; + } /** * bitwise-OR with a constant (BOTH BITS). @@ -27,7 +27,7 @@ module.exports = function (SecretShare) { * @memberof module:jiff-client~JIFFClient#SecretShare * @instance */ - SecretShare.prototype.cor_bit = function (cst) { + cor_bit(cst) { if (!this.isConstant(cst)) { throw new Error('parameter should be a number (|)'); } @@ -36,7 +36,7 @@ module.exports = function (SecretShare) { } return this.icadd(cst).issub(this.icmult(cst)); - }; + } /** * bitwise-XOR of two secret shares OF BITS. @@ -50,7 +50,7 @@ module.exports = function (SecretShare) { * @memberof module:jiff-client~JIFFClient#SecretShare * @instance */ - SecretShare.prototype.sxor_bit = function (o, op_id) { + sxor_bit(o, op_id) { if (!(o.jiff === this.jiff)) { throw new Error('shares do not belong to the same instance (^)'); } @@ -65,7 +65,7 @@ module.exports = function (SecretShare) { } return this.isadd(o).issub(this.ismult(o, op_id + ':smult1').icmult(2)); - }; + } /** * OR of two secret shares OF BITS. @@ -79,7 +79,7 @@ module.exports = function (SecretShare) { * @memberof module:jiff-client~JIFFClient#SecretShare * @instance */ - SecretShare.prototype.sor_bit = function (o, op_id) { + sor_bit(o, op_id) { if (!(o.jiff === this.jiff)) { throw new Error('shares do not belong to the same instance (|)'); } @@ -94,7 +94,7 @@ module.exports = function (SecretShare) { } return this.isadd(o).issub(this.ismult(o, op_id + ':smult1')); - }; + } /** * Negation of a bit. @@ -104,9 +104,9 @@ module.exports = function (SecretShare) { * @memberof module:jiff-client~JIFFClient#SecretShare * @instance */ - SecretShare.prototype.not = function () { + not() { return this.icmult(-1).icadd(1); - }; + } /** * Simulate an oblivious If-else statement with a single return value. @@ -131,7 +131,7 @@ module.exports = function (SecretShare) { * // max is set to the greater value, without revealing the value or the result of the inequality * let max = cmp.if_else(a, b); */ - SecretShare.prototype.if_else = function (trueVal, falseVal, op_id) { + if_else(trueVal, falseVal, op_id) { if (op_id == null) { op_id = this.jiff.counters.gen_op_id('if_else', this.holders); } @@ -149,5 +149,7 @@ module.exports = function (SecretShare) { } else { return this.ismult(trueVal.issub(falseVal), op_id + ':smult').isadd(falseVal); } - }; -}; + } +} + +module.exports = Booleans; diff --git a/lib/client/share.js b/lib/client/share.js index c6eea9b88..92062f42e 100644 --- a/lib/client/share.js +++ b/lib/client/share.js @@ -2,7 +2,7 @@ const genericProtocols = require('./protocols/generic.js'); const arithmetic = require('./protocols/numbers/arithmetic.js'); const comparison = require('./protocols/numbers/comparison.js'); const protocols = require('./protocols/numbers/protocols.js'); -const booleans = require('./protocols/booleans/boolean.js'); +const Booleans = require('./protocols/booleans/boolean.js'); // a metaclass that creates SecretShare classes when given a jiff instance // alternatively, we can think of this as a factory for a secret share prototypes/constructors given a jiff instance @@ -212,7 +212,11 @@ module.exports = function (jiff) { arithmetic(SecretShare); comparison(SecretShare); protocols(SecretShare); - booleans(SecretShare); + + // Attach all methods from Booleans class to SecretShare prototype + Object.getOwnPropertyNames(Booleans.prototype).forEach((method) => { + SecretShare.prototype[String(method)] = Booleans.prototype[String(method)]; + }); // internal variant of primitives, to use internally by other primitives const internals = [