bits

Namespace

bits()

Description:
  • Contains bits protocols (including rejection sampling and bits operations)

    Important: bit protocols (including bit_decomposition) are unaware of any extension specific customizations, and will operate as on the given shares as if they are natural numbers in Zp. Make sure to take into consideration any magnification/shift transformations needed to translate correctly between plain representations and extension representations of bits!

Source:

Methods

(static) jiffClient.protocols.bits.bit_composition(bits) → {SecretShare}

Description:
  • Creates a secret share of the number represented by the given array of secret shared bits. Requires no communication, only local operations

Source:
Parameters:
Name Type Description
bits Array.<SecretShare>

an array of the secret shares of bits, starting from least to most significant bits.

Returns:

a secret share of the number represented by bits.

Type
SecretShare

(static) jiffClient.protocols.bits.cadd(bits, constant, op_idopt) → {Array.<SecretShare>}

Description:
  • Compute sum of bitwise secret shared number and a constant

Source:
Parameters:
Name Type Attributes Default Description
bits Array.<SecretShare>

the bit wise secret shares

constant number

the constant

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for communication default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

bitwise sharing of the result. Note that the length here will be max(|bits|, |constant|) + 1 in case of potential overflow / carry

Type
Array.<SecretShare>

(static) jiffClient.protocols.bits.cdivl(bits, constant, op_idopt) → {Object}

Description:
  • Computes integer division of [secret bits] / constant

Source:
Parameters:
Name Type Attributes Default Description
bits Array.<SecretShare>

numerator: an array of secret shares of bits, starting from least to most significant bits

constant number

the denominator number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Throws:

if constant is 0.

Returns:

the quotient and remainder bits arrays, note that the quotient array has the same length as bits, and the remainder array has the same length as constant or bits, whichever is smaller

Type
Object

(static) jiffClient.protocols.bits.cdivr(constant, bits, op_idopt) → {Object}

Description:
  • Computes integer division of constant / [secret bits]

Source:
Parameters:
Name Type Attributes Default Description
constant number

the numerator number

bits Array.<SecretShare>

denominator: an array of secret shares of bits, starting from least to most significant bits

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

the quotient and remainder bits arrays, note that the quotient array has the same length as the number of bits in constant, and the remainder array has the same length as bits or constant, whichever is smaller. Note: if bits represent 0, the returned result is the maximum number that fits in its bits (all 1), and the remainder is equal to constant

Type
Object

(static) jiffClient.protocols.bits.ceq(bits, constant, op_idopt) → {SecretShare|boolean}

Description:
  • Checks whether the given bitwise secret shared number and numeric constant are equal

Source:
Parameters:
Name Type Attributes Default Description
bits Array.<SecretShare>

an array of secret shares of bits, starting from least to most significant bits

constant number

the constant number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

