Class: Lightning::Onion::Packet
- Inherits:
-
Object
- Object
- Lightning::Onion::Packet
- Includes:
- Sphinx
- Defined in:
- lib/lightning/onion/packet.rb
Constant Summary
Constants included from Sphinx
Sphinx::ERROR_PACKET_LENGTH, Sphinx::HOP_LENGTH, Sphinx::LAST_PACKET, Sphinx::MAC_LENGTH, Sphinx::MAX_ERROR_PAYLOAD_LENGTH, Sphinx::MAX_HOPS, Sphinx::PACKET_LENGTH, Sphinx::PAYLOAD_LENGTH, Sphinx::PUBKEY_LENGTH, Sphinx::VERSION
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
Methods included from Sphinx
check_mac, compute_blinding_factor, compute_keys_and_secrets, compute_shared_secret, extract_failure_message, forward_error_packet, generate_cipher_stream, generate_filler, generate_key, hmac256, internal_compute_keys_and_secrets, internal_make_packet, internal_parse_error, mac, make_blind, make_blinds, make_error_packet, make_next_packet, make_packet, parse_error, xor
Constructor Details
#initialize(version, public_key, routing_info, hmac) ⇒ Packet
Returns a new instance of Packet.
10 11 12 13 14 15 16 |
# File 'lib/lightning/onion/packet.rb', line 10 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 == MAX_HOPS * HOP_LENGTH * 2 @hmac = hmac end |
Instance Attribute Details
#hmac ⇒ Object
Returns the value of attribute hmac.
8 9 10 |
# File 'lib/lightning/onion/packet.rb', line 8 def hmac @hmac end |
#public_key ⇒ Object
Returns the value of attribute public_key.
8 9 10 |
# File 'lib/lightning/onion/packet.rb', line 8 def public_key @public_key end |
#routing_info ⇒ Object
Returns the value of attribute routing_info.
8 9 10 |
# File 'lib/lightning/onion/packet.rb', line 8 def routing_info @routing_info end |
#version ⇒ Object
Returns the value of attribute version.
8 9 10 |
# File 'lib/lightning/onion/packet.rb', line 8 def version @version end |
Class Method Details
.parse(payload) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/lightning/onion/packet.rb', line 18 def self.parse(payload) version, public_key, rest = payload.unpack('aH66a*') routing_info = rest[0...MAX_HOPS * HOP_LENGTH].bth hmac = rest[MAX_HOPS * HOP_LENGTH..-1].bth new(version, public_key, routing_info, hmac) end |
Instance Method Details
#to_payload ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/lightning/onion/packet.rb', line 25 def to_payload payload = +'' payload << [version, public_key].pack('aH66') payload << routing_info.htb payload << hmac.htb payload end |