helpers
- Description:
Contains helper functions: these may be overriden by extensions to customize behavior
- Source:
- See:
Classes
Methods
(static) jiffClient.helpers.array_equals(arr1, arr2) → {boolean}
- Description:
Check that two sorted arrays are equal.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
arr1 |
Array | the first array. |
arr2 |
Array | the second array. |
Returns:
true if arr1 is equal to arr2, false otherwise.
- Type
- boolean
(static) jiffClient.helpers.bits_to_number(bits, lengthopt) → {number}
- Description:
Transforms the given array of bits to a number.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
bits |
Array.<number> | the array of bits to compose as a number, starting from least to most significant bits. |
||
length |
number |
<optional> |
bits.length
|
if provided, only the first 'length' bits will be used |
Returns:
the array of bits.
- Type
- number
(static) jiffClient.helpers.bLog(value, baseopt) → {number}
- Description:
Compute Log to a given base.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
number | the number to find log for. |
||
base |
number |
<optional> |
2
|
the base (2 by default). |
Returns:
log(value) with the given base.
- Type
- number
(static) jiffClient.helpers.ceil(x) → {number}
- Description:
Ceil of a number.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
x |
number | the number to ceil. |
Returns:
ceil of x.
- Type
- number
(static) jiffClient.helpers.extended_gcd(a, b) → {Array.<number>}
- Description:
Extended Euclidean for finding inverses.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
number | the number to find inverse for. |
b |
number | the mod. |
Returns:
[inverse of a mod b, coefficient for a, coefficient for b].
- Type
- Array.<number>
(static) jiffClient.helpers.floor(x) → {number}
- Description:
Floor of a number
- Source:
Parameters:
Name | Type | Description |
---|---|---|
x |
number | the number to floor. |
Returns:
floor of x.
- Type
- number
(static) jiffClient.helpers.get_party_number(party_id) → {number}
- Description:
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).
- Source:
Parameters:
Name | Type | Description |
---|---|---|
party_id |
number | string | the party id from which to compute the number. |
Returns:
the party number (> 0).
- Type
- number
(static) jiffClient.helpers.is_prime(p) → {boolean}
- Description:
Checks if the given number is prime using AKS primality test
- Source:
Parameters:
Name | Type | Description |
---|---|---|
p |
number | the number to check |
Returns:
true if p is prime, false otherwise
- Type
- boolean
(static) jiffClient.helpers.mod(x, y) → {number}
- Description:
Correct Mod instead of javascript's remainder (%).
- Source:
Parameters:
Name | Type | Description |
---|---|---|
x |
number | the number. |
y |
number | the mod. |
Returns:
x mod y.
- Type
- number
(static) jiffClient.helpers.number_to_bits(number, lengthopt) → {Array.<number>}
- Description:
Transforms the given number to an array of bits (numbers). Lower indices in the returned array corresponding to less significant bits.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
number |
number | the number to transform to binary |
||
length |
length |
<optional> |
ceil(log2(number))
|
if provided, then the given array will be padded with zeros to the length. |
Returns:
the array of bits.
- Type
- Array.<number>
(static) jiffClient.helpers.pow_mod(a, b, n) → {number}
- Description:
Fast Exponentiation Mod
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
number | the base number |
b |
number | the power |
n |
number | the mod |
Returns:
(base^pow) mod m
- Type
- number
(static) jiffClient.helpers.random(max) → {number}
- Description:
Generate a random integer between 0 and max-1 [inclusive]. Modify this to change the source of randomness and how it is generated.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
max |
number | the maximum number. |
Returns:
the random number.
- Type
- number
(static) jiffClient.helpers.sort_ids(ids)
- Description:
sorts an array of ids (in place) according to a consistent ordering
- Source:
Parameters:
Name | Type | Description |
---|---|---|
ids |
array | array of ids containing numbers or "s1" |
(static) jiffClient.helpers.Zp_equals(s1, s2) → {boolean}
- Description:
Check that two Zps are equal. Used to determine if shares can be computed on or not.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
s1 |
SecretShare | the first share. |
s2 |
SecretShare | the second share. |
Returns:
true both shares have the same Zp, false otherwise.
- Type
- boolean