Skip to content

Module BSV::Primitives::Curve

Low-level secp256k1 elliptic curve operations.

Wraps OpenSSL::PKey::EC to provide point arithmetic, scalar multiplication, and key construction helpers used throughout the SDK. All constants and methods operate on the secp256k1 curve.

Constants

G

The generator point (base point).

GROUP

The secp256k1 curve group.

HALF_N

Half the curve order, used for low-S normalisation.

N

The curve order (number of points on the curve).

Public Class Methods

add_points(point_a, point_b)

Add two curve points together.

Uses +Point#add+ where available (Ruby 3.0+ / OpenSSL 3), falling back to multi-scalar multiplication for Ruby 2.7 compatibility. - @param point_a [OpenSSL::PKey::EC::Point] first point - @param point_b [OpenSSL::PKey::EC::Point] second point - @return [OpenSSL::PKey::EC::Point] the sum of the two points

ec_key_from_private_bytes(private_bytes)

Build an OpenSSL::PKey::EC key object from raw private key bytes. - @param private_bytes [String] 32-byte big-endian private key - @return [OpenSSL::PKey::EC] an EC key with both private and public components

ec_key_from_public_bytes(public_bytes)

Build an OpenSSL::PKey::EC key object from raw public key bytes. - @param public_bytes [String] compressed (33) or uncompressed (65) public key bytes - @return [OpenSSL::PKey::EC] an EC key with only the public component

multiply_generator(scalar_bn)

Multiply the generator point by a scalar. - @param scalar_bn [OpenSSL::BN] the scalar multiplier - @return [OpenSSL::PKey::EC::Point] the resulting curve point

multiply_point(point, scalar_bn)

Multiply an arbitrary curve point by a scalar. - @param point [OpenSSL::PKey::EC::Point] the point to multiply - @param scalar_bn [OpenSSL::BN] the scalar multiplier - @return [OpenSSL::PKey::EC::Point] the resulting curve point

point_from_bytes(bytes)

Reconstruct a curve point from its byte representation. - @param bytes [String] compressed (33 bytes) or uncompressed (65 bytes) point encoding - @return [OpenSSL::PKey::EC::Point] the decoded curve point

point_x(point)

Extract the x-coordinate from a curve point as a big number. - @param point [OpenSSL::PKey::EC::Point] the curve point - @return [OpenSSL::BN] the x-coordinate