Class: BSV::Primitives::PointInFiniteField
- Inherits:
-
Object
- Object
- BSV::Primitives::PointInFiniteField
- Defined in:
- lib/bsv/primitives/point_in_finite_field.rb
Overview
A point (x, y) in a finite field over the secp256k1 field prime P.
Used as a share in Shamir’s Secret Sharing Scheme. Both coordinates are reduced modulo P on construction so they always lie in [0, P).
Serialisation uses Base58 for each coordinate, joined by a dot, matching the format used by the Go and TypeScript reference SDKs.
Constant Summary collapse
- P =
The secp256k1 field prime P.
OpenSSL::BN.new('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 16).freeze
Instance Attribute Summary collapse
-
#x ⇒ OpenSSL::BN
readonly
The x-coordinate, reduced mod P.
-
#y ⇒ OpenSSL::BN
readonly
The y-coordinate, reduced mod P.
Class Method Summary collapse
-
.from_string(str) ⇒ PointInFiniteField
Deserialise from a “Base58(x).Base58(y)” string.
Instance Method Summary collapse
-
#initialize(x, y) ⇒ PointInFiniteField
constructor
A new instance of PointInFiniteField.
-
#to_s ⇒ String
Serialise to Base58(x) + “.” + Base58(y).
Constructor Details
#initialize(x, y) ⇒ PointInFiniteField
Returns a new instance of PointInFiniteField.
31 32 33 34 |
# File 'lib/bsv/primitives/point_in_finite_field.rb', line 31 def initialize(x, y) @x = umod(x, P) @y = umod(y, P) end |
Instance Attribute Details
#x ⇒ OpenSSL::BN (readonly)
Returns the x-coordinate, reduced mod P.
24 25 26 |
# File 'lib/bsv/primitives/point_in_finite_field.rb', line 24 def x @x end |
#y ⇒ OpenSSL::BN (readonly)
Returns the y-coordinate, reduced mod P.
27 28 29 |
# File 'lib/bsv/primitives/point_in_finite_field.rb', line 27 def y @y end |
Class Method Details
.from_string(str) ⇒ PointInFiniteField
Deserialise from a “Base58(x).Base58(y)” string.
48 49 50 51 52 53 54 55 |
# File 'lib/bsv/primitives/point_in_finite_field.rb', line 48 def self.from_string(str) parts = str.split('.') raise ArgumentError, "invalid point string: expected 'x.y', got #{str.inspect}" unless parts.length == 2 x = OpenSSL::BN.new(Base58.decode(parts[0]), 2) y = OpenSSL::BN.new(Base58.decode(parts[1]), 2) new(x, y) end |