Class: RingSig::PublicKey
- Inherits:
-
Object
- Object
- RingSig::PublicKey
- Defined in:
- lib/ring_sig/public_key.rb
Overview
Instances of this class represent a public ECDSA key.
Instance Attribute Summary collapse
- #hasher ⇒ Hasher readonly
-
#point ⇒ ECDSA::Point
readonly
The elliptical curve point of this public key.
Class Method Summary collapse
-
.from_hex(hex_string, hasher) ⇒ PublicKey
Creates a new instance of PublicKey from a hex string.
-
.from_octet(octet_string, hasher) ⇒ PublicKey
Creates a new instance of PublicKey from an octet string.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
True if the public keys are equal.
-
#initialize(point, hasher) ⇒ PublicKey
constructor
Creates a new instance of PublicKey.
-
#public_key ⇒ PublicKey
Self.
-
#to_hex(opts = {}) ⇒ String
Encodes this public key into an octet string.
-
#to_octet(opts = {}) ⇒ String
Encodes this public key into a hex string.
Constructor Details
#initialize(point, hasher) ⇒ PublicKey
Creates a new instance of RingSig::PublicKey.
17 18 19 20 21 22 23 |
# File 'lib/ring_sig/public_key.rb', line 17 def initialize(point, hasher) raise ArgumentError, "Point is not an ECDSA::Point" unless point.is_a?(ECDSA::Point) raise ArgumentError, "Point is not on the group's curve" unless hasher.group.include?(point) @point = point @hasher = hasher end |
Instance Attribute Details
#hasher ⇒ Hasher (readonly)
11 12 13 |
# File 'lib/ring_sig/public_key.rb', line 11 def hasher @hasher end |
#point ⇒ ECDSA::Point (readonly)
The elliptical curve point of this public key.
8 9 10 |
# File 'lib/ring_sig/public_key.rb', line 8 def point @point end |
Class Method Details
.from_hex(hex_string, hasher) ⇒ PublicKey
Creates a new instance of RingSig::PublicKey from a hex string.
30 31 32 |
# File 'lib/ring_sig/public_key.rb', line 30 def self.from_hex(hex_string, hasher) self.from_octet([hex_string].pack('H*'), hasher) end |
.from_octet(octet_string, hasher) ⇒ PublicKey
Creates a new instance of RingSig::PublicKey from an octet string.
39 40 41 42 |
# File 'lib/ring_sig/public_key.rb', line 39 def self.from_octet(octet_string, hasher) point = ECDSA::Format::PointOctetString.decode(octet_string, hasher.group) PublicKey.new(point, hasher) end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true if the public keys are equal.
76 77 78 79 |
# File 'lib/ring_sig/public_key.rb', line 76 def ==(other) return false unless other.is_a?(PublicKey) point == other.point && hasher == other.hasher end |
#public_key ⇒ PublicKey
Returns self.
71 72 73 |
# File 'lib/ring_sig/public_key.rb', line 71 def public_key self end |
#to_hex(opts = {}) ⇒ String
Encodes this public key into an octet string. The encoded data contains only the point. It does not contain the hasher.
50 51 52 53 54 55 |
# File 'lib/ring_sig/public_key.rb', line 50 def to_hex(opts = {}) compression = opts.delete(:compression) { true } raise ArgumentError, "Unknown opts: #{opts.keys.join(', ')}" unless opts.empty? to_octet(compression: compression).unpack('H*').first end |
#to_octet(opts = {}) ⇒ String
Encodes this public key into a hex string. The encoded data contains only the point. It does not contain the hasher.
63 64 65 66 67 68 |
# File 'lib/ring_sig/public_key.rb', line 63 def to_octet(opts = {}) compression = opts.delete(:compression) { true } raise ArgumentError, "Unknown opts: #{opts.keys.join(', ')}" unless opts.empty? ECDSA::Format::PointOctetString.encode(point, compression: compression) end |