Class: Ciri::Crypto::Signature
- Inherits:
-
Object
- Object
- Ciri::Crypto::Signature
- Defined in:
- lib/ciri/crypto/signature.rb
Instance Attribute Summary collapse
-
#r ⇒ Object
readonly
Returns the value of attribute r.
-
#s ⇒ Object
readonly
Returns the value of attribute s.
-
#v ⇒ Object
readonly
Returns the value of attribute v.
Instance Method Summary collapse
-
#initialize(signature: nil, vrs: nil) ⇒ Signature
constructor
A new instance of Signature.
- #low_s? ⇒ Boolean
- #signature ⇒ Object (also: #to_s)
- #valid? ⇒ Boolean
Constructor Details
#initialize(signature: nil, vrs: nil) ⇒ Signature
Returns a new instance of Signature.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ciri/crypto/signature.rb', line 34 def initialize(signature: nil, vrs: nil) if !!signature == !!vrs raise ArgumentError.new("should pass signature_bytes or vrs, but can't provide both together") end if signature unless signature.size == 65 raise ECDSASignatureError.new("signature size should be 65, got: #{signature.size}") end @r = Utils.big_endian_decode(signature[0...32]) @s = Utils.big_endian_decode(signature[32...64]) @v = Utils.big_endian_decode(signature[64]) else @v, @r, @s = vrs unless self.signature.size == 65 raise ECDSASignatureError.new("vrs is incorrect") end end end |
Instance Attribute Details
#r ⇒ Object (readonly)
Returns the value of attribute r.
32 33 34 |
# File 'lib/ciri/crypto/signature.rb', line 32 def r @r end |
#s ⇒ Object (readonly)
Returns the value of attribute s.
32 33 34 |
# File 'lib/ciri/crypto/signature.rb', line 32 def s @s end |
#v ⇒ Object (readonly)
Returns the value of attribute v.
32 33 34 |
# File 'lib/ciri/crypto/signature.rb', line 32 def v @v end |
Instance Method Details
#low_s? ⇒ Boolean
70 71 72 |
# File 'lib/ciri/crypto/signature.rb', line 70 def low_s? s < (SECP256K1N / 2) end |
#signature ⇒ Object Also known as: to_s
56 57 58 59 60 |
# File 'lib/ciri/crypto/signature.rb', line 56 def signature @signature ||= Utils.big_endian_encode(@r, "\x00".b, size: 32) + Utils.big_endian_encode(@s, "\x00".b, size: 32) + Utils.big_endian_encode(@v, "\x00".b) end |
#valid? ⇒ Boolean
64 65 66 67 68 |
# File 'lib/ciri/crypto/signature.rb', line 64 def valid? v <= 1 && r < SECP256K1N && r >= 1 && s < SECP256K1N && s >= 1 end |