j-bitcoin
Version:
Comprehensive JavaScript cryptocurrency wallet library for Bitcoin (BTC), Bitcoin Cash (BCH), and Bitcoin SV (BSV) with custodial and non-custodial wallet support, threshold signatures, and multiple address formats
2,633 lines (744 loc) • 41.3 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: Polynomial</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: Polynomial</h1>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>Polynomial<span class="signature">()</span><span class="type-signature"></span></h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="Polynomial"><span class="type-signature"></span>new Polynomial<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Polynomial class for finite field arithmetic over secp256k1 curve order</p>
<p>Provides polynomial operations essential for cryptographic secret sharing:</p>
<ul>
<li>Random polynomial generation for secret distribution</li>
<li>Polynomial evaluation at specific points (share generation)</li>
<li>Lagrange interpolation for secret reconstruction</li>
<li>Polynomial arithmetic (addition, multiplication)</li>
</ul>
<p>All coefficients are BigNumbers reduced modulo the secp256k1 curve order,
ensuring compatibility with elliptic curve cryptographic operations.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line26">line 26</a>
</li></ul></dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Create a random degree-2 polynomial for 3-of-5 threshold scheme
const poly = Polynomial.fromRandom(2);
// Evaluate at points 1,2,3,4,5 to generate shares
const shares = [1,2,3,4,5].map(x => [x, poly.evaluate(x)]);
// Reconstruct secret using any 3 shares
const secret = Polynomial.interpolate_evaluate(shares.slice(0,3), 0);</code></pre>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="coefficients"><span class="type-signature">(readonly) </span>coefficients<span class="type-signature"> :Array.<BN></span></h4>
<div class="description">
<p>Array of polynomial coefficients as BigNumbers</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Array.<BN></span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line77">line 77</a>
</li></ul></dd>
</dl>
<h4 class="name" id="order"><span class="type-signature">(readonly) </span>order<span class="type-signature"> :number</span></h4>
<div class="description">
<p>Polynomial degree (highest power of x)</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line70">line 70</a>
</li></ul></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="add"><span class="type-signature"></span>add<span class="signature">(other<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="Polynomial.html">Polynomial</a>}</span></h4>
<div class="description">
<p>Adds two polynomials coefficient-wise</p>
<p>Performs polynomial addition: (f + g)(x) = f(x) + g(x)
The resulting polynomial has degree max(deg(f), deg(g))</p>
<p>This operation is useful in cryptographic protocols that require
linear combinations of shared secrets.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>other</code></td>
<td class="type">
<span class="param-type"><a href="Polynomial.html">Polynomial</a></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
{order: 1, coefficients: [1, 2, 3]}
</td>
<td class="description last"><p>Polynomial to add</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line218">line 218</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>New polynomial representing the sum</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Polynomial.html">Polynomial</a></span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Add two random polynomials
const poly1 = Polynomial.fromRandom(2); // f(x) = a₀ + a₁x + a₂x²
const poly2 = Polynomial.fromRandom(2); // g(x) = b₀ + b₁x + b₂x²
const sum = poly1.add(poly2); // h(x) = (a₀+b₀) + (a₁+b₁)x + (a₂+b₂)x²
// Verify addition property: h(5) = f(5) + g(5)
const x = 5;
const sumAtX = sum.evaluate(x);
const directSum = poly1.evaluate(x).add(poly2.evaluate(x)).umod(N);
console.log(sumAtX.eq(directSum)); // true</code></pre>
<h4 class="name" id="evaluate"><span class="type-signature"></span>evaluate<span class="signature">(x<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {BN}</span></h4>
<div class="description">
<p>Evaluates the polynomial at a given point using Horner's method</p>
<p>Efficiently computes f(x) = a₀ + a₁x + a₂x² + ... + aₙxⁿ
using Horner's method: f(x) = a₀ + x(a₁ + x(a₂ + x(a₃ + ...)))</p>
<p>This method is used to generate shares in secret sharing schemes
by evaluating the polynomial at participant indices.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>x</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
2
</td>
<td class="description last"><p>Point at which to evaluate the polynomial</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line187">line 187</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>The polynomial value f(x) modulo curve order</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">BN</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Generate shares for a 3-of-5 threshold scheme
const secret = new BN("deadbeefcafe", 'hex');
const coeffs = [secret, new BN(randomBytes(32)), new BN(randomBytes(32))];
const poly = new Polynomial(coeffs);
// Generate 5 shares
const shares = [];
for (let i = 1; i <= 5; i++) {
shares.push([i, poly.evaluate(i)]);
}
// Any 3 shares can reconstruct the secret
const reconstructed = Polynomial.interpolate_evaluate(shares.slice(0, 3), 0);
console.log(reconstructed.eq(secret)); // true</code></pre>
<h4 class="name" id="multiply"><span class="type-signature"></span>multiply<span class="signature">(other<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="Polynomial.html">Polynomial</a>}</span></h4>
<div class="description">
<p>Multiplies two polynomials using convolution</p>
<p>Performs polynomial multiplication: (f * g)(x) = f(x) * g(x)
The resulting polynomial has degree deg(f) + deg(g)</p>
<p>Uses the standard convolution algorithm where each coefficient of the result
is the sum of products of coefficients whose indices sum to that position.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>other</code></td>
<td class="type">
<span class="param-type"><a href="Polynomial.html">Polynomial</a></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
{order: 1, coefficients: [1, 2, 3]}
</td>
<td class="description last"><p>Polynomial to multiply</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line256">line 256</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>New polynomial representing the product</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Polynomial.html">Polynomial</a></span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Multiply two polynomials: (2 + 3x) * (1 + 4x) = 2 + 11x + 12x²
const poly1 = new Polynomial([new BN(2), new BN(3)]); // 2 + 3x
const poly2 = new Polynomial([new BN(1), new BN(4)]); // 1 + 4x
const product = poly1.multiply(poly2); // 2 + 11x + 12x²
// Verify: coefficients should be [2, 11, 12]
console.log(product.coefficients[0].toNumber()); // 2
console.log(product.coefficients[1].toNumber()); // 11
console.log(product.coefficients[2].toNumber()); // 12</code></pre>
<h4 class="name" id=".fromRandom"><span class="type-signature">(static) </span>fromRandom<span class="signature">(order<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="Polynomial.html">Polynomial</a>}</span></h4>
<div class="description">
<p>Generates a random polynomial of specified degree using cryptographically secure randomness</p>
<p>Each coefficient is generated using 32 bytes of secure random data,
ensuring unpredictability suitable for cryptographic applications.
The constant term (coefficients[0]) becomes the secret to be shared.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>order</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
2
</td>
<td class="description last"><p>Degree of the polynomial to generate</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line101">line 101</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>New polynomial with random coefficients</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Polynomial.html">Polynomial</a></span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Generate random polynomial for 2-of-3 threshold (degree = threshold - 1)
const poly = Polynomial.fromRandom(2);
// Generate shares by evaluating at points 1, 2, 3
const share1 = poly.evaluate(1);
const share2 = poly.evaluate(2);
const share3 = poly.evaluate(3);
// Any 2 shares can reconstruct the secret (coefficients[0])</code></pre>
<h4 class="name" id=".interpolate_evaluate"><span class="type-signature">(static) </span>interpolate_evaluate<span class="signature">(points<span class="signature-attributes">opt</span>, x<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {BN}</span></h4>
<div class="description">
<p>Reconstructs a secret using Lagrange interpolation from coordinate points</p>
<p>Implements Lagrange interpolation to evaluate a polynomial at point x
given sufficient coordinate pairs. This is the core operation for
reconstructing secrets in Shamir's Secret Sharing.</p>
<p>The algorithm computes: f(x) = Σᵢ yᵢ * Lᵢ(x)
where Lᵢ(x) = Πⱼ≠ᵢ (x - xⱼ) / (xᵢ - xⱼ)</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>points</code></td>
<td class="type">
<span class="param-type"><a href="global.html#InterpolationPoints">InterpolationPoints</a></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
[[1, 2], [1,2]]
</td>
<td class="description last"><p>Array of [x, y] coordinate pairs</p></td>
</tr>
<tr>
<td class="name"><code>x</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
2
</td>
<td class="description last"><p>Point at which to evaluate the interpolated polynomial</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line132">line 132</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>The interpolated value f(x) modulo curve order</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">BN</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Reconstruct secret from threshold shares
const shares = [[1, new BN("123")], [2, new BN("456")], [3, new BN("789")]];
const secret = Polynomial.interpolate_evaluate(shares, 0); // Evaluate at x=0
// Verify polynomial evaluation at known point
const poly = Polynomial.fromRandom(2);
const testPoints = [[1, poly.evaluate(1)], [2, poly.evaluate(2)], [3, poly.evaluate(3)]];
const reconstructed = Polynomial.interpolate_evaluate(testPoints, 5);
const direct = poly.evaluate(5);
console.log(reconstructed.eq(direct)); // true</code></pre>
</article>
</section>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>Polynomial<span class="signature">(coefficients)</span><span class="type-signature"></span></h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="Polynomial"><span class="type-signature"></span>new Polynomial<span class="signature">(coefficients)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Creates a polynomial with given coefficients</p>
<p>The polynomial is represented as: f(x) = a₀ + a₁x + a₂x² + ... + aₙxⁿ
where coefficients[0] = a₀ (constant term), coefficients[1] = a₁, etc.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>coefficients</code></td>
<td class="type">
<span class="param-type">Array.<BN></span>
</td>
<td class="description last"><p>Array of BigNumber coefficients from constant to highest degree</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line64">line 64</a>
</li></ul></dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Create polynomial f(x) = 5 + 3x + 2x²
const coeffs = [new BN(5), new BN(3), new BN(2)];
const poly = new Polynomial(coeffs);
console.log(poly.order); // 2 (degree)</code></pre>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="coefficients"><span class="type-signature">(readonly) </span>coefficients<span class="type-signature"> :Array.<BN></span></h4>
<div class="description">
<p>Array of polynomial coefficients as BigNumbers</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Array.<BN></span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line77">line 77</a>
</li></ul></dd>
</dl>
<h4 class="name" id="order"><span class="type-signature">(readonly) </span>order<span class="type-signature"> :number</span></h4>
<div class="description">
<p>Polynomial degree (highest power of x)</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line70">line 70</a>
</li></ul></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="add"><span class="type-signature"></span>add<span class="signature">(other<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="Polynomial.html">Polynomial</a>}</span></h4>
<div class="description">
<p>Adds two polynomials coefficient-wise</p>
<p>Performs polynomial addition: (f + g)(x) = f(x) + g(x)
The resulting polynomial has degree max(deg(f), deg(g))</p>
<p>This operation is useful in cryptographic protocols that require
linear combinations of shared secrets.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>other</code></td>
<td class="type">
<span class="param-type"><a href="Polynomial.html">Polynomial</a></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
{order: 1, coefficients: [1, 2, 3]}
</td>
<td class="description last"><p>Polynomial to add</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line218">line 218</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>New polynomial representing the sum</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Polynomial.html">Polynomial</a></span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Add two random polynomials
const poly1 = Polynomial.fromRandom(2); // f(x) = a₀ + a₁x + a₂x²
const poly2 = Polynomial.fromRandom(2); // g(x) = b₀ + b₁x + b₂x²
const sum = poly1.add(poly2); // h(x) = (a₀+b₀) + (a₁+b₁)x + (a₂+b₂)x²
// Verify addition property: h(5) = f(5) + g(5)
const x = 5;
const sumAtX = sum.evaluate(x);
const directSum = poly1.evaluate(x).add(poly2.evaluate(x)).umod(N);
console.log(sumAtX.eq(directSum)); // true</code></pre>
<h4 class="name" id="evaluate"><span class="type-signature"></span>evaluate<span class="signature">(x<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {BN}</span></h4>
<div class="description">
<p>Evaluates the polynomial at a given point using Horner's method</p>
<p>Efficiently computes f(x) = a₀ + a₁x + a₂x² + ... + aₙxⁿ
using Horner's method: f(x) = a₀ + x(a₁ + x(a₂ + x(a₃ + ...)))</p>
<p>This method is used to generate shares in secret sharing schemes
by evaluating the polynomial at participant indices.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>x</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
2
</td>
<td class="description last"><p>Point at which to evaluate the polynomial</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line187">line 187</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>The polynomial value f(x) modulo curve order</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">BN</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Generate shares for a 3-of-5 threshold scheme
const secret = new BN("deadbeefcafe", 'hex');
const coeffs = [secret, new BN(randomBytes(32)), new BN(randomBytes(32))];
const poly = new Polynomial(coeffs);
// Generate 5 shares
const shares = [];
for (let i = 1; i <= 5; i++) {
shares.push([i, poly.evaluate(i)]);
}
// Any 3 shares can reconstruct the secret
const reconstructed = Polynomial.interpolate_evaluate(shares.slice(0, 3), 0);
console.log(reconstructed.eq(secret)); // true</code></pre>
<h4 class="name" id="multiply"><span class="type-signature"></span>multiply<span class="signature">(other<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="Polynomial.html">Polynomial</a>}</span></h4>
<div class="description">
<p>Multiplies two polynomials using convolution</p>
<p>Performs polynomial multiplication: (f * g)(x) = f(x) * g(x)
The resulting polynomial has degree deg(f) + deg(g)</p>
<p>Uses the standard convolution algorithm where each coefficient of the result
is the sum of products of coefficients whose indices sum to that position.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>other</code></td>
<td class="type">
<span class="param-type"><a href="Polynomial.html">Polynomial</a></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
{order: 1, coefficients: [1, 2, 3]}
</td>
<td class="description last"><p>Polynomial to multiply</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line256">line 256</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>New polynomial representing the product</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Polynomial.html">Polynomial</a></span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Multiply two polynomials: (2 + 3x) * (1 + 4x) = 2 + 11x + 12x²
const poly1 = new Polynomial([new BN(2), new BN(3)]); // 2 + 3x
const poly2 = new Polynomial([new BN(1), new BN(4)]); // 1 + 4x
const product = poly1.multiply(poly2); // 2 + 11x + 12x²
// Verify: coefficients should be [2, 11, 12]
console.log(product.coefficients[0].toNumber()); // 2
console.log(product.coefficients[1].toNumber()); // 11
console.log(product.coefficients[2].toNumber()); // 12</code></pre>
<h4 class="name" id=".fromRandom"><span class="type-signature">(static) </span>fromRandom<span class="signature">(order<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="Polynomial.html">Polynomial</a>}</span></h4>
<div class="description">
<p>Generates a random polynomial of specified degree using cryptographically secure randomness</p>
<p>Each coefficient is generated using 32 bytes of secure random data,
ensuring unpredictability suitable for cryptographic applications.
The constant term (coefficients[0]) becomes the secret to be shared.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>order</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
2
</td>
<td class="description last"><p>Degree of the polynomial to generate</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line101">line 101</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>New polynomial with random coefficients</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Polynomial.html">Polynomial</a></span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Generate random polynomial for 2-of-3 threshold (degree = threshold - 1)
const poly = Polynomial.fromRandom(2);
// Generate shares by evaluating at points 1, 2, 3
const share1 = poly.evaluate(1);
const share2 = poly.evaluate(2);
const share3 = poly.evaluate(3);
// Any 2 shares can reconstruct the secret (coefficients[0])</code></pre>
<h4 class="name" id=".interpolate_evaluate"><span class="type-signature">(static) </span>interpolate_evaluate<span class="signature">(points<span class="signature-attributes">opt</span>, x<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {BN}</span></h4>
<div class="description">
<p>Reconstructs a secret using Lagrange interpolation from coordinate points</p>
<p>Implements Lagrange interpolation to evaluate a polynomial at point x
given sufficient coordinate pairs. This is the core operation for
reconstructing secrets in Shamir's Secret Sharing.</p>
<p>The algorithm computes: f(x) = Σᵢ yᵢ * Lᵢ(x)
where Lᵢ(x) = Πⱼ≠ᵢ (x - xⱼ) / (xᵢ - xⱼ)</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>points</code></td>
<td class="type">
<span class="param-type"><a href="global.html#InterpolationPoints">InterpolationPoints</a></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
[[1, 2], [1,2]]
</td>
<td class="description last"><p>Array of [x, y] coordinate pairs</p></td>
</tr>
<tr>
<td class="name"><code>x</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
2
</td>
<td class="description last"><p>Point at which to evaluate the interpolated polynomial</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="src_Threshold-signature_Polynomial.js.html">src/Threshold-signature/Polynomial.js</a>, <a href="src_Threshold-signature_Polynomial.js.html#line132">line 132</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>The interpolated value f(x) modulo curve order</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">BN</span>
</dd>
</dl>
<h5>Example</h5>
<pre class="prettyprint"><code>// Reconstruct secret from threshold shares
const shares = [[1, new BN("123")], [2, new BN("456")], [3, new BN("789")]];
const secret = Polynomial.interpolate_evaluate(shares, 0); // Evaluate at x=0
// Verify polynomial evaluation at known point
const poly = Polynomial.fromRandom(2);
const testPoints = [[1, poly.evaluate(1)], [2, poly.evaluate(2)], [3, poly.evaluate(3)]];
const reconstructed = Polynomial.interpolate_evaluate(testPoints, 5);
const direct = poly.evaluate(5);
console.log(reconstructed.eq(direct)); // true</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="AddressFormats.html">AddressFormats</a></li><li><a href="BECH32.html">BECH32</a></li><li><a href="BIP32.html">BIP32</a></li><li><a href="BIP39.html">BIP39</a></li><li><a href="CASH_ADDR.html">CASH_ADDR</a></li><li><a href="ECDSA.html">ECDSA</a></li><li><a href="KeyDecoding.html">KeyDecoding</a></li><li><a href="Signatures.html">Signatures</a></li><li><a href="ThresholdCrypto.html">ThresholdCrypto</a></li><li><a href="Utilities.html">Utilities</a></li><li><a href="Wallets.html">Wallets</a></li><li><a href="schnorr_sig.html">schnorr_sig</a></li></ul><h3>Classes</h3><ul><li><a href="Custodial_Wallet.html">Custodial_Wallet</a></li><li><a href="Non_Custodial_Wallet.html">Non_Custodial_Wallet</a></li><li><a href="Polynomial.html">Polynomial</a></li><li><a href="ThresholdSignature.html">ThresholdSignature</a></li></ul><h3>Global</h3><ul><li><a href="global.html#CHARSET">CHARSET</a></li><li><a href="global.html#FEATURES">FEATURES</a></li><li><a href="global.html#NETWORKS">NETWORKS</a></li><li><a href="global.html#address">address</a></li><li><a href="global.html#b58encode">b58encode</a></li><li><a href="global.html#base32_encode">base32_encode</a></li><li><a href="global.html#derive">derive</a></li><li><a href="global.html#fromSeed">fromSeed</a></li><li><a href="global.html#hdKey">hdKey</a></li><li><a href="global.html#legacyAddress_decode">legacyAddress_decode</a></li><li><a href="global.html#privateKey_decode">privateKey_decode</a></li><li><a href="global.html#rmd160">rmd160</a></li><li><a href="global.html#standardKey">standardKey</a></li><li><a href="global.html#table">table</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Wed Jun 04 2025 02:28:50 GMT-0400 (Eastern Daylight Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>