a secret share of 1 if parameters are equal, 0 otherwise. If result is known (e.g. constant has a greater non-zero bit than bits' most significant bit), the result is returned immediately as a boolean

Type
SecretShare | boolean

(static) jiffClient.protocols.bits.cgt(bits, constant, op_idopt) → {SecretShare|boolean}

Description:
  • Checks whether given secret shared bits are greater than the given constant

Source:
Parameters:
Name Type Attributes Default Description
bits Array.<SecretShare>

an array of the secret shares of bits, starting from least to most significant bits

constant number

the constant number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

a secret share of 1 if bits are greater than constant, 0 otherwise, if result is known (e.g. constant has greater non-zero bit than bits' most significant bit), the result is returned immediately as a boolean

Type
SecretShare | boolean

(static) jiffClient.protocols.bits.cgteq(bits, constant, op_idopt) → {SecretShare|boolean}

Description:
  • Checks whether given secret shared bits are greater or equal to the given constant

Source:
Parameters:
Name Type Attributes Default Description
bits Array.<SecretShare>

an array of the secret shares of bits, starting from least to most significant bits

constant number

the constant number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

a secret share of 1 if bits are greater or equal to constant, 0 otherwise, if result is known (e.g. constant has greater non-zero bit than bits' most significant bit or constant is zero), the result is returned immediately as a boolean

Type
SecretShare | boolean

(static) jiffClient.protocols.bits.clt(bits, constant, op_idopt) → {SecretShare|boolean}

Description:
  • Checks whether given secret shared bits are less than the given constant

Source:
Parameters:
Name Type Attributes Default Description
bits Array.<SecretShare>

an array of the secret shares of bits, starting from least to most significant bits

constant number

the constant number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

a secret share of 1 if bits are less than the constant, 0 otherwise, if result is known (e.g. constant has greater non-zero bit than bits' most significant bit), the result is returned immediately as a boolean

Type
SecretShare | boolean

(static) jiffClient.protocols.bits.clteq(bits, constant, op_idopt) → {SecretShare|boolean}

Description:
  • Checks whether given secret shared bits are less or equal to the given constant

Source:
Parameters:
Name Type Attributes Default Description
bits Array.<SecretShare>

an array of the secret shares of bits, starting from least to most significant bits

constant number

the constant number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

a secret share of 1 if bits are less or equal to constant, 0 otherwise, if result is known (e.g. constant has greater non-zero bit than bits' most significant bit), the result is returned immediately as a boolean

Type
SecretShare | boolean

(static) jiffClient.protocols.bits.cmult(bits, constant, op_idopt) → {Array.<SecretShare>}

Description:
  • Compute [secret bits] * constant

Source:
Parameters:
Name Type Attributes Default Description
bits Array.<SecretShare>

bitwise shared secret to multiply: lower indices represent less significant bits

constant number

constant to multiply with

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for communication. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

bitwise sharing of the result, the length of the result will be bits.length + ceil(log2(constant)), except if constant is zero, the result will then be [ zero share ]

Type
Array.<SecretShare>

(static) jiffClient.protocols.bits.cneq(bits, constant, op_idopt) → {SecretShare|boolean}

Description:
  • Checks whether the given bitwise secret shared number and numeric constant are not equal

Source:
Parameters:
Name Type Attributes Default Description
bits Array.<SecretShare>

an array of secret shares of bits, starting from least to most significant bits

constant number

the constant number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

a secret share of 1 if parameters are not equal, 0 otherwise. If result is known (e.g. constant has a greater non-zero bit than bits' most significant bit), the result is returned immediately as a boolean

Type
SecretShare | boolean

(static) jiffClient.protocols.bits.csubl(constant, bits, op_idopt) → {Array.<SecretShare>}

Description:
  • Compute [secret bits] - [constant bits]

Source:
Parameters:
Name Type Attributes Default Description
constant number

the constant

bits Array.<SecretShare>

the bit wise secret shares

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for communication. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

bitwise sharing of the result. Note that the length of the returned result is |bits|+1, where the bit at index 0 is the least significant bit. The bit at index 1 is the most significant bit, and the bit at index |bits| is 1 if the result overflows, or 0 otherwise

Type
Array.<SecretShare>

(static) jiffClient.protocols.bits.csubr(constant, bits, op_idopt) → {Array.<SecretShare>}

Description:
  • Compute [constant bits] - [secret bits]

Source:
Parameters:
Name Type Attributes Default Description
constant number

the constant

bits Array.<SecretShare>

the bit wise secret shares

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for communication. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

bitwise sharing of the result. Note that the length of the returned result is |bits|+1, where the bit at index 0 is the least significant bit. The bit at index 1 is the most significant bit, and the bit at index |bits| is 1 if the result overflows, or 0 otherwise

Type
Array.<SecretShare>

(static) jiffClient.protocols.bits.open(bits, parties, op_idopt) → {promise}

Description:
  • Opens the given array of secret shared bits. This works regardless of whether the represented value fit inside the corresponding field or not

Source:
Parameters:
Name Type Attributes Default Description
bits Array.<SecretShare>

an array of the secret shares of bits, starting from least to most significant bits

parties Array.<number>

parties to open (same as jiff_instance.open)

op_id string | number <optional>
auto_gen()

same as jiff_instance.open

Returns:

a promise to the number represented by bits

Type
promise

(static) jiffClient.protocols.bits.rejection_sampling(lower_bound, upper_bound, thresholdopt, partiesopt, Zpopt, op_idopt) → {Array.<SecretShare>}

Description:
  • Retrieves preprocessed rejection_sampling bits or performs the rejection sampling on the fly if crypto_provider is enabled

Source:
Parameters:
Name Type Attributes Default Description
lower_bound number

the lower bound, included (can be a bigNumber if using bigNumber extension)

upper_bound number

the upper bound, excluded (can be a bigNumber if using bigNumber extension)

threshold number <optional>
parties.length

the threshold of the resulting shares after sampling

parties Array <optional>
all_parties

array of party ids that want to receive (or compute if needed) the sampling shares, by default, this includes all parties

Zp number <optional>
jiff-instance.Zp

the mod (if null then the default Zp for the instance is used)

op_id string <optional>
auto_gen()

the operation id which is used to identify this operation. This id must be unique, and must be passed by all parties to the same instruction, to ensure that corresponding instructions across different parties are matched correctly

Returns:

an array of secret shares, each representing a bit from the sampled value (from least to most significant)

Type
Array.<SecretShare>

(static) jiffClient.protocols.bits.sadd(bits1, bits2, op_idopt) → {Array.<SecretShare>}

Description:
  • Compute [secret bits1] + [secret bits2]

Source:
Parameters:
Name Type Attributes Default Description
bits1 Array.<SecretShare>

the first bitwise shared number: array of secrets with index 0 being least significant bit

bits2 Array.<SecretShare>

the second bitwise shared number (length may be different)

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for communication. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

bitwise sharing of the result. Note that the length of the returned result is |bits|+1, where the bit at index 0 is the least significant bit

Type
Array.<SecretShare>

(static) jiffClient.protocols.bits.sdiv(bits1, bits2, op_idopt) → {Object}

Description:
  • Computes integer division of [secret bits 1] / [secret bits 2]

Source:
Parameters:
Name Type Attributes Default Description
bits1 Array.<SecretShare>

an array of secret shares of bits, starting from least to most significant bits

bits2 Array.<SecretShare>

the second bitwise shared number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

the quotient and remainder bits arrays, note that the quotient array has the same length as bits1, and the remainder array has the same length as bits2 or bits1, whichever is smaller. Note: if bits2 represent 0, the returned result is the maximum number that fits in the number of bits (all 1), and the remainder is equal to bits1

Type
Object

(static) jiffClient.protocols.bits.seq(bits1, bits2, op_idopt) → {SecretShare}

Description:
  • Checks whether the two given bitwise secret shared numbers are equal

Source:
Parameters:
Name Type Attributes Default Description
bits1 Array.<SecretShare>

an array of secret shares of bits, starting from least to most significant bits

bits2 Array.<SecretShare>

the second bitwise shared number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

a secret share of 1 if bits are equal, 0 otherwise

Type
SecretShare

(static) jiffClient.protocols.bits.sgt(bits1, bits2, op_idopt) → {SecretShare}

Description:
  • Checks whether the first given bitwise secret shared number is greater than the second bitwise secret shared number

Source:
Parameters:
Name Type Attributes Default Description
bits1 Array.<SecretShare>

an array of secret shares of bits, starting from least to most significant bits

bits2 Array.<SecretShare>

the second bitwise shared number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

a secret share of 1 if the first number is greater than the second, 0 otherwise

Type
SecretShare

(static) jiffClient.protocols.bits.sgteq(bits1, bits2, op_idopt) → {SecretShare}

Description:
  • Checks whether the first given bitwise secret shared number is greater than or equal to the second bitwise secret shared number

Source:
Parameters:
Name Type Attributes Default Description
bits1 Array.<SecretShare>

an array of secret shares of bits, starting from least to most significant bits

bits2 Array.<SecretShare>

the second bitwise shared number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

a secret share of 1 if the first number is greater or equal to the second, 0 otherwise

Type
SecretShare

(static) jiffClient.protocols.bits.share(secret, bit_lengthopt, thresholdopt, receivers_listopt, senders_listopt, Zpopt, share_idopt) → {object}

Description:
  • Share a number as an array of secret bits This takes the same parameters as jiff-instance.share, but returns an array of secret bit shares per sending party. Each bit array starts with the least significant bit at index 0, and most significant bit at index length-1

Source:
Parameters:
Name Type Attributes Default Description
secret number

the number to share (this party's input)

bit_length number <optional>
jiff_instance.Zp

the number of generated bits, if the secret has less bits, it will be padded with zeros

threshold number <optional>
receivers_list.length

threshold of each shared bit

receivers_list Array <optional>
all_parties

receivers of every bits

senders_list Array <optional>
all_parties

senders of evey bit

Zp number <optional>
jiff_instance.Zp

the field of sharing for every bit

share_id string | number <optional>
auto_gen()

synchronization id

Returns:

a map (of size equal to the number of parties) where the key is the party id (from 1 to n) and the value is an array of secret shared bits

Type
object

(static) jiffClient.protocols.bits.slt(bits1, bits2, op_idopt) → {SecretShare}

Description:
  • Checks whether the first given bitwise secret shared number is less than the second bitwise secret shared number

Source:
Parameters:
Name Type Attributes Default Description
bits1 Array.<SecretShare>

an array of secret shares of bits, starting from least to most significant bits

bits2 Array.<SecretShare>

the second bitwise shared number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

a secret share of 1 if the first number is less than the second, 0 otherwise

Type
SecretShare

(static) jiffClient.protocols.bits.slteq(bits1, bits2, op_idopt) → {SecretShare}

Description:
  • Checks whether the first given bitwise secret shared number is less or equal to the second bitwise secret shared number

Source:
Parameters:
Name Type Attributes Default Description
bits1 Array.<SecretShare>

an array of secret shares of bits, starting from least to most significant bits

bits2 Array.<SecretShare>

the second bitwise shared number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

a secret share of 1 if the first number is less than or equal to the second, 0 otherwise

Type
SecretShare

(static) jiffClient.protocols.bits.smult(bits1, bits2, op_idopt) → {Array.<SecretShare>}

Description:
  • Compute [secret bits1] * [secret bits2]

Source:
Parameters:
Name Type Attributes Default Description
bits1 Array.<SecretShare>

bitwise shared secret to multiply: lower indices represent less significant bits

bits2 Array.<SecretShare>

bitwise shared secret to multiply

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for communication. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

bitwise sharing of the result, the length of the result will be bits1.length + bits2.length

Type
Array.<SecretShare>

(static) jiffClient.protocols.bits.sneq(bits1, bits2, op_idopt) → {SecretShare}

Description:
  • Checks whether the two given bitwise secret shared numbers are not equal

Source:
Parameters:
Name Type Attributes Default Description
bits1 Array.<SecretShare>

an array of secret shares of bits, starting from least to most significant bits

bits2 Array.<SecretShare>

the second bitwise shared number

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for multiplications. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

a secret share of 1 if bits are not equal, 0 otherwise

Type
SecretShare

(static) jiffClient.protocols.bits.ssub(bits1, bits2, op_idopt) → {Array.<SecretShare>}

Description:
  • Compute [secret bits1] - [secret bits2]

Source:
Parameters:
Name Type Attributes Default Description
bits1 Array.<SecretShare>

first bitwise secret shared number: lower indices represent less significant bits

bits2 Array.<SecretShare>

second bitwise secret shared number (length may be different)

op_id string <optional>
<auto-generate-id>

the base operation id to use when generating unique ids for communication. default value should suffice when the code of all parties executes all instructions in the same exact order, otherwise, a unique base name is needed here

Returns:

bitwise sharing of the result. Note that the length of the returned result is |bits|+1, where the bit at index 0 is the least significant bit. The bit at index 1 is the most significant bit, and the bit at index |bits| is 1 if the result overflows, or 0 otherwise

Type
Array.<SecretShare>