mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 21:09:11 +00:00
* refactor: update import paths in gateway handlers * refactor: remove obsolete devtools Makefile and README * build: optimize build process for improved efficiency * refactor: remove obsolete pkl files related to Matrix and Sonr network configurations * refactor: move embed code to x/dwn/types
36 lines
761 B
Go
Executable File
36 lines
761 B
Go
Executable File
//
|
|
// Copyright Coinbase, Inc. All Rights Reserved.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package sharing
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/onsonr/sonr/internal/crypto/core/curves"
|
|
)
|
|
|
|
type Polynomial struct {
|
|
Coefficients []curves.Scalar
|
|
}
|
|
|
|
func (p *Polynomial) Init(intercept curves.Scalar, degree uint32, reader io.Reader) *Polynomial {
|
|
p.Coefficients = make([]curves.Scalar, degree)
|
|
p.Coefficients[0] = intercept.Clone()
|
|
for i := 1; i < int(degree); i++ {
|
|
p.Coefficients[i] = intercept.Random(reader)
|
|
}
|
|
return p
|
|
}
|
|
|
|
func (p Polynomial) Evaluate(x curves.Scalar) curves.Scalar {
|
|
degree := len(p.Coefficients) - 1
|
|
out := p.Coefficients[degree].Clone()
|
|
for i := degree - 1; i >= 0; i-- {
|
|
out = out.Mul(x).Add(p.Coefficients[i])
|
|
}
|
|
return out
|
|
}
|