Skip to content

Class BSV::Primitives::Signature

Inherits: Object

An ECDSA signature consisting of (r, s) components.

Supports DER encoding/decoding with strict BIP-66 validation, low-S normalisation (BIP-62 rule 5), and hex convenience methods.

@example Parse a DER-encoded signature

sig = BSV::Primitives::Signature.from_der(der_bytes)
sig.low_s? #=> true

Attributes

r [R]

  • @return [OpenSSL::BN] the r component

s [R]

  • @return [OpenSSL::BN] the s component

Public Class Methods

from_der(der_bytes)

Parse a signature from DER-encoded bytes with strict BIP-66 validation. - @param der_bytes [String] DER-encoded signature bytes - @raise [ArgumentError] if the DER encoding is invalid - @return [Signature]

from_hex(hex)

Parse a signature from a hex-encoded DER string. - @param hex [String] hex-encoded DER signature - @return [Signature]

Public Instance Methods

==(other)

  • @param other [Object] the object to compare
  • @return [Boolean] +true+ if both signatures have equal r and s values

initialize(r, s)

  • @param r [OpenSSL::BN, Integer] the r component
  • @param s [OpenSSL::BN, Integer] the s component
  • @return [Signature] a new instance of Signature

low_s?()

Check whether the S value is in the lower half of the curve order.

BIP-62 rule 5 requires S <= N/2 for transaction malleability protection. - @return [Boolean] +true+ if S is in the lower half

to_der()

Serialise the signature in DER format. - @return [String] DER-encoded binary string

to_hex()

Serialise the signature as a hex-encoded DER string. - @return [String] hex-encoded DER signature

to_low_s()

Return a new signature with S normalised to the lower half of the curve order. - @return [Signature] a new signature with low-S, or +self+ if already low-S