Class: Schnorr::Signature
- Inherits:
-
Object
- Object
- Schnorr::Signature
- Defined in:
- lib/schnorr/signature.rb
Overview
Instances of this class represents Schnorr signatures, which are simply a pair of integers named ‘r` and `s`.
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(string) ⇒ Signature
Parse a string to a Signature.
Instance Method Summary collapse
-
#encode ⇒ String
Encode signature to string.
-
#initialize(r, s) ⇒ Signature
constructor
A new instance of Signature.
Constructor Details
Instance Attribute Details
#r ⇒ Object (readonly)
Returns the value of attribute r.
9 10 11 |
# File 'lib/schnorr/signature.rb', line 9 def r @r end |
#s ⇒ Object (readonly)
Returns the value of attribute s.
10 11 12 |
# File 'lib/schnorr/signature.rb', line 10 def s @s end |
Class Method Details
.decode(string) ⇒ Signature
Parse a string to a Schnorr::Signature.
23 24 25 26 27 28 |
# File 'lib/schnorr/signature.rb', line 23 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 |
Instance Method Details
#encode ⇒ String
Encode signature to string.
32 33 34 |
# File 'lib/schnorr/signature.rb', line 32 def encode ECDSA::Format::IntegerOctetString.encode(r, 32) + ECDSA::Format::IntegerOctetString.encode(s, 32) end |