class Schnorr::Signature

Instances of this class represents Schnorr signatures, which are simply a pair of integers named `r` and `s`.

Attributes

r[R]
s[R]

Public Class Methods

decode(string) click to toggle source

Parse a string to a {Signature}. @param string (String) signature string with binary format. @return (Signature) signature instance.

# File lib/schnorr/signature.rb, line 22
def self.decode(string)
  raise InvalidSignatureError, 'Invalid schnorr signature length.' unless string.bytesize == 64
  r = string[0...32].unpack('H*').first.to_i(16)
  s = string[32..-1].unpack('H*').first.to_i(16)
  new(r, s)
end
new(r, s) click to toggle source

@param r (Integer) the value of r. @param s (Integer) the value of s.

# File lib/schnorr/signature.rb, line 13
def initialize(r, s)
  @r, @s = r, s
  r.is_a?(Integer) or raise ArgumentError, 'r is not an integer.'
  s.is_a?(Integer) or raise ArgumentError, 's is not an integer.'
end

Public Instance Methods

encode() click to toggle source

Encode signature to string. @return (String) encoded signature.

# File lib/schnorr/signature.rb, line 31
def encode
  ECDSA::Format::IntegerOctetString.encode(r, 32) + ECDSA::Format::IntegerOctetString.encode(s, 32)
end