Class: Lightning::Onion::Packet
- Inherits:
-
Object
- Object
- Lightning::Onion::Packet
- Defined in:
- lib/lightning/onion/packet.rb
Instance Attribute Summary collapse
-
#hmac ⇒ Object
Returns the value of attribute hmac.
-
#public_key ⇒ Object
Returns the value of attribute public_key.
-
#routing_info ⇒ Object
Returns the value of attribute routing_info.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(version, public_key, routing_info, hmac) ⇒ Packet
constructor
A new instance of Packet.
- #to_payload ⇒ Object
Constructor Details
#initialize(version, public_key, routing_info, hmac) ⇒ Packet
7 8 9 10 11 12 13 |
# File 'lib/lightning/onion/packet.rb', line 7 def initialize(version, public_key, routing_info, hmac) @version = version @public_key = public_key @routing_info = routing_info raise "invalid size #{routing_info.size}" unless routing_info.size == 1300 * 2 @hmac = hmac end |
Instance Attribute Details
#hmac ⇒ Object
Returns the value of attribute hmac.
6 7 8 |
# File 'lib/lightning/onion/packet.rb', line 6 def hmac @hmac end |
#public_key ⇒ Object
Returns the value of attribute public_key.
6 7 8 |
# File 'lib/lightning/onion/packet.rb', line 6 def public_key @public_key end |
#routing_info ⇒ Object
Returns the value of attribute routing_info.
6 7 8 |
# File 'lib/lightning/onion/packet.rb', line 6 def routing_info @routing_info end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/lightning/onion/packet.rb', line 6 def version @version end |
Class Method Details
.parse(payload) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/lightning/onion/packet.rb', line 15 def self.parse(payload) version, public_key, rest = payload.unpack('aH66a*') routing_info = rest[0...20 * 65].bth hmac = rest[20 * 65..-1].bth new(version, public_key, routing_info, hmac) end |
Instance Method Details
#to_payload ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/lightning/onion/packet.rb', line 22 def to_payload payload = +'' payload << [version, public_key].pack('aH66') payload << routing_info.htb payload << hmac.htb payload end |