import { ISerializable , PolynomialID , StringifiedType } from "../baseTypes/commonTypes" ; import Point from "./Point" ; class PublicPolynomial implements ISerializable { polynomialCommitments : Point [ ] ; polynomialId : PolynomialID ; constructor ( polynomialCommitments ) { this . polynomialCommitments = polynomialCommitments ; } static fromJSON ( value ) { const points = value . polynomialCommitments . map ( ( x ) => Point . fromJSON ( x ) ) ; return new PublicPolynomial ( points ) ; } getThreshold ( ) { return this . polynomialCommitments . length ; } getPolynomialID ( ) { let idSeed = "" ; for ( let i = 0 ; i < this . polynomialCommitments . length ; i += 1 ) { let nextChunk = this . polynomialCommitments [ i ] . encode ( "elliptic-compressed" ) . toString ( ) ; if ( i !== 0 ) { nextChunk = `|${ nextChunk }` ; } idSeed += nextChunk ; } this . polynomialId = idSeed ; return this . polynomialId ; } toJSON ( ) { return { polynomialCommitments : this . polynomialCommitments , } ; } } export type PublicPolynomialMap = { [ polynomialID ] : PublicPolynomial ; } ; export default PublicPolynomial ;