Class: FROST::Signature
- Inherits:
-
Object
- Object
- FROST::Signature
- Defined in:
- lib/frost/signature.rb
Overview
A Schnorr signature over some prime order group (or subgroup).
Instance Attribute Summary collapse
-
#r ⇒ Object
readonly
Returns the value of attribute r.
-
#s ⇒ Object
readonly
Returns the value of attribute s.
Class Method Summary collapse
-
.decode(hex_value, group) ⇒ FROST::Signature
Decode hex value to FROST::Signature.
Instance Method Summary collapse
-
#encode ⇒ String
Encode signature to byte string.
-
#initialize(r, s) ⇒ Signature
constructor
Constructor.
-
#to_hex ⇒ String
Encode signature to hex string.
Constructor Details
#initialize(r, s) ⇒ Signature
Constructor
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
#r ⇒ Object (readonly)
Returns the value of attribute r.
4 5 6 |
# File 'lib/frost/signature.rb', line 4 def r @r end |
#s ⇒ Object (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.
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
#encode ⇒ String
Encode signature to byte 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_hex ⇒ String
Encode signature to hex string.
20 21 22 |
# File 'lib/frost/signature.rb', line 20 def to_hex encode.unpack1("H*") end |