11import { mod } from "@noble/curves/abstract/modular.js" ;
22
3- import { bigintToHex , toBigIntBE } from "./helpers/common" ;
3+ import { bigintToHex , Curve , toBigIntBE } from "./helpers/common" ;
44import { BigIntString } from "./interfaces" ;
55import Share from "./Share" ;
66
@@ -11,25 +11,26 @@ export type ShareMap = {
1111class 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 }
0 commit comments