Class BSV::Primitives::Polynomial ¶
Inherits: Object
A polynomial defined by a set of points, evaluated using Lagrange interpolation.
Used in Shamir's Secret Sharing Scheme to split and reconstruct a secret. All arithmetic is performed in the finite field GF(P) where P is the secp256k1 field prime.
The secret is encoded as the y-value at x=0. Given threshold distinct points the polynomial can be evaluated at any x by Lagrange interpolation.
@example Construct shares from a private key
poly = Polynomial.from_private_key(key, threshold: 2)
share1 = poly.value_at(OpenSSL::BN.new('1'))
share0 = poly.value_at(OpenSSL::BN.new('0')) # recovers the secret
Constants¶
P ¶
Not documented.
Attributes¶
points [R] ¶
- @return [Array
] the defining points of the polynomial
threshold [R] ¶
- @return [Integer] the minimum number of shares needed to reconstruct the secret
Public Class Methods¶
from_private_key(key, threshold:) ¶
Build a polynomial whose y-intercept (secret) is the private key scalar.
The first point is (0, key_scalar). The remaining threshold-1 points have random coordinates in [0, P), providing the random coefficients of the underlying polynomial. - @param key [PrivateKey] the private key to split - @param threshold [Integer] the reconstruction threshold (minimum 2) - @return [Polynomial]
Public Instance Methods¶
initialize(points, threshold = nil) ¶
- @param
points[Array] defining points - @param
threshold[Integer] reconstruction threshold (defaults to points.length) - @return [Polynomial] a new instance of Polynomial
value_at(x) ¶
Evaluate the polynomial at x using Lagrange interpolation mod P. - @param x [OpenSSL::BN] the x value at which to evaluate - @return [OpenSSL::BN] the y value, in [0, P)