Constructor
new Polynomial(degree, secret)
- Description:
Create a polynomial of given degree with random coefficients
- Source:
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
degree |
number | Polynomial degree (t) |
|
secret |
BN | null |
null
|
Optional secret value for a_0 (zeroth coefficient) |
Methods
clear()
- Description:
Clear sensitive data from memory
- Source:
evaluate(x) → {BN}
- Description:
Evaluate polynomial at point x using Horner's method f(x) = a_0 + a_1x + a_2x^2 + ... + a_t*x^t
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
x |
number | BN | Evaluation point (must be non-zero for secret sharing) |
Returns:
f(x) mod n
- Type
- BN
generateShares(n) → {Array.<{x: BN, y: BN, index: number}>}
- Description:
Generate shares for n participants Share for participant i is the point (i, f(i))
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
n |
number | Number of participants |
Returns:
Array of shares
- Type
- Array.<{x: BN, y: BN, index: number}>
getCoefficients() → {Array.<BN>}
- Description:
Get all coefficients (cloned for safety)
- Source:
Returns:
Array of coefficients [a_0, a_1, ..., a_t]
- Type
- Array.<BN>
getSecret() → {BN}
- Description:
Get the secret (zeroth coefficient)
- Source:
Returns:
The secret a_0
- Type
- BN
(static) interpolate(shares, x) → {BN}
- Description:
Lagrange interpolation to reconstruct polynomial value at x f(x) = Σ y_i * L_i(x)
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
shares |
Array.<{x: BN, y: BN}> | Array of shares (points on polynomial) |
x |
BN | Point to interpolate at (default 0 for secret) |
Returns:
Interpolated value f(x)
- Type
- BN
(static) lagrangeCoefficient(i, xCoords, x) → {BN}
- Description:
Calculate Lagrange basis polynomial coefficient L_i(x) L_i(x) = Ī _{jā i} (x - x_j) / (x_i - x_j)
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
i |
number | Index in the xCoords array |
xCoords |
Array.<BN> | Array of x-coordinates |
x |
BN | Point to evaluate at (default 0 for secret reconstruction) |
Returns:
Lagrange coefficient
- Type
- BN
(static) reconstructSecret(shares) → {BN}
- Description:
Reconstruct the secret (f(0)) from shares Shorthand for interpolate(shares, 0)
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
shares |
Array.<{x: BN, y: BN}> | Array of shares |
Returns:
The reconstructed secret
- Type
- BN