Class: FROST::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/frost/signature.rb

Overview

A Schnorr signature over some prime order group (or subgroup).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r, s) ⇒ Signature

Constructor

Parameters:

  • r (ECDSA::Point)

    Public nonce of signature.

  • s (Integer)

    Scalar value of signature.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
# File 'lib/frost/signature.rb', line 10

def initialize(r, s)
  raise ArgumentError, "r must be ECDSA::Point" unless r.is_a?(ECDSA::Point)
  raise ArgumentError, "s must be Integer" unless s.is_a?(Integer)

  @r = r
  @s = s
end

Instance Attribute Details

#rObject (readonly)

Returns the value of attribute r.



4
5
6
# File 'lib/frost/signature.rb', line 4

def r
  @r
end

#sObject (readonly)

Returns the value of attribute s.



5
6
7
# File 'lib/frost/signature.rb', line 5

def s
  @s
end

Class Method Details

.decode(hex_value, group) ⇒ FROST::Signature

Decode hex value to FROST::Signature.

Parameters:

  • hex_value (String)

    Hex value of signature.

  • group (ECDSA::Group)

    Group of elliptic curve.

Returns:



35
36
37
38
39
40
# File 'lib/frost/signature.rb', line 35

def self.decode(hex_value, group)
  data = [hex_value].pack("H*")
  r = ECDSA::Format::PointOctetString.decode(data[0...33], group)
  s = ECDSA::Format::IntegerOctetString.decode(data[33..-1])
  Signature.new(r,s )
end

Instance Method Details

#encodeString

Encode signature to byte string.

Returns:

  • (String)


26
27
28
29
# File 'lib/frost/signature.rb', line 26

def encode
  ECDSA::Format::PointOctetString.encode(r, compression: true) +
    ECDSA::Format::IntegerOctetString.encode(s, 32)
end

#to_hexString

Encode signature to hex string.

Returns:

  • (String)


20
21
22
# File 'lib/frost/signature.rb', line 20

def to_hex
  encode.unpack1("H*")
end