Skip to content

Commit 20f5c41

Browse files
committed
fix: ecCurve type
1 parent 3ce17bf commit 20f5c41

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/Polynomial.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mod } from "@noble/curves/abstract/modular.js";
22

3-
import { bigintToHex, toBigIntBE } from "./helpers/common";
3+
import { bigintToHex, Curve, toBigIntBE } from "./helpers/common";
44
import { BigIntString } from "./interfaces";
55
import Share from "./Share";
66

@@ -11,25 +11,26 @@ export type ShareMap = {
1111
class Polynomial {
1212
polynomial: bigint[];
1313

14-
curveOrder: bigint;
14+
ecCurve: Curve;
1515

16-
constructor(polynomial: bigint[], curveOrder: bigint) {
16+
constructor(polynomial: bigint[], ecCurve: Curve) {
1717
this.polynomial = polynomial;
18-
this.curveOrder = curveOrder;
18+
this.ecCurve = ecCurve;
1919
}
2020

2121
getThreshold(): number {
2222
return this.polynomial.length;
2323
}
2424

2525
polyEval(x: BigIntString): bigint {
26+
const n = this.ecCurve.Point.CURVE().n;
2627
const tmpX = toBigIntBE(x);
2728
let xi = tmpX;
2829
let sum = this.polynomial[0];
2930
for (let i = 1; i < this.polynomial.length; i += 1) {
3031
const tmp = xi * this.polynomial[i];
31-
sum = mod(sum + tmp, this.curveOrder);
32-
xi = mod(xi * tmpX, this.curveOrder);
32+
sum = mod(sum + tmp, n);
33+
xi = mod(xi * tmpX, n);
3334
}
3435
return sum;
3536
}

src/helpers/langrangeInterpolatePoly.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const lagrange = (ecCurve: Curve, unsortedPoints: Point[]) => {
7676
polynomial[k] = mod(polynomial[k] + tmp, n);
7777
}
7878
}
79-
return new Polynomial(polynomial, n);
79+
return new Polynomial(polynomial, ecCurve);
8080
};
8181

8282
export function lagrangeInterpolatePolynomial(ecCurve: Curve, points: Point[]): Polynomial {
@@ -115,15 +115,14 @@ export function generateRandomPolynomial(
115115
secret?: bigint,
116116
deterministicShares?: Share[]
117117
): Polynomial {
118-
const n = ecCurve.Point.CURVE().n;
119118
const actualS = secret !== undefined ? secret : generatePrivateExcludingIndexes([0n], keyType);
120119
if (!deterministicShares) {
121120
const poly: bigint[] = [actualS];
122121
for (let i = 0; i < degree; i += 1) {
123122
const share = generatePrivateExcludingIndexes(poly, keyType);
124123
poly.push(share);
125124
}
126-
return new Polynomial(poly, n);
125+
return new Polynomial(poly, ecCurve);
127126
}
128127
if (!Array.isArray(deterministicShares)) {
129128
throw new Error("deterministic shares in generateRandomPolynomial should be an array");

0 commit comments

Comments
 (0)