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
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#r ⇒ Object
readonly
Returns the value of attribute r.
-
#s ⇒ Object
readonly
Returns the value of attribute s.
Class Method Summary collapse
-
.decode(context, hex_value) ⇒ FROST::Signature
Decode hex value to FROST::Signature.
Instance Method Summary collapse
-
#encode ⇒ String
Encode signature to byte string.
-
#initialize(context, r, s) ⇒ Signature
constructor
Constructor.
-
#to_hex ⇒ String
Encode signature to hex string.
Constructor Details
#initialize(context, r, s) ⇒ Signature
Constructor
12 13 14 15 16 17 18 19 20 |
# File 'lib/frost/signature.rb', line 12 def initialize(context, 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) raise ArgumentError, "context must be FROST::Context" unless context.is_a?(FROST::Context) @r = r @s = s @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/frost/signature.rb', line 6 def context @context end |
#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(context, hex_value) ⇒ FROST::Signature
Decode hex value to FROST::Signature.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/frost/signature.rb', line 45 def self.decode(context, hex_value) raise ArgumentError, "context must be FROST::Context" unless context.is_a?(FROST::Context) raise ArgumentError, "hex value must be String" unless hex_value.is_a?(String) data = [hex_value].pack("H*") data = [0x02].pack('C') + data if context.taproot? len = context.group.byte_length + 1 r = ECDSA::Format::PointOctetString.decode(data[0...len], context.group) s = ECDSA::Format::IntegerOctetString.decode(data[len..-1]) Signature.new(context, r, s) end |
Instance Method Details
#encode ⇒ String
Encode signature to byte string.
30 31 32 33 34 35 36 37 38 |
# File 'lib/frost/signature.rb', line 30 def encode if context.taproot? ECDSA::Format::IntegerOctetString.encode(r.x, context.group.byte_length) + ECDSA::Format::IntegerOctetString.encode(s, context.group.byte_length) else ECDSA::Format::PointOctetString.encode(r, compression: true) + ECDSA::Format::IntegerOctetString.encode(s, context.group.byte_length) end end |
#to_hex ⇒ String
Encode signature to hex string.
24 25 26 |
# File 'lib/frost/signature.rb', line 24 def to_hex encode.unpack1("H*") end |